1 //===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===// 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 // Top-level implementation for the MSP430 target. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "MSP430TargetMachine.h" 15 #include "MSP430.h" 16 #include "llvm/CodeGen/Passes.h" 17 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" 18 #include "llvm/CodeGen/TargetPassConfig.h" 19 #include "llvm/IR/LegacyPassManager.h" 20 #include "llvm/MC/MCAsmInfo.h" 21 #include "llvm/Support/TargetRegistry.h" 22 using namespace llvm; 23 24 extern "C" void LLVMInitializeMSP430Target() { 25 // Register the target. 26 RegisterTargetMachine<MSP430TargetMachine> X(TheMSP430Target); 27 } 28 29 MSP430TargetMachine::MSP430TargetMachine(const Target &T, const Triple &TT, 30 StringRef CPU, StringRef FS, 31 const TargetOptions &Options, 32 Reloc::Model RM, CodeModel::Model CM, 33 CodeGenOpt::Level OL) 34 : LLVMTargetMachine(T, "e-m:e-p:16:16-i32:16:32-a:16-n8:16", TT, CPU, FS, 35 Options, RM, CM, OL), 36 TLOF(make_unique<TargetLoweringObjectFileELF>()), 37 // FIXME: Check DataLayout string. 38 Subtarget(TT, CPU, FS, *this) { 39 initAsmInfo(); 40 } 41 42 MSP430TargetMachine::~MSP430TargetMachine() {} 43 44 namespace { 45 /// MSP430 Code Generator Pass Configuration Options. 46 class MSP430PassConfig : public TargetPassConfig { 47 public: 48 MSP430PassConfig(MSP430TargetMachine *TM, PassManagerBase &PM) 49 : TargetPassConfig(TM, PM) {} 50 51 MSP430TargetMachine &getMSP430TargetMachine() const { 52 return getTM<MSP430TargetMachine>(); 53 } 54 55 bool addInstSelector() override; 56 void addPreEmitPass() override; 57 }; 58 } // namespace 59 60 TargetPassConfig *MSP430TargetMachine::createPassConfig(PassManagerBase &PM) { 61 return new MSP430PassConfig(this, PM); 62 } 63 64 bool MSP430PassConfig::addInstSelector() { 65 // Install an instruction selector. 66 addPass(createMSP430ISelDag(getMSP430TargetMachine(), getOptLevel())); 67 return false; 68 } 69 70 void MSP430PassConfig::addPreEmitPass() { 71 // Must run branch selection immediately preceding the asm printer. 72 addPass(createMSP430BranchSelectionPass(), false); 73 } 74