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> EnableIfConversion("enable-arm-if-conversion", cl::Hidden,
29 cl::desc("Enable 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() {
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 (M.getEndianness() == Module::LittleEndian &&
52 M.getPointerSize() == Module::Pointer32)
53 return 10; // Weak match
54 else if (M.getEndianness() != Module::AnyEndianness ||
55 M.getPointerSize() != Module::AnyPointerSize)
56 return 0; // Match for some other target
58 return getJITMatchQuality()/2;
61 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
62 : ARMTargetMachine(M, FS, true) {
65 /// TargetMachine ctor - Create an ARM architecture model.
67 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
69 : Subtarget(M, FS, isThumb),
70 DataLayout(Subtarget.isAPCS_ABI() ?
73 std::string("e-p:32:32-f64:32:32-i64:32:32-"
74 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
75 std::string("e-p:32:32-f64:32:32-i64:32:32")) :
78 std::string("e-p:32:32-f64:64:64-i64:64:64-"
79 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
80 std::string("e-p:32:32-f64:64:64-i64:64:64"))),
86 unsigned ARMTargetMachine::getJITMatchQuality() {
87 #if defined(__thumb__)
93 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
94 std::string TT = M.getTargetTriple();
95 if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-")
98 if (M.getEndianness() == Module::LittleEndian &&
99 M.getPointerSize() == Module::Pointer32)
100 return 10; // Weak match
101 else if (M.getEndianness() != Module::AnyEndianness ||
102 M.getPointerSize() != Module::AnyPointerSize)
103 return 0; // Match for some other target
105 return getJITMatchQuality()/2;
109 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
110 return new ARMTargetAsmInfo(*this);
114 // Pass Pipeline Configuration
115 bool ARMTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
116 PM.add(createARMISelDag(*this));
120 bool ARMTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
121 // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
122 if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
123 PM.add(createARMLoadStoreOptimizationPass());
125 if (!Fast && EnableIfConversion && !Subtarget.isThumb())
126 PM.add(createIfConverterPass());
128 PM.add(createARMConstantIslandPass());
132 bool ARMTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
134 // Output assembly language.
135 PM.add(createARMCodePrinterPass(Out, *this));
140 bool ARMTargetMachine::addCodeEmitter(FunctionPassManager &PM, bool Fast,
141 MachineCodeEmitter &MCE) {
142 // FIXME: Move this to TargetJITInfo!
143 setRelocationModel(Reloc::Static);
145 // Machine code emitter pass for ARM.
146 PM.add(createARMCodeEmitterPass(*this, MCE));
150 bool ARMTargetMachine::addSimpleCodeEmitter(FunctionPassManager &PM, bool Fast,
151 MachineCodeEmitter &MCE) {
152 // Machine code emitter pass for ARM.
153 PM.add(createARMCodeEmitterPass(*this, MCE));