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 // Match thumb-foo-bar, as well as things like thumbv5blah-*
58 (TT
.substr(0, 6) == "thumb-" || TT
.substr(0, 6) == "thumbv"))
61 // If the target triple is something non-thumb, we don't match.
62 if (!TT
.empty()) return 0;
64 if (M
.getEndianness() == Module::LittleEndian
&&
65 M
.getPointerSize() == Module::Pointer32
)
66 return 10; // Weak match
67 else if (M
.getEndianness() != Module::AnyEndianness
||
68 M
.getPointerSize() != Module::AnyPointerSize
)
69 return 0; // Match for some other target
71 return getJITMatchQuality()/2;
74 ThumbTargetMachine::ThumbTargetMachine(const Module
&M
, const std::string
&FS
)
75 : ARMTargetMachine(M
, FS
, true) {
78 /// TargetMachine ctor - Create an ARM architecture model.
80 ARMTargetMachine::ARMTargetMachine(const Module
&M
, const std::string
&FS
,
82 : Subtarget(M
, FS
, isThumb
),
83 DataLayout(Subtarget
.isAPCS_ABI() ?
86 std::string("e-p:32:32-f64:32:32-i64:32:32-"
87 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
88 std::string("e-p:32:32-f64:32:32-i64:32:32")) :
91 std::string("e-p:32:32-f64:64:64-i64:64:64-"
92 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
93 std::string("e-p:32:32-f64:64:64-i64:64:64"))),
98 DefRelocModel
= getRelocationModel();
101 unsigned ARMTargetMachine::getJITMatchQuality() {
108 unsigned ARMTargetMachine::getModuleMatchQuality(const Module
&M
) {
109 std::string TT
= M
.getTargetTriple();
110 // Match arm-foo-bar, as well as things like armv5blah-*
111 if (TT
.size() >= 4 &&
112 (TT
.substr(0, 4) == "arm-" || TT
.substr(0, 4) == "armv"))
114 // If the target triple is something non-arm, we don't match.
115 if (!TT
.empty()) return 0;
117 if (M
.getEndianness() == Module::LittleEndian
&&
118 M
.getPointerSize() == Module::Pointer32
)
119 return 10; // Weak match
120 else if (M
.getEndianness() != Module::AnyEndianness
||
121 M
.getPointerSize() != Module::AnyPointerSize
)
122 return 0; // Match for some other target
124 return getJITMatchQuality()/2;
128 const TargetAsmInfo
*ARMTargetMachine::createTargetAsmInfo() const {
129 switch (Subtarget
.TargetType
) {
130 case ARMSubtarget::isDarwin
:
131 return new ARMDarwinTargetAsmInfo(*this);
132 case ARMSubtarget::isELF
:
133 return new ARMELFTargetAsmInfo(*this);
135 return new ARMGenericTargetAsmInfo(*this);
140 // Pass Pipeline Configuration
141 bool ARMTargetMachine::addInstSelector(PassManagerBase
&PM
,
142 CodeGenOpt::Level OptLevel
) {
143 PM
.add(createARMISelDag(*this));
147 bool ARMTargetMachine::addPreEmitPass(PassManagerBase
&PM
,
148 CodeGenOpt::Level OptLevel
) {
149 // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
150 if (OptLevel
!= CodeGenOpt::None
&& !DisableLdStOpti
&& !Subtarget
.isThumb())
151 PM
.add(createARMLoadStoreOptimizationPass());
153 if (OptLevel
!= CodeGenOpt::None
&&
154 !DisableIfConversion
&& !Subtarget
.isThumb())
155 PM
.add(createIfConverterPass());
157 PM
.add(createARMConstantIslandPass());
161 bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase
&PM
,
162 CodeGenOpt::Level OptLevel
,
165 // Output assembly language.
166 assert(AsmPrinterCtor
&& "AsmPrinter was not linked in");
168 PM
.add(AsmPrinterCtor(Out
, *this, OptLevel
, Verbose
));
174 bool ARMTargetMachine::addCodeEmitter(PassManagerBase
&PM
,
175 CodeGenOpt::Level OptLevel
,
177 MachineCodeEmitter
&MCE
) {
178 // FIXME: Move this to TargetJITInfo!
179 if (DefRelocModel
== Reloc::Default
)
180 setRelocationModel(Reloc::Static
);
182 // Machine code emitter pass for ARM.
183 PM
.add(createARMCodeEmitterPass(*this, MCE
));
185 assert(AsmPrinterCtor
&& "AsmPrinter was not linked in");
187 PM
.add(AsmPrinterCtor(errs(), *this, OptLevel
, true));
193 bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase
&PM
,
194 CodeGenOpt::Level OptLevel
,
196 MachineCodeEmitter
&MCE
) {
197 // Machine code emitter pass for ARM.
198 PM
.add(createARMCodeEmitterPass(*this, MCE
));
200 assert(AsmPrinterCtor
&& "AsmPrinter was not linked in");
202 PM
.add(AsmPrinterCtor(errs(), *this, OptLevel
, true));