1 //===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===//
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 //===----------------------------------------------------------------------===//
10 // Top-level implementation for the MSP430 target.
12 //===----------------------------------------------------------------------===//
14 #include "MSP430TargetMachine.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"
24 extern "C" void LLVMInitializeMSP430Target() {
25 // Register the target.
26 RegisterTargetMachine<MSP430TargetMachine> X(getTheMSP430Target());
29 static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
35 MSP430TargetMachine::MSP430TargetMachine(const Target &T, const Triple &TT,
36 StringRef CPU, StringRef FS,
37 const TargetOptions &Options,
38 Optional<Reloc::Model> RM,
41 : LLVMTargetMachine(T, "e-m:e-p:16:16-i32:16:32-a:16-n8:16", TT, CPU, FS,
42 Options, getEffectiveRelocModel(RM), CM, OL),
43 TLOF(make_unique<TargetLoweringObjectFileELF>()),
44 // FIXME: Check DataLayout string.
45 Subtarget(TT, CPU, FS, *this) {
49 MSP430TargetMachine::~MSP430TargetMachine() {}
52 /// MSP430 Code Generator Pass Configuration Options.
53 class MSP430PassConfig : public TargetPassConfig {
55 MSP430PassConfig(MSP430TargetMachine *TM, PassManagerBase &PM)
56 : TargetPassConfig(TM, PM) {}
58 MSP430TargetMachine &getMSP430TargetMachine() const {
59 return getTM<MSP430TargetMachine>();
62 bool addInstSelector() override;
63 void addPreEmitPass() override;
67 TargetPassConfig *MSP430TargetMachine::createPassConfig(PassManagerBase &PM) {
68 return new MSP430PassConfig(this, PM);
71 bool MSP430PassConfig::addInstSelector() {
72 // Install an instruction selector.
73 addPass(createMSP430ISelDag(getMSP430TargetMachine(), getOptLevel()));
77 void MSP430PassConfig::addPreEmitPass() {
78 // Must run branch selection immediately preceding the asm printer.
79 addPass(createMSP430BranchSelectionPass(), false);