LLVM 21.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 if (OpVT == MVT::f80)
173 return FPROUND_F80_BF16;
174 if (OpVT == MVT::f128)
175 return FPROUND_F128_BF16;
176 } else if (RetVT == MVT::f32) {
177 if (OpVT == MVT::f64)
178 return FPROUND_F64_F32;
179 if (OpVT == MVT::f80)
180 return FPROUND_F80_F32;
181 if (OpVT == MVT::f128)
182 return FPROUND_F128_F32;
183 if (OpVT == MVT::ppcf128)
184 return FPROUND_PPCF128_F32;
185 } else if (RetVT == MVT::f64) {
186 if (OpVT == MVT::f80)
187 return FPROUND_F80_F64;
188 if (OpVT == MVT::f128)
189 return FPROUND_F128_F64;
190 if (OpVT == MVT::ppcf128)
191 return FPROUND_PPCF128_F64;
192 } else if (RetVT == MVT::f80) {
193 if (OpVT == MVT::f128)
194 return FPROUND_F128_F80;
195 }
196
197 return UNKNOWN_LIBCALL;
198}
199
200/// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
201/// UNKNOWN_LIBCALL if there is none.
203 if (OpVT == MVT::f16) {
204 if (RetVT == MVT::i32)
205 return FPTOSINT_F16_I32;
206 if (RetVT == MVT::i64)
207 return FPTOSINT_F16_I64;
208 if (RetVT == MVT::i128)
209 return FPTOSINT_F16_I128;
210 } else if (OpVT == MVT::f32) {
211 if (RetVT == MVT::i32)
212 return FPTOSINT_F32_I32;
213 if (RetVT == MVT::i64)
214 return FPTOSINT_F32_I64;
215 if (RetVT == MVT::i128)
216 return FPTOSINT_F32_I128;
217 } else if (OpVT == MVT::f64) {
218 if (RetVT == MVT::i32)
219 return FPTOSINT_F64_I32;
220 if (RetVT == MVT::i64)
221 return FPTOSINT_F64_I64;
222 if (RetVT == MVT::i128)
223 return FPTOSINT_F64_I128;
224 } else if (OpVT == MVT::f80) {
225 if (RetVT == MVT::i32)
226 return FPTOSINT_F80_I32;
227 if (RetVT == MVT::i64)
228 return FPTOSINT_F80_I64;
229 if (RetVT == MVT::i128)
230 return FPTOSINT_F80_I128;
231 } else if (OpVT == MVT::f128) {
232 if (RetVT == MVT::i32)
233 return FPTOSINT_F128_I32;
234 if (RetVT == MVT::i64)
235 return FPTOSINT_F128_I64;
236 if (RetVT == MVT::i128)
237 return FPTOSINT_F128_I128;
238 } else if (OpVT == MVT::ppcf128) {
239 if (RetVT == MVT::i32)
240 return FPTOSINT_PPCF128_I32;
241 if (RetVT == MVT::i64)
242 return FPTOSINT_PPCF128_I64;
243 if (RetVT == MVT::i128)
244 return FPTOSINT_PPCF128_I128;
245 }
246 return UNKNOWN_LIBCALL;
247}
248
249/// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
250/// UNKNOWN_LIBCALL if there is none.
252 if (OpVT == MVT::f16) {
253 if (RetVT == MVT::i32)
254 return FPTOUINT_F16_I32;
255 if (RetVT == MVT::i64)
256 return FPTOUINT_F16_I64;
257 if (RetVT == MVT::i128)
258 return FPTOUINT_F16_I128;
259 } else if (OpVT == MVT::f32) {
260 if (RetVT == MVT::i32)
261 return FPTOUINT_F32_I32;
262 if (RetVT == MVT::i64)
263 return FPTOUINT_F32_I64;
264 if (RetVT == MVT::i128)
265 return FPTOUINT_F32_I128;
266 } else if (OpVT == MVT::f64) {
267 if (RetVT == MVT::i32)
268 return FPTOUINT_F64_I32;
269 if (RetVT == MVT::i64)
270 return FPTOUINT_F64_I64;
271 if (RetVT == MVT::i128)
272 return FPTOUINT_F64_I128;
273 } else if (OpVT == MVT::f80) {
274 if (RetVT == MVT::i32)
275 return FPTOUINT_F80_I32;
276 if (RetVT == MVT::i64)
277 return FPTOUINT_F80_I64;
278 if (RetVT == MVT::i128)
279 return FPTOUINT_F80_I128;
280 } else if (OpVT == MVT::f128) {
281 if (RetVT == MVT::i32)
282 return FPTOUINT_F128_I32;
283 if (RetVT == MVT::i64)
284 return FPTOUINT_F128_I64;
285 if (RetVT == MVT::i128)
286 return FPTOUINT_F128_I128;
287 } else if (OpVT == MVT::ppcf128) {
288 if (RetVT == MVT::i32)
289 return FPTOUINT_PPCF128_I32;
290 if (RetVT == MVT::i64)
291 return FPTOUINT_PPCF128_I64;
292 if (RetVT == MVT::i128)
293 return FPTOUINT_PPCF128_I128;
294 }
295 return UNKNOWN_LIBCALL;
296}
297
298/// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
299/// UNKNOWN_LIBCALL if there is none.
301 if (OpVT == MVT::i32) {
302 if (RetVT == MVT::f16)
303 return SINTTOFP_I32_F16;
304 if (RetVT == MVT::f32)
305 return SINTTOFP_I32_F32;
306 if (RetVT == MVT::f64)
307 return SINTTOFP_I32_F64;
308 if (RetVT == MVT::f80)
309 return SINTTOFP_I32_F80;
310 if (RetVT == MVT::f128)
311 return SINTTOFP_I32_F128;
312 if (RetVT == MVT::ppcf128)
313 return SINTTOFP_I32_PPCF128;
314 } else if (OpVT == MVT::i64) {
315 if (RetVT == MVT::f16)
316 return SINTTOFP_I64_F16;
317 if (RetVT == MVT::f32)
318 return SINTTOFP_I64_F32;
319 if (RetVT == MVT::f64)
320 return SINTTOFP_I64_F64;
321 if (RetVT == MVT::f80)
322 return SINTTOFP_I64_F80;
323 if (RetVT == MVT::f128)
324 return SINTTOFP_I64_F128;
325 if (RetVT == MVT::ppcf128)
326 return SINTTOFP_I64_PPCF128;
327 } else if (OpVT == MVT::i128) {
328 if (RetVT == MVT::f16)
329 return SINTTOFP_I128_F16;
330 if (RetVT == MVT::f32)
331 return SINTTOFP_I128_F32;
332 if (RetVT == MVT::f64)
333 return SINTTOFP_I128_F64;
334 if (RetVT == MVT::f80)
335 return SINTTOFP_I128_F80;
336 if (RetVT == MVT::f128)
337 return SINTTOFP_I128_F128;
338 if (RetVT == MVT::ppcf128)
339 return SINTTOFP_I128_PPCF128;
340 }
341 return UNKNOWN_LIBCALL;
342}
343
344/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
345/// UNKNOWN_LIBCALL if there is none.
347 if (OpVT == MVT::i32) {
348 if (RetVT == MVT::f16)
349 return UINTTOFP_I32_F16;
350 if (RetVT == MVT::f32)
351 return UINTTOFP_I32_F32;
352 if (RetVT == MVT::f64)
353 return UINTTOFP_I32_F64;
354 if (RetVT == MVT::f80)
355 return UINTTOFP_I32_F80;
356 if (RetVT == MVT::f128)
357 return UINTTOFP_I32_F128;
358 if (RetVT == MVT::ppcf128)
359 return UINTTOFP_I32_PPCF128;
360 } else if (OpVT == MVT::i64) {
361 if (RetVT == MVT::f16)
362 return UINTTOFP_I64_F16;
363 if (RetVT == MVT::f32)
364 return UINTTOFP_I64_F32;
365 if (RetVT == MVT::f64)
366 return UINTTOFP_I64_F64;
367 if (RetVT == MVT::f80)
368 return UINTTOFP_I64_F80;
369 if (RetVT == MVT::f128)
370 return UINTTOFP_I64_F128;
371 if (RetVT == MVT::ppcf128)
372 return UINTTOFP_I64_PPCF128;
373 } else if (OpVT == MVT::i128) {
374 if (RetVT == MVT::f16)
375 return UINTTOFP_I128_F16;
376 if (RetVT == MVT::f32)
377 return UINTTOFP_I128_F32;
378 if (RetVT == MVT::f64)
379 return UINTTOFP_I128_F64;
380 if (RetVT == MVT::f80)
381 return UINTTOFP_I128_F80;
382 if (RetVT == MVT::f128)
383 return UINTTOFP_I128_F128;
384 if (RetVT == MVT::ppcf128)
385 return UINTTOFP_I128_PPCF128;
386 }
387 return UNKNOWN_LIBCALL;
388}
389
391 return getFPLibCall(RetVT, POWI_F32, POWI_F64, POWI_F80, POWI_F128,
392 POWI_PPCF128);
393}
394
396 return getFPLibCall(RetVT, LDEXP_F32, LDEXP_F64, LDEXP_F80, LDEXP_F128,
397 LDEXP_PPCF128);
398}
399
401 return getFPLibCall(RetVT, FREXP_F32, FREXP_F64, FREXP_F80, FREXP_F128,
402 FREXP_PPCF128);
403}
404
406 return getFPLibCall(RetVT, SINCOS_F32, SINCOS_F64, SINCOS_F80, SINCOS_F128,
407 SINCOS_PPCF128);
408}
409
411 return getFPLibCall(RetVT, SINCOSPI_F32, SINCOSPI_F64, SINCOSPI_F80,
412 SINCOSPI_F128, SINCOSPI_PPCF128);
413}
414
416 return getFPLibCall(RetVT, MODF_F32, MODF_F64, MODF_F80, MODF_F128,
417 MODF_PPCF128);
418}
419
421 AtomicOrdering Order,
422 uint64_t MemSize) {
423 unsigned ModeN, ModelN;
424 switch (MemSize) {
425 case 1:
426 ModeN = 0;
427 break;
428 case 2:
429 ModeN = 1;
430 break;
431 case 4:
432 ModeN = 2;
433 break;
434 case 8:
435 ModeN = 3;
436 break;
437 case 16:
438 ModeN = 4;
439 break;
440 default:
441 return RTLIB::UNKNOWN_LIBCALL;
442 }
443
444 switch (Order) {
445 case AtomicOrdering::Monotonic:
446 ModelN = 0;
447 break;
448 case AtomicOrdering::Acquire:
449 ModelN = 1;
450 break;
451 case AtomicOrdering::Release:
452 ModelN = 2;
453 break;
454 case AtomicOrdering::AcquireRelease:
455 case AtomicOrdering::SequentiallyConsistent:
456 ModelN = 3;
457 break;
458 default:
459 return UNKNOWN_LIBCALL;
460 }
461
462 return LC[ModeN][ModelN];
463}
464
466 MVT VT) {
467 if (!VT.isScalarInteger())
468 return UNKNOWN_LIBCALL;
469 uint64_t MemSize = VT.getScalarSizeInBits() / 8;
470
471#define LCALLS(A, B) \
472 { A##B##_RELAX, A##B##_ACQ, A##B##_REL, A##B##_ACQ_REL }
473#define LCALL5(A) \
474 LCALLS(A, 1), LCALLS(A, 2), LCALLS(A, 4), LCALLS(A, 8), LCALLS(A, 16)
475 switch (Opc) {
477 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_CAS)};
478 return getOutlineAtomicHelper(LC, Order, MemSize);
479 }
480 case ISD::ATOMIC_SWAP: {
481 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_SWP)};
482 return getOutlineAtomicHelper(LC, Order, MemSize);
483 }
485 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDADD)};
486 return getOutlineAtomicHelper(LC, Order, MemSize);
487 }
488 case ISD::ATOMIC_LOAD_OR: {
489 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDSET)};
490 return getOutlineAtomicHelper(LC, Order, MemSize);
491 }
493 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDCLR)};
494 return getOutlineAtomicHelper(LC, Order, MemSize);
495 }
497 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDEOR)};
498 return getOutlineAtomicHelper(LC, Order, MemSize);
499 }
500 default:
501 return UNKNOWN_LIBCALL;
502 }
503#undef LCALLS
504#undef LCALL5
505}
506
508#define OP_TO_LIBCALL(Name, Enum) \
509 case Name: \
510 switch (VT.SimpleTy) { \
511 default: \
512 return UNKNOWN_LIBCALL; \
513 case MVT::i8: \
514 return Enum##_1; \
515 case MVT::i16: \
516 return Enum##_2; \
517 case MVT::i32: \
518 return Enum##_4; \
519 case MVT::i64: \
520 return Enum##_8; \
521 case MVT::i128: \
522 return Enum##_16; \
523 }
524
525 switch (Opc) {
526 OP_TO_LIBCALL(ISD::ATOMIC_SWAP, SYNC_LOCK_TEST_AND_SET)
527 OP_TO_LIBCALL(ISD::ATOMIC_CMP_SWAP, SYNC_VAL_COMPARE_AND_SWAP)
528 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_ADD, SYNC_FETCH_AND_ADD)
529 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_SUB, SYNC_FETCH_AND_SUB)
530 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_AND, SYNC_FETCH_AND_AND)
531 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_OR, SYNC_FETCH_AND_OR)
532 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_XOR, SYNC_FETCH_AND_XOR)
533 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_NAND, SYNC_FETCH_AND_NAND)
534 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MAX, SYNC_FETCH_AND_MAX)
535 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMAX, SYNC_FETCH_AND_UMAX)
536 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MIN, SYNC_FETCH_AND_MIN)
537 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMIN, SYNC_FETCH_AND_UMIN)
538 }
539
540#undef OP_TO_LIBCALL
541
542 return UNKNOWN_LIBCALL;
543}
544
546 switch (ElementSize) {
547 case 1:
548 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_1;
549 case 2:
550 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_2;
551 case 4:
552 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_4;
553 case 8:
554 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_8;
555 case 16:
556 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_16;
557 default:
558 return UNKNOWN_LIBCALL;
559 }
560}
561
563 switch (ElementSize) {
564 case 1:
565 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_1;
566 case 2:
567 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_2;
568 case 4:
569 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_4;
570 case 8:
571 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_8;
572 case 16:
573 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_16;
574 default:
575 return UNKNOWN_LIBCALL;
576 }
577}
578
580 switch (ElementSize) {
581 case 1:
582 return MEMSET_ELEMENT_UNORDERED_ATOMIC_1;
583 case 2:
584 return MEMSET_ELEMENT_UNORDERED_ATOMIC_2;
585 case 4:
586 return MEMSET_ELEMENT_UNORDERED_ATOMIC_4;
587 case 8:
588 return MEMSET_ELEMENT_UNORDERED_ATOMIC_8;
589 case 16:
590 return MEMSET_ELEMENT_UNORDERED_ATOMIC_16;
591 default:
592 return UNKNOWN_LIBCALL;
593 }
594}
595
597 std::fill(CmpLibcallCCs, CmpLibcallCCs + RTLIB::UNKNOWN_LIBCALL,
599 CmpLibcallCCs[RTLIB::OEQ_F32] = ISD::SETEQ;
600 CmpLibcallCCs[RTLIB::OEQ_F64] = ISD::SETEQ;
601 CmpLibcallCCs[RTLIB::OEQ_F128] = ISD::SETEQ;
602 CmpLibcallCCs[RTLIB::OEQ_PPCF128] = ISD::SETEQ;
603 CmpLibcallCCs[RTLIB::UNE_F32] = ISD::SETNE;
604 CmpLibcallCCs[RTLIB::UNE_F64] = ISD::SETNE;
605 CmpLibcallCCs[RTLIB::UNE_F128] = ISD::SETNE;
606 CmpLibcallCCs[RTLIB::UNE_PPCF128] = ISD::SETNE;
607 CmpLibcallCCs[RTLIB::OGE_F32] = ISD::SETGE;
608 CmpLibcallCCs[RTLIB::OGE_F64] = ISD::SETGE;
609 CmpLibcallCCs[RTLIB::OGE_F128] = ISD::SETGE;
610 CmpLibcallCCs[RTLIB::OGE_PPCF128] = ISD::SETGE;
611 CmpLibcallCCs[RTLIB::OLT_F32] = ISD::SETLT;
612 CmpLibcallCCs[RTLIB::OLT_F64] = ISD::SETLT;
613 CmpLibcallCCs[RTLIB::OLT_F128] = ISD::SETLT;
614 CmpLibcallCCs[RTLIB::OLT_PPCF128] = ISD::SETLT;
615 CmpLibcallCCs[RTLIB::OLE_F32] = ISD::SETLE;
616 CmpLibcallCCs[RTLIB::OLE_F64] = ISD::SETLE;
617 CmpLibcallCCs[RTLIB::OLE_F128] = ISD::SETLE;
618 CmpLibcallCCs[RTLIB::OLE_PPCF128] = ISD::SETLE;
619 CmpLibcallCCs[RTLIB::OGT_F32] = ISD::SETGT;
620 CmpLibcallCCs[RTLIB::OGT_F64] = ISD::SETGT;
621 CmpLibcallCCs[RTLIB::OGT_F128] = ISD::SETGT;
622 CmpLibcallCCs[RTLIB::OGT_PPCF128] = ISD::SETGT;
623 CmpLibcallCCs[RTLIB::UO_F32] = ISD::SETNE;
624 CmpLibcallCCs[RTLIB::UO_F64] = ISD::SETNE;
625 CmpLibcallCCs[RTLIB::UO_F128] = ISD::SETNE;
626 CmpLibcallCCs[RTLIB::UO_PPCF128] = ISD::SETNE;
627}
628
629/// NOTE: The TargetMachine owns TLOF.
631 : TM(tm), Libcalls(TM.getTargetTriple()) {
632 initActions();
633
634 // Perform these initializations only once.
640 HasMultipleConditionRegisters = false;
641 HasExtractBitsInsn = false;
642 JumpIsExpensive = JumpIsExpensiveOverride;
644 EnableExtLdPromotion = false;
645 StackPointerRegisterToSaveRestore = 0;
646 BooleanContents = UndefinedBooleanContent;
647 BooleanFloatContents = UndefinedBooleanContent;
648 BooleanVectorContents = UndefinedBooleanContent;
649 SchedPreferenceInfo = Sched::ILP;
652 MaxBytesForAlignment = 0;
653 MaxAtomicSizeInBitsSupported = 0;
654
655 // Assume that even with libcalls, no target supports wider than 128 bit
656 // division.
657 MaxDivRemBitWidthSupported = 128;
658
659 MaxLargeFPConvertBitWidthSupported = llvm::IntegerType::MAX_INT_BITS;
660
661 MinCmpXchgSizeInBits = 0;
662 SupportsUnalignedAtomics = false;
663
664 RTLIB::initCmpLibcallCCs(CmpLibcallCCs);
665}
666
668 // All operations default to being supported.
669 memset(OpActions, 0, sizeof(OpActions));
670 memset(LoadExtActions, 0, sizeof(LoadExtActions));
671 memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
672 memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
673 memset(CondCodeActions, 0, sizeof(CondCodeActions));
674 std::fill(std::begin(RegClassForVT), std::end(RegClassForVT), nullptr);
675 std::fill(std::begin(TargetDAGCombineArray),
676 std::end(TargetDAGCombineArray), 0);
677
678 // Let extending atomic loads be unsupported by default.
679 for (MVT ValVT : MVT::all_valuetypes())
680 for (MVT MemVT : MVT::all_valuetypes())
682 Expand);
683
684 // We're somewhat special casing MVT::i2 and MVT::i4. Ideally we want to
685 // remove this and targets should individually set these types if not legal.
688 for (MVT VT : {MVT::i2, MVT::i4})
689 OpActions[(unsigned)VT.SimpleTy][NT] = Expand;
690 }
691 for (MVT AVT : MVT::all_valuetypes()) {
692 for (MVT VT : {MVT::i2, MVT::i4, MVT::v128i2, MVT::v64i4}) {
693 setTruncStoreAction(AVT, VT, Expand);
696 }
697 }
698 for (unsigned IM = (unsigned)ISD::PRE_INC;
699 IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
700 for (MVT VT : {MVT::i2, MVT::i4}) {
705 }
706 }
707
708 for (MVT VT : MVT::fp_valuetypes()) {
709 MVT IntVT = MVT::getIntegerVT(VT.getFixedSizeInBits());
710 if (IntVT.isValid()) {
713 }
714 }
715
716 // Set default actions for various operations.
717 for (MVT VT : MVT::all_valuetypes()) {
718 // Default all indexed load / store to expand.
719 for (unsigned IM = (unsigned)ISD::PRE_INC;
720 IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
725 }
726
727 // Most backends expect to see the node which just returns the value loaded.
729
730 // These operations default to expand.
749 VT, Expand);
750
751 // Overflow operations default to expand
754 VT, Expand);
755
756 // Carry-using overflow operations default to expand.
759 VT, Expand);
760
761 // ADDC/ADDE/SUBC/SUBE default to expand.
763 Expand);
764
765 // [US]CMP default to expand
767
768 // Halving adds
771 Expand);
772
773 // Absolute difference
775
776 // Saturated trunc
780
781 // These default to Expand so they will be expanded to CTLZ/CTTZ by default.
783 Expand);
784
786
787 // These library functions default to expand.
790 VT, Expand);
791
792 // These operations default to expand for vector types.
793 if (VT.isVector())
800 VT, Expand);
801
802 // Constrained floating-point operations default to expand.
803#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
804 setOperationAction(ISD::STRICT_##DAGN, VT, Expand);
805#include "llvm/IR/ConstrainedOps.def"
806
807 // For most targets @llvm.get.dynamic.area.offset just returns 0.
809
810 // Vector reduction default to expand.
818 VT, Expand);
819
820 // Named vector shuffles default to expand.
822
823 // Only some target support this vector operation. Most need to expand it.
825
826 // VP operations default to expand.
827#define BEGIN_REGISTER_VP_SDNODE(SDOPC, ...) \
828 setOperationAction(ISD::SDOPC, VT, Expand);
829#include "llvm/IR/VPIntrinsics.def"
830
831 // Masked vector extracts default to expand.
833
834 // FP environment operations default to expand.
838 }
839
840 // Most targets ignore the @llvm.prefetch intrinsic.
842
843 // Most targets also ignore the @llvm.readcyclecounter intrinsic.
845
846 // Most targets also ignore the @llvm.readsteadycounter intrinsic.
848
849 // ConstantFP nodes default to expand. Targets can either change this to
850 // Legal, in which case all fp constants are legal, or use isFPImmLegal()
851 // to optimize expansions for certain constants.
853 {MVT::bf16, MVT::f16, MVT::f32, MVT::f64, MVT::f80, MVT::f128},
854 Expand);
855
856 // These library functions default to expand.
863 {MVT::f32, MVT::f64, MVT::f128}, Expand);
864
865 // FIXME: Query RuntimeLibCalls to make the decision.
867 {MVT::f32, MVT::f64, MVT::f128}, LibCall);
868
871 MVT::f16, Promote);
872 // Default ISD::TRAP to expand (which turns it into abort).
873 setOperationAction(ISD::TRAP, MVT::Other, Expand);
874
875 // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand"
876 // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP.
878
880
883
884 for (MVT VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64}) {
887 }
889
890 // This one by default will call __clear_cache unless the target
891 // wants something different.
893}
894
896 EVT) const {
897 return MVT::getIntegerVT(DL.getPointerSizeInBits(0));
898}
899
901 const DataLayout &DL) const {
902 assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
903 if (LHSTy.isVector())
904 return LHSTy;
905 MVT ShiftVT = getScalarShiftAmountTy(DL, LHSTy);
906 // If any possible shift value won't fit in the prefered type, just use
907 // something safe. Assume it will be legalized when the shift is expanded.
908 if (ShiftVT.getSizeInBits() < Log2_32_Ceil(LHSTy.getSizeInBits()))
909 ShiftVT = MVT::i32;
910 assert(ShiftVT.getSizeInBits() >= Log2_32_Ceil(LHSTy.getSizeInBits()) &&
911 "ShiftVT is still too small!");
912 return ShiftVT;
913}
914
915bool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
916 assert(isTypeLegal(VT));
917 switch (Op) {
918 default:
919 return false;
920 case ISD::SDIV:
921 case ISD::UDIV:
922 case ISD::SREM:
923 case ISD::UREM:
924 return true;
925 }
926}
927
929 unsigned DestAS) const {
930 return TM.isNoopAddrSpaceCast(SrcAS, DestAS);
931}
932
934 Type *RetTy, ElementCount EC, bool ZeroIsPoison,
935 const ConstantRange *VScaleRange) const {
936 // Find the smallest "sensible" element type to use for the expansion.
937 ConstantRange CR(APInt(64, EC.getKnownMinValue()));
938 if (EC.isScalable())
939 CR = CR.umul_sat(*VScaleRange);
940
941 if (ZeroIsPoison)
942 CR = CR.subtract(APInt(64, 1));
943
944 unsigned EltWidth = RetTy->getScalarSizeInBits();
945 EltWidth = std::min(EltWidth, (unsigned)CR.getActiveBits());
946 EltWidth = std::max(llvm::bit_ceil(EltWidth), (unsigned)8);
947
948 return EltWidth;
949}
950
952 // If the command-line option was specified, ignore this request.
954 JumpIsExpensive = isExpensive;
955}
956
959 // If this is a simple type, use the ComputeRegisterProp mechanism.
960 if (VT.isSimple()) {
961 MVT SVT = VT.getSimpleVT();
962 assert((unsigned)SVT.SimpleTy < std::size(TransformToType));
963 MVT NVT = TransformToType[SVT.SimpleTy];
964 LegalizeTypeAction LA = ValueTypeActions.getTypeAction(SVT);
965
966 assert((LA == TypeLegal || LA == TypeSoftenFloat ||
967 LA == TypeSoftPromoteHalf ||
968 (NVT.isVector() ||
969 ValueTypeActions.getTypeAction(NVT) != TypePromoteInteger)) &&
970 "Promote may not follow Expand or Promote");
971
972 if (LA == TypeSplitVector)
973 return LegalizeKind(LA, EVT(SVT).getHalfNumVectorElementsVT(Context));
974 if (LA == TypeScalarizeVector)
975 return LegalizeKind(LA, SVT.getVectorElementType());
976 return LegalizeKind(LA, NVT);
977 }
978
979 // Handle Extended Scalar Types.
980 if (!VT.isVector()) {
981 assert(VT.isInteger() && "Float types must be simple");
982 unsigned BitSize = VT.getSizeInBits();
983 // First promote to a power-of-two size, then expand if necessary.
984 if (BitSize < 8 || !isPowerOf2_32(BitSize)) {
985 EVT NVT = VT.getRoundIntegerType(Context);
986 assert(NVT != VT && "Unable to round integer VT");
987 LegalizeKind NextStep = getTypeConversion(Context, NVT);
988 // Avoid multi-step promotion.
989 if (NextStep.first == TypePromoteInteger)
990 return NextStep;
991 // Return rounded integer type.
992 return LegalizeKind(TypePromoteInteger, NVT);
993 }
994
996 EVT::getIntegerVT(Context, VT.getSizeInBits() / 2));
997 }
998
999 // Handle vector types.
1000 ElementCount NumElts = VT.getVectorElementCount();
1001 EVT EltVT = VT.getVectorElementType();
1002
1003 // Vectors with only one element are always scalarized.
1004 if (NumElts.isScalar())
1005 return LegalizeKind(TypeScalarizeVector, EltVT);
1006
1007 // Try to widen vector elements until the element type is a power of two and
1008 // promote it to a legal type later on, for example:
1009 // <3 x i8> -> <4 x i8> -> <4 x i32>
1010 if (EltVT.isInteger()) {
1011 // Vectors with a number of elements that is not a power of two are always
1012 // widened, for example <3 x i8> -> <4 x i8>.
1013 if (!VT.isPow2VectorType()) {
1014 NumElts = NumElts.coefficientNextPowerOf2();
1015 EVT NVT = EVT::getVectorVT(Context, EltVT, NumElts);
1016 return LegalizeKind(TypeWidenVector, NVT);
1017 }
1018
1019 // Examine the element type.
1020 LegalizeKind LK = getTypeConversion(Context, EltVT);
1021
1022 // If type is to be expanded, split the vector.
1023 // <4 x i140> -> <2 x i140>
1024 if (LK.first == TypeExpandInteger) {
1028 VT.getHalfNumVectorElementsVT(Context));
1029 }
1030
1031 // Promote the integer element types until a legal vector type is found
1032 // or until the element integer type is too big. If a legal type was not
1033 // found, fallback to the usual mechanism of widening/splitting the
1034 // vector.
1035 EVT OldEltVT = EltVT;
1036 while (true) {
1037 // Increase the bitwidth of the element to the next pow-of-two
1038 // (which is greater than 8 bits).
1039 EltVT = EVT::getIntegerVT(Context, 1 + EltVT.getSizeInBits())
1040 .getRoundIntegerType(Context);
1041
1042 // Stop trying when getting a non-simple element type.
1043 // Note that vector elements may be greater than legal vector element
1044 // types. Example: X86 XMM registers hold 64bit element on 32bit
1045 // systems.
1046 if (!EltVT.isSimple())
1047 break;
1048
1049 // Build a new vector type and check if it is legal.
1050 MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1051 // Found a legal promoted vector type.
1052 if (NVT != MVT() && ValueTypeActions.getTypeAction(NVT) == TypeLegal)
1054 EVT::getVectorVT(Context, EltVT, NumElts));
1055 }
1056
1057 // Reset the type to the unexpanded type if we did not find a legal vector
1058 // type with a promoted vector element type.
1059 EltVT = OldEltVT;
1060 }
1061
1062 // Try to widen the vector until a legal type is found.
1063 // If there is no wider legal type, split the vector.
1064 while (true) {
1065 // Round up to the next power of 2.
1066 NumElts = NumElts.coefficientNextPowerOf2();
1067
1068 // If there is no simple vector type with this many elements then there
1069 // cannot be a larger legal vector type. Note that this assumes that
1070 // there are no skipped intermediate vector types in the simple types.
1071 if (!EltVT.isSimple())
1072 break;
1073 MVT LargerVector = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1074 if (LargerVector == MVT())
1075 break;
1076
1077 // If this type is legal then widen the vector.
1078 if (ValueTypeActions.getTypeAction(LargerVector) == TypeLegal)
1079 return LegalizeKind(TypeWidenVector, LargerVector);
1080 }
1081
1082 // Widen odd vectors to next power of two.
1083 if (!VT.isPow2VectorType()) {
1084 EVT NVT = VT.getPow2VectorType(Context);
1085 return LegalizeKind(TypeWidenVector, NVT);
1086 }
1087
1090
1091 // Vectors with illegal element types are expanded.
1092 EVT NVT = EVT::getVectorVT(Context, EltVT,
1094 return LegalizeKind(TypeSplitVector, NVT);
1095}
1096
1097static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
1098 unsigned &NumIntermediates,
1099 MVT &RegisterVT,
1100 TargetLoweringBase *TLI) {
1101 // Figure out the right, legal destination reg to copy into.
1103 MVT EltTy = VT.getVectorElementType();
1104
1105 unsigned NumVectorRegs = 1;
1106
1107 // Scalable vectors cannot be scalarized, so splitting or widening is
1108 // required.
1109 if (VT.isScalableVector() && !isPowerOf2_32(EC.getKnownMinValue()))
1111 "Splitting or widening of non-power-of-2 MVTs is not implemented.");
1112
1113 // FIXME: We don't support non-power-of-2-sized vectors for now.
1114 // Ideally we could break down into LHS/RHS like LegalizeDAG does.
1115 if (!isPowerOf2_32(EC.getKnownMinValue())) {
1116 // Split EC to unit size (scalable property is preserved).
1117 NumVectorRegs = EC.getKnownMinValue();
1118 EC = ElementCount::getFixed(1);
1119 }
1120
1121 // Divide the input until we get to a supported size. This will
1122 // always end up with an EC that represent a scalar or a scalable
1123 // scalar.
1124 while (EC.getKnownMinValue() > 1 &&
1125 !TLI->isTypeLegal(MVT::getVectorVT(EltTy, EC))) {
1126 EC = EC.divideCoefficientBy(2);
1127 NumVectorRegs <<= 1;
1128 }
1129
1130 NumIntermediates = NumVectorRegs;
1131
1132 MVT NewVT = MVT::getVectorVT(EltTy, EC);
1133 if (!TLI->isTypeLegal(NewVT))
1134 NewVT = EltTy;
1135 IntermediateVT = NewVT;
1136
1137 unsigned LaneSizeInBits = NewVT.getScalarSizeInBits();
1138
1139 // Convert sizes such as i33 to i64.
1140 LaneSizeInBits = llvm::bit_ceil(LaneSizeInBits);
1141
1142 MVT DestVT = TLI->getRegisterType(NewVT);
1143 RegisterVT = DestVT;
1144 if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16.
1145 return NumVectorRegs * (LaneSizeInBits / DestVT.getScalarSizeInBits());
1146
1147 // Otherwise, promotion or legal types use the same number of registers as
1148 // the vector decimated to the appropriate level.
1149 return NumVectorRegs;
1150}
1151
1152/// isLegalRC - Return true if the value types that can be represented by the
1153/// specified register class are all legal.
1155 const TargetRegisterClass &RC) const {
1156 for (const auto *I = TRI.legalclasstypes_begin(RC); *I != MVT::Other; ++I)
1157 if (isTypeLegal(*I))
1158 return true;
1159 return false;
1160}
1161
1162/// Replace/modify any TargetFrameIndex operands with a targte-dependent
1163/// sequence of memory operands that is recognized by PrologEpilogInserter.
1166 MachineBasicBlock *MBB) const {
1167 MachineInstr *MI = &InitialMI;
1168 MachineFunction &MF = *MI->getMF();
1169 MachineFrameInfo &MFI = MF.getFrameInfo();
1170
1171 // We're handling multiple types of operands here:
1172 // PATCHPOINT MetaArgs - live-in, read only, direct
1173 // STATEPOINT Deopt Spill - live-through, read only, indirect
1174 // STATEPOINT Deopt Alloca - live-through, read only, direct
1175 // (We're currently conservative and mark the deopt slots read/write in
1176 // practice.)
1177 // STATEPOINT GC Spill - live-through, read/write, indirect
1178 // STATEPOINT GC Alloca - live-through, read/write, direct
1179 // The live-in vs live-through is handled already (the live through ones are
1180 // all stack slots), but we need to handle the different type of stackmap
1181 // operands and memory effects here.
1182
1183 if (llvm::none_of(MI->operands(),
1184 [](MachineOperand &Operand) { return Operand.isFI(); }))
1185 return MBB;
1186
1187 MachineInstrBuilder MIB = BuildMI(MF, MI->getDebugLoc(), MI->getDesc());
1188
1189 // Inherit previous memory operands.
1190 MIB.cloneMemRefs(*MI);
1191
1192 for (unsigned i = 0; i < MI->getNumOperands(); ++i) {
1193 MachineOperand &MO = MI->getOperand(i);
1194 if (!MO.isFI()) {
1195 // Index of Def operand this Use it tied to.
1196 // Since Defs are coming before Uses, if Use is tied, then
1197 // index of Def must be smaller that index of that Use.
1198 // Also, Defs preserve their position in new MI.
1199 unsigned TiedTo = i;
1200 if (MO.isReg() && MO.isTied())
1201 TiedTo = MI->findTiedOperandIdx(i);
1202 MIB.add(MO);
1203 if (TiedTo < i)
1204 MIB->tieOperands(TiedTo, MIB->getNumOperands() - 1);
1205 continue;
1206 }
1207
1208 // foldMemoryOperand builds a new MI after replacing a single FI operand
1209 // with the canonical set of five x86 addressing-mode operands.
1210 int FI = MO.getIndex();
1211
1212 // Add frame index operands recognized by stackmaps.cpp
1214 // indirect-mem-ref tag, size, #FI, offset.
1215 // Used for spills inserted by StatepointLowering. This codepath is not
1216 // used for patchpoints/stackmaps at all, for these spilling is done via
1217 // foldMemoryOperand callback only.
1218 assert(MI->getOpcode() == TargetOpcode::STATEPOINT && "sanity");
1219 MIB.addImm(StackMaps::IndirectMemRefOp);
1220 MIB.addImm(MFI.getObjectSize(FI));
1221 MIB.add(MO);
1222 MIB.addImm(0);
1223 } else {
1224 // direct-mem-ref tag, #FI, offset.
1225 // Used by patchpoint, and direct alloca arguments to statepoints
1226 MIB.addImm(StackMaps::DirectMemRefOp);
1227 MIB.add(MO);
1228 MIB.addImm(0);
1229 }
1230
1231 assert(MIB->mayLoad() && "Folded a stackmap use to a non-load!");
1232
1233 // Add a new memory operand for this FI.
1234 assert(MFI.getObjectOffset(FI) != -1);
1235
1236 // Note: STATEPOINT MMOs are added during SelectionDAG. STACKMAP, and
1237 // PATCHPOINT should be updated to do the same. (TODO)
1238 if (MI->getOpcode() != TargetOpcode::STATEPOINT) {
1239 auto Flags = MachineMemOperand::MOLoad;
1241 MachinePointerInfo::getFixedStack(MF, FI), Flags,
1243 MIB->addMemOperand(MF, MMO);
1244 }
1245 }
1247 MI->eraseFromParent();
1248 return MBB;
1249}
1250
1251/// findRepresentativeClass - Return the largest legal super-reg register class
1252/// of the register class for the specified type and its associated "cost".
1253// This function is in TargetLowering because it uses RegClassForVT which would
1254// need to be moved to TargetRegisterInfo and would necessitate moving
1255// isTypeLegal over as well - a massive change that would just require
1256// TargetLowering having a TargetRegisterInfo class member that it would use.
1257std::pair<const TargetRegisterClass *, uint8_t>
1259 MVT VT) const {
1260 const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
1261 if (!RC)
1262 return std::make_pair(RC, 0);
1263
1264 // Compute the set of all super-register classes.
1265 BitVector SuperRegRC(TRI->getNumRegClasses());
1266 for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI)
1267 SuperRegRC.setBitsInMask(RCI.getMask());
1268
1269 // Find the first legal register class with the largest spill size.
1270 const TargetRegisterClass *BestRC = RC;
1271 for (unsigned i : SuperRegRC.set_bits()) {
1272 const TargetRegisterClass *SuperRC = TRI->getRegClass(i);
1273 // We want the largest possible spill size.
1274 if (TRI->getSpillSize(*SuperRC) <= TRI->getSpillSize(*BestRC))
1275 continue;
1276 if (!isLegalRC(*TRI, *SuperRC))
1277 continue;
1278 BestRC = SuperRC;
1279 }
1280 return std::make_pair(BestRC, 1);
1281}
1282
1283/// computeRegisterProperties - Once all of the register classes are added,
1284/// this allows us to compute derived properties we expose.
1286 const TargetRegisterInfo *TRI) {
1287 // Everything defaults to needing one register.
1288 for (unsigned i = 0; i != MVT::VALUETYPE_SIZE; ++i) {
1289 NumRegistersForVT[i] = 1;
1290 RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i;
1291 }
1292 // ...except isVoid, which doesn't need any registers.
1293 NumRegistersForVT[MVT::isVoid] = 0;
1294
1295 // Find the largest integer register class.
1296 unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE;
1297 for (; RegClassForVT[LargestIntReg] == nullptr; --LargestIntReg)
1298 assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
1299
1300 // Every integer value type larger than this largest register takes twice as
1301 // many registers to represent as the previous ValueType.
1302 for (unsigned ExpandedReg = LargestIntReg + 1;
1303 ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) {
1304 NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1];
1305 RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg;
1306 TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1);
1307 ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg,
1309 }
1310
1311 // Inspect all of the ValueType's smaller than the largest integer
1312 // register to see which ones need promotion.
1313 unsigned LegalIntReg = LargestIntReg;
1314 for (unsigned IntReg = LargestIntReg - 1;
1315 IntReg >= (unsigned)MVT::i1; --IntReg) {
1316 MVT IVT = (MVT::SimpleValueType)IntReg;
1317 if (isTypeLegal(IVT)) {
1318 LegalIntReg = IntReg;
1319 } else {
1320 RegisterTypeForVT[IntReg] = TransformToType[IntReg] =
1321 (MVT::SimpleValueType)LegalIntReg;
1322 ValueTypeActions.setTypeAction(IVT, TypePromoteInteger);
1323 }
1324 }
1325
1326 // ppcf128 type is really two f64's.
1327 if (!isTypeLegal(MVT::ppcf128)) {
1328 if (isTypeLegal(MVT::f64)) {
1329 NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64];
1330 RegisterTypeForVT[MVT::ppcf128] = MVT::f64;
1331 TransformToType[MVT::ppcf128] = MVT::f64;
1332 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat);
1333 } else {
1334 NumRegistersForVT[MVT::ppcf128] = NumRegistersForVT[MVT::i128];
1335 RegisterTypeForVT[MVT::ppcf128] = RegisterTypeForVT[MVT::i128];
1336 TransformToType[MVT::ppcf128] = MVT::i128;
1337 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeSoftenFloat);
1338 }
1339 }
1340
1341 // Decide how to handle f128. If the target does not have native f128 support,
1342 // expand it to i128 and we will be generating soft float library calls.
1343 if (!isTypeLegal(MVT::f128)) {
1344 NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128];
1345 RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128];
1346 TransformToType[MVT::f128] = MVT::i128;
1347 ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat);
1348 }
1349
1350 // Decide how to handle f80. If the target does not have native f80 support,
1351 // expand it to i96 and we will be generating soft float library calls.
1352 if (!isTypeLegal(MVT::f80)) {
1353 NumRegistersForVT[MVT::f80] = 3*NumRegistersForVT[MVT::i32];
1354 RegisterTypeForVT[MVT::f80] = RegisterTypeForVT[MVT::i32];
1355 TransformToType[MVT::f80] = MVT::i32;
1356 ValueTypeActions.setTypeAction(MVT::f80, TypeSoftenFloat);
1357 }
1358
1359 // Decide how to handle f64. If the target does not have native f64 support,
1360 // expand it to i64 and we will be generating soft float library calls.
1361 if (!isTypeLegal(MVT::f64)) {
1362 NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64];
1363 RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64];
1364 TransformToType[MVT::f64] = MVT::i64;
1365 ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat);
1366 }
1367
1368 // Decide how to handle f32. If the target does not have native f32 support,
1369 // expand it to i32 and we will be generating soft float library calls.
1370 if (!isTypeLegal(MVT::f32)) {
1371 NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32];
1372 RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32];
1373 TransformToType[MVT::f32] = MVT::i32;
1374 ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat);
1375 }
1376
1377 // Decide how to handle f16. If the target does not have native f16 support,
1378 // promote it to f32, because there are no f16 library calls (except for
1379 // conversions).
1380 if (!isTypeLegal(MVT::f16)) {
1381 // Allow targets to control how we legalize half.
1382 bool SoftPromoteHalfType = softPromoteHalfType();
1383 bool UseFPRegsForHalfType = !SoftPromoteHalfType || useFPRegsForHalfType();
1384
1385 if (!UseFPRegsForHalfType) {
1386 NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::i16];
1387 RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::i16];
1388 } else {
1389 NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::f32];
1390 RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::f32];
1391 }
1392 TransformToType[MVT::f16] = MVT::f32;
1393 if (SoftPromoteHalfType) {
1394 ValueTypeActions.setTypeAction(MVT::f16, TypeSoftPromoteHalf);
1395 } else {
1396 ValueTypeActions.setTypeAction(MVT::f16, TypePromoteFloat);
1397 }
1398 }
1399
1400 // Decide how to handle bf16. If the target does not have native bf16 support,
1401 // promote it to f32, because there are no bf16 library calls (except for
1402 // converting from f32 to bf16).
1403 if (!isTypeLegal(MVT::bf16)) {
1404 NumRegistersForVT[MVT::bf16] = NumRegistersForVT[MVT::f32];
1405 RegisterTypeForVT[MVT::bf16] = RegisterTypeForVT[MVT::f32];
1406 TransformToType[MVT::bf16] = MVT::f32;
1407 ValueTypeActions.setTypeAction(MVT::bf16, TypeSoftPromoteHalf);
1408 }
1409
1410 // Loop over all of the vector value types to see which need transformations.
1411 for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE;
1412 i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
1413 MVT VT = (MVT::SimpleValueType) i;
1414 if (isTypeLegal(VT))
1415 continue;
1416
1417 MVT EltVT = VT.getVectorElementType();
1419 bool IsLegalWiderType = false;
1420 bool IsScalable = VT.isScalableVector();
1421 LegalizeTypeAction PreferredAction = getPreferredVectorAction(VT);
1422 switch (PreferredAction) {
1423 case TypePromoteInteger: {
1424 MVT::SimpleValueType EndVT = IsScalable ?
1425 MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE :
1426 MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE;
1427 // Try to promote the elements of integer vectors. If no legal
1428 // promotion was found, fall through to the widen-vector method.
1429 for (unsigned nVT = i + 1;
1430 (MVT::SimpleValueType)nVT <= EndVT; ++nVT) {
1431 MVT SVT = (MVT::SimpleValueType) nVT;
1432 // Promote vectors of integers to vectors with the same number
1433 // of elements, with a wider element type.
1434 if (SVT.getScalarSizeInBits() > EltVT.getFixedSizeInBits() &&
1435 SVT.getVectorElementCount() == EC && isTypeLegal(SVT)) {
1436 TransformToType[i] = SVT;
1437 RegisterTypeForVT[i] = SVT;
1438 NumRegistersForVT[i] = 1;
1439 ValueTypeActions.setTypeAction(VT, TypePromoteInteger);
1440 IsLegalWiderType = true;
1441 break;
1442 }
1443 }
1444 if (IsLegalWiderType)
1445 break;
1446 [[fallthrough]];
1447 }
1448
1449 case TypeWidenVector:
1450 if (isPowerOf2_32(EC.getKnownMinValue())) {
1451 // Try to widen the vector.
1452 for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
1453 MVT SVT = (MVT::SimpleValueType) nVT;
1454 if (SVT.getVectorElementType() == EltVT &&
1455 SVT.isScalableVector() == IsScalable &&
1457 EC.getKnownMinValue() &&
1458 isTypeLegal(SVT)) {
1459 TransformToType[i] = SVT;
1460 RegisterTypeForVT[i] = SVT;
1461 NumRegistersForVT[i] = 1;
1462 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1463 IsLegalWiderType = true;
1464 break;
1465 }
1466 }
1467 if (IsLegalWiderType)
1468 break;
1469 } else {
1470 // Only widen to the next power of 2 to keep consistency with EVT.
1471 MVT NVT = VT.getPow2VectorType();
1472 if (isTypeLegal(NVT)) {
1473 TransformToType[i] = NVT;
1474 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1475 RegisterTypeForVT[i] = NVT;
1476 NumRegistersForVT[i] = 1;
1477 break;
1478 }
1479 }
1480 [[fallthrough]];
1481
1482 case TypeSplitVector:
1483 case TypeScalarizeVector: {
1484 MVT IntermediateVT;
1485 MVT RegisterVT;
1486 unsigned NumIntermediates;
1487 unsigned NumRegisters = getVectorTypeBreakdownMVT(VT, IntermediateVT,
1488 NumIntermediates, RegisterVT, this);
1489 NumRegistersForVT[i] = NumRegisters;
1490 assert(NumRegistersForVT[i] == NumRegisters &&
1491 "NumRegistersForVT size cannot represent NumRegisters!");
1492 RegisterTypeForVT[i] = RegisterVT;
1493
1494 MVT NVT = VT.getPow2VectorType();
1495 if (NVT == VT) {
1496 // Type is already a power of 2. The default action is to split.
1497 TransformToType[i] = MVT::Other;
1498 if (PreferredAction == TypeScalarizeVector)
1499 ValueTypeActions.setTypeAction(VT, TypeScalarizeVector);
1500 else if (PreferredAction == TypeSplitVector)
1501 ValueTypeActions.setTypeAction(VT, TypeSplitVector);
1502 else if (EC.getKnownMinValue() > 1)
1503 ValueTypeActions.setTypeAction(VT, TypeSplitVector);
1504 else
1505 ValueTypeActions.setTypeAction(VT, EC.isScalable()
1508 } else {
1509 TransformToType[i] = NVT;
1510 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1511 }
1512 break;
1513 }
1514 default:
1515 llvm_unreachable("Unknown vector legalization action!");
1516 }
1517 }
1518
1519 // Determine the 'representative' register class for each value type.
1520 // An representative register class is the largest (meaning one which is
1521 // not a sub-register class / subreg register class) legal register class for
1522 // a group of value types. For example, on i386, i8, i16, and i32
1523 // representative would be GR32; while on x86_64 it's GR64.
1524 for (unsigned i = 0; i != MVT::VALUETYPE_SIZE; ++i) {
1525 const TargetRegisterClass* RRC;
1526 uint8_t Cost;
1528 RepRegClassForVT[i] = RRC;
1529 RepRegClassCostForVT[i] = Cost;
1530 }
1531}
1532
1534 EVT VT) const {
1535 assert(!VT.isVector() && "No default SetCC type for vectors!");
1536 return getPointerTy(DL).SimpleTy;
1537}
1538
1540 return MVT::i32; // return the default value
1541}
1542
1543/// getVectorTypeBreakdown - Vector types are broken down into some number of
1544/// legal first class types. For example, MVT::v8f32 maps to 2 MVT::v4f32
1545/// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
1546/// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
1547///
1548/// This method returns the number of registers needed, and the VT for each
1549/// register. It also returns the VT and quantity of the intermediate values
1550/// before they are promoted/expanded.
1552 EVT VT, EVT &IntermediateVT,
1553 unsigned &NumIntermediates,
1554 MVT &RegisterVT) const {
1555 ElementCount EltCnt = VT.getVectorElementCount();
1556
1557 // If there is a wider vector type with the same element type as this one,
1558 // or a promoted vector type that has the same number of elements which
1559 // are wider, then we should convert to that legal vector type.
1560 // This handles things like <2 x float> -> <4 x float> and
1561 // <4 x i1> -> <4 x i32>.
1562 LegalizeTypeAction TA = getTypeAction(Context, VT);
1563 if (!EltCnt.isScalar() &&
1564 (TA == TypeWidenVector || TA == TypePromoteInteger)) {
1565 EVT RegisterEVT = getTypeToTransformTo(Context, VT);
1566 if (isTypeLegal(RegisterEVT)) {
1567 IntermediateVT = RegisterEVT;
1568 RegisterVT = RegisterEVT.getSimpleVT();
1569 NumIntermediates = 1;
1570 return 1;
1571 }
1572 }
1573
1574 // Figure out the right, legal destination reg to copy into.
1575 EVT EltTy = VT.getVectorElementType();
1576
1577 unsigned NumVectorRegs = 1;
1578
1579 // Scalable vectors cannot be scalarized, so handle the legalisation of the
1580 // types like done elsewhere in SelectionDAG.
1581 if (EltCnt.isScalable()) {
1582 LegalizeKind LK;
1583 EVT PartVT = VT;
1584 do {
1585 // Iterate until we've found a legal (part) type to hold VT.
1586 LK = getTypeConversion(Context, PartVT);
1587 PartVT = LK.second;
1588 } while (LK.first != TypeLegal);
1589
1590 if (!PartVT.isVector()) {
1592 "Don't know how to legalize this scalable vector type");
1593 }
1594
1595 NumIntermediates =
1598 IntermediateVT = PartVT;
1599 RegisterVT = getRegisterType(Context, IntermediateVT);
1600 return NumIntermediates;
1601 }
1602
1603 // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally
1604 // we could break down into LHS/RHS like LegalizeDAG does.
1605 if (!isPowerOf2_32(EltCnt.getKnownMinValue())) {
1606 NumVectorRegs = EltCnt.getKnownMinValue();
1607 EltCnt = ElementCount::getFixed(1);
1608 }
1609
1610 // Divide the input until we get to a supported size. This will always
1611 // end with a scalar if the target doesn't support vectors.
1612 while (EltCnt.getKnownMinValue() > 1 &&
1613 !isTypeLegal(EVT::getVectorVT(Context, EltTy, EltCnt))) {
1614 EltCnt = EltCnt.divideCoefficientBy(2);
1615 NumVectorRegs <<= 1;
1616 }
1617
1618 NumIntermediates = NumVectorRegs;
1619
1620 EVT NewVT = EVT::getVectorVT(Context, EltTy, EltCnt);
1621 if (!isTypeLegal(NewVT))
1622 NewVT = EltTy;
1623 IntermediateVT = NewVT;
1624
1625 MVT DestVT = getRegisterType(Context, NewVT);
1626 RegisterVT = DestVT;
1627
1628 if (EVT(DestVT).bitsLT(NewVT)) { // Value is expanded, e.g. i64 -> i16.
1629 TypeSize NewVTSize = NewVT.getSizeInBits();
1630 // Convert sizes such as i33 to i64.
1631 if (!llvm::has_single_bit<uint32_t>(NewVTSize.getKnownMinValue()))
1632 NewVTSize = NewVTSize.coefficientNextPowerOf2();
1633 return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
1634 }
1635
1636 // Otherwise, promotion or legal types use the same number of registers as
1637 // the vector decimated to the appropriate level.
1638 return NumVectorRegs;
1639}
1640
1642 uint64_t NumCases,
1644 ProfileSummaryInfo *PSI,
1645 BlockFrequencyInfo *BFI) const {
1646 // FIXME: This function check the maximum table size and density, but the
1647 // minimum size is not checked. It would be nice if the minimum size is
1648 // also combined within this function. Currently, the minimum size check is
1649 // performed in findJumpTable() in SelectionDAGBuiler and
1650 // getEstimatedNumberOfCaseClusters() in BasicTTIImpl.
1651 const bool OptForSize =
1652 llvm::shouldOptimizeForSize(SI->getParent(), PSI, BFI);
1653 const unsigned MinDensity = getMinimumJumpTableDensity(OptForSize);
1654 const unsigned MaxJumpTableSize = getMaximumJumpTableSize();
1655
1656 // Check whether the number of cases is small enough and
1657 // the range is dense enough for a jump table.
1658 return (OptForSize || Range <= MaxJumpTableSize) &&
1659 (NumCases * 100 >= Range * MinDensity);
1660}
1661
1663 EVT ConditionVT) const {
1664 return getRegisterType(Context, ConditionVT);
1665}
1666
1667/// Get the EVTs and ArgFlags collections that represent the legalized return
1668/// type of the given function. This does not require a DAG or a return value,
1669/// and is suitable for use before any DAGs for the function are constructed.
1670/// TODO: Move this out of TargetLowering.cpp.
1672 AttributeList attr,
1674 const TargetLowering &TLI, const DataLayout &DL) {
1675 SmallVector<EVT, 4> ValueVTs;
1676 ComputeValueVTs(TLI, DL, ReturnType, ValueVTs);
1677 unsigned NumValues = ValueVTs.size();
1678 if (NumValues == 0) return;
1679
1680 for (unsigned j = 0, f = NumValues; j != f; ++j) {
1681 EVT VT = ValueVTs[j];
1682 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
1683
1684 if (attr.hasRetAttr(Attribute::SExt))
1685 ExtendKind = ISD::SIGN_EXTEND;
1686 else if (attr.hasRetAttr(Attribute::ZExt))
1687 ExtendKind = ISD::ZERO_EXTEND;
1688
1689 if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger())
1690 VT = TLI.getTypeForExtReturn(ReturnType->getContext(), VT, ExtendKind);
1691
1692 unsigned NumParts =
1693 TLI.getNumRegistersForCallingConv(ReturnType->getContext(), CC, VT);
1694 MVT PartVT =
1695 TLI.getRegisterTypeForCallingConv(ReturnType->getContext(), CC, VT);
1696
1697 // 'inreg' on function refers to return value
1699 if (attr.hasRetAttr(Attribute::InReg))
1700 Flags.setInReg();
1701
1702 // Propagate extension type if any
1703 if (attr.hasRetAttr(Attribute::SExt))
1704 Flags.setSExt();
1705 else if (attr.hasRetAttr(Attribute::ZExt))
1706 Flags.setZExt();
1707
1708 for (unsigned i = 0; i < NumParts; ++i)
1709 Outs.push_back(ISD::OutputArg(Flags, PartVT, VT, /*isfixed=*/true, 0, 0));
1710 }
1711}
1712
1714 const DataLayout &DL) const {
1715 return DL.getABITypeAlign(Ty);
1716}
1717
1719 LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace,
1720 Align Alignment, MachineMemOperand::Flags Flags, unsigned *Fast) const {
1721 // Check if the specified alignment is sufficient based on the data layout.
1722 // TODO: While using the data layout works in practice, a better solution
1723 // would be to implement this check directly (make this a virtual function).
1724 // For example, the ABI alignment may change based on software platform while
1725 // this function should only be affected by hardware implementation.
1726 Type *Ty = VT.getTypeForEVT(Context);
1727 if (VT.isZeroSized() || Alignment >= DL.getABITypeAlign(Ty)) {
1728 // Assume that an access that meets the ABI-specified alignment is fast.
1729 if (Fast != nullptr)
1730 *Fast = 1;
1731 return true;
1732 }
1733
1734 // This is a misaligned access.
1735 return allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment, Flags, Fast);
1736}
1737
1739 LLVMContext &Context, const DataLayout &DL, EVT VT,
1740 const MachineMemOperand &MMO, unsigned *Fast) const {
1741 return allowsMemoryAccessForAlignment(Context, DL, VT, MMO.getAddrSpace(),
1742 MMO.getAlign(), MMO.getFlags(), Fast);
1743}
1744
1746 const DataLayout &DL, EVT VT,
1747 unsigned AddrSpace, Align Alignment,
1749 unsigned *Fast) const {
1750 return allowsMemoryAccessForAlignment(Context, DL, VT, AddrSpace, Alignment,
1751 Flags, Fast);
1752}
1753
1755 const DataLayout &DL, EVT VT,
1756 const MachineMemOperand &MMO,
1757 unsigned *Fast) const {
1758 return allowsMemoryAccess(Context, DL, VT, MMO.getAddrSpace(), MMO.getAlign(),
1759 MMO.getFlags(), Fast);
1760}
1761
1763 const DataLayout &DL, LLT Ty,
1764 const MachineMemOperand &MMO,
1765 unsigned *Fast) const {
1766 EVT VT = getApproximateEVTForLLT(Ty, Context);
1767 return allowsMemoryAccess(Context, DL, VT, MMO.getAddrSpace(), MMO.getAlign(),
1768 MMO.getFlags(), Fast);
1769}
1770
1771//===----------------------------------------------------------------------===//
1772// TargetTransformInfo Helpers
1773//===----------------------------------------------------------------------===//
1774
1776 enum InstructionOpcodes {
1777#define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM,
1778#define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM
1779#include "llvm/IR/Instruction.def"
1780 };
1781 switch (static_cast<InstructionOpcodes>(Opcode)) {
1782 case Ret: return 0;
1783 case Br: return 0;
1784 case Switch: return 0;
1785 case IndirectBr: return 0;
1786 case Invoke: return 0;
1787 case CallBr: return 0;
1788 case Resume: return 0;
1789 case Unreachable: return 0;
1790 case CleanupRet: return 0;
1791 case CatchRet: return 0;
1792 case CatchPad: return 0;
1793 case CatchSwitch: return 0;
1794 case CleanupPad: return 0;
1795 case FNeg: return ISD::FNEG;
1796 case Add: return ISD::ADD;
1797 case FAdd: return ISD::FADD;
1798 case Sub: return ISD::SUB;
1799 case FSub: return ISD::FSUB;
1800 case Mul: return ISD::MUL;
1801 case FMul: return ISD::FMUL;
1802 case UDiv: return ISD::UDIV;
1803 case SDiv: return ISD::SDIV;
1804 case FDiv: return ISD::FDIV;
1805 case URem: return ISD::UREM;
1806 case SRem: return ISD::SREM;
1807 case FRem: return ISD::FREM;
1808 case Shl: return ISD::SHL;
1809 case LShr: return ISD::SRL;
1810 case AShr: return ISD::SRA;
1811 case And: return ISD::AND;
1812 case Or: return ISD::OR;
1813 case Xor: return ISD::XOR;
1814 case Alloca: return 0;
1815 case Load: return ISD::LOAD;
1816 case Store: return ISD::STORE;
1817 case GetElementPtr: return 0;
1818 case Fence: return 0;
1819 case AtomicCmpXchg: return 0;
1820 case AtomicRMW: return 0;
1821 case Trunc: return ISD::TRUNCATE;
1822 case ZExt: return ISD::ZERO_EXTEND;
1823 case SExt: return ISD::SIGN_EXTEND;
1824 case FPToUI: return ISD::FP_TO_UINT;
1825 case FPToSI: return ISD::FP_TO_SINT;
1826 case UIToFP: return ISD::UINT_TO_FP;
1827 case SIToFP: return ISD::SINT_TO_FP;
1828 case FPTrunc: return ISD::FP_ROUND;
1829 case FPExt: return ISD::FP_EXTEND;
1830 case PtrToInt: return ISD::BITCAST;
1831 case IntToPtr: return ISD::BITCAST;
1832 case BitCast: return ISD::BITCAST;
1833 case AddrSpaceCast: return ISD::ADDRSPACECAST;
1834 case ICmp: return ISD::SETCC;
1835 case FCmp: return ISD::SETCC;
1836 case PHI: return 0;
1837 case Call: return 0;
1838 case Select: return ISD::SELECT;
1839 case UserOp1: return 0;
1840 case UserOp2: return 0;
1841 case VAArg: return 0;
1842 case ExtractElement: return ISD::EXTRACT_VECTOR_ELT;
1843 case InsertElement: return ISD::INSERT_VECTOR_ELT;
1844 case ShuffleVector: return ISD::VECTOR_SHUFFLE;
1845 case ExtractValue: return ISD::MERGE_VALUES;
1846 case InsertValue: return ISD::MERGE_VALUES;
1847 case LandingPad: return 0;
1848 case Freeze: return ISD::FREEZE;
1849 }
1850
1851 llvm_unreachable("Unknown instruction type encountered!");
1852}
1853
1855 switch (ID) {
1856 case Intrinsic::exp:
1857 return ISD::FEXP;
1858 case Intrinsic::exp2:
1859 return ISD::FEXP2;
1860 default:
1861 return ISD::DELETED_NODE;
1862 }
1863}
1864
1865Value *
1867 bool UseTLS) const {
1868 // compiler-rt provides a variable with a magic name. Targets that do not
1869 // link with compiler-rt may also provide such a variable.
1870 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1871 const char *UnsafeStackPtrVar = "__safestack_unsafe_stack_ptr";
1872 auto UnsafeStackPtr =
1873 dyn_cast_or_null<GlobalVariable>(M->getNamedValue(UnsafeStackPtrVar));
1874
1875 const DataLayout &DL = M->getDataLayout();
1876 PointerType *StackPtrTy = DL.getAllocaPtrType(M->getContext());
1877
1878 if (!UnsafeStackPtr) {
1879 auto TLSModel = UseTLS ?
1882 // The global variable is not defined yet, define it ourselves.
1883 // We use the initial-exec TLS model because we do not support the
1884 // variable living anywhere other than in the main executable.
1885 UnsafeStackPtr = new GlobalVariable(
1886 *M, StackPtrTy, false, GlobalValue::ExternalLinkage, nullptr,
1887 UnsafeStackPtrVar, nullptr, TLSModel);
1888 } else {
1889 // The variable exists, check its type and attributes.
1890 //
1891 // FIXME: Move to IR verifier.
1892 if (UnsafeStackPtr->getValueType() != StackPtrTy)
1893 report_fatal_error(Twine(UnsafeStackPtrVar) + " must have void* type");
1894 if (UseTLS != UnsafeStackPtr->isThreadLocal())
1895 report_fatal_error(Twine(UnsafeStackPtrVar) + " must " +
1896 (UseTLS ? "" : "not ") + "be thread-local");
1897 }
1898 return UnsafeStackPtr;
1899}
1900
1901Value *
1903 if (!TM.getTargetTriple().isAndroid())
1904 return getDefaultSafeStackPointerLocation(IRB, true);
1905
1906 // Android provides a libc function to retrieve the address of the current
1907 // thread's unsafe stack pointer.
1908 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1909 auto *PtrTy = PointerType::getUnqual(M->getContext());
1910 FunctionCallee Fn =
1911 M->getOrInsertFunction("__safestack_pointer_address", PtrTy);
1912 return IRB.CreateCall(Fn);
1913}
1914
1915//===----------------------------------------------------------------------===//
1916// Loop Strength Reduction hooks
1917//===----------------------------------------------------------------------===//
1918
1919/// isLegalAddressingMode - Return true if the addressing mode represented
1920/// by AM is legal for this target, for a load/store of the specified type.
1922 const AddrMode &AM, Type *Ty,
1923 unsigned AS, Instruction *I) const {
1924 // The default implementation of this implements a conservative RISCy, r+r and
1925 // r+i addr mode.
1926
1927 // Scalable offsets not supported
1928 if (AM.ScalableOffset)
1929 return false;
1930
1931 // Allows a sign-extended 16-bit immediate field.
1932 if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1)
1933 return false;
1934
1935 // No global is ever allowed as a base.
1936 if (AM.BaseGV)
1937 return false;
1938
1939 // Only support r+r,
1940 switch (AM.Scale) {
1941 case 0: // "r+i" or just "i", depending on HasBaseReg.
1942 break;
1943 case 1:
1944 if (AM.HasBaseReg && AM.BaseOffs) // "r+r+i" is not allowed.
1945 return false;
1946 // Otherwise we have r+r or r+i.
1947 break;
1948 case 2:
1949 if (AM.HasBaseReg || AM.BaseOffs) // 2*r+r or 2*r+i is not allowed.
1950 return false;
1951 // Allow 2*r as r+r.
1952 break;
1953 default: // Don't allow n * r
1954 return false;
1955 }
1956
1957 return true;
1958}
1959
1960//===----------------------------------------------------------------------===//
1961// Stack Protector
1962//===----------------------------------------------------------------------===//
1963
1964// For OpenBSD return its special guard variable. Otherwise return nullptr,
1965// so that SelectionDAG handle SSP.
1967 if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
1968 Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
1969 PointerType *PtrTy = PointerType::getUnqual(M.getContext());
1970 Constant *C = M.getOrInsertGlobal("__guard_local", PtrTy);
1971 if (GlobalVariable *G = dyn_cast_or_null<GlobalVariable>(C))
1972 G->setVisibility(GlobalValue::HiddenVisibility);
1973 return C;
1974 }
1975 return nullptr;
1976}
1977
1978// Currently only support "standard" __stack_chk_guard.
1979// TODO: add LOAD_STACK_GUARD support.
1981 if (!M.getNamedValue("__stack_chk_guard")) {
1982 auto *GV = new GlobalVariable(M, PointerType::getUnqual(M.getContext()),
1984 nullptr, "__stack_chk_guard");
1985
1986 // FreeBSD has "__stack_chk_guard" defined externally on libc.so
1987 if (M.getDirectAccessExternalData() &&
1989 !(TM.getTargetTriple().isPPC64() &&
1990 TM.getTargetTriple().isOSFreeBSD()) &&
1991 (!TM.getTargetTriple().isOSDarwin() ||
1993 GV->setDSOLocal(true);
1994 }
1995}
1996
1997// Currently only support "standard" __stack_chk_guard.
1998// TODO: add LOAD_STACK_GUARD support.
2000 return M.getNamedValue("__stack_chk_guard");
2001}
2002
2004 return nullptr;
2005}
2006
2009}
2010
2013}
2014
2015unsigned TargetLoweringBase::getMinimumJumpTableDensity(bool OptForSize) const {
2016 return OptForSize ? OptsizeJumpTableDensity : JumpTableDensity;
2017}
2018
2020 return MaximumJumpTableSize;
2021}
2022
2025}
2026
2029}
2030
2032 if (TM.Options.LoopAlignment)
2033 return Align(TM.Options.LoopAlignment);
2034 return PrefLoopAlignment;
2035}
2036
2038 MachineBasicBlock *MBB) const {
2039 return MaxBytesForAlignment;
2040}
2041
2042//===----------------------------------------------------------------------===//
2043// Reciprocal Estimates
2044//===----------------------------------------------------------------------===//
2045
2046/// Get the reciprocal estimate attribute string for a function that will
2047/// override the target defaults.
2049 const Function &F = MF.getFunction();
2050 return F.getFnAttribute("reciprocal-estimates").getValueAsString();
2051}
2052
2053/// Construct a string for the given reciprocal operation of the given type.
2054/// This string should match the corresponding option to the front-end's
2055/// "-mrecip" flag assuming those strings have been passed through in an
2056/// attribute string. For example, "vec-divf" for a division of a vXf32.
2057static std::string getReciprocalOpName(bool IsSqrt, EVT VT) {
2058 std::string Name = VT.isVector() ? "vec-" : "";
2059
2060 Name += IsSqrt ? "sqrt" : "div";
2061
2062 // TODO: Handle other float types?
2063 if (VT.getScalarType() == MVT::f64) {
2064 Name += "d";
2065 } else if (VT.getScalarType() == MVT::f16) {
2066 Name += "h";
2067 } else {
2068 assert(VT.getScalarType() == MVT::f32 &&
2069 "Unexpected FP type for reciprocal estimate");
2070 Name += "f";
2071 }
2072
2073 return Name;
2074}
2075
2076/// Return the character position and value (a single numeric character) of a
2077/// customized refinement operation in the input string if it exists. Return
2078/// false if there is no customized refinement step count.
2079static bool parseRefinementStep(StringRef In, size_t &Position,
2080 uint8_t &Value) {
2081 const char RefStepToken = ':';
2082 Position = In.find(RefStepToken);
2083 if (Position == StringRef::npos)
2084 return false;
2085
2086 StringRef RefStepString = In.substr(Position + 1);
2087 // Allow exactly one numeric character for the additional refinement
2088 // step parameter.
2089 if (RefStepString.size() == 1) {
2090 char RefStepChar = RefStepString[0];
2091 if (isDigit(RefStepChar)) {
2092 Value = RefStepChar - '0';
2093 return true;
2094 }
2095 }
2096 report_fatal_error("Invalid refinement step for -recip.");
2097}
2098
2099/// For the input attribute string, return one of the ReciprocalEstimate enum
2100/// status values (enabled, disabled, or not specified) for this operation on
2101/// the specified data type.
2102static int getOpEnabled(bool IsSqrt, EVT VT, StringRef Override) {
2103 if (Override.empty())
2105
2106 SmallVector<StringRef, 4> OverrideVector;
2107 Override.split(OverrideVector, ',');
2108 unsigned NumArgs = OverrideVector.size();
2109
2110 // Check if "all", "none", or "default" was specified.
2111 if (NumArgs == 1) {
2112 // Look for an optional setting of the number of refinement steps needed
2113 // for this type of reciprocal operation.
2114 size_t RefPos;
2115 uint8_t RefSteps;
2116 if (parseRefinementStep(Override, RefPos, RefSteps)) {
2117 // Split the string for further processing.
2118 Override = Override.substr(0, RefPos);
2119 }
2120
2121 // All reciprocal types are enabled.
2122 if (Override == "all")
2124
2125 // All reciprocal types are disabled.
2126 if (Override == "none")
2128
2129 // Target defaults for enablement are used.
2130 if (Override == "default")
2132 }
2133
2134 // The attribute string may omit the size suffix ('f'/'d').
2135 std::string VTName = getReciprocalOpName(IsSqrt, VT);
2136 std::string VTNameNoSize = VTName;
2137 VTNameNoSize.pop_back();
2138 static const char DisabledPrefix = '!';
2139
2140 for (StringRef RecipType : OverrideVector) {
2141 size_t RefPos;
2142 uint8_t RefSteps;
2143 if (parseRefinementStep(RecipType, RefPos, RefSteps))
2144 RecipType = RecipType.substr(0, RefPos);
2145
2146 // Ignore the disablement token for string matching.
2147 bool IsDisabled = RecipType[0] == DisabledPrefix;
2148 if (IsDisabled)
2149 RecipType = RecipType.substr(1);
2150
2151 if (RecipType == VTName || RecipType == VTNameNoSize)
2154 }
2155
2157}
2158
2159/// For the input attribute string, return the customized refinement step count
2160/// for this operation on the specified data type. If the step count does not
2161/// exist, return the ReciprocalEstimate enum value for unspecified.
2162static int getOpRefinementSteps(bool IsSqrt, EVT VT, StringRef Override) {
2163 if (Override.empty())
2165
2166 SmallVector<StringRef, 4> OverrideVector;
2167 Override.split(OverrideVector, ',');
2168 unsigned NumArgs = OverrideVector.size();
2169
2170 // Check if "all", "default", or "none" was specified.
2171 if (NumArgs == 1) {
2172 // Look for an optional setting of the number of refinement steps needed
2173 // for this type of reciprocal operation.
2174 size_t RefPos;
2175 uint8_t RefSteps;
2176 if (!parseRefinementStep(Override, RefPos, RefSteps))
2178
2179 // Split the string for further processing.
2180 Override = Override.substr(0, RefPos);
2181 assert(Override != "none" &&
2182 "Disabled reciprocals, but specifed refinement steps?");
2183
2184 // If this is a general override, return the specified number of steps.
2185 if (Override == "all" || Override == "default")
2186 return RefSteps;
2187 }
2188
2189 // The attribute string may omit the size suffix ('f'/'d').
2190 std::string VTName = getReciprocalOpName(IsSqrt, VT);
2191 std::string VTNameNoSize = VTName;
2192 VTNameNoSize.pop_back();
2193
2194 for (StringRef RecipType : OverrideVector) {
2195 size_t RefPos;
2196 uint8_t RefSteps;
2197 if (!parseRefinementStep(RecipType, RefPos, RefSteps))
2198 continue;
2199
2200 RecipType = RecipType.substr(0, RefPos);
2201 if (RecipType == VTName || RecipType == VTNameNoSize)
2202 return RefSteps;
2203 }
2204
2206}
2207
2209 MachineFunction &MF) const {
2210 return getOpEnabled(true, VT, getRecipEstimateForFunc(MF));
2211}
2212
2214 MachineFunction &MF) const {
2215 return getOpEnabled(false, VT, getRecipEstimateForFunc(MF));
2216}
2217
2219 MachineFunction &MF) const {
2220 return getOpRefinementSteps(true, VT, getRecipEstimateForFunc(MF));
2221}
2222
2224 MachineFunction &MF) const {
2225 return getOpRefinementSteps(false, VT, getRecipEstimateForFunc(MF));
2226}
2227
2229 EVT LoadVT, EVT BitcastVT, const SelectionDAG &DAG,
2230 const MachineMemOperand &MMO) const {
2231 // Single-element vectors are scalarized, so we should generally avoid having
2232 // any memory operations on such types, as they would get scalarized too.
2233 if (LoadVT.isFixedLengthVector() && BitcastVT.isFixedLengthVector() &&
2234 BitcastVT.getVectorNumElements() == 1)
2235 return false;
2236
2237 // Don't do if we could do an indexed load on the original type, but not on
2238 // the new one.
2239 if (!LoadVT.isSimple() || !BitcastVT.isSimple())
2240 return true;
2241
2242 MVT LoadMVT = LoadVT.getSimpleVT();
2243
2244 // Don't bother doing this if it's just going to be promoted again later, as
2245 // doing so might interfere with other combines.
2246 if (getOperationAction(ISD::LOAD, LoadMVT) == Promote &&
2247 getTypeToPromoteTo(ISD::LOAD, LoadMVT) == BitcastVT.getSimpleVT())
2248 return false;
2249
2250 unsigned Fast = 0;
2251 return allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), BitcastVT,
2252 MMO, &Fast) &&
2253 Fast;
2254}
2255
2258}
2259
2261 const LoadInst &LI, const DataLayout &DL, AssumptionCache *AC,
2262 const TargetLibraryInfo *LibInfo) const {
2264 if (LI.isVolatile())
2266
2267 if (LI.hasMetadata(LLVMContext::MD_nontemporal))
2269
2270 if (LI.hasMetadata(LLVMContext::MD_invariant_load))
2272
2274 LI.getAlign(), DL, &LI, AC,
2275 /*DT=*/nullptr, LibInfo))
2277
2278 Flags |= getTargetMMOFlags(LI);
2279 return Flags;
2280}
2281
2284 const DataLayout &DL) const {
2286
2287 if (SI.isVolatile())
2289
2290 if (SI.hasMetadata(LLVMContext::MD_nontemporal))
2292
2293 // FIXME: Not preserving dereferenceable
2294 Flags |= getTargetMMOFlags(SI);
2295 return Flags;
2296}
2297
2300 const DataLayout &DL) const {
2302
2303 if (const AtomicRMWInst *RMW = dyn_cast<AtomicRMWInst>(&AI)) {
2304 if (RMW->isVolatile())
2306 } else if (const AtomicCmpXchgInst *CmpX = dyn_cast<AtomicCmpXchgInst>(&AI)) {
2307 if (CmpX->isVolatile())
2309 } else
2310 llvm_unreachable("not an atomic instruction");
2311
2312 // FIXME: Not preserving dereferenceable
2313 Flags |= getTargetMMOFlags(AI);
2314 return Flags;
2315}
2316
2318 Instruction *Inst,
2319 AtomicOrdering Ord) const {
2320 if (isReleaseOrStronger(Ord) && Inst->hasAtomicStore())
2321 return Builder.CreateFence(Ord);
2322 else
2323 return nullptr;
2324}
2325
2327 Instruction *Inst,
2328 AtomicOrdering Ord) const {
2329 if (isAcquireOrStronger(Ord))
2330 return Builder.CreateFence(Ord);
2331 else
2332 return nullptr;
2333}
2334
2335//===----------------------------------------------------------------------===//
2336// GlobalISel Hooks
2337//===----------------------------------------------------------------------===//
2338
2340 const TargetTransformInfo *TTI) const {
2341 auto &MF = *MI.getMF();
2342 auto &MRI = MF.getRegInfo();
2343 // Assuming a spill and reload of a value has a cost of 1 instruction each,
2344 // this helper function computes the maximum number of uses we should consider
2345 // for remat. E.g. on arm64 global addresses take 2 insts to materialize. We
2346 // break even in terms of code size when the original MI has 2 users vs
2347 // choosing to potentially spill. Any more than 2 users we we have a net code
2348 // size increase. This doesn't take into account register pressure though.
2349 auto maxUses = [](unsigned RematCost) {
2350 // A cost of 1 means remats are basically free.
2351 if (RematCost == 1)
2352 return std::numeric_limits<unsigned>::max();
2353 if (RematCost == 2)
2354 return 2U;
2355
2356 // Remat is too expensive, only sink if there's one user.
2357 if (RematCost > 2)
2358 return 1U;
2359 llvm_unreachable("Unexpected remat cost");
2360 };
2361
2362 switch (MI.getOpcode()) {
2363 default:
2364 return false;
2365 // Constants-like instructions should be close to their users.
2366 // We don't want long live-ranges for them.
2367 case TargetOpcode::G_CONSTANT:
2368 case TargetOpcode::G_FCONSTANT:
2369 case TargetOpcode::G_FRAME_INDEX:
2370 case TargetOpcode::G_INTTOPTR:
2371 return true;
2372 case TargetOpcode::G_GLOBAL_VALUE: {
2373 unsigned RematCost = TTI->getGISelRematGlobalCost();
2374 Register Reg = MI.getOperand(0).getReg();
2375 unsigned MaxUses = maxUses(RematCost);
2376 if (MaxUses == UINT_MAX)
2377 return true; // Remats are "free" so always localize.
2378 return MRI.hasAtMostUserInstrs(Reg, MaxUses);
2379 }
2380 }
2381}
unsigned const MachineRegisterInfo * MRI
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
Module.h This file contains the declarations for the Module class.
#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
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:501
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:704
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the return value.
Definition: Attributes.h:849
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:220
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:739
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:170
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:657
@ 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:113
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition: IRBuilder.h:1842
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:193
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2449
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:404
@ MAX_INT_BITS
Maximum number of bits that can be specified.
Definition: DerivedTypes.h:54
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:176
Value * getPointerOperand()
Definition: Instructions.h:255
bool isVolatile() const
Return true if this is a load from a volatile memory location.
Definition: Instructions.h:205
Align getAlign() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:211
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:71
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:580
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:679
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:695
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:228
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:497
LLVMContext * getContext() const
Definition: SelectionDAG.h:510
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An instruction for storing to memory.
Definition: Instructions.h:292
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:700
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:571
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:150
static constexpr size_t npos
Definition: StringRef.h:53
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 ...
virtual Align getByValTypeAlignment(Type *Ty, const DataLayout &DL) const
Returns the desired alignment for ByVal or InAlloca aggregate function arguments in the caller parame...
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 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...
int IntrinsicIDToISD(Intrinsic::ID ID) const
Get the ISD node that corresponds to the Intrinsic ID.
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:81
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:691
bool isAndroid() const
Tests whether the target is Android.
Definition: Triple.h:803
bool isOSFreeBSD() const
Definition: Triple.h:614
bool isPPC64() const
Tests whether the target is 64-bit PowerPC (little and big endian).
Definition: Triple.h:1007
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, XROS, or DriverKit).
Definition: Triple.h:588
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
int getNumOccurrences() const
Definition: CommandLine.h:399
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:780
@ 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:753
@ 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:1077
@ VECREDUCE_SEQ_FADD
Generic reduction nodes.
Definition: ISDOpcodes.h:1425
@ VECREDUCE_SMIN
Definition: ISDOpcodes.h:1458
@ FGETSIGN
INT = FGETSIGN(FP) - Return the sign bit of the specified floating point value as an integer 0/1 valu...
Definition: ISDOpcodes.h:512
@ ATOMIC_LOAD_NAND
Definition: ISDOpcodes.h:1348
@ 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:1350
@ ATOMIC_LOAD_UMIN
Definition: ISDOpcodes.h:1351
@ 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:1081
@ FMAD
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations.
Definition: ISDOpcodes.h:502
@ 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:1110
@ 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:1100
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:814
@ VECTOR_FIND_LAST_ACTIVE
Definition: ISDOpcodes.h:1493
@ FMODF
FMODF - Decomposes the operand into integral and fractional parts, each having the same type and sign...
Definition: ISDOpcodes.h:1067
@ FATAN2
FATAN2 - atan2, inspired by libm.
Definition: ISDOpcodes.h:999
@ FSINCOSPI
FSINCOSPI - Compute both the sine and cosine times pi more accurately than FSINCOS(pi*x),...
Definition: ISDOpcodes.h:1063
@ ATOMIC_CMP_SWAP_WITH_SUCCESS
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
Definition: ISDOpcodes.h:1333
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:841
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition: ISDOpcodes.h:558
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
Definition: ISDOpcodes.h:1443
@ 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:1447
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition: ISDOpcodes.h:717
@ RESET_FPMODE
Sets default dynamic floating-point control modes.
Definition: ISDOpcodes.h:1104
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition: ISDOpcodes.h:871
@ VECREDUCE_SMAX
Definition: ISDOpcodes.h:1457
@ ATOMIC_LOAD_OR
Definition: ISDOpcodes.h:1346
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:954
@ ATOMIC_LOAD_XOR
Definition: ISDOpcodes.h:1347
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Definition: ISDOpcodes.h:997
@ 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:1502
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:805
@ AVGCEILS
AVGCEILS/AVGCEILU - Rounding averaging add - Add two integers using an integer of type i[N+2],...
Definition: ISDOpcodes.h:685
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
Definition: ISDOpcodes.h:1267
@ VECREDUCE_FADD
These reductions have relaxed evaluation order semantics, and have a single vector operand.
Definition: ISDOpcodes.h:1440
@ CTTZ_ZERO_UNDEF
Bit counting operators with an undefined result for zero inputs.
Definition: ISDOpcodes.h:752
@ PREFETCH
PREFETCH - This corresponds to a prefetch intrinsic.
Definition: ISDOpcodes.h:1300
@ TRUNCATE_SSAT_U
Definition: ISDOpcodes.h:834
@ VECREDUCE_FMIN
Definition: ISDOpcodes.h:1444
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
Definition: ISDOpcodes.h:1059
@ 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:788
@ FNEG
Perform various unary floating-point operations inspired by libm.
Definition: ISDOpcodes.h:981
@ SSUBO
Same for subtraction.
Definition: ISDOpcodes.h:334
@ ATOMIC_LOAD_MIN
Definition: ISDOpcodes.h:1349
@ IS_FPCLASS
Performs a check of floating point class property, defined by IEEE-754.
Definition: ISDOpcodes.h:522
@ 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:757
@ VECREDUCE_UMAX
Definition: ISDOpcodes.h:1459
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition: ISDOpcodes.h:642
@ 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:1452
@ GET_FPMODE
Reads the current dynamic floating-point control modes.
Definition: ISDOpcodes.h:1095
@ GET_FPENV
Gets the current floating-point environment.
Definition: ISDOpcodes.h:1072
@ SHL
Shift and rotation operations.
Definition: ISDOpcodes.h:735
@ ATOMIC_LOAD_CLR
Definition: ISDOpcodes.h:1345
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:615
@ ATOMIC_LOAD_AND
Definition: ISDOpcodes.h:1344
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
Definition: ISDOpcodes.h:1044
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:550
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:811
@ DEBUGTRAP
DEBUGTRAP - Trap intended to get the attention of a debugger.
Definition: ISDOpcodes.h:1290
@ FP_TO_UINT_SAT
Definition: ISDOpcodes.h:907
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
Definition: ISDOpcodes.h:1327
@ ATOMIC_LOAD_UMAX
Definition: ISDOpcodes.h:1352
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:1031
@ UBSANTRAP
UBSANTRAP - Trap with an immediate describing the kind of sanitizer failure.
Definition: ISDOpcodes.h:1294
@ 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:860
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:849
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition: ISDOpcodes.h:697
@ 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:939
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:310
@ VECREDUCE_UMIN
Definition: ISDOpcodes.h:1460
@ ATOMIC_LOAD_ADD
Definition: ISDOpcodes.h:1342
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
Definition: ISDOpcodes.h:1050
@ ATOMIC_LOAD_SUB
Definition: ISDOpcodes.h:1343
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:887
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
Definition: ISDOpcodes.h:1261
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:709
@ TRAP
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:1287
@ GET_FPENV_MEM
Gets the current floating-point environment.
Definition: ISDOpcodes.h:1086
@ SCMP
[US]CMP - 3-way comparison of signed or unsigned integers.
Definition: ISDOpcodes.h:705
@ AVGFLOORS
AVGFLOORS/AVGFLOORU - Averaging add - Add two integers using an integer of type i[N+1],...
Definition: ISDOpcodes.h:680
@ VECREDUCE_FMUL
Definition: ISDOpcodes.h:1441
@ 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:539
@ VECTOR_SPLICE
VECTOR_SPLICE(VEC1, VEC2, IMM) - Returns a subvector of the same type as VEC1/VEC2 from CONCAT_VECTOR...
Definition: ISDOpcodes.h:627
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
Definition: ISDOpcodes.h:1341
@ FFREXP
FFREXP - frexp, extract fractional and exponent component of a floating-point value.
Definition: ISDOpcodes.h:1004
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:920
@ VECTOR_COMPRESS
VECTOR_COMPRESS(Vec, Mask, Passthru) consecutively place vector elements based on mask e....
Definition: ISDOpcodes.h:669
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition: ISDOpcodes.h:882
@ ADDRSPACECAST
ADDRSPACECAST - This operator converts between pointers of different address spaces.
Definition: ISDOpcodes.h:958
@ 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:906
@ VECREDUCE_FMINIMUM
Definition: ISDOpcodes.h:1448
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:817
@ VECREDUCE_SEQ_FMUL
Definition: ISDOpcodes.h:1426
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:508
@ 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:1406
@ SET_FPENV_MEM
Sets the current floating point environment.
Definition: ISDOpcodes.h:1091
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
Definition: ISDOpcodes.h:1055
@ TRUNCATE_SSAT_S
TRUNCATE_[SU]SAT_[SU] - Truncate for saturated operand [SU] located in middle, prefix for SAT means i...
Definition: ISDOpcodes.h:832
@ ABDS
ABDS/ABDU - Absolute difference - Return the absolute difference between two numbers interpreted as s...
Definition: ISDOpcodes.h:692
@ TRUNCATE_USAT_U
Definition: ISDOpcodes.h:836
@ 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:1618
static const int LAST_INDEXED_MODE
Definition: ISDOpcodes.h:1569
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 getSINCOSPI(EVT RetVT)
getSINCOSPI - Return the SINCOSPI_* 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 getMODF(EVT RetVT)
getMODF - Return the MODF_* value for the given types, or UNKNOWN_LIBCALL if there is none.
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 getSINCOS(EVT RetVT)
getSINCOS - Return the SINCOS_* value for the given types, or UNKNOWN_LIBCALL if there is none.
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:354
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:217
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:292
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:1753
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.
EVT getApproximateEVTForLLT(LLT Ty, LLVMContext &Ctx)
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:404
@ 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:472
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:345
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:368
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
Definition: ValueTypes.h:465
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:311
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:181
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:414
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:318
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:210
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:323
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:331
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:448
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*...