LLVM 22.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.
103RTLIB::Libcall RTLIB::getFPLibCall(EVT VT,
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.
120RTLIB::Libcall RTLIB::getFPEXT(EVT OpVT, EVT RetVT) {
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.
155RTLIB::Libcall RTLIB::getFPROUND(EVT OpVT, EVT RetVT) {
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.
202RTLIB::Libcall RTLIB::getFPTOSINT(EVT OpVT, EVT RetVT) {
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.
251RTLIB::Libcall RTLIB::getFPTOUINT(EVT OpVT, EVT RetVT) {
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.
300RTLIB::Libcall RTLIB::getSINTTOFP(EVT OpVT, EVT RetVT) {
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::bf16)
316 return SINTTOFP_I64_BF16;
317 if (RetVT == MVT::f16)
318 return SINTTOFP_I64_F16;
319 if (RetVT == MVT::f32)
320 return SINTTOFP_I64_F32;
321 if (RetVT == MVT::f64)
322 return SINTTOFP_I64_F64;
323 if (RetVT == MVT::f80)
324 return SINTTOFP_I64_F80;
325 if (RetVT == MVT::f128)
326 return SINTTOFP_I64_F128;
327 if (RetVT == MVT::ppcf128)
328 return SINTTOFP_I64_PPCF128;
329 } else if (OpVT == MVT::i128) {
330 if (RetVT == MVT::f16)
331 return SINTTOFP_I128_F16;
332 if (RetVT == MVT::f32)
333 return SINTTOFP_I128_F32;
334 if (RetVT == MVT::f64)
335 return SINTTOFP_I128_F64;
336 if (RetVT == MVT::f80)
337 return SINTTOFP_I128_F80;
338 if (RetVT == MVT::f128)
339 return SINTTOFP_I128_F128;
340 if (RetVT == MVT::ppcf128)
341 return SINTTOFP_I128_PPCF128;
342 }
343 return UNKNOWN_LIBCALL;
344}
345
346/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
347/// UNKNOWN_LIBCALL if there is none.
348RTLIB::Libcall RTLIB::getUINTTOFP(EVT OpVT, EVT RetVT) {
349 if (OpVT == MVT::i32) {
350 if (RetVT == MVT::f16)
351 return UINTTOFP_I32_F16;
352 if (RetVT == MVT::f32)
353 return UINTTOFP_I32_F32;
354 if (RetVT == MVT::f64)
355 return UINTTOFP_I32_F64;
356 if (RetVT == MVT::f80)
357 return UINTTOFP_I32_F80;
358 if (RetVT == MVT::f128)
359 return UINTTOFP_I32_F128;
360 if (RetVT == MVT::ppcf128)
361 return UINTTOFP_I32_PPCF128;
362 } else if (OpVT == MVT::i64) {
363 if (RetVT == MVT::bf16)
364 return UINTTOFP_I64_BF16;
365 if (RetVT == MVT::f16)
366 return UINTTOFP_I64_F16;
367 if (RetVT == MVT::f32)
368 return UINTTOFP_I64_F32;
369 if (RetVT == MVT::f64)
370 return UINTTOFP_I64_F64;
371 if (RetVT == MVT::f80)
372 return UINTTOFP_I64_F80;
373 if (RetVT == MVT::f128)
374 return UINTTOFP_I64_F128;
375 if (RetVT == MVT::ppcf128)
376 return UINTTOFP_I64_PPCF128;
377 } else if (OpVT == MVT::i128) {
378 if (RetVT == MVT::f16)
379 return UINTTOFP_I128_F16;
380 if (RetVT == MVT::f32)
381 return UINTTOFP_I128_F32;
382 if (RetVT == MVT::f64)
383 return UINTTOFP_I128_F64;
384 if (RetVT == MVT::f80)
385 return UINTTOFP_I128_F80;
386 if (RetVT == MVT::f128)
387 return UINTTOFP_I128_F128;
388 if (RetVT == MVT::ppcf128)
389 return UINTTOFP_I128_PPCF128;
390 }
391 return UNKNOWN_LIBCALL;
392}
393
394RTLIB::Libcall RTLIB::getPOWI(EVT RetVT) {
395 return getFPLibCall(RetVT, POWI_F32, POWI_F64, POWI_F80, POWI_F128,
396 POWI_PPCF128);
397}
398
399RTLIB::Libcall RTLIB::getPOW(EVT RetVT) {
400 return getFPLibCall(RetVT, POW_F32, POW_F64, POW_F80, POW_F128, POW_PPCF128);
401}
402
403RTLIB::Libcall RTLIB::getLDEXP(EVT RetVT) {
404 return getFPLibCall(RetVT, LDEXP_F32, LDEXP_F64, LDEXP_F80, LDEXP_F128,
405 LDEXP_PPCF128);
406}
407
408RTLIB::Libcall RTLIB::getFREXP(EVT RetVT) {
409 return getFPLibCall(RetVT, FREXP_F32, FREXP_F64, FREXP_F80, FREXP_F128,
410 FREXP_PPCF128);
411}
412
413RTLIB::Libcall RTLIB::getSIN(EVT RetVT) {
414 return getFPLibCall(RetVT, SIN_F32, SIN_F64, SIN_F80, SIN_F128, SIN_PPCF128);
415}
416
417RTLIB::Libcall RTLIB::getCOS(EVT RetVT) {
418 return getFPLibCall(RetVT, COS_F32, COS_F64, COS_F80, COS_F128, COS_PPCF128);
419}
420
421RTLIB::Libcall RTLIB::getSINCOS(EVT RetVT) {
422 return getFPLibCall(RetVT, SINCOS_F32, SINCOS_F64, SINCOS_F80, SINCOS_F128,
423 SINCOS_PPCF128);
424}
425
426RTLIB::Libcall RTLIB::getSINCOSPI(EVT RetVT) {
427 return getFPLibCall(RetVT, SINCOSPI_F32, SINCOSPI_F64, SINCOSPI_F80,
428 SINCOSPI_F128, SINCOSPI_PPCF128);
429}
430
431RTLIB::Libcall RTLIB::getMODF(EVT RetVT) {
432 return getFPLibCall(RetVT, MODF_F32, MODF_F64, MODF_F80, MODF_F128,
433 MODF_PPCF128);
434}
435
436RTLIB::Libcall RTLIB::getOutlineAtomicHelper(const Libcall (&LC)[5][4],
437 AtomicOrdering Order,
438 uint64_t MemSize) {
439 unsigned ModeN, ModelN;
440 switch (MemSize) {
441 case 1:
442 ModeN = 0;
443 break;
444 case 2:
445 ModeN = 1;
446 break;
447 case 4:
448 ModeN = 2;
449 break;
450 case 8:
451 ModeN = 3;
452 break;
453 case 16:
454 ModeN = 4;
455 break;
456 default:
457 return RTLIB::UNKNOWN_LIBCALL;
458 }
459
460 switch (Order) {
461 case AtomicOrdering::Monotonic:
462 ModelN = 0;
463 break;
464 case AtomicOrdering::Acquire:
465 ModelN = 1;
466 break;
467 case AtomicOrdering::Release:
468 ModelN = 2;
469 break;
470 case AtomicOrdering::AcquireRelease:
471 case AtomicOrdering::SequentiallyConsistent:
472 ModelN = 3;
473 break;
474 default:
475 return UNKNOWN_LIBCALL;
476 }
477
478 return LC[ModeN][ModelN];
479}
480
481RTLIB::Libcall RTLIB::getOUTLINE_ATOMIC(unsigned Opc, AtomicOrdering Order,
482 MVT VT) {
483 if (!VT.isScalarInteger())
484 return UNKNOWN_LIBCALL;
485 uint64_t MemSize = VT.getScalarSizeInBits() / 8;
486
487#define LCALLS(A, B) \
488 { A##B##_RELAX, A##B##_ACQ, A##B##_REL, A##B##_ACQ_REL }
489#define LCALL5(A) \
490 LCALLS(A, 1), LCALLS(A, 2), LCALLS(A, 4), LCALLS(A, 8), LCALLS(A, 16)
491 switch (Opc) {
493 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_CAS)};
494 return getOutlineAtomicHelper(LC, Order, MemSize);
495 }
496 case ISD::ATOMIC_SWAP: {
497 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_SWP)};
498 return getOutlineAtomicHelper(LC, Order, MemSize);
499 }
501 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDADD)};
502 return getOutlineAtomicHelper(LC, Order, MemSize);
503 }
504 case ISD::ATOMIC_LOAD_OR: {
505 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDSET)};
506 return getOutlineAtomicHelper(LC, Order, MemSize);
507 }
509 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDCLR)};
510 return getOutlineAtomicHelper(LC, Order, MemSize);
511 }
513 const Libcall LC[5][4] = {LCALL5(OUTLINE_ATOMIC_LDEOR)};
514 return getOutlineAtomicHelper(LC, Order, MemSize);
515 }
516 default:
517 return UNKNOWN_LIBCALL;
518 }
519#undef LCALLS
520#undef LCALL5
521}
522
523RTLIB::Libcall RTLIB::getSYNC(unsigned Opc, MVT VT) {
524#define OP_TO_LIBCALL(Name, Enum) \
525 case Name: \
526 switch (VT.SimpleTy) { \
527 default: \
528 return UNKNOWN_LIBCALL; \
529 case MVT::i8: \
530 return Enum##_1; \
531 case MVT::i16: \
532 return Enum##_2; \
533 case MVT::i32: \
534 return Enum##_4; \
535 case MVT::i64: \
536 return Enum##_8; \
537 case MVT::i128: \
538 return Enum##_16; \
539 }
540
541 switch (Opc) {
542 OP_TO_LIBCALL(ISD::ATOMIC_SWAP, SYNC_LOCK_TEST_AND_SET)
543 OP_TO_LIBCALL(ISD::ATOMIC_CMP_SWAP, SYNC_VAL_COMPARE_AND_SWAP)
544 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_ADD, SYNC_FETCH_AND_ADD)
545 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_SUB, SYNC_FETCH_AND_SUB)
546 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_AND, SYNC_FETCH_AND_AND)
547 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_OR, SYNC_FETCH_AND_OR)
548 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_XOR, SYNC_FETCH_AND_XOR)
549 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_NAND, SYNC_FETCH_AND_NAND)
550 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MAX, SYNC_FETCH_AND_MAX)
551 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMAX, SYNC_FETCH_AND_UMAX)
552 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MIN, SYNC_FETCH_AND_MIN)
553 OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMIN, SYNC_FETCH_AND_UMIN)
554 }
555
556#undef OP_TO_LIBCALL
557
558 return UNKNOWN_LIBCALL;
559}
560
562 switch (ElementSize) {
563 case 1:
564 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_1;
565 case 2:
566 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_2;
567 case 4:
568 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_4;
569 case 8:
570 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_8;
571 case 16:
572 return MEMCPY_ELEMENT_UNORDERED_ATOMIC_16;
573 default:
574 return UNKNOWN_LIBCALL;
575 }
576}
577
579 switch (ElementSize) {
580 case 1:
581 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_1;
582 case 2:
583 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_2;
584 case 4:
585 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_4;
586 case 8:
587 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_8;
588 case 16:
589 return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_16;
590 default:
591 return UNKNOWN_LIBCALL;
592 }
593}
594
596 switch (ElementSize) {
597 case 1:
598 return MEMSET_ELEMENT_UNORDERED_ATOMIC_1;
599 case 2:
600 return MEMSET_ELEMENT_UNORDERED_ATOMIC_2;
601 case 4:
602 return MEMSET_ELEMENT_UNORDERED_ATOMIC_4;
603 case 8:
604 return MEMSET_ELEMENT_UNORDERED_ATOMIC_8;
605 case 16:
606 return MEMSET_ELEMENT_UNORDERED_ATOMIC_16;
607 default:
608 return UNKNOWN_LIBCALL;
609 }
610}
611
613 RTLIB::LibcallImpl Impl) const {
614 switch (Impl) {
615 case RTLIB::__aeabi_dcmpeq__une:
616 case RTLIB::__aeabi_fcmpeq__une:
617 // Usage in the eq case, so we have to invert the comparison.
618 return ISD::SETEQ;
619 case RTLIB::__aeabi_dcmpeq__oeq:
620 case RTLIB::__aeabi_fcmpeq__oeq:
621 // Normal comparison to boolean value.
622 return ISD::SETNE;
623 case RTLIB::__aeabi_dcmplt:
624 case RTLIB::__aeabi_dcmple:
625 case RTLIB::__aeabi_dcmpge:
626 case RTLIB::__aeabi_dcmpgt:
627 case RTLIB::__aeabi_dcmpun:
628 case RTLIB::__aeabi_fcmplt:
629 case RTLIB::__aeabi_fcmple:
630 case RTLIB::__aeabi_fcmpge:
631 case RTLIB::__aeabi_fcmpgt:
632 /// The AEABI versions return a typical boolean value, so we can compare
633 /// against the integer result as simply != 0.
634 return ISD::SETNE;
635 default:
636 break;
637 }
638
639 // Assume libgcc/compiler-rt behavior. Most of the cases are really aliases of
640 // each other, and return a 3-way comparison style result of -1, 0, or 1
641 // depending on lt/eq/gt.
642 //
643 // FIXME: It would be cleaner to directly express this as a 3-way comparison
644 // soft FP libcall instead of individual compares.
645 RTLIB::Libcall LC = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl);
646 switch (LC) {
647 case RTLIB::OEQ_F32:
648 case RTLIB::OEQ_F64:
649 case RTLIB::OEQ_F128:
650 case RTLIB::OEQ_PPCF128:
651 return ISD::SETEQ;
652 case RTLIB::UNE_F32:
653 case RTLIB::UNE_F64:
654 case RTLIB::UNE_F128:
655 case RTLIB::UNE_PPCF128:
656 return ISD::SETNE;
657 case RTLIB::OGE_F32:
658 case RTLIB::OGE_F64:
659 case RTLIB::OGE_F128:
660 case RTLIB::OGE_PPCF128:
661 return ISD::SETGE;
662 case RTLIB::OLT_F32:
663 case RTLIB::OLT_F64:
664 case RTLIB::OLT_F128:
665 case RTLIB::OLT_PPCF128:
666 return ISD::SETLT;
667 case RTLIB::OLE_F32:
668 case RTLIB::OLE_F64:
669 case RTLIB::OLE_F128:
670 case RTLIB::OLE_PPCF128:
671 return ISD::SETLE;
672 case RTLIB::OGT_F32:
673 case RTLIB::OGT_F64:
674 case RTLIB::OGT_F128:
675 case RTLIB::OGT_PPCF128:
676 return ISD::SETGT;
677 case RTLIB::UO_F32:
678 case RTLIB::UO_F64:
679 case RTLIB::UO_F128:
680 case RTLIB::UO_PPCF128:
681 return ISD::SETNE;
682 default:
683 llvm_unreachable("not a compare libcall");
684 }
685}
686
687/// NOTE: The TargetMachine owns TLOF.
689 : TM(tm), Libcalls(TM.getTargetTriple(), TM.Options.ExceptionModel,
690 TM.Options.FloatABIType, TM.Options.EABIVersion,
691 TM.Options.MCOptions.getABIName()) {
692 initActions();
693
694 // Perform these initializations only once.
700 HasExtractBitsInsn = false;
701 JumpIsExpensive = JumpIsExpensiveOverride;
703 EnableExtLdPromotion = false;
704 StackPointerRegisterToSaveRestore = 0;
705 BooleanContents = UndefinedBooleanContent;
706 BooleanFloatContents = UndefinedBooleanContent;
707 BooleanVectorContents = UndefinedBooleanContent;
708 SchedPreferenceInfo = Sched::ILP;
711 MaxBytesForAlignment = 0;
712 MaxAtomicSizeInBitsSupported = 0;
713
714 // Assume that even with libcalls, no target supports wider than 128 bit
715 // division.
716 MaxDivRemBitWidthSupported = 128;
717
718 MaxLargeFPConvertBitWidthSupported = llvm::IntegerType::MAX_INT_BITS;
719
720 MinCmpXchgSizeInBits = 0;
721 SupportsUnalignedAtomics = false;
722}
723
724// Define the virtual destructor out-of-line to act as a key method to anchor
725// debug info (see coding standards).
727
729 // All operations default to being supported.
730 memset(OpActions, 0, sizeof(OpActions));
731 memset(LoadExtActions, 0, sizeof(LoadExtActions));
732 memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
733 memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
734 memset(CondCodeActions, 0, sizeof(CondCodeActions));
735 llvm::fill(RegClassForVT, nullptr);
736 llvm::fill(TargetDAGCombineArray, 0);
737
738 // Let extending atomic loads be unsupported by default.
739 for (MVT ValVT : MVT::all_valuetypes())
740 for (MVT MemVT : MVT::all_valuetypes())
742 Expand);
743
744 // We're somewhat special casing MVT::i2 and MVT::i4. Ideally we want to
745 // remove this and targets should individually set these types if not legal.
748 for (MVT VT : {MVT::i2, MVT::i4})
749 OpActions[(unsigned)VT.SimpleTy][NT] = Expand;
750 }
751 for (MVT AVT : MVT::all_valuetypes()) {
752 for (MVT VT : {MVT::i2, MVT::i4, MVT::v128i2, MVT::v64i4}) {
753 setTruncStoreAction(AVT, VT, Expand);
756 }
757 }
758 for (unsigned IM = (unsigned)ISD::PRE_INC;
759 IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
760 for (MVT VT : {MVT::i2, MVT::i4}) {
765 }
766 }
767
768 for (MVT VT : MVT::fp_valuetypes()) {
769 MVT IntVT = MVT::getIntegerVT(VT.getFixedSizeInBits());
770 if (IntVT.isValid()) {
773 }
774 }
775
776 // Set default actions for various operations.
777 for (MVT VT : MVT::all_valuetypes()) {
778 // Default all indexed load / store to expand.
779 for (unsigned IM = (unsigned)ISD::PRE_INC;
780 IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
785 }
786
787 // Most backends expect to see the node which just returns the value loaded.
789
790 // These operations default to expand.
819 VT, Expand);
820
821 // Overflow operations default to expand
824 VT, Expand);
825
826 // Carry-using overflow operations default to expand.
829 VT, Expand);
830
831 // ADDC/ADDE/SUBC/SUBE default to expand.
833 Expand);
834
835 // [US]CMP default to expand
837
838 // Halving adds
841 Expand);
842
843 // Absolute difference
845
846 // Saturated trunc
850
851 // These default to Expand so they will be expanded to CTLZ/CTTZ by default.
853 Expand);
854
856
857 // These library functions default to expand.
860 VT, Expand);
861
862 // These operations default to expand for vector types.
863 if (VT.isVector())
869 VT, Expand);
870
871 // Constrained floating-point operations default to expand.
872#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
873 setOperationAction(ISD::STRICT_##DAGN, VT, Expand);
874#include "llvm/IR/ConstrainedOps.def"
875
876 // For most targets @llvm.get.dynamic.area.offset just returns 0.
878
879 // Vector reduction default to expand.
887 VT, Expand);
888
889 // Named vector shuffles default to expand.
891
892 // Only some target support this vector operation. Most need to expand it.
894
895 // VP operations default to expand.
896#define BEGIN_REGISTER_VP_SDNODE(SDOPC, ...) \
897 setOperationAction(ISD::SDOPC, VT, Expand);
898#include "llvm/IR/VPIntrinsics.def"
899
900 // Masked vector extracts default to expand.
902
903 // FP environment operations default to expand.
907
909 }
910
911 // Most targets ignore the @llvm.prefetch intrinsic.
913
914 // Most targets also ignore the @llvm.readcyclecounter intrinsic.
916
917 // Most targets also ignore the @llvm.readsteadycounter intrinsic.
919
920 // ConstantFP nodes default to expand. Targets can either change this to
921 // Legal, in which case all fp constants are legal, or use isFPImmLegal()
922 // to optimize expansions for certain constants.
924 {MVT::bf16, MVT::f16, MVT::f32, MVT::f64, MVT::f80, MVT::f128},
925 Expand);
926
927 // Insert custom handling default for llvm.canonicalize.*.
929 {MVT::f16, MVT::f32, MVT::f64, MVT::f128}, Expand);
930
931 // FIXME: Query RuntimeLibCalls to make the decision.
933 {MVT::f32, MVT::f64, MVT::f128}, LibCall);
934
937 MVT::f16, Promote);
938 // Default ISD::TRAP to expand (which turns it into abort).
939 setOperationAction(ISD::TRAP, MVT::Other, Expand);
940
941 // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand"
942 // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP.
944
946
949
950 for (MVT VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64}) {
953 }
955
956 // This one by default will call __clear_cache unless the target
957 // wants something different.
959}
960
962 EVT) const {
963 return MVT::getIntegerVT(DL.getPointerSizeInBits(0));
964}
965
967 const DataLayout &DL) const {
968 assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
969 if (LHSTy.isVector())
970 return LHSTy;
971 MVT ShiftVT = getScalarShiftAmountTy(DL, LHSTy);
972 // If any possible shift value won't fit in the prefered type, just use
973 // something safe. Assume it will be legalized when the shift is expanded.
974 if (ShiftVT.getSizeInBits() < Log2_32_Ceil(LHSTy.getSizeInBits()))
975 ShiftVT = MVT::i32;
976 assert(ShiftVT.getSizeInBits() >= Log2_32_Ceil(LHSTy.getSizeInBits()) &&
977 "ShiftVT is still too small!");
978 return ShiftVT;
979}
980
981bool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
982 assert(isTypeLegal(VT));
983 switch (Op) {
984 default:
985 return false;
986 case ISD::SDIV:
987 case ISD::UDIV:
988 case ISD::SREM:
989 case ISD::UREM:
990 return true;
991 }
992}
993
995 unsigned DestAS) const {
996 return TM.isNoopAddrSpaceCast(SrcAS, DestAS);
997}
998
1000 Type *RetTy, ElementCount EC, bool ZeroIsPoison,
1001 const ConstantRange *VScaleRange) const {
1002 // Find the smallest "sensible" element type to use for the expansion.
1003 ConstantRange CR(APInt(64, EC.getKnownMinValue()));
1004 if (EC.isScalable())
1005 CR = CR.umul_sat(*VScaleRange);
1006
1007 if (ZeroIsPoison)
1008 CR = CR.subtract(APInt(64, 1));
1009
1010 unsigned EltWidth = RetTy->getScalarSizeInBits();
1011 EltWidth = std::min(EltWidth, CR.getActiveBits());
1012 EltWidth = std::max(llvm::bit_ceil(EltWidth), (unsigned)8);
1013
1014 return EltWidth;
1015}
1016
1018 // If the command-line option was specified, ignore this request.
1020 JumpIsExpensive = isExpensive;
1021}
1022
1025 // If this is a simple type, use the ComputeRegisterProp mechanism.
1026 if (VT.isSimple()) {
1027 MVT SVT = VT.getSimpleVT();
1028 assert((unsigned)SVT.SimpleTy < std::size(TransformToType));
1029 MVT NVT = TransformToType[SVT.SimpleTy];
1030 LegalizeTypeAction LA = ValueTypeActions.getTypeAction(SVT);
1031
1032 assert((LA == TypeLegal || LA == TypeSoftenFloat ||
1033 LA == TypeSoftPromoteHalf ||
1034 (NVT.isVector() ||
1035 ValueTypeActions.getTypeAction(NVT) != TypePromoteInteger)) &&
1036 "Promote may not follow Expand or Promote");
1037
1038 if (LA == TypeSplitVector)
1039 return LegalizeKind(LA, EVT(SVT).getHalfNumVectorElementsVT(Context));
1040 if (LA == TypeScalarizeVector)
1041 return LegalizeKind(LA, SVT.getVectorElementType());
1042 return LegalizeKind(LA, NVT);
1043 }
1044
1045 // Handle Extended Scalar Types.
1046 if (!VT.isVector()) {
1047 assert(VT.isInteger() && "Float types must be simple");
1048 unsigned BitSize = VT.getSizeInBits();
1049 // First promote to a power-of-two size, then expand if necessary.
1050 if (BitSize < 8 || !isPowerOf2_32(BitSize)) {
1052 assert(NVT != VT && "Unable to round integer VT");
1053 LegalizeKind NextStep = getTypeConversion(Context, NVT);
1054 // Avoid multi-step promotion.
1055 if (NextStep.first == TypePromoteInteger)
1056 return NextStep;
1057 // Return rounded integer type.
1058 return LegalizeKind(TypePromoteInteger, NVT);
1059 }
1060
1063 }
1064
1065 // Handle vector types.
1066 ElementCount NumElts = VT.getVectorElementCount();
1067 EVT EltVT = VT.getVectorElementType();
1068
1069 // Vectors with only one element are always scalarized.
1070 if (NumElts.isScalar())
1071 return LegalizeKind(TypeScalarizeVector, EltVT);
1072
1073 // Try to widen vector elements until the element type is a power of two and
1074 // promote it to a legal type later on, for example:
1075 // <3 x i8> -> <4 x i8> -> <4 x i32>
1076 if (EltVT.isInteger()) {
1077 // Vectors with a number of elements that is not a power of two are always
1078 // widened, for example <3 x i8> -> <4 x i8>.
1079 if (!VT.isPow2VectorType()) {
1080 NumElts = NumElts.coefficientNextPowerOf2();
1081 EVT NVT = EVT::getVectorVT(Context, EltVT, NumElts);
1082 return LegalizeKind(TypeWidenVector, NVT);
1083 }
1084
1085 // Examine the element type.
1087
1088 // If type is to be expanded, split the vector.
1089 // <4 x i140> -> <2 x i140>
1090 if (LK.first == TypeExpandInteger) {
1091 if (NumElts.isScalable() && NumElts.getKnownMinValue() == 1)
1095 }
1096
1097 // Promote the integer element types until a legal vector type is found
1098 // or until the element integer type is too big. If a legal type was not
1099 // found, fallback to the usual mechanism of widening/splitting the
1100 // vector.
1101 EVT OldEltVT = EltVT;
1102 while (true) {
1103 // Increase the bitwidth of the element to the next pow-of-two
1104 // (which is greater than 8 bits).
1105 EltVT = EVT::getIntegerVT(Context, 1 + EltVT.getSizeInBits())
1107
1108 // Stop trying when getting a non-simple element type.
1109 // Note that vector elements may be greater than legal vector element
1110 // types. Example: X86 XMM registers hold 64bit element on 32bit
1111 // systems.
1112 if (!EltVT.isSimple())
1113 break;
1114
1115 // Build a new vector type and check if it is legal.
1116 MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1117 // Found a legal promoted vector type.
1118 if (NVT != MVT() && ValueTypeActions.getTypeAction(NVT) == TypeLegal)
1120 EVT::getVectorVT(Context, EltVT, NumElts));
1121 }
1122
1123 // Reset the type to the unexpanded type if we did not find a legal vector
1124 // type with a promoted vector element type.
1125 EltVT = OldEltVT;
1126 }
1127
1128 // Try to widen the vector until a legal type is found.
1129 // If there is no wider legal type, split the vector.
1130 while (true) {
1131 // Round up to the next power of 2.
1132 NumElts = NumElts.coefficientNextPowerOf2();
1133
1134 // If there is no simple vector type with this many elements then there
1135 // cannot be a larger legal vector type. Note that this assumes that
1136 // there are no skipped intermediate vector types in the simple types.
1137 if (!EltVT.isSimple())
1138 break;
1139 MVT LargerVector = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1140 if (LargerVector == MVT())
1141 break;
1142
1143 // If this type is legal then widen the vector.
1144 if (ValueTypeActions.getTypeAction(LargerVector) == TypeLegal)
1145 return LegalizeKind(TypeWidenVector, LargerVector);
1146 }
1147
1148 // Widen odd vectors to next power of two.
1149 if (!VT.isPow2VectorType()) {
1150 EVT NVT = VT.getPow2VectorType(Context);
1151 return LegalizeKind(TypeWidenVector, NVT);
1152 }
1153
1156
1157 // Vectors with illegal element types are expanded.
1158 EVT NVT = EVT::getVectorVT(Context, EltVT,
1160 return LegalizeKind(TypeSplitVector, NVT);
1161}
1162
1163static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
1164 unsigned &NumIntermediates,
1165 MVT &RegisterVT,
1166 TargetLoweringBase *TLI) {
1167 // Figure out the right, legal destination reg to copy into.
1169 MVT EltTy = VT.getVectorElementType();
1170
1171 unsigned NumVectorRegs = 1;
1172
1173 // Scalable vectors cannot be scalarized, so splitting or widening is
1174 // required.
1175 if (VT.isScalableVector() && !isPowerOf2_32(EC.getKnownMinValue()))
1177 "Splitting or widening of non-power-of-2 MVTs is not implemented.");
1178
1179 // FIXME: We don't support non-power-of-2-sized vectors for now.
1180 // Ideally we could break down into LHS/RHS like LegalizeDAG does.
1181 if (!isPowerOf2_32(EC.getKnownMinValue())) {
1182 // Split EC to unit size (scalable property is preserved).
1183 NumVectorRegs = EC.getKnownMinValue();
1184 EC = ElementCount::getFixed(1);
1185 }
1186
1187 // Divide the input until we get to a supported size. This will
1188 // always end up with an EC that represent a scalar or a scalable
1189 // scalar.
1190 while (EC.getKnownMinValue() > 1 &&
1191 !TLI->isTypeLegal(MVT::getVectorVT(EltTy, EC))) {
1192 EC = EC.divideCoefficientBy(2);
1193 NumVectorRegs <<= 1;
1194 }
1195
1196 NumIntermediates = NumVectorRegs;
1197
1198 MVT NewVT = MVT::getVectorVT(EltTy, EC);
1199 if (!TLI->isTypeLegal(NewVT))
1200 NewVT = EltTy;
1201 IntermediateVT = NewVT;
1202
1203 unsigned LaneSizeInBits = NewVT.getScalarSizeInBits();
1204
1205 // Convert sizes such as i33 to i64.
1206 LaneSizeInBits = llvm::bit_ceil(LaneSizeInBits);
1207
1208 MVT DestVT = TLI->getRegisterType(NewVT);
1209 RegisterVT = DestVT;
1210 if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16.
1211 return NumVectorRegs * (LaneSizeInBits / DestVT.getScalarSizeInBits());
1212
1213 // Otherwise, promotion or legal types use the same number of registers as
1214 // the vector decimated to the appropriate level.
1215 return NumVectorRegs;
1216}
1217
1218/// isLegalRC - Return true if the value types that can be represented by the
1219/// specified register class are all legal.
1221 const TargetRegisterClass &RC) const {
1222 for (const auto *I = TRI.legalclasstypes_begin(RC); *I != MVT::Other; ++I)
1223 if (isTypeLegal(*I))
1224 return true;
1225 return false;
1226}
1227
1228/// Replace/modify any TargetFrameIndex operands with a targte-dependent
1229/// sequence of memory operands that is recognized by PrologEpilogInserter.
1232 MachineBasicBlock *MBB) const {
1233 MachineInstr *MI = &InitialMI;
1234 MachineFunction &MF = *MI->getMF();
1235 MachineFrameInfo &MFI = MF.getFrameInfo();
1236
1237 // We're handling multiple types of operands here:
1238 // PATCHPOINT MetaArgs - live-in, read only, direct
1239 // STATEPOINT Deopt Spill - live-through, read only, indirect
1240 // STATEPOINT Deopt Alloca - live-through, read only, direct
1241 // (We're currently conservative and mark the deopt slots read/write in
1242 // practice.)
1243 // STATEPOINT GC Spill - live-through, read/write, indirect
1244 // STATEPOINT GC Alloca - live-through, read/write, direct
1245 // The live-in vs live-through is handled already (the live through ones are
1246 // all stack slots), but we need to handle the different type of stackmap
1247 // operands and memory effects here.
1248
1249 if (llvm::none_of(MI->operands(),
1250 [](MachineOperand &Operand) { return Operand.isFI(); }))
1251 return MBB;
1252
1253 MachineInstrBuilder MIB = BuildMI(MF, MI->getDebugLoc(), MI->getDesc());
1254
1255 // Inherit previous memory operands.
1256 MIB.cloneMemRefs(*MI);
1257
1258 for (unsigned i = 0; i < MI->getNumOperands(); ++i) {
1259 MachineOperand &MO = MI->getOperand(i);
1260 if (!MO.isFI()) {
1261 // Index of Def operand this Use it tied to.
1262 // Since Defs are coming before Uses, if Use is tied, then
1263 // index of Def must be smaller that index of that Use.
1264 // Also, Defs preserve their position in new MI.
1265 unsigned TiedTo = i;
1266 if (MO.isReg() && MO.isTied())
1267 TiedTo = MI->findTiedOperandIdx(i);
1268 MIB.add(MO);
1269 if (TiedTo < i)
1270 MIB->tieOperands(TiedTo, MIB->getNumOperands() - 1);
1271 continue;
1272 }
1273
1274 // foldMemoryOperand builds a new MI after replacing a single FI operand
1275 // with the canonical set of five x86 addressing-mode operands.
1276 int FI = MO.getIndex();
1277
1278 // Add frame index operands recognized by stackmaps.cpp
1280 // indirect-mem-ref tag, size, #FI, offset.
1281 // Used for spills inserted by StatepointLowering. This codepath is not
1282 // used for patchpoints/stackmaps at all, for these spilling is done via
1283 // foldMemoryOperand callback only.
1284 assert(MI->getOpcode() == TargetOpcode::STATEPOINT && "sanity");
1285 MIB.addImm(StackMaps::IndirectMemRefOp);
1286 MIB.addImm(MFI.getObjectSize(FI));
1287 MIB.add(MO);
1288 MIB.addImm(0);
1289 } else {
1290 // direct-mem-ref tag, #FI, offset.
1291 // Used by patchpoint, and direct alloca arguments to statepoints
1292 MIB.addImm(StackMaps::DirectMemRefOp);
1293 MIB.add(MO);
1294 MIB.addImm(0);
1295 }
1296
1297 assert(MIB->mayLoad() && "Folded a stackmap use to a non-load!");
1298
1299 // Add a new memory operand for this FI.
1300 assert(MFI.getObjectOffset(FI) != -1);
1301
1302 // Note: STATEPOINT MMOs are added during SelectionDAG. STACKMAP, and
1303 // PATCHPOINT should be updated to do the same. (TODO)
1304 if (MI->getOpcode() != TargetOpcode::STATEPOINT) {
1305 auto Flags = MachineMemOperand::MOLoad;
1307 MachinePointerInfo::getFixedStack(MF, FI), Flags,
1309 MIB->addMemOperand(MF, MMO);
1310 }
1311 }
1313 MI->eraseFromParent();
1314 return MBB;
1315}
1316
1317/// findRepresentativeClass - Return the largest legal super-reg register class
1318/// of the register class for the specified type and its associated "cost".
1319// This function is in TargetLowering because it uses RegClassForVT which would
1320// need to be moved to TargetRegisterInfo and would necessitate moving
1321// isTypeLegal over as well - a massive change that would just require
1322// TargetLowering having a TargetRegisterInfo class member that it would use.
1323std::pair<const TargetRegisterClass *, uint8_t>
1325 MVT VT) const {
1326 const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
1327 if (!RC)
1328 return std::make_pair(RC, 0);
1329
1330 // Compute the set of all super-register classes.
1331 BitVector SuperRegRC(TRI->getNumRegClasses());
1332 for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI)
1333 SuperRegRC.setBitsInMask(RCI.getMask());
1334
1335 // Find the first legal register class with the largest spill size.
1336 const TargetRegisterClass *BestRC = RC;
1337 for (unsigned i : SuperRegRC.set_bits()) {
1338 const TargetRegisterClass *SuperRC = TRI->getRegClass(i);
1339 // We want the largest possible spill size.
1340 if (TRI->getSpillSize(*SuperRC) <= TRI->getSpillSize(*BestRC))
1341 continue;
1342 if (!isLegalRC(*TRI, *SuperRC))
1343 continue;
1344 BestRC = SuperRC;
1345 }
1346 return std::make_pair(BestRC, 1);
1347}
1348
1349/// computeRegisterProperties - Once all of the register classes are added,
1350/// this allows us to compute derived properties we expose.
1352 const TargetRegisterInfo *TRI) {
1353 // Everything defaults to needing one register.
1354 for (unsigned i = 0; i != MVT::VALUETYPE_SIZE; ++i) {
1355 NumRegistersForVT[i] = 1;
1356 RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i;
1357 }
1358 // ...except isVoid, which doesn't need any registers.
1359 NumRegistersForVT[MVT::isVoid] = 0;
1360
1361 // Find the largest integer register class.
1362 unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE;
1363 for (; RegClassForVT[LargestIntReg] == nullptr; --LargestIntReg)
1364 assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
1365
1366 // Every integer value type larger than this largest register takes twice as
1367 // many registers to represent as the previous ValueType.
1368 for (unsigned ExpandedReg = LargestIntReg + 1;
1369 ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) {
1370 NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1];
1371 RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg;
1372 TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1);
1373 ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg,
1375 }
1376
1377 // Inspect all of the ValueType's smaller than the largest integer
1378 // register to see which ones need promotion.
1379 unsigned LegalIntReg = LargestIntReg;
1380 for (unsigned IntReg = LargestIntReg - 1;
1381 IntReg >= (unsigned)MVT::i1; --IntReg) {
1382 MVT IVT = (MVT::SimpleValueType)IntReg;
1383 if (isTypeLegal(IVT)) {
1384 LegalIntReg = IntReg;
1385 } else {
1386 RegisterTypeForVT[IntReg] = TransformToType[IntReg] =
1387 (MVT::SimpleValueType)LegalIntReg;
1388 ValueTypeActions.setTypeAction(IVT, TypePromoteInteger);
1389 }
1390 }
1391
1392 // ppcf128 type is really two f64's.
1393 if (!isTypeLegal(MVT::ppcf128)) {
1394 if (isTypeLegal(MVT::f64)) {
1395 NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64];
1396 RegisterTypeForVT[MVT::ppcf128] = MVT::f64;
1397 TransformToType[MVT::ppcf128] = MVT::f64;
1398 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat);
1399 } else {
1400 NumRegistersForVT[MVT::ppcf128] = NumRegistersForVT[MVT::i128];
1401 RegisterTypeForVT[MVT::ppcf128] = RegisterTypeForVT[MVT::i128];
1402 TransformToType[MVT::ppcf128] = MVT::i128;
1403 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeSoftenFloat);
1404 }
1405 }
1406
1407 // Decide how to handle f128. If the target does not have native f128 support,
1408 // expand it to i128 and we will be generating soft float library calls.
1409 if (!isTypeLegal(MVT::f128)) {
1410 NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128];
1411 RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128];
1412 TransformToType[MVT::f128] = MVT::i128;
1413 ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat);
1414 }
1415
1416 // Decide how to handle f80. If the target does not have native f80 support,
1417 // expand it to i96 and we will be generating soft float library calls.
1418 if (!isTypeLegal(MVT::f80)) {
1419 NumRegistersForVT[MVT::f80] = 3*NumRegistersForVT[MVT::i32];
1420 RegisterTypeForVT[MVT::f80] = RegisterTypeForVT[MVT::i32];
1421 TransformToType[MVT::f80] = MVT::i32;
1422 ValueTypeActions.setTypeAction(MVT::f80, TypeSoftenFloat);
1423 }
1424
1425 // Decide how to handle f64. If the target does not have native f64 support,
1426 // expand it to i64 and we will be generating soft float library calls.
1427 if (!isTypeLegal(MVT::f64)) {
1428 NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64];
1429 RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64];
1430 TransformToType[MVT::f64] = MVT::i64;
1431 ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat);
1432 }
1433
1434 // Decide how to handle f32. If the target does not have native f32 support,
1435 // expand it to i32 and we will be generating soft float library calls.
1436 if (!isTypeLegal(MVT::f32)) {
1437 NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32];
1438 RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32];
1439 TransformToType[MVT::f32] = MVT::i32;
1440 ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat);
1441 }
1442
1443 // Decide how to handle f16. If the target does not have native f16 support,
1444 // promote it to f32, because there are no f16 library calls (except for
1445 // conversions).
1446 if (!isTypeLegal(MVT::f16)) {
1447 // Allow targets to control how we legalize half.
1448 bool SoftPromoteHalfType = softPromoteHalfType();
1449 bool UseFPRegsForHalfType = !SoftPromoteHalfType || useFPRegsForHalfType();
1450
1451 if (!UseFPRegsForHalfType) {
1452 NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::i16];
1453 RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::i16];
1454 } else {
1455 NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::f32];
1456 RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::f32];
1457 }
1458 TransformToType[MVT::f16] = MVT::f32;
1459 if (SoftPromoteHalfType) {
1460 ValueTypeActions.setTypeAction(MVT::f16, TypeSoftPromoteHalf);
1461 } else {
1462 ValueTypeActions.setTypeAction(MVT::f16, TypePromoteFloat);
1463 }
1464 }
1465
1466 // Decide how to handle bf16. If the target does not have native bf16 support,
1467 // promote it to f32, because there are no bf16 library calls (except for
1468 // converting from f32 to bf16).
1469 if (!isTypeLegal(MVT::bf16)) {
1470 NumRegistersForVT[MVT::bf16] = NumRegistersForVT[MVT::f32];
1471 RegisterTypeForVT[MVT::bf16] = RegisterTypeForVT[MVT::f32];
1472 TransformToType[MVT::bf16] = MVT::f32;
1473 ValueTypeActions.setTypeAction(MVT::bf16, TypeSoftPromoteHalf);
1474 }
1475
1476 // Loop over all of the vector value types to see which need transformations.
1477 for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE;
1478 i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
1479 MVT VT = (MVT::SimpleValueType) i;
1480 if (isTypeLegal(VT))
1481 continue;
1482
1483 MVT EltVT = VT.getVectorElementType();
1485 bool IsLegalWiderType = false;
1486 bool IsScalable = VT.isScalableVector();
1487 LegalizeTypeAction PreferredAction = getPreferredVectorAction(VT);
1488 switch (PreferredAction) {
1489 case TypePromoteInteger: {
1490 MVT::SimpleValueType EndVT = IsScalable ?
1491 MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE :
1492 MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE;
1493 // Try to promote the elements of integer vectors. If no legal
1494 // promotion was found, fall through to the widen-vector method.
1495 for (unsigned nVT = i + 1;
1496 (MVT::SimpleValueType)nVT <= EndVT; ++nVT) {
1497 MVT SVT = (MVT::SimpleValueType) nVT;
1498 // Promote vectors of integers to vectors with the same number
1499 // of elements, with a wider element type.
1500 if (SVT.getScalarSizeInBits() > EltVT.getFixedSizeInBits() &&
1501 SVT.getVectorElementCount() == EC && isTypeLegal(SVT)) {
1502 TransformToType[i] = SVT;
1503 RegisterTypeForVT[i] = SVT;
1504 NumRegistersForVT[i] = 1;
1505 ValueTypeActions.setTypeAction(VT, TypePromoteInteger);
1506 IsLegalWiderType = true;
1507 break;
1508 }
1509 }
1510 if (IsLegalWiderType)
1511 break;
1512 [[fallthrough]];
1513 }
1514
1515 case TypeWidenVector:
1516 if (isPowerOf2_32(EC.getKnownMinValue())) {
1517 // Try to widen the vector.
1518 for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
1519 MVT SVT = (MVT::SimpleValueType) nVT;
1520 if (SVT.getVectorElementType() == EltVT &&
1521 SVT.isScalableVector() == IsScalable &&
1523 EC.getKnownMinValue() &&
1524 isTypeLegal(SVT)) {
1525 TransformToType[i] = SVT;
1526 RegisterTypeForVT[i] = SVT;
1527 NumRegistersForVT[i] = 1;
1528 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1529 IsLegalWiderType = true;
1530 break;
1531 }
1532 }
1533 if (IsLegalWiderType)
1534 break;
1535 } else {
1536 // Only widen to the next power of 2 to keep consistency with EVT.
1537 MVT NVT = VT.getPow2VectorType();
1538 if (isTypeLegal(NVT)) {
1539 TransformToType[i] = NVT;
1540 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1541 RegisterTypeForVT[i] = NVT;
1542 NumRegistersForVT[i] = 1;
1543 break;
1544 }
1545 }
1546 [[fallthrough]];
1547
1548 case TypeSplitVector:
1549 case TypeScalarizeVector: {
1550 MVT IntermediateVT;
1551 MVT RegisterVT;
1552 unsigned NumIntermediates;
1553 unsigned NumRegisters = getVectorTypeBreakdownMVT(VT, IntermediateVT,
1554 NumIntermediates, RegisterVT, this);
1555 NumRegistersForVT[i] = NumRegisters;
1556 assert(NumRegistersForVT[i] == NumRegisters &&
1557 "NumRegistersForVT size cannot represent NumRegisters!");
1558 RegisterTypeForVT[i] = RegisterVT;
1559
1560 MVT NVT = VT.getPow2VectorType();
1561 if (NVT == VT) {
1562 // Type is already a power of 2. The default action is to split.
1563 TransformToType[i] = MVT::Other;
1564 if (PreferredAction == TypeScalarizeVector)
1565 ValueTypeActions.setTypeAction(VT, TypeScalarizeVector);
1566 else if (PreferredAction == TypeSplitVector)
1567 ValueTypeActions.setTypeAction(VT, TypeSplitVector);
1568 else if (EC.getKnownMinValue() > 1)
1569 ValueTypeActions.setTypeAction(VT, TypeSplitVector);
1570 else
1571 ValueTypeActions.setTypeAction(VT, EC.isScalable()
1574 } else {
1575 TransformToType[i] = NVT;
1576 ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1577 }
1578 break;
1579 }
1580 default:
1581 llvm_unreachable("Unknown vector legalization action!");
1582 }
1583 }
1584
1585 // Determine the 'representative' register class for each value type.
1586 // An representative register class is the largest (meaning one which is
1587 // not a sub-register class / subreg register class) legal register class for
1588 // a group of value types. For example, on i386, i8, i16, and i32
1589 // representative would be GR32; while on x86_64 it's GR64.
1590 for (unsigned i = 0; i != MVT::VALUETYPE_SIZE; ++i) {
1591 const TargetRegisterClass* RRC;
1592 uint8_t Cost;
1594 RepRegClassForVT[i] = RRC;
1595 RepRegClassCostForVT[i] = Cost;
1596 }
1597}
1598
1600 EVT VT) const {
1601 assert(!VT.isVector() && "No default SetCC type for vectors!");
1602 return getPointerTy(DL).SimpleTy;
1603}
1604
1606 return MVT::i32; // return the default value
1607}
1608
1609/// getVectorTypeBreakdown - Vector types are broken down into some number of
1610/// legal first class types. For example, MVT::v8f32 maps to 2 MVT::v4f32
1611/// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
1612/// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
1613///
1614/// This method returns the number of registers needed, and the VT for each
1615/// register. It also returns the VT and quantity of the intermediate values
1616/// before they are promoted/expanded.
1618 EVT VT, EVT &IntermediateVT,
1619 unsigned &NumIntermediates,
1620 MVT &RegisterVT) const {
1621 ElementCount EltCnt = VT.getVectorElementCount();
1622
1623 // If there is a wider vector type with the same element type as this one,
1624 // or a promoted vector type that has the same number of elements which
1625 // are wider, then we should convert to that legal vector type.
1626 // This handles things like <2 x float> -> <4 x float> and
1627 // <4 x i1> -> <4 x i32>.
1629 if (!EltCnt.isScalar() &&
1630 (TA == TypeWidenVector || TA == TypePromoteInteger)) {
1631 EVT RegisterEVT = getTypeToTransformTo(Context, VT);
1632 if (isTypeLegal(RegisterEVT)) {
1633 IntermediateVT = RegisterEVT;
1634 RegisterVT = RegisterEVT.getSimpleVT();
1635 NumIntermediates = 1;
1636 return 1;
1637 }
1638 }
1639
1640 // Figure out the right, legal destination reg to copy into.
1641 EVT EltTy = VT.getVectorElementType();
1642
1643 unsigned NumVectorRegs = 1;
1644
1645 // Scalable vectors cannot be scalarized, so handle the legalisation of the
1646 // types like done elsewhere in SelectionDAG.
1647 if (EltCnt.isScalable()) {
1648 LegalizeKind LK;
1649 EVT PartVT = VT;
1650 do {
1651 // Iterate until we've found a legal (part) type to hold VT.
1652 LK = getTypeConversion(Context, PartVT);
1653 PartVT = LK.second;
1654 } while (LK.first != TypeLegal);
1655
1656 if (!PartVT.isVector()) {
1658 "Don't know how to legalize this scalable vector type");
1659 }
1660
1661 NumIntermediates =
1664 IntermediateVT = PartVT;
1665 RegisterVT = getRegisterType(Context, IntermediateVT);
1666 return NumIntermediates;
1667 }
1668
1669 // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally
1670 // we could break down into LHS/RHS like LegalizeDAG does.
1671 if (!isPowerOf2_32(EltCnt.getKnownMinValue())) {
1672 NumVectorRegs = EltCnt.getKnownMinValue();
1673 EltCnt = ElementCount::getFixed(1);
1674 }
1675
1676 // Divide the input until we get to a supported size. This will always
1677 // end with a scalar if the target doesn't support vectors.
1678 while (EltCnt.getKnownMinValue() > 1 &&
1679 !isTypeLegal(EVT::getVectorVT(Context, EltTy, EltCnt))) {
1680 EltCnt = EltCnt.divideCoefficientBy(2);
1681 NumVectorRegs <<= 1;
1682 }
1683
1684 NumIntermediates = NumVectorRegs;
1685
1686 EVT NewVT = EVT::getVectorVT(Context, EltTy, EltCnt);
1687 if (!isTypeLegal(NewVT))
1688 NewVT = EltTy;
1689 IntermediateVT = NewVT;
1690
1691 MVT DestVT = getRegisterType(Context, NewVT);
1692 RegisterVT = DestVT;
1693
1694 if (EVT(DestVT).bitsLT(NewVT)) { // Value is expanded, e.g. i64 -> i16.
1695 TypeSize NewVTSize = NewVT.getSizeInBits();
1696 // Convert sizes such as i33 to i64.
1697 if (!llvm::has_single_bit<uint32_t>(NewVTSize.getKnownMinValue()))
1698 NewVTSize = NewVTSize.coefficientNextPowerOf2();
1699 return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
1700 }
1701
1702 // Otherwise, promotion or legal types use the same number of registers as
1703 // the vector decimated to the appropriate level.
1704 return NumVectorRegs;
1705}
1706
1708 uint64_t NumCases,
1710 ProfileSummaryInfo *PSI,
1711 BlockFrequencyInfo *BFI) const {
1712 // FIXME: This function check the maximum table size and density, but the
1713 // minimum size is not checked. It would be nice if the minimum size is
1714 // also combined within this function. Currently, the minimum size check is
1715 // performed in findJumpTable() in SelectionDAGBuiler and
1716 // getEstimatedNumberOfCaseClusters() in BasicTTIImpl.
1717 const bool OptForSize =
1718 llvm::shouldOptimizeForSize(SI->getParent(), PSI, BFI);
1719 const unsigned MinDensity = getMinimumJumpTableDensity(OptForSize);
1720 const unsigned MaxJumpTableSize = getMaximumJumpTableSize();
1721
1722 // Check whether the number of cases is small enough and
1723 // the range is dense enough for a jump table.
1724 return (OptForSize || Range <= MaxJumpTableSize) &&
1725 (NumCases * 100 >= Range * MinDensity);
1726}
1727
1729 EVT ConditionVT) const {
1730 return getRegisterType(Context, ConditionVT);
1731}
1732
1733/// Get the EVTs and ArgFlags collections that represent the legalized return
1734/// type of the given function. This does not require a DAG or a return value,
1735/// and is suitable for use before any DAGs for the function are constructed.
1736/// TODO: Move this out of TargetLowering.cpp.
1738 AttributeList attr,
1740 const TargetLowering &TLI, const DataLayout &DL) {
1742 ComputeValueTypes(DL, ReturnType, Types);
1743 unsigned NumValues = Types.size();
1744 if (NumValues == 0) return;
1745
1746 for (Type *Ty : Types) {
1747 EVT VT = TLI.getValueType(DL, Ty);
1748 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
1749
1750 if (attr.hasRetAttr(Attribute::SExt))
1751 ExtendKind = ISD::SIGN_EXTEND;
1752 else if (attr.hasRetAttr(Attribute::ZExt))
1753 ExtendKind = ISD::ZERO_EXTEND;
1754
1755 if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger())
1756 VT = TLI.getTypeForExtReturn(ReturnType->getContext(), VT, ExtendKind);
1757
1758 unsigned NumParts =
1759 TLI.getNumRegistersForCallingConv(ReturnType->getContext(), CC, VT);
1760 MVT PartVT =
1761 TLI.getRegisterTypeForCallingConv(ReturnType->getContext(), CC, VT);
1762
1763 // 'inreg' on function refers to return value
1765 if (attr.hasRetAttr(Attribute::InReg))
1766 Flags.setInReg();
1767
1768 // Propagate extension type if any
1769 if (attr.hasRetAttr(Attribute::SExt))
1770 Flags.setSExt();
1771 else if (attr.hasRetAttr(Attribute::ZExt))
1772 Flags.setZExt();
1773
1774 for (unsigned i = 0; i < NumParts; ++i)
1775 Outs.push_back(ISD::OutputArg(Flags, PartVT, VT, Ty, 0, 0));
1776 }
1777}
1778
1780 const DataLayout &DL) const {
1781 return DL.getABITypeAlign(Ty);
1782}
1783
1785 LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace,
1786 Align Alignment, MachineMemOperand::Flags Flags, unsigned *Fast) const {
1787 // Check if the specified alignment is sufficient based on the data layout.
1788 // TODO: While using the data layout works in practice, a better solution
1789 // would be to implement this check directly (make this a virtual function).
1790 // For example, the ABI alignment may change based on software platform while
1791 // this function should only be affected by hardware implementation.
1792 Type *Ty = VT.getTypeForEVT(Context);
1793 if (VT.isZeroSized() || Alignment >= DL.getABITypeAlign(Ty)) {
1794 // Assume that an access that meets the ABI-specified alignment is fast.
1795 if (Fast != nullptr)
1796 *Fast = 1;
1797 return true;
1798 }
1799
1800 // This is a misaligned access.
1801 return allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment, Flags, Fast);
1802}
1803
1805 LLVMContext &Context, const DataLayout &DL, EVT VT,
1806 const MachineMemOperand &MMO, unsigned *Fast) const {
1808 MMO.getAlign(), MMO.getFlags(), Fast);
1809}
1810
1812 const DataLayout &DL, EVT VT,
1813 unsigned AddrSpace, Align Alignment,
1815 unsigned *Fast) const {
1816 return allowsMemoryAccessForAlignment(Context, DL, VT, AddrSpace, Alignment,
1817 Flags, Fast);
1818}
1819
1821 const DataLayout &DL, EVT VT,
1822 const MachineMemOperand &MMO,
1823 unsigned *Fast) const {
1824 return allowsMemoryAccess(Context, DL, VT, MMO.getAddrSpace(), MMO.getAlign(),
1825 MMO.getFlags(), Fast);
1826}
1827
1829 const DataLayout &DL, LLT Ty,
1830 const MachineMemOperand &MMO,
1831 unsigned *Fast) const {
1833 return allowsMemoryAccess(Context, DL, VT, MMO.getAddrSpace(), MMO.getAlign(),
1834 MMO.getFlags(), Fast);
1835}
1836
1837//===----------------------------------------------------------------------===//
1838// TargetTransformInfo Helpers
1839//===----------------------------------------------------------------------===//
1840
1842 enum InstructionOpcodes {
1843#define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM,
1844#define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM
1845#include "llvm/IR/Instruction.def"
1846 };
1847 switch (static_cast<InstructionOpcodes>(Opcode)) {
1848 case Ret: return 0;
1849 case Br: return 0;
1850 case Switch: return 0;
1851 case IndirectBr: return 0;
1852 case Invoke: return 0;
1853 case CallBr: return 0;
1854 case Resume: return 0;
1855 case Unreachable: return 0;
1856 case CleanupRet: return 0;
1857 case CatchRet: return 0;
1858 case CatchPad: return 0;
1859 case CatchSwitch: return 0;
1860 case CleanupPad: return 0;
1861 case FNeg: return ISD::FNEG;
1862 case Add: return ISD::ADD;
1863 case FAdd: return ISD::FADD;
1864 case Sub: return ISD::SUB;
1865 case FSub: return ISD::FSUB;
1866 case Mul: return ISD::MUL;
1867 case FMul: return ISD::FMUL;
1868 case UDiv: return ISD::UDIV;
1869 case SDiv: return ISD::SDIV;
1870 case FDiv: return ISD::FDIV;
1871 case URem: return ISD::UREM;
1872 case SRem: return ISD::SREM;
1873 case FRem: return ISD::FREM;
1874 case Shl: return ISD::SHL;
1875 case LShr: return ISD::SRL;
1876 case AShr: return ISD::SRA;
1877 case And: return ISD::AND;
1878 case Or: return ISD::OR;
1879 case Xor: return ISD::XOR;
1880 case Alloca: return 0;
1881 case Load: return ISD::LOAD;
1882 case Store: return ISD::STORE;
1883 case GetElementPtr: return 0;
1884 case Fence: return 0;
1885 case AtomicCmpXchg: return 0;
1886 case AtomicRMW: return 0;
1887 case Trunc: return ISD::TRUNCATE;
1888 case ZExt: return ISD::ZERO_EXTEND;
1889 case SExt: return ISD::SIGN_EXTEND;
1890 case FPToUI: return ISD::FP_TO_UINT;
1891 case FPToSI: return ISD::FP_TO_SINT;
1892 case UIToFP: return ISD::UINT_TO_FP;
1893 case SIToFP: return ISD::SINT_TO_FP;
1894 case FPTrunc: return ISD::FP_ROUND;
1895 case FPExt: return ISD::FP_EXTEND;
1896 case PtrToAddr: return ISD::BITCAST;
1897 case PtrToInt: return ISD::BITCAST;
1898 case IntToPtr: return ISD::BITCAST;
1899 case BitCast: return ISD::BITCAST;
1900 case AddrSpaceCast: return ISD::ADDRSPACECAST;
1901 case ICmp: return ISD::SETCC;
1902 case FCmp: return ISD::SETCC;
1903 case PHI: return 0;
1904 case Call: return 0;
1905 case Select: return ISD::SELECT;
1906 case UserOp1: return 0;
1907 case UserOp2: return 0;
1908 case VAArg: return 0;
1909 case ExtractElement: return ISD::EXTRACT_VECTOR_ELT;
1910 case InsertElement: return ISD::INSERT_VECTOR_ELT;
1911 case ShuffleVector: return ISD::VECTOR_SHUFFLE;
1912 case ExtractValue: return ISD::MERGE_VALUES;
1913 case InsertValue: return ISD::MERGE_VALUES;
1914 case LandingPad: return 0;
1915 case Freeze: return ISD::FREEZE;
1916 }
1917
1918 llvm_unreachable("Unknown instruction type encountered!");
1919}
1920
1922 switch (ID) {
1923 case Intrinsic::exp:
1924 return ISD::FEXP;
1925 case Intrinsic::exp2:
1926 return ISD::FEXP2;
1927 case Intrinsic::log:
1928 return ISD::FLOG;
1929 default:
1930 return ISD::DELETED_NODE;
1931 }
1932}
1933
1934Value *
1936 bool UseTLS) const {
1937 // compiler-rt provides a variable with a magic name. Targets that do not
1938 // link with compiler-rt may also provide such a variable.
1939 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1940 const char *UnsafeStackPtrVar = "__safestack_unsafe_stack_ptr";
1941 auto UnsafeStackPtr =
1942 dyn_cast_or_null<GlobalVariable>(M->getNamedValue(UnsafeStackPtrVar));
1943
1944 const DataLayout &DL = M->getDataLayout();
1945 PointerType *StackPtrTy = DL.getAllocaPtrType(M->getContext());
1946
1947 if (!UnsafeStackPtr) {
1948 auto TLSModel = UseTLS ?
1951 // The global variable is not defined yet, define it ourselves.
1952 // We use the initial-exec TLS model because we do not support the
1953 // variable living anywhere other than in the main executable.
1954 UnsafeStackPtr = new GlobalVariable(
1955 *M, StackPtrTy, false, GlobalValue::ExternalLinkage, nullptr,
1956 UnsafeStackPtrVar, nullptr, TLSModel);
1957 } else {
1958 // The variable exists, check its type and attributes.
1959 //
1960 // FIXME: Move to IR verifier.
1961 if (UnsafeStackPtr->getValueType() != StackPtrTy)
1962 report_fatal_error(Twine(UnsafeStackPtrVar) + " must have void* type");
1963 if (UseTLS != UnsafeStackPtr->isThreadLocal())
1964 report_fatal_error(Twine(UnsafeStackPtrVar) + " must " +
1965 (UseTLS ? "" : "not ") + "be thread-local");
1966 }
1967 return UnsafeStackPtr;
1968}
1969
1970Value *
1972 // FIXME: Can this triple check be replaced with SAFESTACK_POINTER_ADDRESS
1973 // being available?
1974 if (!TM.getTargetTriple().isAndroid())
1975 return getDefaultSafeStackPointerLocation(IRB, true);
1976
1977 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1978 auto *PtrTy = PointerType::getUnqual(M->getContext());
1979
1980 const char *SafestackPointerAddressName =
1981 getLibcallName(RTLIB::SAFESTACK_POINTER_ADDRESS);
1982 if (!SafestackPointerAddressName) {
1983 M->getContext().emitError(
1984 "no libcall available for safestack pointer address");
1985 return PoisonValue::get(PtrTy);
1986 }
1987
1988 // Android provides a libc function to retrieve the address of the current
1989 // thread's unsafe stack pointer.
1990 FunctionCallee Fn =
1991 M->getOrInsertFunction(SafestackPointerAddressName, PtrTy);
1992 return IRB.CreateCall(Fn);
1993}
1994
1995//===----------------------------------------------------------------------===//
1996// Loop Strength Reduction hooks
1997//===----------------------------------------------------------------------===//
1998
1999/// isLegalAddressingMode - Return true if the addressing mode represented
2000/// by AM is legal for this target, for a load/store of the specified type.
2002 const AddrMode &AM, Type *Ty,
2003 unsigned AS, Instruction *I) const {
2004 // The default implementation of this implements a conservative RISCy, r+r and
2005 // r+i addr mode.
2006
2007 // Scalable offsets not supported
2008 if (AM.ScalableOffset)
2009 return false;
2010
2011 // Allows a sign-extended 16-bit immediate field.
2012 if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1)
2013 return false;
2014
2015 // No global is ever allowed as a base.
2016 if (AM.BaseGV)
2017 return false;
2018
2019 // Only support r+r,
2020 switch (AM.Scale) {
2021 case 0: // "r+i" or just "i", depending on HasBaseReg.
2022 break;
2023 case 1:
2024 if (AM.HasBaseReg && AM.BaseOffs) // "r+r+i" is not allowed.
2025 return false;
2026 // Otherwise we have r+r or r+i.
2027 break;
2028 case 2:
2029 if (AM.HasBaseReg || AM.BaseOffs) // 2*r+r or 2*r+i is not allowed.
2030 return false;
2031 // Allow 2*r as r+r.
2032 break;
2033 default: // Don't allow n * r
2034 return false;
2035 }
2036
2037 return true;
2038}
2039
2040//===----------------------------------------------------------------------===//
2041// Stack Protector
2042//===----------------------------------------------------------------------===//
2043
2044// For OpenBSD return its special guard variable. Otherwise return nullptr,
2045// so that SelectionDAG handle SSP.
2047 if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
2048 Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
2049 const DataLayout &DL = M.getDataLayout();
2050 PointerType *PtrTy =
2051 PointerType::get(M.getContext(), DL.getDefaultGlobalsAddressSpace());
2052 GlobalVariable *G = M.getOrInsertGlobal("__guard_local", PtrTy);
2053 G->setVisibility(GlobalValue::HiddenVisibility);
2054 return G;
2055 }
2056 return nullptr;
2057}
2058
2059// Currently only support "standard" __stack_chk_guard.
2060// TODO: add LOAD_STACK_GUARD support.
2062 RTLIB::LibcallImpl StackGuardImpl = getLibcallImpl(RTLIB::STACK_CHECK_GUARD);
2063 if (StackGuardImpl == RTLIB::Unsupported)
2064 return;
2065
2066 StringRef StackGuardVarName = getLibcallImplName(StackGuardImpl);
2067 M.getOrInsertGlobal(
2068 StackGuardVarName, PointerType::getUnqual(M.getContext()), [=, &M]() {
2069 auto *GV = new GlobalVariable(M, PointerType::getUnqual(M.getContext()),
2070 false, GlobalVariable::ExternalLinkage,
2071 nullptr, StackGuardVarName);
2072
2073 // FreeBSD has "__stack_chk_guard" defined externally on libc.so
2074 if (M.getDirectAccessExternalData() &&
2075 !TM.getTargetTriple().isOSCygMing() &&
2076 !(TM.getTargetTriple().isPPC64() &&
2077 TM.getTargetTriple().isOSFreeBSD()) &&
2078 (!TM.getTargetTriple().isOSDarwin() ||
2079 TM.getRelocationModel() == Reloc::Static))
2080 GV->setDSOLocal(true);
2081
2082 return GV;
2083 });
2084}
2085
2086// Currently only support "standard" __stack_chk_guard.
2087// TODO: add LOAD_STACK_GUARD support.
2089 RTLIB::LibcallImpl GuardVarImpl = getLibcallImpl(RTLIB::STACK_CHECK_GUARD);
2090 if (GuardVarImpl == RTLIB::Unsupported)
2091 return nullptr;
2092 return M.getNamedValue(getLibcallImplName(GuardVarImpl));
2093}
2094
2096 return nullptr;
2097}
2098
2101}
2102
2105}
2106
2107unsigned TargetLoweringBase::getMinimumJumpTableDensity(bool OptForSize) const {
2108 return OptForSize ? OptsizeJumpTableDensity : JumpTableDensity;
2109}
2110
2112 return MaximumJumpTableSize;
2113}
2114
2117}
2118
2121}
2122
2124 if (TM.Options.LoopAlignment)
2125 return Align(TM.Options.LoopAlignment);
2126 return PrefLoopAlignment;
2127}
2128
2130 MachineBasicBlock *MBB) const {
2131 return MaxBytesForAlignment;
2132}
2133
2134//===----------------------------------------------------------------------===//
2135// Reciprocal Estimates
2136//===----------------------------------------------------------------------===//
2137
2138/// Get the reciprocal estimate attribute string for a function that will
2139/// override the target defaults.
2141 const Function &F = MF.getFunction();
2142 return F.getFnAttribute("reciprocal-estimates").getValueAsString();
2143}
2144
2145/// Construct a string for the given reciprocal operation of the given type.
2146/// This string should match the corresponding option to the front-end's
2147/// "-mrecip" flag assuming those strings have been passed through in an
2148/// attribute string. For example, "vec-divf" for a division of a vXf32.
2149static std::string getReciprocalOpName(bool IsSqrt, EVT VT) {
2150 std::string Name = VT.isVector() ? "vec-" : "";
2151
2152 Name += IsSqrt ? "sqrt" : "div";
2153
2154 // TODO: Handle other float types?
2155 if (VT.getScalarType() == MVT::f64) {
2156 Name += "d";
2157 } else if (VT.getScalarType() == MVT::f16) {
2158 Name += "h";
2159 } else {
2160 assert(VT.getScalarType() == MVT::f32 &&
2161 "Unexpected FP type for reciprocal estimate");
2162 Name += "f";
2163 }
2164
2165 return Name;
2166}
2167
2168/// Return the character position and value (a single numeric character) of a
2169/// customized refinement operation in the input string if it exists. Return
2170/// false if there is no customized refinement step count.
2171static bool parseRefinementStep(StringRef In, size_t &Position,
2172 uint8_t &Value) {
2173 const char RefStepToken = ':';
2174 Position = In.find(RefStepToken);
2175 if (Position == StringRef::npos)
2176 return false;
2177
2178 StringRef RefStepString = In.substr(Position + 1);
2179 // Allow exactly one numeric character for the additional refinement
2180 // step parameter.
2181 if (RefStepString.size() == 1) {
2182 char RefStepChar = RefStepString[0];
2183 if (isDigit(RefStepChar)) {
2184 Value = RefStepChar - '0';
2185 return true;
2186 }
2187 }
2188 report_fatal_error("Invalid refinement step for -recip.");
2189}
2190
2191/// For the input attribute string, return one of the ReciprocalEstimate enum
2192/// status values (enabled, disabled, or not specified) for this operation on
2193/// the specified data type.
2194static int getOpEnabled(bool IsSqrt, EVT VT, StringRef Override) {
2195 if (Override.empty())
2197
2198 SmallVector<StringRef, 4> OverrideVector;
2199 Override.split(OverrideVector, ',');
2200 unsigned NumArgs = OverrideVector.size();
2201
2202 // Check if "all", "none", or "default" was specified.
2203 if (NumArgs == 1) {
2204 // Look for an optional setting of the number of refinement steps needed
2205 // for this type of reciprocal operation.
2206 size_t RefPos;
2207 uint8_t RefSteps;
2208 if (parseRefinementStep(Override, RefPos, RefSteps)) {
2209 // Split the string for further processing.
2210 Override = Override.substr(0, RefPos);
2211 }
2212
2213 // All reciprocal types are enabled.
2214 if (Override == "all")
2216
2217 // All reciprocal types are disabled.
2218 if (Override == "none")
2220
2221 // Target defaults for enablement are used.
2222 if (Override == "default")
2224 }
2225
2226 // The attribute string may omit the size suffix ('f'/'d').
2227 std::string VTName = getReciprocalOpName(IsSqrt, VT);
2228 std::string VTNameNoSize = VTName;
2229 VTNameNoSize.pop_back();
2230 static const char DisabledPrefix = '!';
2231
2232 for (StringRef RecipType : OverrideVector) {
2233 size_t RefPos;
2234 uint8_t RefSteps;
2235 if (parseRefinementStep(RecipType, RefPos, RefSteps))
2236 RecipType = RecipType.substr(0, RefPos);
2237
2238 // Ignore the disablement token for string matching.
2239 bool IsDisabled = RecipType[0] == DisabledPrefix;
2240 if (IsDisabled)
2241 RecipType = RecipType.substr(1);
2242
2243 if (RecipType == VTName || RecipType == VTNameNoSize)
2246 }
2247
2249}
2250
2251/// For the input attribute string, return the customized refinement step count
2252/// for this operation on the specified data type. If the step count does not
2253/// exist, return the ReciprocalEstimate enum value for unspecified.
2254static int getOpRefinementSteps(bool IsSqrt, EVT VT, StringRef Override) {
2255 if (Override.empty())
2257
2258 SmallVector<StringRef, 4> OverrideVector;
2259 Override.split(OverrideVector, ',');
2260 unsigned NumArgs = OverrideVector.size();
2261
2262 // Check if "all", "default", or "none" was specified.
2263 if (NumArgs == 1) {
2264 // Look for an optional setting of the number of refinement steps needed
2265 // for this type of reciprocal operation.
2266 size_t RefPos;
2267 uint8_t RefSteps;
2268 if (!parseRefinementStep(Override, RefPos, RefSteps))
2270
2271 // Split the string for further processing.
2272 Override = Override.substr(0, RefPos);
2273 assert(Override != "none" &&
2274 "Disabled reciprocals, but specifed refinement steps?");
2275
2276 // If this is a general override, return the specified number of steps.
2277 if (Override == "all" || Override == "default")
2278 return RefSteps;
2279 }
2280
2281 // The attribute string may omit the size suffix ('f'/'d').
2282 std::string VTName = getReciprocalOpName(IsSqrt, VT);
2283 std::string VTNameNoSize = VTName;
2284 VTNameNoSize.pop_back();
2285
2286 for (StringRef RecipType : OverrideVector) {
2287 size_t RefPos;
2288 uint8_t RefSteps;
2289 if (!parseRefinementStep(RecipType, RefPos, RefSteps))
2290 continue;
2291
2292 RecipType = RecipType.substr(0, RefPos);
2293 if (RecipType == VTName || RecipType == VTNameNoSize)
2294 return RefSteps;
2295 }
2296
2298}
2299
2301 MachineFunction &MF) const {
2302 return getOpEnabled(true, VT, getRecipEstimateForFunc(MF));
2303}
2304
2306 MachineFunction &MF) const {
2307 return getOpEnabled(false, VT, getRecipEstimateForFunc(MF));
2308}
2309
2311 MachineFunction &MF) const {
2312 return getOpRefinementSteps(true, VT, getRecipEstimateForFunc(MF));
2313}
2314
2316 MachineFunction &MF) const {
2317 return getOpRefinementSteps(false, VT, getRecipEstimateForFunc(MF));
2318}
2319
2321 EVT LoadVT, EVT BitcastVT, const SelectionDAG &DAG,
2322 const MachineMemOperand &MMO) const {
2323 // Single-element vectors are scalarized, so we should generally avoid having
2324 // any memory operations on such types, as they would get scalarized too.
2325 if (LoadVT.isFixedLengthVector() && BitcastVT.isFixedLengthVector() &&
2326 BitcastVT.getVectorNumElements() == 1)
2327 return false;
2328
2329 // Don't do if we could do an indexed load on the original type, but not on
2330 // the new one.
2331 if (!LoadVT.isSimple() || !BitcastVT.isSimple())
2332 return true;
2333
2334 MVT LoadMVT = LoadVT.getSimpleVT();
2335
2336 // Don't bother doing this if it's just going to be promoted again later, as
2337 // doing so might interfere with other combines.
2338 if (getOperationAction(ISD::LOAD, LoadMVT) == Promote &&
2339 getTypeToPromoteTo(ISD::LOAD, LoadMVT) == BitcastVT.getSimpleVT())
2340 return false;
2341
2342 unsigned Fast = 0;
2343 return allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), BitcastVT,
2344 MMO, &Fast) &&
2345 Fast;
2346}
2347
2350}
2351
2353 const LoadInst &LI, const DataLayout &DL, AssumptionCache *AC,
2354 const TargetLibraryInfo *LibInfo) const {
2356 if (LI.isVolatile())
2358
2359 if (LI.hasMetadata(LLVMContext::MD_nontemporal))
2361
2362 if (LI.hasMetadata(LLVMContext::MD_invariant_load))
2364
2366 LI.getAlign(), DL, &LI, AC,
2367 /*DT=*/nullptr, LibInfo))
2369
2370 Flags |= getTargetMMOFlags(LI);
2371 return Flags;
2372}
2373
2376 const DataLayout &DL) const {
2378
2379 if (SI.isVolatile())
2381
2382 if (SI.hasMetadata(LLVMContext::MD_nontemporal))
2384
2385 // FIXME: Not preserving dereferenceable
2386 Flags |= getTargetMMOFlags(SI);
2387 return Flags;
2388}
2389
2392 const DataLayout &DL) const {
2394
2395 if (const AtomicRMWInst *RMW = dyn_cast<AtomicRMWInst>(&AI)) {
2396 if (RMW->isVolatile())
2398 } else if (const AtomicCmpXchgInst *CmpX = dyn_cast<AtomicCmpXchgInst>(&AI)) {
2399 if (CmpX->isVolatile())
2401 } else
2402 llvm_unreachable("not an atomic instruction");
2403
2404 // FIXME: Not preserving dereferenceable
2405 Flags |= getTargetMMOFlags(AI);
2406 return Flags;
2407}
2408
2410 const VPIntrinsic &VPIntrin) const {
2412 Intrinsic::ID IntrinID = VPIntrin.getIntrinsicID();
2413
2414 switch (IntrinID) {
2415 default:
2416 llvm_unreachable("unexpected intrinsic. Existing code may be appropriate "
2417 "for it, but support must be explicitly enabled");
2418 case Intrinsic::vp_load:
2419 case Intrinsic::vp_gather:
2420 case Intrinsic::experimental_vp_strided_load:
2422 break;
2423 case Intrinsic::vp_store:
2424 case Intrinsic::vp_scatter:
2425 case Intrinsic::experimental_vp_strided_store:
2427 break;
2428 }
2429
2430 if (VPIntrin.hasMetadata(LLVMContext::MD_nontemporal))
2432
2433 Flags |= getTargetMMOFlags(VPIntrin);
2434 return Flags;
2435}
2436
2438 Instruction *Inst,
2439 AtomicOrdering Ord) const {
2440 if (isReleaseOrStronger(Ord) && Inst->hasAtomicStore())
2441 return Builder.CreateFence(Ord);
2442 else
2443 return nullptr;
2444}
2445
2447 Instruction *Inst,
2448 AtomicOrdering Ord) const {
2449 if (isAcquireOrStronger(Ord))
2450 return Builder.CreateFence(Ord);
2451 else
2452 return nullptr;
2453}
2454
2455//===----------------------------------------------------------------------===//
2456// GlobalISel Hooks
2457//===----------------------------------------------------------------------===//
2458
2460 const TargetTransformInfo *TTI) const {
2461 auto &MF = *MI.getMF();
2462 auto &MRI = MF.getRegInfo();
2463 // Assuming a spill and reload of a value has a cost of 1 instruction each,
2464 // this helper function computes the maximum number of uses we should consider
2465 // for remat. E.g. on arm64 global addresses take 2 insts to materialize. We
2466 // break even in terms of code size when the original MI has 2 users vs
2467 // choosing to potentially spill. Any more than 2 users we we have a net code
2468 // size increase. This doesn't take into account register pressure though.
2469 auto maxUses = [](unsigned RematCost) {
2470 // A cost of 1 means remats are basically free.
2471 if (RematCost == 1)
2472 return std::numeric_limits<unsigned>::max();
2473 if (RematCost == 2)
2474 return 2U;
2475
2476 // Remat is too expensive, only sink if there's one user.
2477 if (RematCost > 2)
2478 return 1U;
2479 llvm_unreachable("Unexpected remat cost");
2480 };
2481
2482 switch (MI.getOpcode()) {
2483 default:
2484 return false;
2485 // Constants-like instructions should be close to their users.
2486 // We don't want long live-ranges for them.
2487 case TargetOpcode::G_CONSTANT:
2488 case TargetOpcode::G_FCONSTANT:
2489 case TargetOpcode::G_FRAME_INDEX:
2490 case TargetOpcode::G_INTTOPTR:
2491 return true;
2492 case TargetOpcode::G_GLOBAL_VALUE: {
2493 unsigned RematCost = TTI->getGISelRematGlobalCost();
2494 Register Reg = MI.getOperand(0).getReg();
2495 unsigned MaxUses = maxUses(RematCost);
2496 if (MaxUses == UINT_MAX)
2497 return true; // Remats are "free" so always localize.
2498 return MRI.hasAtMostUserInstrs(Reg, MaxUses);
2499 }
2500 }
2501}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
static LVOptions Options
Definition: LVOptions.cpp:25
#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
Register const TargetRegisterInfo * TRI
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static bool isDigit(const char C)
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:506
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:709
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the return value.
Definition: Attributes.h:860
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:213
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
LLVM_ABI unsigned getActiveBits() const
Compute the maximal number of active bits needed to represent every value in this range.
LLVM_ABI ConstantRange umul_sat(const ConstantRange &Other) const
Perform an unsigned saturating multiplication of two constant ranges.
LLVM_ABI ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
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
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
Definition: DataLayout.cpp:738
static constexpr ElementCount getScalable(ScalarTy MinVal)
Definition: TypeSize.h:315
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:312
constexpr bool isScalar() const
Exactly one element.
Definition: TypeSize.h:323
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:663
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:69
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:53
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:114
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition: IRBuilder.h:1891
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:201
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2508
LLVM_ABI 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:406
@ MAX_INT_BITS
Maximum number of bits that can be specified.
Definition: DerivedTypes.h:54
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:56
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
An instruction for reading from memory.
Definition: Instructions.h:180
Value * getPointerOperand()
Definition: Instructions.h:259
bool isVolatile() const
Return true if this is a load from a volatile memory location.
Definition: Instructions.h:209
Align getAlign() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:215
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.
LLVM_ABI 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:72
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:590
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
LLVM_ABI void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.
LLVM_ABI 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,.
LLVM_ABI 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.
LLVM_ABI 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:67
Class to represent pointers.
Definition: DerivedTypes.h:700
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:720
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1885
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:229
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:498
LLVMContext * getContext() const
Definition: SelectionDAG.h:511
size_t size() const
Definition: SmallVector.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
An instruction for storing to memory.
Definition: Instructions.h:296
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:710
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:581
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:154
static constexpr size_t npos
Definition: StringRef.h:57
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...
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
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.
MachineMemOperand::Flags getVPIntrinsicMemOperandFlags(const VPIntrinsic &VPIntrin) const
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.
ISD::CondCode getSoftFloatCmpLibcallPredicate(RTLIB::LibcallImpl Call) const
Get the comparison predicate that's to be used to test the result of the comparison libcall against z...
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...
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const
Get the libcall impl routine name for the specified libcall.
TargetLoweringBase(const TargetMachine &TM)
NOTE: The TargetMachine owns TLOF.
static StringRef getLibcallImplName(RTLIB::LibcallImpl Call)
Get the libcall routine name for the specified libcall implementation.
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...
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
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:83
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
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.
LLVM_ABI unsigned getGISelRematGlobalCost() const
bool isAndroid() const
Tests whether the target is Android.
Definition: Triple.h:816
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This is the common base class for vector predication intrinsics.
LLVM Value Representation.
Definition: Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
int getNumOccurrences() const
Definition: CommandLine.h:400
constexpr LeafTy coefficientNextPowerOf2() const
Definition: TypeSize.h:263
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:172
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:169
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:255
#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
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:41
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:801
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
Definition: ISDOpcodes.h:256
@ CTLZ_ZERO_UNDEF
Definition: ISDOpcodes.h:774
@ DELETED_NODE
DELETED_NODE - This is an illegal value that is used to catch errors.
Definition: ISDOpcodes.h:45
@ SET_FPENV
Sets the current floating-point environment.
Definition: ISDOpcodes.h:1108
@ VECREDUCE_SEQ_FADD
Generic reduction nodes.
Definition: ISDOpcodes.h:1458
@ VECREDUCE_SMIN
Definition: ISDOpcodes.h:1491
@ FGETSIGN
INT = FGETSIGN(FP) - Return the sign bit of the specified floating point value as an integer 0/1 valu...
Definition: ISDOpcodes.h:525
@ ATOMIC_LOAD_NAND
Definition: ISDOpcodes.h:1379
@ SMULFIX
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
Definition: ISDOpcodes.h:387
@ ConstantFP
Definition: ISDOpcodes.h:87
@ ATOMIC_LOAD_MAX
Definition: ISDOpcodes.h:1381
@ ATOMIC_LOAD_UMIN
Definition: ISDOpcodes.h:1382
@ ADDC
Carry-setting nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:289
@ RESET_FPENV
Set floating-point environment to default state.
Definition: ISDOpcodes.h:1112
@ FMAD
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations.
Definition: ISDOpcodes.h:515
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:259
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:1141
@ SMULFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:393
@ SET_FPMODE
Sets the current dynamic floating-point control modes.
Definition: ISDOpcodes.h:1131
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:835
@ VECTOR_FIND_LAST_ACTIVE
Definition: ISDOpcodes.h:1550
@ FMODF
FMODF - Decomposes the operand into integral and fractional parts, each having the same type and sign...
Definition: ISDOpcodes.h:1098
@ FATAN2
FATAN2 - atan2, inspired by libm.
Definition: ISDOpcodes.h:1020
@ FSINCOSPI
FSINCOSPI - Compute both the sine and cosine times pi more accurately than FSINCOS(pi*x),...
Definition: ISDOpcodes.h:1094
@ ATOMIC_CMP_SWAP_WITH_SUCCESS
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
Definition: ISDOpcodes.h:1364
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:862
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition: ISDOpcodes.h:571
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
Definition: ISDOpcodes.h:1476
@ FADD
Simple binary floating point operators.
Definition: ISDOpcodes.h:410
@ VECREDUCE_FMAXIMUM
FMINIMUM/FMAXIMUM nodes propatate NaNs and signed zeroes using the llvm.minimum and llvm....
Definition: ISDOpcodes.h:1480
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition: ISDOpcodes.h:738
@ RESET_FPMODE
Sets default dynamic floating-point control modes.
Definition: ISDOpcodes.h:1135
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition: ISDOpcodes.h:892
@ VECREDUCE_SMAX
Definition: ISDOpcodes.h:1490
@ ATOMIC_LOAD_OR
Definition: ISDOpcodes.h:1377
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:975
@ ATOMIC_LOAD_XOR
Definition: ISDOpcodes.h:1378
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Definition: ISDOpcodes.h:1018
@ SDIVFIX
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
Definition: ISDOpcodes.h:400
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:1568
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:826
@ AVGCEILS
AVGCEILS/AVGCEILU - Rounding averaging add - Add two integers using an integer of type i[N+2],...
Definition: ISDOpcodes.h:706
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
Definition: ISDOpcodes.h:1298
@ VECREDUCE_FADD
These reductions have relaxed evaluation order semantics, and have a single vector operand.
Definition: ISDOpcodes.h:1473
@ CTTZ_ZERO_UNDEF
Bit counting operators with an undefined result for zero inputs.
Definition: ISDOpcodes.h:773
@ PREFETCH
PREFETCH - This corresponds to a prefetch intrinsic.
Definition: ISDOpcodes.h:1331
@ TRUNCATE_SSAT_U
Definition: ISDOpcodes.h:855
@ VECREDUCE_FMIN
Definition: ISDOpcodes.h:1477
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
Definition: ISDOpcodes.h:1090
@ 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:809
@ FNEG
Perform various unary floating-point operations inspired by libm.
Definition: ISDOpcodes.h:1002
@ SSUBO
Same for subtraction.
Definition: ISDOpcodes.h:347
@ ATOMIC_LOAD_MIN
Definition: ISDOpcodes.h:1380
@ FCANONICALIZE
Returns platform specific canonical encoding of a floating point number.
Definition: ISDOpcodes.h:528
@ IS_FPCLASS
Performs a check of floating point class property, defined by IEEE-754.
Definition: ISDOpcodes.h:535
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition: ISDOpcodes.h:369
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:778
@ VECREDUCE_UMAX
Definition: ISDOpcodes.h:1492
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition: ISDOpcodes.h:663
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition: ISDOpcodes.h:343
@ VECREDUCE_ADD
Integer reductions may have a result type larger than the vector element type.
Definition: ISDOpcodes.h:1485
@ GET_FPMODE
Reads the current dynamic floating-point control modes.
Definition: ISDOpcodes.h:1126
@ GET_FPENV
Gets the current floating-point environment.
Definition: ISDOpcodes.h:1103
@ SHL
Shift and rotation operations.
Definition: ISDOpcodes.h:756
@ ATOMIC_LOAD_CLR
Definition: ISDOpcodes.h:1376
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:636
@ ATOMIC_LOAD_AND
Definition: ISDOpcodes.h:1375
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
Definition: ISDOpcodes.h:1075
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:563
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:832
@ DEBUGTRAP
DEBUGTRAP - Trap intended to get the attention of a debugger.
Definition: ISDOpcodes.h:1321
@ FP_TO_UINT_SAT
Definition: ISDOpcodes.h:928
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
Definition: ISDOpcodes.h:1358
@ ATOMIC_LOAD_UMAX
Definition: ISDOpcodes.h:1383
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum maximum on two values, following IEEE-754 definition...
Definition: ISDOpcodes.h:1059
@ UBSANTRAP
UBSANTRAP - Trap with an immediate describing the kind of sanitizer failure.
Definition: ISDOpcodes.h:1325
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
Definition: ISDOpcodes.h:379
@ SMULO
Same for multiplication.
Definition: ISDOpcodes.h:351
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
Definition: ISDOpcodes.h:881
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:870
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition: ISDOpcodes.h:718
@ SDIVFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:406
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:960
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:323
@ VECREDUCE_UMIN
Definition: ISDOpcodes.h:1493
@ ATOMIC_LOAD_ADD
Definition: ISDOpcodes.h:1373
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
Definition: ISDOpcodes.h:1081
@ ATOMIC_LOAD_SUB
Definition: ISDOpcodes.h:1374
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:908
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
Definition: ISDOpcodes.h:1292
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:730
@ TRAP
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:1318
@ GET_FPENV_MEM
Gets the current floating-point environment.
Definition: ISDOpcodes.h:1117
@ SCMP
[US]CMP - 3-way comparison of signed or unsigned integers.
Definition: ISDOpcodes.h:726
@ AVGFLOORS
AVGFLOORS/AVGFLOORU - Averaging add - Add two integers using an integer of type i[N+1],...
Definition: ISDOpcodes.h:701
@ VECREDUCE_FMUL
Definition: ISDOpcodes.h:1474
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:299
@ FREEZE
FREEZE - FREEZE(VAL) returns an arbitrary value if VAL is UNDEF (or is evaluated to UNDEF),...
Definition: ISDOpcodes.h:236
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition: ISDOpcodes.h:552
@ VECTOR_SPLICE
VECTOR_SPLICE(VEC1, VEC2, IMM) - Returns a subvector of the same type as VEC1/VEC2 from CONCAT_VECTOR...
Definition: ISDOpcodes.h:648
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
Definition: ISDOpcodes.h:1372
@ FFREXP
FFREXP - frexp, extract fractional and exponent component of a floating-point value.
Definition: ISDOpcodes.h:1025
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:941
@ VECTOR_COMPRESS
VECTOR_COMPRESS(Vec, Mask, Passthru) consecutively place vector elements based on mask e....
Definition: ISDOpcodes.h:690
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition: ISDOpcodes.h:903
@ ADDRSPACECAST
ADDRSPACECAST - This operator converts between pointers of different address spaces.
Definition: ISDOpcodes.h:979
@ 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:927
@ VECREDUCE_FMINIMUM
Definition: ISDOpcodes.h:1481
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:838
@ VECREDUCE_SEQ_FMUL
Definition: ISDOpcodes.h:1459
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:521
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition: ISDOpcodes.h:360
@ 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:1439
@ SET_FPENV_MEM
Sets the current floating point environment.
Definition: ISDOpcodes.h:1122
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
Definition: ISDOpcodes.h:1086
@ TRUNCATE_SSAT_S
TRUNCATE_[SU]SAT_[SU] - Truncate for saturated operand [SU] located in middle, prefix for SAT means i...
Definition: ISDOpcodes.h:853
@ ABDS
ABDS/ABDU - Absolute difference - Return the absolute difference between two numbers interpreted as s...
Definition: ISDOpcodes.h:713
@ TRUNCATE_USAT_U
Definition: ISDOpcodes.h:857
@ SADDO_CARRY
Carry-using overflow-aware nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:333
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1685
static const int LAST_INDEXED_MODE
Definition: ISDOpcodes.h:1636
LLVM_ABI Libcall getPOWI(EVT RetVT)
getPOWI - Return the POWI_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getSINTTOFP(EVT OpVT, EVT RetVT)
getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI 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.
LLVM_ABI Libcall getLDEXP(EVT RetVT)
getLDEXP - Return the LDEXP_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getUINTTOFP(EVT OpVT, EVT RetVT)
getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getFREXP(EVT RetVT)
getFREXP - Return the FREXP_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getSINCOSPI(EVT RetVT)
getSINCOSPI - Return the SINCOSPI_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getMEMCPY_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize)
getMEMCPY_ELEMENT_UNORDERED_ATOMIC - Return MEMCPY_ELEMENT_UNORDERED_ATOMIC_* value for the given ele...
LLVM_ABI Libcall getMODF(EVT RetVT)
getMODF - Return the MODF_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI 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,...
LLVM_ABI Libcall getFPTOUINT(EVT OpVT, EVT RetVT)
getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getCOS(EVT RetVT)
Return the COS_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getFPTOSINT(EVT OpVT, EVT RetVT)
getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI 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...
LLVM_ABI Libcall getFPEXT(EVT OpVT, EVT RetVT)
getFPEXT - Return the FPEXT_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getFPROUND(EVT OpVT, EVT RetVT)
getFPROUND - Return the FPROUND_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getSIN(EVT RetVT)
Return the SIN_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getMEMSET_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize)
getMEMSET_ELEMENT_UNORDERED_ATOMIC - Return MEMSET_ELEMENT_UNORDERED_ATOMIC_* value for the given ele...
LLVM_ABI Libcall getPOW(EVT RetVT)
getPOW - Return the POW_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI 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...
LLVM_ABI Libcall getSINCOS(EVT RetVT)
getSINCOS - Return the SINCOS_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI 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:444
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:349
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1764
LLVM_ABI 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
LLVM_ABI 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:232
LLVM_ABI 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:295
void ComputeValueTypes(const DataLayout &DL, Type *Ty, SmallVectorImpl< Type * > &Types, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
Given an LLVM IR type, compute non-aggregate subtypes.
Definition: Analysis.cpp:72
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:288
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:1758
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
AtomicOrdering
Atomic ordering for LLVM's memory model.
LLVM_ABI EVT getApproximateEVTForLLT(LLT Ty, LLVMContext &Ctx)
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:399
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ FMul
Product of floats.
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
@ FAdd
Sum of floats.
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
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:216
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...
Matching combinators.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
static RTLIB::Libcall getLibcallFromImpl(RTLIB::LibcallImpl Impl)
Return the libcall provided by Impl.
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...