ARM backend contribution from Apple.
[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 }
32
33 /// TargetMachine ctor - Create an ILP32 architecture model
34 ///
35 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS)
36   : Subtarget(M, FS), DataLayout("e-p:32:32-d:32"), InstrInfo(Subtarget),
37     FrameInfo(Subtarget) {
38   if (Subtarget.isDarwin())
39     NoFramePointerElim = true;
40 }
41
42 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
43   std::string TT = M.getTargetTriple();
44   if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-")
45     return 20;
46
47   if (M.getPointerSize() == Module::Pointer32)
48     return 1;
49   else
50     return 0;
51 }
52
53
54 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
55   return new ARMTargetAsmInfo(*this);
56 }
57
58
59 // Pass Pipeline Configuration
60 bool ARMTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
61   PM.add(createARMISelDag(*this));
62   return false;
63 }
64
65 bool ARMTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
66   // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
67   if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
68     PM.add(createARMLoadStoreOptimizationPass());
69   
70   PM.add(createARMConstantIslandPass());
71   return true;
72 }
73
74 bool ARMTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
75                                           std::ostream &Out) {
76   // Output assembly language.
77   PM.add(createARMCodePrinterPass(Out, *this));
78   return false;
79 }