llvm.org GIT mirror llvm / 51b198a
Reapply TargetRegistry refactoring commits. --- Reverse-merging r75799 into '.': U test/Analysis/PointerTracking U include/llvm/Target/TargetMachineRegistry.h U include/llvm/Target/TargetMachine.h U include/llvm/Target/TargetRegistry.h U include/llvm/Target/TargetSelect.h U tools/lto/LTOCodeGenerator.cpp U tools/lto/LTOModule.cpp U tools/llc/llc.cpp U lib/Target/PowerPC/PPCTargetMachine.h U lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp U lib/Target/PowerPC/PPCTargetMachine.cpp U lib/Target/PowerPC/PPC.h U lib/Target/ARM/ARMTargetMachine.cpp U lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp U lib/Target/ARM/ARMTargetMachine.h U lib/Target/ARM/ARM.h U lib/Target/XCore/XCoreTargetMachine.cpp U lib/Target/XCore/XCoreTargetMachine.h U lib/Target/PIC16/PIC16TargetMachine.cpp U lib/Target/PIC16/PIC16TargetMachine.h U lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp U lib/Target/Alpha/AlphaTargetMachine.cpp U lib/Target/Alpha/AlphaTargetMachine.h U lib/Target/X86/X86TargetMachine.h U lib/Target/X86/X86.h U lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h U lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp U lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.h U lib/Target/X86/X86TargetMachine.cpp U lib/Target/MSP430/MSP430TargetMachine.cpp U lib/Target/MSP430/MSP430TargetMachine.h U lib/Target/CppBackend/CPPTargetMachine.h U lib/Target/CppBackend/CPPBackend.cpp U lib/Target/CBackend/CTargetMachine.h U lib/Target/CBackend/CBackend.cpp U lib/Target/TargetMachine.cpp U lib/Target/IA64/IA64TargetMachine.cpp U lib/Target/IA64/AsmPrinter/IA64AsmPrinter.cpp U lib/Target/IA64/IA64TargetMachine.h U lib/Target/IA64/IA64.h U lib/Target/MSIL/MSILWriter.cpp U lib/Target/CellSPU/SPUTargetMachine.h U lib/Target/CellSPU/SPU.h U lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp U lib/Target/CellSPU/SPUTargetMachine.cpp U lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp U lib/Target/Mips/MipsTargetMachine.cpp U lib/Target/Mips/MipsTargetMachine.h U lib/Target/Mips/Mips.h U lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp U lib/Target/Sparc/SparcTargetMachine.cpp U lib/Target/Sparc/SparcTargetMachine.h U lib/ExecutionEngine/JIT/TargetSelect.cpp U lib/Support/TargetRegistry.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75820 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 11 years ago
54 changed file(s) with 318 addition(s) and 644 deletion(s). Raw diff Collapse all Expand all
1818
1919 namespace llvm {
2020
21 class Target;
2122 class TargetAsmInfo;
2223 class TargetData;
2324 class TargetSubtarget;
9899 TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT
99100 void operator=(const TargetMachine &); // DO NOT IMPLEMENT
100101 protected: // Can only create subclasses.
101 TargetMachine();
102 TargetMachine(const Target &);
102103
103104 /// getSubtargetImpl - virtual method implemented by subclasses that returns
104105 /// a reference to that target's TargetSubtarget-derived member variable.
105106 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
107
108 /// TheTarget - The Target that this machine was created for.
109 const Target &TheTarget;
106110
107111 /// AsmInfo - Contains target specific asm information.
108112 ///
115119 public:
116120 virtual ~TargetMachine();
117121
118 /// getModuleMatchQuality - This static method should be implemented by
119 /// targets to indicate how closely they match the specified module. This is
120 /// used by the LLC tool to determine which target to use when an explicit
121 /// -march option is not specified. If a target returns zero, it will never
122 /// be chosen without an explicit -march option.
123 static unsigned getModuleMatchQuality(const Module &) { return 0; }
124
125 /// getJITMatchQuality - This static method should be implemented by targets
126 /// that provide JIT capabilities to indicate how suitable they are for
127 /// execution on the current host. If a value of 0 is returned, the target
128 /// will not be used unless an explicit -march option is used.
129 static unsigned getJITMatchQuality() { return 0; }
122 const Target &getTarget() const { return TheTarget; }
130123
131124 // Interfaces to the major aspects of target machine information:
132125 // -- Instruction opcode and operand information
307300 ///
308301 class LLVMTargetMachine : public TargetMachine {
309302 protected: // Can only create subclasses.
310 LLVMTargetMachine() { }
303 LLVMTargetMachine(const Target &T) : TargetMachine(T) { }
311304
312305 /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
313306 /// both emitting to assembly files or machine code output.
1818
1919 #include "llvm/Module.h"
2020 #include "llvm/Support/Registry.h"
21 #include "llvm/Target/TargetRegistry.h"
2122
2223 namespace llvm {
2324 class Module;
25 class Target;
2426 class TargetMachine;
2527
2628 struct TargetMachineRegistryEntry {
29 const Target &TheTarget;
2730 const char *Name;
2831 const char *ShortDesc;
29 TargetMachine *(*CtorFn)(const Module &, const std::string &);
30 unsigned (*ModuleMatchQualityFn)(const Module &M);
31 unsigned (*JITMatchQualityFn)();
3232
3333 public:
34 TargetMachineRegistryEntry(const char *N, const char *SD,
35 TargetMachine *(*CF)(const Module &, const std::string &),
36 unsigned (*MMF)(const Module &M),
37 unsigned (*JMF)())
38 : Name(N), ShortDesc(SD), CtorFn(CF), ModuleMatchQualityFn(MMF),
39 JITMatchQualityFn(JMF) {}
34 TargetMachineRegistryEntry(const Target &T, const char *N, const char *SD)
35 : TheTarget(T), Name(N), ShortDesc(SD) {}
4036 };
4137
4238 template<>
4945 };
5046
5147 struct TargetMachineRegistry : public Registry {
52 /// getClosestStaticTargetForModule - Given an LLVM module, pick the best
53 /// target that is compatible with the module. If no close target can be
54 /// found, this returns null and sets the Error string to a reason.
55 static const entry *getClosestStaticTargetForModule(const Module &M,
56 std::string &Error);
57
58 /// getClosestTargetForJIT - Pick the best target that is compatible with
59 /// the current host. If no close target can be found, this returns null
60 /// and sets the Error string to a reason.
61 static const entry *getClosestTargetForJIT(std::string &Error);
6248
6349 };
6450
6551 //===--------------------------------------------------------------------===//
6652 /// RegisterTarget - This class is used to make targets automatically register
67 /// themselves with the tool they are linked. Targets should define an
68 /// instance of this and implement the static methods described in the
69 /// TargetMachine comments.
53 /// themselves with the tools they are linked with. Targets should define an
54 /// single global Target instance and register it using the TargetRegistry
55 /// interfaces. Targets must also include a static instance of this class.
56 ///
7057 /// The type 'TargetMachineImpl' should provide a constructor with two
7158 /// parameters:
7259 /// - const Module& M: the module that is being compiled:
7562
7663 template
7764 struct RegisterTarget {
78 RegisterTarget(const char *Name, const char *ShortDesc)
79 : Entry(Name, ShortDesc, &Allocator,
80 &TargetMachineImpl::getModuleMatchQuality,
81 &TargetMachineImpl::getJITMatchQuality),
82 Node(Entry)
83 {}
65 RegisterTarget(Target &T, const char *Name, const char *ShortDesc)
66 : Entry(T, Name, ShortDesc),
67 Node(Entry) {
68 TargetRegistry::RegisterTargetMachine(T, &Allocator);
69 }
8470
8571 private:
8672 TargetMachineRegistry::entry Entry;
8773 TargetMachineRegistry::node Node;
8874
89 static TargetMachine *Allocator(const Module &M, const std::string &FS) {
90 return new TargetMachineImpl(M, FS);
75 static TargetMachine *Allocator(const Target &T, const Module &M,
76 const std::string &FS) {
77 return new TargetMachineImpl(T, M, FS);
9178 }
9279 };
9380
4141 typedef unsigned (*ModuleMatchQualityFnTy)(const Module &M);
4242 typedef unsigned (*JITMatchQualityFnTy)();
4343
44 typedef TargetMachine *(*TargetMachineCtorTy)(const Module &,
44 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &,
45 const Module &,
4546 const std::string &);
4647 typedef FunctionPass *(*AsmPrinterCtorTy)(formatted_raw_ostream &,
4748 TargetMachine &,
8687 /// getShortDescription - Get a short description of the target.
8788 const char *getShortDescription() const { return ShortDesc; }
8889
90 /// getJITMatchQuality - Get the quality of this targets match for use as a
91 /// JIT.
92 unsigned getJITMatchQuality() const { return JITMatchQualityFn(); }
93
8994 /// createTargetMachine - Create a target specific machine implementation.
9095 TargetMachine *createTargetMachine(const Module &M,
91 const std::string &Features) {
96 const std::string &Features) const {
9297 if (!TargetMachineCtorFn)
9398 return 0;
94 return TargetMachineCtorFn(M, Features);
99 return TargetMachineCtorFn(*this, M, Features);
95100 }
96101
97102 /// createAsmPrinter - Create a target specific assembly printer pass.
98103 FunctionPass *createAsmPrinter(formatted_raw_ostream &OS,
99104 TargetMachine &M,
100 bool Verbose) {
105 bool Verbose) const {
101106 if (!AsmPrinterCtorFn)
102107 return 0;
103108 return AsmPrinterCtorFn(OS, M, Verbose);
134139 /// @name Target Registration
135140 /// @{
136141
137 /// RegisterTarget - Register the given target.
142 /// RegisterTarget - Register the given target. Attempts to register a
143 /// target which has already been registered will be ignored.
138144 ///
139145 /// Clients are responsible for ensuring that registration doesn't occur
140146 /// while another thread is attempting to access the registry. Typically
5757 inline bool InitializeNativeTarget() {
5858 // If we have a native target, initialize it to ensure it is linked in.
5959 #ifdef LLVM_NATIVE_ARCH
60 #define DoInit2(TARG) LLVMInitialize ## TARG ()
60 #define DoInit2(TARG) \
61 LLVMInitialize ## TARG ## Info (); \
62 LLVMInitialize ## TARG ()
6163 #define DoInit(T) DoInit2(T)
6264 DoInit(LLVM_NATIVE_ARCH);
6365 return false;
4444 JITMemoryManager *JMM,
4545 CodeGenOpt::Level OptLevel,
4646 bool AllocateGVsWithCode) {
47 const TargetMachineRegistry::entry *TheArch = MArch;
48 if (TheArch == 0) {
47 const Target *TheTarget;
48 if (MArch == 0) {
4949 std::string Error;
50 TheArch = TargetMachineRegistry::getClosestTargetForJIT(Error);
51 if (TheArch == 0) {
50 TheTarget = TargetRegistry::getClosestTargetForJIT(Error);
51 if (TheTarget == 0) {
5252 if (ErrorStr)
5353 *ErrorStr = Error;
5454 return 0;
5555 }
56 } else if (TheArch->JITMatchQualityFn() == 0) {
57 cerr << "WARNING: This target JIT is not designed for the host you are"
58 << " running. If bad things happen, please choose a different "
59 << "-march switch.\n";
56 } else {
57 TheTarget = &MArch->TheTarget;
58 if (TheTarget->getJITMatchQuality() == 0) {
59 cerr << "WARNING: This target JIT is not designed for the host you are"
60 << " running. If bad things happen, please choose a different "
61 << "-march switch.\n";
62 }
6063 }
6164
6265 // Package up features to be passed to target/subtarget
7073 }
7174
7275 // Allocate a target...
73 TargetMachine *Target = TheArch->CtorFn(*MP->getModule(), FeaturesStr);
76 TargetMachine *Target =
77 TheTarget->createTargetMachine(*MP->getModule(), FeaturesStr);
7478 assert(Target && "Could not allocate target machine!");
7579
7680 // If the target supports JIT code generation, return a new JIT now.
110110 Target::TripleMatchQualityFnTy TQualityFn,
111111 Target::ModuleMatchQualityFnTy MQualityFn,
112112 Target::JITMatchQualityFnTy JITQualityFn) {
113 // Note that we don't require the constructor functions already be defined, in
114 // case a module happens to initialize the optional functionality before the
115 // target.
116 assert(!T.Next && !T.Name && !T.ShortDesc && !T.TripleMatchQualityFn &&
117 !T.ModuleMatchQualityFn && !T.JITMatchQualityFn &&
118 "This Target already registered!");
119
120113 assert(Name && ShortDesc && TQualityFn && MQualityFn && JITQualityFn &&
121114 "Missing required target information!");
115
116 // Check if this target has already been initialized, we allow this as a
117 // convenience to some clients.
118 if (T.Name)
119 return;
122120
123121 // Add to the list of targets.
124122 T.Next = FirstTarget;
9393
9494 FunctionPass *createARMISelDag(ARMBaseTargetMachine &TM);
9595 FunctionPass *createARMCodePrinterPass(formatted_raw_ostream &O,
96 ARMBaseTargetMachine &TM,
96 TargetMachine &TM,
9797 bool Verbose);
9898 FunctionPass *createARMCodeEmitterPass(ARMBaseTargetMachine &TM,
9999 MachineCodeEmitter &MCE);
3535 int ARMTargetMachineModule = 0;
3636
3737 // Register the target.
38 static RegisterTarget X("arm", "ARM");
39 static RegisterTarget Y("thumb", "Thumb");
38 extern Target TheARMTarget;
39 static RegisterTarget X(TheARMTarget, "arm", "ARM");
40
41 extern Target TheThumbTarget;
42 static RegisterTarget Y(TheThumbTarget, "thumb", "Thumb");
4043
4144 // Force static initialization.
4245 extern "C" void LLVMInitializeARMTarget() { }
4447 // No assembler printer by default
4548 ARMBaseTargetMachine::AsmPrinterCtorFn ARMBaseTargetMachine::AsmPrinterCtor = 0;
4649
47 /// ThumbTargetMachine - Create an Thumb architecture model.
48 ///
49 unsigned ThumbTargetMachine::getJITMatchQuality() {
50 #if defined(__thumb__)
51 return 10;
52 #endif
53 return 0;
54 }
55
56 unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
57 std::string TT = M.getTargetTriple();
58 // Match thumb-foo-bar, as well as things like thumbv5blah-*
59 if (TT.size() >= 6 &&
60 (TT.substr(0, 6) == "thumb-" || TT.substr(0, 6) == "thumbv"))
61 return 20;
62
63 // If the target triple is something non-thumb, we don't match.
64 if (!TT.empty()) return 0;
65
66 if (M.getEndianness() == Module::LittleEndian &&
67 M.getPointerSize() == Module::Pointer32)
68 return 10; // Weak match
69 else if (M.getEndianness() != Module::AnyEndianness ||
70 M.getPointerSize() != Module::AnyPointerSize)
71 return 0; // Match for some other target
72
73 return getJITMatchQuality()/2;
74 }
75
7650 /// TargetMachine ctor - Create an ARM architecture model.
7751 ///
78 ARMBaseTargetMachine::ARMBaseTargetMachine(const Module &M,
52 ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T,
53 const Module &M,
7954 const std::string &FS,
8055 bool isThumb)
81 : Subtarget(M, FS, isThumb),
56 : LLVMTargetMachine(T),
57 Subtarget(M, FS, isThumb),
8258 FrameInfo(Subtarget),
8359 JITInfo(),
8460 InstrItins(Subtarget.getInstrItineraryData()) {
8561 DefRelocModel = getRelocationModel();
8662 }
8763
88 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS)
89 : ARMBaseTargetMachine(M, FS, false), InstrInfo(Subtarget),
64 ARMTargetMachine::ARMTargetMachine(const Target &T, const Module &M,
65 const std::string &FS)
66 : ARMBaseTargetMachine(T, M, FS, false), InstrInfo(Subtarget),
9067 DataLayout(Subtarget.isAPCS_ABI() ?
9168 std::string("e-p:32:32-f64:32:32-i64:32:32") :
9269 std::string("e-p:32:32-f64:64:64-i64:64:64")),
9370 TLInfo(*this) {
9471 }
9572
96 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
97 : ARMBaseTargetMachine(M, FS, true),
73 ThumbTargetMachine::ThumbTargetMachine(const Target &T, const Module &M,
74 const std::string &FS)
75 : ARMBaseTargetMachine(T, M, FS, true),
9876 DataLayout(Subtarget.isAPCS_ABI() ?
9977 std::string("e-p:32:32-f64:32:32-i64:32:32-"
10078 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
10886 InstrInfo = new Thumb1InstrInfo(Subtarget);
10987 }
11088
111 unsigned ARMTargetMachine::getJITMatchQuality() {
112 #if defined(__arm__)
113 return 10;
114 #endif
115 return 0;
116 }
117
118 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
119 std::string TT = M.getTargetTriple();
120 // Match arm-foo-bar, as well as things like armv5blah-*
121 if (TT.size() >= 4 &&
122 (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
123 return 20;
124 // If the target triple is something non-arm, we don't match.
125 if (!TT.empty()) return 0;
126
127 if (M.getEndianness() == Module::LittleEndian &&
128 M.getPointerSize() == Module::Pointer32)
129 return 10; // Weak match
130 else if (M.getEndianness() != Module::AnyEndianness ||
131 M.getPointerSize() != Module::AnyPointerSize)
132 return 0; // Match for some other target
133
134 return getJITMatchQuality()/2;
135 }
136
13789
13890 const TargetAsmInfo *ARMBaseTargetMachine::createTargetAsmInfo() const {
13991 switch (Subtarget.TargetType) {
4141 // To avoid having target depend on the asmprinter stuff libraries, asmprinter
4242 // set this functions to ctor pointer at startup time if they are linked in.
4343 typedef FunctionPass *(*AsmPrinterCtorFn)(formatted_raw_ostream &o,
44 ARMBaseTargetMachine &tm,
44 TargetMachine &tm,
4545 bool verbose);
4646 static AsmPrinterCtorFn AsmPrinterCtor;
4747
4848 public:
49 ARMBaseTargetMachine(const Module &M, const std::string &FS, bool isThumb);
49 ARMBaseTargetMachine(const Target &T, const Module &M, const std::string &FS,
50 bool isThumb);
5051
5152 virtual const ARMFrameInfo *getFrameInfo() const { return &FrameInfo; }
5253 virtual ARMJITInfo *getJITInfo() { return &JITInfo; }
5859 static void registerAsmPrinter(AsmPrinterCtorFn F) {
5960 AsmPrinterCtor = F;
6061 }
61
62 static unsigned getModuleMatchQuality(const Module &M);
63 static unsigned getJITMatchQuality();
6462
6563 virtual const TargetAsmInfo *createTargetAsmInfo() const;
6664
9896 const TargetData DataLayout; // Calculates type size & alignment
9997 ARMTargetLowering TLInfo;
10098 public:
101 ARMTargetMachine(const Module &M, const std::string &FS);
99 ARMTargetMachine(const Target &T, const Module &M, const std::string &FS);
102100
103101 virtual const ARMRegisterInfo *getRegisterInfo() const {
104102 return &InstrInfo.getRegisterInfo();
124122 const TargetData DataLayout; // Calculates type size & alignment
125123 ARMTargetLowering TLInfo;
126124 public:
127 ThumbTargetMachine(const Module &M, const std::string &FS);
125 ThumbTargetMachine(const Target &T, const Module &M, const std::string &FS);
128126
129127 /// returns either Thumb1RegisterInfo of Thumb2RegisterInfo
130128 virtual const ARMBaseRegisterInfo *getRegisterInfo() const {
3030 #include "llvm/Target/TargetData.h"
3131 #include "llvm/Target/TargetMachine.h"
3232 #include "llvm/Target/TargetOptions.h"
33 #include "llvm/Target/TargetRegistry.h"
3334 #include "llvm/ADT/Statistic.h"
3435 #include "llvm/ADT/StringExtras.h"
3536 #include "llvm/ADT/StringSet.h"
12861287 /// regardless of whether the function is in SSA form.
12871288 ///
12881289 FunctionPass *llvm::createARMCodePrinterPass(formatted_raw_ostream &o,
1289 ARMBaseTargetMachine &tm,
1290 TargetMachine &tm,
12901291 bool verbose) {
12911292 return new ARMAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
12921293 }
13001301 }
13011302
13021303 // Force static initialization.
1303 extern "C" void LLVMInitializeARMAsmPrinter() { }
1304 extern "C" void LLVMInitializeARMAsmPrinter() {
1305 extern Target TheARMTarget, TheThumbTarget;
1306 TargetRegistry::RegisterAsmPrinter(TheARMTarget, createARMCodePrinterPass);
1307 TargetRegistry::RegisterAsmPrinter(TheThumbTarget, createARMCodePrinterPass);
1308 }
2121 using namespace llvm;
2222
2323 // Register the targets
24 static RegisterTarget X("alpha", "Alpha [experimental]");
24 extern Target TheAlphaTarget;
25 static RegisterTarget X(TheAlphaTarget, "alpha",
26 "Alpha [experimental]");
2527
2628 // No assembler printer by default
2729 AlphaTargetMachine::AsmPrinterCtorFn AlphaTargetMachine::AsmPrinterCtor = 0;
3335 return new AlphaTargetAsmInfo(*this);
3436 }
3537
36 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
37 // We strongly match "alpha*".
38 std::string TT = M.getTargetTriple();
39 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
40 TT[3] == 'h' && TT[4] == 'a')
41 return 20;
42 // If the target triple is something non-alpha, we don't match.
43 if (!TT.empty()) return 0;
44
45 if (M.getEndianness() == Module::LittleEndian &&
46 M.getPointerSize() == Module::Pointer64)
47 return 10; // Weak match
48 else if (M.getEndianness() != Module::AnyEndianness ||
49 M.getPointerSize() != Module::AnyPointerSize)
50 return 0; // Match for some other target
51
52 return getJITMatchQuality()/2;
53 }
54
55 unsigned AlphaTargetMachine::getJITMatchQuality() {
56 #ifdef __alpha
57 return 10;
58 #else
59 return 0;
60 #endif
61 }
62
63 AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
64 : DataLayout("e-f128:128:128"),
38 AlphaTargetMachine::AlphaTargetMachine(const Target &T, const Module &M,
39 const std::string &FS)
40 : LLVMTargetMachine(T),
41 DataLayout("e-f128:128:128"),
6542 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
6643 JITInfo(*this),
6744 Subtarget(M, FS),
4444 static AsmPrinterCtorFn AsmPrinterCtor;
4545
4646 public:
47 AlphaTargetMachine(const Module &M, const std::string &FS);
47 AlphaTargetMachine(const Target &T, const Module &M, const std::string &FS);
4848
4949 virtual const AlphaInstrInfo *getInstrInfo() const { return &InstrInfo; }
5050 virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; }
5959 virtual AlphaJITInfo* getJITInfo() {
6060 return &JITInfo;
6161 }
62
63 static unsigned getJITMatchQuality();
64 static unsigned getModuleMatchQuality(const Module &M);
6562
6663 // Pass Pipeline Configuration
6764 virtual bool addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
2323 #include "llvm/CodeGen/DwarfWriter.h"
2424 #include "llvm/Target/TargetAsmInfo.h"
2525 #include "llvm/Target/TargetMachine.h"
26 #include "llvm/Target/TargetRegistry.h"
2627 #include "llvm/Support/Compiler.h"
2728 #include "llvm/Support/ErrorHandling.h"
2829 #include "llvm/Support/Mangler.h"
291292 return false;
292293 }
293294
294 // Force static initialization.
295 extern "C" void LLVMInitializeAlphaAsmPrinter() { }
296
297295 namespace {
298296 static struct Register {
299297 Register() {
301299 }
302300 } Registrator;
303301 }
302
303 // Force static initialization.
304 extern "C" void LLVMInitializeAlphaAsmPrinter() {
305 extern Target TheAlphaTarget;
306 TargetRegistry::RegisterAsmPrinter(TheAlphaTarget,
307 createAlphaCodePrinterPass);
308 }
2929 #include "llvm/CodeGen/Passes.h"
3030 #include "llvm/CodeGen/IntrinsicLowering.h"
3131 #include "llvm/Transforms/Scalar.h"
32 #include "llvm/Target/TargetMachineRegistry.h"
3332 #include "llvm/Target/TargetAsmInfo.h"
3433 #include "llvm/Target/TargetData.h"
34 #include "llvm/Target/TargetMachineRegistry.h"
35 #include "llvm/Target/TargetRegistry.h"
3536 #include "llvm/Support/CallSite.h"
3637 #include "llvm/Support/CFG.h"
3738 #include "llvm/Support/ErrorHandling.h"
5758 int CBackendTargetMachineModule = 0;
5859
5960 // Register the target.
60 static RegisterTarget X("c", "C backend");
61 extern Target TheCBackendTarget;
62 static RegisterTarget X(TheCBackendTarget, "c", "C backend");
6163
6264 // Force static initialization.
6365 extern "C" void LLVMInitializeCBackendTarget() { }
31853187
31863188 const char *const *table = 0;
31873189
3188 //Grab the translation table from TargetAsmInfo if it exists
3190 // Grab the translation table from TargetAsmInfo if it exists.
31893191 if (!TAsm) {
31903192 std::string E;
3191 const TargetMachineRegistry::entry* Match =
3192 TargetMachineRegistry::getClosestStaticTargetForModule(*TheModule, E);
3193 const Target *Match =
3194 TargetRegistry::getClosestStaticTargetForModule(*TheModule, E);
31933195 if (Match) {
3194 //Per platform Target Machines don't exist, so create it
3195 // this must be done only once
3196 const TargetMachine* TM = Match->CtorFn(*TheModule, "");
3196 // Per platform Target Machines don't exist, so create it;
3197 // this must be done only once.
3198 const TargetMachine* TM = Match->createTargetMachine(*TheModule, "");
31973199 TAsm = TM->getTargetAsmInfo();
31983200 }
31993201 }
32003202 if (TAsm)
32013203 table = TAsm->getAsmCBE();
32023204
3203 //Search the translation table if it exists
3205 // Search the translation table if it exists.
32043206 for (int i = 0; table && table[i]; i += 2)
32053207 if (c.Codes[0] == table[i])
32063208 return table[i+1];
32073209
3208 //default is identity
3210 // Default is identity.
32093211 return c.Codes[0];
32103212 }
32113213
2121 struct CTargetMachine : public TargetMachine {
2222 const TargetData DataLayout; // Calculates type size & alignment
2323
24 CTargetMachine(const Module &M, const std::string &FS)
25 : DataLayout(&M) {}
24 CTargetMachine(const Target &T, const Module &M, const std::string &FS)
25 : TargetMachine(T), DataLayout(&M) {}
2626
2727 virtual bool WantsWholeFile() const { return true; }
2828 virtual bool addPassesToEmitWholeFile(PassManager &PM,
2929 formatted_raw_ostream &Out,
3030 CodeGenFileType FileType,
3131 CodeGenOpt::Level OptLevel);
32
33 // This class always works, but must be requested explicitly on
34 // llc command line.
35 static unsigned getModuleMatchQuality(const Module &M) { return 0; }
3632
3733 virtual const TargetData *getTargetData() const { return &DataLayout; }
3834 };
3636 #include "llvm/Target/TargetRegisterInfo.h"
3737 #include "llvm/Target/TargetInstrInfo.h"
3838 #include "llvm/Target/TargetOptions.h"
39 #include "llvm/Target/TargetRegistry.h"
3940 #include "llvm/ADT/Statistic.h"
4041 #include "llvm/ADT/StringExtras.h"
4142 #include
288289 class VISIBILITY_HIDDEN LinuxAsmPrinter : public SPUAsmPrinter {
289290 DwarfWriter *DW;
290291 public:
291 explicit LinuxAsmPrinter(formatted_raw_ostream &O, SPUTargetMachine &TM,
292 explicit LinuxAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
292293 const TargetAsmInfo *T, bool V)
293294 : SPUAsmPrinter(O, TM, T, V), DW(0) {}
294295
598599 /// that the Linux SPU assembler can deal with.
599600 ///
600601 FunctionPass *llvm::createSPUAsmPrinterPass(formatted_raw_ostream &o,
601 SPUTargetMachine &tm,
602 TargetMachine &tm,
602603 bool verbose) {
603604 return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
604605 }
605
606 // Force static initialization.
607 extern "C" void LLVMInitializeCellSPUAsmPrinter() { }
608606
609607 namespace {
610608 static struct Register {
613611 }
614612 } Registrator;
615613 }
614
615 // Force static initialization.
616 extern "C" void LLVMInitializeCellSPUAsmPrinter() {
617 extern Target TheCellSPUTarget;
618 TargetRegistry::RegisterAsmPrinter(TheCellSPUTarget, createSPUAsmPrinterPass);
619 }
2424
2525 FunctionPass *createSPUISelDag(SPUTargetMachine &TM);
2626 FunctionPass *createSPUAsmPrinterPass(formatted_raw_ostream &o,
27 SPUTargetMachine &tm,
27 TargetMachine &tm,
2828 bool verbose);
2929
3030 /*--== Utility functions/predicates/etc used all over the place: --==*/
2222
2323 using namespace llvm;
2424
25 extern Target TheCellSPUTarget;
2526 namespace {
2627 // Register the targets
2728 RegisterTarget
28 CELLSPU("cellspu", "STI CBEA Cell SPU [experimental]");
29 CELLSPU(TheCellSPUTarget, "cellspu", "STI CBEA Cell SPU [experimental]");
2930 }
3031
3132 // No assembler printer by default
4647 return new SPULinuxTargetAsmInfo(*this);
4748 }
4849
49 unsigned
50 SPUTargetMachine::getModuleMatchQuality(const Module &M)
51 {
52 // We strongly match "spu-*" or "cellspu-*".
53 std::string TT = M.getTargetTriple();
54 if ((TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "spu")
55 || (TT.size() == 7 && std::string(TT.begin(), TT.begin()+7) == "cellspu")
56 || (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "spu-")
57 || (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "cellspu-"))
58 return 20;
59
60 return 0; // No match at all...
61 }
62
63 SPUTargetMachine::SPUTargetMachine(const Module &M, const std::string &FS)
64 : Subtarget(*this, M, FS),
50 SPUTargetMachine::SPUTargetMachine(const Target &T, const Module &M,
51 const std::string &FS)
52 : LLVMTargetMachine(T),
53 Subtarget(*this, M, FS),
6554 DataLayout(Subtarget.getTargetDataString()),
6655 InstrInfo(*this),
6756 FrameInfo(*this),
4141 // To avoid having target depend on the asmprinter stuff libraries, asmprinter
4242 // set this functions to ctor pointer at startup time if they are linked in.
4343 typedef FunctionPass *(*AsmPrinterCtorFn)(formatted_raw_ostream &o,
44 SPUTargetMachine &tm,
44 TargetMachine &tm,
4545 bool verbose);
4646 static AsmPrinterCtorFn AsmPrinterCtor;
4747
4848 public:
49 SPUTargetMachine(const Module &M, const std::string &FS);
49 SPUTargetMachine(const Target &T, const Module &M, const std::string &FS);
5050
5151 /// Return the subtarget implementation object
5252 virtual const SPUSubtarget *getSubtargetImpl() const {
6565 virtual TargetJITInfo *getJITInfo() {
6666 return NULL;
6767 }
68
69 //! Module match function
70 /*!
71 Module matching function called by TargetMachineRegistry().
72 */
73 static unsigned getModuleMatchQuality(const Module &M);
7468
7569 virtual SPUTargetLowering *getTargetLowering() const {
7670 return const_cast(&TLInfo);
8080 int CppBackendTargetMachineModule = 0;
8181
8282 // Register the target.
83 static RegisterTarget X("cpp", "C++ backend");
83 extern Target TheCppBackendTarget;
84 static RegisterTarget X(TheCppBackendTarget, "cpp", "C++ backend");
8485
8586 // Force static initialization.
8687 extern "C" void LLVMInitializeCppBackendTarget() { }
2323 struct CPPTargetMachine : public TargetMachine {
2424 const TargetData DataLayout; // Calculates type size & alignment
2525
26 CPPTargetMachine(const Module &M, const std::string &FS)
27 : DataLayout(&M) {}
26 CPPTargetMachine(const Target &T, const Module &M, const std::string &FS)
27 : TargetMachine(T), DataLayout(&M) {}
2828
2929 virtual bool WantsWholeFile() const { return true; }
3030 virtual bool addPassesToEmitWholeFile(PassManager &PM,
3131 formatted_raw_ostream &Out,
3232 CodeGenFileType FileType,
3333 CodeGenOpt::Level OptLevel);
34
35 // This class always works, but shouldn't be the default in most cases.
36 static unsigned getModuleMatchQuality(const Module &M) { return 1; }
3734
3835 virtual const TargetData *getTargetData() const { return &DataLayout; }
3936 };
2525 #include "llvm/CodeGen/DwarfWriter.h"
2626 #include "llvm/CodeGen/MachineFunctionPass.h"
2727 #include "llvm/Target/TargetAsmInfo.h"
28 #include "llvm/Target/TargetRegistry.h"
2829 #include "llvm/Support/ErrorHandling.h"
2930 #include "llvm/Support/FormattedStream.h"
3031 #include "llvm/Support/Mangler.h"
368369 /// the given target machine description.
369370 ///
370371 FunctionPass *llvm::createIA64CodePrinterPass(formatted_raw_ostream &o,
371 IA64TargetMachine &tm,
372 TargetMachine &tm,
372373 bool verbose) {
373374 return new IA64AsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
374375 }
383384
384385
385386 // Force static initialization.
386 extern "C" void LLVMInitializeIA64AsmPrinter() { }
387 extern "C" void LLVMInitializeIA64AsmPrinter() {
388 extern Target TheIA64Target;
389 TargetRegistry::RegisterAsmPrinter(TheIA64Target, createIA64CodePrinterPass);
390 }
3737 /// regardless of whether the function is in SSA form.
3838 ///
3939 FunctionPass *createIA64CodePrinterPass(formatted_raw_ostream &o,
40 IA64TargetMachine &tm,
40 TargetMachine &tm,
4141 bool verbose);
4242
4343 } // End llvm namespace
1919 using namespace llvm;
2020
2121 // Register the target
22 static RegisterTarget X("ia64",
22 extern Target TheIA64Target;
23 static RegisterTarget X(TheIA64Target, "ia64",
2324 "IA-64 (Itanium) [experimental]");
2425
2526 // No assembler printer by default
3233 return new IA64TargetAsmInfo(*this);
3334 }
3435
35 unsigned IA64TargetMachine::getModuleMatchQuality(const Module &M) {
36 // we match [iI][aA]*64
37 bool seenIA64=false;
38 std::string TT = M.getTargetTriple();
39
40 if (TT.size() >= 4) {
41 if( (TT[0]=='i' || TT[0]=='I') &&
42 (TT[1]=='a' || TT[1]=='A') ) {
43 for(unsigned int i=2; i<(TT.size()-1); i++)
44 if(TT[i]=='6' && TT[i+1]=='4')
45 seenIA64=true;
46 }
47
48 if (seenIA64)
49 return 20; // strong match
50 }
51 // If the target triple is something non-ia64, we don't match.
52 if (!TT.empty()) return 0;
53
54 #if defined(__ia64__) || defined(__IA64__)
55 return 5;
56 #else
57 return 0;
58 #endif
59 }
60
6136 /// IA64TargetMachine ctor - Create an LP64 architecture model
6237 ///
63 IA64TargetMachine::IA64TargetMachine(const Module &M, const std::string &FS)
64 : DataLayout("e-f80:128:128"),
38 IA64TargetMachine::IA64TargetMachine(const Target &T, const Module &M,
39 const std::string &FS)
40 : LLVMTargetMachine(T),
41 DataLayout("e-f80:128:128"),
6542 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
6643 TLInfo(*this) { // FIXME? check this stuff
6744 }
3636 // To avoid having target depend on the asmprinter stuff libraries, asmprinter
3737 // set this functions to ctor pointer at startup time if they are linked in.
3838 typedef FunctionPass *(*AsmPrinterCtorFn)(formatted_raw_ostream &o,
39 IA64TargetMachine &tm,
39 TargetMachine &tm,
4040 bool verbose);
4141 static AsmPrinterCtorFn AsmPrinterCtor;
4242
4343 public:
44 IA64TargetMachine(const Module &M, const std::string &FS);
44 IA64TargetMachine(const Target &T, const Module &M, const std::string &FS);
4545
4646 virtual const IA64InstrInfo *getInstrInfo() const { return &InstrInfo; }
4747 virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; }
5353 return &InstrInfo.getRegisterInfo();
5454 }
5555 virtual const TargetData *getTargetData() const { return &DataLayout; }
56
57 static unsigned getModuleMatchQuality(const Module &M);
5856
5957 // Pass Pipeline Configuration
6058 virtual bool addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
3030 struct VISIBILITY_HIDDEN MSILTarget : public TargetMachine {
3131 const TargetData DataLayout; // Calculates type size & alignment
3232
33 MSILTarget(const Module &M, const std::string &FS)
34 : DataLayout(&M) {}
33 MSILTarget(const Target &T, const Module &M, const std::string &FS)
34 : TargetMachine(T), DataLayout(&M) {}
3535
3636 virtual bool WantsWholeFile() const { return true; }
3737 virtual bool addPassesToEmitWholeFile(PassManager &PM,
5454 extern "C" int MSILTargetMachineModule;
5555 int MSILTargetMachineModule = 0;
5656
57 static RegisterTarget X("msil", "MSIL backend");
57 extern Target TheMSILTarget;
58 static RegisterTarget X(TheMSILTarget, "msil", "MSIL backend");
5859
5960 // Force static initialization.
6061 extern "C" void LLVMInitializeMSILTarget() { }
3131
3232
3333 // Register the targets
34 extern Target TheMSP430Target;
3435 static RegisterTarget
35 X("msp430", "MSP430 [experimental]");
36 X(TheMSP430Target, "msp430", "MSP430 [experimental]");
3637
3738 // Force static initialization.
3839 extern "C" void LLVMInitializeMSP430Target() { }
3940
40 MSP430TargetMachine::MSP430TargetMachine(const Module &M,
41 MSP430TargetMachine::MSP430TargetMachine(const Target &T,
42 const Module &M,
4143 const std::string &FS) :
44 LLVMTargetMachine(T),
4245 Subtarget(*this, M, FS),
4346 // FIXME: Check TargetData string.
4447 DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
6568 return false;
6669 }
6770
68 unsigned MSP430TargetMachine::getModuleMatchQuality(const Module &M) {
69 std::string TT = M.getTargetTriple();
70
71 // We strongly match msp430
72 if (TT.size() >= 6 && TT[0] == 'm' && TT[1] == 's' && TT[2] == 'p' &&
73 TT[3] == '4' && TT[4] == '3' && TT[5] == '0')
74 return 20;
75
76 return 0;
77 }
78
4040 virtual const TargetAsmInfo *createTargetAsmInfo() const;
4141
4242 public:
43 MSP430TargetMachine(const Module &M, const std::string &FS);
43 MSP430TargetMachine(const Target &T, const Module &M, const std::string &FS);
4444
4545 virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; }
4646 virtual const MSP430InstrInfo *getInstrInfo() const { return &InstrInfo; }
5959 virtual bool addAssemblyEmitter(PassManagerBase &PM,
6060 CodeGenOpt::Level OptLevel, bool Verbose,
6161 formatted_raw_ostream &Out);
62 static unsigned getModuleMatchQuality(const Module &M);
6362 }; // MSP430TargetMachine.
6463
6564 } // end namespace llvm
3232 #include "llvm/Target/TargetData.h"
3333 #include "llvm/Target/TargetMachine.h"
3434 #include "llvm/Target/TargetOptions.h"
35 #include "llvm/Target/TargetRegistry.h"
3536 #include "llvm/Support/ErrorHandling.h"
3637 #include "llvm/Support/Mangler.h"
3738 #include "llvm/ADT/Statistic.h"
5051 class VISIBILITY_HIDDEN MipsAsmPrinter : public AsmPrinter {
5152 const MipsSubtarget *Subtarget;
5253 public:
53 explicit MipsAsmPrinter(formatted_raw_ostream &O, MipsTargetMachine &TM,
54 explicit MipsAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
5455 const TargetAsmInfo *T, bool V)
5556 : AsmPrinter(O, TM, T, V) {
5657 Subtarget = &TM.getSubtarget();
9192 /// using the given target machine description. This should work
9293 /// regardless of whether the function is in SSA form.
9394 FunctionPass *llvm::createMipsCodePrinterPass(formatted_raw_ostream &o,
94 MipsTargetMachine &tm,
95 TargetMachine &tm,
9596 bool verbose) {
9697 return new MipsAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
9798 }
583584 }
584585
585586 // Force static initialization.
586 extern "C" void LLVMInitializeMipsAsmPrinter() { }
587 extern "C" void LLVMInitializeMipsAsmPrinter() {
588 extern Target TheMipsTarget;
589 TargetRegistry::RegisterAsmPrinter(TheMipsTarget, createMipsCodePrinterPass);
590
591 extern Target TheMipselTarget;
592 TargetRegistry::RegisterAsmPrinter(TheMipselTarget,
593 createMipsCodePrinterPass);
594 }
2525 FunctionPass *createMipsISelDag(MipsTargetMachine &TM);
2626 FunctionPass *createMipsDelaySlotFillerPass(MipsTargetMachine &TM);
2727 FunctionPass *createMipsCodePrinterPass(formatted_raw_ostream &OS,
28 MipsTargetMachine &TM,
28 TargetMachine &TM,
2929 bool Verbose);
3030 } // end namespace llvm;
3131
2727 int MipsTargetMachineModule = 0;
2828
2929 // Register the target.
30 static RegisterTarget X("mips", "Mips");
31 static RegisterTarget Y("mipsel", "Mipsel");
30 extern Target TheMipsTarget;
31 static RegisterTarget X(TheMipsTarget, "mips", "Mips");
32
33 extern Target TheMipselTarget;
34 static RegisterTarget Y(TheMipselTarget, "mipsel",
35 "Mipsel");
3236
3337 MipsTargetMachine::AsmPrinterCtorFn MipsTargetMachine::AsmPrinterCtor = 0;
3438
5054 // an easier handling.
5155 // Using CodeModel::Large enables different CALL behavior.
5256 MipsTargetMachine::
53 MipsTargetMachine(const Module &M, const std::string &FS, bool isLittle=false):
57 MipsTargetMachine(const Target &T, const Module &M, const std::string &FS,
58 bool isLittle=false):
59 LLVMTargetMachine(T),
5460 Subtarget(*this, M, FS, isLittle),
5561 DataLayout(isLittle ? std::string("e-p:32:32:32-i8:8:32-i16:16:32") :
5662 std::string("E-p:32:32:32-i8:8:32-i16:16:32")),
6975 }
7076
7177 MipselTargetMachine::
72 MipselTargetMachine(const Module &M, const std::string &FS) :
73 MipsTargetMachine(M, FS, true) {}
74
75 // return 0 and must specify -march to gen MIPS code.
76 unsigned MipsTargetMachine::
77 getModuleMatchQuality(const Module &M)
78 {
79 // We strongly match "mips*-*".
80 std::string TT = M.getTargetTriple();
81 if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
82 return 20;
83
84 if (TT.size() >= 13 && std::string(TT.begin(),
85 TT.begin()+13) == "mipsallegrex-")
86 return 20;
87
88 return 0;
89 }
90
91 // return 0 and must specify -march to gen MIPSEL code.
92 unsigned MipselTargetMachine::
93 getModuleMatchQuality(const Module &M)
94 {
95 // We strongly match "mips*el-*".
96 std::string TT = M.getTargetTriple();
97 if (TT.size() >= 7 && std::string(TT.begin(), TT.begin()+7) == "mipsel-")
98 return 20;
99
100 if (TT.size() >= 15 && std::string(TT.begin(),
101 TT.begin()+15) == "mipsallegrexel-")
102 return 20;
103
104 if (TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "psp")
105 return 20;
106
107 return 0;
108 }
78 MipselTargetMachine(const Target &T, const Module &M, const std::string &FS) :
79 MipsTargetMachine(T, M, FS, true) {}
10980
11081 // Install an instruction selector pass using
11182 // the ISelDag to gen Mips code.
3737 // asmprinter set this functions to ctor pointer at startup time if they are
3838 // linked in.
3939 typedef FunctionPass *(*AsmPrinterCtorFn)(formatted_raw_ostream &o,
40 MipsTargetMachine &tm,
40 TargetMachine &tm,
4141 bool verbose);
4242 static AsmPrinterCtorFn AsmPrinterCtor;
4343
4444 public:
45 MipsTargetMachine(const Module &M, const std::string &FS, bool isLittle);
45 MipsTargetMachine(const Target &T, const Module &M, const std::string &FS,
46 bool isLittle);
4647
4748 static void registerAsmPrinter(AsmPrinterCtorFn F) {
4849 AsmPrinterCtor = F;
6566 return const_cast(&TLInfo);
6667 }
6768
68 static unsigned getModuleMatchQuality(const Module &M);
69
7069 // Pass Pipeline Configuration
7170 virtual bool addInstSelector(PassManagerBase &PM,
7271 CodeGenOpt::Level OptLevel);
8180 ///
8281 class MipselTargetMachine : public MipsTargetMachine {
8382 public:
84 MipselTargetMachine(const Module &M, const std::string &FS);
83 MipselTargetMachine(const Target &T, const Module &M, const std::string &FS);
8584
8685 static unsigned getModuleMatchQuality(const Module &M);
8786 };
3131
3232
3333 // Register the targets
34 extern Target ThePIC16Target;
3435 static RegisterTarget
35 X("pic16", "PIC16 14-bit [experimental].");
36 X(ThePIC16Target, "pic16", "PIC16 14-bit [experimental].");
37
38 extern Target TheCooperTarget;
3639 static RegisterTarget
37 Y("cooper", "PIC16 Cooper [experimental].");
40 Y(TheCooperTarget, "cooper", "PIC16 Cooper [experimental].");
3841
3942 // Force static initialization.
4043 extern "C" void LLVMInitializePIC16Target() { }
4144
4245 // PIC16TargetMachine - Traditional PIC16 Machine.
43 PIC16TargetMachine::PIC16TargetMachine(const Module &M, const std::string &FS,
44 bool Cooper)
45 : Subtarget(M, FS, Cooper),
46 PIC16TargetMachine::PIC16TargetMachine(const Target &T, const Module &M,
47 const std::string &FS, bool Cooper)
48 : LLVMTargetMachine(T),
49 Subtarget(M, FS, Cooper),
4650 DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
4751 InstrInfo(*this), TLInfo(*this),
4852 FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0) { }
4953
5054 // CooperTargetMachine - Uses the same PIC16TargetMachine, but makes IsCooper
5155 // as true.
52 CooperTargetMachine::CooperTargetMachine(const Module &M, const std::string &FS)
53 : PIC16TargetMachine(M, FS, true) {}
56 CooperTargetMachine::CooperTargetMachine(const Target &T, const Module &M,
57 const std::string &FS)
58 : PIC16TargetMachine(T, M, FS, true) {}
5459
5560
5661 const TargetAsmInfo *PIC16TargetMachine::createTargetAsmInfo() const {
4040 virtual const TargetAsmInfo *createTargetAsmInfo() const;
4141
4242 public:
43 PIC16TargetMachine(const Module &M, const std::string &FS,
43 PIC16TargetMachine(const Target &T, const Module &M, const std::string &FS,
4444 bool Cooper = false);
4545
4646 virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; }
6767 /// CooperTargetMachine
6868 class CooperTargetMachine : public PIC16TargetMachine {
6969 public:
70 CooperTargetMachine(const Module &M, const std::string &FS);
70 CooperTargetMachine(const Target &T, const Module &M, const std::string &FS);
7171 }; // CooperTargetMachine.
7272
7373 } // end namespace llvm
4242 #include "llvm/Target/TargetRegisterInfo.h"
4343 #include "llvm/Target/TargetInstrInfo.h"
4444 #include "llvm/Target/TargetOptions.h"
45 #include "llvm/Target/TargetRegistry.h"
4546 #include "llvm/ADT/Statistic.h"
4647 #include "llvm/ADT/StringExtras.h"
4748 #include "llvm/ADT/StringSet.h"
316317 /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
317318 class VISIBILITY_HIDDEN PPCLinuxAsmPrinter : public PPCAsmPrinter {
318319 public:
319 explicit PPCLinuxAsmPrinter(formatted_raw_ostream &O, PPCTargetMachine &TM,
320 explicit PPCLinuxAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
320321 const TargetAsmInfo *T, bool V)
321322 : PPCAsmPrinter(O, TM, T, V){}
322323
342343 class VISIBILITY_HIDDEN PPCDarwinAsmPrinter : public PPCAsmPrinter {
343344 formatted_raw_ostream &OS;
344345 public:
345 explicit PPCDarwinAsmPrinter(formatted_raw_ostream &O, PPCTargetMachine &TM,
346 explicit PPCDarwinAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
346347 const TargetAsmInfo *T, bool V)
347348 : PPCAsmPrinter(O, TM, T, V), OS(O) {}
348349
10791080 /// Darwin assembler can deal with.
10801081 ///
10811082 FunctionPass *llvm::createPPCAsmPrinterPass(formatted_raw_ostream &o,
1082 PPCTargetMachine &tm,
1083 TargetMachine &tm,
10831084 bool verbose) {
10841085 const PPCSubtarget *Subtarget = &tm.getSubtarget();
10851086
11021103 int PowerPCAsmPrinterForceLink = 0;
11031104
11041105 // Force static initialization.
1105 extern "C" void LLVMInitializePowerPCAsmPrinter() { }
1106 extern "C" void LLVMInitializePowerPCAsmPrinter() {
1107 extern Target ThePPC32Target;
1108 TargetRegistry::RegisterAsmPrinter(ThePPC32Target, createPPCAsmPrinterPass);
1109
1110 extern Target ThePPC64Target;
1111 TargetRegistry::RegisterAsmPrinter(ThePPC64Target, createPPCAsmPrinterPass);
1112 }
2929 FunctionPass *createPPCBranchSelectionPass();
3030 FunctionPass *createPPCISelDag(PPCTargetMachine &TM);
3131 FunctionPass *createPPCAsmPrinterPass(formatted_raw_ostream &OS,
32 PPCTargetMachine &TM,
32 TargetMachine &TM,
3333 bool Verbose);
3434 FunctionPass *createPPCCodeEmitterPass(PPCTargetMachine &TM,
3535 MachineCodeEmitter &MCE);
2929 int PowerPCTargetMachineModule = 0;
3030
3131 // Register the targets
32 extern Target ThePPC32Target;
3233 static RegisterTarget
33 X("ppc32", "PowerPC 32");
34 X(ThePPC32Target, "ppc32", "PowerPC 32");
35
36 extern Target ThePPC64Target;
3437 static RegisterTarget
35 Y("ppc64", "PowerPC 64");
38 Y(ThePPC64Target, "ppc64", "PowerPC 64");
3639
3740 // Force static initialization.
3841 extern "C" void LLVMInitializePowerPCTarget() { }
4750 return new PPCLinuxTargetAsmInfo(*this);
4851 }
4952
50 unsigned PPC32TargetMachine::getJITMatchQuality() {
51 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
52 if (sizeof(void*) == 4)
53 return 10;
54 #endif
55 return 0;
56 }
57 unsigned PPC64TargetMachine::getJITMatchQuality() {
58 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
59 if (sizeof(void*) == 8)
60 return 10;
61 #endif
62 return 0;
63 }
64
65 unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
66 // We strongly match "powerpc-*".
67 std::string TT = M.getTargetTriple();
68 if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
69 return 20;
70
71 // If the target triple is something non-powerpc, we don't match.
72 if (!TT.empty()) return 0;
73
74 if (M.getEndianness() == Module::BigEndian &&
75 M.getPointerSize() == Module::Pointer32)
76 return 10; // Weak match
77 else if (M.getEndianness() != Module::AnyEndianness ||
78 M.getPointerSize() != Module::AnyPointerSize)
79 return 0; // Match for some other target
80
81 return getJITMatchQuality()/2;
82 }
83
84 unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
85 // We strongly match "powerpc64-*".
86 std::string TT = M.getTargetTriple();
87 if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
88 return 20;
89
90 if (M.getEndianness() == Module::BigEndian &&
91 M.getPointerSize() == Module::Pointer64)
92 return 10; // Weak match
93 else if (M.getEndianness() != Module::AnyEndianness ||
94 M.getPointerSize() != Module::AnyPointerSize)
95 return 0; // Match for some other target
96
97 return getJITMatchQuality()/2;
98 }
99
100
101 PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS,
102 bool is64Bit)
103 : Subtarget(*this, M, FS, is64Bit),
53 PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
54 const std::string &FS, bool is64Bit)
55 : LLVMTargetMachine(T),
56 Subtarget(*this, M, FS, is64Bit),
10457 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
10558 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
10659 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
11770 /// groups, which typically degrades performance.
11871 bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
11972
120 PPC32TargetMachine::PPC32TargetMachine(const Module &M, const std::string &FS)
121 : PPCTargetMachine(M, FS, false) {
122 }
123
124
125 PPC64TargetMachine::PPC64TargetMachine(const Module &M, const std::string &FS)
126 : PPCTargetMachine(M, FS, true) {
73 PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
74 const std::string &FS)
75 : PPCTargetMachine(T, M, FS, false) {
76 }
77
78
79 PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
80 const std::string &FS)
81 : PPCTargetMachine(T, M, FS, true) {
12782 }
12883
12984
4444 // To avoid having target depend on the asmprinter stuff libraries, asmprinter
4545 // set this functions to ctor pointer at startup time if they are linked in.
4646 typedef FunctionPass *(*AsmPrinterCtorFn)(formatted_raw_ostream &o,
47 PPCTargetMachine &tm,
47 TargetMachine &m,
4848 bool verbose);
4949 static AsmPrinterCtorFn AsmPrinterCtor;
5050
5151 public:
52 PPCTargetMachine(const Module &M, const std::string &FS, bool is64Bit);
52 PPCTargetMachine(const Target &T, const Module &M, const std::string &FS,
53 bool is64Bit);
5354
5455 virtual const PPCInstrInfo *getInstrInfo() const { return &InstrInfo; }
5556 virtual const PPCFrameInfo *getFrameInfo() const { return &FrameInfo; }
102103 ///
103104 class PPC32TargetMachine : public PPCTargetMachine {
104105 public:
105 PPC32TargetMachine(const Module &M, const std::string &FS);
106
107 static unsigned getJITMatchQuality();
108 static unsigned getModuleMatchQuality(const Module &M);
106 PPC32TargetMachine(const Target &T, const Module &M, const std::string &FS);
109107 };
110108
111109 /// PPC64TargetMachine - PowerPC 64-bit target machine.
112110 ///
113111 class PPC64TargetMachine : public PPCTargetMachine {
114112 public:
115 PPC64TargetMachine(const Module &M, const std::string &FS);
116
117 static unsigned getJITMatchQuality();
118 static unsigned getModuleMatchQuality(const Module &M);
113 PPC64TargetMachine(const Target &T, const Module &M, const std::string &FS);
119114 };
120115
121116 } // end namespace llvm
2525 #include "llvm/CodeGen/MachineConstantPool.h"
2626 #include "llvm/CodeGen/MachineInstr.h"
2727 #include "llvm/Target/TargetAsmInfo.h"
28 #include "llvm/Target/TargetRegistry.h"
2829 #include "llvm/Support/ErrorHandling.h"
2930 #include "llvm/Support/FormattedStream.h"
3031 #include "llvm/Support/Mangler.h"
358359 }
359360
360361 // Force static initialization.
361 extern "C" void LLVMInitializeSparcAsmPrinter() { }
362 extern "C" void LLVMInitializeSparcAsmPrinter() {
363 extern Target TheSparcTarget;
364 TargetRegistry::RegisterAsmPrinter(TheSparcTarget,
365 createSparcCodePrinterPass);
366 }
1818 using namespace llvm;
1919
2020 // Register the target.
21 static RegisterTarget X("sparc", "SPARC");
21 extern Target TheSparcTarget;
22 static RegisterTarget X(TheSparcTarget, "sparc", "SPARC");
2223
2324 // No assembler printer by default
2425 SparcTargetMachine::AsmPrinterCtorFn SparcTargetMachine::AsmPrinterCtor = 0;
3435
3536 /// SparcTargetMachine ctor - Create an ILP32 architecture model
3637 ///
37 SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
38 : DataLayout("E-p:32:32-f128:128:128"),
38 SparcTargetMachine::SparcTargetMachine(const Target &T, const Module &M,
39 const std::string &FS)
40 : LLVMTargetMachine(T),
41 DataLayout("E-p:32:32-f128:128:128"),
3942 Subtarget(M, FS), TLInfo(*this), InstrInfo(Subtarget),
4043 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
41 }
42
43 unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
44 std::string TT = M.getTargetTriple();
45 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
46 return 20;
47
48 // If the target triple is something non-sparc, we don't match.
49 if (!TT.empty()) return 0;
50
51 if (M.getEndianness() == Module::BigEndian &&
52 M.getPointerSize() == Module::Pointer32)
53 #ifdef __sparc__
54 return 20; // BE/32 ==> Prefer sparc on sparc
55 #else
56 return 5; // BE/32 ==> Prefer ppc elsewhere
57 #endif
58 else if (M.getEndianness() != Module::AnyEndianness ||
59 M.getPointerSize() != Module::AnyPointerSize)
60 return 0; // Match for some other target
61
62 #if defined(__sparc__)
63 return 10;
64 #else
65 return 0;
66 #endif
6744 }
6845
6946 bool SparcTargetMachine::addInstSelector(PassManagerBase &PM,
4242 static AsmPrinterCtorFn AsmPrinterCtor;
4343
4444 public:
45 SparcTargetMachine(const Module &M, const std::string &FS);
45 SparcTargetMachine(const Target &T, const Module &M, const std::string &FS);
4646
4747 virtual const SparcInstrInfo *getInstrInfo() const { return &InstrInfo; }
4848 virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; }
5454 return const_cast(&TLInfo);
5555 }
5656 virtual const TargetData *getTargetData() const { return &DataLayout; }
57 static unsigned getModuleMatchQuality(const Module &M);
5857
5958 // Pass Pipeline Configuration
6059 virtual bool addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
175175 // TargetMachine Class
176176 //
177177
178 TargetMachine::TargetMachine()
179 : AsmInfo(0) {
178 TargetMachine::TargetMachine(const Target &T)
179 : TheTarget(T), AsmInfo(0) {
180180 // Typically it will be subtargets that will adjust FloatABIType from Default
181181 // to Soft or Hard.
182182 if (UseSoftFloat)
+0
-78
lib/Target/TargetMachineRegistry.cpp less more
None //===-- TargetMachineRegistry.cpp - Target Auto Registration Impl ---------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file exposes the RegisterTarget class, which TargetMachine
10 // implementations should use to register themselves with the system. This file
11 // also exposes the TargetMachineRegistry class, which allows tools to inspect
12 // all of registered targets.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "llvm/Target/TargetMachineRegistry.h"
17 #include
18 using namespace llvm;
19
20 /// getClosestStaticTargetForModule - Given an LLVM module, pick the best target
21 /// that is compatible with the module. If no close target can be found, this
22 /// returns null and sets the Error string to a reason.
23 const TargetMachineRegistry::entry *
24 TargetMachineRegistry::getClosestStaticTargetForModule(const Module &M,
25 std::string &Error) {
26 std::vector > UsableTargets;
27 for (Registry::iterator I = begin(), E = end(); I != E; ++I)
28 if (unsigned Qual = I->ModuleMatchQualityFn(M))
29 UsableTargets.push_back(std::make_pair(Qual, &*I));
30
31 if (UsableTargets.empty()) {
32 Error = "No available targets are compatible with this module";
33 return 0;
34 } else if (UsableTargets.size() == 1)
35 return UsableTargets.back().second;
36
37 // Otherwise, take the best target, but make sure we don't have two equally
38 // good best targets.
39 std::sort(UsableTargets.begin(), UsableTargets.end());
40 if (UsableTargets.back().first ==UsableTargets[UsableTargets.size()-2].first){
41 Error = "Cannot choose between targets \"" +
42 std::string(UsableTargets.back().second->Name) + "\" and \"" +
43 std::string(UsableTargets[UsableTargets.size()-2].second->Name) + "\"";
44 return 0;
45 }
46 return UsableTargets.back().second;
47 }
48
49 /// getClosestTargetForJIT - Pick the best target that is compatible with
50 /// the current host. If no close target can be found, this returns null
51 /// and sets the Error string to a reason.
52 const TargetMachineRegistry::entry *
53 TargetMachineRegistry::getClosestTargetForJIT(std::string &Error) {
54 std::vector > UsableTargets;
55 for (Registry::iterator I = begin(), E = end(); I != E; ++I)
56 if (unsigned Qual = I->JITMatchQualityFn())
57 UsableTargets.push_back(std::make_pair(Qual, &*I));
58
59 if (UsableTargets.empty()) {
60 Error = "No JIT is available for this host";
61 return 0;
62 } else if (UsableTargets.size() == 1)
63 return UsableTargets.back().second;
64
65 // Otherwise, take the best target. If there is a tie, just pick one.
66 unsigned MaxQual = UsableTargets.front().first;
67 const entry *MaxQualTarget = UsableTargets.front().second;
68
69 for (unsigned i = 1, e = UsableTargets.size(); i != e; ++i)
70 if (UsableTargets[i].first > MaxQual) {
71 MaxQual = UsableTargets[i].first;
72 MaxQualTarget = UsableTargets[i].second;
73 }
74
75 return MaxQualTarget;
76 }
77
3636 MCContext *Context;
3737 MCStreamer *Streamer;
3838 public:
39 explicit X86ATTAsmPrinter(formatted_raw_ostream &O, X86TargetMachine &TM,
39 explicit X86ATTAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
4040 const TargetAsmInfo *T, bool V)
4141 : AsmPrinter(O, TM, T, V) {
4242 Subtarget = &TM.getSubtarget();
1616 #include "X86ATTAsmPrinter.h"
1717 #include "X86IntelAsmPrinter.h"
1818 #include "X86Subtarget.h"
19 #include "llvm/Target/TargetRegistry.h"
1920 using namespace llvm;
2021
2122 /// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
2324 /// machine description.
2425 ///
2526 FunctionPass *llvm::createX86CodePrinterPass(formatted_raw_ostream &o,
26 X86TargetMachine &tm,
27 TargetMachine &tm,
2728 bool verbose) {
2829 const X86Subtarget *Subtarget = &tm.getSubtarget();
2930
4445 int X86AsmPrinterForceLink = 0;
4546
4647 // Force static initialization.
47 extern "C" void LLVMInitializeX86AsmPrinter() { }
48 extern "C" void LLVMInitializeX86AsmPrinter() {
49 extern Target TheX86_32Target;
50 TargetRegistry::RegisterAsmPrinter(TheX86_32Target, createX86CodePrinterPass);
51
52 extern Target TheX86_64Target;
53 TargetRegistry::RegisterAsmPrinter(TheX86_64Target, createX86CodePrinterPass);
54 }
2424 namespace llvm {
2525
2626 struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter {
27 explicit X86IntelAsmPrinter(formatted_raw_ostream &O, X86TargetMachine &TM,
27 explicit X86IntelAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
2828 const TargetAsmInfo *T, bool V)
2929 : AsmPrinter(O, TM, T, V) {}
3030
4646 /// using the given target machine description.
4747 ///
4848 FunctionPass *createX86CodePrinterPass(formatted_raw_ostream &o,
49 X86TargetMachine &tm,
49 TargetMachine &tm,
5050 bool Verbose);
5151
5252 /// createX86CodeEmitterPass - Return a pass that emits the collected X86 code
3030 int X86TargetMachineModule = 0;
3131
3232 // Register the target.
33 extern Target TheX86_32Target;
3334 static RegisterTarget
34 X("x86", "32-bit X86: Pentium-Pro and above");
35 X(TheX86_32Target, "x86", "32-bit X86: Pentium-Pro and above");
36
37 extern Target TheX86_64Target;
3538 static RegisterTarget
36 Y("x86-64", "64-bit X86: EM64T and AMD64");
39 Y(TheX86_64Target, "x86-64", "64-bit X86: EM64T and AMD64");
3740
3841 // Force static initialization.
39 extern "C" void LLVMInitializeX86Target() { }
42 extern "C" void LLVMInitializeX86Target() {
43
44 }
4045
4146 // No assembler printer by default
4247 X86TargetMachine::AsmPrinterCtorFn X86TargetMachine::AsmPrinterCtor = 0;
6065 }
6166 }
6267
63 unsigned X86_32TargetMachine::getJITMatchQuality() {
64 #if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
65 return 10;
66 #endif
67 return 0;
68 }
69
70 unsigned X86_64TargetMachine::getJITMatchQuality() {
71 #if defined(__x86_64__) || defined(_M_AMD64)
72 return 10;
73 #endif
74 return 0;
75 }
76
77 unsigned X86_32TargetMachine::getModuleMatchQuality(const Module &M) {
78 // We strongly match "i[3-9]86-*".
79 std::string TT = M.getTargetTriple();
80 if (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
81 TT[4] == '-' && TT[1] - '3' < 6)
82 return 20;
83 // If the target triple is something non-X86, we don't match.
84 if (!TT.empty()) return 0;
85
86 if (M.getEndianness() == Module::LittleEndian &&
87 M.getPointerSize() == Module::Pointer32)
88 return 10; // Weak match
89 else if (M.getEndianness() != Module::AnyEndianness ||
90 M.getPointerSize() != Module::AnyPointerSize)
91 return 0; // Match for some other target
92
93 return getJITMatchQuality()/2;
94 }
95
96 unsigned X86_64TargetMachine::getModuleMatchQuality(const Module &M) {
97 // We strongly match "x86_64-*".
98 std::string TT = M.getTargetTriple();
99 if (TT.size() >= 7 && TT[0] == 'x' && TT[1] == '8' && TT[2] == '6' &&
100 TT[3] == '_' && TT[4] == '6' && TT[5] == '4' && TT[6] == '-')
101 return 20;
102
103 // We strongly match "amd64-*".
104 if (TT.size() >= 6 && TT[0] == 'a' && TT[1] == 'm' && TT[2] == 'd' &&
105 TT[3] == '6' && TT[4] == '4' && TT[5] == '-')
106 return 20;
107
108 // If the target triple is something non-X86-64, we don't match.
109 if (!TT.empty()) return 0;
110
111 if (M.getEndianness() == Module::LittleEndian &&
112 M.getPointerSize() == Module::Pointer64)
113 return 10; // Weak match
114 else if (M.getEndianness() != Module::AnyEndianness ||
115 M.getPointerSize() != Module::AnyPointerSize)
116 return 0; // Match for some other target
117
118 return getJITMatchQuality()/2;
119 }
120
121 X86_32TargetMachine::X86_32TargetMachine(const Module &M, const std::string &FS)
122 : X86TargetMachine(M, FS, false) {
123 }
124
125
126 X86_64TargetMachine::X86_64TargetMachine(const Module &M, const std::string &FS)
127 : X86TargetMachine(M, FS, true) {
68 X86_32TargetMachine::X86_32TargetMachine(const Target &T, const Module &M,
69 const std::string &FS)
70 : X86TargetMachine(T, M, FS, false) {
71 }
72
73
74 X86_64TargetMachine::X86_64TargetMachine(const Target &T, const Module &M,
75 const std::string &FS)
76 : X86TargetMachine(T, M, FS, true) {
12877 }
12978
13079 /// X86TargetMachine ctor - Create an X86 target.
13180 ///
132 X86TargetMachine::X86TargetMachine(const Module &M, const std::string &FS,
133 bool is64Bit)
134 : Subtarget(M, FS, is64Bit),
81 X86TargetMachine::X86TargetMachine(const Target &T, const Module &M,
82 const std::string &FS, bool is64Bit)
83 : LLVMTargetMachine(T),
84 Subtarget(M, FS, is64Bit),
13585 DataLayout(Subtarget.getDataLayout()),
13686 FrameInfo(TargetFrameInfo::StackGrowsDown,
13787 Subtarget.getStackAlignment(), Subtarget.is64Bit() ? -8 : -4),
4343 // To avoid having target depend on the asmprinter stuff libraries, asmprinter
4444 // set this functions to ctor pointer at startup time if they are linked in.
4545 typedef FunctionPass *(*AsmPrinterCtorFn)(formatted_raw_ostream &o,
46 X86TargetMachine &tm,
46 TargetMachine &tm,
4747 bool verbose);
4848 static AsmPrinterCtorFn AsmPrinterCtor;
4949
5050 public:
51 X86TargetMachine(const Module &M, const std::string &FS, bool is64Bit);
51 X86TargetMachine(const Target &T, const Module &M, const std::string &FS,
52 bool is64Bit);
5253
5354 virtual const X86InstrInfo *getInstrInfo() const { return &InstrInfo; }
5455 virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; }
6465 virtual const X86ELFWriterInfo *getELFWriterInfo() const {
6566 return Subtarget.isTargetELF() ? &ELFWriterInfo : 0;
6667 }
67
68 static unsigned getModuleMatchQuality(const Module &M);
69 static unsigned getJITMatchQuality();
7068
7169 static void registerAsmPrinter(AsmPrinterCtorFn F) {
7270 AsmPrinterCtor = F;
10098 ///
10199 class X86_32TargetMachine : public X86TargetMachine {
102100 public:
103 X86_32TargetMachine(const Module &M, const std::string &FS);
101 X86_32TargetMachine(const Target &T, const Module &M, const std::string &FS);
104102
105103 static unsigned getJITMatchQuality();
106104 static unsigned getModuleMatchQuality(const Module &M);
110108 ///
111109 class X86_64TargetMachine : public X86TargetMachine {
112110 public:
113 X86_64TargetMachine(const Module &M, const std::string &FS);
111 X86_64TargetMachine(const Target &T, const Module &M, const std::string &FS);
114112
115113 static unsigned getJITMatchQuality();
116114 static unsigned getModuleMatchQuality(const Module &M);
2525 extern "C" int XCoreTargetMachineModule;
2626 int XCoreTargetMachineModule = 0;
2727
28 extern Target TheXCoreTarget;
2829 namespace {
2930 // Register the target.
30 RegisterTarget X("xcore", "XCore");
31 RegisterTarget X(TheXCoreTarget, "xcore", "XCore");
3132 }
3233
3334 // Force static initialization.
3940
4041 /// XCoreTargetMachine ctor - Create an ILP32 architecture model
4142 ///
42 XCoreTargetMachine::XCoreTargetMachine(const Module &M, const std::string &FS)
43 : Subtarget(*this, M, FS),
43 XCoreTargetMachine::XCoreTargetMachine(const Target &T, const Module &M,
44 const std::string &FS)
45 : LLVMTargetMachine(T),
46 Subtarget(*this, M, FS),
4447 DataLayout("e-p:32:32:32-a0:0:32-f32:32:32-f64:32:32-i1:8:32-i8:8:32-"
4548 "i16:16:32-i32:32:32-i64:32:32"),
4649 InstrInfo(),
4750 FrameInfo(*this),
4851 TLInfo(*this) {
49 }
50
51 unsigned XCoreTargetMachine::getModuleMatchQuality(const Module &M) {
52 std::string TT = M.getTargetTriple();
53 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "xcore-")
54 return 20;
55
56 // Otherwise we don't match.
57 return 0;
5852 }
5953
6054 bool XCoreTargetMachine::addInstSelector(PassManagerBase &PM,
3535 virtual const TargetAsmInfo *createTargetAsmInfo() const;
3636
3737 public:
38 XCoreTargetMachine(const Module &M, const std::string &FS);
38 XCoreTargetMachine(const Target &T, const Module &M, const std::string &FS);
3939
4040 virtual const XCoreInstrInfo *getInstrInfo() const { return &InstrInfo; }
4141 virtual const XCoreFrameInfo *getFrameInfo() const { return &FrameInfo; }
4848 return &InstrInfo.getRegisterInfo();
4949 }
5050 virtual const TargetData *getTargetData() const { return &DataLayout; }
51 static unsigned getModuleMatchQuality(const Module &M);
5251
5352 // Pass Pipeline Configuration
5453 virtual bool addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
125125 return outputFilename;
126126 }
127127
128 static formatted_raw_ostream *GetOutputStream(const char *ProgName) {
128 static formatted_raw_ostream *GetOutputStream(const char *TargetName,
129 const char *ProgName) {
129130 if (OutputFilename != "") {
130131 if (OutputFilename == "-")
131132 return &fouts();
160161 bool Binary = false;
161162 switch (FileType) {
162163 case TargetMachine::AssemblyFile:
163 if (MArch->Name[0] == 'c') {
164 if (MArch->Name[1] == 0)
164 if (TargetName[0] == 'c') {
165 if (TargetName[1] == 0)
165166 OutputFilename += ".cbe.c";
166 else if (MArch->Name[1] == 'p' && MArch->Name[2] == 'p')
167 else if (TargetName[1] == 'p' && TargetName[2] == 'p')
167168 OutputFilename += ".cpp";
168169 else
169170 OutputFilename += ".s";
234235
235236 // Allocate target machine. First, check whether the user has
236237 // explicitly specified an architecture to compile for.
237 if (MArch == 0) {
238 const Target *TheTarget;
239 if (MArch) {
240 TheTarget = &MArch->TheTarget;
241 } else {
238242 std::string Err;
239 MArch = TargetMachineRegistry::getClosestStaticTargetForModule(mod, Err);
240 if (MArch == 0) {
243 TheTarget = TargetRegistry::getClosestStaticTargetForModule(mod, Err);
244 if (TheTarget == 0) {
241245 errs() << argv[0] << ": error auto-selecting target for module '"
242246 << Err << "'. Please use the -march option to explicitly "
243247 << "pick a target.\n";
255259 FeaturesStr = Features.getString();
256260 }
257261
258 std::auto_ptr target(MArch->CtorFn(mod, FeaturesStr));
262 std::auto_ptr
263 target(TheTarget->createTargetMachine(mod, FeaturesStr));
259264 assert(target.get() && "Could not allocate target machine!");
260265 TargetMachine &Target = *target.get();
261266
262267 // Figure out where we are going to send the output...
263 formatted_raw_ostream *Out = GetOutputStream(argv[0]);
268 formatted_raw_ostream *Out = GetOutputStream(TheTarget->getName(), argv[0]);
264269 if (Out == 0) return 1;
265270
266271 CodeGenOpt::Level OLvl = CodeGenOpt::Default;
328328 if ( _target == NULL ) {
329329 // create target machine from info for merged modules
330330 Module* mergedModule = _linker.getModule();
331 const TargetMachineRegistry::entry* march =
332 TargetMachineRegistry::getClosestStaticTargetForModule(
333 *mergedModule, errMsg);
331 const Target *march =
332 TargetRegistry::getClosestStaticTargetForModule(*mergedModule,
333 errMsg);
334334 if ( march == NULL )
335335 return true;
336336
351351 // construct LTModule, hand over ownership of module and target
352352 std::string FeatureStr =
353353 getFeatureString(_linker.getModule()->getTargetTriple().c_str());
354 _target = march->CtorFn(*mergedModule, FeatureStr.c_str());
354 _target = march->createTargetMachine(*mergedModule, FeatureStr.c_str());
355355 }
356356 return false;
357357 }
146146 if ( !m )
147147 return NULL;
148148 // find machine architecture for this module
149 const TargetMachineRegistry::entry* march =
150 TargetMachineRegistry::getClosestStaticTargetForModule(*m, errMsg);
149 const Target* march =
150 TargetRegistry::getClosestStaticTargetForModule(*m, errMsg);
151151
152152 if ( march == NULL )
153153 return NULL;
154154
155155 // construct LTModule, hand over ownership of module and target
156156 std::string FeatureStr = getFeatureString(m->getTargetTriple().c_str());
157 TargetMachine* target = march->CtorFn(*m, FeatureStr);
157 TargetMachine* target = march->createTargetMachine(*m, FeatureStr);
158158 return new LTOModule(m.take(), target);
159159 }
160160