5714ab969560dabc80ce9690b52ca19a7b70af81
[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 "SparcTargetObjectFile.h"
15 #include "Sparc.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/Support/TargetRegistry.h"
19 using namespace llvm;
20
21 extern "C" void LLVMInitializeSparcTarget() {
22   // Register the target.
23   RegisterTargetMachine<SparcV8TargetMachine> X(TheSparcTarget);
24   RegisterTargetMachine<SparcV9TargetMachine> Y(TheSparcV9Target);
25 }
26
27 static std::string computeDataLayout(bool is64Bit) {
28   // Sparc is big endian.
29   std::string Ret = "E-m:e";
30
31   // Some ABIs have 32bit pointers.
32   if (!is64Bit)
33     Ret += "-p:32:32";
34
35   // Alignments for 64 bit integers.
36   Ret += "-i64:64";
37
38   // On SparcV9 128 floats are aligned to 128 bits, on others only to 64.
39   // On SparcV9 registers can hold 64 or 32 bits, on others only 32.
40   if (is64Bit)
41     Ret += "-n32:64";
42   else
43     Ret += "-f128:64-n32";
44
45   if (is64Bit)
46     Ret += "-S128";
47   else
48     Ret += "-S64";
49
50   return Ret;
51 }
52
53 /// SparcTargetMachine ctor - Create an ILP32 architecture model
54 ///
55 SparcTargetMachine::SparcTargetMachine(const Target &T, StringRef TT,
56                                        StringRef CPU, StringRef FS,
57                                        const TargetOptions &Options,
58                                        Reloc::Model RM, CodeModel::Model CM,
59                                        CodeGenOpt::Level OL,
60                                        bool is64bit)
61   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
62     TLOF(make_unique<SparcELFTargetObjectFile>()),
63     DL(computeDataLayout(is64bit)),
64     Subtarget(TT, CPU, FS, *this, is64bit) {
65   initAsmInfo();
66 }
67
68 SparcTargetMachine::~SparcTargetMachine() {}
69
70 namespace {
71 /// Sparc Code Generator Pass Configuration Options.
72 class SparcPassConfig : public TargetPassConfig {
73 public:
74   SparcPassConfig(SparcTargetMachine *TM, PassManagerBase &PM)
75     : TargetPassConfig(TM, PM) {}
76
77   SparcTargetMachine &getSparcTargetMachine() const {
78     return getTM<SparcTargetMachine>();
79   }
80
81   void addIRPasses() override;
82   bool addInstSelector() override;
83   void addPreEmitPass() override;
84 };
85 } // namespace
86
87 TargetPassConfig *SparcTargetMachine::createPassConfig(PassManagerBase &PM) {
88   return new SparcPassConfig(this, PM);
89 }
90
91 void SparcPassConfig::addIRPasses() {
92   addPass(createAtomicExpandPass(&getSparcTargetMachine()));
93
94   TargetPassConfig::addIRPasses();
95 }
96
97 bool SparcPassConfig::addInstSelector() {
98   addPass(createSparcISelDag(getSparcTargetMachine()));
99   return false;
100 }
101
102 void SparcPassConfig::addPreEmitPass(){
103   addPass(createSparcDelaySlotFillerPass(getSparcTargetMachine()));
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 }