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 "ARMMCAsmInfo.h"
15 #include "ARMFrameInfo.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/Support/FormattedStream.h"
20 #include "llvm/Target/TargetOptions.h"
21 #include "llvm/Target/TargetRegistry.h"
24 static const MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
26 switch (TheTriple.getOS()) {
28 return new ARMMCAsmInfoDarwin();
30 return new ARMELFMCAsmInfo();
35 extern "C" void LLVMInitializeARMTarget() {
36 // Register the target.
37 RegisterTargetMachine<ARMTargetMachine> X(TheARMTarget);
38 RegisterTargetMachine<ThumbTargetMachine> Y(TheThumbTarget);
40 // Register the target asm info.
41 RegisterAsmInfoFn A(TheARMTarget, createMCAsmInfo);
42 RegisterAsmInfoFn B(TheThumbTarget, createMCAsmInfo);
45 /// TargetMachine ctor - Create an ARM architecture model.
47 ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T,
48 const std::string &TT,
49 const std::string &FS,
51 : LLVMTargetMachine(T, TT),
52 Subtarget(TT, FS, isThumb),
55 InstrItins(Subtarget.getInstrItineraryData()) {
56 DefRelocModel = getRelocationModel();
59 ARMTargetMachine::ARMTargetMachine(const Target &T, const std::string &TT,
60 const std::string &FS)
61 : ARMBaseTargetMachine(T, TT, FS, false), InstrInfo(Subtarget),
62 DataLayout(Subtarget.isAPCS_ABI() ?
63 std::string("e-p:32:32-f64:32:32-i64:32:32") :
64 std::string("e-p:32:32-f64:64:64-i64:64:64")),
68 ThumbTargetMachine::ThumbTargetMachine(const Target &T, const std::string &TT,
69 const std::string &FS)
70 : ARMBaseTargetMachine(T, TT, FS, true),
71 InstrInfo(Subtarget.hasThumb2()
72 ? ((ARMBaseInstrInfo*)new Thumb2InstrInfo(Subtarget))
73 : ((ARMBaseInstrInfo*)new Thumb1InstrInfo(Subtarget))),
74 DataLayout(Subtarget.isAPCS_ABI() ?
75 std::string("e-p:32:32-f64:32:32-i64:32:32-"
76 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
77 std::string("e-p:32:32-f64:64:64-i64:64:64-"
78 "i16:16:32-i8:8:32-i1:8:32-a:0:32")),
84 // Pass Pipeline Configuration
85 bool ARMBaseTargetMachine::addInstSelector(PassManagerBase &PM,
86 CodeGenOpt::Level OptLevel) {
87 PM.add(createARMISelDag(*this, OptLevel));
91 bool ARMBaseTargetMachine::addPreRegAlloc(PassManagerBase &PM,
92 CodeGenOpt::Level OptLevel) {
93 if (Subtarget.hasNEON())
94 PM.add(createNEONPreAllocPass());
96 // FIXME: temporarily disabling load / store optimization pass for Thumb1.
97 if (OptLevel != CodeGenOpt::None && !Subtarget.isThumb1Only())
98 PM.add(createARMLoadStoreOptimizationPass(true));
102 bool ARMBaseTargetMachine::addPreSched2(PassManagerBase &PM,
103 CodeGenOpt::Level OptLevel) {
104 // FIXME: temporarily disabling load / store optimization pass for Thumb1.
105 if (OptLevel != CodeGenOpt::None && !Subtarget.isThumb1Only())
106 PM.add(createARMLoadStoreOptimizationPass());
111 bool ARMBaseTargetMachine::addPreEmitPass(PassManagerBase &PM,
112 CodeGenOpt::Level OptLevel) {
113 // FIXME: temporarily disabling load / store optimization pass for Thumb1.
114 if (OptLevel != CodeGenOpt::None) {
115 if (!Subtarget.isThumb1Only())
116 PM.add(createIfConverterPass());
117 if (Subtarget.hasNEON())
118 PM.add(createNEONMoveFixPass());
121 if (Subtarget.isThumb2()) {
122 PM.add(createThumb2ITBlockPass());
123 PM.add(createThumb2SizeReductionPass());
126 PM.add(createARMConstantIslandPass());
130 bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM,
131 CodeGenOpt::Level OptLevel,
132 MachineCodeEmitter &MCE) {
133 // FIXME: Move this to TargetJITInfo!
134 if (DefRelocModel == Reloc::Default)
135 setRelocationModel(Reloc::Static);
137 // Machine code emitter pass for ARM.
138 PM.add(createARMCodeEmitterPass(*this, MCE));
142 bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM,
143 CodeGenOpt::Level OptLevel,
144 JITCodeEmitter &JCE) {
145 // FIXME: Move this to TargetJITInfo!
146 if (DefRelocModel == Reloc::Default)
147 setRelocationModel(Reloc::Static);
149 // Machine code emitter pass for ARM.
150 PM.add(createARMJITCodeEmitterPass(*this, JCE));
154 bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM,
155 CodeGenOpt::Level OptLevel,
156 ObjectCodeEmitter &OCE) {
157 // FIXME: Move this to TargetJITInfo!
158 if (DefRelocModel == Reloc::Default)
159 setRelocationModel(Reloc::Static);
161 // Machine code emitter pass for ARM.
162 PM.add(createARMObjectCodeEmitterPass(*this, OCE));
166 bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
167 CodeGenOpt::Level OptLevel,
168 MachineCodeEmitter &MCE) {
169 // Machine code emitter pass for ARM.
170 PM.add(createARMCodeEmitterPass(*this, MCE));
174 bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
175 CodeGenOpt::Level OptLevel,
176 JITCodeEmitter &JCE) {
177 // Machine code emitter pass for ARM.
178 PM.add(createARMJITCodeEmitterPass(*this, JCE));
182 bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
183 CodeGenOpt::Level OptLevel,
184 ObjectCodeEmitter &OCE) {
185 // Machine code emitter pass for ARM.
186 PM.add(createARMObjectCodeEmitterPass(*this, OCE));