LLVM API Documentation

MSP430TargetMachine.cpp
Go to the documentation of this file.
00001 //===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===//
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 // Top-level implementation for the MSP430 target.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "MSP430TargetMachine.h"
00015 #include "MSP430.h"
00016 #include "llvm/CodeGen/Passes.h"
00017 #include "llvm/MC/MCAsmInfo.h"
00018 #include "llvm/PassManager.h"
00019 #include "llvm/Support/TargetRegistry.h"
00020 using namespace llvm;
00021 
00022 extern "C" void LLVMInitializeMSP430Target() {
00023   // Register the target.
00024   RegisterTargetMachine<MSP430TargetMachine> X(TheMSP430Target);
00025 }
00026 
00027 MSP430TargetMachine::MSP430TargetMachine(const Target &T, StringRef TT,
00028                                          StringRef CPU, StringRef FS,
00029                                          const TargetOptions &Options,
00030                                          Reloc::Model RM, CodeModel::Model CM,
00031                                          CodeGenOpt::Level OL)
00032     : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
00033       Subtarget(TT, CPU, FS, *this) {
00034   initAsmInfo();
00035 }
00036 
00037 namespace {
00038 /// MSP430 Code Generator Pass Configuration Options.
00039 class MSP430PassConfig : public TargetPassConfig {
00040 public:
00041   MSP430PassConfig(MSP430TargetMachine *TM, PassManagerBase &PM)
00042     : TargetPassConfig(TM, PM) {}
00043 
00044   MSP430TargetMachine &getMSP430TargetMachine() const {
00045     return getTM<MSP430TargetMachine>();
00046   }
00047 
00048   bool addInstSelector() override;
00049   bool addPreEmitPass() override;
00050 };
00051 } // namespace
00052 
00053 TargetPassConfig *MSP430TargetMachine::createPassConfig(PassManagerBase &PM) {
00054   return new MSP430PassConfig(this, PM);
00055 }
00056 
00057 bool MSP430PassConfig::addInstSelector() {
00058   // Install an instruction selector.
00059   addPass(createMSP430ISelDag(getMSP430TargetMachine(), getOptLevel()));
00060   return false;
00061 }
00062 
00063 bool MSP430PassConfig::addPreEmitPass() {
00064   // Must run branch selection immediately preceding the asm printer.
00065   addPass(createMSP430BranchSelectionPass());
00066   return false;
00067 }