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/Target/TargetMachineRegistry.h"
22 #include "llvm/Target/TargetOptions.h"
25 static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
26 cl::desc("Disable load store optimization pass"));
27 static cl::opt<bool> DisableIfConversion("disable-arm-if-conversion",cl::Hidden,
28 cl::desc("Disable if-conversion pass"));
31 // Register the target.
32 RegisterTarget<ARMTargetMachine> X("arm", " ARM");
33 RegisterTarget<ThumbTargetMachine> Y("thumb", " Thumb");
36 /// ThumbTargetMachine - Create an Thumb architecture model.
38 unsigned ThumbTargetMachine::getJITMatchQuality() {
39 #if defined(__thumb__)
45 unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
46 std::string TT = M.getTargetTriple();
47 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
50 // If the target triple is something non-thumb, we don't match.
51 if (!TT.empty()) return 0;
53 if (M.getEndianness() == Module::LittleEndian &&
54 M.getPointerSize() == Module::Pointer32)
55 return 10; // Weak match
56 else if (M.getEndianness() != Module::AnyEndianness ||
57 M.getPointerSize() != Module::AnyPointerSize)
58 return 0; // Match for some other target
60 return getJITMatchQuality()/2;
63 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
64 : ARMTargetMachine(M, FS, true) {
67 /// TargetMachine ctor - Create an ARM architecture model.
69 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
71 : Subtarget(M, FS, isThumb),
72 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:32:32-i64:32:32")) :
80 std::string("e-p:32:32-f64:64:64-i64:64:64-"
81 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
82 std::string("e-p:32:32-f64:64:64-i64:64:64"))),
88 unsigned ARMTargetMachine::getJITMatchQuality() {
95 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
96 std::string TT = M.getTargetTriple();
97 if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-")
99 // If the target triple is something non-arm, we don't match.
100 if (!TT.empty()) return 0;
102 if (M.getEndianness() == Module::LittleEndian &&
103 M.getPointerSize() == Module::Pointer32)
104 return 10; // Weak match
105 else if (M.getEndianness() != Module::AnyEndianness ||
106 M.getPointerSize() != Module::AnyPointerSize)
107 return 0; // Match for some other target
109 return getJITMatchQuality()/2;
113 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
114 return new ARMTargetAsmInfo(*this);
118 // Pass Pipeline Configuration
119 bool ARMTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
120 PM.add(createARMISelDag(*this));
124 bool ARMTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
125 // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
126 if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
127 PM.add(createARMLoadStoreOptimizationPass());
129 if (!Fast && !DisableIfConversion && !Subtarget.isThumb())
130 PM.add(createIfConverterPass());
132 PM.add(createARMConstantIslandPass());
136 bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
138 // Output assembly language.
139 PM.add(createARMCodePrinterPass(Out, *this));
144 bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
145 bool DumpAsm, MachineCodeEmitter &MCE) {
146 // FIXME: Move this to TargetJITInfo!
147 setRelocationModel(Reloc::Static);
149 // Machine code emitter pass for ARM.
150 PM.add(createARMCodeEmitterPass(*this, MCE));
152 PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
156 bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
157 bool DumpAsm, MachineCodeEmitter &MCE) {
158 // Machine code emitter pass for ARM.
159 PM.add(createARMCodeEmitterPass(*this, MCE));
161 PM.add(createARMCodePrinterPass(*cerr.stream(), *this));