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