ARMTargetMachine.cpp revision bfae83139dcb4fffd50b939e1b1224b0126f04d4
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"
23using namespace llvm;
24
25static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
26                              cl::desc("Disable load store optimization pass"));
27static cl::opt<bool> DisableIfConversion("disable-arm-if-conversion",cl::Hidden,
28                              cl::desc("Disable if-conversion pass"));
29
30namespace {
31  // Register the target.
32  RegisterTarget<ARMTargetMachine>   X("arm",   "  ARM");
33  RegisterTarget<ThumbTargetMachine> Y("thumb", "  Thumb");
34}
35
36/// ThumbTargetMachine - Create an Thumb architecture model.
37///
38unsigned ThumbTargetMachine::getJITMatchQuality() {
39#if defined(__thumb__)
40  return 10;
41#endif
42  return 0;
43}
44
45unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
46  std::string TT = M.getTargetTriple();
47  if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
48    return 20;
49
50  // If the target triple is something non-thumb, we don't match.
51  if (!TT.empty()) return 0;
52
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
59
60  return getJITMatchQuality()/2;
61}
62
63ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
64  : ARMTargetMachine(M, FS, true) {
65}
66
67/// TargetMachine ctor - Create an ARM architecture model.
68///
69ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
70                                   bool isThumb)
71  : Subtarget(M, FS, isThumb),
72    DataLayout(Subtarget.isAPCS_ABI() ?
73               // APCS ABI
74          (isThumb ?
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")) :
78               // AAPCS ABI
79          (isThumb ?
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"))),
83    InstrInfo(Subtarget),
84    FrameInfo(Subtarget),
85    JITInfo(*this),
86    TLInfo(*this) {}
87
88unsigned ARMTargetMachine::getJITMatchQuality() {
89#if defined(__arm__)
90  return 10;
91#endif
92  return 0;
93}
94
95unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
96  std::string TT = M.getTargetTriple();
97  if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-")
98    return 20;
99  // If the target triple is something non-arm, we don't match.
100  if (!TT.empty()) return 0;
101
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
108
109  return getJITMatchQuality()/2;
110}
111
112
113const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
114  return new ARMTargetAsmInfo(*this);
115}
116
117
118// Pass Pipeline Configuration
119bool ARMTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
120  PM.add(createARMISelDag(*this));
121  return false;
122}
123
124bool 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());
128
129  if (!Fast && !DisableIfConversion && !Subtarget.isThumb())
130    PM.add(createIfConverterPass());
131
132  PM.add(createARMConstantIslandPass());
133  return true;
134}
135
136bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
137                                          std::ostream &Out) {
138  // Output assembly language.
139  PM.add(createARMCodePrinterPass(Out, *this));
140  return false;
141}
142
143
144bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
145                                      bool DumpAsm, MachineCodeEmitter &MCE) {
146  // FIXME: Move this to TargetJITInfo!
147  setRelocationModel(Reloc::Static);
148
149  // Machine code emitter pass for ARM.
150  PM.add(createARMCodeEmitterPass(*this, MCE));
151  if (DumpAsm)
152    PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
153  return false;
154}
155
156bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
157                                        bool DumpAsm, MachineCodeEmitter &MCE) {
158  // Machine code emitter pass for ARM.
159  PM.add(createARMCodeEmitterPass(*this, MCE));
160  if (DumpAsm)
161    PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
162  return false;
163}
164