blob: 757dab2f59eff3374b9b424abcca22fa3b3886ef [file] [log] [blame]
Anton Korobeynikov10138002009-05-03 12:57:15 +00001//===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Anton Korobeynikov10138002009-05-03 12:57:15 +00006//
7//===----------------------------------------------------------------------===//
8//
9// Top-level implementation for the MSP430 target.
10//
11//===----------------------------------------------------------------------===//
12
Anton Korobeynikov10138002009-05-03 12:57:15 +000013#include "MSP430TargetMachine.h"
Craig Topperb25fda92012-03-17 18:46:09 +000014#include "MSP430.h"
Anton Korobeynikov10138002009-05-03 12:57:15 +000015#include "llvm/CodeGen/Passes.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000016#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
Matthias Braun31d19d42016-05-10 03:21:59 +000017#include "llvm/CodeGen/TargetPassConfig.h"
Chandler Carruth30d69c22015-02-13 10:01:29 +000018#include "llvm/IR/LegacyPassManager.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000019#include "llvm/MC/MCAsmInfo.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.
Mehdi Aminif42454b2016-10-09 23:00:34 +000025 RegisterTargetMachine<MSP430TargetMachine> X(getTheMSP430Target());
Anton Korobeynikovc1524d42009-08-14 19:06:50 +000026}
27
Rafael Espindola8c34dd82016-05-18 22:04:49 +000028static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
29 if (!RM.hasValue())
30 return Reloc::Static;
31 return *RM;
32}
33
Vadzim Dambrouski9e0d3872017-06-23 21:11:45 +000034static std::string computeDataLayout(const Triple &TT, StringRef CPU,
35 const TargetOptions &Options) {
36 return "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16";
37}
38
Daniel Sanders3e5de882015-06-11 19:41:26 +000039MSP430TargetMachine::MSP430TargetMachine(const Target &T, const Triple &TT,
Eric Christopher1f86cca2014-06-27 01:14:54 +000040 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000041 const TargetOptions &Options,
Rafael Espindola8c34dd82016-05-18 22:04:49 +000042 Optional<Reloc::Model> RM,
Rafael Espindola79e238a2017-08-03 02:16:21 +000043 Optional<CodeModel::Model> CM,
44 CodeGenOpt::Level OL, bool JIT)
Matthias Braunbb8507e2017-10-12 22:57:28 +000045 : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options), TT, CPU, FS,
46 Options, getEffectiveRelocModel(RM),
David Greenca29c272018-12-07 12:10:23 +000047 getEffectiveCodeModel(CM, CodeModel::Small), OL),
Aditya Nandakumara2719322014-11-13 09:26:31 +000048 TLOF(make_unique<TargetLoweringObjectFileELF>()),
Daniel Sanders3e5de882015-06-11 19:41:26 +000049 Subtarget(TT, CPU, FS, *this) {
Rafael Espindola227144c2013-05-13 01:16:13 +000050 initAsmInfo();
51}
Anton Korobeynikov10138002009-05-03 12:57:15 +000052
Reid Kleckner357600e2014-11-20 23:37:18 +000053MSP430TargetMachine::~MSP430TargetMachine() {}
54
Andrew Trickccb67362012-02-03 05:12:41 +000055namespace {
56/// MSP430 Code Generator Pass Configuration Options.
57class MSP430PassConfig : public TargetPassConfig {
58public:
Matthias Braun5e394c32017-05-30 21:36:41 +000059 MSP430PassConfig(MSP430TargetMachine &TM, PassManagerBase &PM)
Andrew Trickf8ea1082012-02-04 02:56:59 +000060 : TargetPassConfig(TM, PM) {}
Anton Korobeynikov10138002009-05-03 12:57:15 +000061
Andrew Trickccb67362012-02-03 05:12:41 +000062 MSP430TargetMachine &getMSP430TargetMachine() const {
63 return getTM<MSP430TargetMachine>();
64 }
65
Craig Topper6f9e59e2014-04-29 07:58:09 +000066 bool addInstSelector() override;
Matthias Braun7e37a5f2014-12-11 21:26:47 +000067 void addPreEmitPass() override;
Andrew Trickccb67362012-02-03 05:12:41 +000068};
69} // namespace
70
Andrew Trickf8ea1082012-02-04 02:56:59 +000071TargetPassConfig *MSP430TargetMachine::createPassConfig(PassManagerBase &PM) {
Matthias Braun5e394c32017-05-30 21:36:41 +000072 return new MSP430PassConfig(*this, PM);
Andrew Trickccb67362012-02-03 05:12:41 +000073}
74
75bool MSP430PassConfig::addInstSelector() {
Anton Korobeynikov10138002009-05-03 12:57:15 +000076 // Install an instruction selector.
Bob Wilsonbbd38dd2012-07-02 19:48:31 +000077 addPass(createMSP430ISelDag(getMSP430TargetMachine(), getOptLevel()));
Anton Korobeynikov10138002009-05-03 12:57:15 +000078 return false;
79}
80
Matthias Braun7e37a5f2014-12-11 21:26:47 +000081void MSP430PassConfig::addPreEmitPass() {
Anton Korobeynikovce52fd52010-01-15 21:19:05 +000082 // Must run branch selection immediately preceding the asm printer.
Matthias Braun7e37a5f2014-12-11 21:26:47 +000083 addPass(createMSP430BranchSelectionPass(), false);
Anton Korobeynikovce52fd52010-01-15 21:19:05 +000084}