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/CommandLine.h"
20 #include "llvm/Support/FormattedStream.h"
21 #include "llvm/Target/TargetOptions.h"
22 #include "llvm/Target/TargetRegistry.h"
26 EarlyITBlockFormation("thumb2-early-it-blocks", cl::Hidden,
27 cl::desc("Form IT blocks early before register allocation"),
31 EarlyIfConvert("arm-early-if-convert", cl::Hidden,
32 cl::desc("Run if-conversion before post-ra scheduling"),
35 static MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
37 switch (TheTriple.getOS()) {
39 return new ARMMCAsmInfoDarwin();
41 return new ARMELFMCAsmInfo();
46 extern "C" void LLVMInitializeARMTarget() {
47 // Register the target.
48 RegisterTargetMachine<ARMTargetMachine> X(TheARMTarget);
49 RegisterTargetMachine<ThumbTargetMachine> Y(TheThumbTarget);
51 // Register the target asm info.
52 RegisterAsmInfoFn A(TheARMTarget, createMCAsmInfo);
53 RegisterAsmInfoFn B(TheThumbTarget, createMCAsmInfo);
56 /// TargetMachine ctor - Create an ARM architecture model.
58 ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T,
59 const std::string &TT,
60 const std::string &FS,
62 : LLVMTargetMachine(T, TT),
63 Subtarget(TT, FS, isThumb),
66 InstrItins(Subtarget.getInstrItineraryData()) {
67 DefRelocModel = getRelocationModel();
70 ARMTargetMachine::ARMTargetMachine(const Target &T, const std::string &TT,
71 const std::string &FS)
72 : ARMBaseTargetMachine(T, TT, FS, false), InstrInfo(Subtarget),
73 DataLayout(Subtarget.isAPCS_ABI() ?
74 std::string("e-p:32:32-f64:32:32-i64:32:32-n32") :
75 std::string("e-p:32:32-f64:64:64-i64:64:64-n32")),
80 ThumbTargetMachine::ThumbTargetMachine(const Target &T, const std::string &TT,
81 const std::string &FS)
82 : ARMBaseTargetMachine(T, TT, FS, true),
83 InstrInfo(Subtarget.hasThumb2()
84 ? ((ARMBaseInstrInfo*)new Thumb2InstrInfo(Subtarget))
85 : ((ARMBaseInstrInfo*)new Thumb1InstrInfo(Subtarget))),
86 DataLayout(Subtarget.isAPCS_ABI() ?
87 std::string("e-p:32:32-f64:32:32-i64:32:32-"
88 "i16:16:32-i8:8:32-i1:8:32-a:0:32-n32") :
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-n32")),
97 // Pass Pipeline Configuration
98 bool ARMBaseTargetMachine::addInstSelector(PassManagerBase &PM,
99 CodeGenOpt::Level OptLevel) {
100 PM.add(createARMISelDag(*this, OptLevel));
104 bool ARMBaseTargetMachine::addPreRegAlloc(PassManagerBase &PM,
105 CodeGenOpt::Level OptLevel) {
106 if (Subtarget.hasNEON())
107 PM.add(createNEONPreAllocPass());
109 // FIXME: temporarily disabling load / store optimization pass for Thumb1.
110 if (OptLevel != CodeGenOpt::None && !Subtarget.isThumb1Only())
111 PM.add(createARMLoadStoreOptimizationPass(true));
113 if (OptLevel != CodeGenOpt::None && Subtarget.isThumb2() &&
114 EarlyITBlockFormation)
115 PM.add(createThumb2ITBlockPass(true));
119 bool ARMBaseTargetMachine::addPreSched2(PassManagerBase &PM,
120 CodeGenOpt::Level OptLevel) {
121 // FIXME: temporarily disabling load / store optimization pass for Thumb1.
122 if (OptLevel != CodeGenOpt::None) {
123 if (!Subtarget.isThumb1Only())
124 PM.add(createARMLoadStoreOptimizationPass());
125 if (Subtarget.hasNEON())
126 PM.add(createNEONMoveFixPass());
129 // Expand some pseudo instructions into multiple instructions to allow
130 // proper scheduling.
131 PM.add(createARMExpandPseudoPass());
133 if (EarlyIfConvert && OptLevel != CodeGenOpt::None) {
134 if (!Subtarget.isThumb1Only())
135 PM.add(createIfConverterPass());
136 if (Subtarget.isThumb2())
137 PM.add(createThumb2ITBlockPass());
143 bool ARMBaseTargetMachine::addPreEmitPass(PassManagerBase &PM,
144 CodeGenOpt::Level OptLevel) {
145 if (!EarlyIfConvert && OptLevel != CodeGenOpt::None) {
146 if (!Subtarget.isThumb1Only())
147 PM.add(createIfConverterPass());
150 if (Subtarget.isThumb2()) {
152 PM.add(createThumb2ITBlockPass());
153 PM.add(createThumb2SizeReductionPass());
156 PM.add(createARMConstantIslandPass());
160 bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM,
161 CodeGenOpt::Level OptLevel,
162 JITCodeEmitter &JCE) {
163 // FIXME: Move this to TargetJITInfo!
164 if (DefRelocModel == Reloc::Default)
165 setRelocationModel(Reloc::Static);
167 // Machine code emitter pass for ARM.
168 PM.add(createARMJITCodeEmitterPass(*this, JCE));