LLVM 24.0.0git
MSP430Subtarget.cpp
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the MSP430 specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#include "MSP430Subtarget.h"
15#include "MSP430TargetMachine.h"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "msp430-subtarget"
22
23#define GET_SUBTARGETINFO_TARGET_DESC
24#define GET_SUBTARGETINFO_CTOR
25#include "MSP430GenSubtargetInfo.inc"
26
27#define OPTIONS_STRUCT_DEFS
28#include "MSP430Options.inc"
29
30void MSP430Subtarget::anchor() { }
31
34 ExtendedInsts = false;
35 HWMultMode = MSP430::HWMult::None;
36
37 StringRef CPUName = CPU;
38 if (CPUName.empty())
39 CPUName = "msp430";
40
41 ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
42
43 if (CLOpts.hwmult != MSP430::HWMult::None)
44 HWMultMode = CLOpts.hwmult;
45
46 return *this;
47}
48
49MSP430Subtarget::MSP430Subtarget(const Triple &TT, const std::string &CPU,
50 const std::string &FS,
51 const MSP430TargetMachine &TM)
52 : MSP430GenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
53 CLOpts(TM.getCLOpts()),
54 InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
55 FrameLowering(*this) {
56 TSInfo = std::make_unique<MSP430SelectionDAGInfo>();
57}
58
60
62 return TSInfo.get();
63}
64
66 if (hasHWMult16()) {
67 const struct {
68 const RTLIB::Libcall Op;
69 const RTLIB::LibcallImpl Impl;
70 } LibraryCalls[] = {
71 // Integer Multiply - EABI Table 9
72 {RTLIB::MUL_I16, RTLIB::impl___mspabi_mpyi_hw},
73 {RTLIB::MUL_I32, RTLIB::impl___mspabi_mpyl_hw},
74 {RTLIB::MUL_I64, RTLIB::impl___mspabi_mpyll_hw},
75 // TODO The __mspabi_mpysl*_hw functions ARE implemented in libgcc
76 // TODO The __mspabi_mpyul*_hw functions ARE implemented in libgcc
77 };
78 for (const auto &LC : LibraryCalls) {
79 Info.setLibcallImpl(LC.Op, LC.Impl);
80 }
81 } else if (hasHWMult32()) {
82 const struct {
83 const RTLIB::Libcall Op;
84 const RTLIB::LibcallImpl Impl;
85 } LibraryCalls[] = {
86 // Integer Multiply - EABI Table 9
87 {RTLIB::MUL_I16, RTLIB::impl___mspabi_mpyi_hw},
88 {RTLIB::MUL_I32, RTLIB::impl___mspabi_mpyl_hw32},
89 {RTLIB::MUL_I64, RTLIB::impl___mspabi_mpyll_hw32},
90 // TODO The __mspabi_mpysl*_hw32 functions ARE implemented in libgcc
91 // TODO The __mspabi_mpyul*_hw32 functions ARE implemented in libgcc
92 };
93 for (const auto &LC : LibraryCalls) {
94 Info.setLibcallImpl(LC.Op, LC.Impl);
95 }
96 } else if (hasHWMultF5()) {
97 const struct {
98 const RTLIB::Libcall Op;
99 const RTLIB::LibcallImpl Impl;
100 } LibraryCalls[] = {
101 // Integer Multiply - EABI Table 9
102 {RTLIB::MUL_I16, RTLIB::impl___mspabi_mpyi_f5hw},
103 {RTLIB::MUL_I32, RTLIB::impl___mspabi_mpyl_f5hw},
104 {RTLIB::MUL_I64, RTLIB::impl___mspabi_mpyll_f5hw},
105 // TODO The __mspabi_mpysl*_f5hw functions ARE implemented in libgcc
106 // TODO The __mspabi_mpyul*_f5hw functions ARE implemented in libgcc
107 };
108 for (const auto &LC : LibraryCalls) {
109 Info.setLibcallImpl(LC.Op, LC.Impl);
110 }
111 } else { // NoHWMult
112 const struct {
113 const RTLIB::Libcall Op;
114 const RTLIB::LibcallImpl Impl;
115 } LibraryCalls[] = {
116 // Integer Multiply - EABI Table 9
117 {RTLIB::MUL_I16, RTLIB::impl___mspabi_mpyi},
118 {RTLIB::MUL_I32, RTLIB::impl___mspabi_mpyl},
119 {RTLIB::MUL_I64, RTLIB::impl___mspabi_mpyll},
120 // The __mspabi_mpysl* functions are NOT implemented in libgcc
121 // The __mspabi_mpyul* functions are NOT implemented in libgcc
122 };
123 for (const auto &LC : LibraryCalls) {
124 Info.setLibcallImpl(LC.Op, LC.Impl);
125 }
126 }
127
128 // The generic soft-float/integer helper routines (__addsf3, __divli, ...)
129 // exist in msp430 libgcc alongside the __mspabi_* variants, so both are
130 // available. The __mspabi_* variants are the one that should be used.
131 static const struct {
132 const RTLIB::Libcall Op;
133 const RTLIB::LibcallImpl Impl;
134 } EABISelected[] = {
135 // Floating point conversions - EABI Table 6.
136 {RTLIB::FPROUND_F64_F32, RTLIB::impl___mspabi_cvtdf},
137 {RTLIB::FPEXT_F32_F64, RTLIB::impl___mspabi_cvtfd},
138 {RTLIB::FPTOSINT_F64_I32, RTLIB::impl___mspabi_fixdli},
139 {RTLIB::FPTOSINT_F64_I64, RTLIB::impl___mspabi_fixdlli},
140 {RTLIB::FPTOUINT_F64_I32, RTLIB::impl___mspabi_fixdul},
141 {RTLIB::FPTOUINT_F64_I64, RTLIB::impl___mspabi_fixdull},
142 {RTLIB::FPTOSINT_F32_I32, RTLIB::impl___mspabi_fixfli},
143 {RTLIB::FPTOSINT_F32_I64, RTLIB::impl___mspabi_fixflli},
144 {RTLIB::FPTOUINT_F32_I32, RTLIB::impl___mspabi_fixful},
145 {RTLIB::FPTOUINT_F32_I64, RTLIB::impl___mspabi_fixfull},
146 {RTLIB::SINTTOFP_I32_F64, RTLIB::impl___mspabi_fltlid},
147 {RTLIB::SINTTOFP_I64_F64, RTLIB::impl___mspabi_fltllid},
148 {RTLIB::UINTTOFP_I32_F64, RTLIB::impl___mspabi_fltuld},
149 {RTLIB::UINTTOFP_I64_F64, RTLIB::impl___mspabi_fltulld},
150 {RTLIB::SINTTOFP_I32_F32, RTLIB::impl___mspabi_fltlif},
151 {RTLIB::SINTTOFP_I64_F32, RTLIB::impl___mspabi_fltllif},
152 {RTLIB::UINTTOFP_I32_F32, RTLIB::impl___mspabi_fltulf},
153 {RTLIB::UINTTOFP_I64_F32, RTLIB::impl___mspabi_fltullf},
154 // Floating point comparisons - EABI Table 7. A single three-way compare
155 // symbol serves every predicate.
156 {RTLIB::FCMP3_PRED_OEQ_F64, RTLIB::impl___mspabi_cmpd},
157 {RTLIB::FCMP3_PRED_UNE_F64, RTLIB::impl___mspabi_cmpd},
158 {RTLIB::FCMP3_PRED_OGE_F64, RTLIB::impl___mspabi_cmpd},
159 {RTLIB::FCMP3_PRED_OLT_F64, RTLIB::impl___mspabi_cmpd},
160 {RTLIB::FCMP3_PRED_OLE_F64, RTLIB::impl___mspabi_cmpd},
161 {RTLIB::FCMP3_PRED_OGT_F64, RTLIB::impl___mspabi_cmpd},
162 {RTLIB::FCMP3_PRED_OEQ_F32, RTLIB::impl___mspabi_cmpf},
163 {RTLIB::FCMP3_PRED_UNE_F32, RTLIB::impl___mspabi_cmpf},
164 {RTLIB::FCMP3_PRED_OGE_F32, RTLIB::impl___mspabi_cmpf},
165 {RTLIB::FCMP3_PRED_OLT_F32, RTLIB::impl___mspabi_cmpf},
166 {RTLIB::FCMP3_PRED_OLE_F32, RTLIB::impl___mspabi_cmpf},
167 {RTLIB::FCMP3_PRED_OGT_F32, RTLIB::impl___mspabi_cmpf},
168 // Floating point arithmetic - EABI Table 8.
169 {RTLIB::ADD_F64, RTLIB::impl___mspabi_addd},
170 {RTLIB::SUB_F64, RTLIB::impl___mspabi_subd},
171 {RTLIB::MUL_F64, RTLIB::impl___mspabi_mpyd},
172 {RTLIB::DIV_F64, RTLIB::impl___mspabi_divd},
173 {RTLIB::ADD_F32, RTLIB::impl___mspabi_addf},
174 {RTLIB::SUB_F32, RTLIB::impl___mspabi_subf},
175 {RTLIB::MUL_F32, RTLIB::impl___mspabi_mpyf},
176 {RTLIB::DIV_F32, RTLIB::impl___mspabi_divf},
177 // Universal Integer Operations - EABI Table 9.
178 {RTLIB::SDIV_I16, RTLIB::impl___mspabi_divi},
179 {RTLIB::SDIV_I32, RTLIB::impl___mspabi_divli},
180 {RTLIB::SDIV_I64, RTLIB::impl___mspabi_divlli},
181 {RTLIB::UDIV_I16, RTLIB::impl___mspabi_divu},
182 {RTLIB::UDIV_I32, RTLIB::impl___mspabi_divul},
183 {RTLIB::UDIV_I64, RTLIB::impl___mspabi_divull},
184 {RTLIB::SREM_I16, RTLIB::impl___mspabi_remi},
185 {RTLIB::SREM_I32, RTLIB::impl___mspabi_remli},
186 {RTLIB::SREM_I64, RTLIB::impl___mspabi_remlli},
187 {RTLIB::UREM_I16, RTLIB::impl___mspabi_remu},
188 {RTLIB::UREM_I32, RTLIB::impl___mspabi_remul},
189 {RTLIB::UREM_I64, RTLIB::impl___mspabi_remull},
190 // Bitwise Operations - EABI Table 10.
191 {RTLIB::SHL_I32, RTLIB::impl___mspabi_slll},
192 {RTLIB::SRA_I32, RTLIB::impl___mspabi_sral},
193 };
194 for (const auto &LC : EABISelected)
195 Info.setLibcallImpl(LC.Op, LC.Impl);
196}
Tracks which library functions to use for a particular subtarget or function.
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
~MSP430Subtarget() override
MSP430Subtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
MSP430Subtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const MSP430TargetMachine &TM)
This constructor initializes the data members to match that of the specified triple.
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
const MSP430Options & getCLOpts() const
void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
This is an optimization pass for GlobalISel generic memory operations.
DWARFExpression::Operation Op