Hooks for predication support.
[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> EnableIfConversion("enable-arm-if-conversion", cl::Hidden,
29                               cl::desc("Enable 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::getModuleMatchQuality(const Module &M) {
40   std::string TT = M.getTargetTriple();
41   if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
42     return 20;
43
44   return M.getPointerSize() == Module::Pointer32;
45 }
46
47 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS) 
48   : ARMTargetMachine(M, FS, true) {
49 }
50
51 /// TargetMachine ctor - Create an ARM architecture model.
52 ///
53 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
54                                    bool isThumb)
55   : Subtarget(M, FS, isThumb),
56     DataLayout(Subtarget.isAPCS_ABI() ?
57                // APCS ABI
58           (isThumb ?
59            std::string("e-p:32:32-f64:32:32-i64:32:32-"
60                        "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
61            std::string("e-p:32:32-f64:32:32-i64:32:32")) :
62                // AAPCS ABI
63           (isThumb ?
64            std::string("e-p:32:32-f64:64:64-i64:64:64-"
65                        "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
66            std::string("e-p:32:32-f64:64:64-i64:64:64"))),
67     InstrInfo(Subtarget),
68     FrameInfo(Subtarget),
69     TLInfo(*this) {}
70
71 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
72   std::string TT = M.getTargetTriple();
73   if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-")
74     return 20;
75
76   return M.getPointerSize() == Module::Pointer32;
77 }
78
79
80 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
81   return new ARMTargetAsmInfo(*this);
82 }
83
84
85 // Pass Pipeline Configuration
86 bool ARMTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
87   PM.add(createARMISelDag(*this));
88   return false;
89 }
90
91 bool ARMTargetMachine::addPostRegAlloc(FunctionPassManager &PM, bool Fast) {
92   if (Fast || !EnableIfConversion || Subtarget.isThumb())
93     return false;
94
95   PM.add(createIfConverterPass());
96   return true;
97 }
98
99 bool ARMTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
100   // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
101   if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
102     PM.add(createARMLoadStoreOptimizationPass());
103   
104   PM.add(createARMConstantIslandPass());
105   return true;
106 }
107
108 bool ARMTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
109                                           std::ostream &Out) {
110   // Output assembly language.
111   PM.add(createARMCodePrinterPass(Out, *this));
112   return false;
113 }