135 lines · cpp
1//===-- MSP430Subtarget.cpp - MSP430 Subtarget Information ----------------===//2//3// 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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements the MSP430 specific subclass of TargetSubtargetInfo.10//11//===----------------------------------------------------------------------===//12 13#include "MSP430Subtarget.h"14#include "MSP430SelectionDAGInfo.h"15#include "llvm/MC/TargetRegistry.h"16 17using namespace llvm;18 19#define DEBUG_TYPE "msp430-subtarget"20 21static cl::opt<MSP430Subtarget::HWMultEnum>22HWMultModeOption("mhwmult", cl::Hidden,23 cl::desc("Hardware multiplier use mode for MSP430"),24 cl::init(MSP430Subtarget::NoHWMult),25 cl::values(26 clEnumValN(MSP430Subtarget::NoHWMult, "none",27 "Do not use hardware multiplier"),28 clEnumValN(MSP430Subtarget::HWMult16, "16bit",29 "Use 16-bit hardware multiplier"),30 clEnumValN(MSP430Subtarget::HWMult32, "32bit",31 "Use 32-bit hardware multiplier"),32 clEnumValN(MSP430Subtarget::HWMultF5, "f5series",33 "Use F5 series hardware multiplier")));34 35#define GET_SUBTARGETINFO_TARGET_DESC36#define GET_SUBTARGETINFO_CTOR37#include "MSP430GenSubtargetInfo.inc"38 39void MSP430Subtarget::anchor() { }40 41MSP430Subtarget &42MSP430Subtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {43 ExtendedInsts = false;44 HWMultMode = NoHWMult;45 46 StringRef CPUName = CPU;47 if (CPUName.empty())48 CPUName = "msp430";49 50 ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);51 52 if (HWMultModeOption != NoHWMult)53 HWMultMode = HWMultModeOption;54 55 return *this;56}57 58MSP430Subtarget::MSP430Subtarget(const Triple &TT, const std::string &CPU,59 const std::string &FS, const TargetMachine &TM)60 : MSP430GenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),61 InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),62 FrameLowering(*this) {63 TSInfo = std::make_unique<MSP430SelectionDAGInfo>();64}65 66MSP430Subtarget::~MSP430Subtarget() = default;67 68const SelectionDAGTargetInfo *MSP430Subtarget::getSelectionDAGInfo() const {69 return TSInfo.get();70}71 72void MSP430Subtarget::initLibcallLoweringInfo(LibcallLoweringInfo &Info) const {73 if (hasHWMult16()) {74 const struct {75 const RTLIB::Libcall Op;76 const RTLIB::LibcallImpl Impl;77 } LibraryCalls[] = {78 // Integer Multiply - EABI Table 979 {RTLIB::MUL_I16, RTLIB::impl___mspabi_mpyi_hw},80 {RTLIB::MUL_I32, RTLIB::impl___mspabi_mpyl_hw},81 {RTLIB::MUL_I64, RTLIB::impl___mspabi_mpyll_hw},82 // TODO The __mspabi_mpysl*_hw functions ARE implemented in libgcc83 // TODO The __mspabi_mpyul*_hw functions ARE implemented in libgcc84 };85 for (const auto &LC : LibraryCalls) {86 Info.setLibcallImpl(LC.Op, LC.Impl);87 }88 } else if (hasHWMult32()) {89 const struct {90 const RTLIB::Libcall Op;91 const RTLIB::LibcallImpl Impl;92 } LibraryCalls[] = {93 // Integer Multiply - EABI Table 994 {RTLIB::MUL_I16, RTLIB::impl___mspabi_mpyi_hw},95 {RTLIB::MUL_I32, RTLIB::impl___mspabi_mpyl_hw32},96 {RTLIB::MUL_I64, RTLIB::impl___mspabi_mpyll_hw32},97 // TODO The __mspabi_mpysl*_hw32 functions ARE implemented in libgcc98 // TODO The __mspabi_mpyul*_hw32 functions ARE implemented in libgcc99 };100 for (const auto &LC : LibraryCalls) {101 Info.setLibcallImpl(LC.Op, LC.Impl);102 }103 } else if (hasHWMultF5()) {104 const struct {105 const RTLIB::Libcall Op;106 const RTLIB::LibcallImpl Impl;107 } LibraryCalls[] = {108 // Integer Multiply - EABI Table 9109 {RTLIB::MUL_I16, RTLIB::impl___mspabi_mpyi_f5hw},110 {RTLIB::MUL_I32, RTLIB::impl___mspabi_mpyl_f5hw},111 {RTLIB::MUL_I64, RTLIB::impl___mspabi_mpyll_f5hw},112 // TODO The __mspabi_mpysl*_f5hw functions ARE implemented in libgcc113 // TODO The __mspabi_mpyul*_f5hw functions ARE implemented in libgcc114 };115 for (const auto &LC : LibraryCalls) {116 Info.setLibcallImpl(LC.Op, LC.Impl);117 }118 } else { // NoHWMult119 const struct {120 const RTLIB::Libcall Op;121 const RTLIB::LibcallImpl Impl;122 } LibraryCalls[] = {123 // Integer Multiply - EABI Table 9124 {RTLIB::MUL_I16, RTLIB::impl___mspabi_mpyi},125 {RTLIB::MUL_I32, RTLIB::impl___mspabi_mpyl},126 {RTLIB::MUL_I64, RTLIB::impl___mspabi_mpyll},127 // The __mspabi_mpysl* functions are NOT implemented in libgcc128 // The __mspabi_mpyul* functions are NOT implemented in libgcc129 };130 for (const auto &LC : LibraryCalls) {131 Info.setLibcallImpl(LC.Op, LC.Impl);132 }133 }134}135