1 //===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #include "SparcTargetMachine.h"
14 #include "SparcTargetObjectFile.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/IR/LegacyPassManager.h"
18 #include "llvm/Support/TargetRegistry.h"
21 extern "C" void LLVMInitializeSparcTarget() {
22 // Register the target.
23 RegisterTargetMachine<SparcV8TargetMachine> X(TheSparcTarget);
24 RegisterTargetMachine<SparcV9TargetMachine> Y(TheSparcV9Target);
27 static std::string computeDataLayout(bool is64Bit) {
28 // Sparc is big endian.
29 std::string Ret = "E-m:e";
31 // Some ABIs have 32bit pointers.
35 // Alignments for 64 bit integers.
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.
43 Ret += "-f128:64-n32";
53 /// SparcTargetMachine ctor - Create an ILP32 architecture model
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, bool is64bit)
60 : LLVMTargetMachine(T, computeDataLayout(is64bit), TT, CPU, FS, Options, RM,
62 TLOF(make_unique<SparcELFTargetObjectFile>()),
63 Subtarget(TT, CPU, FS, *this, is64bit) {
67 SparcTargetMachine::~SparcTargetMachine() {}
70 /// Sparc Code Generator Pass Configuration Options.
71 class SparcPassConfig : public TargetPassConfig {
73 SparcPassConfig(SparcTargetMachine *TM, PassManagerBase &PM)
74 : TargetPassConfig(TM, PM) {}
76 SparcTargetMachine &getSparcTargetMachine() const {
77 return getTM<SparcTargetMachine>();
80 void addIRPasses() override;
81 bool addInstSelector() override;
82 void addPreEmitPass() override;
86 TargetPassConfig *SparcTargetMachine::createPassConfig(PassManagerBase &PM) {
87 return new SparcPassConfig(this, PM);
90 void SparcPassConfig::addIRPasses() {
91 addPass(createAtomicExpandPass(&getSparcTargetMachine()));
93 TargetPassConfig::addIRPasses();
96 bool SparcPassConfig::addInstSelector() {
97 addPass(createSparcISelDag(getSparcTargetMachine()));
101 void SparcPassConfig::addPreEmitPass(){
102 addPass(createSparcDelaySlotFillerPass(getSparcTargetMachine()));
105 void SparcV8TargetMachine::anchor() { }
107 SparcV8TargetMachine::SparcV8TargetMachine(const Target &T,
108 StringRef TT, StringRef CPU,
110 const TargetOptions &Options,
113 CodeGenOpt::Level OL)
114 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
117 void SparcV9TargetMachine::anchor() { }
119 SparcV9TargetMachine::SparcV9TargetMachine(const Target &T,
120 StringRef TT, StringRef CPU,
122 const TargetOptions &Options,
125 CodeGenOpt::Level OL)
126 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {