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"
14#include "MSP430SelectionDAGInfo.h"
15#include "MSP430TargetMachine.h"
16#include "llvm/Option/LibraryOptions.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
31MSP430Subtarget &
32MSP430Subtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
33 ExtendedInsts = false;
34 HWMultMode = MSP430::HWMult::None;
35
36 StringRef CPUName = CPU;
37 if (CPUName.empty())
38 CPUName = "msp430";
39
40 ParseSubtargetFeatures(CPU: 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
58MSP430Subtarget::~MSP430Subtarget() = default;
59
60const SelectionDAGTargetInfo *MSP430Subtarget::getSelectionDAGInfo() const {
61 return TSInfo.get();
62}
63
64void MSP430Subtarget::initLibcallLoweringInfo(LibcallLoweringInfo &Info) const {
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 {.Op: RTLIB::MUL_I16, .Impl: RTLIB::impl___mspabi_mpyi_hw},
72 {.Op: RTLIB::MUL_I32, .Impl: RTLIB::impl___mspabi_mpyl_hw},
73 {.Op: RTLIB::MUL_I64, .Impl: 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(Call: LC.Op, Impl: 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 {.Op: RTLIB::MUL_I16, .Impl: RTLIB::impl___mspabi_mpyi_hw},
87 {.Op: RTLIB::MUL_I32, .Impl: RTLIB::impl___mspabi_mpyl_hw32},
88 {.Op: RTLIB::MUL_I64, .Impl: 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(Call: LC.Op, Impl: 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 {.Op: RTLIB::MUL_I16, .Impl: RTLIB::impl___mspabi_mpyi_f5hw},
102 {.Op: RTLIB::MUL_I32, .Impl: RTLIB::impl___mspabi_mpyl_f5hw},
103 {.Op: RTLIB::MUL_I64, .Impl: 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(Call: LC.Op, Impl: 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 {.Op: RTLIB::MUL_I16, .Impl: RTLIB::impl___mspabi_mpyi},
117 {.Op: RTLIB::MUL_I32, .Impl: RTLIB::impl___mspabi_mpyl},
118 {.Op: RTLIB::MUL_I64, .Impl: 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(Call: LC.Op, Impl: 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 {.Op: RTLIB::FPROUND_F64_F32, .Impl: RTLIB::impl___mspabi_cvtdf},
136 {.Op: RTLIB::FPEXT_F32_F64, .Impl: RTLIB::impl___mspabi_cvtfd},
137 {.Op: RTLIB::FPTOSINT_F64_I32, .Impl: RTLIB::impl___mspabi_fixdli},
138 {.Op: RTLIB::FPTOSINT_F64_I64, .Impl: RTLIB::impl___mspabi_fixdlli},
139 {.Op: RTLIB::FPTOUINT_F64_I32, .Impl: RTLIB::impl___mspabi_fixdul},
140 {.Op: RTLIB::FPTOUINT_F64_I64, .Impl: RTLIB::impl___mspabi_fixdull},
141 {.Op: RTLIB::FPTOSINT_F32_I32, .Impl: RTLIB::impl___mspabi_fixfli},
142 {.Op: RTLIB::FPTOSINT_F32_I64, .Impl: RTLIB::impl___mspabi_fixflli},
143 {.Op: RTLIB::FPTOUINT_F32_I32, .Impl: RTLIB::impl___mspabi_fixful},
144 {.Op: RTLIB::FPTOUINT_F32_I64, .Impl: RTLIB::impl___mspabi_fixfull},
145 {.Op: RTLIB::SINTTOFP_I32_F64, .Impl: RTLIB::impl___mspabi_fltlid},
146 {.Op: RTLIB::SINTTOFP_I64_F64, .Impl: RTLIB::impl___mspabi_fltllid},
147 {.Op: RTLIB::UINTTOFP_I32_F64, .Impl: RTLIB::impl___mspabi_fltuld},
148 {.Op: RTLIB::UINTTOFP_I64_F64, .Impl: RTLIB::impl___mspabi_fltulld},
149 {.Op: RTLIB::SINTTOFP_I32_F32, .Impl: RTLIB::impl___mspabi_fltlif},
150 {.Op: RTLIB::SINTTOFP_I64_F32, .Impl: RTLIB::impl___mspabi_fltllif},
151 {.Op: RTLIB::UINTTOFP_I32_F32, .Impl: RTLIB::impl___mspabi_fltulf},
152 {.Op: RTLIB::UINTTOFP_I64_F32, .Impl: RTLIB::impl___mspabi_fltullf},
153 // Floating point comparisons - EABI Table 7. A single three-way compare
154 // symbol serves every predicate.
155 {.Op: RTLIB::FCMP3_PRED_OEQ_F64, .Impl: RTLIB::impl___mspabi_cmpd},
156 {.Op: RTLIB::FCMP3_PRED_UNE_F64, .Impl: RTLIB::impl___mspabi_cmpd},
157 {.Op: RTLIB::FCMP3_PRED_OGE_F64, .Impl: RTLIB::impl___mspabi_cmpd},
158 {.Op: RTLIB::FCMP3_PRED_OLT_F64, .Impl: RTLIB::impl___mspabi_cmpd},
159 {.Op: RTLIB::FCMP3_PRED_OLE_F64, .Impl: RTLIB::impl___mspabi_cmpd},
160 {.Op: RTLIB::FCMP3_PRED_OGT_F64, .Impl: RTLIB::impl___mspabi_cmpd},
161 {.Op: RTLIB::FCMP3_PRED_OEQ_F32, .Impl: RTLIB::impl___mspabi_cmpf},
162 {.Op: RTLIB::FCMP3_PRED_UNE_F32, .Impl: RTLIB::impl___mspabi_cmpf},
163 {.Op: RTLIB::FCMP3_PRED_OGE_F32, .Impl: RTLIB::impl___mspabi_cmpf},
164 {.Op: RTLIB::FCMP3_PRED_OLT_F32, .Impl: RTLIB::impl___mspabi_cmpf},
165 {.Op: RTLIB::FCMP3_PRED_OLE_F32, .Impl: RTLIB::impl___mspabi_cmpf},
166 {.Op: RTLIB::FCMP3_PRED_OGT_F32, .Impl: RTLIB::impl___mspabi_cmpf},
167 // Floating point arithmetic - EABI Table 8.
168 {.Op: RTLIB::ADD_F64, .Impl: RTLIB::impl___mspabi_addd},
169 {.Op: RTLIB::SUB_F64, .Impl: RTLIB::impl___mspabi_subd},
170 {.Op: RTLIB::MUL_F64, .Impl: RTLIB::impl___mspabi_mpyd},
171 {.Op: RTLIB::DIV_F64, .Impl: RTLIB::impl___mspabi_divd},
172 {.Op: RTLIB::ADD_F32, .Impl: RTLIB::impl___mspabi_addf},
173 {.Op: RTLIB::SUB_F32, .Impl: RTLIB::impl___mspabi_subf},
174 {.Op: RTLIB::MUL_F32, .Impl: RTLIB::impl___mspabi_mpyf},
175 {.Op: RTLIB::DIV_F32, .Impl: RTLIB::impl___mspabi_divf},
176 // Universal Integer Operations - EABI Table 9.
177 {.Op: RTLIB::SDIV_I16, .Impl: RTLIB::impl___mspabi_divi},
178 {.Op: RTLIB::SDIV_I32, .Impl: RTLIB::impl___mspabi_divli},
179 {.Op: RTLIB::SDIV_I64, .Impl: RTLIB::impl___mspabi_divlli},
180 {.Op: RTLIB::UDIV_I16, .Impl: RTLIB::impl___mspabi_divu},
181 {.Op: RTLIB::UDIV_I32, .Impl: RTLIB::impl___mspabi_divul},
182 {.Op: RTLIB::UDIV_I64, .Impl: RTLIB::impl___mspabi_divull},
183 {.Op: RTLIB::SREM_I16, .Impl: RTLIB::impl___mspabi_remi},
184 {.Op: RTLIB::SREM_I32, .Impl: RTLIB::impl___mspabi_remli},
185 {.Op: RTLIB::SREM_I64, .Impl: RTLIB::impl___mspabi_remlli},
186 {.Op: RTLIB::UREM_I16, .Impl: RTLIB::impl___mspabi_remu},
187 {.Op: RTLIB::UREM_I32, .Impl: RTLIB::impl___mspabi_remul},
188 {.Op: RTLIB::UREM_I64, .Impl: RTLIB::impl___mspabi_remull},
189 // Bitwise Operations - EABI Table 10.
190 {.Op: RTLIB::SHL_I32, .Impl: RTLIB::impl___mspabi_slll},
191 {.Op: RTLIB::SRA_I32, .Impl: RTLIB::impl___mspabi_sral},
192 };
193 for (const auto &LC : EABISelected)
194 Info.setLibcallImpl(Call: LC.Op, Impl: LC.Impl);
195}
196