1 //===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the "Instituto Nokia de Tecnologia" and
6 // is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
14 #include "ARMTargetMachine.h"
15 #include "ARMTargetAsmInfo.h"
16 #include "ARMFrameInfo.h"
18 #include "llvm/Module.h"
19 #include "llvm/PassManager.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Support/CommandLine.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"));
32 // Register the target.
33 RegisterTarget
<ARMTargetMachine
> X("arm", " ARM");
34 RegisterTarget
<ThumbTargetMachine
> Y("thumb", " Thumb");
37 /// ThumbTargetMachine - Create an Thumb architecture model.
39 unsigned ThumbTargetMachine::getJITMatchQuality() {
40 #if defined(__thumb__)
46 unsigned ThumbTargetMachine::getModuleMatchQuality(const Module
&M
) {
47 std::string TT
= M
.getTargetTriple();
48 if (TT
.size() >= 6 && std::string(TT
.begin(), TT
.begin()+6) == "thumb-")
51 // If the target triple is something non-thumb, we don't match.
52 if (!TT
.empty()) return 0;
54 if (M
.getEndianness() == Module::LittleEndian
&&
55 M
.getPointerSize() == Module::Pointer32
)
56 return 10; // Weak match
57 else if (M
.getEndianness() != Module::AnyEndianness
||
58 M
.getPointerSize() != Module::AnyPointerSize
)
59 return 0; // Match for some other target
61 return getJITMatchQuality()/2;
64 ThumbTargetMachine::ThumbTargetMachine(const Module
&M
, const std::string
&FS
)
65 : ARMTargetMachine(M
, FS
, true) {
68 /// TargetMachine ctor - Create an ARM architecture model.
70 ARMTargetMachine::ARMTargetMachine(const Module
&M
, const std::string
&FS
,
72 : Subtarget(M
, FS
, isThumb
),
73 DataLayout(Subtarget
.isAPCS_ABI() ?
76 std::string("e-p:32:32-f64:32:32-i64:32:32-"
77 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
78 std::string("e-p:32:32-f64:32:32-i64:32:32")) :
81 std::string("e-p:32:32-f64:64:64-i64:64:64-"
82 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
83 std::string("e-p:32:32-f64:64:64-i64:64:64"))),
89 unsigned ARMTargetMachine::getJITMatchQuality() {
96 unsigned ARMTargetMachine::getModuleMatchQuality(const Module
&M
) {
97 std::string TT
= M
.getTargetTriple();
98 if (TT
.size() >= 4 && std::string(TT
.begin(), TT
.begin()+4) == "arm-")
100 // If the target triple is something non-arm, we don't match.
101 if (!TT
.empty()) return 0;
103 if (M
.getEndianness() == Module::LittleEndian
&&
104 M
.getPointerSize() == Module::Pointer32
)
105 return 10; // Weak match
106 else if (M
.getEndianness() != Module::AnyEndianness
||
107 M
.getPointerSize() != Module::AnyPointerSize
)
108 return 0; // Match for some other target
110 return getJITMatchQuality()/2;
114 const TargetAsmInfo
*ARMTargetMachine::createTargetAsmInfo() const {
115 return new ARMTargetAsmInfo(*this);
119 // Pass Pipeline Configuration
120 bool ARMTargetMachine::addInstSelector(FunctionPassManager
&PM
, bool Fast
) {
121 PM
.add(createARMISelDag(*this));
125 bool ARMTargetMachine::addPreEmitPass(FunctionPassManager
&PM
, bool Fast
) {
126 // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
127 if (!Fast
&& !DisableLdStOpti
&& !Subtarget
.isThumb())
128 PM
.add(createARMLoadStoreOptimizationPass());
130 if (!Fast
&& !DisableIfConversion
&& !Subtarget
.isThumb())
131 PM
.add(createIfConverterPass());
133 PM
.add(createARMConstantIslandPass());
137 bool ARMTargetMachine::addAssemblyEmitter(FunctionPassManager
&PM
, bool Fast
,
139 // Output assembly language.
140 PM
.add(createARMCodePrinterPass(Out
, *this));
145 bool ARMTargetMachine::addCodeEmitter(FunctionPassManager
&PM
, bool Fast
,
146 bool DumpAsm
, MachineCodeEmitter
&MCE
) {
147 // FIXME: Move this to TargetJITInfo!
148 setRelocationModel(Reloc::Static
);
150 // Machine code emitter pass for ARM.
151 PM
.add(createARMCodeEmitterPass(*this, MCE
));
153 PM
.add(createARMCodePrinterPass(*cerr
.stream(), *this));
157 bool ARMTargetMachine::addSimpleCodeEmitter(FunctionPassManager
&PM
, bool Fast
,
158 bool DumpAsm
, MachineCodeEmitter
&MCE
) {
159 // Machine code emitter pass for ARM.
160 PM
.add(createARMCodeEmitterPass(*this, MCE
));
162 PM
.add(createARMCodePrinterPass(*cerr
.stream(), *this));