1 //===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #include "ARMTargetMachine.h"
14 #include "ARMTargetAsmInfo.h"
15 #include "ARMFrameInfo.h"
17 #include "llvm/Module.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/Target/TargetMachineRegistry.h"
23 #include "llvm/Target/TargetOptions.h"
26 static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
27 cl::desc("Disable load store optimization pass"));
28 static cl::opt<bool> DisableIfConversion("disable-arm-if-conversion",cl::Hidden,
29 cl::desc("Disable if-conversion pass"));
31 /// ARMTargetMachineModule - Note that this is used on hosts that cannot link
32 /// in a library unless there are references into the library. In particular,
33 /// it seems that it is not possible to get things to work on Win32 without
34 /// this. Though it is unused, do not remove it.
35 extern "C" int ARMTargetMachineModule;
36 int ARMTargetMachineModule = 0;
38 // Register the target.
39 static RegisterTarget<ARMTargetMachine> X("arm", "ARM");
40 static RegisterTarget<ThumbTargetMachine> Y("thumb", "Thumb");
42 // No assembler printer by default
43 ARMTargetMachine::AsmPrinterCtorFn ARMTargetMachine::AsmPrinterCtor = 0;
45 /// ThumbTargetMachine - Create an Thumb architecture model.
47 unsigned ThumbTargetMachine::getJITMatchQuality() {
48 #if defined(__thumb__)
54 unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
55 std::string TT = M.getTargetTriple();
56 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
59 // If the target triple is something non-thumb, we don't match.
60 if (!TT.empty()) return 0;
62 if (M.getEndianness() == Module::LittleEndian &&
63 M.getPointerSize() == Module::Pointer32)
64 return 10; // Weak match
65 else if (M.getEndianness() != Module::AnyEndianness ||
66 M.getPointerSize() != Module::AnyPointerSize)
67 return 0; // Match for some other target
69 return getJITMatchQuality()/2;
72 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
73 : ARMTargetMachine(M, FS, true) {
76 /// TargetMachine ctor - Create an ARM architecture model.
78 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
80 : Subtarget(M, FS, isThumb),
81 DataLayout(Subtarget.isAPCS_ABI() ?
84 std::string("e-p:32:32-f64:32:32-i64:32:32-"
85 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
86 std::string("e-p:32:32-f64:32:32-i64:32:32")) :
89 std::string("e-p:32:32-f64:64:64-i64:64:64-"
90 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
91 std::string("e-p:32:32-f64:64:64-i64:64:64"))),
96 DefRelocModel = getRelocationModel();
99 unsigned ARMTargetMachine::getJITMatchQuality() {
106 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
107 std::string TT = M.getTargetTriple();
108 if (TT.size() >= 4 && // Match arm-foo-bar, as well as things like armv5blah-*
109 (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
111 // If the target triple is something non-arm, we don't match.
112 if (!TT.empty()) return 0;
114 if (M.getEndianness() == Module::LittleEndian &&
115 M.getPointerSize() == Module::Pointer32)
116 return 10; // Weak match
117 else if (M.getEndianness() != Module::AnyEndianness ||
118 M.getPointerSize() != Module::AnyPointerSize)
119 return 0; // Match for some other target
121 return getJITMatchQuality()/2;
125 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
126 switch (Subtarget.TargetType) {
127 case ARMSubtarget::isDarwin:
128 return new ARMDarwinTargetAsmInfo(*this);
129 case ARMSubtarget::isELF:
130 return new ARMELFTargetAsmInfo(*this);
132 return new ARMGenericTargetAsmInfo(*this);
137 // Pass Pipeline Configuration
138 bool ARMTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
139 PM.add(createARMISelDag(*this));
143 bool ARMTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
144 // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
145 if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
146 PM.add(createARMLoadStoreOptimizationPass());
148 if (!Fast && !DisableIfConversion && !Subtarget.isThumb())
149 PM.add(createIfConverterPass());
151 PM.add(createARMConstantIslandPass());
155 bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
157 // Output assembly language.
158 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
160 PM.add(AsmPrinterCtor(Out, *this));
166 bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
167 bool DumpAsm, MachineCodeEmitter &MCE) {
168 // FIXME: Move this to TargetJITInfo!
169 if (DefRelocModel == Reloc::Default)
170 setRelocationModel(Reloc::Static);
172 // Machine code emitter pass for ARM.
173 PM.add(createARMCodeEmitterPass(*this, MCE));
175 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
177 PM.add(AsmPrinterCtor(errs(), *this));
183 bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
184 bool DumpAsm, MachineCodeEmitter &MCE) {
185 // Machine code emitter pass for ARM.
186 PM.add(createARMCodeEmitterPass(*this, MCE));
188 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
190 PM.add(AsmPrinterCtor(errs(), *this));