Enable if-conversion for ARM by default.
[oota-llvm.git] / lib / Target / ARM / ARMTargetMachine.cpp
1 //===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARMTargetMachine.h"
15 #include "ARMTargetAsmInfo.h"
16 #include "ARMFrameInfo.h"
17 #include "ARM.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"
24 using namespace llvm;
25
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"));
30
31 namespace {
32   // Register the target.
33   RegisterTarget<ARMTargetMachine>   X("arm",   "  ARM");
34   RegisterTarget<ThumbTargetMachine> Y("thumb", "  Thumb");
35 }
36
37 /// ThumbTargetMachine - Create an Thumb architecture model.
38 ///
39 unsigned ThumbTargetMachine::getJITMatchQuality() {
40 #if defined(__thumb__)
41   return 10;
42 #endif
43   return 0;
44 }
45
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-")
49     return 20;
50
51   // If the target triple is something non-thumb, we don't match.
52   if (!TT.empty()) return 0;
53
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
60
61   return getJITMatchQuality()/2;
62 }
63
64 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS) 
65   : ARMTargetMachine(M, FS, true) {
66 }
67
68 /// TargetMachine ctor - Create an ARM architecture model.
69 ///
70 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
71                                    bool isThumb)
72   : Subtarget(M, FS, isThumb),
73     DataLayout(Subtarget.isAPCS_ABI() ?
74                // APCS ABI
75           (isThumb ?
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")) :
79                // AAPCS ABI
80           (isThumb ?
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"))),
84     InstrInfo(Subtarget),
85     FrameInfo(Subtarget),
86     JITInfo(*this),
87     TLInfo(*this) {}
88
89 unsigned ARMTargetMachine::getJITMatchQuality() {
90 #if defined(__arm__)
91   return 10;
92 #endif
93   return 0;
94 }
95
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-")
99     return 20;
100   // If the target triple is something non-arm, we don't match.
101   if (!TT.empty()) return 0;
102
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
109
110   return getJITMatchQuality()/2;
111 }
112
113
114 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
115   return new ARMTargetAsmInfo(*this);
116 }
117
118
119 // Pass Pipeline Configuration
120 bool ARMTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
121   PM.add(createARMISelDag(*this));
122   return false;
123 }
124
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());
129   
130   if (!Fast && !DisableIfConversion && !Subtarget.isThumb())
131     PM.add(createIfConverterPass());
132
133   PM.add(createARMConstantIslandPass());
134   return true;
135 }
136
137 bool ARMTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
138                                           std::ostream &Out) {
139   // Output assembly language.
140   PM.add(createARMCodePrinterPass(Out, *this));
141   return false;
142 }
143
144
145 bool ARMTargetMachine::addCodeEmitter(FunctionPassManager &PM, bool Fast,
146                                       bool DumpAsm, MachineCodeEmitter &MCE) {
147   // FIXME: Move this to TargetJITInfo!
148   setRelocationModel(Reloc::Static);
149
150   // Machine code emitter pass for ARM.
151   PM.add(createARMCodeEmitterPass(*this, MCE));
152   if (DumpAsm)
153     PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
154   return false;
155 }
156
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));
161   if (DumpAsm)
162     PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
163   return false;
164 }