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 // Register the target.
32 static RegisterTarget<ARMTargetMachine> X("arm", "ARM");
33 static RegisterTarget<ThumbTargetMachine> Y("thumb", "Thumb");
35 // No assembler printer by default
36 ARMTargetMachine::AsmPrinterCtorFn ARMTargetMachine::AsmPrinterCtor = 0;
38 /// ThumbTargetMachine - Create an Thumb architecture model.
40 unsigned ThumbTargetMachine::getJITMatchQuality() {
41 #if defined(__thumb__)
47 unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
48 std::string TT = M.getTargetTriple();
49 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
52 // If the target triple is something non-thumb, we don't match.
53 if (!TT.empty()) return 0;
55 if (M.getEndianness() == Module::LittleEndian &&
56 M.getPointerSize() == Module::Pointer32)
57 return 10; // Weak match
58 else if (M.getEndianness() != Module::AnyEndianness ||
59 M.getPointerSize() != Module::AnyPointerSize)
60 return 0; // Match for some other target
62 return getJITMatchQuality()/2;
65 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
66 : ARMTargetMachine(M, FS, true) {
69 /// TargetMachine ctor - Create an ARM architecture model.
71 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
73 : Subtarget(M, FS, isThumb),
74 DataLayout(Subtarget.isAPCS_ABI() ?
77 std::string("e-p:32:32-f64:32:32-i64:32:32-"
78 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
79 std::string("e-p:32:32-f64:32:32-i64:32:32")) :
82 std::string("e-p:32:32-f64:64:64-i64:64:64-"
83 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
84 std::string("e-p:32:32-f64:64:64-i64:64:64"))),
89 DefRelocModel = getRelocationModel();
92 unsigned ARMTargetMachine::getJITMatchQuality() {
99 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
100 std::string TT = M.getTargetTriple();
101 if (TT.size() >= 4 && // Match arm-foo-bar, as well as things like armv5blah-*
102 (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
104 // If the target triple is something non-arm, we don't match.
105 if (!TT.empty()) return 0;
107 if (M.getEndianness() == Module::LittleEndian &&
108 M.getPointerSize() == Module::Pointer32)
109 return 10; // Weak match
110 else if (M.getEndianness() != Module::AnyEndianness ||
111 M.getPointerSize() != Module::AnyPointerSize)
112 return 0; // Match for some other target
114 return getJITMatchQuality()/2;
118 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
119 switch (Subtarget.TargetType) {
120 case ARMSubtarget::isDarwin:
121 return new ARMDarwinTargetAsmInfo(*this);
122 case ARMSubtarget::isELF:
123 return new ARMELFTargetAsmInfo(*this);
125 return new ARMGenericTargetAsmInfo(*this);
130 // Pass Pipeline Configuration
131 bool ARMTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
132 PM.add(createARMISelDag(*this));
136 bool ARMTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
137 // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
138 if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
139 PM.add(createARMLoadStoreOptimizationPass());
141 if (!Fast && !DisableIfConversion && !Subtarget.isThumb())
142 PM.add(createIfConverterPass());
144 PM.add(createARMConstantIslandPass());
148 bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
150 // Output assembly language.
151 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
153 PM.add(AsmPrinterCtor(Out, *this));
159 bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
160 bool DumpAsm, MachineCodeEmitter &MCE) {
161 // FIXME: Move this to TargetJITInfo!
162 if (DefRelocModel == Reloc::Default)
163 setRelocationModel(Reloc::Static);
165 // Machine code emitter pass for ARM.
166 PM.add(createARMCodeEmitterPass(*this, MCE));
168 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
170 PM.add(AsmPrinterCtor(errs(), *this));
176 bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
177 bool DumpAsm, MachineCodeEmitter &MCE) {
178 // Machine code emitter pass for ARM.
179 PM.add(createARMCodeEmitterPass(*this, MCE));
181 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
183 PM.add(AsmPrinterCtor(errs(), *this));