1f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov//===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===// 2f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// 3f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// The LLVM Compiler Infrastructure 4f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// 5f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// This file is distributed under the University of Illinois Open Source 6f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// License. See LICENSE.TXT for details. 7f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// 8f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov//===----------------------------------------------------------------------===// 9f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// 10f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// Top-level implementation for the MSP430 target. 11f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov// 12f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov//===----------------------------------------------------------------------===// 13f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov 14f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov#include "MSP430TargetMachine.h" 1579aa3417eb6f58d668aadfedf075240a41d35a26Craig Topper#include "MSP430.h" 16f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov#include "llvm/CodeGen/Passes.h" 17ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" 18ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/IR/LegacyPassManager.h" 19af76e592c7f9deff0e55c13dbb4a34f07f1c7f64Chris Lattner#include "llvm/MC/MCAsmInfo.h" 203e74d6fdd248e20a280f1dff3da9a6c689c2c4c3Evan Cheng#include "llvm/Support/TargetRegistry.h" 21f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikovusing namespace llvm; 22f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov 239b9014f2a088356e4ba814d7f0fd422af721f32dAnton Korobeynikovextern "C" void LLVMInitializeMSP430Target() { 249b9014f2a088356e4ba814d7f0fd422af721f32dAnton Korobeynikov // Register the target. 259b9014f2a088356e4ba814d7f0fd422af721f32dAnton Korobeynikov RegisterTargetMachine<MSP430TargetMachine> X(TheMSP430Target); 269b9014f2a088356e4ba814d7f0fd422af721f32dAnton Korobeynikov} 279b9014f2a088356e4ba814d7f0fd422af721f32dAnton Korobeynikov 286948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarMSP430TargetMachine::MSP430TargetMachine(const Target &T, const Triple &TT, 29c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines StringRef CPU, StringRef FS, 308a8d479214745c82ef00f08d4e4f1c173b5f9ce2Nick Lewycky const TargetOptions &Options, 31b95fc31aa2e5a0a0b9ee1909d1cb949577c5aa16Evan Cheng Reloc::Model RM, CodeModel::Model CM, 32b95fc31aa2e5a0a0b9ee1909d1cb949577c5aa16Evan Cheng CodeGenOpt::Level OL) 334c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar : LLVMTargetMachine(T, "e-m:e-p:16:16-i32:16:32-a:16-n8:16", TT, CPU, FS, 344c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar Options, RM, CM, OL), 3537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines TLOF(make_unique<TargetLoweringObjectFileELF>()), 36ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // FIXME: Check DataLayout string. 374c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar Subtarget(TT, CPU, FS, *this) { 384a971705bc6030dc2e4338b3cd5cffa2e0f88b7bRafael Espindola initAsmInfo(); 394a971705bc6030dc2e4338b3cd5cffa2e0f88b7bRafael Espindola} 40f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov 4137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen HinesMSP430TargetMachine::~MSP430TargetMachine() {} 4237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 43843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Tricknamespace { 44843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick/// MSP430 Code Generator Pass Configuration Options. 45843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trickclass MSP430PassConfig : public TargetPassConfig { 46843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trickpublic: 47061efcfb3e79899493d857f49e50d09f29037e0aAndrew Trick MSP430PassConfig(MSP430TargetMachine *TM, PassManagerBase &PM) 48061efcfb3e79899493d857f49e50d09f29037e0aAndrew Trick : TargetPassConfig(TM, PM) {} 49f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov 50843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick MSP430TargetMachine &getMSP430TargetMachine() const { 51843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick return getTM<MSP430TargetMachine>(); 52843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick } 53843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick 54dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines bool addInstSelector() override; 55ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines void addPreEmitPass() override; 56843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick}; 57843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick} // namespace 58843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick 59061efcfb3e79899493d857f49e50d09f29037e0aAndrew TrickTargetPassConfig *MSP430TargetMachine::createPassConfig(PassManagerBase &PM) { 60061efcfb3e79899493d857f49e50d09f29037e0aAndrew Trick return new MSP430PassConfig(this, PM); 61843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick} 62843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trick 63843ee2e6a46b2b2d74a84c2eea68dec35cb359ccAndrew Trickbool MSP430PassConfig::addInstSelector() { 64f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov // Install an instruction selector. 65564fbf6aff8fb95646a1290078a37c2d4dbe629fBob Wilson addPass(createMSP430ISelDag(getMSP430TargetMachine(), getOptLevel())); 66f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov return false; 67f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov} 68f2c3e179ecc2a6ebc259382828a5e5dc5a61d2f8Anton Korobeynikov 69ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesvoid MSP430PassConfig::addPreEmitPass() { 70702adaba6d7442f180c6bc0bec3a2b19e1169ed9Anton Korobeynikov // Must run branch selection immediately preceding the asm printer. 71ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines addPass(createMSP430BranchSelectionPass(), false); 72702adaba6d7442f180c6bc0bec3a2b19e1169ed9Anton Korobeynikov} 73