LLVM 20.0.0git
TargetLoweringBase.cpp
Go to the documentation of this file.
1//===- TargetLoweringBase.cpp - Implement the TargetLoweringBase class ----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This implements the TargetLoweringBase class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/ADT/BitVector.h"
14#include "llvm/ADT/STLExtras.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/Twine.h"
19#include "llvm/Analysis/Loads.h"
38#include "llvm/IR/Attributes.h"
39#include "llvm/IR/CallingConv.h"
40#include "llvm/IR/DataLayout.h"
42#include "llvm/IR/Function.h"
43#include "llvm/IR/GlobalValue.h"
45#include "llvm/IR/IRBuilder.h"
46#include "llvm/IR/Module.h"
47#include "llvm/IR/Type.h"
57#include <algorithm>
58#include <cassert>
59#include <cstdint>
60#include <cstring>
61#include <iterator>
62#include <string>
63#include <tuple>
64#include <utility>
65
66using namespace llvm;
67
69 "jump-is-expensive", cl::init(false),
70 cl::desc("Do not create extra branches to split comparison logic."),
72
74 ("min-jump-table-entries", cl::init(4), cl::Hidden,
75 cl::desc("Set minimum number of entries to use a jump table."));
76
78 ("max-jump-table-size", cl::init(UINT_MAX), cl::Hidden,
79 cl::desc("Set maximum size of jump tables."));
80
81/// Minimum jump table density for normal functions.
83 JumpTableDensity("jump-table-density", cl::init(10), cl::Hidden,
84 cl::desc("Minimum density for building a jump table in "
85 "a normal function"));
86
87/// Minimum jump table density for -Os or -Oz functions.
89 "optsize-jump-table-density", cl::init(40), cl::Hidden,
90 cl::desc("Minimum density for building a jump table in "
91 "an optsize function"));
92
93// FIXME: This option is only to test if the strict fp operation processed
94// correctly by preventing mutating strict fp operation to normal fp operation
95// during development. When the backend supports strict float operation, this
96// option will be meaningless.
97static cl::opt<bool> DisableStrictNodeMutation("disable-strictnode-mutation",
98 cl::desc("Don't mutate strict-float node to a legalize node"),
99 cl::init(false), cl::Hidden);
100
101/// GetFPLibCall - Helper to return the right libcall for the given floating
102/// point type, or UNKNOWN_LIBCALL if there is none.
104 RTLIB::Libcall Call_F32,
105 RTLIB::Libcall Call_F64,
106 RTLIB::Libcall Call_F80,
107 RTLIB::Libcall Call_F128,
108 RTLIB::Libcall Call_PPCF128) {
109 return
110 VT == MVT::f32 ? Call_F32 :
111 VT == MVT::f64 ? Call_F64 :
112 VT == MVT::f80 ? Call_F80 :
113 VT == MVT::f128 ? Call_F128 :
114 VT == MVT::ppcf128 ? Call_PPCF128 :
115 RTLIB::UNKNOWN_LIBCALL;
116}
117
118/// getFPEXT - Return the FPEXT_*_* value for the given types, or
119/// UNKNOWN_LIBCALL if there is none.
121 if (OpVT == MVT::f16) {
122 if (RetVT == MVT::f32)
123 return FPEXT_F16_F32;
124 if (RetVT == MVT::f64)
125 return FPEXT_F16_F64;
126 if (RetVT == MVT::f80)
127 return FPEXT_F16_F80;
128 if (RetVT == MVT::f128)
129 return FPEXT_F16_F128;
130 } else if (OpVT == MVT::f32) {
131 if (RetVT == MVT::f64)
132 return FPEXT_F32_F64;
133 if (RetVT == MVT::f128)
134 return FPEXT_F32_F128;
135 if (RetVT == MVT::ppcf128)
136 return FPEXT_F32_PPCF128;
137 } else if (OpVT == MVT::f64) {
138 if (RetVT == MVT::f128)
139 return FPEXT_F64_F128;
140 else if (RetVT == MVT::ppcf128)
141 return FPEXT_F64_PPCF128;
142 } else if (OpVT == MVT::f80) {
143 if (RetVT == MVT::f128)
144 return FPEXT_F80_F128;
145 } else if (OpVT == MVT::bf16) {
146 if (RetVT == MVT::f32)
147 return FPEXT_BF16_F32;
148 }
149
150 return UNKNOWN_LIBCALL;
151}
152
153/// getFPROUND - Return the FPROUND_*_* value for the given types, or
154/// UNKNOWN_LIBCALL if there is none.
156 if (RetVT == MVT::f16) {
157 if (OpVT == MVT::f32)
158 return FPROUND_F32_F16;
159 if (OpVT == MVT::f64)
160 return FPROUND_F64_F16;
161 if (OpVT == MVT::f80)
162 return FPROUND_F80_F16;
163 if (OpVT == MVT::f128)
164 return FPROUND_F128_F16;
165 if (OpVT == MVT::ppcf128)
166 return FPROUND_PPCF128_F16;
167 } else if (RetVT == MVT::bf16) {
168 if (OpVT == MVT::f32)
169 return FPROUND_F32_BF16;
170 if (OpVT == MVT::f64)
171 return FPROUND_F64_BF16;
172 } else if (RetVT == MVT::f32) {
173 if (OpVT == MVT::f64)
174 return FPROUND_F64_F32;
175 if (OpVT == MVT::f80)
176 return FPROUND_F80_F32;
177 if (OpVT == MVT::f128)
178 return FPROUND_F128_F32;
179 if (OpVT == MVT::ppcf128)
180 return FPROUND_PPCF128_F32;
181 } else if (RetVT == MVT::f64) {
182 if (OpVT == MVT::f80)
183 return FPROUND_F80_F64;
184 if (OpVT == MVT::f128)
185 return FPROUND_F128_F64;
186 if (OpVT == MVT::ppcf128)
187 return FPROUND_PPCF128_F64;
188 } else if (RetVT == MVT::f80) {
189 if (OpVT == MVT::f128)
190 return FPROUND_F128_F80;
191 }
192
193 return UNKNOWN_LIBCALL;
194}
195
196/// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
197/// UNKNOWN_LIBCALL if there is none.
199 if (OpVT == MVT::f16) {
200 if (RetVT == MVT::i32)
201 return FPTOSINT_F16_I32;
202 if (RetVT == MVT::i64)
203 return FPTOSINT_F16_I64;
204 if (RetVT == MVT::i128)
205 return FPTOSINT_F16_I128;
206 } else if (OpVT == MVT::f32) {
207 if (RetVT == MVT::i32)
208 return FPTOSINT_F32_I32;
209 if (RetVT == MVT::i64)
210 return FPTOSINT_F32_I64;
211 if (RetVT == MVT::i128)
212 return FPTOSINT_F32_I128;
213 } else if (OpVT == MVT::f64) {
214 if (RetVT == MVT::i32)
215 return FPTOSINT_F64_I32;
216 if (RetVT == MVT::i64)
217 return FPTOSINT_F64_I64;
218 if (RetVT == MVT::i128)
219 return FPTOSINT_F64_I128;
220 } else if (OpVT == MVT::f80) {
221 if (RetVT == MVT::i32)
222 return FPTOSINT_F80_I32;
223 if (RetVT == MVT::i64)
224 return FPTOSINT_F80_I64;
225 if (RetVT == MVT::i128)
226 return FPTOSINT_F80_I128;
227 } else if (OpVT == MVT::f128) {
228 if (RetVT == MVT::i32)
229 return FPTOSINT_F128_I32;
230 if (RetVT == MVT::i64)
231 return FPTOSINT_F128_I64;
232 if (RetVT == MVT::i128)
233 return FPTOSINT_F128_I128;
234 } else if (OpVT == MVT::ppcf128) {
235 if (RetVT == MVT::i32)
236 return FPTOSINT_PPCF128_I32;
237 if (RetVT == MVT::i64)
238 return FPTOSINT_PPCF128_I64;
239 if (RetVT == MVT::i128)
240 return FPTOSINT_PPCF128_I128;
241 }
242 return UNKNOWN_LIBCALL;
243}
244
245/// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
246/// UNKNOWN_LIBCALL if there is none.
248 if (OpVT == MVT::f16) {
249 if (RetVT == MVT::i32)
250 return FPTOUINT_F16_I32;
251 if (RetVT == MVT::i64)
252 return FPTOUINT_F16_I64;
253 if (RetVT == MVT::i128)
254 return FPTOUINT_F16_I128;
255 } else if (OpVT == MVT::f32) {
256 if (RetVT == MVT::i32)
257 return FPTOUINT_F32_I32;
258 if (RetVT == MVT::i64)
259 return FPTOUINT_F32_I64;
260 if (RetVT == MVT::i128)
261 return FPTOUINT_F32_I128;
262 } else if (OpVT == MVT::f64) {
263 if (RetVT == MVT::i32)
264 return FPTOUINT_F64_I32;
265 if (RetVT == MVT::i64)
266 return FPTOUINT_F64_I64;
267 if (RetVT == MVT::i128)
268 return FPTOUINT_F64_I128;
269 } else if (OpVT == MVT::f80) {
270 if (RetVT == MVT::i32)
271 return FPTOUINT_F80_I32;
272 if (RetVT == MVT::i64)
273 return FPTOUINT_F80_I64;
274 if (RetVT == MVT::i128)
275 return FPTOUINT_F80_I128;
276 } else if (OpVT == MVT::f128) {
277 if (RetVT == MVT::i32)
278 return FPTOUINT_F128_I32;
279 if (RetVT == MVT::i64)
280 return FPTOUINT_F128_I64;
281 if (RetVT == MVT::i128)
282 return FPTOUINT_F128_I128;
283 } else if (OpVT == MVT::ppcf128) {
284 if (RetVT == MVT::i32)
285 return FPTOUINT_PPCF128_I32;
286 if (RetVT == MVT::i64)
287 return FPTOUINT_PPCF128_I64;
288 if (RetVT == MVT::i128)
289 return FPTOUINT_PPCF128_I128;
290 }
291 return UNKNOWN_LIBCALL;
292}
293
294/// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
295/// UNKNOWN_LIBCALL if there is none.
297 if (OpVT == MVT::i32) {
298 if (RetVT == MVT::f16)
299 return SINTTOFP_I32_F16;
300 if (RetVT == MVT::f32)
301 return SINTTOFP_I32_F32;
302 if (RetVT == MVT::f64)
303 return SINTTOFP_I32_F64;
304 if (RetVT == MVT::f80)
305 return SINTTOFP_I32_F80;
306 if (RetVT == MVT::f128)
307 return SINTTOFP_I32_F128;
308 if (RetVT == MVT::ppcf128)
309 return SINTTOFP_I32_PPCF128;
310 } else if (OpVT == MVT::i64) {
311 if (RetVT == MVT::f16)
312 return SINTTOFP_I64_F16;
313 if (RetVT == MVT::f32)
314 return SINTTOFP_I64_F32;
315 if (RetVT == MVT::f64)
316 return SINTTOFP_I64_F64;
317 if (RetVT == MVT::f80)
318 return SINTTOFP_I64_F80;
319 if (RetVT == MVT::f128)
320 return SINTTOFP_I64_F128;
321 if (RetVT == MVT::ppcf128)
322 return SINTTOFP_I64_PPCF128;
323 } else if (OpVT == MVT::i128) {
324 if (RetVT == MVT::f16)
325 return SINTTOFP_I128_F16;
326 if (RetVT == MVT::f32)
327 return SINTTOFP_I128_F32;
328 if (RetVT == MVT::f64)
329 return SINTTOFP_I128_F64;
330 if (RetVT == MVT::f80)
331 return SINTTOFP_I128_F80;
332 if (RetVT == MVT::f128)
333 return SINTTOFP_I128_F128;
334 if (RetVT == MVT::ppcf128)
335 return SINTTOFP_I128_PPCF128;
336 }
337 return UNKNOWN_LIBCALL;
338}
339
340/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
341/// UNKNOWN_LIBCALL if there is none.
343 if (OpVT == MVT::i32) {
344 if (RetVT == MVT::f16)
345 return UINTTOFP_I32_F16;
346 if (RetVT == MVT::f32)
347 return UINTTOFP_I32_F32;
348 if (RetVT == MVT::f64)
349 return UINTTOFP_I32_F64;
350 if (RetVT == MVT::f80)
351 return UINTTOFP_I32_F80;
352 if (RetVT == MVT::f128)
353 return UINTTOFP_I32_F128;
354 if (RetVT == MVT::ppcf128)
355 return UINTTOFP_I32_PPCF128;
356 } else if (OpVT == MVT::i64) {
357 if (RetVT == MVT::f16)
358 return UINTTOFP_I64_F16;
359 if (RetVT == MVT::f32)
360 return UINTTOFP_I64_F32;
361 if (RetVT == MVT::f64)
362 return UINTTOFP_I64_F64;
363 if (RetVT == MVT::f80)
364 return UINTTOFP_I64_F80;
365 if (RetVT == MVT::f128)
366 return UINTTOFP_I64_F128;
367 if (RetVT == MVT::ppcf128)
368 return UINTTOFP_I64_PPCF128;
369 } else if (OpVT == MVT::i128) {
370 if (RetVT == MVT::f16)
371 return UINTTOFP_I128_F16;
372 if (RetVT == MVT::f32)
373 return UINTTOFP_I128_F32;
374 if (RetVT == MVT::f64)
375 return UINTTOFP_I128_F64;
376 if (RetVT == MVT::f80)
377 return UINTTOFP_I128_F80;
378 if (RetVT == MVT::f128)
379 return UINTTOFP_I128_F128;
380 if (RetVT == MVT::ppcf128)
381 return UINTTOFP_I128_PPCF128;
382 }
383 return UNKNOWN_LIBCALL;
384}
385
387 return getFPLibCall(RetVT, POWI_F32, POWI_F64, POWI_F80, POWI_F128,
388 POWI_PPCF128);
389}
390
392 return getFPLibCall(RetVT, LDEXP_F32, LDEXP_F64, LDEXP_F80, LDEXP_F128,
393 LDEXP_PPCF128);
394}
395
397 return getFPLibCall(RetVT, FREXP_F32, FREXP_F64, FREXP_F80, FREXP_F128,
398 FREXP_PPCF128);
399}
400
402 AtomicOrdering Order,
403 uint64_t MemSize) {
404 unsigned ModeN, ModelN;
405 switch (MemSize) {
406 case 1:
407 ModeN = 0;
408 break;
409 case 2:
410 ModeN = 1;
411 break;
412 case 4:
413 ModeN = 2;
414 break;
415 case 8:
416 ModeN = 3;
417 break;
418 case 16:
419 ModeN = 4;
420 break;
421 default:
422 return RTLIB::UNKNOWN_LIBCALL;
423 }
424
425 switch (Order) {
426 case AtomicOrdering::Monotonic:
427 ModelN = 0;
428 break;
429 case AtomicOrdering::Acquire:
430 ModelN = 1;
431 break;
432 case AtomicOrdering::Release:
433 ModelN = 2;
434 break;
435 case AtomicOrdering::AcquireRelease:
436 case AtomicOrdering::SequentiallyConsistent:
437 ModelN = 3;
438 break;
439 default:
440 return UNKNOWN_LIBCALL;
441 }
442
443 return LC[ModeN][ModelN];
444}
445
447 MVT VT) {
448 if (!VT.isScalarInteger())
449 return UNKNOWN_LIBCALL;
450 uint64_t MemSize = VT.getScalarSizeInBits() / 8;
451
452#define LCALLS(A, B) \
453 { A##B##_RELAX, A##B##_ACQ, A##B##_REL, A##B##_ACQ_REL }
454#define LCALL5(A) \
455 LCALLS(A, 1), LCALLS(A, 2), LCALLS(A, 4), LCALLS(A, 8), LCALLS(A, 16)
456 switch (Opc) {
458 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_CAS)};
459 return getOutlineAtomicHelper(LC, Order, MemSize);
460 }
461 case ISD::ATOMIC_SWAP: {
462 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_SWP)};
463 return getOutlineAtomicHelper(LC, Order, MemSize);
464 }
466 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDADD)};
467 return getOutlineAtomicHelper(LC, Order, MemSize);
468 }
469 case ISD::ATOMIC_LOAD_OR: {
470 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDSET)};
471 return getOutlineAtomicHelper(LC, Order, MemSize);
472 }
474 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDCLR)};
475 return getOutlineAtomicHelper(LC, Order, MemSize);
476 }
478 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDEOR)};
479 return getOutlineAtomicHelper(LC, Order, MemSize);
480 }
481 default:
482 return UNKNOWN_LIBCALL;
483 }
484#undef LCALLS
485#undef LCALL5
486}
487
489#define OP_TO_LIBCALL(Name, Enum) \
490 case Name: \
491 switch (VT.SimpleTy) { \
492 default: \
493 return UNKNOWN_LIBCALL; \
494 case MVT::i8: \
495 return Enum##_1; \
496 case MVT::i16: \
497 return Enum##_2; \
498 case MVT::i32: \
499 return Enum##_4; \
500 case MVT::i64: \
501 return Enum##_8; \
502 case MVT::i128: \
503 return Enum##_16; \
504 }
505
506 switch (Opc) {
507 OP_TO_LIBCALL(ISD::ATOMIC_SWAP, SYNC_LOCK_TEST_AND_SET)
508 OP_TO_LIBCALL(ISD::ATOMIC_CMP_SWAP, SYNC_VAL_COMPARE_AND_SWAP)
509 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_ADD, SYNC_FETCH_AND_ADD)
510 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_SUB, SYNC_FETCH_AND_SUB)
511 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_AND, SYNC_FETCH_AND_AND)
512 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_OR, SYNC_FETCH_AND_OR)
513 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_XOR, SYNC_FETCH_AND_XOR)
514 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_NAND, SYNC_FETCH_AND_NAND)
515 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MAX, SYNC_FETCH_AND_MAX)
516 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMAX, SYNC_FETCH_AND_UMAX)
517 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MIN, SYNC_FETCH_AND_MIN)
518 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMIN, SYNC_FETCH_AND_UMIN)
519 }
520
521#undef OP_TO_LIBCALL
522
523 return UNKNOWN_LIBCALL;
524}
525
527 switch (ElementSize) {
528 case 1:
529 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_1;
530 case 2:
531 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_2;
532 case 4:
533 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_4;
534 case 8:
535 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_8;
536 case 16:
537 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_16;
538 default:
539 return UNKNOWN_LIBCALL;
540 }
541}
542
544 switch (ElementSize) {
545 case 1:
546 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_1;
547 case 2:
548 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_2;
549 case 4:
550 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_4;
551 case 8:
552 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_8;
553 case 16:
554 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_16;
555 default:
556 return UNKNOWN_LIBCALL;
557 }
558}
559
561 switch (ElementSize) {
562 case 1:
563 return MEMSET_ELEMENT_UNORDERED_ATOMIC_1;
564 case 2:
565 return MEMSET_ELEMENT_UNORDERED_ATOMIC_2;
566 case 4:
567 return MEMSET_ELEMENT_UNORDERED_ATOMIC_4;
568 case 8:
569 return MEMSET_ELEMENT_UNORDERED_ATOMIC_8;
570 case 16:
571 return MEMSET_ELEMENT_UNORDERED_ATOMIC_16;
572 default:
573 return UNKNOWN_LIBCALL;
574 }
575}
576
578 std::fill(CmpLibcallCCs, CmpLibcallCCs + RTLIB::UNKNOWN_LIBCALL,
580 CmpLibcallCCs[RTLIB::OEQ_F32] = ISD::SETEQ;
581 CmpLibcallCCs[RTLIB::OEQ_F64] = ISD::SETEQ;
582 CmpLibcallCCs[RTLIB::OEQ_F128] = ISD::SETEQ;
583 CmpLibcallCCs[RTLIB::OEQ_PPCF128] = ISD::SETEQ;
584 CmpLibcallCCs[RTLIB::UNE_F32] = ISD::SETNE;
585 CmpLibcallCCs[RTLIB::UNE_F64] = ISD::SETNE;
586 CmpLibcallCCs[RTLIB::UNE_F128] = ISD::SETNE;
587 CmpLibcallCCs[RTLIB::UNE_PPCF128] = ISD::SETNE;
588 CmpLibcallCCs[RTLIB::OGE_F32] = ISD::SETGE;
589 CmpLibcallCCs[RTLIB::OGE_F64] = ISD::SETGE;
590 CmpLibcallCCs[RTLIB::OGE_F128] = ISD::SETGE;
591 CmpLibcallCCs[RTLIB::OGE_PPCF128] = ISD::SETGE;
592 CmpLibcallCCs[RTLIB::OLT_F32] = ISD::SETLT;
593 CmpLibcallCCs[RTLIB::OLT_F64] = ISD::SETLT;
594 CmpLibcallCCs[RTLIB::OLT_F128] = ISD::SETLT;
595 CmpLibcallCCs[RTLIB::OLT_PPCF128] = ISD::SETLT;
596 CmpLibcallCCs[RTLIB::OLE_F32] = ISD::SETLE;
597 CmpLibcallCCs[RTLIB::OLE_F64] = ISD::SETLE;
598 CmpLibcallCCs[RTLIB::OLE_F128] = ISD::SETLE;
599 CmpLibcallCCs[RTLIB::OLE_PPCF128] = ISD::SETLE;
600 CmpLibcallCCs[RTLIB::OGT_F32] = ISD::SETGT;
601 CmpLibcallCCs[RTLIB::OGT_F64] = ISD::SETGT;
602 CmpLibcallCCs[RTLIB::OGT_F128] = ISD::SETGT;
603 CmpLibcallCCs[RTLIB::OGT_PPCF128] = ISD::SETGT;
604 CmpLibcallCCs[RTLIB::UO_F32] = ISD::SETNE;
605 CmpLibcallCCs[RTLIB::UO_F64] = ISD::SETNE;
606 CmpLibcallCCs[RTLIB::UO_F128] = ISD::SETNE;
607 CmpLibcallCCs[RTLIB::UO_PPCF128] = ISD::SETNE;
608}
609
610/// NOTE: The TargetMachine owns TLOF.
612 : TM(tm), Libcalls(TM.getTargetTriple()) {
613 initActions();
614
615 // Perform these initializations only once.
621 HasMultipleConditionRegisters = false;
622 HasExtractBitsInsn = false;
623 JumpIsExpensive = JumpIsExpensiveOverride;
625 EnableExtLdPromotion = false;
626 StackPointerRegisterToSaveRestore = 0;
627 BooleanContents = UndefinedBooleanContent;
628 BooleanFloatContents = UndefinedBooleanContent;
629 BooleanVectorContents = UndefinedBooleanContent;
630 SchedPreferenceInfo = Sched::ILP;
633 MaxBytesForAlignment = 0;
634 MaxAtomicSizeInBitsSupported = 0;
635
636 // Assume that even with libcalls, no target supports wider than 128 bit
637 // division.
638 MaxDivRemBitWidthSupported = 128;
639
640 MaxLargeFPConvertBitWidthSupported = llvm::IntegerType::MAX_INT_BITS;
641
642 MinCmpXchgSizeInBits = 0;
643 SupportsUnalignedAtomics = false;
644
645 RTLIB::initCmpLibcallCCs(CmpLibcallCCs);
646}
647
649 // All operations default to being supported.
650 memset(OpActions, 0, sizeof(OpActions));
651 memset(LoadExtActions, 0, sizeof(LoadExtActions));
652 memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
653 memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
654 memset(CondCodeActions, 0, sizeof(CondCodeActions));
655 std::fill(std::begin(RegClassForVT), std::end(RegClassForVT), nullptr);
656 std::fill(std::begin(TargetDAGCombineArray),
657 std::end(TargetDAGCombineArray), 0);
658
659 // Let extending atomic loads be unsupported by default.
660 for (MVT ValVT : MVT::all_valuetypes())
661 for (MVT MemVT : MVT::all_valuetypes())
663 Expand);
664
665 // We're somewhat special casing MVT::i2 and MVT::i4. Ideally we want to
666 // remove this and targets should individually set these types if not legal.
669 for (MVT VT : {MVT::i2, MVT::i4})
670 OpActions[(unsigned)VT.SimpleTy][NT] = Expand;
671 }
672 for (MVT AVT : MVT::all_valuetypes()) {
673 for (MVT VT : {MVT::i2, MVT::i4, MVT::v128i2, MVT::v64i4}) {
674 setTruncStoreAction(AVT, VT, Expand);
677 }
678 }
679 for (unsigned IM = (unsigned)ISD::PRE_INC;
680 IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
681 for (MVT VT : {MVT::i2, MVT::i4}) {
686 }
687 }
688
689 for (MVT VT : MVT::fp_valuetypes()) {
690 MVT IntVT = MVT::getIntegerVT(VT.getFixedSizeInBits());
691 if (IntVT.isValid()) {
694 }
695 }
696
697 // Set default actions for various operations.
698 for (MVT VT : MVT::all_valuetypes()) {
699 // Default all indexed load / store to expand.
700 for (unsigned IM = (unsigned)ISD::PRE_INC;
701 IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
706 }
707
708 // Most backends expect to see the node which just returns the value loaded.
710
711 // These operations default to expand.
730 VT, Expand);
731
732 // Overflow operations default to expand
735 VT, Expand);
736
737 // Carry-using overflow operations default to expand.
740 VT, Expand);
741
742 // ADDC/ADDE/SUBC/SUBE default to expand.
744 Expand);
745
746 // [US]CMP default to expand
748
749 // Halving adds
752 Expand);
753
754 // Absolute difference
756
757 // Saturated trunc
761
762 // These default to Expand so they will be expanded to CTLZ/CTTZ by default.
764 Expand);
765
767
768 // These library functions default to expand.
770 Expand);
771
772 // These operations default to expand for vector types.
773 if (VT.isVector())
779 VT, Expand);
780
781 // Constrained floating-point operations default to expand.
782#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
783 setOperationAction(ISD::STRICT_##DAGN, VT, Expand);
784#include "llvm/IR/ConstrainedOps.def"
785
786 // For most targets @llvm.get.dynamic.area.offset just returns 0.
788
789 // Vector reduction default to expand.
797 VT, Expand);
798
799 // Named vector shuffles default to expand.
801
802 // Only some target support this vector operation. Most need to expand it.
804
805 // VP operations default to expand.
806#define BEGIN_REGISTER_VP_SDNODE(SDOPC, ...) \
807 setOperationAction(ISD::SDOPC, VT, Expand);
808#include "llvm/IR/VPIntrinsics.def"
809
810 // FP environment operations default to expand.
814 }
815
816 // Most targets ignore the @llvm.prefetch intrinsic.
818
819 // Most targets also ignore the @llvm.readcyclecounter intrinsic.
821
822 // Most targets also ignore the @llvm.readsteadycounter intrinsic.
824
825 // ConstantFP nodes default to expand. Targets can either change this to
826 // Legal, in which case all fp constants are legal, or use isFPImmLegal()
827 // to optimize expansions for certain constants.
829 {MVT::bf16, MVT::f16, MVT::f32, MVT::f64, MVT::f80, MVT::f128},
830 Expand);
831
832 // These library functions default to expand.
838 {MVT::f32, MVT::f64, MVT::f128}, Expand);
839
840 // FIXME: Query RuntimeLibCalls to make the decision.
842 {MVT::f32, MVT::f64, MVT::f128}, LibCall);
843
846 MVT::f16, Promote);
847 // Default ISD::TRAP to expand (which turns it into abort).
848 setOperationAction(ISD::TRAP, MVT::Other, Expand);
849
850 // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand"
851 // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP.
853
855
858
859 for (MVT VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64}) {
862 }
864
865 // This one by default will call __clear_cache unless the target
866 // wants something different.
868}
869
871 EVT) const {
872 return MVT::getIntegerVT(DL.getPointerSizeInBits(0));
873}
874
876 const DataLayout &DL) const {
877 assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
878 if (LHSTy.isVector())
879 return LHSTy;
880 MVT ShiftVT = getScalarShiftAmountTy(DL, LHSTy);
881 // If any possible shift value won't fit in the prefered type, just use
882 // something safe. Assume it will be legalized when the shift is expanded.
883 if (ShiftVT.getSizeInBits() < Log2_32_Ceil(LHSTy.getSizeInBits()))
884 ShiftVT = MVT::i32;
885 assert(ShiftVT.getSizeInBits() >= Log2_32_Ceil(LHSTy.getSizeInBits()) &&
886 "ShiftVT is still too small!");
887 return ShiftVT;
888}
889
890bool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
891 assert(isTypeLegal(VT));
892 switch (Op) {
893 default:
894 return false;
895 case ISD::SDIV:
896 case ISD::UDIV:
897 case ISD::SREM:
898 case ISD::UREM:
899 return true;
900 }
901}
902
904 unsigned DestAS) const {
905 return TM.isNoopAddrSpaceCast(SrcAS, DestAS);
906}
907
909 Type *RetTy, ElementCount EC, bool ZeroIsPoison,
910 const ConstantRange *VScaleRange) const {
911 // Find the smallest "sensible" element type to use for the expansion.
912 ConstantRange CR(APInt(64, EC.getKnownMinValue()));
913 if (EC.isScalable())
914 CR = CR.umul_sat(*VScaleRange);
915
916 if (ZeroIsPoison)
917 CR = CR.subtract(APInt(64, 1));
918
919 unsigned EltWidth = RetTy->getScalarSizeInBits();
920 EltWidth = std::min(EltWidth, (unsigned)CR.getActiveBits());
921 EltWidth = std::max(llvm::bit_ceil(EltWidth), (unsigned)8);
922
923 return EltWidth;
924}
925
927 // If the command-line option was specified, ignore this request.
928 if (!JumpIsExpensiveOverride.getNumOccurrences())
929 JumpIsExpensive = isExpensive;
930}
931
934 // If this is a simple type, use the ComputeRegisterProp mechanism.
935 if (VT.isSimple()) {
936 MVT SVT = VT.getSimpleVT();
937 assert((unsigned)SVT.SimpleTy < std::size(TransformToType));
938 MVT NVT = TransformToType[SVT.SimpleTy];
939 LegalizeTypeAction LA = ValueTypeActions.getTypeAction(SVT);
940
941 assert((LA == TypeLegal || LA == TypeSoftenFloat ||
942 LA == TypeSoftPromoteHalf ||
943 (NVT.isVector() ||
944 ValueTypeActions.getTypeAction(NVT) != TypePromoteInteger)) &&
945 "Promote may not follow Expand or Promote");
946
947 if (LA == TypeSplitVector)
948 return LegalizeKind(LA, EVT(SVT).getHalfNumVectorElementsVT(Context));
949 if (LA == TypeScalarizeVector)
950 return LegalizeKind(LA, SVT.getVectorElementType());
951 return LegalizeKind(LA, NVT);
952 }
953
954 // Handle Extended Scalar Types.
955 if (!VT.isVector()) {
956 assert(VT.isInteger() && "Float types must be simple");
957 unsigned BitSize = VT.getSizeInBits();
958 // First promote to a power-of-two size, then expand if necessary.
959 if (BitSize < 8 || !isPowerOf2_32(BitSize)) {
960 EVT NVT = VT.getRoundIntegerType(Context);
961 assert(NVT != VT && "Unable to round integer VT");
962 LegalizeKind NextStep = getTypeConversion(Context, NVT);
963 // Avoid multi-step promotion.
964 if (NextStep.first == TypePromoteInteger)
965 return NextStep;
966 // Return rounded integer type.
967 return LegalizeKind(TypePromoteInteger, NVT);
968 }
969
971 EVT::getIntegerVT(Context, VT.getSizeInBits() / 2));
972 }
973
974 // Handle vector types.
975 ElementCount NumElts = VT.getVectorElementCount();
976 EVT EltVT = VT.getVectorElementType();
977
978 // Vectors with only one element are always scalarized.
979 if (NumElts.isScalar())
980 return LegalizeKind(TypeScalarizeVector, EltVT);
981
982 // Try to widen vector elements until the element type is a power of two and
983 // promote it to a legal type later on, for example:
984 // <3 x i8> -> <4 x i8> -> <4 x i32>
985 if (EltVT.isInteger()) {
986 // Vectors with a number of elements that is not a power of two are always
987 // widened, for example <3 x i8> -> <4 x i8>.
988 if (!VT.isPow2VectorType()) {
989 NumElts = NumElts.coefficientNextPowerOf2();
990 EVT NVT = EVT::getVectorVT(Context, EltVT, NumElts);
991 return LegalizeKind(TypeWidenVector, NVT);
992 }
993
994 // Examine the element type.
995 LegalizeKind LK = getTypeConversion(Context, EltVT);
996
997 // If type is to be expanded, split the vector.
998 // <4 x i140> -> <2 x i140>
999 if (LK.first == TypeExpandInteger) {
1003 VT.getHalfNumVectorElementsVT(Context));
1004 }
1005
1006 // Promote the integer element types until a legal vector type is found
1007 // or until the element integer type is too big. If a legal type was not
1008 // found, fallback to the usual mechanism of widening/splitting the
1009 // vector.
1010 EVT OldEltVT = EltVT;
1011 while (true) {
1012 // Increase the bitwidth of the element to the next pow-of-two
1013 // (which is greater than 8 bits).
1014 EltVT = EVT::getIntegerVT(Context, 1 + EltVT.getSizeInBits())
1015 .getRoundIntegerType(Context);
1016
1017 // Stop trying when getting a non-simple element type.
1018 // Note that vector elements may be greater than legal vector element
1019 // types. Example: X86 XMM registers hold 64bit element on 32bit
1020 // systems.
1021 if (!EltVT.isSimple())
1022 break;
1023
1024 // Build a new vector type and check if it is legal.
1025 MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1026 // Found a legal promoted vector type.
1027 if (NVT != MVT() && ValueTypeActions.getTypeAction(NVT) == TypeLegal)
1029 EVT::getVectorVT(Context, EltVT, NumElts));
1030 }
1031
1032 // Reset the type to the unexpanded type if we did not find a legal vector
1033 // type with a promoted vector element type.
1034 EltVT = OldEltVT;
1035 }
1036
1037 // Try to widen the vector until a legal type is found.
1038 // If there is no wider legal type, split the vector.
1039 while (true) {
1040 // Round up to the next power of 2.
1041 NumElts = NumElts.coefficientNextPowerOf2();
1042
1043 // If there is no simple vector type with this many elements then there
1044 // cannot be a larger legal vector type. Note that this assumes that
1045 // there are no skipped intermediate vector types in the simple types.
1046 if (!EltVT.isSimple())
1047 break;
1048 MVT LargerVector = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1049 if (LargerVector == MVT())
1050 break;
1051
1052 // If this type is legal then widen the vector.
1053 if (ValueTypeActions.getTypeAction(LargerVector) == TypeLegal)
1054 return LegalizeKind(TypeWidenVector, LargerVector);
1055 }
1056
1057 // Widen odd vectors to next power of two.
1058 if (!VT.isPow2VectorType()) {
1059 EVT NVT = VT.getPow2VectorType(Context);
1060 return LegalizeKind(TypeWidenVector, NVT);
1061 }
1062
1065
1066 // Vectors with illegal element types are expanded.
1067 EVT NVT = EVT::getVectorVT(Context, EltVT,
1069 return LegalizeKind(TypeSplitVector, NVT);
1070}
1071
1072static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
1073 unsigned &NumIntermediates,
1074 MVT &RegisterVT,
1075 TargetLoweringBase *TLI) {
1076 // Figure out the right, legal destination reg to copy into.
1078 MVT EltTy = VT.getVectorElementType();
1079
1080 unsigned NumVectorRegs = 1;
1081
1082 // Scalable vectors cannot be scalarized, so splitting or widening is
1083 // required.
1084 if (VT.isScalableVector() && !isPowerOf2_32(EC.getKnownMinValue()))
1086 "Splitting or widening of non-power-of-2 MVTs is not implemented.");
1087
1088 // FIXME: We don't support non-power-of-2-sized vectors for now.
1089 // Ideally we could break down into LHS/RHS like LegalizeDAG does.
1090 if (!isPowerOf2_32(EC.getKnownMinValue())) {
1091 // Split EC to unit size (scalable property is preserved).
1092 NumVectorRegs = EC.getKnownMinValue();
1093 EC = ElementCount::getFixed(1);
1094 }
1095
1096 // Divide the input until we get to a supported size. This will
1097 // always end up with an EC that represent a scalar or a scalable
1098 // scalar.
1099 while (EC.getKnownMinValue() > 1 &&
1100 !TLI->isTypeLegal(MVT::getVectorVT(EltTy, EC))) {
1101 EC = EC.divideCoefficientBy(2);
1102 NumVectorRegs <<= 1;
1103 }
1104
1105 NumIntermediates = NumVectorRegs;
1106
1107 MVT NewVT = MVT::getVectorVT(EltTy, EC);
1108 if (!TLI->isTypeLegal(NewVT))
1109 NewVT = EltTy;
1110 IntermediateVT = NewVT;
1111
1112 unsigned LaneSizeInBits = NewVT.getScalarSizeInBits();
1113
1114 // Convert sizes such as i33 to i64.
1115 LaneSizeInBits = llvm::bit_ceil(LaneSizeInBits);
1116
1117 MVT DestVT = TLI->getRegisterType(NewVT);
1118 RegisterVT = DestVT;
1119 if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16.
1120 return NumVectorRegs * (LaneSizeInBits / DestVT.getScalarSizeInBits());
1121
1122 // Otherwise, promotion or legal types use the same number of registers as
1123 // the vector decimated to the appropriate level.
1124 return NumVectorRegs;
1125}
1126
1127/// isLegalRC - Return true if the value types that can be represented by the
1128/// specified register class are all legal.
1130 const TargetRegisterClass &RC) const {
1131 for (const auto *I = TRI.legalclasstypes_begin(RC); *I != MVT::Other; ++I)
1132 if (isTypeLegal(*I))
1133 return true;
1134 return false;
1135}
1136
1137/// Replace/modify any TargetFrameIndex operands with a targte-dependent
1138/// sequence of memory operands that is recognized by PrologEpilogInserter.
1141 MachineBasicBlock *MBB) const {
1142 MachineInstr *MI = &InitialMI;
1143 MachineFunction &MF = *MI->getMF();
1144 MachineFrameInfo &MFI = MF.getFrameInfo();
1145
1146 // We're handling multiple types of operands here:
1147 // PATCHPOINT MetaArgs - live-in, read only, direct
1148 // STATEPOINT Deopt Spill - live-through, read only, indirect
1149 // STATEPOINT Deopt Alloca - live-through, read only, direct
1150 // (We're currently conservative and mark the deopt slots read/write in
1151 // practice.)
1152 // STATEPOINT GC Spill - live-through, read/write, indirect
1153 // STATEPOINT GC Alloca - live-through, read/write, direct
1154 // The live-in vs live-through is handled already (the live through ones are
1155 // all stack slots), but we need to handle the different type of stackmap
1156 // operands and memory effects here.
1157
1158 if (llvm::none_of(MI->operands(),
1159 [](MachineOperand &Operand) { return Operand.isFI(); }))
1160 return MBB;
1161
1162 MachineInstrBuilder MIB = BuildMI(MF, MI->getDebugLoc(), MI->getDesc());
1163
1164 // Inherit previous memory operands.
1165 MIB.cloneMemRefs(*MI);
1166
1167 for (unsigned i = 0; i < MI->getNumOperands(); ++i) {
1168 MachineOperand &MO = MI->getOperand(i);
1169 if (!MO.isFI()) {
1170 // Index of Def operand this Use it tied to.
1171 // Since Defs are coming before Uses, if Use is tied, then
1172 // index of Def must be smaller that index of that Use.
1173 // Also, Defs preserve their position in new MI.
1174 unsigned TiedTo = i;
1175 if (MO.isReg() && MO.isTied())
1176 TiedTo = MI->findTiedOperandIdx(i);
1177 MIB.add(MO);
1178 if (TiedTo < i)
1179 MIB->tieOperands(TiedTo, MIB->getNumOperands() - 1);
1180 continue;
1181 }
1182
1183 // foldMemoryOperand builds a new MI after replacing a single FI operand
1184 // with the canonical set of five x86 addressing-mode operands.
1185 int FI = MO.getIndex();
1186
1187 // Add frame index operands recognized by stackmaps.cpp
1189 // indirect-mem-ref tag, size, #FI, offset.
1190 // Used for spills inserted by StatepointLowering. This codepath is not
1191 // used for patchpoints/stackmaps at all, for these spilling is done via
1192 // foldMemoryOperand callback only.
1193 assert(MI->getOpcode() == TargetOpcode::STATEPOINT && "sanity");
1194 MIB.addImm(StackMaps::IndirectMemRefOp);
1195 MIB.addImm(MFI.getObjectSize(FI));
1196 MIB.add(MO);
1197 MIB.addImm(0);
1198 } else {
1199 // direct-mem-ref tag, #FI, offset.
1200 // Used by patchpoint, and direct alloca arguments to statepoints
1201 MIB.addImm(StackMaps::DirectMemRefOp);
1202 MIB.add(MO);
1203 MIB.addImm(0);
1204 }
1205
1206 assert(MIB->mayLoad() && "Folded a stackmap use to a non-load!");
1207
1208 // Add a new memory operand for this FI.
1209 assert(MFI.getObjectOffset(FI) != -1);
1210
1211 // Note: STATEPOINT MMOs are added during SelectionDAG. STACKMAP, and
1212 // PATCHPOINT should be updated to do the same. (TODO)
1213 if (MI->getOpcode() != TargetOpcode::STATEPOINT) {
1214 auto Flags = MachineMemOperand::MOLoad;
1216 MachinePointerInfo::getFixedStack(MF, FI), Flags,
1218 MIB->addMemOperand(MF, MMO);
1219 }
1220 }
1222 MI->eraseFromParent();
1223 return MBB;
1224}
1225
1226/// findRepresentativeClass - Return the largest legal super-reg register class
1227/// of the register class for the specified type and its associated "cost".
1228// This function is in TargetLowering because it uses RegClassForVT which would
1229// need to be moved to TargetRegisterInfo and would necessitate moving
1230// isTypeLegal over as well - a massive change that would just require
1231// TargetLowering having a TargetRegisterInfo class member that it would use.
1232std::pair<const TargetRegisterClass *, uint8_t>
1234 MVT VT) const {
1235 const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
1236 if (!RC)
1237 return std::make_pair(RC, 0);
1238
1239 // Compute the set of all super-register classes.
1240 BitVector SuperRegRC(TRI->getNumRegClasses());
1241 for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI)
1242 SuperRegRC.setBitsInMask(RCI.getMask());
1243
1244 // Find the first legal register class with the largest spill size.
1245 const TargetRegisterClass *BestRC = RC;
1246 for (unsigned i : SuperRegRC.set_bits()) {
1247 const TargetRegisterClass *SuperRC = TRI->getRegClass(i);
1248 // We want the largest possible spill size.
1249 if (TRI->getSpillSize(*SuperRC) <= TRI->getSpillSize(*BestRC))
1250 continue;
1251 if (!isLegalRC(*TRI, *SuperRC))
1252 continue;
1253 BestRC = SuperRC;
1254 }
1255 return std::make_pair(BestRC, 1);
1256}
1257
1258/// computeRegisterProperties - Once all of the register classes are added,
1259/// this allows us to compute derived properties we expose.
1261 const TargetRegisterInfo *TRI) {
1262 // Everything defaults to needing one register.
1263 for (unsigned i = 0; i != MVT::VALUETYPE_SIZE; ++i) {
1264 NumRegistersForVT[i] = 1;
1265 RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i;
1266 }
1267 // ...except isVoid, which doesn't need any registers.
1268 NumRegistersForVT[MVT::isVoid] = 0;
1269
1270 // Find the largest integer register class.
1271 unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE;
1272 for (; RegClassForVT[LargestIntReg] == nullptr; --LargestIntReg)
1273 assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
1274
1275 // Every integer value type larger than this largest register takes twice as
1276 // many registers to represent as the previous ValueType.
1277 for (unsigned ExpandedReg = LargestIntReg + 1;
1278 ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) {
1279 NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1];
1280 RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg;
1281 TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1);
1282 ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg,
1284 }
1285
1286 // Inspect all of the ValueType's smaller than the largest integer
1287 // register to see which ones need promotion.
1288 unsigned LegalIntReg = LargestIntReg;
1289 for (unsigned IntReg = LargestIntReg - 1;
1290 IntReg >= (unsigned)MVT::i1; --IntReg) {
1291 MVT IVT = (MVT::SimpleValueType)IntReg;
1292 if (isTypeLegal(IVT)) {
1293 LegalIntReg = IntReg;
1294 } else {
1295 RegisterTypeForVT[IntReg] = TransformToType[IntReg] =
1296 (MVT::SimpleValueType)LegalIntReg;
1297 ValueTypeActions.setTypeAction(IVT, TypePromoteInteger);
1298 }
1299 }
1300
1301 // ppcf128 type is really two f64's.
1302 if (!isTypeLegal(MVT::ppcf128)) {
1303 if (isTypeLegal(MVT::f64)) {
1304 NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64];
1305 RegisterTypeForVT[MVT::ppcf128] = MVT::f64;
1306 TransformToType[MVT::ppcf128] = MVT::f64;
1307 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat);
1308 } else {
1309 NumRegistersForVT[MVT::ppcf128] = NumRegistersForVT[MVT::i128];
1310 RegisterTypeForVT[MVT::ppcf128] = RegisterTypeForVT[MVT::i128];
1311 TransformToType[MVT::ppcf128] = MVT::i128;
1312 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeSoftenFloat);
1313 }
1314 }
1315
1316 // Decide how to handle f128. If the target does not have native f128 support,
1317 // expand it to i128 and we will be generating soft float library calls.
1318 if (!isTypeLegal(MVT::f128)) {
1319 NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128];
1320 RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128];
1321 TransformToType[MVT::f128] = MVT::i128;
1322 ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat);
1323 }
1324
1325 // Decide how to handle f80. If the target does not have native f80 support,
1326 // expand it to i96 and we will be generating soft float library calls.
1327 if (!isTypeLegal(MVT::f80)) {
1328 NumRegistersForVT[MVT::f80] = 3*NumRegistersForVT[MVT::i32];
1329 RegisterTypeForVT[MVT::f80] = RegisterTypeForVT[MVT::i32];
1330 TransformToType[MVT::f80] = MVT::i32;
1331 ValueTypeActions.setTypeAction(MVT::f80, TypeSoftenFloat);
1332 }
1333
1334 // Decide how to handle f64. If the target does not have native f64 support,
1335 // expand it to i64 and we will be generating soft float library calls.
1336 if (!isTypeLegal(MVT::f64)) {
1337 NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64];
1338 RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64];
1339 TransformToType[MVT::f64] = MVT::i64;
1340 ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat);
1341 }
1342
1343 // Decide how to handle f32. If the target does not have native f32 support,
1344 // expand it to i32 and we will be generating soft float library calls.
1345 if (!isTypeLegal(MVT::f32)) {
1346 NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32];
1347 RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32];
1348 TransformToType[MVT::f32] = MVT::i32;
1349 ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat);
1350 }
1351
1352 // Decide how to handle f16. If the target does not have native f16 support,
1353 // promote it to f32, because there are no f16 library calls (except for
1354 // conversions).
1355 if (!isTypeLegal(MVT::f16)) {
1356 // Allow targets to control how we legalize half.
1357 bool SoftPromoteHalfType = softPromoteHalfType();
1358 bool UseFPRegsForHalfType = !SoftPromoteHalfType || useFPRegsForHalfType();
1359
1360 if (!UseFPRegsForHalfType) {
1361 NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::i16];
1362 RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::i16];
1363 } else {
1364 NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::f32];
1365 RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::f32];
1366 }
1367 TransformToType[MVT::f16] = MVT::f32;
1368 if (SoftPromoteHalfType) {
1369 ValueTypeActions.setTypeAction(MVT::f16, TypeSoftPromoteHalf);
1370 } else {
1371 ValueTypeActions.setTypeAction(MVT::f16, TypePromoteFloat);
1372 }
1373 }
1374
1375 // Decide how to handle bf16. If the target does not have native bf16 support,
1376 // promote it to f32, because there are no bf16 library calls (except for
1377 // converting from f32 to bf16).
1378 if (!isTypeLegal(MVT::bf16)) {
1379 NumRegistersForVT[MVT::bf16] = NumRegistersForVT[MVT::f32];
1380 RegisterTypeForVT[MVT::bf16] = RegisterTypeForVT[MVT::f32];
1381 TransformToType[MVT::bf16] = MVT::f32;
1382 ValueTypeActions.setTypeAction(MVT::bf16, TypeSoftPromoteHalf);
1383 }
1384
1385 // Loop over all of the vector value types to see which need transformations.
1386 for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE;
1387 i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
1388 MVT VT = (MVT::SimpleValueType) i;
1389 if (isTypeLegal(VT))
1390 continue;
1391
1392 MVT EltVT = VT.getVectorElementType();
1394 bool IsLegalWiderType = false;
1395 bool IsScalable = VT.isScalableVector();
1396 LegalizeTypeAction PreferredAction = getPreferredVectorAction(VT);
1397 switch (PreferredAction) {
1398 case TypePromoteInteger: {
1399 MVT::SimpleValueType EndVT = IsScalable ?
1400 MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE :
1401 MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE;
1402 // Try to promote the elements of integer vectors. If no legal
1403 // promotion was found, fall through to the widen-vector method.
1404 for (unsigned nVT = i + 1;
1405 (MVT::SimpleValueType)nVT <= EndVT; ++nVT) {
1406 MVT SVT = (MVT::SimpleValueType) nVT;
1407 // Promote vectors of integers to vectors with the same number
1408 // of elements, with a wider element type.
1409 if (SVT.getScalarSizeInBits() > EltVT.getFixedSizeInBits() &&
1410 SVT.getVectorElementCount() == EC && isTypeLegal(SVT)) {
1411 TransformToType[i] = SVT;
1412 RegisterTypeForVT[i] = SVT;
1413 NumRegistersForVT[i] = 1;
1414 ValueTypeActions.setTypeAction(VT, TypePromoteInteger);
1415 IsLegalWiderType = true;
1416 break;
1417 }
1418 }
1419 if (IsLegalWiderType)
1420 break;
1421 [[fallthrough]];
1422 }
1423
1424 case TypeWidenVector:
1425 if (isPowerOf2_32(EC.getKnownMinValue())) {
1426 // Try to widen the vector.
1427 for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
1428 MVT SVT = (MVT::SimpleValueType) nVT;
1429 if (SVT.getVectorElementType() == EltVT &&
1430 SVT.isScalableVector() == IsScalable &&
1432 EC.getKnownMinValue() &&
1433 isTypeLegal(SVT)) {
1434 TransformToType[i] = SVT;
1435 RegisterTypeForVT[i] = SVT;
1436 NumRegistersForVT[i] = 1;
1437 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1438 IsLegalWiderType = true;
1439 break;
1440 }
1441 }
1442 if (IsLegalWiderType)
1443 break;
1444 } else {
1445 // Only widen to the next power of 2 to keep consistency with EVT.
1446 MVT NVT = VT.getPow2VectorType();
1447 if (isTypeLegal(NVT)) {
1448 TransformToType[i] = NVT;
1449 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1450 RegisterTypeForVT[i] = NVT;
1451 NumRegistersForVT[i] = 1;
1452 break;
1453 }
1454 }
1455 [[fallthrough]];
1456
1457 case TypeSplitVector:
1458 case TypeScalarizeVector: {
1459 MVT IntermediateVT;
1460 MVT RegisterVT;
1461 unsigned NumIntermediates;
1462 unsigned NumRegisters = getVectorTypeBreakdownMVT(VT, IntermediateVT,
1463 NumIntermediates, RegisterVT, this);
1464 NumRegistersForVT[i] = NumRegisters;
1465 assert(NumRegistersForVT[i] == NumRegisters &&
1466 "NumRegistersForVT size cannot represent NumRegisters!");
1467 RegisterTypeForVT[i] = RegisterVT;
1468
1469 MVT NVT = VT.getPow2VectorType();
1470 if (NVT == VT) {
1471 // Type is already a power of 2. The default action is to split.
1472 TransformToType[i] = MVT::Other;
1473 if (PreferredAction == TypeScalarizeVector)
1474 ValueTypeActions.setTypeAction(VT, TypeScalarizeVector);
1475 else if (PreferredAction == TypeSplitVector)
1476 ValueTypeActions.setTypeAction(VT, TypeSplitVector);
1477 else if (EC.getKnownMinValue() > 1)
1478 ValueTypeActions.setTypeAction(VT, TypeSplitVector);
1479 else
1480 ValueTypeActions.setTypeAction(VT, EC.isScalable()
1483 } else {
1484 TransformToType[i] = NVT;
1485 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1486 }
1487 break;
1488 }
1489 default:
1490 llvm_unreachable("Unknown vector legalization action!");
1491 }
1492 }
1493
1494 // Determine the 'representative' register class for each value type.
1495 // An representative register class is the largest (meaning one which is
1496 // not a sub-register class / subreg register class) legal register class for
1497 // a group of value types. For example, on i386, i8, i16, and i32
1498 // representative would be GR32; while on x86_64 it's GR64.
1499 for (unsigned i = 0; i != MVT::VALUETYPE_SIZE; ++i) {
1500 const TargetRegisterClass* RRC;
1501 uint8_t Cost;
1503 RepRegClassForVT[i] = RRC;
1504 RepRegClassCostForVT[i] = Cost;
1505 }
1506}
1507
1509 EVT VT) const {
1510 assert(!VT.isVector() && "No default SetCC type for vectors!");
1511 return getPointerTy(DL).SimpleTy;
1512}
1513
1515 return MVT::i32; // return the default value
1516}
1517
1518/// getVectorTypeBreakdown - Vector types are broken down into some number of
1519/// legal first class types. For example, MVT::v8f32 maps to 2 MVT::v4f32
1520/// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
1521/// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
1522///
1523/// This method returns the number of registers needed, and the VT for each
1524/// register. It also returns the VT and quantity of the intermediate values
1525/// before they are promoted/expanded.
1527 EVT VT, EVT &IntermediateVT,
1528 unsigned &NumIntermediates,
1529 MVT &RegisterVT) const {
1530 ElementCount EltCnt = VT.getVectorElementCount();
1531
1532 // If there is a wider vector type with the same element type as this one,
1533 // or a promoted vector type that has the same number of elements which
1534 // are wider, then we should convert to that legal vector type.
1535 // This handles things like <2 x float> -> <4 x float> and
1536 // <4 x i1> -> <4 x i32>.
1537 LegalizeTypeAction TA = getTypeAction(Context, VT);
1538 if (!EltCnt.isScalar() &&
1539 (TA == TypeWidenVector || TA == TypePromoteInteger)) {
1540 EVT RegisterEVT = getTypeToTransformTo(Context, VT);
1541 if (isTypeLegal(RegisterEVT)) {
1542 IntermediateVT = RegisterEVT;
1543 RegisterVT = RegisterEVT.getSimpleVT();
1544 NumIntermediates = 1;
1545 return 1;
1546 }
1547 }
1548
1549 // Figure out the right, legal destination reg to copy into.
1550 EVT EltTy = VT.getVectorElementType();
1551
1552 unsigned NumVectorRegs = 1;
1553
1554 // Scalable vectors cannot be scalarized, so handle the legalisation of the
1555 // types like done elsewhere in SelectionDAG.
1556 if (EltCnt.isScalable()) {
1557 LegalizeKind LK;
1558 EVT PartVT = VT;
1559 do {
1560 // Iterate until we've found a legal (part) type to hold VT.
1561 LK = getTypeConversion(Context, PartVT);
1562 PartVT = LK.second;
1563 } while (LK.first != TypeLegal);
1564
1565 if (!PartVT.isVector()) {
1567 "Don't know how to legalize this scalable vector type");
1568 }
1569
1570 NumIntermediates =
1573 IntermediateVT = PartVT;
1574 RegisterVT = getRegisterType(Context, IntermediateVT);
1575 return NumIntermediates;
1576 }
1577
1578 // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally
1579 // we could break down into LHS/RHS like LegalizeDAG does.
1580 if (!isPowerOf2_32(EltCnt.getKnownMinValue())) {
1581 NumVectorRegs = EltCnt.getKnownMinValue();
1582 EltCnt = ElementCount::getFixed(1);
1583 }
1584
1585 // Divide the input until we get to a supported size. This will always
1586 // end with a scalar if the target doesn't support vectors.
1587 while (EltCnt.getKnownMinValue() > 1 &&
1588 !isTypeLegal(EVT::getVectorVT(Context, EltTy, EltCnt))) {
1589 EltCnt = EltCnt.divideCoefficientBy(2);
1590 NumVectorRegs <<= 1;
1591 }
1592
1593 NumIntermediates = NumVectorRegs;
1594
1595 EVT NewVT = EVT::getVectorVT(Context, EltTy, EltCnt);
1596 if (!isTypeLegal(NewVT))
1597 NewVT = EltTy;
1598 IntermediateVT = NewVT;
1599
1600 MVT DestVT = getRegisterType(Context, NewVT);
1601 RegisterVT = DestVT;
1602
1603 if (EVT(DestVT).bitsLT(NewVT)) { // Value is expanded, e.g. i64 -> i16.
1604 TypeSize NewVTSize = NewVT.getSizeInBits();
1605 // Convert sizes such as i33 to i64.
1606 if (!llvm::has_single_bit<uint32_t>(NewVTSize.getKnownMinValue()))
1607 NewVTSize = NewVTSize.coefficientNextPowerOf2();
1608 return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
1609 }
1610
1611 // Otherwise, promotion or legal types use the same number of registers as
1612 // the vector decimated to the appropriate level.
1613 return NumVectorRegs;
1614}
1615
1617 uint64_t NumCases,
1619 ProfileSummaryInfo *PSI,
1620 BlockFrequencyInfo *BFI) const {
1621 // FIXME: This function check the maximum table size and density, but the
1622 // minimum size is not checked. It would be nice if the minimum size is
1623 // also combined within this function. Currently, the minimum size check is
1624 // performed in findJumpTable() in SelectionDAGBuiler and
1625 // getEstimatedNumberOfCaseClusters() in BasicTTIImpl.
1626 const bool OptForSize =
1627 SI->getParent()->getParent()->hasOptSize() ||
1628 llvm::shouldOptimizeForSize(SI->getParent(), PSI, BFI);
1629 const unsigned MinDensity = getMinimumJumpTableDensity(OptForSize);
1630 const unsigned MaxJumpTableSize = getMaximumJumpTableSize();
1631
1632 // Check whether the number of cases is small enough and
1633 // the range is dense enough for a jump table.
1634 return (OptForSize || Range <= MaxJumpTableSize) &&
1635 (NumCases * 100 >= Range * MinDensity);
1636}
1637
1639 EVT ConditionVT) const {
1640 return getRegisterType(Context, ConditionVT);
1641}
1642
1643/// Get the EVTs and ArgFlags collections that represent the legalized return
1644/// type of the given function. This does not require a DAG or a return value,
1645/// and is suitable for use before any DAGs for the function are constructed.
1646/// TODO: Move this out of TargetLowering.cpp.
1648 AttributeList attr,
1650 const TargetLowering &TLI, const DataLayout &DL) {
1651 SmallVector<EVT, 4> ValueVTs;
1652 ComputeValueVTs(TLI, DL, ReturnType, ValueVTs);
1653 unsigned NumValues = ValueVTs.size();
1654 if (NumValues == 0) return;
1655
1656 for (unsigned j = 0, f = NumValues; j != f; ++j) {
1657 EVT VT = ValueVTs[j];
1658 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
1659
1660 if (attr.hasRetAttr(Attribute::SExt))
1661 ExtendKind = ISD::SIGN_EXTEND;
1662 else if (attr.hasRetAttr(Attribute::ZExt))
1663 ExtendKind = ISD::ZERO_EXTEND;
1664
1665 if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger())
1666 VT = TLI.getTypeForExtReturn(ReturnType->getContext(), VT, ExtendKind);
1667
1668 unsigned NumParts =
1669 TLI.getNumRegistersForCallingConv(ReturnType->getContext(), CC, VT);
1670 MVT PartVT =
1671 TLI.getRegisterTypeForCallingConv(ReturnType->getContext(), CC, VT);
1672
1673 // 'inreg' on function refers to return value
1675 if (attr.hasRetAttr(Attribute::InReg))
1676 Flags.setInReg();
1677
1678 // Propagate extension type if any
1679 if (attr.hasRetAttr(Attribute::SExt))
1680 Flags.setSExt();
1681 else if (attr.hasRetAttr(Attribute::ZExt))
1682 Flags.setZExt();
1683
1684 for (unsigned i = 0; i < NumParts; ++i) {
1685 ISD::ArgFlagsTy OutFlags = Flags;
1686 if (NumParts > 1 && i == 0)
1687 OutFlags.setSplit();
1688 else if (i == NumParts - 1 && i != 0)
1689 OutFlags.setSplitEnd();
1690
1691 Outs.push_back(
1692 ISD::OutputArg(OutFlags, PartVT, VT, /*isfixed=*/true, 0, 0));
1693 }
1694 }
1695}
1696
1697/// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
1698/// function arguments in the caller parameter area. This is the actual
1699/// alignment, not its logarithm.
1701 const DataLayout &DL) const {
1702 return DL.getABITypeAlign(Ty).value();
1703}
1704
1706 LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace,
1707 Align Alignment, MachineMemOperand::Flags Flags, unsigned *Fast) const {
1708 // Check if the specified alignment is sufficient based on the data layout.
1709 // TODO: While using the data layout works in practice, a better solution
1710 // would be to implement this check directly (make this a virtual function).
1711 // For example, the ABI alignment may change based on software platform while
1712 // this function should only be affected by hardware implementation.
1713 Type *Ty = VT.getTypeForEVT(Context);
1714 if (VT.isZeroSized() || Alignment >= DL.getABITypeAlign(Ty)) {
1715 // Assume that an access that meets the ABI-specified alignment is fast.
1716 if (Fast != nullptr)
1717 *Fast = 1;
1718 return true;
1719 }
1720
1721 // This is a misaligned access.
1722 return allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment, Flags, Fast);
1723}
1724
1726 LLVMContext &Context, const DataLayout &DL, EVT VT,
1727 const MachineMemOperand &MMO, unsigned *Fast) const {
1728 return allowsMemoryAccessForAlignment(Context, DL, VT, MMO.getAddrSpace(),
1729 MMO.getAlign(), MMO.getFlags(), Fast);
1730}
1731
1733 const DataLayout &DL, EVT VT,
1734 unsigned AddrSpace, Align Alignment,
1736 unsigned *Fast) const {
1737 return allowsMemoryAccessForAlignment(Context, DL, VT, AddrSpace, Alignment,
1738 Flags, Fast);
1739}
1740
1742 const DataLayout &DL, EVT VT,
1743 const MachineMemOperand &MMO,
1744 unsigned *Fast) const {
1745 return allowsMemoryAccess(Context, DL, VT, MMO.getAddrSpace(), MMO.getAlign(),
1746 MMO.getFlags(), Fast);
1747}
1748
1750 const DataLayout &DL, LLT Ty,
1751 const MachineMemOperand &MMO,
1752 unsigned *Fast) const {
1753 EVT VT = getApproximateEVTForLLT(Ty, DL, Context);
1754 return allowsMemoryAccess(Context, DL, VT, MMO.getAddrSpace(), MMO.getAlign(),
1755 MMO.getFlags(), Fast);
1756}
1757
1758//===----------------------------------------------------------------------===//
1759// TargetTransformInfo Helpers
1760//===----------------------------------------------------------------------===//
1761
1763 enum InstructionOpcodes {
1764#define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM,
1765#define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM
1766#include "llvm/IR/Instruction.def"
1767 };
1768 switch (static_cast<InstructionOpcodes>(Opcode)) {
1769 case Ret: return 0;
1770 case Br: return 0;
1771 case Switch: return 0;
1772 case IndirectBr: return 0;
1773 case Invoke: return 0;
1774 case CallBr: return 0;
1775 case Resume: return 0;
1776 case Unreachable: return 0;
1777 case CleanupRet: return 0;
1778 case CatchRet: return 0;
1779 case CatchPad: return 0;
1780 case CatchSwitch: return 0;
1781 case CleanupPad: return 0;
1782 case FNeg: return ISD::FNEG;
1783 case Add: return ISD::ADD;
1784 case FAdd: return ISD::FADD;
1785 case Sub: return ISD::SUB;
1786 case FSub: return ISD::FSUB;
1787 case Mul: return ISD::MUL;
1788 case FMul: return ISD::FMUL;
1789 case UDiv: return ISD::UDIV;
1790 case SDiv: return ISD::SDIV;
1791 case FDiv: return ISD::FDIV;
1792 case URem: return ISD::UREM;
1793 case SRem: return ISD::SREM;
1794 case FRem: return ISD::FREM;
1795 case Shl: return ISD::SHL;
1796 case LShr: return ISD::SRL;
1797 case AShr: return ISD::SRA;
1798 case And: return ISD::AND;
1799 case Or: return ISD::OR;
1800 case Xor: return ISD::XOR;
1801 case Alloca: return 0;
1802 case Load: return ISD::LOAD;
1803 case Store: return ISD::STORE;
1804 case GetElementPtr: return 0;
1805 case Fence: return 0;
1806 case AtomicCmpXchg: return 0;
1807 case AtomicRMW: return 0;
1808 case Trunc: return ISD::TRUNCATE;
1809 case ZExt: return ISD::ZERO_EXTEND;
1810 case SExt: return ISD::SIGN_EXTEND;
1811 case FPToUI: return ISD::FP_TO_UINT;
1812 case FPToSI: return ISD::FP_TO_SINT;
1813 case UIToFP: return ISD::UINT_TO_FP;
1814 case SIToFP: return ISD::SINT_TO_FP;
1815 case FPTrunc: return ISD::FP_ROUND;
1816 case FPExt: return ISD::FP_EXTEND;
1817 case PtrToInt: return ISD::BITCAST;
1818 case IntToPtr: return ISD::BITCAST;
1819 case BitCast: return ISD::BITCAST;
1820 case AddrSpaceCast: return ISD::ADDRSPACECAST;
1821 case ICmp: return ISD::SETCC;
1822 case FCmp: return ISD::SETCC;
1823 case PHI: return 0;
1824 case Call: return 0;
1825 case Select: return ISD::SELECT;
1826 case UserOp1: return 0;
1827 case UserOp2: return 0;
1828 case VAArg: return 0;
1829 case ExtractElement: return ISD::EXTRACT_VECTOR_ELT;
1830 case InsertElement: return ISD::INSERT_VECTOR_ELT;
1831 case ShuffleVector: return ISD::VECTOR_SHUFFLE;
1832 case ExtractValue: return ISD::MERGE_VALUES;
1833 case InsertValue: return ISD::MERGE_VALUES;
1834 case LandingPad: return 0;
1835 case Freeze: return ISD::FREEZE;
1836 }
1837
1838 llvm_unreachable("Unknown instruction type encountered!");
1839}
1840
1841Value *
1843 bool UseTLS) const {
1844 // compiler-rt provides a variable with a magic name. Targets that do not
1845 // link with compiler-rt may also provide such a variable.
1846 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1847 const char *UnsafeStackPtrVar = "__safestack_unsafe_stack_ptr";
1848 auto UnsafeStackPtr =
1849 dyn_cast_or_null<GlobalVariable>(M->getNamedValue(UnsafeStackPtrVar));
1850
1851 Type *StackPtrTy = PointerType::getUnqual(M->getContext());
1852
1853 if (!UnsafeStackPtr) {
1854 auto TLSModel = UseTLS ?
1857 // The global variable is not defined yet, define it ourselves.
1858 // We use the initial-exec TLS model because we do not support the
1859 // variable living anywhere other than in the main executable.
1860 UnsafeStackPtr = new GlobalVariable(
1861 *M, StackPtrTy, false, GlobalValue::ExternalLinkage, nullptr,
1862 UnsafeStackPtrVar, nullptr, TLSModel);
1863 } else {
1864 // The variable exists, check its type and attributes.
1865 if (UnsafeStackPtr->getValueType() != StackPtrTy)
1866 report_fatal_error(Twine(UnsafeStackPtrVar) + " must have void* type");
1867 if (UseTLS != UnsafeStackPtr->isThreadLocal())
1868 report_fatal_error(Twine(UnsafeStackPtrVar) + " must " +
1869 (UseTLS ? "" : "not ") + "be thread-local");
1870 }
1871 return UnsafeStackPtr;
1872}
1873
1874Value *
1876 if (!TM.getTargetTriple().isAndroid())
1877 return getDefaultSafeStackPointerLocation(IRB, true);
1878
1879 // Android provides a libc function to retrieve the address of the current
1880 // thread's unsafe stack pointer.
1881 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1882 auto *PtrTy = PointerType::getUnqual(M->getContext());
1883 FunctionCallee Fn =
1884 M->getOrInsertFunction("__safestack_pointer_address", PtrTy);
1885 return IRB.CreateCall(Fn);
1886}
1887
1888//===----------------------------------------------------------------------===//
1889// Loop Strength Reduction hooks
1890//===----------------------------------------------------------------------===//
1891
1892/// isLegalAddressingMode - Return true if the addressing mode represented
1893/// by AM is legal for this target, for a load/store of the specified type.
1895 const AddrMode &AM, Type *Ty,
1896 unsigned AS, Instruction *I) const {
1897 // The default implementation of this implements a conservative RISCy, r+r and
1898 // r+i addr mode.
1899
1900 // Scalable offsets not supported
1901 if (AM.ScalableOffset)
1902 return false;
1903
1904 // Allows a sign-extended 16-bit immediate field.
1905 if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1)
1906 return false;
1907
1908 // No global is ever allowed as a base.
1909 if (AM.BaseGV)
1910 return false;
1911
1912 // Only support r+r,
1913 switch (AM.Scale) {
1914 case 0: // "r+i" or just "i", depending on HasBaseReg.
1915 break;
1916 case 1:
1917 if (AM.HasBaseReg && AM.BaseOffs) // "r+r+i" is not allowed.
1918 return false;
1919 // Otherwise we have r+r or r+i.
1920 break;
1921 case 2:
1922 if (AM.HasBaseReg || AM.BaseOffs) // 2*r+r or 2*r+i is not allowed.
1923 return false;
1924 // Allow 2*r as r+r.
1925 break;
1926 default: // Don't allow n * r
1927 return false;
1928 }
1929
1930 return true;
1931}
1932
1933//===----------------------------------------------------------------------===//
1934// Stack Protector
1935//===----------------------------------------------------------------------===//
1936
1937// For OpenBSD return its special guard variable. Otherwise return nullptr,
1938// so that SelectionDAG handle SSP.
1940 if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
1941 Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
1942 PointerType *PtrTy = PointerType::getUnqual(M.getContext());
1943 Constant *C = M.getOrInsertGlobal("__guard_local", PtrTy);
1944 if (GlobalVariable *G = dyn_cast_or_null<GlobalVariable>(C))
1945 G->setVisibility(GlobalValue::HiddenVisibility);
1946 return C;
1947 }
1948 return nullptr;
1949}
1950
1951// Currently only support "standard" __stack_chk_guard.
1952// TODO: add LOAD_STACK_GUARD support.
1954 if (!M.getNamedValue("__stack_chk_guard")) {
1955 auto *GV = new GlobalVariable(M, PointerType::getUnqual(M.getContext()),
1957 nullptr, "__stack_chk_guard");
1958
1959 // FreeBSD has "__stack_chk_guard" defined externally on libc.so
1960 if (M.getDirectAccessExternalData() &&
1962 !(TM.getTargetTriple().isPPC64() &&
1963 TM.getTargetTriple().isOSFreeBSD()) &&
1964 (!TM.getTargetTriple().isOSDarwin() ||
1966 GV->setDSOLocal(true);
1967 }
1968}
1969
1970// Currently only support "standard" __stack_chk_guard.
1971// TODO: add LOAD_STACK_GUARD support.
1973 return M.getNamedValue("__stack_chk_guard");
1974}
1975
1977 return nullptr;
1978}
1979
1982}
1983
1986}
1987
1988unsigned TargetLoweringBase::getMinimumJumpTableDensity(bool OptForSize) const {
1989 return OptForSize ? OptsizeJumpTableDensity : JumpTableDensity;
1990}
1991
1993 return MaximumJumpTableSize;
1994}
1995
1998}
1999
2002}
2003
2005 if (TM.Options.LoopAlignment)
2006 return Align(TM.Options.LoopAlignment);
2007 return PrefLoopAlignment;
2008}
2009
2011 MachineBasicBlock *MBB) const {
2012 return MaxBytesForAlignment;
2013}
2014
2015//===----------------------------------------------------------------------===//
2016// Reciprocal Estimates
2017//===----------------------------------------------------------------------===//
2018
2019/// Get the reciprocal estimate attribute string for a function that will
2020/// override the target defaults.
2022 const Function &F = MF.getFunction();
2023 return F.getFnAttribute("reciprocal-estimates").getValueAsString();
2024}
2025
2026/// Construct a string for the given reciprocal operation of the given type.
2027/// This string should match the corresponding option to the front-end's
2028/// "-mrecip" flag assuming those strings have been passed through in an
2029/// attribute string. For example, "vec-divf" for a division of a vXf32.
2030static std::string getReciprocalOpName(bool IsSqrt, EVT VT) {
2031 std::string Name = VT.isVector() ? "vec-" : "";
2032
2033 Name += IsSqrt ? "sqrt" : "div";
2034
2035 // TODO: Handle other float types?
2036 if (VT.getScalarType() == MVT::f64) {
2037 Name += "d";
2038 } else if (VT.getScalarType() == MVT::f16) {
2039 Name += "h";
2040 } else {
2041 assert(VT.getScalarType() == MVT::f32 &&
2042 "Unexpected FP type for reciprocal estimate");
2043 Name += "f";
2044 }
2045
2046 return Name;
2047}
2048
2049/// Return the character position and value (a single numeric character) of a
2050/// customized refinement operation in the input string if it exists. Return
2051/// false if there is no customized refinement step count.
2052static bool parseRefinementStep(StringRef In, size_t &Position,
2053 uint8_t &Value) {
2054 const char RefStepToken = ':';
2055 Position = In.find(RefStepToken);
2056 if (Position == StringRef::npos)
2057 return false;
2058
2059 StringRef RefStepString = In.substr(Position + 1);
2060 // Allow exactly one numeric character for the additional refinement
2061 // step parameter.
2062 if (RefStepString.size() == 1) {
2063 char RefStepChar = RefStepString[0];
2064 if (isDigit(RefStepChar)) {
2065 Value = RefStepChar - '0';
2066 return true;
2067 }
2068 }
2069 report_fatal_error("Invalid refinement step for -recip.");
2070}
2071
2072/// For the input attribute string, return one of the ReciprocalEstimate enum
2073/// status values (enabled, disabled, or not specified) for this operation on
2074/// the specified data type.
2075static int getOpEnabled(bool IsSqrt, EVT VT, StringRef Override) {
2076 if (Override.empty())
2078
2079 SmallVector<StringRef, 4> OverrideVector;
2080 Override.split(OverrideVector, ',');
2081 unsigned NumArgs = OverrideVector.size();
2082
2083 // Check if "all", "none", or "default" was specified.
2084 if (NumArgs == 1) {
2085 // Look for an optional setting of the number of refinement steps needed
2086 // for this type of reciprocal operation.
2087 size_t RefPos;
2088 uint8_t RefSteps;
2089 if (parseRefinementStep(Override, RefPos, RefSteps)) {
2090 // Split the string for further processing.
2091 Override = Override.substr(0, RefPos);
2092 }
2093
2094 // All reciprocal types are enabled.
2095 if (Override == "all")
2097
2098 // All reciprocal types are disabled.
2099 if (Override == "none")
2101
2102 // Target defaults for enablement are used.
2103 if (Override == "default")
2105 }
2106
2107 // The attribute string may omit the size suffix ('f'/'d').
2108 std::string VTName = getReciprocalOpName(IsSqrt, VT);
2109 std::string VTNameNoSize = VTName;
2110 VTNameNoSize.pop_back();
2111 static const char DisabledPrefix = '!';
2112
2113 for (StringRef RecipType : OverrideVector) {
2114 size_t RefPos;
2115 uint8_t RefSteps;
2116 if (parseRefinementStep(RecipType, RefPos, RefSteps))
2117 RecipType = RecipType.substr(0, RefPos);
2118
2119 // Ignore the disablement token for string matching.
2120 bool IsDisabled = RecipType[0] == DisabledPrefix;
2121 if (IsDisabled)
2122 RecipType = RecipType.substr(1);
2123
2124 if (RecipType == VTName || RecipType == VTNameNoSize)
2127 }
2128
2130}
2131
2132/// For the input attribute string, return the customized refinement step count
2133/// for this operation on the specified data type. If the step count does not
2134/// exist, return the ReciprocalEstimate enum value for unspecified.
2135static int getOpRefinementSteps(bool IsSqrt, EVT VT, StringRef Override) {
2136 if (Override.empty())
2138
2139 SmallVector<StringRef, 4> OverrideVector;
2140 Override.split(OverrideVector, ',');
2141 unsigned NumArgs = OverrideVector.size();
2142
2143 // Check if "all", "default", or "none" was specified.
2144 if (NumArgs == 1) {
2145 // Look for an optional setting of the number of refinement steps needed
2146 // for this type of reciprocal operation.
2147 size_t RefPos;
2148 uint8_t RefSteps;
2149 if (!parseRefinementStep(Override, RefPos, RefSteps))
2151
2152 // Split the string for further processing.
2153 Override = Override.substr(0, RefPos);
2154 assert(Override != "none" &&
2155 "Disabled reciprocals, but specifed refinement steps?");
2156
2157 // If this is a general override, return the specified number of steps.
2158 if (Override == "all" || Override == "default")
2159 return RefSteps;
2160 }
2161
2162 // The attribute string may omit the size suffix ('f'/'d').
2163 std::string VTName = getReciprocalOpName(IsSqrt, VT);
2164 std::string VTNameNoSize = VTName;
2165 VTNameNoSize.pop_back();
2166
2167 for (StringRef RecipType : OverrideVector) {
2168 size_t RefPos;
2169 uint8_t RefSteps;
2170 if (!parseRefinementStep(RecipType, RefPos, RefSteps))
2171 continue;
2172
2173 RecipType = RecipType.substr(0, RefPos);
2174 if (RecipType == VTName || RecipType == VTNameNoSize)
2175 return RefSteps;
2176 }
2177
2179}
2180
2182 MachineFunction &MF) const {
2183 return getOpEnabled(true, VT, getRecipEstimateForFunc(MF));
2184}
2185
2187 MachineFunction &MF) const {
2188 return getOpEnabled(false, VT, getRecipEstimateForFunc(MF));
2189}
2190
2192 MachineFunction &MF) const {
2193 return getOpRefinementSteps(true, VT, getRecipEstimateForFunc(MF));
2194}
2195
2197 MachineFunction &MF) const {
2198 return getOpRefinementSteps(false, VT, getRecipEstimateForFunc(MF));
2199}
2200
2202 EVT LoadVT, EVT BitcastVT, const SelectionDAG &DAG,
2203 const MachineMemOperand &MMO) const {
2204 // Single-element vectors are scalarized, so we should generally avoid having
2205 // any memory operations on such types, as they would get scalarized too.
2206 if (LoadVT.isFixedLengthVector() && BitcastVT.isFixedLengthVector() &&
2207 BitcastVT.getVectorNumElements() == 1)
2208 return false;
2209
2210 // Don't do if we could do an indexed load on the original type, but not on
2211 // the new one.
2212 if (!LoadVT.isSimple() || !BitcastVT.isSimple())
2213 return true;
2214
2215 MVT LoadMVT = LoadVT.getSimpleVT();
2216
2217 // Don't bother doing this if it's just going to be promoted again later, as
2218 // doing so might interfere with other combines.
2219 if (getOperationAction(ISD::LOAD, LoadMVT) == Promote &&
2220 getTypeToPromoteTo(ISD::LOAD, LoadMVT) == BitcastVT.getSimpleVT())
2221 return false;
2222
2223 unsigned Fast = 0;
2224 return allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), BitcastVT,
2225 MMO, &Fast) &&
2226 Fast;
2227}
2228
2231}
2232
2234 const LoadInst &LI, const DataLayout &DL, AssumptionCache *AC,
2235 const TargetLibraryInfo *LibInfo) const {
2237 if (LI.isVolatile())
2239
2240 if (LI.hasMetadata(LLVMContext::MD_nontemporal))
2242
2243 if (LI.hasMetadata(LLVMContext::MD_invariant_load))
2245
2247 LI.getAlign(), DL, &LI, AC,
2248 /*DT=*/nullptr, LibInfo))
2250
2251 Flags |= getTargetMMOFlags(LI);
2252 return Flags;
2253}
2254
2257 const DataLayout &DL) const {
2259
2260 if (SI.isVolatile())
2262
2263 if (SI.hasMetadata(LLVMContext::MD_nontemporal))
2265
2266 // FIXME: Not preserving dereferenceable
2267 Flags |= getTargetMMOFlags(SI);
2268 return Flags;
2269}
2270
2273 const DataLayout &DL) const {
2275
2276 if (const AtomicRMWInst *RMW = dyn_cast<AtomicRMWInst>(&AI)) {
2277 if (RMW->isVolatile())
2279 } else if (const AtomicCmpXchgInst *CmpX = dyn_cast<AtomicCmpXchgInst>(&AI)) {
2280 if (CmpX->isVolatile())
2282 } else
2283 llvm_unreachable("not an atomic instruction");
2284
2285 // FIXME: Not preserving dereferenceable
2286 Flags |= getTargetMMOFlags(AI);
2287 return Flags;
2288}
2289
2291 Instruction *Inst,
2292 AtomicOrdering Ord) const {
2293 if (isReleaseOrStronger(Ord) && Inst->hasAtomicStore())
2294 return Builder.CreateFence(Ord);
2295 else
2296 return nullptr;
2297}
2298
2300 Instruction *Inst,
2301 AtomicOrdering Ord) const {
2302 if (isAcquireOrStronger(Ord))
2303 return Builder.CreateFence(Ord);
2304 else
2305 return nullptr;
2306}
2307
2308//===----------------------------------------------------------------------===//
2309// GlobalISel Hooks
2310//===----------------------------------------------------------------------===//
2311
2313 const TargetTransformInfo *TTI) const {
2314 auto &MF = *MI.getMF();
2315 auto &MRI = MF.getRegInfo();
2316 // Assuming a spill and reload of a value has a cost of 1 instruction each,
2317 // this helper function computes the maximum number of uses we should consider
2318 // for remat. E.g. on arm64 global addresses take 2 insts to materialize. We
2319 // break even in terms of code size when the original MI has 2 users vs
2320 // choosing to potentially spill. Any more than 2 users we we have a net code
2321 // size increase. This doesn't take into account register pressure though.
2322 auto maxUses = [](unsigned RematCost) {
2323 // A cost of 1 means remats are basically free.
2324 if (RematCost == 1)
2325 return std::numeric_limits<unsigned>::max();
2326 if (RematCost == 2)
2327 return 2U;
2328
2329 // Remat is too expensive, only sink if there's one user.
2330 if (RematCost > 2)
2331 return 1U;
2332 llvm_unreachable("Unexpected remat cost");
2333 };
2334
2335 switch (MI.getOpcode()) {
2336 default:
2337 return false;
2338 // Constants-like instructions should be close to their users.
2339 // We don't want long live-ranges for them.
2340 case TargetOpcode::G_CONSTANT:
2341 case TargetOpcode::G_FCONSTANT:
2342 case TargetOpcode::G_FRAME_INDEX:
2343 case TargetOpcode::G_INTTOPTR:
2344 return true;
2345 case TargetOpcode::G_GLOBAL_VALUE: {
2346 unsigned RematCost = TTI->getGISelRematGlobalCost();
2347 Register Reg = MI.getOperand(0).getReg();
2348 unsigned MaxUses = maxUses(RematCost);
2349 if (MaxUses == UINT_MAX)
2350 return true; // Remats are "free" so always localize.
2351 return MRI.hasAtMostUserInstrs(Reg, MaxUses);
2352 }
2353 }
2354}
unsigned const MachineRegisterInfo * MRI
amdgpu AMDGPU Register Bank Select
Rewrite undef for PHI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the BitVector class.
return RetTy
std::string Name
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
unsigned const TargetRegisterInfo * TRI
Module.h This file contains the declarations for the Module class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static bool isDigit(const char C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
static cl::opt< bool > JumpIsExpensiveOverride("jump-is-expensive", cl::init(false), cl::desc("Do not create extra branches to split comparison logic."), cl::Hidden)
#define OP_TO_LIBCALL(Name, Enum)
static cl::opt< unsigned > MinimumJumpTableEntries("min-jump-table-entries", cl::init(4), cl::Hidden, cl::desc("Set minimum number of entries to use a jump table."))
static cl::opt< bool > DisableStrictNodeMutation("disable-strictnode-mutation", cl::desc("Don't mutate strict-float node to a legalize node"), cl::init(false), cl::Hidden)
static bool parseRefinementStep(StringRef In, size_t &Position, uint8_t &Value)
Return the character position and value (a single numeric character) of a customized refinement opera...
static cl::opt< unsigned > MaximumJumpTableSize("max-jump-table-size", cl::init(UINT_MAX), cl::Hidden, cl::desc("Set maximum size of jump tables."))
static cl::opt< unsigned > JumpTableDensity("jump-table-density", cl::init(10), cl::Hidden, cl::desc("Minimum density for building a jump table in " "a normal function"))
Minimum jump table density for normal functions.
static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT, TargetLoweringBase *TLI)
static std::string getReciprocalOpName(bool IsSqrt, EVT VT)
Construct a string for the given reciprocal operation of the given type.
#define LCALL5(A)
static int getOpRefinementSteps(bool IsSqrt, EVT VT, StringRef Override)
For the input attribute string, return the customized refinement step count for this operation on the...
static int getOpEnabled(bool IsSqrt, EVT VT, StringRef Override)
For the input attribute string, return one of the ReciprocalEstimate enum status values (enabled,...
static StringRef getRecipEstimateForFunc(MachineFunction &MF)
Get the reciprocal estimate attribute string for a function that will override the target defaults.
static cl::opt< unsigned > OptsizeJumpTableDensity("optsize-jump-table-density", cl::init(40), cl::Hidden, cl::desc("Minimum density for building a jump table in " "an optsize function"))
Minimum jump table density for -Os or -Oz functions.
This file describes how to lower LLVM code to machine code.
This pass exposes codegen information to IR-level passes.
Class for arbitrary precision integers.
Definition: APInt.h:78
A cache of @llvm.assume calls within a function.
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:495
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:696
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the return value.
Definition: Attributes.h:820
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:219
void setBitsInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
setBitsInMask - Add '1' bits from Mask to this vector.
Definition: BitVector.h:707
iterator_range< const_set_bits_iterator > set_bits() const
Definition: BitVector.h:140
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
This class represents a range of values.
Definition: ConstantRange.h:47
unsigned getActiveBits() const
Compute the maximal number of active bits needed to represent every value in this range.
ConstantRange umul_sat(const ConstantRange &Other) const
Perform an unsigned saturating multiplication of two constant ranges.
ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
This is an important base class in LLVM.
Definition: Constant.h:42
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size in bytes, rounded up to a whole number of bytes.
Definition: DataLayout.cpp:725
static constexpr ElementCount getScalable(ScalarTy MinVal)
Definition: TypeSize.h:314
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:311
constexpr bool isScalar() const
Exactly one element.
Definition: TypeSize.h:322
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:168
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:656
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:68
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:52
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:91
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition: IRBuilder.h:1851
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:171
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2432
bool hasAtomicStore() const LLVM_READONLY
Return true if this atomic instruction stores to memory.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
Definition: Instruction.h:363
@ MAX_INT_BITS
Maximum number of bits that can be specified.
Definition: DerivedTypes.h:52
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
An instruction for reading from memory.
Definition: Instructions.h:174
Value * getPointerOperand()
Definition: Instructions.h:253
bool isVolatile() const
Return true if this is a load from a volatile memory location.
Definition: Instructions.h:203
Align getAlign() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:209
Machine Value Type.
SimpleValueType SimpleTy
uint64_t getScalarSizeInBits() const
bool isVector() const
Return true if this is a vector value type.
bool isScalableVector() const
Return true if this is a vector value type where the runtime length is machine dependent.
static auto all_valuetypes()
SimpleValueType Iteration.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
ElementCount getVectorElementCount() const
bool isScalarInteger() const
Return true if this is an integer, not including vectors.
static MVT getVectorVT(MVT VT, unsigned NumElements)
MVT getVectorElementType() const
bool isValid() const
Return true if this is a valid simple valuetype.
static MVT getIntegerVT(unsigned BitWidth)
static auto fp_valuetypes()
MVT getPow2VectorType() const
Widens the length of the given vector MVT up to the nearest power of 2 and returns that type.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
Representation of each machine instruction.
Definition: MachineInstr.h:69
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:572
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.
void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
A description of a memory reference used in the backend.
unsigned getAddrSpace() const
Flags
Flags values. These may be or'd together.
@ MOVolatile
The memory access is volatile.
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
@ MOLoad
The memory access reads data.
@ MONonTemporal
The memory access is non-temporal.
@ MOInvariant
The memory access always returns the same value (or traps).
@ MOStore
The memory access writes data.
Flags getFlags() const
Return the raw flags of the source value,.
Align getAlign() const
Return the minimum known alignment in bytes of the actual memory reference.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
void freezeReservedRegs()
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Class to represent pointers.
Definition: DerivedTypes.h:646
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:662
Analysis providing profile information.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:226
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:487
LLVMContext * getContext() const
Definition: SelectionDAG.h:500
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
An instruction for storing to memory.
Definition: Instructions.h:290
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:685
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:556
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
static constexpr size_t npos
Definition: StringRef.h:52
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
Multiway switch.
Provides information about what library functions are available for the current target.
LegalizeTypeAction getTypeAction(MVT VT) const
void setTypeAction(MVT VT, LegalizeTypeAction Action)
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
virtual void finalizeLowering(MachineFunction &MF) const
Execute target specific actions to finalize target lowering.
void initActions()
Initialize all of the actions to default values.
bool PredictableSelectIsExpensive
Tells the code generator that select is more expensive than a branch if the branch is usually predict...
unsigned MaxStoresPerMemcpyOptSize
Likewise for functions with the OptSize attribute.
MachineBasicBlock * emitPatchPoint(MachineInstr &MI, MachineBasicBlock *MBB) const
Replace/modify any TargetFrameIndex operands with a targte-dependent sequence of memory operands that...
virtual Value * getSafeStackPointerLocation(IRBuilderBase &IRB) const
Returns the target-specific address of the unsafe stack pointer.
int getRecipEstimateSqrtEnabled(EVT VT, MachineFunction &MF) const
Return a ReciprocalEstimate enum value for a square root of the given type based on the function's at...
virtual bool canOpTrap(unsigned Op, EVT VT) const
Returns true if the operation can trap for the value type.
virtual bool shouldLocalize(const MachineInstr &MI, const TargetTransformInfo *TTI) const
Check whether or not MI needs to be moved close to its uses.
virtual unsigned getMaxPermittedBytesForAlignment(MachineBasicBlock *MBB) const
Return the maximum amount of bytes allowed to be emitted when padding for alignment.
void setMaximumJumpTableSize(unsigned)
Indicate the maximum number of entries in jump tables.
virtual unsigned getMinimumJumpTableEntries() const
Return lower limit for number of blocks in a jump table.
const TargetMachine & getTargetMachine() const
unsigned MaxLoadsPerMemcmp
Specify maximum number of load instructions per memcmp call.
virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain targets require unusual breakdowns of certain types.
virtual MachineMemOperand::Flags getTargetMMOFlags(const Instruction &I) const
This callback is used to inspect load/store instructions and add target-specific MachineMemOperand fl...
unsigned MaxGluedStoresPerMemcpy
Specify max number of store instructions to glue in inlined memcpy.
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
virtual bool isSuitableForJumpTable(const SwitchInst *SI, uint64_t NumCases, uint64_t Range, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) const
Return true if lowering to a jump table is suitable for a set of case clusters which may contain NumC...
void setIndexedMaskedLoadAction(unsigned IdxMode, MVT VT, LegalizeAction Action)
Indicate that the specified indexed masked load does or does not work with the specified type and ind...
virtual Value * getSDagStackGuard(const Module &M) const
Return the variable that's previously inserted by insertSSPDeclarations, if any, otherwise return nul...
virtual bool useFPRegsForHalfType() const
virtual bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT, const SelectionDAG &DAG, const MachineMemOperand &MMO) const
Return true if the following transform is beneficial: fold (conv (load x)) -> (load (conv*)x) On arch...
void setIndexedLoadAction(ArrayRef< unsigned > IdxModes, MVT VT, LegalizeAction Action)
Indicate that the specified indexed load does or does not work with the specified type and indicate w...
virtual bool softPromoteHalfType() const
unsigned getMaximumJumpTableSize() const
Return upper limit for number of entries in a jump table.
virtual MVT::SimpleValueType getCmpLibcallReturnType() const
Return the ValueType for comparison libcalls.
unsigned getBitWidthForCttzElements(Type *RetTy, ElementCount EC, bool ZeroIsPoison, const ConstantRange *VScaleRange) const
Return the minimum number of bits required to hold the maximum possible number of trailing zero vecto...
bool isLegalRC(const TargetRegisterInfo &TRI, const TargetRegisterClass &RC) const
Return true if the value types that can be represented by the specified register class are all legal.
virtual TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const
Return the preferred vector type legalization action.
void setAtomicLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Let target indicate that an extending atomic load of the specified type is legal.
Value * getDefaultSafeStackPointerLocation(IRBuilderBase &IRB, bool UseTLS) const
virtual Function * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
MachineMemOperand::Flags getAtomicMemOperandFlags(const Instruction &AI, const DataLayout &DL) const
virtual bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *=nullptr) const
Determine if the target supports unaligned memory accesses.
unsigned MaxStoresPerMemsetOptSize
Likewise for functions with the OptSize attribute.
EVT getShiftAmountTy(EVT LHSTy, const DataLayout &DL) const
Returns the type for the shift amount of a shift opcode.
unsigned MaxStoresPerMemmove
Specify maximum number of store instructions per memmove call.
virtual Align getPrefLoopAlignment(MachineLoop *ML=nullptr) const
Return the preferred loop alignment.
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose.
int getDivRefinementSteps(EVT VT, MachineFunction &MF) const
Return the refinement step count for a division of the given type based on the function's attributes.
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
MachineMemOperand::Flags getLoadMemOperandFlags(const LoadInst &LI, const DataLayout &DL, AssumptionCache *AC=nullptr, const TargetLibraryInfo *LibInfo=nullptr) const
virtual EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
unsigned MaxStoresPerMemmoveOptSize
Likewise for functions with the OptSize attribute.
virtual Value * getIRStackGuard(IRBuilderBase &IRB) const
If the target has a standard location for the stack protector guard, returns the address of that loca...
virtual MVT getPreferredSwitchConditionType(LLVMContext &Context, EVT ConditionVT) const
Returns preferred type for switch condition.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
int getRecipEstimateDivEnabled(EVT VT, MachineFunction &MF) const
Return a ReciprocalEstimate enum value for a division of the given type based on the function's attri...
void setIndexedStoreAction(ArrayRef< unsigned > IdxModes, MVT VT, LegalizeAction Action)
Indicate that the specified indexed store does or does not work with the specified type and indicate ...
virtual bool isJumpTableRelative() const
virtual MVT getScalarShiftAmountTy(const DataLayout &, EVT) const
Return the type to use for a scalar shift opcode, given the shifted amount type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
virtual bool isFreeAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const
Returns true if a cast from SrcAS to DestAS is "cheap", such that e.g.
void setIndexedMaskedStoreAction(unsigned IdxMode, MVT VT, LegalizeAction Action)
Indicate that the specified indexed masked store does or does not work with the specified type and in...
unsigned MaxStoresPerMemset
Specify maximum number of store instructions per memset call.
void setMinimumJumpTableEntries(unsigned Val)
Indicate the minimum number of blocks to generate jump tables.
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
virtual uint64_t getByValTypeAlignment(Type *Ty, const DataLayout &DL) const
Return the desired alignment for ByVal or InAlloca aggregate function arguments in the caller paramet...
virtual bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *Fast=nullptr) const
Return true if the target supports a memory access of this type for the given address space and align...
unsigned MaxLoadsPerMemcmpOptSize
Likewise for functions with the OptSize attribute.
MachineMemOperand::Flags getStoreMemOperandFlags(const StoreInst &SI, const DataLayout &DL) const
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
unsigned getMinimumJumpTableDensity(bool OptForSize) const
Return lower limit of the density in a jump table.
virtual std::pair< const TargetRegisterClass *, uint8_t > findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const
Return the largest legal super-reg register class of the register class for the specified type and it...
TargetLoweringBase(const TargetMachine &TM)
NOTE: The TargetMachine owns TLOF.
LegalizeKind getTypeConversion(LLVMContext &Context, EVT VT) const
Return pair that represents the legalization kind (first) that needs to happen to EVT (second) in ord...
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
unsigned GatherAllAliasesMaxDepth
Depth that GatherAllAliases should continue looking for chain dependencies when trying to find a more...
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
Return how we should legalize values of this type, either it is already legal (return 'Legal') or we ...
int getSqrtRefinementSteps(EVT VT, MachineFunction &MF) const
Return the refinement step count for a square root of the given type based on the function's attribut...
bool allowsMemoryAccessForAlignment(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *Fast=nullptr) const
This function returns true if the memory access is aligned or if the target allows this specific unal...
virtual Instruction * emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const
virtual Instruction * emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const
Inserts in the IR a target-specific intrinsic specifying a fence.
unsigned MaxStoresPerMemcpy
Specify maximum number of store instructions per memcpy call.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
virtual void insertSSPDeclarations(Module &M) const
Inserts necessary declarations for SSP (stack protection) purpose.
void setJumpIsExpensive(bool isExpensive=true)
Tells the code generator not to expand logic operations on comparison predicates into separate sequen...
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
MVT getTypeToPromoteTo(unsigned Op, MVT VT) const
If the action for this operation is to promote, this method returns the ValueType to promote to.
virtual bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AddrSpace, Instruction *I=nullptr) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const
Vector types are broken down into some number of legal first class types.
std::pair< LegalizeTypeAction, EVT > LegalizeKind
LegalizeKind holds the legalization kind that needs to happen to EVT in order to type-legalize it.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
virtual EVT getTypeForExtReturn(LLVMContext &Context, EVT VT, ISD::NodeType) const
Return the type that should be used to zero or sign extend a zeroext/signext integer return value.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
bool isPositionIndependent() const
virtual bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const
Returns true if a cast between SrcAS and DestAS is a noop.
const Triple & getTargetTriple() const
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
TargetOptions Options
unsigned LoopAlignment
If greater than 0, override TargetLoweringBase::PrefLoopAlignment.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
unsigned getGISelRematGlobalCost() const
bool isWindowsGNUEnvironment() const
Definition: Triple.h:657
bool isAndroid() const
Tests whether the target is Android.
Definition: Triple.h:769
bool isOSFreeBSD() const
Definition: Triple.h:584
bool isPPC64() const
Tests whether the target is 64-bit PowerPC (little and big endian).
Definition: Triple.h:964
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, XROS, or DriverKit).
Definition: Triple.h:558
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
constexpr LeafTy coefficientNextPowerOf2() const
Definition: TypeSize.h:262
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:168
constexpr LeafTy divideCoefficientBy(ScalarTy RHS) const
We do not provide the '/' operator here because division for polynomial types does not work in the sa...
Definition: TypeSize.h:254
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:41
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:40
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:779
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
Definition: ISDOpcodes.h:243
@ CTLZ_ZERO_UNDEF
Definition: ISDOpcodes.h:752
@ DELETED_NODE
DELETED_NODE - This is an illegal value that is used to catch errors.
Definition: ISDOpcodes.h:44
@ SET_FPENV
Sets the current floating-point environment.
Definition: ISDOpcodes.h:1066
@ VECREDUCE_SEQ_FADD
Generic reduction nodes.
Definition: ISDOpcodes.h:1407
@ VECREDUCE_SMIN
Definition: ISDOpcodes.h:1440
@ FGETSIGN
INT = FGETSIGN(FP) - Return the sign bit of the specified floating point value as an integer 0/1 valu...
Definition: ISDOpcodes.h:511
@ ATOMIC_LOAD_NAND
Definition: ISDOpcodes.h:1337
@ SMULFIX
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
Definition: ISDOpcodes.h:374
@ ConstantFP
Definition: ISDOpcodes.h:77
@ ATOMIC_LOAD_MAX
Definition: ISDOpcodes.h:1339
@ ATOMIC_LOAD_UMIN
Definition: ISDOpcodes.h:1340
@ ADDC
Carry-setting nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:276
@ RESET_FPENV
Set floating-point environment to default state.
Definition: ISDOpcodes.h:1070
@ FMAD
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations.
Definition: ISDOpcodes.h:501
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:246
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:1099
@ SMULFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:380
@ SET_FPMODE
Sets the current dynamic floating-point control modes.
Definition: ISDOpcodes.h:1089
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:813
@ ATOMIC_CMP_SWAP_WITH_SUCCESS
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
Definition: ISDOpcodes.h:1322
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:840
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition: ISDOpcodes.h:557
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
Definition: ISDOpcodes.h:1425
@ FADD
Simple binary floating point operators.
Definition: ISDOpcodes.h:397
@ VECREDUCE_FMAXIMUM
FMINIMUM/FMAXIMUM nodes propatate NaNs and signed zeroes using the llvm.minimum and llvm....
Definition: ISDOpcodes.h:1429
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition: ISDOpcodes.h:716
@ RESET_FPMODE
Sets default dynamic floating-point control modes.
Definition: ISDOpcodes.h:1093
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition: ISDOpcodes.h:870
@ VECREDUCE_SMAX
Definition: ISDOpcodes.h:1439
@ ATOMIC_LOAD_OR
Definition: ISDOpcodes.h:1335
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:953
@ ATOMIC_LOAD_XOR
Definition: ISDOpcodes.h:1336
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Definition: ISDOpcodes.h:996
@ SDIVFIX
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
Definition: ISDOpcodes.h:387
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:1480
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:804
@ AVGCEILS
AVGCEILS/AVGCEILU - Rounding averaging add - Add two integers using an integer of type i[N+2],...
Definition: ISDOpcodes.h:684
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
Definition: ISDOpcodes.h:1256
@ VECREDUCE_FADD
These reductions have relaxed evaluation order semantics, and have a single vector operand.
Definition: ISDOpcodes.h:1422
@ CTTZ_ZERO_UNDEF
Bit counting operators with an undefined result for zero inputs.
Definition: ISDOpcodes.h:751
@ PREFETCH
PREFETCH - This corresponds to a prefetch intrinsic.
Definition: ISDOpcodes.h:1289
@ TRUNCATE_SSAT_U
Definition: ISDOpcodes.h:833
@ VECREDUCE_FMIN
Definition: ISDOpcodes.h:1426
@ SETCCCARRY
Like SetCC, ops #0 and #1 are the LHS and RHS operands to compare, but op #2 is a boolean indicating ...
Definition: ISDOpcodes.h:787
@ FNEG
Perform various unary floating-point operations inspired by libm.
Definition: ISDOpcodes.h:980
@ SSUBO
Same for subtraction.
Definition: ISDOpcodes.h:334
@ ATOMIC_LOAD_MIN
Definition: ISDOpcodes.h:1338
@ IS_FPCLASS
Performs a check of floating point class property, defined by IEEE-754.
Definition: ISDOpcodes.h:521
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition: ISDOpcodes.h:356
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:756
@ VECREDUCE_UMAX
Definition: ISDOpcodes.h:1441
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition: ISDOpcodes.h:641
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition: ISDOpcodes.h:330
@ VECREDUCE_ADD
Integer reductions may have a result type larger than the vector element type.
Definition: ISDOpcodes.h:1434
@ GET_FPMODE
Reads the current dynamic floating-point control modes.
Definition: ISDOpcodes.h:1084
@ GET_FPENV
Gets the current floating-point environment.
Definition: ISDOpcodes.h:1061
@ SHL
Shift and rotation operations.
Definition: ISDOpcodes.h:734
@ ATOMIC_LOAD_CLR
Definition: ISDOpcodes.h:1334
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:614
@ ATOMIC_LOAD_AND
Definition: ISDOpcodes.h:1333
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
Definition: ISDOpcodes.h:1041
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:549
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:810
@ DEBUGTRAP
DEBUGTRAP - Trap intended to get the attention of a debugger.
Definition: ISDOpcodes.h:1279
@ FP_TO_UINT_SAT
Definition: ISDOpcodes.h:906
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
Definition: ISDOpcodes.h:1316
@ ATOMIC_LOAD_UMAX
Definition: ISDOpcodes.h:1341
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:1028
@ UBSANTRAP
UBSANTRAP - Trap with an immediate describing the kind of sanitizer failure.
Definition: ISDOpcodes.h:1283
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
Definition: ISDOpcodes.h:366
@ SMULO
Same for multiplication.
Definition: ISDOpcodes.h:338
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
Definition: ISDOpcodes.h:859
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:848
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition: ISDOpcodes.h:696
@ SDIVFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:393
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:938
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:310
@ VECREDUCE_UMIN
Definition: ISDOpcodes.h:1442
@ ATOMIC_LOAD_ADD
Definition: ISDOpcodes.h:1331
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
Definition: ISDOpcodes.h:1047
@ ATOMIC_LOAD_SUB
Definition: ISDOpcodes.h:1332
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:886
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
Definition: ISDOpcodes.h:1250
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:708
@ TRAP
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:1276
@ GET_FPENV_MEM
Gets the current floating-point environment.
Definition: ISDOpcodes.h:1075
@ SCMP
[US]CMP - 3-way comparison of signed or unsigned integers.
Definition: ISDOpcodes.h:704
@ AVGFLOORS
AVGFLOORS/AVGFLOORU - Averaging add - Add two integers using an integer of type i[N+1],...
Definition: ISDOpcodes.h:679
@ VECREDUCE_FMUL
Definition: ISDOpcodes.h:1423
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:286
@ FREEZE
FREEZE - FREEZE(VAL) returns an arbitrary value if VAL is UNDEF (or is evaluated to UNDEF),...
Definition: ISDOpcodes.h:223
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition: ISDOpcodes.h:538
@ VECTOR_SPLICE
VECTOR_SPLICE(VEC1, VEC2, IMM) - Returns a subvector of the same type as VEC1/VEC2 from CONCAT_VECTOR...
Definition: ISDOpcodes.h:626
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
Definition: ISDOpcodes.h:1330
@ FFREXP
FFREXP - frexp, extract fractional and exponent component of a floating-point value.
Definition: ISDOpcodes.h:1001
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:919
@ VECTOR_COMPRESS
VECTOR_COMPRESS(Vec, Mask, Passthru) consecutively place vector elements based on mask e....
Definition: ISDOpcodes.h:668
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition: ISDOpcodes.h:881
@ ADDRSPACECAST
ADDRSPACECAST - This operator converts between pointers of different address spaces.
Definition: ISDOpcodes.h:957
@ FP_TO_SINT_SAT
FP_TO_[US]INT_SAT - Convert floating point value in operand 0 to a signed or unsigned scalar integer ...
Definition: ISDOpcodes.h:905
@ VECREDUCE_FMINIMUM
Definition: ISDOpcodes.h:1430
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:816
@ VECREDUCE_SEQ_FMUL
Definition: ISDOpcodes.h:1408
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:507
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition: ISDOpcodes.h:347
@ GET_DYNAMIC_AREA_OFFSET
GET_DYNAMIC_AREA_OFFSET - get offset from native SP to the address of the most recent dynamic alloca.
Definition: ISDOpcodes.h:1388
@ SET_FPENV_MEM
Sets the current floating point environment.
Definition: ISDOpcodes.h:1080
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
Definition: ISDOpcodes.h:1052
@ TRUNCATE_SSAT_S
TRUNCATE_[SU]SAT_[SU] - Truncate for saturated operand [SU] located in middle, prefix for SAT means i...
Definition: ISDOpcodes.h:831
@ ABDS
ABDS/ABDU - Absolute difference - Return the absolute difference between two numbers interpreted as s...
Definition: ISDOpcodes.h:691
@ TRUNCATE_USAT_U
Definition: ISDOpcodes.h:835
@ SADDO_CARRY
Carry-using overflow-aware nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:320
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1603
static const int LAST_INDEXED_MODE
Definition: ISDOpcodes.h:1554
Libcall getPOWI(EVT RetVT)
getPOWI - Return the POWI_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall getSINTTOFP(EVT OpVT, EVT RetVT)
getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
void initCmpLibcallCCs(ISD::CondCode *CmpLibcallCCs)
Initialize the default condition code on the libcalls.
Libcall getSYNC(unsigned Opc, MVT VT)
Return the SYNC_FETCH_AND_* value for the given opcode and type, or UNKNOWN_LIBCALL if there is none.
Libcall getLDEXP(EVT RetVT)
getLDEXP - Return the LDEXP_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall getUINTTOFP(EVT OpVT, EVT RetVT)
getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall getFREXP(EVT RetVT)
getFREXP - Return the FREXP_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit.
Libcall getMEMCPY_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize)
getMEMCPY_ELEMENT_UNORDERED_ATOMIC - Return MEMCPY_ELEMENT_UNORDERED_ATOMIC_* value for the given ele...
Libcall getFPTOUINT(EVT OpVT, EVT RetVT)
getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall getFPTOSINT(EVT OpVT, EVT RetVT)
getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall getOUTLINE_ATOMIC(unsigned Opc, AtomicOrdering Order, MVT VT)
Return the outline atomics value for the given opcode, atomic ordering and type, or UNKNOWN_LIBCALL i...
Libcall getFPEXT(EVT OpVT, EVT RetVT)
getFPEXT - Return the FPEXT_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall getFPROUND(EVT OpVT, EVT RetVT)
getFPROUND - Return the FPROUND_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall getMEMSET_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize)
getMEMSET_ELEMENT_UNORDERED_ATOMIC - Return MEMSET_ELEMENT_UNORDERED_ATOMIC_* value for the given ele...
Libcall getOutlineAtomicHelper(const Libcall(&LC)[5][4], AtomicOrdering Order, uint64_t MemSize)
Return the outline atomics value for the given atomic ordering, access size and set of libcalls for a...
Libcall getFPLibCall(EVT VT, Libcall Call_F32, Libcall Call_F64, Libcall Call_F80, Libcall Call_F128, Libcall Call_PPCF128)
GetFPLibCall - Helper to return the right libcall for the given floating point type,...
Libcall getMEMMOVE_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize)
getMEMMOVE_ELEMENT_UNORDERED_ATOMIC - Return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_* value for the given e...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition: MathExtras.h:353
EVT getApproximateEVTForLLT(LLT Ty, const DataLayout &DL, LLVMContext &Ctx)
void GetReturnInfo(CallingConv::ID CC, Type *ReturnType, AttributeList attr, SmallVectorImpl< ISD::OutputArg > &Outs, const TargetLowering &TLI, const DataLayout &DL)
Given an LLVM IR type and return type attributes, compute the return value EVTs and flags,...
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
auto enum_seq(EnumT Begin, EnumT End)
Iterate over an enum type from Begin up to - but not including - End.
Definition: Sequence.h:337
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, Align Alignment, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested.
Definition: Loads.cpp:201
bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
constexpr force_iteration_on_noniterable_enum_t force_iteration_on_noniterable_enum
Definition: Sequence.h:108
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
Definition: bit.h:342
bool isReleaseOrStronger(AtomicOrdering AO)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:291
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1736
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
AtomicOrdering
Atomic ordering for LLVM's memory model.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:403
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ FMul
Product of floats.
@ And
Bitwise or logical AND of integers.
@ Add
Sum of integers.
@ FAdd
Sum of floats.
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition: Analysis.cpp:79
bool isAcquireOrStronger(AtomicOrdering AO)
InstructionCost Cost
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Extended Value Type.
Definition: ValueTypes.h:35
EVT getPow2VectorType(LLVMContext &Context) const
Widens the length of the given vector EVT up to the nearest power of 2 and returns that type.
Definition: ValueTypes.h:463
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:137
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition: ValueTypes.h:74
ElementCount getVectorElementCount() const
Definition: ValueTypes.h:341
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:359
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
Definition: ValueTypes.h:456
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:307
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Definition: ValueTypes.h:65
bool isFixedLengthVector() const
Definition: ValueTypes.h:178
EVT getRoundIntegerType(LLVMContext &Context) const
Rounds the bit-width of the given integer EVT up to the nearest power of two (and at least to eight),...
Definition: ValueTypes.h:405
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:168
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:314
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:204
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:319
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:327
bool isZeroSized() const
Test if the given EVT has zero size, this will fail if called on a scalable type.
Definition: ValueTypes.h:132
EVT getHalfNumVectorElementsVT(LLVMContext &Context) const
Definition: ValueTypes.h:439
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:152
OutputArg - This struct carries flags and a value for a single outgoing (actual) argument or outgoing...
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...