LLVM API Documentation

SparcTargetMachine.cpp
Go to the documentation of this file.
00001 //===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //
00011 //===----------------------------------------------------------------------===//
00012 
00013 #include "SparcTargetMachine.h"
00014 #include "Sparc.h"
00015 #include "llvm/CodeGen/Passes.h"
00016 #include "llvm/PassManager.h"
00017 #include "llvm/Support/TargetRegistry.h"
00018 using namespace llvm;
00019 
00020 extern "C" void LLVMInitializeSparcTarget() {
00021   // Register the target.
00022   RegisterTargetMachine<SparcV8TargetMachine> X(TheSparcTarget);
00023   RegisterTargetMachine<SparcV9TargetMachine> Y(TheSparcV9Target);
00024 }
00025 
00026 /// SparcTargetMachine ctor - Create an ILP32 architecture model
00027 ///
00028 SparcTargetMachine::SparcTargetMachine(const Target &T, StringRef TT,
00029                                        StringRef CPU, StringRef FS,
00030                                        const TargetOptions &Options,
00031                                        Reloc::Model RM, CodeModel::Model CM,
00032                                        CodeGenOpt::Level OL,
00033                                        bool is64bit)
00034   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
00035     Subtarget(TT, CPU, FS, *this, is64bit) {
00036   initAsmInfo();
00037 }
00038 
00039 namespace {
00040 /// Sparc Code Generator Pass Configuration Options.
00041 class SparcPassConfig : public TargetPassConfig {
00042 public:
00043   SparcPassConfig(SparcTargetMachine *TM, PassManagerBase &PM)
00044     : TargetPassConfig(TM, PM) {}
00045 
00046   SparcTargetMachine &getSparcTargetMachine() const {
00047     return getTM<SparcTargetMachine>();
00048   }
00049 
00050   bool addInstSelector() override;
00051   bool addPreEmitPass() override;
00052 };
00053 } // namespace
00054 
00055 TargetPassConfig *SparcTargetMachine::createPassConfig(PassManagerBase &PM) {
00056   return new SparcPassConfig(this, PM);
00057 }
00058 
00059 bool SparcPassConfig::addInstSelector() {
00060   addPass(createSparcISelDag(getSparcTargetMachine()));
00061   return false;
00062 }
00063 
00064 /// addPreEmitPass - This pass may be implemented by targets that want to run
00065 /// passes immediately before machine code is emitted.  This should return
00066 /// true if -print-machineinstrs should print out the code after the passes.
00067 bool SparcPassConfig::addPreEmitPass(){
00068   addPass(createSparcDelaySlotFillerPass(getSparcTargetMachine()));
00069   return true;
00070 }
00071 
00072 void SparcV8TargetMachine::anchor() { }
00073 
00074 SparcV8TargetMachine::SparcV8TargetMachine(const Target &T,
00075                                            StringRef TT, StringRef CPU,
00076                                            StringRef FS,
00077                                            const TargetOptions &Options,
00078                                            Reloc::Model RM,
00079                                            CodeModel::Model CM,
00080                                            CodeGenOpt::Level OL)
00081   : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
00082 }
00083 
00084 void SparcV9TargetMachine::anchor() { }
00085 
00086 SparcV9TargetMachine::SparcV9TargetMachine(const Target &T,
00087                                            StringRef TT,  StringRef CPU,
00088                                            StringRef FS,
00089                                            const TargetOptions &Options,
00090                                            Reloc::Model RM,
00091                                            CodeModel::Model CM,
00092                                            CodeGenOpt::Level OL)
00093   : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
00094 }