Switch ARM to new section handling stuff
[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 is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "ARMTargetMachine.h"
14 #include "ARMTargetAsmInfo.h"
15 #include "ARMFrameInfo.h"
16 #include "ARM.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"
23 using namespace llvm;
24
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"));
29
30 // Register the target.
31 static RegisterTarget<ARMTargetMachine>   X("arm",   "  ARM");
32 static RegisterTarget<ThumbTargetMachine> Y("thumb", "  Thumb");
33
34 /// ThumbTargetMachine - Create an Thumb architecture model.
35 ///
36 unsigned ThumbTargetMachine::getJITMatchQuality() {
37 #if defined(__thumb__)
38   return 10;
39 #endif
40   return 0;
41 }
42
43 unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
44   std::string TT = M.getTargetTriple();
45   if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
46     return 20;
47
48   // If the target triple is something non-thumb, we don't match.
49   if (!TT.empty()) return 0;
50
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
57
58   return getJITMatchQuality()/2;
59 }
60
61 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
62   : ARMTargetMachine(M, FS, true) {
63 }
64
65 /// TargetMachine ctor - Create an ARM architecture model.
66 ///
67 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
68                                    bool isThumb)
69   : Subtarget(M, FS, isThumb),
70     DataLayout(Subtarget.isAPCS_ABI() ?
71                // APCS ABI
72           (isThumb ?
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")) :
76                // AAPCS ABI
77           (isThumb ?
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"))),
81     InstrInfo(Subtarget),
82     FrameInfo(Subtarget),
83     JITInfo(*this),
84     TLInfo(*this) {}
85
86 unsigned ARMTargetMachine::getJITMatchQuality() {
87 #if defined(__arm__)
88   return 10;
89 #endif
90   return 0;
91 }
92
93 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
94   std::string TT = M.getTargetTriple();
95   if (TT.size() >= 4 && // Match arm-foo-bar, as well as things like armv5blah-*
96       (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
97     return 20;
98   // If the target triple is something non-arm, we don't match.
99   if (!TT.empty()) return 0;
100
101   if (M.getEndianness()  == Module::LittleEndian &&
102       M.getPointerSize() == Module::Pointer32)
103     return 10;                                   // Weak match
104   else if (M.getEndianness() != Module::AnyEndianness ||
105            M.getPointerSize() != Module::AnyPointerSize)
106     return 0;                                    // Match for some other target
107
108   return getJITMatchQuality()/2;
109 }
110
111
112 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
113   switch (Subtarget.TargetType) {
114    case ARMSubtarget::isDarwin:
115     return new ARMDarwinTargetAsmInfo(*this);
116    case ARMSubtarget::isELF:
117     return new ARMELFTargetAsmInfo(*this);
118    default:
119     return new ARMTargetAsmInfo(*this);
120   }
121 }
122
123
124 // Pass Pipeline Configuration
125 bool ARMTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
126   PM.add(createARMISelDag(*this));
127   return false;
128 }
129
130 bool ARMTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
131   // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
132   if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
133     PM.add(createARMLoadStoreOptimizationPass());
134
135   if (!Fast && !DisableIfConversion && !Subtarget.isThumb())
136     PM.add(createIfConverterPass());
137
138   PM.add(createARMConstantIslandPass());
139   return true;
140 }
141
142 bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
143                                           std::ostream &Out) {
144   // Output assembly language.
145   PM.add(createARMCodePrinterPass(Out, *this));
146   return false;
147 }
148
149
150 bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
151                                       bool DumpAsm, MachineCodeEmitter &MCE) {
152   // FIXME: Move this to TargetJITInfo!
153   setRelocationModel(Reloc::Static);
154
155   // Machine code emitter pass for ARM.
156   PM.add(createARMCodeEmitterPass(*this, MCE));
157   if (DumpAsm)
158     PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
159   return false;
160 }
161
162 bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
163                                         bool DumpAsm, MachineCodeEmitter &MCE) {
164   // Machine code emitter pass for ARM.
165   PM.add(createARMCodeEmitterPass(*this, MCE));
166   if (DumpAsm)
167     PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
168   return false;
169 }