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