XCoreTargetMachine.cpp revision 194612
1//===-- XCoreTargetMachine.cpp - Define TargetMachine for XCore -----------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
13#include "XCoreTargetAsmInfo.h"
14#include "XCoreTargetMachine.h"
15#include "XCore.h"
16#include "llvm/Module.h"
17#include "llvm/PassManager.h"
18#include "llvm/Target/TargetMachineRegistry.h"
19using namespace llvm;
20
21/// XCoreTargetMachineModule - Note that this is used on hosts that
22/// cannot link in a library unless there are references into the
23/// library.  In particular, it seems that it is not possible to get
24/// things to work on Win32 without this.  Though it is unused, do not
25/// remove it.
26extern "C" int XCoreTargetMachineModule;
27int XCoreTargetMachineModule = 0;
28
29namespace {
30  // Register the target.
31  RegisterTarget<XCoreTargetMachine> X("xcore", "XCore");
32}
33
34// Force static initialization when called from llvm/InitializeAllTargets.h
35namespace llvm {
36  void InitializeXCoreTarget() { }
37}
38
39const TargetAsmInfo *XCoreTargetMachine::createTargetAsmInfo() const {
40  return new XCoreTargetAsmInfo(*this);
41}
42
43/// XCoreTargetMachine ctor - Create an ILP32 architecture model
44///
45XCoreTargetMachine::XCoreTargetMachine(const Module &M, const std::string &FS)
46  : Subtarget(*this, M, FS),
47    DataLayout("e-p:32:32:32-a0:0:32-f32:32:32-f64:32:32-i1:8:32-i8:8:32-"
48               "i16:16:32-i32:32:32-i64:32:32"),
49    InstrInfo(),
50    FrameInfo(*this),
51    TLInfo(*this) {
52}
53
54unsigned XCoreTargetMachine::getModuleMatchQuality(const Module &M) {
55  std::string TT = M.getTargetTriple();
56  if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "xcore-")
57    return 20;
58
59  // Otherwise we don't match.
60  return 0;
61}
62
63bool XCoreTargetMachine::addInstSelector(PassManagerBase &PM,
64                                         CodeGenOpt::Level OptLevel) {
65  PM.add(createXCoreISelDag(*this));
66  return false;
67}
68
69bool XCoreTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
70                                            CodeGenOpt::Level OptLevel,
71                                            bool Verbose,
72                                            raw_ostream &Out) {
73  // Output assembly language.
74  PM.add(createXCoreCodePrinterPass(Out, *this, OptLevel, Verbose));
75  return false;
76}
77