Path: blob/main/contrib/llvm-project/llvm/lib/Target/MSP430/MSP430TargetMachine.cpp
35269 views
//===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Top-level implementation for the MSP430 target.9//10//===----------------------------------------------------------------------===//1112#include "MSP430TargetMachine.h"13#include "MSP430.h"14#include "MSP430MachineFunctionInfo.h"15#include "TargetInfo/MSP430TargetInfo.h"16#include "llvm/CodeGen/Passes.h"17#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"18#include "llvm/CodeGen/TargetPassConfig.h"19#include "llvm/MC/MCAsmInfo.h"20#include "llvm/MC/TargetRegistry.h"21#include <optional>22using namespace llvm;2324extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMSP430Target() {25// Register the target.26RegisterTargetMachine<MSP430TargetMachine> X(getTheMSP430Target());27PassRegistry &PR = *PassRegistry::getPassRegistry();28initializeMSP430DAGToDAGISelLegacyPass(PR);29}3031static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {32return RM.value_or(Reloc::Static);33}3435static std::string computeDataLayout(const Triple &TT, StringRef CPU,36const TargetOptions &Options) {37return "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16";38}3940MSP430TargetMachine::MSP430TargetMachine(const Target &T, const Triple &TT,41StringRef CPU, StringRef FS,42const TargetOptions &Options,43std::optional<Reloc::Model> RM,44std::optional<CodeModel::Model> CM,45CodeGenOptLevel OL, bool JIT)46: LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options), TT, CPU, FS,47Options, getEffectiveRelocModel(RM),48getEffectiveCodeModel(CM, CodeModel::Small), OL),49TLOF(std::make_unique<TargetLoweringObjectFileELF>()),50Subtarget(TT, std::string(CPU), std::string(FS), *this) {51initAsmInfo();52}5354MSP430TargetMachine::~MSP430TargetMachine() = default;5556namespace {57/// MSP430 Code Generator Pass Configuration Options.58class MSP430PassConfig : public TargetPassConfig {59public:60MSP430PassConfig(MSP430TargetMachine &TM, PassManagerBase &PM)61: TargetPassConfig(TM, PM) {}6263MSP430TargetMachine &getMSP430TargetMachine() const {64return getTM<MSP430TargetMachine>();65}6667void addIRPasses() override;68bool addInstSelector() override;69void addPreEmitPass() override;70};71} // namespace7273TargetPassConfig *MSP430TargetMachine::createPassConfig(PassManagerBase &PM) {74return new MSP430PassConfig(*this, PM);75}7677MachineFunctionInfo *MSP430TargetMachine::createMachineFunctionInfo(78BumpPtrAllocator &Allocator, const Function &F,79const TargetSubtargetInfo *STI) const {80return MSP430MachineFunctionInfo::create<MSP430MachineFunctionInfo>(Allocator,81F, STI);82}8384void MSP430PassConfig::addIRPasses() {85addPass(createAtomicExpandLegacyPass());8687TargetPassConfig::addIRPasses();88}8990bool MSP430PassConfig::addInstSelector() {91// Install an instruction selector.92addPass(createMSP430ISelDag(getMSP430TargetMachine(), getOptLevel()));93return false;94}9596void MSP430PassConfig::addPreEmitPass() {97// Must run branch selection immediately preceding the asm printer.98addPass(createMSP430BranchSelectionPass());99}100101102