Assume defaults to produce smaller datalayout strings.
[oota-llvm.git] / lib / Target / Sparc / SparcTargetMachine.cpp
1 //===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
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 "SparcTargetMachine.h"
14 #include "Sparc.h"
15 #include "llvm/CodeGen/Passes.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/Support/TargetRegistry.h"
18 using namespace llvm;
19
20 extern "C" void LLVMInitializeSparcTarget() {
21   // Register the target.
22   RegisterTargetMachine<SparcV8TargetMachine> X(TheSparcTarget);
23   RegisterTargetMachine<SparcV9TargetMachine> Y(TheSparcV9Target);
24 }
25
26 static std::string computeDataLayout(const SparcSubtarget &ST) {
27   // Sparc is big endian.
28   std::string Ret = "E";
29
30   // V9 has 64 bit pointers, others have 32bit pointers.
31   if (ST.is64Bit())
32     Ret += "-p:64:64:64";
33   else
34     Ret += "-p:32:32:32";
35
36   // Alignments for 64 bit integers.
37   Ret += "-i64:64:64";
38
39   // On SparcV9 128 floats are aligned to 128 bits, on others only to 64.
40   // On SparcV9 registers can hold 64 or 32 bits, on others only 32.
41   if (ST.is64Bit())
42     Ret += "-n32:64";
43   else
44     Ret += "-f128:64:64-n32";
45
46   return Ret;
47 }
48
49 /// SparcTargetMachine ctor - Create an ILP32 architecture model
50 ///
51 SparcTargetMachine::SparcTargetMachine(const Target &T, StringRef TT,
52                                        StringRef CPU, StringRef FS,
53                                        const TargetOptions &Options,
54                                        Reloc::Model RM, CodeModel::Model CM,
55                                        CodeGenOpt::Level OL,
56                                        bool is64bit)
57   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
58     Subtarget(TT, CPU, FS, is64bit),
59     DL(computeDataLayout(Subtarget)),
60     InstrInfo(Subtarget),
61     TLInfo(*this), TSInfo(*this),
62     FrameLowering(Subtarget) {
63   initAsmInfo();
64 }
65
66 namespace {
67 /// Sparc Code Generator Pass Configuration Options.
68 class SparcPassConfig : public TargetPassConfig {
69 public:
70   SparcPassConfig(SparcTargetMachine *TM, PassManagerBase &PM)
71     : TargetPassConfig(TM, PM) {}
72
73   SparcTargetMachine &getSparcTargetMachine() const {
74     return getTM<SparcTargetMachine>();
75   }
76
77   virtual bool addInstSelector();
78   virtual bool addPreEmitPass();
79 };
80 } // namespace
81
82 TargetPassConfig *SparcTargetMachine::createPassConfig(PassManagerBase &PM) {
83   return new SparcPassConfig(this, PM);
84 }
85
86 bool SparcPassConfig::addInstSelector() {
87   addPass(createSparcISelDag(getSparcTargetMachine()));
88   return false;
89 }
90
91 bool SparcTargetMachine::addCodeEmitter(PassManagerBase &PM,
92                                         JITCodeEmitter &JCE) {
93   // Machine code emitter pass for Sparc.
94   PM.add(createSparcJITCodeEmitterPass(*this, JCE));
95   return false;
96 }
97
98 /// addPreEmitPass - This pass may be implemented by targets that want to run
99 /// passes immediately before machine code is emitted.  This should return
100 /// true if -print-machineinstrs should print out the code after the passes.
101 bool SparcPassConfig::addPreEmitPass(){
102   addPass(createSparcDelaySlotFillerPass(getSparcTargetMachine()));
103   return true;
104 }
105
106 void SparcV8TargetMachine::anchor() { }
107
108 SparcV8TargetMachine::SparcV8TargetMachine(const Target &T,
109                                            StringRef TT, StringRef CPU,
110                                            StringRef FS,
111                                            const TargetOptions &Options,
112                                            Reloc::Model RM,
113                                            CodeModel::Model CM,
114                                            CodeGenOpt::Level OL)
115   : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
116 }
117
118 void SparcV9TargetMachine::anchor() { }
119
120 SparcV9TargetMachine::SparcV9TargetMachine(const Target &T,
121                                            StringRef TT,  StringRef CPU,
122                                            StringRef FS,
123                                            const TargetOptions &Options,
124                                            Reloc::Model RM,
125                                            CodeModel::Model CM,
126                                            CodeGenOpt::Level OL)
127   : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
128 }