blob: 941f3da87eaa5e9ecb27ba2616f97c4c670624a4 [file] [log] [blame]
Anton Korobeynikov10138002009-05-03 12:57:15 +00001//===-- 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
Anton Korobeynikov10138002009-05-03 12:57:15 +000014#include "MSP430TargetMachine.h"
Craig Topperb25fda92012-03-17 18:46:09 +000015#include "MSP430.h"
Anton Korobeynikov10138002009-05-03 12:57:15 +000016#include "llvm/CodeGen/Passes.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000017#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000018#include "llvm/MC/MCAsmInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000019#include "llvm/PassManager.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000020#include "llvm/Support/TargetRegistry.h"
Anton Korobeynikov10138002009-05-03 12:57:15 +000021using namespace llvm;
22
Anton Korobeynikovc1524d42009-08-14 19:06:50 +000023extern "C" void LLVMInitializeMSP430Target() {
24 // Register the target.
25 RegisterTargetMachine<MSP430TargetMachine> X(TheMSP430Target);
Anton Korobeynikovc1524d42009-08-14 19:06:50 +000026}
27
Eric Christopher1f86cca2014-06-27 01:14:54 +000028MSP430TargetMachine::MSP430TargetMachine(const Target &T, StringRef TT,
29 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000030 const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +000031 Reloc::Model RM, CodeModel::Model CM,
32 CodeGenOpt::Level OL)
Eric Christopher1f86cca2014-06-27 01:14:54 +000033 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
Aditya Nandakumara2719322014-11-13 09:26:31 +000034 TLOF(make_unique<TargetLoweringObjectFileELF>()),
Eric Christopher8b770652015-01-26 19:03:15 +000035 // FIXME: Check DataLayout string.
36 DL("e-m:e-p:16:16-i32:16:32-a:16-n8:16"), Subtarget(TT, CPU, FS, *this) {
Rafael Espindola227144c2013-05-13 01:16:13 +000037 initAsmInfo();
38}
Anton Korobeynikov10138002009-05-03 12:57:15 +000039
Reid Kleckner357600e2014-11-20 23:37:18 +000040MSP430TargetMachine::~MSP430TargetMachine() {}
41
Andrew Trickccb67362012-02-03 05:12:41 +000042namespace {
43/// MSP430 Code Generator Pass Configuration Options.
44class MSP430PassConfig : public TargetPassConfig {
45public:
Andrew Trickf8ea1082012-02-04 02:56:59 +000046 MSP430PassConfig(MSP430TargetMachine *TM, PassManagerBase &PM)
47 : TargetPassConfig(TM, PM) {}
Anton Korobeynikov10138002009-05-03 12:57:15 +000048
Andrew Trickccb67362012-02-03 05:12:41 +000049 MSP430TargetMachine &getMSP430TargetMachine() const {
50 return getTM<MSP430TargetMachine>();
51 }
52
Craig Topper6f9e59e2014-04-29 07:58:09 +000053 bool addInstSelector() override;
Matthias Braun7e37a5f2014-12-11 21:26:47 +000054 void addPreEmitPass() override;
Andrew Trickccb67362012-02-03 05:12:41 +000055};
56} // namespace
57
Andrew Trickf8ea1082012-02-04 02:56:59 +000058TargetPassConfig *MSP430TargetMachine::createPassConfig(PassManagerBase &PM) {
59 return new MSP430PassConfig(this, PM);
Andrew Trickccb67362012-02-03 05:12:41 +000060}
61
62bool MSP430PassConfig::addInstSelector() {
Anton Korobeynikov10138002009-05-03 12:57:15 +000063 // Install an instruction selector.
Bob Wilsonbbd38dd2012-07-02 19:48:31 +000064 addPass(createMSP430ISelDag(getMSP430TargetMachine(), getOptLevel()));
Anton Korobeynikov10138002009-05-03 12:57:15 +000065 return false;
66}
67
Matthias Braun7e37a5f2014-12-11 21:26:47 +000068void MSP430PassConfig::addPreEmitPass() {
Anton Korobeynikovce52fd52010-01-15 21:19:05 +000069 // Must run branch selection immediately preceding the asm printer.
Matthias Braun7e37a5f2014-12-11 21:26:47 +000070 addPass(createMSP430BranchSelectionPass(), false);
Anton Korobeynikovce52fd52010-01-15 21:19:05 +000071}