2009-05-03 20:57:15 +08:00
|
|
|
//===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-05-03 20:57:15 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Top-level implementation for the MSP430 target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MSP430TargetMachine.h"
|
2012-03-18 02:46:09 +08:00
|
|
|
#include "MSP430.h"
|
2019-05-15 07:45:18 +08:00
|
|
|
#include "TargetInfo/MSP430TargetInfo.h"
|
2009-05-03 20:57:15 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
|
2016-05-10 11:21:59 +08:00
|
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
2015-02-13 18:01:29 +08:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2009-08-23 04:48:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2009-05-03 20:57:15 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2019-06-11 11:21:13 +08:00
|
|
|
extern "C" void LLVMInitializeMSP430Target() {
|
2009-08-15 03:06:50 +08:00
|
|
|
// Register the target.
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterTargetMachine<MSP430TargetMachine> X(getTheMSP430Target());
|
2009-08-15 03:06:50 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:04:49 +08:00
|
|
|
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
|
|
|
|
if (!RM.hasValue())
|
|
|
|
return Reloc::Static;
|
|
|
|
return *RM;
|
|
|
|
}
|
|
|
|
|
2017-06-24 05:11:45 +08:00
|
|
|
static std::string computeDataLayout(const Triple &TT, StringRef CPU,
|
|
|
|
const TargetOptions &Options) {
|
|
|
|
return "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16";
|
|
|
|
}
|
|
|
|
|
2015-06-12 03:41:26 +08:00
|
|
|
MSP430TargetMachine::MSP430TargetMachine(const Target &T, const Triple &TT,
|
2014-06-27 09:14:54 +08:00
|
|
|
StringRef CPU, StringRef FS,
|
2011-12-03 06:16:29 +08:00
|
|
|
const TargetOptions &Options,
|
2016-05-19 06:04:49 +08:00
|
|
|
Optional<Reloc::Model> RM,
|
2017-08-03 10:16:21 +08:00
|
|
|
Optional<CodeModel::Model> CM,
|
|
|
|
CodeGenOpt::Level OL, bool JIT)
|
2017-10-13 06:57:28 +08:00
|
|
|
: LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options), TT, CPU, FS,
|
|
|
|
Options, getEffectiveRelocModel(RM),
|
2018-12-07 20:10:23 +08:00
|
|
|
getEffectiveCodeModel(CM, CodeModel::Small), OL),
|
2019-08-15 23:54:37 +08:00
|
|
|
TLOF(std::make_unique<TargetLoweringObjectFileELF>()),
|
2015-06-12 03:41:26 +08:00
|
|
|
Subtarget(TT, CPU, FS, *this) {
|
2013-05-13 09:16:13 +08:00
|
|
|
initAsmInfo();
|
|
|
|
}
|
2009-05-03 20:57:15 +08:00
|
|
|
|
2014-11-21 07:37:18 +08:00
|
|
|
MSP430TargetMachine::~MSP430TargetMachine() {}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
namespace {
|
|
|
|
/// MSP430 Code Generator Pass Configuration Options.
|
|
|
|
class MSP430PassConfig : public TargetPassConfig {
|
|
|
|
public:
|
2017-05-31 05:36:41 +08:00
|
|
|
MSP430PassConfig(MSP430TargetMachine &TM, PassManagerBase &PM)
|
2012-02-04 10:56:59 +08:00
|
|
|
: TargetPassConfig(TM, PM) {}
|
2009-05-03 20:57:15 +08:00
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
MSP430TargetMachine &getMSP430TargetMachine() const {
|
|
|
|
return getTM<MSP430TargetMachine>();
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:09 +08:00
|
|
|
bool addInstSelector() override;
|
2014-12-12 05:26:47 +08:00
|
|
|
void addPreEmitPass() override;
|
2012-02-03 13:12:41 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2012-02-04 10:56:59 +08:00
|
|
|
TargetPassConfig *MSP430TargetMachine::createPassConfig(PassManagerBase &PM) {
|
2017-05-31 05:36:41 +08:00
|
|
|
return new MSP430PassConfig(*this, PM);
|
2012-02-03 13:12:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MSP430PassConfig::addInstSelector() {
|
2009-05-03 20:57:15 +08:00
|
|
|
// Install an instruction selector.
|
2012-07-03 03:48:31 +08:00
|
|
|
addPass(createMSP430ISelDag(getMSP430TargetMachine(), getOptLevel()));
|
2009-05-03 20:57:15 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-12 05:26:47 +08:00
|
|
|
void MSP430PassConfig::addPreEmitPass() {
|
2010-01-16 05:19:05 +08:00
|
|
|
// Must run branch selection immediately preceding the asm printer.
|
2014-12-12 05:26:47 +08:00
|
|
|
addPass(createMSP430BranchSelectionPass(), false);
|
2010-01-16 05:19:05 +08:00
|
|
|
}
|