blob: 320f931845a38f5aee75473ea9e0bf4fb081a904 [file] [log] [blame]
Eugene Zelenkofb7f7922017-09-21 23:20:16 +00001//===- TargetLoweringBase.cpp - Implement the TargetLoweringBase class ----===//
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This implements the TargetLoweringBase class.
10//
11//===----------------------------------------------------------------------===//
12
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000013#include "llvm/ADT/BitVector.h"
14#include "llvm/ADT/STLExtras.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000015#include "llvm/ADT/SmallVector.h"
Sanjay Patel0051efc2016-10-20 16:55:45 +000016#include "llvm/ADT/StringExtras.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000017#include "llvm/ADT/StringRef.h"
Paul Redmondf29ddfe2013-02-15 18:45:18 +000018#include "llvm/ADT/Triple.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000019#include "llvm/ADT/Twine.h"
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000020#include "llvm/CodeGen/Analysis.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000021#include "llvm/CodeGen/ISDOpcodes.h"
22#include "llvm/CodeGen/MachineBasicBlock.h"
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000023#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/MachineFunction.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000025#include "llvm/CodeGen/MachineInstr.h"
Lang Hames39609992013-11-29 03:07:54 +000026#include "llvm/CodeGen/MachineInstrBuilder.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000027#include "llvm/CodeGen/MachineMemOperand.h"
28#include "llvm/CodeGen/MachineOperand.h"
Matthias Braun744c2152017-04-28 20:25:05 +000029#include "llvm/CodeGen/MachineRegisterInfo.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000030#include "llvm/CodeGen/RuntimeLibcalls.h"
Lang Hames39609992013-11-29 03:07:54 +000031#include "llvm/CodeGen/StackMaps.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000032#include "llvm/CodeGen/TargetLowering.h"
33#include "llvm/CodeGen/TargetOpcodes.h"
34#include "llvm/CodeGen/TargetRegisterInfo.h"
Craig Topper2fa14362018-03-29 17:21:10 +000035#include "llvm/CodeGen/ValueTypes.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000036#include "llvm/IR/Attributes.h"
37#include "llvm/IR/CallingConv.h"
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000038#include "llvm/IR/DataLayout.h"
39#include "llvm/IR/DerivedTypes.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000040#include "llvm/IR/Function.h"
41#include "llvm/IR/GlobalValue.h"
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000042#include "llvm/IR/GlobalVariable.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000043#include "llvm/IR/IRBuilder.h"
44#include "llvm/IR/Module.h"
45#include "llvm/IR/Type.h"
Sanjay Pateld66607b2016-04-26 17:11:17 +000046#include "llvm/Support/BranchProbability.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000047#include "llvm/Support/Casting.h"
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000048#include "llvm/Support/CommandLine.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000049#include "llvm/Support/Compiler.h"
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000050#include "llvm/Support/ErrorHandling.h"
David Blaikie13e77db2018-03-23 23:58:25 +000051#include "llvm/Support/MachineValueType.h"
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000052#include "llvm/Support/MathExtras.h"
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000053#include "llvm/Target/TargetMachine.h"
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000054#include <algorithm>
55#include <cassert>
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000056#include <cstddef>
57#include <cstdint>
David Blaikieb3bde2e2017-11-17 01:07:10 +000058#include <cstring>
Eugene Zelenkofb7f7922017-09-21 23:20:16 +000059#include <iterator>
60#include <string>
61#include <tuple>
62#include <utility>
63
Benjamin Kramer56b31bd2013-01-11 20:05:37 +000064using namespace llvm;
65
Sanjay Patel943829a2015-07-01 18:10:20 +000066static cl::opt<bool> JumpIsExpensiveOverride(
67 "jump-is-expensive", cl::init(false),
68 cl::desc("Do not create extra branches to split comparison logic."),
69 cl::Hidden);
70
Evandro Menezeseb97e352016-10-25 19:53:51 +000071static cl::opt<unsigned> MinimumJumpTableEntries
72 ("min-jump-table-entries", cl::init(4), cl::Hidden,
73 cl::desc("Set minimum number of entries to use a jump table."));
74
Evandro Menezese45de8a2016-09-26 15:32:33 +000075static cl::opt<unsigned> MaximumJumpTableSize
Evandro Menezes0f797b82019-03-29 17:28:11 +000076 ("max-jump-table-size", cl::init(UINT_MAX), cl::Hidden,
77 cl::desc("Set maximum size of jump tables."));
Evandro Menezese45de8a2016-09-26 15:32:33 +000078
Jun Bum Lim919f9e82017-04-28 16:04:03 +000079/// Minimum jump table density for normal functions.
80static cl::opt<unsigned>
81 JumpTableDensity("jump-table-density", cl::init(10), cl::Hidden,
82 cl::desc("Minimum density for building a jump table in "
83 "a normal function"));
84
85/// Minimum jump table density for -Os or -Oz functions.
86static cl::opt<unsigned> OptsizeJumpTableDensity(
87 "optsize-jump-table-density", cl::init(40), cl::Hidden,
88 cl::desc("Minimum density for building a jump table in "
89 "an optsize function"));
90
Matthias Brauna4852d2c2017-12-18 23:19:42 +000091static bool darwinHasSinCos(const Triple &TT) {
92 assert(TT.isOSDarwin() && "should be called with darwin triple");
Matthias Braund2d7fb62017-12-19 20:24:12 +000093 // Don't bother with 32 bit x86.
94 if (TT.getArch() == Triple::x86)
95 return false;
96 // Macos < 10.9 has no sincos_stret.
Matthias Brauna4852d2c2017-12-18 23:19:42 +000097 if (TT.isMacOSX())
98 return !TT.isMacOSXVersionLT(10, 9) && TT.isArch64Bit();
Matthias Braun02820912017-12-18 23:33:28 +000099 // iOS < 7.0 has no sincos_stret.
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000100 if (TT.isiOS())
Matthias Braun02820912017-12-18 23:33:28 +0000101 return !TT.isOSVersionLT(7, 0);
102 // Any other darwin such as WatchOS/TvOS is new enough.
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000103 return true;
104}
105
Sanjay Pateld66607b2016-04-26 17:11:17 +0000106// Although this default value is arbitrary, it is not random. It is assumed
107// that a condition that evaluates the same way by a higher percentage than this
108// is best represented as control flow. Therefore, the default value N should be
109// set such that the win from N% correct executions is greater than the loss
110// from (100 - N)% mispredicted executions for the majority of intended targets.
111static cl::opt<int> MinPercentageForPredictableBranch(
112 "min-predictable-branch", cl::init(99),
113 cl::desc("Minimum percentage (0-100) that a condition must be either true "
114 "or false to assume that the condition is predictable"),
115 cl::Hidden);
116
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000117void TargetLoweringBase::InitLibcalls(const Triple &TT) {
Derek Schuff36454af2017-07-19 21:53:30 +0000118#define HANDLE_LIBCALL(code, name) \
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000119 setLibcallName(RTLIB::code, name);
Peter Collingbournee06bac42018-07-24 19:34:37 +0000120#include "llvm/IR/RuntimeLibcalls.def"
Derek Schuff36454af2017-07-19 21:53:30 +0000121#undef HANDLE_LIBCALL
Matthias Braun92de8b22017-12-19 00:20:33 +0000122 // Initialize calling conventions to their default.
123 for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC)
124 setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000125
Fangrui Song335f9552019-07-15 05:02:32 +0000126 // For IEEE quad-precision libcall names, PPC uses "kf" instead of "tf".
127 if (TT.getArch() == Triple::ppc || TT.isPPC64()) {
128 setLibcallName(RTLIB::ADD_F128, "__addkf3");
129 setLibcallName(RTLIB::SUB_F128, "__subkf3");
130 setLibcallName(RTLIB::MUL_F128, "__mulkf3");
131 setLibcallName(RTLIB::DIV_F128, "__divkf3");
132 setLibcallName(RTLIB::FPEXT_F32_F128, "__extendsfkf2");
133 setLibcallName(RTLIB::FPEXT_F64_F128, "__extenddfkf2");
134 setLibcallName(RTLIB::FPROUND_F128_F32, "__trunckfsf2");
135 setLibcallName(RTLIB::FPROUND_F128_F64, "__trunckfdf2");
136 setLibcallName(RTLIB::FPTOSINT_F128_I32, "__fixkfsi");
137 setLibcallName(RTLIB::FPTOSINT_F128_I64, "__fixkfdi");
138 setLibcallName(RTLIB::FPTOUINT_F128_I32, "__fixunskfsi");
139 setLibcallName(RTLIB::FPTOUINT_F128_I64, "__fixunskfdi");
140 setLibcallName(RTLIB::SINTTOFP_I32_F128, "__floatsikf");
141 setLibcallName(RTLIB::SINTTOFP_I64_F128, "__floatdikf");
142 setLibcallName(RTLIB::UINTTOFP_I32_F128, "__floatunsikf");
143 setLibcallName(RTLIB::UINTTOFP_I64_F128, "__floatundikf");
144 setLibcallName(RTLIB::OEQ_F128, "__eqkf2");
145 setLibcallName(RTLIB::UNE_F128, "__nekf2");
146 setLibcallName(RTLIB::OGE_F128, "__gekf2");
147 setLibcallName(RTLIB::OLT_F128, "__ltkf2");
148 setLibcallName(RTLIB::OLE_F128, "__lekf2");
149 setLibcallName(RTLIB::OGT_F128, "__gtkf2");
150 setLibcallName(RTLIB::UO_F128, "__unordkf2");
151 setLibcallName(RTLIB::O_F128, "__unordkf2");
152 }
153
Derek Schuff36454af2017-07-19 21:53:30 +0000154 // A few names are different on particular architectures or environments.
James Y Knight7873fb92016-04-12 22:32:47 +0000155 if (TT.isOSDarwin()) {
156 // For f16/f32 conversions, Darwin uses the standard naming scheme, instead
157 // of the gnueabi-style __gnu_*_ieee.
158 // FIXME: What about other targets?
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000159 setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
160 setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
Matthias Brauna92cecf2017-12-18 23:14:28 +0000161
Matthias Braun725ad0e2018-01-10 20:49:57 +0000162 // Some darwins have an optimized __bzero/bzero function.
163 switch (TT.getArch()) {
164 case Triple::x86:
165 case Triple::x86_64:
166 if (TT.isMacOSX() && !TT.isMacOSXVersionLT(10, 6))
167 setLibcallName(RTLIB::BZERO, "__bzero");
168 break;
169 case Triple::aarch64:
170 setLibcallName(RTLIB::BZERO, "bzero");
171 break;
172 default:
173 break;
Matthias Braune29c0b82017-12-19 00:43:00 +0000174 }
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000175
176 if (darwinHasSinCos(TT)) {
177 setLibcallName(RTLIB::SINCOS_STRET_F32, "__sincosf_stret");
178 setLibcallName(RTLIB::SINCOS_STRET_F64, "__sincos_stret");
179 if (TT.isWatchABI()) {
180 setLibcallCallingConv(RTLIB::SINCOS_STRET_F32,
181 CallingConv::ARM_AAPCS_VFP);
182 setLibcallCallingConv(RTLIB::SINCOS_STRET_F64,
183 CallingConv::ARM_AAPCS_VFP);
184 }
185 }
James Y Knight7873fb92016-04-12 22:32:47 +0000186 } else {
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000187 setLibcallName(RTLIB::FPEXT_F16_F32, "__gnu_h2f_ieee");
188 setLibcallName(RTLIB::FPROUND_F32_F16, "__gnu_f2h_ieee");
James Y Knight7873fb92016-04-12 22:32:47 +0000189 }
James Y Knight19f6cce2016-04-12 20:18:48 +0000190
John Brawn83d74142018-09-18 13:18:21 +0000191 if (TT.isGNUEnvironment() || TT.isOSFuchsia() ||
192 (TT.isAndroid() && !TT.isAndroidVersionLT(9))) {
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000193 setLibcallName(RTLIB::SINCOS_F32, "sincosf");
194 setLibcallName(RTLIB::SINCOS_F64, "sincos");
195 setLibcallName(RTLIB::SINCOS_F80, "sincosl");
196 setLibcallName(RTLIB::SINCOS_F128, "sincosl");
197 setLibcallName(RTLIB::SINCOS_PPCF128, "sincosl");
Paul Redmondf29ddfe2013-02-15 18:45:18 +0000198 }
Michael Gottesman7dce16f2013-08-12 18:45:38 +0000199
Robert Lougher13190c42019-09-02 16:53:32 +0000200 if (TT.isPS4CPU()) {
201 setLibcallName(RTLIB::SINCOS_F32, "sincosf");
202 setLibcallName(RTLIB::SINCOS_F64, "sincos");
203 }
204
Derek Schuff36454af2017-07-19 21:53:30 +0000205 if (TT.isOSOpenBSD()) {
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000206 setLibcallName(RTLIB::STACKPROTECTOR_CHECK_FAIL, nullptr);
Ahmed Bougacha6402ad22015-05-14 01:00:51 +0000207 }
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000208}
209
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000210/// getFPEXT - Return the FPEXT_*_* value for the given types, or
211/// UNKNOWN_LIBCALL if there is none.
212RTLIB::Libcall RTLIB::getFPEXT(EVT OpVT, EVT RetVT) {
Tim Northoverf7a02c12014-07-21 09:13:56 +0000213 if (OpVT == MVT::f16) {
214 if (RetVT == MVT::f32)
215 return FPEXT_F16_F32;
216 } else if (OpVT == MVT::f32) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000217 if (RetVT == MVT::f64)
218 return FPEXT_F32_F64;
219 if (RetVT == MVT::f128)
220 return FPEXT_F32_F128;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000221 if (RetVT == MVT::ppcf128)
222 return FPEXT_F32_PPCF128;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000223 } else if (OpVT == MVT::f64) {
224 if (RetVT == MVT::f128)
225 return FPEXT_F64_F128;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000226 else if (RetVT == MVT::ppcf128)
227 return FPEXT_F64_PPCF128;
Benjamin Kramer8b1986b2018-01-17 22:29:16 +0000228 } else if (OpVT == MVT::f80) {
229 if (RetVT == MVT::f128)
230 return FPEXT_F80_F128;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000231 }
232
233 return UNKNOWN_LIBCALL;
234}
235
236/// getFPROUND - Return the FPROUND_*_* value for the given types, or
237/// UNKNOWN_LIBCALL if there is none.
238RTLIB::Libcall RTLIB::getFPROUND(EVT OpVT, EVT RetVT) {
Tim Northover84ce0a62014-07-17 11:12:12 +0000239 if (RetVT == MVT::f16) {
240 if (OpVT == MVT::f32)
241 return FPROUND_F32_F16;
242 if (OpVT == MVT::f64)
243 return FPROUND_F64_F16;
244 if (OpVT == MVT::f80)
245 return FPROUND_F80_F16;
246 if (OpVT == MVT::f128)
247 return FPROUND_F128_F16;
248 if (OpVT == MVT::ppcf128)
249 return FPROUND_PPCF128_F16;
250 } else if (RetVT == MVT::f32) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000251 if (OpVT == MVT::f64)
252 return FPROUND_F64_F32;
253 if (OpVT == MVT::f80)
254 return FPROUND_F80_F32;
255 if (OpVT == MVT::f128)
256 return FPROUND_F128_F32;
257 if (OpVT == MVT::ppcf128)
258 return FPROUND_PPCF128_F32;
259 } else if (RetVT == MVT::f64) {
260 if (OpVT == MVT::f80)
261 return FPROUND_F80_F64;
262 if (OpVT == MVT::f128)
263 return FPROUND_F128_F64;
264 if (OpVT == MVT::ppcf128)
265 return FPROUND_PPCF128_F64;
Benjamin Kramer8b1986b2018-01-17 22:29:16 +0000266 } else if (RetVT == MVT::f80) {
267 if (OpVT == MVT::f128)
268 return FPROUND_F128_F80;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000269 }
270
271 return UNKNOWN_LIBCALL;
272}
273
274/// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
275/// UNKNOWN_LIBCALL if there is none.
276RTLIB::Libcall RTLIB::getFPTOSINT(EVT OpVT, EVT RetVT) {
277 if (OpVT == MVT::f32) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000278 if (RetVT == MVT::i32)
279 return FPTOSINT_F32_I32;
280 if (RetVT == MVT::i64)
281 return FPTOSINT_F32_I64;
282 if (RetVT == MVT::i128)
283 return FPTOSINT_F32_I128;
284 } else if (OpVT == MVT::f64) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000285 if (RetVT == MVT::i32)
286 return FPTOSINT_F64_I32;
287 if (RetVT == MVT::i64)
288 return FPTOSINT_F64_I64;
289 if (RetVT == MVT::i128)
290 return FPTOSINT_F64_I128;
291 } else if (OpVT == MVT::f80) {
292 if (RetVT == MVT::i32)
293 return FPTOSINT_F80_I32;
294 if (RetVT == MVT::i64)
295 return FPTOSINT_F80_I64;
296 if (RetVT == MVT::i128)
297 return FPTOSINT_F80_I128;
298 } else if (OpVT == MVT::f128) {
299 if (RetVT == MVT::i32)
300 return FPTOSINT_F128_I32;
301 if (RetVT == MVT::i64)
302 return FPTOSINT_F128_I64;
303 if (RetVT == MVT::i128)
304 return FPTOSINT_F128_I128;
305 } else if (OpVT == MVT::ppcf128) {
306 if (RetVT == MVT::i32)
307 return FPTOSINT_PPCF128_I32;
308 if (RetVT == MVT::i64)
309 return FPTOSINT_PPCF128_I64;
310 if (RetVT == MVT::i128)
311 return FPTOSINT_PPCF128_I128;
312 }
313 return UNKNOWN_LIBCALL;
314}
315
316/// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
317/// UNKNOWN_LIBCALL if there is none.
318RTLIB::Libcall RTLIB::getFPTOUINT(EVT OpVT, EVT RetVT) {
319 if (OpVT == MVT::f32) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000320 if (RetVT == MVT::i32)
321 return FPTOUINT_F32_I32;
322 if (RetVT == MVT::i64)
323 return FPTOUINT_F32_I64;
324 if (RetVT == MVT::i128)
325 return FPTOUINT_F32_I128;
326 } else if (OpVT == MVT::f64) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000327 if (RetVT == MVT::i32)
328 return FPTOUINT_F64_I32;
329 if (RetVT == MVT::i64)
330 return FPTOUINT_F64_I64;
331 if (RetVT == MVT::i128)
332 return FPTOUINT_F64_I128;
333 } else if (OpVT == MVT::f80) {
334 if (RetVT == MVT::i32)
335 return FPTOUINT_F80_I32;
336 if (RetVT == MVT::i64)
337 return FPTOUINT_F80_I64;
338 if (RetVT == MVT::i128)
339 return FPTOUINT_F80_I128;
340 } else if (OpVT == MVT::f128) {
341 if (RetVT == MVT::i32)
342 return FPTOUINT_F128_I32;
343 if (RetVT == MVT::i64)
344 return FPTOUINT_F128_I64;
345 if (RetVT == MVT::i128)
346 return FPTOUINT_F128_I128;
347 } else if (OpVT == MVT::ppcf128) {
348 if (RetVT == MVT::i32)
349 return FPTOUINT_PPCF128_I32;
350 if (RetVT == MVT::i64)
351 return FPTOUINT_PPCF128_I64;
352 if (RetVT == MVT::i128)
353 return FPTOUINT_PPCF128_I128;
354 }
355 return UNKNOWN_LIBCALL;
356}
357
358/// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
359/// UNKNOWN_LIBCALL if there is none.
360RTLIB::Libcall RTLIB::getSINTTOFP(EVT OpVT, EVT RetVT) {
361 if (OpVT == MVT::i32) {
362 if (RetVT == MVT::f32)
363 return SINTTOFP_I32_F32;
364 if (RetVT == MVT::f64)
365 return SINTTOFP_I32_F64;
366 if (RetVT == MVT::f80)
367 return SINTTOFP_I32_F80;
368 if (RetVT == MVT::f128)
369 return SINTTOFP_I32_F128;
370 if (RetVT == MVT::ppcf128)
371 return SINTTOFP_I32_PPCF128;
372 } else if (OpVT == MVT::i64) {
373 if (RetVT == MVT::f32)
374 return SINTTOFP_I64_F32;
375 if (RetVT == MVT::f64)
376 return SINTTOFP_I64_F64;
377 if (RetVT == MVT::f80)
378 return SINTTOFP_I64_F80;
379 if (RetVT == MVT::f128)
380 return SINTTOFP_I64_F128;
381 if (RetVT == MVT::ppcf128)
382 return SINTTOFP_I64_PPCF128;
383 } else if (OpVT == MVT::i128) {
384 if (RetVT == MVT::f32)
385 return SINTTOFP_I128_F32;
386 if (RetVT == MVT::f64)
387 return SINTTOFP_I128_F64;
388 if (RetVT == MVT::f80)
389 return SINTTOFP_I128_F80;
390 if (RetVT == MVT::f128)
391 return SINTTOFP_I128_F128;
392 if (RetVT == MVT::ppcf128)
393 return SINTTOFP_I128_PPCF128;
394 }
395 return UNKNOWN_LIBCALL;
396}
397
398/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
399/// UNKNOWN_LIBCALL if there is none.
400RTLIB::Libcall RTLIB::getUINTTOFP(EVT OpVT, EVT RetVT) {
401 if (OpVT == MVT::i32) {
402 if (RetVT == MVT::f32)
403 return UINTTOFP_I32_F32;
404 if (RetVT == MVT::f64)
405 return UINTTOFP_I32_F64;
406 if (RetVT == MVT::f80)
407 return UINTTOFP_I32_F80;
408 if (RetVT == MVT::f128)
409 return UINTTOFP_I32_F128;
410 if (RetVT == MVT::ppcf128)
411 return UINTTOFP_I32_PPCF128;
412 } else if (OpVT == MVT::i64) {
413 if (RetVT == MVT::f32)
414 return UINTTOFP_I64_F32;
415 if (RetVT == MVT::f64)
416 return UINTTOFP_I64_F64;
417 if (RetVT == MVT::f80)
418 return UINTTOFP_I64_F80;
419 if (RetVT == MVT::f128)
420 return UINTTOFP_I64_F128;
421 if (RetVT == MVT::ppcf128)
422 return UINTTOFP_I64_PPCF128;
423 } else if (OpVT == MVT::i128) {
424 if (RetVT == MVT::f32)
425 return UINTTOFP_I128_F32;
426 if (RetVT == MVT::f64)
427 return UINTTOFP_I128_F64;
428 if (RetVT == MVT::f80)
429 return UINTTOFP_I128_F80;
430 if (RetVT == MVT::f128)
431 return UINTTOFP_I128_F128;
432 if (RetVT == MVT::ppcf128)
433 return UINTTOFP_I128_PPCF128;
434 }
435 return UNKNOWN_LIBCALL;
436}
437
James Y Knightf44fc522016-03-16 22:12:04 +0000438RTLIB::Libcall RTLIB::getSYNC(unsigned Opc, MVT VT) {
Benjamin Kramerc54c38e2015-03-05 20:04:29 +0000439#define OP_TO_LIBCALL(Name, Enum) \
440 case Name: \
441 switch (VT.SimpleTy) { \
442 default: \
443 return UNKNOWN_LIBCALL; \
444 case MVT::i8: \
445 return Enum##_1; \
446 case MVT::i16: \
447 return Enum##_2; \
448 case MVT::i32: \
449 return Enum##_4; \
450 case MVT::i64: \
451 return Enum##_8; \
452 case MVT::i128: \
453 return Enum##_16; \
454 }
455
456 switch (Opc) {
457 OP_TO_LIBCALL(ISD::ATOMIC_SWAP, SYNC_LOCK_TEST_AND_SET)
458 OP_TO_LIBCALL(ISD::ATOMIC_CMP_SWAP, SYNC_VAL_COMPARE_AND_SWAP)
459 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_ADD, SYNC_FETCH_AND_ADD)
460 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_SUB, SYNC_FETCH_AND_SUB)
461 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_AND, SYNC_FETCH_AND_AND)
462 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_OR, SYNC_FETCH_AND_OR)
463 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_XOR, SYNC_FETCH_AND_XOR)
464 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_NAND, SYNC_FETCH_AND_NAND)
465 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MAX, SYNC_FETCH_AND_MAX)
466 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMAX, SYNC_FETCH_AND_UMAX)
467 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MIN, SYNC_FETCH_AND_MIN)
468 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMIN, SYNC_FETCH_AND_UMIN)
469 }
470
471#undef OP_TO_LIBCALL
472
473 return UNKNOWN_LIBCALL;
474}
475
Daniel Neilson3faabbb2017-06-16 14:43:59 +0000476RTLIB::Libcall RTLIB::getMEMCPY_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize) {
Igor Laevsky4f31e522016-12-29 14:31:07 +0000477 switch (ElementSize) {
478 case 1:
Daniel Neilson3faabbb2017-06-16 14:43:59 +0000479 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_1;
Igor Laevsky4f31e522016-12-29 14:31:07 +0000480 case 2:
Daniel Neilson3faabbb2017-06-16 14:43:59 +0000481 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_2;
Igor Laevsky4f31e522016-12-29 14:31:07 +0000482 case 4:
Daniel Neilson3faabbb2017-06-16 14:43:59 +0000483 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_4;
Igor Laevsky4f31e522016-12-29 14:31:07 +0000484 case 8:
Daniel Neilson3faabbb2017-06-16 14:43:59 +0000485 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_8;
Igor Laevsky4f31e522016-12-29 14:31:07 +0000486 case 16:
Daniel Neilson3faabbb2017-06-16 14:43:59 +0000487 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_16;
Igor Laevsky4f31e522016-12-29 14:31:07 +0000488 default:
489 return UNKNOWN_LIBCALL;
490 }
Igor Laevsky4f31e522016-12-29 14:31:07 +0000491}
492
Daniel Neilson57226ef2017-07-12 15:25:26 +0000493RTLIB::Libcall RTLIB::getMEMMOVE_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize) {
494 switch (ElementSize) {
495 case 1:
496 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_1;
497 case 2:
498 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_2;
499 case 4:
500 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_4;
501 case 8:
502 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_8;
503 case 16:
504 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_16;
505 default:
506 return UNKNOWN_LIBCALL;
507 }
508}
509
Daniel Neilson965613e2017-07-12 21:57:23 +0000510RTLIB::Libcall RTLIB::getMEMSET_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize) {
511 switch (ElementSize) {
512 case 1:
513 return MEMSET_ELEMENT_UNORDERED_ATOMIC_1;
514 case 2:
515 return MEMSET_ELEMENT_UNORDERED_ATOMIC_2;
516 case 4:
517 return MEMSET_ELEMENT_UNORDERED_ATOMIC_4;
518 case 8:
519 return MEMSET_ELEMENT_UNORDERED_ATOMIC_8;
520 case 16:
521 return MEMSET_ELEMENT_UNORDERED_ATOMIC_16;
522 default:
523 return UNKNOWN_LIBCALL;
524 }
525}
526
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000527/// InitCmpLibcallCCs - Set default comparison libcall CC.
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000528static void InitCmpLibcallCCs(ISD::CondCode *CCs) {
529 memset(CCs, ISD::SETCC_INVALID, sizeof(ISD::CondCode)*RTLIB::UNKNOWN_LIBCALL);
530 CCs[RTLIB::OEQ_F32] = ISD::SETEQ;
531 CCs[RTLIB::OEQ_F64] = ISD::SETEQ;
532 CCs[RTLIB::OEQ_F128] = ISD::SETEQ;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000533 CCs[RTLIB::OEQ_PPCF128] = ISD::SETEQ;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000534 CCs[RTLIB::UNE_F32] = ISD::SETNE;
535 CCs[RTLIB::UNE_F64] = ISD::SETNE;
536 CCs[RTLIB::UNE_F128] = ISD::SETNE;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000537 CCs[RTLIB::UNE_PPCF128] = ISD::SETNE;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000538 CCs[RTLIB::OGE_F32] = ISD::SETGE;
539 CCs[RTLIB::OGE_F64] = ISD::SETGE;
540 CCs[RTLIB::OGE_F128] = ISD::SETGE;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000541 CCs[RTLIB::OGE_PPCF128] = ISD::SETGE;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000542 CCs[RTLIB::OLT_F32] = ISD::SETLT;
543 CCs[RTLIB::OLT_F64] = ISD::SETLT;
544 CCs[RTLIB::OLT_F128] = ISD::SETLT;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000545 CCs[RTLIB::OLT_PPCF128] = ISD::SETLT;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000546 CCs[RTLIB::OLE_F32] = ISD::SETLE;
547 CCs[RTLIB::OLE_F64] = ISD::SETLE;
548 CCs[RTLIB::OLE_F128] = ISD::SETLE;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000549 CCs[RTLIB::OLE_PPCF128] = ISD::SETLE;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000550 CCs[RTLIB::OGT_F32] = ISD::SETGT;
551 CCs[RTLIB::OGT_F64] = ISD::SETGT;
552 CCs[RTLIB::OGT_F128] = ISD::SETGT;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000553 CCs[RTLIB::OGT_PPCF128] = ISD::SETGT;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000554 CCs[RTLIB::UO_F32] = ISD::SETNE;
555 CCs[RTLIB::UO_F64] = ISD::SETNE;
556 CCs[RTLIB::UO_F128] = ISD::SETNE;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000557 CCs[RTLIB::UO_PPCF128] = ISD::SETNE;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000558 CCs[RTLIB::O_F32] = ISD::SETEQ;
559 CCs[RTLIB::O_F64] = ISD::SETEQ;
560 CCs[RTLIB::O_F128] = ISD::SETEQ;
Petar Jovanovic23e44f52016-02-04 14:43:50 +0000561 CCs[RTLIB::O_PPCF128] = ISD::SETEQ;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000562}
563
Aditya Nandakumar30531552014-11-13 21:29:21 +0000564/// NOTE: The TargetMachine owns TLOF.
Mehdi Aminia28d91d2015-03-10 02:37:25 +0000565TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm) : TM(tm) {
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000566 initActions();
567
568 // Perform these initializations only once.
Zaara Syeda3a7578c2017-05-31 17:12:38 +0000569 MaxStoresPerMemset = MaxStoresPerMemcpy = MaxStoresPerMemmove =
570 MaxLoadsPerMemcmp = 8;
Sirish Pandecabe50a32018-05-16 15:36:52 +0000571 MaxGluedStoresPerMemcpy = 0;
Zaara Syeda3a7578c2017-05-31 17:12:38 +0000572 MaxStoresPerMemsetOptSize = MaxStoresPerMemcpyOptSize =
573 MaxStoresPerMemmoveOptSize = MaxLoadsPerMemcmpOptSize = 4;
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000574 UseUnderscoreSetJmp = false;
575 UseUnderscoreLongJmp = false;
Hal Finkeldecb0242014-01-02 21:13:43 +0000576 HasMultipleConditionRegisters = false;
Yi Jiangb23edeb2014-04-21 22:22:44 +0000577 HasExtractBitsInsn = false;
Sanjay Patel943829a2015-07-01 18:10:20 +0000578 JumpIsExpensive = JumpIsExpensiveOverride;
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000579 PredictableSelectIsExpensive = false;
Quentin Colombetfc2201e2014-12-17 01:36:17 +0000580 EnableExtLdPromotion = false;
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000581 StackPointerRegisterToSaveRestore = 0;
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000582 BooleanContents = UndefinedBooleanContent;
Daniel Sanderscbd44c52014-07-10 10:18:12 +0000583 BooleanFloatContents = UndefinedBooleanContent;
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000584 BooleanVectorContents = UndefinedBooleanContent;
585 SchedPreferenceInfo = Sched::ILP;
Nirav Dave54e22f32017-03-14 00:34:14 +0000586 GatherAllAliasesMaxDepth = 18;
James Y Knight19f6cce2016-04-12 20:18:48 +0000587 // TODO: the default will be switched to 0 in the next commit, along
588 // with the Target-specific changes necessary.
589 MaxAtomicSizeInBitsSupported = 1024;
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000590
James Y Knight148a6462016-06-17 18:11:48 +0000591 MinCmpXchgSizeInBits = 0;
Dylan McKay80463fe2017-12-09 06:45:36 +0000592 SupportsUnalignedAtomics = false;
James Y Knight148a6462016-06-17 18:11:48 +0000593
James Y Knight7873fb92016-04-12 22:32:47 +0000594 std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames), nullptr);
595
Matthias Brauna4852d2c2017-12-18 23:19:42 +0000596 InitLibcalls(TM.getTargetTriple());
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000597 InitCmpLibcallCCs(CmpLibcallCCs);
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000598}
599
Bill Wendlingeb108ba2013-04-05 21:52:40 +0000600void TargetLoweringBase::initActions() {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000601 // All operations default to being supported.
602 memset(OpActions, 0, sizeof(OpActions));
603 memset(LoadExtActions, 0, sizeof(LoadExtActions));
604 memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
605 memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
606 memset(CondCodeActions, 0, sizeof(CondCodeActions));
Craig Topper00230802016-04-08 07:10:46 +0000607 std::fill(std::begin(RegClassForVT), std::end(RegClassForVT), nullptr);
608 std::fill(std::begin(TargetDAGCombineArray),
609 std::end(TargetDAGCombineArray), 0);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000610
Matt Arsenault0cb08e42019-01-17 10:49:01 +0000611 for (MVT VT : MVT::fp_valuetypes()) {
612 MVT IntVT = MVT::getIntegerVT(VT.getSizeInBits());
613 if (IntVT.isValid()) {
614 setOperationAction(ISD::ATOMIC_SWAP, VT, Promote);
615 AddPromotedToType(ISD::ATOMIC_SWAP, VT, IntVT);
616 }
617 }
618
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000619 // Set default actions for various operations.
Ahmed Bougacha67dd2d22015-01-07 21:27:10 +0000620 for (MVT VT : MVT::all_valuetypes()) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000621 // Default all indexed load / store to expand.
622 for (unsigned IM = (unsigned)ISD::PRE_INC;
623 IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
Ahmed Bougacha67dd2d22015-01-07 21:27:10 +0000624 setIndexedLoadAction(IM, VT, Expand);
625 setIndexedStoreAction(IM, VT, Expand);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000626 }
627
Tim Northover420a2162014-06-13 14:24:07 +0000628 // Most backends expect to see the node which just returns the value loaded.
Ahmed Bougacha67dd2d22015-01-07 21:27:10 +0000629 setOperationAction(ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS, VT, Expand);
Tim Northover420a2162014-06-13 14:24:07 +0000630
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000631 // These operations default to expand.
Ahmed Bougacha67dd2d22015-01-07 21:27:10 +0000632 setOperationAction(ISD::FGETSIGN, VT, Expand);
633 setOperationAction(ISD::CONCAT_VECTORS, VT, Expand);
634 setOperationAction(ISD::FMINNUM, VT, Expand);
635 setOperationAction(ISD::FMAXNUM, VT, Expand);
Matt Arsenault687ec752018-10-22 16:27:27 +0000636 setOperationAction(ISD::FMINNUM_IEEE, VT, Expand);
637 setOperationAction(ISD::FMAXNUM_IEEE, VT, Expand);
Thomas Lively30f1d692018-10-24 22:49:55 +0000638 setOperationAction(ISD::FMINIMUM, VT, Expand);
639 setOperationAction(ISD::FMAXIMUM, VT, Expand);
Matt Arsenault0dc54c42015-02-20 22:10:33 +0000640 setOperationAction(ISD::FMAD, VT, Expand);
James Molloy7e9776b2015-05-15 09:03:15 +0000641 setOperationAction(ISD::SMIN, VT, Expand);
642 setOperationAction(ISD::SMAX, VT, Expand);
643 setOperationAction(ISD::UMIN, VT, Expand);
644 setOperationAction(ISD::UMAX, VT, Expand);
Simon Pilgrimcf2da962017-03-14 21:26:58 +0000645 setOperationAction(ISD::ABS, VT, Expand);
Simon Pilgrim180639a2018-12-05 11:12:12 +0000646 setOperationAction(ISD::FSHL, VT, Expand);
647 setOperationAction(ISD::FSHR, VT, Expand);
Leonard Chan699b3b52018-10-16 17:35:41 +0000648 setOperationAction(ISD::SADDSAT, VT, Expand);
Leonard Chan0acfc6b2018-10-22 23:08:40 +0000649 setOperationAction(ISD::UADDSAT, VT, Expand);
Leonard Chan905abe52018-10-29 16:54:37 +0000650 setOperationAction(ISD::SSUBSAT, VT, Expand);
651 setOperationAction(ISD::USUBSAT, VT, Expand);
Leonard Chan118e53f2018-12-12 06:29:14 +0000652 setOperationAction(ISD::SMULFIX, VT, Expand);
Leonard Chan0bada7c2019-05-21 19:17:19 +0000653 setOperationAction(ISD::SMULFIXSAT, VT, Expand);
Leonard Chan68d428e2019-02-04 17:18:11 +0000654 setOperationAction(ISD::UMULFIX, VT, Expand);
Hal Finkel8ec43c62013-08-09 04:13:44 +0000655
Jan Vesely75395482015-04-29 16:30:46 +0000656 // Overflow operations default to expand
657 setOperationAction(ISD::SADDO, VT, Expand);
658 setOperationAction(ISD::SSUBO, VT, Expand);
659 setOperationAction(ISD::UADDO, VT, Expand);
660 setOperationAction(ISD::USUBO, VT, Expand);
661 setOperationAction(ISD::SMULO, VT, Expand);
662 setOperationAction(ISD::UMULO, VT, Expand);
Hal Finkelcd8664c2015-12-11 23:11:52 +0000663
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000664 // ADDCARRY operations default to expand
665 setOperationAction(ISD::ADDCARRY, VT, Expand);
666 setOperationAction(ISD::SUBCARRY, VT, Expand);
Amaury Sechet251ea8a2017-06-01 11:14:17 +0000667 setOperationAction(ISD::SETCCCARRY, VT, Expand);
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000668
Amaury Sechet84674112018-06-01 13:21:33 +0000669 // ADDC/ADDE/SUBC/SUBE default to expand.
670 setOperationAction(ISD::ADDC, VT, Expand);
671 setOperationAction(ISD::ADDE, VT, Expand);
672 setOperationAction(ISD::SUBC, VT, Expand);
673 setOperationAction(ISD::SUBE, VT, Expand);
674
Craig Topper33772c52016-04-28 03:34:31 +0000675 // These default to Expand so they will be expanded to CTLZ/CTTZ by default.
676 setOperationAction(ISD::CTLZ_ZERO_UNDEF, VT, Expand);
677 setOperationAction(ISD::CTTZ_ZERO_UNDEF, VT, Expand);
678
James Molloy90111f72015-11-12 12:29:09 +0000679 setOperationAction(ISD::BITREVERSE, VT, Expand);
Fangrui Songf78650a2018-07-30 19:41:25 +0000680
Hal Finkel8ec43c62013-08-09 04:13:44 +0000681 // These library functions default to expand.
Ahmed Bougacha67dd2d22015-01-07 21:27:10 +0000682 setOperationAction(ISD::FROUND, VT, Expand);
Craig Topperf6d4dc52017-05-30 15:27:55 +0000683 setOperationAction(ISD::FPOWI, VT, Expand);
Hal Finkel0c5c01aa2013-08-19 23:35:46 +0000684
685 // These operations default to expand for vector types.
Ahmed Bougacha67dd2d22015-01-07 21:27:10 +0000686 if (VT.isVector()) {
687 setOperationAction(ISD::FCOPYSIGN, VT, Expand);
688 setOperationAction(ISD::ANY_EXTEND_VECTOR_INREG, VT, Expand);
689 setOperationAction(ISD::SIGN_EXTEND_VECTOR_INREG, VT, Expand);
690 setOperationAction(ISD::ZERO_EXTEND_VECTOR_INREG, VT, Expand);
Chandler Carruthd3561f62014-07-09 22:53:04 +0000691 }
Yury Gribovd7dbb662015-12-01 11:40:55 +0000692
Ulrich Weigand6c5d5ce2019-06-05 22:33:10 +0000693 // Constrained floating-point operations default to expand.
694 setOperationAction(ISD::STRICT_FADD, VT, Expand);
695 setOperationAction(ISD::STRICT_FSUB, VT, Expand);
696 setOperationAction(ISD::STRICT_FMUL, VT, Expand);
697 setOperationAction(ISD::STRICT_FDIV, VT, Expand);
698 setOperationAction(ISD::STRICT_FREM, VT, Expand);
699 setOperationAction(ISD::STRICT_FMA, VT, Expand);
700 setOperationAction(ISD::STRICT_FSQRT, VT, Expand);
701 setOperationAction(ISD::STRICT_FPOW, VT, Expand);
702 setOperationAction(ISD::STRICT_FPOWI, VT, Expand);
703 setOperationAction(ISD::STRICT_FSIN, VT, Expand);
704 setOperationAction(ISD::STRICT_FCOS, VT, Expand);
705 setOperationAction(ISD::STRICT_FEXP, VT, Expand);
706 setOperationAction(ISD::STRICT_FEXP2, VT, Expand);
707 setOperationAction(ISD::STRICT_FLOG, VT, Expand);
708 setOperationAction(ISD::STRICT_FLOG10, VT, Expand);
709 setOperationAction(ISD::STRICT_FLOG2, VT, Expand);
710 setOperationAction(ISD::STRICT_FRINT, VT, Expand);
711 setOperationAction(ISD::STRICT_FNEARBYINT, VT, Expand);
712 setOperationAction(ISD::STRICT_FCEIL, VT, Expand);
713 setOperationAction(ISD::STRICT_FFLOOR, VT, Expand);
714 setOperationAction(ISD::STRICT_FROUND, VT, Expand);
715 setOperationAction(ISD::STRICT_FTRUNC, VT, Expand);
716 setOperationAction(ISD::STRICT_FMAXNUM, VT, Expand);
717 setOperationAction(ISD::STRICT_FMINNUM, VT, Expand);
718 setOperationAction(ISD::STRICT_FP_ROUND, VT, Expand);
719 setOperationAction(ISD::STRICT_FP_EXTEND, VT, Expand);
Kevin P. Nealddf13c02019-08-28 16:33:36 +0000720 setOperationAction(ISD::STRICT_FP_TO_SINT, VT, Expand);
721 setOperationAction(ISD::STRICT_FP_TO_UINT, VT, Expand);
Ulrich Weigand6c5d5ce2019-06-05 22:33:10 +0000722
Etienne Bergeron22bfa832016-06-07 20:15:35 +0000723 // For most targets @llvm.get.dynamic.area.offset just returns 0.
Yury Gribovd7dbb662015-12-01 11:40:55 +0000724 setOperationAction(ISD::GET_DYNAMIC_AREA_OFFSET, VT, Expand);
Nikita Popovaa7cfa72019-03-11 20:22:13 +0000725
726 // Vector reduction default to expand.
727 setOperationAction(ISD::VECREDUCE_FADD, VT, Expand);
728 setOperationAction(ISD::VECREDUCE_FMUL, VT, Expand);
729 setOperationAction(ISD::VECREDUCE_ADD, VT, Expand);
730 setOperationAction(ISD::VECREDUCE_MUL, VT, Expand);
731 setOperationAction(ISD::VECREDUCE_AND, VT, Expand);
732 setOperationAction(ISD::VECREDUCE_OR, VT, Expand);
733 setOperationAction(ISD::VECREDUCE_XOR, VT, Expand);
734 setOperationAction(ISD::VECREDUCE_SMAX, VT, Expand);
735 setOperationAction(ISD::VECREDUCE_SMIN, VT, Expand);
736 setOperationAction(ISD::VECREDUCE_UMAX, VT, Expand);
737 setOperationAction(ISD::VECREDUCE_UMIN, VT, Expand);
738 setOperationAction(ISD::VECREDUCE_FMAX, VT, Expand);
739 setOperationAction(ISD::VECREDUCE_FMIN, VT, Expand);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000740 }
741
742 // Most targets ignore the @llvm.prefetch intrinsic.
743 setOperationAction(ISD::PREFETCH, MVT::Other, Expand);
744
Ahmed Bougachaf9c19da2015-08-28 01:49:59 +0000745 // Most targets also ignore the @llvm.readcyclecounter intrinsic.
746 setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Expand);
747
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000748 // ConstantFP nodes default to expand. Targets can either change this to
749 // Legal, in which case all fp constants are legal, or use isFPImmLegal()
750 // to optimize expansions for certain constants.
751 setOperationAction(ISD::ConstantFP, MVT::f16, Expand);
752 setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
753 setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
754 setOperationAction(ISD::ConstantFP, MVT::f80, Expand);
755 setOperationAction(ISD::ConstantFP, MVT::f128, Expand);
756
757 // These library functions default to expand.
Ahmed Bougacha2a20e272015-03-26 23:21:03 +0000758 for (MVT VT : {MVT::f32, MVT::f64, MVT::f128}) {
Sanjay Patel3eaf5002018-09-16 16:50:26 +0000759 setOperationAction(ISD::FCBRT, VT, Expand);
Ahmed Bougacha2a20e272015-03-26 23:21:03 +0000760 setOperationAction(ISD::FLOG , VT, Expand);
761 setOperationAction(ISD::FLOG2, VT, Expand);
762 setOperationAction(ISD::FLOG10, VT, Expand);
763 setOperationAction(ISD::FEXP , VT, Expand);
764 setOperationAction(ISD::FEXP2, VT, Expand);
765 setOperationAction(ISD::FFLOOR, VT, Expand);
Ahmed Bougacha2a20e272015-03-26 23:21:03 +0000766 setOperationAction(ISD::FNEARBYINT, VT, Expand);
767 setOperationAction(ISD::FCEIL, VT, Expand);
768 setOperationAction(ISD::FRINT, VT, Expand);
769 setOperationAction(ISD::FTRUNC, VT, Expand);
770 setOperationAction(ISD::FROUND, VT, Expand);
Adhemerval Zanella73643b52019-05-16 13:15:27 +0000771 setOperationAction(ISD::LROUND, VT, Expand);
772 setOperationAction(ISD::LLROUND, VT, Expand);
Adhemerval Zanella6d7bf5e2019-05-28 20:47:44 +0000773 setOperationAction(ISD::LRINT, VT, Expand);
774 setOperationAction(ISD::LLRINT, VT, Expand);
Ahmed Bougacha2a20e272015-03-26 23:21:03 +0000775 }
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000776
777 // Default ISD::TRAP to expand (which turns it into abort).
778 setOperationAction(ISD::TRAP, MVT::Other, Expand);
779
780 // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand"
781 // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP.
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000782 setOperationAction(ISD::DEBUGTRAP, MVT::Other, Expand);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000783}
784
Mehdi Aminieaabc512015-07-09 15:12:23 +0000785MVT TargetLoweringBase::getScalarShiftAmountTy(const DataLayout &DL,
786 EVT) const {
Bjorn Pettersson8d19e942019-05-09 08:07:36 +0000787 return MVT::getIntegerVT(DL.getPointerSizeInBits(0));
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000788}
789
Craig Topper35801fa2018-02-20 17:41:05 +0000790EVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy, const DataLayout &DL,
791 bool LegalTypes) const {
Michael Liao6af16fc2013-03-01 18:40:30 +0000792 assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
793 if (LHSTy.isVector())
794 return LHSTy;
Craig Topper35801fa2018-02-20 17:41:05 +0000795 return LegalTypes ? getScalarShiftAmountTy(DL, LHSTy)
796 : getPointerTy(DL);
Michael Liao6af16fc2013-03-01 18:40:30 +0000797}
798
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000799bool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
800 assert(isTypeLegal(VT));
801 switch (Op) {
802 default:
803 return false;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000804 case ISD::SDIV:
805 case ISD::UDIV:
806 case ISD::SREM:
807 case ISD::UREM:
808 return true;
809 }
810}
811
Sanjay Patel943829a2015-07-01 18:10:20 +0000812void TargetLoweringBase::setJumpIsExpensive(bool isExpensive) {
813 // If the command-line option was specified, ignore this request.
814 if (!JumpIsExpensiveOverride.getNumOccurrences())
815 JumpIsExpensive = isExpensive;
816}
817
Eric Christopher75dbd7c2015-02-25 22:41:30 +0000818TargetLoweringBase::LegalizeKind
819TargetLoweringBase::getTypeConversion(LLVMContext &Context, EVT VT) const {
820 // If this is a simple type, use the ComputeRegisterProp mechanism.
821 if (VT.isSimple()) {
822 MVT SVT = VT.getSimpleVT();
823 assert((unsigned)SVT.SimpleTy < array_lengthof(TransformToType));
824 MVT NVT = TransformToType[SVT.SimpleTy];
825 LegalizeTypeAction LA = ValueTypeActions.getTypeAction(SVT);
826
827 assert((LA == TypeLegal || LA == TypeSoftenFloat ||
Matt Arsenault1f2b7272019-08-15 18:58:25 +0000828 (NVT.isVector() ||
829 ValueTypeActions.getTypeAction(NVT) != TypePromoteInteger)) &&
Eric Christopher75dbd7c2015-02-25 22:41:30 +0000830 "Promote may not follow Expand or Promote");
831
832 if (LA == TypeSplitVector)
833 return LegalizeKind(LA,
834 EVT::getVectorVT(Context, SVT.getVectorElementType(),
835 SVT.getVectorNumElements() / 2));
836 if (LA == TypeScalarizeVector)
837 return LegalizeKind(LA, SVT.getVectorElementType());
838 return LegalizeKind(LA, NVT);
839 }
840
841 // Handle Extended Scalar Types.
842 if (!VT.isVector()) {
843 assert(VT.isInteger() && "Float types must be simple");
844 unsigned BitSize = VT.getSizeInBits();
845 // First promote to a power-of-two size, then expand if necessary.
846 if (BitSize < 8 || !isPowerOf2_32(BitSize)) {
847 EVT NVT = VT.getRoundIntegerType(Context);
848 assert(NVT != VT && "Unable to round integer VT");
849 LegalizeKind NextStep = getTypeConversion(Context, NVT);
850 // Avoid multi-step promotion.
851 if (NextStep.first == TypePromoteInteger)
852 return NextStep;
853 // Return rounded integer type.
854 return LegalizeKind(TypePromoteInteger, NVT);
855 }
856
857 return LegalizeKind(TypeExpandInteger,
858 EVT::getIntegerVT(Context, VT.getSizeInBits() / 2));
859 }
860
861 // Handle vector types.
862 unsigned NumElts = VT.getVectorNumElements();
863 EVT EltVT = VT.getVectorElementType();
864
865 // Vectors with only one element are always scalarized.
866 if (NumElts == 1)
867 return LegalizeKind(TypeScalarizeVector, EltVT);
868
869 // Try to widen vector elements until the element type is a power of two and
870 // promote it to a legal type later on, for example:
871 // <3 x i8> -> <4 x i8> -> <4 x i32>
872 if (EltVT.isInteger()) {
873 // Vectors with a number of elements that is not a power of two are always
874 // widened, for example <3 x i8> -> <4 x i8>.
875 if (!VT.isPow2VectorType()) {
876 NumElts = (unsigned)NextPowerOf2(NumElts);
877 EVT NVT = EVT::getVectorVT(Context, EltVT, NumElts);
878 return LegalizeKind(TypeWidenVector, NVT);
879 }
880
881 // Examine the element type.
882 LegalizeKind LK = getTypeConversion(Context, EltVT);
883
884 // If type is to be expanded, split the vector.
885 // <4 x i140> -> <2 x i140>
886 if (LK.first == TypeExpandInteger)
887 return LegalizeKind(TypeSplitVector,
888 EVT::getVectorVT(Context, EltVT, NumElts / 2));
889
890 // Promote the integer element types until a legal vector type is found
891 // or until the element integer type is too big. If a legal type was not
892 // found, fallback to the usual mechanism of widening/splitting the
893 // vector.
894 EVT OldEltVT = EltVT;
Eugene Zelenkofb7f7922017-09-21 23:20:16 +0000895 while (true) {
Eric Christopher75dbd7c2015-02-25 22:41:30 +0000896 // Increase the bitwidth of the element to the next pow-of-two
897 // (which is greater than 8 bits).
898 EltVT = EVT::getIntegerVT(Context, 1 + EltVT.getSizeInBits())
899 .getRoundIntegerType(Context);
900
901 // Stop trying when getting a non-simple element type.
902 // Note that vector elements may be greater than legal vector element
903 // types. Example: X86 XMM registers hold 64bit element on 32bit
904 // systems.
905 if (!EltVT.isSimple())
906 break;
907
908 // Build a new vector type and check if it is legal.
909 MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
910 // Found a legal promoted vector type.
911 if (NVT != MVT() && ValueTypeActions.getTypeAction(NVT) == TypeLegal)
912 return LegalizeKind(TypePromoteInteger,
913 EVT::getVectorVT(Context, EltVT, NumElts));
914 }
915
916 // Reset the type to the unexpanded type if we did not find a legal vector
917 // type with a promoted vector element type.
918 EltVT = OldEltVT;
919 }
920
921 // Try to widen the vector until a legal type is found.
922 // If there is no wider legal type, split the vector.
Eugene Zelenkofb7f7922017-09-21 23:20:16 +0000923 while (true) {
Eric Christopher75dbd7c2015-02-25 22:41:30 +0000924 // Round up to the next power of 2.
925 NumElts = (unsigned)NextPowerOf2(NumElts);
926
927 // If there is no simple vector type with this many elements then there
928 // cannot be a larger legal vector type. Note that this assumes that
929 // there are no skipped intermediate vector types in the simple types.
930 if (!EltVT.isSimple())
931 break;
932 MVT LargerVector = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
933 if (LargerVector == MVT())
934 break;
935
936 // If this type is legal then widen the vector.
937 if (ValueTypeActions.getTypeAction(LargerVector) == TypeLegal)
938 return LegalizeKind(TypeWidenVector, LargerVector);
939 }
940
941 // Widen odd vectors to next power of two.
942 if (!VT.isPow2VectorType()) {
943 EVT NVT = VT.getPow2VectorType(Context);
944 return LegalizeKind(TypeWidenVector, NVT);
945 }
946
947 // Vectors with illegal element types are expanded.
948 EVT NVT = EVT::getVectorVT(Context, EltVT, VT.getVectorNumElements() / 2);
949 return LegalizeKind(TypeSplitVector, NVT);
950}
Benjamin Kramer56b31bd2013-01-11 20:05:37 +0000951
952static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
953 unsigned &NumIntermediates,
954 MVT &RegisterVT,
955 TargetLoweringBase *TLI) {
956 // Figure out the right, legal destination reg to copy into.
957 unsigned NumElts = VT.getVectorNumElements();
958 MVT EltTy = VT.getVectorElementType();
959
960 unsigned NumVectorRegs = 1;
961
962 // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally we
963 // could break down into LHS/RHS like LegalizeDAG does.
964 if (!isPowerOf2_32(NumElts)) {
965 NumVectorRegs = NumElts;
966 NumElts = 1;
967 }
968
969 // Divide the input until we get to a supported size. This will always
970 // end with a scalar if the target doesn't support vectors.
971 while (NumElts > 1 && !TLI->isTypeLegal(MVT::getVectorVT(EltTy, NumElts))) {
972 NumElts >>= 1;
973 NumVectorRegs <<= 1;
974 }
975
976 NumIntermediates = NumVectorRegs;
977
978 MVT NewVT = MVT::getVectorVT(EltTy, NumElts);
979 if (!TLI->isTypeLegal(NewVT))
980 NewVT = EltTy;
981 IntermediateVT = NewVT;
982
983 unsigned NewVTSize = NewVT.getSizeInBits();
984
985 // Convert sizes such as i33 to i64.
986 if (!isPowerOf2_32(NewVTSize))
987 NewVTSize = NextPowerOf2(NewVTSize);
988
989 MVT DestVT = TLI->getRegisterType(NewVT);
990 RegisterVT = DestVT;
991 if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16.
992 return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
993
994 // Otherwise, promotion or legal types use the same number of registers as
995 // the vector decimated to the appropriate level.
996 return NumVectorRegs;
997}
998
999/// isLegalRC - Return true if the value types that can be represented by the
1000/// specified register class are all legal.
Krzysztof Parzyszekc8e8e2a2017-04-24 19:51:12 +00001001bool TargetLoweringBase::isLegalRC(const TargetRegisterInfo &TRI,
1002 const TargetRegisterClass &RC) const {
1003 for (auto I = TRI.legalclasstypes_begin(RC); *I != MVT::Other; ++I)
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001004 if (isTypeLegal(*I))
1005 return true;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001006 return false;
1007}
1008
Lang Hames39609992013-11-29 03:07:54 +00001009/// Replace/modify any TargetFrameIndex operands with a targte-dependent
1010/// sequence of memory operands that is recognized by PrologEpilogInserter.
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +00001011MachineBasicBlock *
1012TargetLoweringBase::emitPatchPoint(MachineInstr &InitialMI,
Lang Hames39609992013-11-29 03:07:54 +00001013 MachineBasicBlock *MBB) const {
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +00001014 MachineInstr *MI = &InitialMI;
Justin Bognerfdf9bf42017-10-10 23:50:49 +00001015 MachineFunction &MF = *MI->getMF();
Matthias Braun941a7052016-07-28 18:40:00 +00001016 MachineFrameInfo &MFI = MF.getFrameInfo();
Philip Reamescb0f9472015-12-23 23:44:28 +00001017
1018 // We're handling multiple types of operands here:
1019 // PATCHPOINT MetaArgs - live-in, read only, direct
1020 // STATEPOINT Deopt Spill - live-through, read only, indirect
1021 // STATEPOINT Deopt Alloca - live-through, read only, direct
1022 // (We're currently conservative and mark the deopt slots read/write in
Fangrui Songf78650a2018-07-30 19:41:25 +00001023 // practice.)
Philip Reamescb0f9472015-12-23 23:44:28 +00001024 // STATEPOINT GC Spill - live-through, read/write, indirect
1025 // STATEPOINT GC Alloca - live-through, read/write, direct
1026 // The live-in vs live-through is handled already (the live through ones are
1027 // all stack slots), but we need to handle the different type of stackmap
1028 // operands and memory effects here.
Lang Hames39609992013-11-29 03:07:54 +00001029
1030 // MI changes inside this loop as we grow operands.
1031 for(unsigned OperIdx = 0; OperIdx != MI->getNumOperands(); ++OperIdx) {
1032 MachineOperand &MO = MI->getOperand(OperIdx);
1033 if (!MO.isFI())
1034 continue;
1035
1036 // foldMemoryOperand builds a new MI after replacing a single FI operand
1037 // with the canonical set of five x86 addressing-mode operands.
1038 int FI = MO.getIndex();
1039 MachineInstrBuilder MIB = BuildMI(MF, MI->getDebugLoc(), MI->getDesc());
1040
1041 // Copy operands before the frame-index.
1042 for (unsigned i = 0; i < OperIdx; ++i)
Diana Picus116bbab2017-01-13 09:58:52 +00001043 MIB.add(MI->getOperand(i));
Philip Reamescb0f9472015-12-23 23:44:28 +00001044 // Add frame index operands recognized by stackmaps.cpp
1045 if (MFI.isStatepointSpillSlotObjectIndex(FI)) {
1046 // indirect-mem-ref tag, size, #FI, offset.
1047 // Used for spills inserted by StatepointLowering. This codepath is not
1048 // used for patchpoints/stackmaps at all, for these spilling is done via
1049 // foldMemoryOperand callback only.
1050 assert(MI->getOpcode() == TargetOpcode::STATEPOINT && "sanity");
1051 MIB.addImm(StackMaps::IndirectMemRefOp);
1052 MIB.addImm(MFI.getObjectSize(FI));
Diana Picus116bbab2017-01-13 09:58:52 +00001053 MIB.add(MI->getOperand(OperIdx));
Philip Reamescb0f9472015-12-23 23:44:28 +00001054 MIB.addImm(0);
1055 } else {
1056 // direct-mem-ref tag, #FI, offset.
1057 // Used by patchpoint, and direct alloca arguments to statepoints
1058 MIB.addImm(StackMaps::DirectMemRefOp);
Diana Picus116bbab2017-01-13 09:58:52 +00001059 MIB.add(MI->getOperand(OperIdx));
Philip Reamescb0f9472015-12-23 23:44:28 +00001060 MIB.addImm(0);
1061 }
Lang Hames39609992013-11-29 03:07:54 +00001062 // Copy the operands after the frame index.
1063 for (unsigned i = OperIdx + 1; i != MI->getNumOperands(); ++i)
Diana Picus116bbab2017-01-13 09:58:52 +00001064 MIB.add(MI->getOperand(i));
Lang Hames39609992013-11-29 03:07:54 +00001065
1066 // Inherit previous memory operands.
Chandler Carruthc73c0302018-08-16 21:30:05 +00001067 MIB.cloneMemRefs(*MI);
Lang Hames39609992013-11-29 03:07:54 +00001068 assert(MIB->mayLoad() && "Folded a stackmap use to a non-load!");
1069
1070 // Add a new memory operand for this FI.
Lang Hames39609992013-11-29 03:07:54 +00001071 assert(MFI.getObjectOffset(FI) != -1);
Philip Reames0365f1a2014-12-01 22:52:56 +00001072
Philip Reames18408d52019-03-12 19:12:33 +00001073 // Note: STATEPOINT MMOs are added during SelectionDAG. STACKMAP, and
1074 // PATCHPOINT should be updated to do the same. (TODO)
1075 if (MI->getOpcode() != TargetOpcode::STATEPOINT) {
1076 auto Flags = MachineMemOperand::MOLoad;
1077 MachineMemOperand *MMO = MF.getMachineMemOperand(
1078 MachinePointerInfo::getFixedStack(MF, FI), Flags,
1079 MF.getDataLayout().getPointerSize(), MFI.getObjectAlignment(FI));
1080 MIB->addMemOperand(MF, MMO);
Philip Reames0365f1a2014-12-01 22:52:56 +00001081 }
Philip Reames18408d52019-03-12 19:12:33 +00001082
Lang Hames39609992013-11-29 03:07:54 +00001083 // Replace the instruction and update the operand index.
1084 MBB->insert(MachineBasicBlock::iterator(MI), MIB);
1085 OperIdx += (MIB->getNumOperands() - MI->getNumOperands()) - 1;
1086 MI->eraseFromParent();
1087 MI = MIB;
1088 }
1089 return MBB;
1090}
1091
Dean Michael Berriscdca0732018-02-01 02:21:54 +00001092MachineBasicBlock *
1093TargetLoweringBase::emitXRayCustomEvent(MachineInstr &MI,
1094 MachineBasicBlock *MBB) const {
1095 assert(MI.getOpcode() == TargetOpcode::PATCHABLE_EVENT_CALL &&
1096 "Called emitXRayCustomEvent on the wrong MI!");
1097 auto &MF = *MI.getMF();
1098 auto MIB = BuildMI(MF, MI.getDebugLoc(), MI.getDesc());
1099 for (unsigned OpIdx = 0; OpIdx != MI.getNumOperands(); ++OpIdx)
1100 MIB.add(MI.getOperand(OpIdx));
1101
1102 MBB->insert(MachineBasicBlock::iterator(MI), MIB);
1103 MI.eraseFromParent();
1104 return MBB;
1105}
1106
Keith Wyss3d868232018-04-17 21:30:29 +00001107MachineBasicBlock *
1108TargetLoweringBase::emitXRayTypedEvent(MachineInstr &MI,
1109 MachineBasicBlock *MBB) const {
1110 assert(MI.getOpcode() == TargetOpcode::PATCHABLE_TYPED_EVENT_CALL &&
1111 "Called emitXRayTypedEvent on the wrong MI!");
1112 auto &MF = *MI.getMF();
1113 auto MIB = BuildMI(MF, MI.getDebugLoc(), MI.getDesc());
1114 for (unsigned OpIdx = 0; OpIdx != MI.getNumOperands(); ++OpIdx)
1115 MIB.add(MI.getOperand(OpIdx));
1116
1117 MBB->insert(MachineBasicBlock::iterator(MI), MIB);
1118 MI.eraseFromParent();
1119 return MBB;
1120}
1121
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001122/// findRepresentativeClass - Return the largest legal super-reg register class
1123/// of the register class for the specified type and its associated "cost".
Eric Christopher720ab842015-03-03 19:47:14 +00001124// This function is in TargetLowering because it uses RegClassForVT which would
1125// need to be moved to TargetRegisterInfo and would necessitate moving
1126// isTypeLegal over as well - a massive change that would just require
1127// TargetLowering having a TargetRegisterInfo class member that it would use.
Eric Christopher23a3a7c2015-02-26 00:00:24 +00001128std::pair<const TargetRegisterClass *, uint8_t>
1129TargetLoweringBase::findRepresentativeClass(const TargetRegisterInfo *TRI,
1130 MVT VT) const {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001131 const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
1132 if (!RC)
1133 return std::make_pair(RC, 0);
1134
1135 // Compute the set of all super-register classes.
1136 BitVector SuperRegRC(TRI->getNumRegClasses());
1137 for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI)
1138 SuperRegRC.setBitsInMask(RCI.getMask());
1139
1140 // Find the first legal register class with the largest spill size.
1141 const TargetRegisterClass *BestRC = RC;
Francis Visoiu Mistrihb52e0362017-05-17 01:07:53 +00001142 for (unsigned i : SuperRegRC.set_bits()) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001143 const TargetRegisterClass *SuperRC = TRI->getRegClass(i);
1144 // We want the largest possible spill size.
Krzysztof Parzyszek44e25f32017-04-24 18:55:33 +00001145 if (TRI->getSpillSize(*SuperRC) <= TRI->getSpillSize(*BestRC))
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001146 continue;
Krzysztof Parzyszekc8e8e2a2017-04-24 19:51:12 +00001147 if (!isLegalRC(*TRI, *SuperRC))
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001148 continue;
1149 BestRC = SuperRC;
1150 }
1151 return std::make_pair(BestRC, 1);
1152}
1153
1154/// computeRegisterProperties - Once all of the register classes are added,
1155/// this allows us to compute derived properties we expose.
Eric Christopher23a3a7c2015-02-26 00:00:24 +00001156void TargetLoweringBase::computeRegisterProperties(
1157 const TargetRegisterInfo *TRI) {
Craig Topper6438fc32014-11-17 00:26:50 +00001158 static_assert(MVT::LAST_VALUETYPE <= MVT::MAX_ALLOWED_VALUETYPE,
1159 "Too many value types for ValueTypeActions to hold!");
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001160
1161 // Everything defaults to needing one register.
1162 for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
1163 NumRegistersForVT[i] = 1;
1164 RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i;
1165 }
1166 // ...except isVoid, which doesn't need any registers.
1167 NumRegistersForVT[MVT::isVoid] = 0;
1168
1169 // Find the largest integer register class.
1170 unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE;
Craig Topperc0196b12014-04-14 00:51:57 +00001171 for (; RegClassForVT[LargestIntReg] == nullptr; --LargestIntReg)
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001172 assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
1173
1174 // Every integer value type larger than this largest register takes twice as
1175 // many registers to represent as the previous ValueType.
1176 for (unsigned ExpandedReg = LargestIntReg + 1;
1177 ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) {
1178 NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1];
1179 RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg;
1180 TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1);
1181 ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg,
1182 TypeExpandInteger);
1183 }
1184
1185 // Inspect all of the ValueType's smaller than the largest integer
1186 // register to see which ones need promotion.
1187 unsigned LegalIntReg = LargestIntReg;
1188 for (unsigned IntReg = LargestIntReg - 1;
1189 IntReg >= (unsigned)MVT::i1; --IntReg) {
1190 MVT IVT = (MVT::SimpleValueType)IntReg;
1191 if (isTypeLegal(IVT)) {
1192 LegalIntReg = IntReg;
1193 } else {
1194 RegisterTypeForVT[IntReg] = TransformToType[IntReg] =
Serge Gueltona4d9e222018-11-07 16:17:30 +00001195 (MVT::SimpleValueType)LegalIntReg;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001196 ValueTypeActions.setTypeAction(IVT, TypePromoteInteger);
1197 }
1198 }
1199
1200 // ppcf128 type is really two f64's.
1201 if (!isTypeLegal(MVT::ppcf128)) {
Petar Jovanovic23e44f52016-02-04 14:43:50 +00001202 if (isTypeLegal(MVT::f64)) {
1203 NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64];
1204 RegisterTypeForVT[MVT::ppcf128] = MVT::f64;
1205 TransformToType[MVT::ppcf128] = MVT::f64;
1206 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat);
1207 } else {
1208 NumRegistersForVT[MVT::ppcf128] = NumRegistersForVT[MVT::i128];
1209 RegisterTypeForVT[MVT::ppcf128] = RegisterTypeForVT[MVT::i128];
1210 TransformToType[MVT::ppcf128] = MVT::i128;
1211 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeSoftenFloat);
1212 }
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001213 }
1214
Akira Hatanaka3d055582013-03-01 21:11:44 +00001215 // Decide how to handle f128. If the target does not have native f128 support,
1216 // expand it to i128 and we will be generating soft float library calls.
1217 if (!isTypeLegal(MVT::f128)) {
1218 NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128];
1219 RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128];
1220 TransformToType[MVT::f128] = MVT::i128;
1221 ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat);
1222 }
1223
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001224 // Decide how to handle f64. If the target does not have native f64 support,
1225 // expand it to i64 and we will be generating soft float library calls.
1226 if (!isTypeLegal(MVT::f64)) {
1227 NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64];
1228 RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64];
1229 TransformToType[MVT::f64] = MVT::i64;
1230 ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat);
1231 }
1232
Ahmed Bougachaa0f35592015-03-28 01:22:37 +00001233 // Decide how to handle f32. If the target does not have native f32 support,
1234 // expand it to i32 and we will be generating soft float library calls.
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001235 if (!isTypeLegal(MVT::f32)) {
Ahmed Bougachaa0f35592015-03-28 01:22:37 +00001236 NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32];
1237 RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32];
1238 TransformToType[MVT::f32] = MVT::i32;
1239 ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001240 }
1241
Oliver Stannard56358572015-11-09 11:03:18 +00001242 // Decide how to handle f16. If the target does not have native f16 support,
1243 // promote it to f32, because there are no f16 library calls (except for
1244 // conversions).
Tim Northover20bd0ce2014-07-18 12:41:46 +00001245 if (!isTypeLegal(MVT::f16)) {
Oliver Stannard56358572015-11-09 11:03:18 +00001246 NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::f32];
1247 RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::f32];
1248 TransformToType[MVT::f16] = MVT::f32;
1249 ValueTypeActions.setTypeAction(MVT::f16, TypePromoteFloat);
Tim Northover20bd0ce2014-07-18 12:41:46 +00001250 }
1251
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001252 // Loop over all of the vector value types to see which need transformations.
1253 for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE;
1254 i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001255 MVT VT = (MVT::SimpleValueType) i;
1256 if (isTypeLegal(VT))
1257 continue;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001258
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001259 MVT EltVT = VT.getVectorElementType();
1260 unsigned NElts = VT.getVectorNumElements();
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001261 bool IsLegalWiderType = false;
1262 LegalizeTypeAction PreferredAction = getPreferredVectorAction(VT);
1263 switch (PreferredAction) {
Eugene Zelenkofb7f7922017-09-21 23:20:16 +00001264 case TypePromoteInteger:
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001265 // Try to promote the elements of integer vectors. If no legal
1266 // promotion was found, fall through to the widen-vector method.
Matt Arsenault940d19a2016-04-22 21:16:17 +00001267 for (unsigned nVT = i + 1; nVT <= MVT::LAST_INTEGER_VECTOR_VALUETYPE; ++nVT) {
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001268 MVT SVT = (MVT::SimpleValueType) nVT;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001269 // Promote vectors of integers to vectors with the same number
1270 // of elements, with a wider element type.
Sanjay Patel1ed771f2016-09-14 16:37:15 +00001271 if (SVT.getScalarSizeInBits() > EltVT.getSizeInBits() &&
Matt Arsenault940d19a2016-04-22 21:16:17 +00001272 SVT.getVectorNumElements() == NElts && isTypeLegal(SVT)) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001273 TransformToType[i] = SVT;
1274 RegisterTypeForVT[i] = SVT;
1275 NumRegistersForVT[i] = 1;
1276 ValueTypeActions.setTypeAction(VT, TypePromoteInteger);
1277 IsLegalWiderType = true;
1278 break;
1279 }
1280 }
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001281 if (IsLegalWiderType)
1282 break;
Galina Kistanovabd79f732017-06-03 05:11:14 +00001283 LLVM_FALLTHROUGH;
Eugene Zelenkofb7f7922017-09-21 23:20:16 +00001284
1285 case TypeWidenVector:
Craig Topper74168de2019-08-18 06:28:06 +00001286 if (isPowerOf2_32(NElts)) {
1287 // Try to widen the vector.
1288 for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
1289 MVT SVT = (MVT::SimpleValueType) nVT;
1290 if (SVT.getVectorElementType() == EltVT
1291 && SVT.getVectorNumElements() > NElts && isTypeLegal(SVT)) {
1292 TransformToType[i] = SVT;
1293 RegisterTypeForVT[i] = SVT;
1294 NumRegistersForVT[i] = 1;
1295 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1296 IsLegalWiderType = true;
1297 break;
1298 }
1299 }
1300 if (IsLegalWiderType)
1301 break;
1302 } else {
1303 // Only widen to the next power of 2 to keep consistency with EVT.
1304 MVT NVT = VT.getPow2VectorType();
1305 if (isTypeLegal(NVT)) {
1306 TransformToType[i] = NVT;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001307 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
Craig Topper74168de2019-08-18 06:28:06 +00001308 RegisterTypeForVT[i] = NVT;
1309 NumRegistersForVT[i] = 1;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001310 break;
1311 }
1312 }
Galina Kistanovabd79f732017-06-03 05:11:14 +00001313 LLVM_FALLTHROUGH;
Eugene Zelenkofb7f7922017-09-21 23:20:16 +00001314
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001315 case TypeSplitVector:
1316 case TypeScalarizeVector: {
1317 MVT IntermediateVT;
1318 MVT RegisterVT;
1319 unsigned NumIntermediates;
1320 NumRegistersForVT[i] = getVectorTypeBreakdownMVT(VT, IntermediateVT,
1321 NumIntermediates, RegisterVT, this);
1322 RegisterTypeForVT[i] = RegisterVT;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001323
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001324 MVT NVT = VT.getPow2VectorType();
1325 if (NVT == VT) {
1326 // Type is already a power of 2. The default action is to split.
1327 TransformToType[i] = MVT::Other;
1328 if (PreferredAction == TypeScalarizeVector)
1329 ValueTypeActions.setTypeAction(VT, TypeScalarizeVector);
Hao Liue02b1a02014-10-31 02:35:34 +00001330 else if (PreferredAction == TypeSplitVector)
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001331 ValueTypeActions.setTypeAction(VT, TypeSplitVector);
Hao Liue02b1a02014-10-31 02:35:34 +00001332 else
1333 // Set type action according to the number of elements.
1334 ValueTypeActions.setTypeAction(VT, NElts == 1 ? TypeScalarizeVector
1335 : TypeSplitVector);
Chandler Carruth9d010ff2014-07-03 00:23:43 +00001336 } else {
1337 TransformToType[i] = NVT;
1338 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1339 }
1340 break;
1341 }
1342 default:
1343 llvm_unreachable("Unknown vector legalization action!");
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001344 }
1345 }
1346
1347 // Determine the 'representative' register class for each value type.
1348 // An representative register class is the largest (meaning one which is
1349 // not a sub-register class / subreg register class) legal register class for
1350 // a group of value types. For example, on i386, i8, i16, and i32
1351 // representative would be GR32; while on x86_64 it's GR64.
1352 for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
1353 const TargetRegisterClass* RRC;
1354 uint8_t Cost;
Eric Christopher23a3a7c2015-02-26 00:00:24 +00001355 std::tie(RRC, Cost) = findRepresentativeClass(TRI, (MVT::SimpleValueType)i);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001356 RepRegClassForVT[i] = RRC;
1357 RepRegClassCostForVT[i] = Cost;
1358 }
1359}
1360
Mehdi Amini44ede332015-07-09 02:09:04 +00001361EVT TargetLoweringBase::getSetCCResultType(const DataLayout &DL, LLVMContext &,
1362 EVT VT) const {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001363 assert(!VT.isVector() && "No default SetCC type for vectors!");
Mehdi Amini44ede332015-07-09 02:09:04 +00001364 return getPointerTy(DL).SimpleTy;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001365}
1366
1367MVT::SimpleValueType TargetLoweringBase::getCmpLibcallReturnType() const {
1368 return MVT::i32; // return the default value
1369}
1370
1371/// getVectorTypeBreakdown - Vector types are broken down into some number of
1372/// legal first class types. For example, MVT::v8f32 maps to 2 MVT::v4f32
1373/// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
1374/// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
1375///
1376/// This method returns the number of registers needed, and the VT for each
1377/// register. It also returns the VT and quantity of the intermediate values
1378/// before they are promoted/expanded.
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001379unsigned TargetLoweringBase::getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
1380 EVT &IntermediateVT,
1381 unsigned &NumIntermediates,
1382 MVT &RegisterVT) const {
1383 unsigned NumElts = VT.getVectorNumElements();
1384
1385 // If there is a wider vector type with the same element type as this one,
1386 // or a promoted vector type that has the same number of elements which
1387 // are wider, then we should convert to that legal vector type.
1388 // This handles things like <2 x float> -> <4 x float> and
1389 // <4 x i1> -> <4 x i32>.
1390 LegalizeTypeAction TA = getTypeAction(Context, VT);
1391 if (NumElts != 1 && (TA == TypeWidenVector || TA == TypePromoteInteger)) {
1392 EVT RegisterEVT = getTypeToTransformTo(Context, VT);
1393 if (isTypeLegal(RegisterEVT)) {
1394 IntermediateVT = RegisterEVT;
1395 RegisterVT = RegisterEVT.getSimpleVT();
1396 NumIntermediates = 1;
1397 return 1;
1398 }
1399 }
1400
1401 // Figure out the right, legal destination reg to copy into.
1402 EVT EltTy = VT.getVectorElementType();
1403
1404 unsigned NumVectorRegs = 1;
1405
1406 // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally we
1407 // could break down into LHS/RHS like LegalizeDAG does.
1408 if (!isPowerOf2_32(NumElts)) {
1409 NumVectorRegs = NumElts;
1410 NumElts = 1;
1411 }
1412
1413 // Divide the input until we get to a supported size. This will always
1414 // end with a scalar if the target doesn't support vectors.
1415 while (NumElts > 1 && !isTypeLegal(
1416 EVT::getVectorVT(Context, EltTy, NumElts))) {
1417 NumElts >>= 1;
1418 NumVectorRegs <<= 1;
1419 }
1420
1421 NumIntermediates = NumVectorRegs;
1422
1423 EVT NewVT = EVT::getVectorVT(Context, EltTy, NumElts);
1424 if (!isTypeLegal(NewVT))
1425 NewVT = EltTy;
1426 IntermediateVT = NewVT;
1427
1428 MVT DestVT = getRegisterType(Context, NewVT);
1429 RegisterVT = DestVT;
1430 unsigned NewVTSize = NewVT.getSizeInBits();
1431
1432 // Convert sizes such as i33 to i64.
1433 if (!isPowerOf2_32(NewVTSize))
1434 NewVTSize = NextPowerOf2(NewVTSize);
1435
1436 if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16.
1437 return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
1438
1439 // Otherwise, promotion or legal types use the same number of registers as
1440 // the vector decimated to the appropriate level.
1441 return NumVectorRegs;
1442}
1443
1444/// Get the EVTs and ArgFlags collections that represent the legalized return
1445/// type of the given function. This does not require a DAG or a return value,
1446/// and is suitable for use before any DAGs for the function are constructed.
1447/// TODO: Move this out of TargetLowering.cpp.
Matt Arsenault81920b02018-07-28 13:25:19 +00001448void llvm::GetReturnInfo(CallingConv::ID CC, Type *ReturnType,
1449 AttributeList attr,
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001450 SmallVectorImpl<ISD::OutputArg> &Outs,
Mehdi Amini56228da2015-07-09 01:57:34 +00001451 const TargetLowering &TLI, const DataLayout &DL) {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001452 SmallVector<EVT, 4> ValueVTs;
Mehdi Amini56228da2015-07-09 01:57:34 +00001453 ComputeValueVTs(TLI, DL, ReturnType, ValueVTs);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001454 unsigned NumValues = ValueVTs.size();
1455 if (NumValues == 0) return;
1456
1457 for (unsigned j = 0, f = NumValues; j != f; ++j) {
1458 EVT VT = ValueVTs[j];
1459 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
1460
Reid Klecknerb5180542017-03-21 16:57:19 +00001461 if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001462 ExtendKind = ISD::SIGN_EXTEND;
Reid Klecknerb5180542017-03-21 16:57:19 +00001463 else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001464 ExtendKind = ISD::ZERO_EXTEND;
1465
1466 // FIXME: C calling convention requires the return type to be promoted to
1467 // at least 32-bit. But this is not necessary for non-C calling
1468 // conventions. The frontend should mark functions whose return values
1469 // require promoting with signext or zeroext attributes.
1470 if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger()) {
1471 MVT MinVT = TLI.getRegisterType(ReturnType->getContext(), MVT::i32);
1472 if (VT.bitsLT(MinVT))
1473 VT = MinVT;
1474 }
1475
Simon Dardis212cccb2017-06-09 14:37:08 +00001476 unsigned NumParts =
Matt Arsenault81920b02018-07-28 13:25:19 +00001477 TLI.getNumRegistersForCallingConv(ReturnType->getContext(), CC, VT);
Simon Dardis212cccb2017-06-09 14:37:08 +00001478 MVT PartVT =
Matt Arsenault81920b02018-07-28 13:25:19 +00001479 TLI.getRegisterTypeForCallingConv(ReturnType->getContext(), CC, VT);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001480
1481 // 'inreg' on function refers to return value
1482 ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
Reid Klecknerb5180542017-03-21 16:57:19 +00001483 if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::InReg))
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001484 Flags.setInReg();
1485
1486 // Propagate extension type if any
Reid Klecknerb5180542017-03-21 16:57:19 +00001487 if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001488 Flags.setSExt();
Reid Klecknerb5180542017-03-21 16:57:19 +00001489 else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001490 Flags.setZExt();
1491
1492 for (unsigned i = 0; i < NumParts; ++i)
Rui Ueyama49a3ad22019-07-16 04:46:31 +00001493 Outs.push_back(ISD::OutputArg(Flags, PartVT, VT, /*isfixed=*/true, 0, 0));
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001494 }
1495}
1496
1497/// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
1498/// function arguments in the caller parameter area. This is the actual
1499/// alignment, not its logarithm.
Mehdi Amini5c183d52015-07-09 02:09:28 +00001500unsigned TargetLoweringBase::getByValTypeAlignment(Type *Ty,
1501 const DataLayout &DL) const {
1502 return DL.getABITypeAlignment(Ty);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001503}
1504
Sanjay Patel0f9dcf82015-07-29 18:24:18 +00001505bool TargetLoweringBase::allowsMemoryAccess(LLVMContext &Context,
1506 const DataLayout &DL, EVT VT,
1507 unsigned AddrSpace,
1508 unsigned Alignment,
Simon Pilgrim4e0648a2019-06-12 17:14:03 +00001509 MachineMemOperand::Flags Flags,
Sanjay Patel0f9dcf82015-07-29 18:24:18 +00001510 bool *Fast) const {
1511 // Check if the specified alignment is sufficient based on the data layout.
1512 // TODO: While using the data layout works in practice, a better solution
1513 // would be to implement this check directly (make this a virtual function).
1514 // For example, the ABI alignment may change based on software platform while
1515 // this function should only be affected by hardware implementation.
1516 Type *Ty = VT.getTypeForEVT(Context);
1517 if (Alignment >= DL.getABITypeAlignment(Ty)) {
1518 // Assume that an access that meets the ABI-specified alignment is fast.
1519 if (Fast != nullptr)
1520 *Fast = true;
1521 return true;
1522 }
Fangrui Songf78650a2018-07-30 19:41:25 +00001523
Sanjay Patel0f9dcf82015-07-29 18:24:18 +00001524 // This is a misaligned access.
Simon Pilgrim4e0648a2019-06-12 17:14:03 +00001525 return allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment, Flags, Fast);
Sanjay Patel0f9dcf82015-07-29 18:24:18 +00001526}
1527
Simon Pilgrim266f4392019-06-11 11:00:23 +00001528bool TargetLoweringBase::allowsMemoryAccess(LLVMContext &Context,
1529 const DataLayout &DL, EVT VT,
1530 const MachineMemOperand &MMO,
1531 bool *Fast) const {
1532 return allowsMemoryAccess(Context, DL, VT, MMO.getAddrSpace(),
Simon Pilgrim4e0648a2019-06-12 17:14:03 +00001533 MMO.getAlignment(), MMO.getFlags(), Fast);
Simon Pilgrim266f4392019-06-11 11:00:23 +00001534}
1535
Sanjay Pateld66607b2016-04-26 17:11:17 +00001536BranchProbability TargetLoweringBase::getPredictableBranchThreshold() const {
1537 return BranchProbability(MinPercentageForPredictableBranch, 100);
1538}
Sanjay Patel0f9dcf82015-07-29 18:24:18 +00001539
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001540//===----------------------------------------------------------------------===//
1541// TargetTransformInfo Helpers
1542//===----------------------------------------------------------------------===//
1543
1544int TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode) const {
1545 enum InstructionOpcodes {
1546#define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM,
1547#define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM
1548#include "llvm/IR/Instruction.def"
1549 };
1550 switch (static_cast<InstructionOpcodes>(Opcode)) {
1551 case Ret: return 0;
1552 case Br: return 0;
1553 case Switch: return 0;
1554 case IndirectBr: return 0;
1555 case Invoke: return 0;
Craig Topper784929d2019-02-08 20:48:56 +00001556 case CallBr: return 0;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001557 case Resume: return 0;
1558 case Unreachable: return 0;
David Majnemer654e1302015-07-31 17:58:14 +00001559 case CleanupRet: return 0;
David Majnemer654e1302015-07-31 17:58:14 +00001560 case CatchRet: return 0;
David Majnemer8a1c45d2015-12-12 05:38:55 +00001561 case CatchPad: return 0;
1562 case CatchSwitch: return 0;
David Majnemer8a1c45d2015-12-12 05:38:55 +00001563 case CleanupPad: return 0;
Cameron McInallycbde0d92018-11-13 18:15:47 +00001564 case FNeg: return ISD::FNEG;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001565 case Add: return ISD::ADD;
1566 case FAdd: return ISD::FADD;
1567 case Sub: return ISD::SUB;
1568 case FSub: return ISD::FSUB;
1569 case Mul: return ISD::MUL;
1570 case FMul: return ISD::FMUL;
1571 case UDiv: return ISD::UDIV;
Benjamin Kramerce4b3fe2014-04-27 18:47:54 +00001572 case SDiv: return ISD::SDIV;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001573 case FDiv: return ISD::FDIV;
1574 case URem: return ISD::UREM;
1575 case SRem: return ISD::SREM;
1576 case FRem: return ISD::FREM;
1577 case Shl: return ISD::SHL;
1578 case LShr: return ISD::SRL;
1579 case AShr: return ISD::SRA;
1580 case And: return ISD::AND;
1581 case Or: return ISD::OR;
1582 case Xor: return ISD::XOR;
1583 case Alloca: return 0;
1584 case Load: return ISD::LOAD;
1585 case Store: return ISD::STORE;
1586 case GetElementPtr: return 0;
1587 case Fence: return 0;
1588 case AtomicCmpXchg: return 0;
1589 case AtomicRMW: return 0;
1590 case Trunc: return ISD::TRUNCATE;
1591 case ZExt: return ISD::ZERO_EXTEND;
1592 case SExt: return ISD::SIGN_EXTEND;
1593 case FPToUI: return ISD::FP_TO_UINT;
1594 case FPToSI: return ISD::FP_TO_SINT;
1595 case UIToFP: return ISD::UINT_TO_FP;
1596 case SIToFP: return ISD::SINT_TO_FP;
1597 case FPTrunc: return ISD::FP_ROUND;
1598 case FPExt: return ISD::FP_EXTEND;
1599 case PtrToInt: return ISD::BITCAST;
1600 case IntToPtr: return ISD::BITCAST;
1601 case BitCast: return ISD::BITCAST;
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001602 case AddrSpaceCast: return ISD::ADDRSPACECAST;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001603 case ICmp: return ISD::SETCC;
1604 case FCmp: return ISD::SETCC;
1605 case PHI: return 0;
1606 case Call: return 0;
1607 case Select: return ISD::SELECT;
1608 case UserOp1: return 0;
1609 case UserOp2: return 0;
1610 case VAArg: return 0;
1611 case ExtractElement: return ISD::EXTRACT_VECTOR_ELT;
1612 case InsertElement: return ISD::INSERT_VECTOR_ELT;
1613 case ShuffleVector: return ISD::VECTOR_SHUFFLE;
1614 case ExtractValue: return ISD::MERGE_VALUES;
1615 case InsertValue: return ISD::MERGE_VALUES;
1616 case LandingPad: return 0;
1617 }
1618
1619 llvm_unreachable("Unknown instruction type encountered!");
1620}
1621
Chandler Carruth93205eb2015-08-05 18:08:10 +00001622std::pair<int, MVT>
Mehdi Amini44ede332015-07-09 02:09:04 +00001623TargetLoweringBase::getTypeLegalizationCost(const DataLayout &DL,
1624 Type *Ty) const {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001625 LLVMContext &C = Ty->getContext();
Mehdi Amini44ede332015-07-09 02:09:04 +00001626 EVT MTy = getValueType(DL, Ty);
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001627
Chandler Carruth93205eb2015-08-05 18:08:10 +00001628 int Cost = 1;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001629 // We keep legalizing the type until we find a legal kind. We assume that
1630 // the only operation that costs anything is the split. After splitting
1631 // we need to handle two types.
1632 while (true) {
1633 LegalizeKind LK = getTypeConversion(C, MTy);
1634
1635 if (LK.first == TypeLegal)
1636 return std::make_pair(Cost, MTy.getSimpleVT());
1637
1638 if (LK.first == TypeSplitVector || LK.first == TypeExpandInteger)
1639 Cost *= 2;
1640
Chih-Hung Hsiehed7d81e2015-12-03 22:02:40 +00001641 // Do not loop with f128 type.
1642 if (MTy == LK.second)
1643 return std::make_pair(Cost, MTy.getSimpleVT());
1644
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001645 // Keep legalizing the type.
1646 MTy = LK.second;
1647 }
1648}
1649
David L Kreitzerd5c67552016-10-14 17:56:00 +00001650Value *TargetLoweringBase::getDefaultSafeStackPointerLocation(IRBuilder<> &IRB,
1651 bool UseTLS) const {
1652 // compiler-rt provides a variable with a magic name. Targets that do not
1653 // link with compiler-rt may also provide such a variable.
1654 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1655 const char *UnsafeStackPtrVar = "__safestack_unsafe_stack_ptr";
1656 auto UnsafeStackPtr =
1657 dyn_cast_or_null<GlobalVariable>(M->getNamedValue(UnsafeStackPtrVar));
1658
1659 Type *StackPtrTy = Type::getInt8PtrTy(M->getContext());
1660
1661 if (!UnsafeStackPtr) {
1662 auto TLSModel = UseTLS ?
1663 GlobalValue::InitialExecTLSModel :
1664 GlobalValue::NotThreadLocal;
1665 // The global variable is not defined yet, define it ourselves.
1666 // We use the initial-exec TLS model because we do not support the
1667 // variable living anywhere other than in the main executable.
1668 UnsafeStackPtr = new GlobalVariable(
1669 *M, StackPtrTy, false, GlobalValue::ExternalLinkage, nullptr,
1670 UnsafeStackPtrVar, nullptr, TLSModel);
1671 } else {
1672 // The variable exists, check its type and attributes.
1673 if (UnsafeStackPtr->getValueType() != StackPtrTy)
1674 report_fatal_error(Twine(UnsafeStackPtrVar) + " must have void* type");
1675 if (UseTLS != UnsafeStackPtr->isThreadLocal())
1676 report_fatal_error(Twine(UnsafeStackPtrVar) + " must " +
1677 (UseTLS ? "" : "not ") + "be thread-local");
1678 }
1679 return UnsafeStackPtr;
1680}
1681
Evgeniy Stepanovd1aad262015-10-26 18:28:25 +00001682Value *TargetLoweringBase::getSafeStackPointerLocation(IRBuilder<> &IRB) const {
1683 if (!TM.getTargetTriple().isAndroid())
David L Kreitzerd5c67552016-10-14 17:56:00 +00001684 return getDefaultSafeStackPointerLocation(IRB, true);
Evgeniy Stepanovd1aad262015-10-26 18:28:25 +00001685
1686 // Android provides a libc function to retrieve the address of the current
1687 // thread's unsafe stack pointer.
1688 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1689 Type *StackPtrTy = Type::getInt8PtrTy(M->getContext());
James Y Knight13680222019-02-01 02:28:03 +00001690 FunctionCallee Fn = M->getOrInsertFunction("__safestack_pointer_address",
1691 StackPtrTy->getPointerTo(0));
Evgeniy Stepanovd1aad262015-10-26 18:28:25 +00001692 return IRB.CreateCall(Fn);
1693}
1694
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001695//===----------------------------------------------------------------------===//
1696// Loop Strength Reduction hooks
1697//===----------------------------------------------------------------------===//
1698
1699/// isLegalAddressingMode - Return true if the addressing mode represented
1700/// by AM is legal for this target, for a load/store of the specified type.
Mehdi Amini0cdec1e2015-07-09 02:09:40 +00001701bool TargetLoweringBase::isLegalAddressingMode(const DataLayout &DL,
1702 const AddrMode &AM, Type *Ty,
Jonas Paulsson024e3192017-07-21 11:59:37 +00001703 unsigned AS, Instruction *I) const {
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001704 // The default implementation of this implements a conservative RISCy, r+r and
1705 // r+i addr mode.
1706
1707 // Allows a sign-extended 16-bit immediate field.
1708 if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1)
1709 return false;
1710
1711 // No global is ever allowed as a base.
1712 if (AM.BaseGV)
1713 return false;
1714
1715 // Only support r+r,
1716 switch (AM.Scale) {
1717 case 0: // "r+i" or just "i", depending on HasBaseReg.
1718 break;
1719 case 1:
1720 if (AM.HasBaseReg && AM.BaseOffs) // "r+r+i" is not allowed.
1721 return false;
1722 // Otherwise we have r+r or r+i.
1723 break;
1724 case 2:
1725 if (AM.HasBaseReg || AM.BaseOffs) // 2*r+r or 2*r+i is not allowed.
1726 return false;
1727 // Allow 2*r as r+r.
1728 break;
Tom Stellard728d4172014-02-14 21:10:34 +00001729 default: // Don't allow n * r
1730 return false;
Benjamin Kramer56b31bd2013-01-11 20:05:37 +00001731 }
1732
1733 return true;
1734}
Tim Shen00127562016-04-08 21:26:31 +00001735
1736//===----------------------------------------------------------------------===//
1737// Stack Protector
1738//===----------------------------------------------------------------------===//
1739
1740// For OpenBSD return its special guard variable. Otherwise return nullptr,
1741// so that SelectionDAG handle SSP.
1742Value *TargetLoweringBase::getIRStackGuard(IRBuilder<> &IRB) const {
1743 if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
1744 Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
1745 PointerType *PtrTy = Type::getInt8PtrTy(M.getContext());
Tim Shena5cc25e2016-08-22 18:26:27 +00001746 return M.getOrInsertGlobal("__guard_local", PtrTy);
Tim Shen00127562016-04-08 21:26:31 +00001747 }
1748 return nullptr;
1749}
1750
1751// Currently only support "standard" __stack_chk_guard.
1752// TODO: add LOAD_STACK_GUARD support.
1753void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
Eli Friedman06441302018-04-21 00:07:46 +00001754 if (!M.getNamedValue("__stack_chk_guard"))
1755 new GlobalVariable(M, Type::getInt8PtrTy(M.getContext()), false,
1756 GlobalVariable::ExternalLinkage,
1757 nullptr, "__stack_chk_guard");
Tim Shen00127562016-04-08 21:26:31 +00001758}
1759
1760// Currently only support "standard" __stack_chk_guard.
1761// TODO: add LOAD_STACK_GUARD support.
Tim Shena1d8bc52016-04-19 20:14:52 +00001762Value *TargetLoweringBase::getSDagStackGuard(const Module &M) const {
Eli Friedman06441302018-04-21 00:07:46 +00001763 return M.getNamedValue("__stack_chk_guard");
Tim Shen00127562016-04-08 21:26:31 +00001764}
Etienne Bergeron22bfa832016-06-07 20:15:35 +00001765
James Y Knight7976eb52019-02-01 20:43:25 +00001766Function *TargetLoweringBase::getSSPStackGuardCheck(const Module &M) const {
Etienne Bergeron22bfa832016-06-07 20:15:35 +00001767 return nullptr;
1768}
Evandro Menezese45de8a2016-09-26 15:32:33 +00001769
Evandro Menezeseb97e352016-10-25 19:53:51 +00001770unsigned TargetLoweringBase::getMinimumJumpTableEntries() const {
1771 return MinimumJumpTableEntries;
1772}
1773
1774void TargetLoweringBase::setMinimumJumpTableEntries(unsigned Val) {
1775 MinimumJumpTableEntries = Val;
1776}
1777
Jun Bum Lim919f9e82017-04-28 16:04:03 +00001778unsigned TargetLoweringBase::getMinimumJumpTableDensity(bool OptForSize) const {
1779 return OptForSize ? OptsizeJumpTableDensity : JumpTableDensity;
1780}
1781
Evandro Menezese45de8a2016-09-26 15:32:33 +00001782unsigned TargetLoweringBase::getMaximumJumpTableSize() const {
1783 return MaximumJumpTableSize;
1784}
1785
1786void TargetLoweringBase::setMaximumJumpTableSize(unsigned Val) {
1787 MaximumJumpTableSize = Val;
1788}
Sanjay Patel0051efc2016-10-20 16:55:45 +00001789
1790//===----------------------------------------------------------------------===//
1791// Reciprocal Estimates
1792//===----------------------------------------------------------------------===//
1793
1794/// Get the reciprocal estimate attribute string for a function that will
1795/// override the target defaults.
1796static StringRef getRecipEstimateForFunc(MachineFunction &MF) {
Matthias Braunf1caa282017-12-15 22:22:58 +00001797 const Function &F = MF.getFunction();
1798 return F.getFnAttribute("reciprocal-estimates").getValueAsString();
Sanjay Patel0051efc2016-10-20 16:55:45 +00001799}
1800
1801/// Construct a string for the given reciprocal operation of the given type.
1802/// This string should match the corresponding option to the front-end's
1803/// "-mrecip" flag assuming those strings have been passed through in an
1804/// attribute string. For example, "vec-divf" for a division of a vXf32.
1805static std::string getReciprocalOpName(bool IsSqrt, EVT VT) {
1806 std::string Name = VT.isVector() ? "vec-" : "";
1807
1808 Name += IsSqrt ? "sqrt" : "div";
1809
1810 // TODO: Handle "half" or other float types?
1811 if (VT.getScalarType() == MVT::f64) {
1812 Name += "d";
1813 } else {
1814 assert(VT.getScalarType() == MVT::f32 &&
1815 "Unexpected FP type for reciprocal estimate");
1816 Name += "f";
1817 }
1818
1819 return Name;
1820}
1821
1822/// Return the character position and value (a single numeric character) of a
1823/// customized refinement operation in the input string if it exists. Return
1824/// false if there is no customized refinement step count.
1825static bool parseRefinementStep(StringRef In, size_t &Position,
1826 uint8_t &Value) {
1827 const char RefStepToken = ':';
1828 Position = In.find(RefStepToken);
1829 if (Position == StringRef::npos)
1830 return false;
1831
1832 StringRef RefStepString = In.substr(Position + 1);
1833 // Allow exactly one numeric character for the additional refinement
1834 // step parameter.
1835 if (RefStepString.size() == 1) {
1836 char RefStepChar = RefStepString[0];
1837 if (RefStepChar >= '0' && RefStepChar <= '9') {
1838 Value = RefStepChar - '0';
1839 return true;
1840 }
1841 }
1842 report_fatal_error("Invalid refinement step for -recip.");
1843}
1844
1845/// For the input attribute string, return one of the ReciprocalEstimate enum
1846/// status values (enabled, disabled, or not specified) for this operation on
1847/// the specified data type.
1848static int getOpEnabled(bool IsSqrt, EVT VT, StringRef Override) {
1849 if (Override.empty())
1850 return TargetLoweringBase::ReciprocalEstimate::Unspecified;
1851
1852 SmallVector<StringRef, 4> OverrideVector;
Craig Topper7413b322018-05-07 01:32:18 +00001853 Override.split(OverrideVector, ',');
Sanjay Patel0051efc2016-10-20 16:55:45 +00001854 unsigned NumArgs = OverrideVector.size();
1855
1856 // Check if "all", "none", or "default" was specified.
1857 if (NumArgs == 1) {
1858 // Look for an optional setting of the number of refinement steps needed
1859 // for this type of reciprocal operation.
1860 size_t RefPos;
1861 uint8_t RefSteps;
1862 if (parseRefinementStep(Override, RefPos, RefSteps)) {
1863 // Split the string for further processing.
1864 Override = Override.substr(0, RefPos);
1865 }
1866
1867 // All reciprocal types are enabled.
1868 if (Override == "all")
1869 return TargetLoweringBase::ReciprocalEstimate::Enabled;
1870
1871 // All reciprocal types are disabled.
1872 if (Override == "none")
1873 return TargetLoweringBase::ReciprocalEstimate::Disabled;
1874
1875 // Target defaults for enablement are used.
1876 if (Override == "default")
1877 return TargetLoweringBase::ReciprocalEstimate::Unspecified;
1878 }
1879
1880 // The attribute string may omit the size suffix ('f'/'d').
1881 std::string VTName = getReciprocalOpName(IsSqrt, VT);
1882 std::string VTNameNoSize = VTName;
Sanjay Patel501be9b2016-10-21 14:58:30 +00001883 VTNameNoSize.pop_back();
Sanjay Patel0051efc2016-10-20 16:55:45 +00001884 static const char DisabledPrefix = '!';
1885
1886 for (StringRef RecipType : OverrideVector) {
1887 size_t RefPos;
1888 uint8_t RefSteps;
1889 if (parseRefinementStep(RecipType, RefPos, RefSteps))
1890 RecipType = RecipType.substr(0, RefPos);
1891
1892 // Ignore the disablement token for string matching.
1893 bool IsDisabled = RecipType[0] == DisabledPrefix;
1894 if (IsDisabled)
1895 RecipType = RecipType.substr(1);
1896
1897 if (RecipType.equals(VTName) || RecipType.equals(VTNameNoSize))
1898 return IsDisabled ? TargetLoweringBase::ReciprocalEstimate::Disabled
1899 : TargetLoweringBase::ReciprocalEstimate::Enabled;
1900 }
1901
1902 return TargetLoweringBase::ReciprocalEstimate::Unspecified;
1903}
1904
1905/// For the input attribute string, return the customized refinement step count
1906/// for this operation on the specified data type. If the step count does not
1907/// exist, return the ReciprocalEstimate enum value for unspecified.
1908static int getOpRefinementSteps(bool IsSqrt, EVT VT, StringRef Override) {
1909 if (Override.empty())
1910 return TargetLoweringBase::ReciprocalEstimate::Unspecified;
1911
1912 SmallVector<StringRef, 4> OverrideVector;
Craig Topper7413b322018-05-07 01:32:18 +00001913 Override.split(OverrideVector, ',');
Sanjay Patel0051efc2016-10-20 16:55:45 +00001914 unsigned NumArgs = OverrideVector.size();
1915
1916 // Check if "all", "default", or "none" was specified.
1917 if (NumArgs == 1) {
1918 // Look for an optional setting of the number of refinement steps needed
1919 // for this type of reciprocal operation.
1920 size_t RefPos;
1921 uint8_t RefSteps;
1922 if (!parseRefinementStep(Override, RefPos, RefSteps))
1923 return TargetLoweringBase::ReciprocalEstimate::Unspecified;
1924
1925 // Split the string for further processing.
1926 Override = Override.substr(0, RefPos);
1927 assert(Override != "none" &&
1928 "Disabled reciprocals, but specifed refinement steps?");
1929
1930 // If this is a general override, return the specified number of steps.
1931 if (Override == "all" || Override == "default")
1932 return RefSteps;
1933 }
1934
1935 // The attribute string may omit the size suffix ('f'/'d').
1936 std::string VTName = getReciprocalOpName(IsSqrt, VT);
1937 std::string VTNameNoSize = VTName;
Sanjay Patel501be9b2016-10-21 14:58:30 +00001938 VTNameNoSize.pop_back();
Sanjay Patel0051efc2016-10-20 16:55:45 +00001939
1940 for (StringRef RecipType : OverrideVector) {
1941 size_t RefPos;
1942 uint8_t RefSteps;
1943 if (!parseRefinementStep(RecipType, RefPos, RefSteps))
1944 continue;
1945
1946 RecipType = RecipType.substr(0, RefPos);
1947 if (RecipType.equals(VTName) || RecipType.equals(VTNameNoSize))
1948 return RefSteps;
1949 }
1950
1951 return TargetLoweringBase::ReciprocalEstimate::Unspecified;
1952}
1953
1954int TargetLoweringBase::getRecipEstimateSqrtEnabled(EVT VT,
1955 MachineFunction &MF) const {
1956 return getOpEnabled(true, VT, getRecipEstimateForFunc(MF));
1957}
1958
1959int TargetLoweringBase::getRecipEstimateDivEnabled(EVT VT,
1960 MachineFunction &MF) const {
1961 return getOpEnabled(false, VT, getRecipEstimateForFunc(MF));
1962}
1963
1964int TargetLoweringBase::getSqrtRefinementSteps(EVT VT,
1965 MachineFunction &MF) const {
1966 return getOpRefinementSteps(true, VT, getRecipEstimateForFunc(MF));
1967}
1968
1969int TargetLoweringBase::getDivRefinementSteps(EVT VT,
1970 MachineFunction &MF) const {
1971 return getOpRefinementSteps(false, VT, getRecipEstimateForFunc(MF));
1972}
Matthias Braun744c2152017-04-28 20:25:05 +00001973
1974void TargetLoweringBase::finalizeLowering(MachineFunction &MF) const {
1975 MF.getRegInfo().freezeReservedRegs(MF);
1976}