LLVM: include/llvm/ADT/APInt.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_ADT_APINT_H
16#define LLVM_ADT_APINT_H
17
21#include
22#include
23#include
24#include
25#include
26
27namespace llvm {
28class FoldingSetNodeID;
29class StringRef;
30class hash_code;
31class raw_ostream;
33class DynamicAPInt;
34
35template class SmallVectorImpl;
36template class ArrayRef;
37template <typename T, typename Enable> struct DenseMapInfo;
38
39class APInt;
40
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
79public:
81
82
83 static constexpr unsigned APINT_WORD_SIZE = sizeof(WordType);
84
85
86 static constexpr unsigned APINT_BITS_PER_WORD = APINT_WORD_SIZE * CHAR_BIT;
87
89 DOWN,
90 TOWARD_ZERO,
91 UP,
92 };
93
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
112 bool implicitTrunc = false)
114 if (!implicitTrunc) {
118 "Value must be 0 or -1 for signed 0-bit APInt");
119 } else {
121 "Value is not an N-bit signed value");
122 }
123 } else {
125 assert(val == 0 && "Value must be zero for unsigned 0-bit APInt");
126 } else {
128 "Value is not an N-bit unsigned value");
129 }
130 }
131 }
132 if (isSingleWord()) {
133 U.VAL = val;
134 if (implicitTrunc || isSigned)
136 } else {
138 }
139 }
140
141
142
143
144
145
146
147
149
150
151
152
153
154
155
156
157 APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
158
159
160
161
162
163
164
165
166
167
168
169
171
172
173 explicit APInt() { U.VAL = 0; }
174
175
177 if (isSingleWord())
178 U.VAL = that.U.VAL;
179 else
180 initSlowCase(that);
181 }
182
183
185 memcpy(&U, &that.U, sizeof(U));
186 that.BitWidth = 0;
187 }
188
189
191 if (needsCleanup())
192 delete[] U.pVal;
193 }
194
195
196
197
198
199
201
202
204
205
206 static APInt getMaxValue(unsigned numBits) { return getAllOnes(numBits); }
207
208
210 APInt API = getAllOnes(numBits);
212 return API;
213 }
214
215
217
218
220 APInt API(numBits, 0);
221 API.setBit(numBits - 1);
222 return API;
223 }
224
225
226
227
228
230 return getSignedMinValue(BitWidth);
231 }
232
233
235 return APInt(numBits, WORDTYPE_MAX, true);
236 }
237
238
240 APInt Res(numBits, 0);
242 return Res;
243 }
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258 static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit) {
259 APInt Res(numBits, 0);
260 Res.setBits(loBit, hiBit);
261 return Res;
262 }
263
264
265
266
267
268
269
271 unsigned hiBit) {
272 APInt Res(numBits, 0);
274 return Res;
275 }
276
277
278
279
280
281
282
283
284
285
287 APInt Res(numBits, 0);
289 return Res;
290 }
291
292
293
294
295
297 APInt Res(numBits, 0);
299 return Res;
300 }
301
302
303
304
305
307 APInt Res(numBits, 0);
309 return Res;
310 }
311
312
313 static APInt getSplat(unsigned NewLen, const APInt &V);
314
315
316
317
318
319
320
321
323
324
325
326
327
328
330
331
332
333
335
336
337
338
339
340
342
343
344
345
346
347
349
350
351
352
353
354
355
357
358
359
360
362
363
364
365
367 return (*this)[BitNo] && popcount() == 1;
368 }
369
370
373 return true;
374 if (isSingleWord())
375 return U.VAL == WORDTYPE_MAX >> (APINT_BITS_PER_WORD - BitWidth);
376 return countTrailingOnesSlowCase() == BitWidth;
377 }
378
379
381 if (isSingleWord())
382 return U.VAL == 0;
383 return countLeadingZerosSlowCase() == BitWidth;
384 }
385
386
387
388
390 if (isSingleWord())
391 return U.VAL == 1;
392 return countLeadingZerosSlowCase() == BitWidth - 1;
393 }
394
395
396
397
398
400
401
402
403
404
406 if (isSingleWord()) {
409 }
410 return !isNegative() && countTrailingOnesSlowCase() == BitWidth - 1;
411 }
412
413
414
415
416
418
419
420
421
422
424 if (isSingleWord()) {
427 }
428 return isNegative() && countTrailingZerosSlowCase() == BitWidth - 1;
429 }
430
431
432 bool isIntN(unsigned N) const { return getActiveBits() <= N; }
433
434
435 bool isSignedIntN(unsigned N) const { return getSignificantBits() <= N; }
436
437
438
439
441 if (isSingleWord()) {
444 }
445 return countPopulationSlowCase() == 1;
446 }
447
448
451 if (isNonNegative())
452 return false;
453
456 return (LO + TZ) == BitWidth;
457 }
458
459
460
462
463
464
465
466 bool isSignMask() const { return isMinSignedValue(); }
467
468
469
470
472
473
474
476 return ugt(Limit) ? Limit : getZExtValue();
477 }
478
479
480
481
482
483
484 bool isSplat(unsigned SplatSizeInBits) const;
485
486
487
488 bool isMask(unsigned numBits) const {
489 assert(numBits != 0 && "numBits must be non-zero");
490 assert(numBits <= BitWidth && "numBits out of range");
491 if (isSingleWord())
492 return U.VAL == (WORDTYPE_MAX >> (APINT_BITS_PER_WORD - numBits));
493 unsigned Ones = countTrailingOnesSlowCase();
494 return (numBits == Ones) &&
495 ((Ones + countLeadingZerosSlowCase()) == BitWidth);
496 }
497
498
499
500
502 if (isSingleWord())
504 unsigned Ones = countTrailingOnesSlowCase();
505 return (Ones > 0) && ((Ones + countLeadingZerosSlowCase()) == BitWidth);
506 }
507
508
509
511 if (isSingleWord())
513 unsigned Ones = countPopulationSlowCase();
514 unsigned LeadZ = countLeadingZerosSlowCase();
515 return (Ones + LeadZ + countTrailingZerosSlowCase()) == BitWidth;
516 }
517
518
519
520
521
522 bool isShiftedMask(unsigned &MaskIdx, unsigned &MaskLen) const {
523 if (isSingleWord())
525 unsigned Ones = countPopulationSlowCase();
526 unsigned LeadZ = countLeadingZerosSlowCase();
527 unsigned TrailZ = countTrailingZerosSlowCase();
528 if ((Ones + LeadZ + TrailZ) != BitWidth)
529 return false;
530 MaskLen = Ones;
531 MaskIdx = TrailZ;
532 return true;
533 }
534
535
536
537
538
539
540
541 APInt getHiBits(unsigned numBits) const;
542
543
544
545
546
547
548
549 APInt getLoBits(unsigned numBits) const;
550
551
552
554 if (I1.getBitWidth() == I2.getBitWidth())
555 return I1 == I2;
556
558 return I1 == I2.zext(I1.getBitWidth());
559
561 }
562
563
565
566
567
568
570 if (isSingleWord())
571 return &U.VAL;
572 return &U.pVal[0];
573 }
574
575
576
577
578
579
580
581
583 APInt API(*this);
584 ++(*this);
585 return API;
586 }
587
588
589
590
591 APInt &operator++();
592
593
594
595
597 APInt API(*this);
598 --(*this);
599 return API;
600 }
601
602
603
604
605 APInt &operator--();
606
607
608
610
611
612
613
614
615
616
617
619
620
621 if (isSingleWord() && RHS.isSingleWord()) {
622 U.VAL = RHS.U.VAL;
624 return *this;
625 }
626
627 assignSlowCase(RHS);
628 return *this;
629 }
630
631
633#ifdef EXPENSIVE_CHECKS
634
635 if (this == &that)
636 return *this;
637#endif
638 assert(this != &that && "Self-move not supported");
639 if (!isSingleWord())
640 delete[] U.pVal;
641
642
643
644 memcpy(&U, &that.U, sizeof(U));
645
647 that.BitWidth = 0;
648 return *this;
649 }
650
651
652
653
654
655
656
657
659 if (isSingleWord()) {
660 U.VAL = RHS;
662 }
663 U.pVal[0] = RHS;
664 memset(U.pVal + 1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
665 return *this;
666 }
667
668
669
670
671
672
673
675 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
676 if (isSingleWord())
677 U.VAL &= RHS.U.VAL;
678 else
679 andAssignSlowCase(RHS);
680 return *this;
681 }
682
683
684
685
686
687
689 if (isSingleWord()) {
690 U.VAL &= RHS;
691 return *this;
692 }
693 U.pVal[0] &= RHS;
694 memset(U.pVal + 1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
695 return *this;
696 }
697
698
699
700
701
702
703
705 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
706 if (isSingleWord())
707 U.VAL |= RHS.U.VAL;
708 else
709 orAssignSlowCase(RHS);
710 return *this;
711 }
712
713
714
715
716
717
719 if (isSingleWord()) {
720 U.VAL |= RHS;
722 }
723 U.pVal[0] |= RHS;
724 return *this;
725 }
726
727
728
729
730
731
732
734 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
735 if (isSingleWord())
736 U.VAL ^= RHS.U.VAL;
737 else
738 xorAssignSlowCase(RHS);
739 return *this;
740 }
741
742
743
744
745
746
748 if (isSingleWord()) {
749 U.VAL ^= RHS;
751 }
752 U.pVal[0] ^= RHS;
753 return *this;
754 }
755
756
757
758
759
760
763
764
765
766
767
768
771
772
773
774
775
776
779
780
781
782
783
784
786 assert(ShiftAmt <= BitWidth && "Invalid shift amount");
787 if (isSingleWord()) {
789 U.VAL = 0;
790 else
791 U.VAL <<= ShiftAmt;
793 }
794 shlSlowCase(ShiftAmt);
795 return *this;
796 }
797
798
799
800
801
802
803 APInt &operator<<=(const APInt &ShiftAmt);
804
805
806
807
808
809
810
811
813
814
815
816
818
819
820
821
823
824
825
826
829 R.ashrInPlace(ShiftAmt);
830 return R;
831 }
832
833
835 assert(ShiftAmt <= BitWidth && "Invalid shift amount");
836 if (isSingleWord()) {
839 U.VAL = SExtVAL >> (APINT_BITS_PER_WORD - 1);
840 else
841 U.VAL = SExtVAL >> ShiftAmt;
843 return;
844 }
845 ashrSlowCase(ShiftAmt);
846 }
847
848
849
850
853 R.lshrInPlace(shiftAmt);
854 return R;
855 }
856
857
859 assert(ShiftAmt <= BitWidth && "Invalid shift amount");
860 if (isSingleWord()) {
862 U.VAL = 0;
863 else
864 U.VAL >>= ShiftAmt;
865 return;
866 }
867 lshrSlowCase(ShiftAmt);
868 }
869
870
871
872
875 R <<= shiftAmt;
876 return R;
877 }
878
879
881 return RelativeShift > 0 ? lshr(RelativeShift) : shl(-RelativeShift);
882 }
883
884
886 return relativeLShr(-RelativeShift);
887 }
888
889
891 return RelativeShift > 0 ? ashr(RelativeShift) : shl(-RelativeShift);
892 }
893
894
896 return relativeAShr(-RelativeShift);
897 }
898
899
900 APInt rotl(unsigned rotateAmt) const;
901
902
903 APInt rotr(unsigned rotateAmt) const;
904
905
906
907
910 R.ashrInPlace(ShiftAmt);
911 return R;
912 }
913
914
915 void ashrInPlace(const APInt &shiftAmt);
916
917
918
919
922 R.lshrInPlace(ShiftAmt);
923 return R;
924 }
925
926
927 void lshrInPlace(const APInt &ShiftAmt);
928
929
930
931
934 R <<= ShiftAmt;
935 return R;
936 }
937
938
940
941
943
944
945
946
948
950 if (NewWidth <= APINT_BITS_PER_WORD)
952 return concatSlowCase(NewLSB);
953 }
954
955
956
957
958
959
960
961
964
965
966
967
968
969
971 APInt sdiv(int64_t RHS) const;
972
973
974
975
976
977
978
979
982
983
984
985
986
987
988
990 int64_t srem(int64_t RHS) const;
991
992
993
994
995
996
997
998
1000 APInt &Remainder);
1003
1005 APInt &Remainder);
1006 static void sdivrem(const APInt &LHS, int64_t RHS, APInt &Quotient,
1007 int64_t &Remainder);
1008
1009
1010 APInt sadd_ov(const APInt &RHS, bool &Overflow) const;
1011 APInt uadd_ov(const APInt &RHS, bool &Overflow) const;
1012 APInt ssub_ov(const APInt &RHS, bool &Overflow) const;
1013 APInt usub_ov(const APInt &RHS, bool &Overflow) const;
1014 APInt sdiv_ov(const APInt &RHS, bool &Overflow) const;
1015 APInt smul_ov(const APInt &RHS, bool &Overflow) const;
1017 APInt sshl_ov(const APInt &Amt, bool &Overflow) const;
1018 APInt sshl_ov(unsigned Amt, bool &Overflow) const;
1019 APInt ushl_ov(const APInt &Amt, bool &Overflow) const;
1020 APInt ushl_ov(unsigned Amt, bool &Overflow) const;
1021
1022
1023
1024
1025
1026 APInt sfloordiv_ov(const APInt &RHS, bool &Overflow) const;
1027
1028
1036 APInt sshl_sat(unsigned RHS) const;
1038 APInt ushl_sat(unsigned RHS) const;
1039
1040
1041
1042
1044 assert(bitPosition < getBitWidth() && "Bit position out of bounds!");
1045 return (maskBit(bitPosition) & getWord(bitPosition)) != 0;
1046 }
1047
1048
1049
1050
1051
1052
1053
1054
1055
1057 assert(BitWidth == RHS.BitWidth && "Comparison requires equal bit widths");
1058 if (isSingleWord())
1059 return U.VAL == RHS.U.VAL;
1060 return equalSlowCase(RHS);
1061 }
1062
1063
1064
1065
1066
1067
1068
1070 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() == Val;
1071 }
1072
1073
1074
1075
1076
1077
1078
1080
1081
1082
1083
1084
1085
1086
1088
1089
1090
1091
1092
1093
1094
1096
1097
1098
1099
1100
1101
1102
1104
1105
1106
1107
1108
1109
1110
1112
1113
1114
1115
1116
1117
1118
1120
1121 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() < RHS;
1122 }
1123
1124
1125
1126
1127
1128
1129
1131
1132
1133
1134
1135
1136
1137
1139 return (!isSingleWord() && getSignificantBits() > 64)
1140 ? isNegative()
1141 : getSExtValue() < RHS;
1142 }
1143
1144
1145
1146
1147
1148
1149
1151
1152
1153
1154
1155
1156
1157
1159
1160
1161
1162
1163
1164
1165
1166 bool sle(const APInt &RHS) const { return compareSigned(RHS) <= 0; }
1167
1168
1169
1170
1171
1172
1173
1175
1176
1177
1178
1179
1180
1181
1183
1184
1185
1186
1187
1188
1189
1191
1192 return (!isSingleWord() && getActiveBits() > 64) || getZExtValue() > RHS;
1193 }
1194
1195
1196
1197
1198
1199
1200
1202
1203
1204
1205
1206
1207
1208
1210 return (!isSingleWord() && getSignificantBits() > 64)
1211 ? !isNegative()
1212 : getSExtValue() > RHS;
1213 }
1214
1215
1216
1217
1218
1219
1220
1222
1223
1224
1225
1226
1227
1228
1230
1231
1232
1233
1234
1235
1236
1238
1239
1240
1241
1242
1243
1244
1245 bool sge(int64_t RHS) const { return !slt(RHS); }
1246
1247
1248
1250 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
1251 if (isSingleWord())
1252 return (U.VAL & RHS.U.VAL) != 0;
1253 return intersectsSlowCase(RHS);
1254 }
1255
1256
1258 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
1259 if (isSingleWord())
1260 return (U.VAL & ~RHS.U.VAL) == 0;
1261 return isSubsetOfSlowCase(RHS);
1262 }
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272 APInt trunc(unsigned width) const;
1273
1274
1275
1276
1277
1278 APInt truncUSat(unsigned width) const;
1279
1280
1281
1282
1283
1284
1285 APInt truncSSat(unsigned width) const;
1286
1287
1288
1289
1290
1291
1292
1293 APInt sext(unsigned width) const;
1294
1295
1296
1297
1298
1299
1300 APInt zext(unsigned width) const;
1301
1302
1303
1304
1305
1306 APInt sextOrTrunc(unsigned width) const;
1307
1308
1309
1310
1311
1312 APInt zextOrTrunc(unsigned width) const;
1313
1314
1315
1316
1317
1318
1320 if (isSingleWord())
1321 U.VAL = WORDTYPE_MAX;
1322 else
1323
1324 memset(U.pVal, -1, getNumWords() * APINT_WORD_SIZE);
1325
1327 }
1328
1329
1331 assert(BitPosition < BitWidth && "BitPosition out of range");
1332 WordType Mask = maskBit(BitPosition);
1333 if (isSingleWord())
1334 U.VAL |= Mask;
1335 else
1336 U.pVal[whichWord(BitPosition)] |= Mask;
1337 }
1338
1339
1341
1342
1343 void setBitVal(unsigned BitPosition, bool BitValue) {
1344 if (BitValue)
1345 setBit(BitPosition);
1346 else
1347 clearBit(BitPosition);
1348 }
1349
1350
1351
1352
1353
1357 if (loBit < hiBit) {
1358 setBits(loBit, hiBit);
1359 return;
1360 }
1361 setLowBits(hiBit);
1362 setHighBits(BitWidth - loBit);
1363 }
1364
1365
1366
1367 void setBits(unsigned loBit, unsigned hiBit) {
1370 assert(loBit <= hiBit && "loBit greater than hiBit");
1371 if (loBit == hiBit)
1372 return;
1373 if (loBit < APINT_BITS_PER_WORD && hiBit <= APINT_BITS_PER_WORD) {
1374 uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
1375 mask <<= loBit;
1376 if (isSingleWord())
1377 U.VAL |= mask;
1378 else
1379 U.pVal[0] |= mask;
1380 } else {
1381 setBitsSlowCase(loBit, hiBit);
1382 }
1383 }
1384
1385
1387
1388
1389 void setLowBits(unsigned loBits) { return setBits(0, loBits); }
1390
1391
1394 }
1395
1396
1398 if (isSingleWord())
1399 U.VAL = 0;
1400 else
1401 memset(U.pVal, 0, getNumWords() * APINT_WORD_SIZE);
1402 }
1403
1404
1405
1406
1408 assert(BitPosition < BitWidth && "BitPosition out of range");
1409 WordType Mask = ~maskBit(BitPosition);
1410 if (isSingleWord())
1411 U.VAL &= Mask;
1412 else
1413 U.pVal[whichWord(BitPosition)] &= Mask;
1414 }
1415
1416
1418 assert(loBits <= BitWidth && "More bits than bitwidth");
1420 *this &= Keep;
1421 }
1422
1423
1425 assert(hiBits <= BitWidth && "More bits than bitwidth");
1427 *this &= Keep;
1428 }
1429
1430
1432
1433
1435 if (isSingleWord()) {
1436 U.VAL ^= WORDTYPE_MAX;
1438 } else {
1439 flipAllBitsSlowCase();
1440 }
1441 }
1442
1443
1444
1445
1446
1447 void flipBit(unsigned bitPosition);
1448
1449
1451 flipAllBits();
1452 ++(*this);
1453 }
1454
1455
1456 void insertBits(const APInt &SubBits, unsigned bitPosition);
1457 void insertBits(uint64_t SubBits, unsigned bitPosition, unsigned numBits);
1458
1459
1460 APInt extractBits(unsigned numBits, unsigned bitPosition) const;
1461 uint64_t extractBitsAsZExtValue(unsigned numBits, unsigned bitPosition) const;
1462
1463
1464
1465
1466
1467
1469
1470
1471
1472
1473
1474
1476
1477
1478
1479
1480
1481
1482
1484 return ((uint64_t)BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
1485 }
1486
1487
1488
1489
1490
1491
1493
1494
1495
1496
1497
1499 unsigned numActiveBits = getActiveBits();
1500 return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
1501 }
1502
1503
1504
1505
1506
1507
1508
1509
1510
1512 return BitWidth - getNumSignBits() + 1;
1513 }
1514
1515
1516
1517
1518
1519
1521 if (isSingleWord())
1522 return U.VAL;
1523 assert(getActiveBits() <= 64 && "Too many bits for uint64_t");
1524 return U.pVal[0];
1525 }
1526
1527
1528
1529
1530
1531
1533 return (getActiveBits() <= 64) ? std::optional<uint64_t>(getZExtValue())
1534 : std::nullopt;
1535 };
1536
1537
1538
1539
1540
1541
1543 if (isSingleWord())
1545 assert(getSignificantBits() <= 64 && "Too many bits for int64_t");
1546 return int64_t(U.pVal[0]);
1547 }
1548
1549
1550
1551
1552
1553
1555 return (getSignificantBits() <= 64) ? std::optional<int64_t>(getSExtValue())
1556 : std::nullopt;
1557 };
1558
1559
1560
1561
1562
1563 static unsigned getBitsNeeded(StringRef str, uint8_t radix);
1564
1565
1566
1567
1568 static unsigned getSufficientBitsNeeded(StringRef Str, uint8_t Radix);
1569
1570
1571
1572
1573
1574
1575
1576
1578 if (isSingleWord()) {
1579 unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
1581 }
1582 return countLeadingZerosSlowCase();
1583 }
1584
1586
1587
1588
1589
1590
1591
1592
1593
1595 if (isSingleWord()) {
1597 return 0;
1599 }
1600 return countLeadingOnesSlowCase();
1601 }
1602
1604
1605
1606
1609 }
1610
1611
1612
1613
1614
1615
1616
1617
1619 if (isSingleWord()) {
1621 return (TrailingZeros > BitWidth ? BitWidth : TrailingZeros);
1622 }
1623 return countTrailingZerosSlowCase();
1624 }
1625
1627
1628
1629
1630
1631
1632
1633
1634
1636 if (isSingleWord())
1638 return countTrailingOnesSlowCase();
1639 }
1640
1642
1643
1644
1645
1646
1647
1648
1650 if (isSingleWord())
1652 return countPopulationSlowCase();
1653 }
1654
1655
1656
1657
1659
1660
1661
1662
1664 bool formatAsCLiteral = false, bool UpperCase = true,
1665 bool InsertSeparators = false) const;
1666
1667
1668
1670 toString(Str, Radix, false, false);
1671 }
1672
1673
1674
1676 toString(Str, Radix, true, false);
1677 }
1678
1679
1680 APInt byteSwap() const;
1681
1682
1683
1685
1686
1687 double roundToDouble(bool isSigned) const;
1688
1689
1691
1692
1694
1695
1696
1697
1698
1699
1700 double bitsToDouble() const { return llvm::bit_cast(getWord(0)); }
1701
1702#ifdef HAS_IEE754_FLOAT128
1703 float128 bitsToQuad() const {
1704 __uint128_t ul = ((__uint128_t)U.pVal[1] << 64) + U.pVal[0];
1705 return llvm::bit_cast(ul);
1706 }
1707#endif
1708
1709
1710
1711
1712
1713
1715 return llvm::bit_cast(static_cast<uint32_t>(getWord(0)));
1716 }
1717
1718
1719
1720
1721
1723 return APInt(sizeof(double) * CHAR_BIT, llvm::bit_cast<uint64_t>(V));
1724 }
1725
1726
1727
1728
1729
1731 return APInt(sizeof(float) * CHAR_BIT, llvm::bit_cast<uint32_t>(V));
1732 }
1733
1734
1735
1736
1737
1738
1739 unsigned logBase2() const { return getActiveBits() - 1; }
1740
1741
1743 APInt temp(*this);
1744 --temp;
1746 }
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757 unsigned nearestLogBase2() const;
1758
1759
1760
1762 if (!isPowerOf2())
1763 return -1;
1764 return logBase2();
1765 }
1766
1767
1768 APInt sqrt() const;
1769
1770
1771
1772
1774 if (isNegative())
1775 return -(*this);
1776 return *this;
1777 }
1778
1779
1780 APInt multiplicativeInverse() const;
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794 static void tcSet(WordType *, WordType, unsigned);
1795
1796
1797 static void tcAssign(WordType *, const WordType *, unsigned);
1798
1799
1800 static bool tcIsZero(const WordType *, unsigned);
1801
1802
1803 static int tcExtractBit(const WordType *, unsigned bit);
1804
1805
1806
1807
1808
1809 static void tcExtract(WordType *, unsigned dstCount, const WordType *,
1810 unsigned srcBits, unsigned srcLSB);
1811
1812
1813 static void tcSetBit(WordType *, unsigned bit);
1814
1815
1816 static void tcClearBit(WordType *, unsigned bit);
1817
1818
1819
1820 static unsigned tcLSB(const WordType *, unsigned n);
1821 static unsigned tcMSB(const WordType *parts, unsigned n);
1822
1823
1824 static void tcNegate(WordType *, unsigned);
1825
1826
1827 static WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned);
1828
1829 static WordType tcAddPart(WordType *, WordType, unsigned);
1830
1831
1832 static WordType tcSubtract(WordType *, const WordType *, WordType carry,
1833 unsigned);
1834
1835 static WordType tcSubtractPart(WordType *, WordType, unsigned);
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847 static int tcMultiplyPart(WordType *dst, const WordType *src,
1848 WordType multiplier, WordType carry,
1849 unsigned srcParts, unsigned dstParts, bool add);
1850
1851
1852
1853
1854
1855 static int tcMultiply(WordType *, const WordType *, const WordType *,
1856 unsigned);
1857
1858
1859
1860 static void tcFullMultiply(WordType *, const WordType *, const WordType *,
1861 unsigned, unsigned);
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872 static int tcDivide(WordType *lhs, const WordType *rhs, WordType *remainder,
1873 WordType *scratch, unsigned parts);
1874
1875
1876
1877 static void tcShiftLeft(WordType *, unsigned Words, unsigned Count);
1878
1879
1880
1881 static void tcShiftRight(WordType *, unsigned Words, unsigned Count);
1882
1883
1884 static int tcCompare(const WordType *, const WordType *, unsigned);
1885
1886
1888 return tcAddPart(dst, 1, parts);
1889 }
1890
1891
1893 return tcSubtractPart(dst, 1, parts);
1894 }
1895
1896
1897
1899
1900
1901 void dump() const;
1902
1903
1905
1906private:
1907
1908
1909 union {
1912 } U;
1913
1915
1918
1919
1921
1922
1923
1924
1926
1927
1928
1929
1930 static unsigned whichWord(unsigned bitPosition) {
1931 return bitPosition / APINT_BITS_PER_WORD;
1932 }
1933
1934
1935 static unsigned whichBit(unsigned bitPosition) {
1936 return bitPosition % APINT_BITS_PER_WORD;
1937 }
1938
1939
1940
1941
1942
1943
1944
1945 static uint64_t maskBit(unsigned bitPosition) {
1946 return 1ULL << whichBit(bitPosition);
1947 }
1948
1949
1950
1951
1952
1953
1954
1956
1957 unsigned WordBits = ((BitWidth - 1) % APINT_BITS_PER_WORD) + 1;
1958
1959
1960 uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - WordBits);
1962 mask = 0;
1963
1964 if (isSingleWord())
1965 U.VAL &= mask;
1966 else
1967 U.pVal[getNumWords() - 1] &= mask;
1968 return *this;
1969 }
1970
1971
1972
1973 uint64_t getWord(unsigned bitPosition) const {
1974 return isSingleWord() ? U.VAL : U.pVal[whichWord(bitPosition)];
1975 }
1976
1977
1978
1979
1980 void reallocate(unsigned NewBitWidth);
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994 void fromString(unsigned numBits, StringRef str, uint8_t radix);
1995
1996
1997
1998
1999
2000
2001
2002 static void divide(const WordType *LHS, unsigned lhsWords,
2003 const WordType *RHS, unsigned rhsWords, WordType *Quotient,
2004 WordType *Remainder);
2005
2006
2008
2009
2010 void initFromArray(ArrayRef<uint64_t> array);
2011
2012
2013 void initSlowCase(const APInt &that);
2014
2015
2016 void shlSlowCase(unsigned ShiftAmt);
2017
2018
2019 void lshrSlowCase(unsigned ShiftAmt);
2020
2021
2022 void ashrSlowCase(unsigned ShiftAmt);
2023
2024
2025 void assignSlowCase(const APInt &RHS);
2026
2027
2029
2030
2032
2033
2035
2036
2038
2039
2041
2042
2044
2045
2047
2048
2050
2051
2052 void setBitsSlowCase(unsigned loBit, unsigned hiBit);
2053
2054
2055 void flipAllBitsSlowCase();
2056
2057
2058 APInt concatSlowCase(const APInt &NewLSB) const;
2059
2060
2061 void andAssignSlowCase(const APInt &RHS);
2062
2063
2064 void orAssignSlowCase(const APInt &RHS);
2065
2066
2067 void xorAssignSlowCase(const APInt &RHS);
2068
2069
2070
2072
2073
2074
2076
2077
2078};
2079
2081
2083
2084
2085
2086
2088 v.flipAllBits();
2089 return v;
2090}
2091
2093 a &= b;
2094 return a;
2095}
2096
2098 b &= a;
2099 return std::move(b);
2100}
2101
2103 a &= RHS;
2104 return a;
2105}
2106
2108 b &= LHS;
2109 return b;
2110}
2111
2113 a |= b;
2114 return a;
2115}
2116
2118 b |= a;
2119 return std::move(b);
2120}
2121
2123 a |= RHS;
2124 return a;
2125}
2126
2128 b |= LHS;
2129 return b;
2130}
2131
2133 a ^= b;
2134 return a;
2135}
2136
2138 b ^= a;
2139 return std::move(b);
2140}
2141
2143 a ^= RHS;
2144 return a;
2145}
2146
2148 b ^= LHS;
2149 return b;
2150}
2151
2154 return OS;
2155}
2156
2158 v.negate();
2159 return v;
2160}
2161
2163 a += b;
2164 return a;
2165}
2166
2168 b += a;
2169 return std::move(b);
2170}
2171
2173 a += RHS;
2174 return a;
2175}
2176
2178 b += LHS;
2179 return b;
2180}
2181
2183 a -= b;
2184 return a;
2185}
2186
2188 b.negate();
2189 b += a;
2190 return std::move(b);
2191}
2192
2194 a -= RHS;
2195 return a;
2196}
2197
2199 b.negate();
2200 b += LHS;
2201 return b;
2202}
2203
2205 a *= RHS;
2206 return a;
2207}
2208
2210 b *= LHS;
2211 return b;
2212}
2213
2214namespace APIntOps {
2215
2216
2219}
2220
2221
2224}
2225
2226
2229}
2230
2231
2234}
2235
2236
2238 return A.sge(B) ? (A - B) : (B - A);
2239}
2240
2241
2243 return A.uge(B) ? (A - B) : (B - A);
2244}
2245
2246
2248
2249
2251
2252
2254
2255
2257
2258
2259
2261
2262
2263
2265
2266
2267
2269
2270
2271
2272
2273
2274
2275
2277
2278
2279
2280
2283}
2284
2285
2286
2287
2290}
2291
2292
2295}
2296
2297
2298
2299
2302}
2303
2304
2305
2306
2307APInt RoundDoubleToAPInt(double Double, unsigned width);
2308
2309
2310
2311
2314}
2315
2316
2318
2319
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355std::optional SolveQuadraticEquationWrap(APInt A, APInt B, APInt C,
2356 unsigned RangeWidth);
2357
2358
2359
2360std::optional GetMostSignificantDifferentBit(const APInt &A,
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374APInt ScaleBitMask(const APInt &A, unsigned NewBitWidth,
2375 bool MatchAllBits = false);
2376}
2377
2378
2379
2380hash_code hash_value(const APInt &Arg);
2381
2382
2383
2384void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst, unsigned StoreBytes);
2385
2386
2387
2388void LoadIntFromMemory(APInt &IntVal, const uint8_t *Src, unsigned LoadBytes);
2389
2390
2393 APInt V(nullptr, 0);
2394 V.U.VAL = ~0ULL;
2395 return V;
2396 }
2397
2399 APInt V(nullptr, 0);
2400 V.U.VAL = ~1ULL;
2401 return V;
2402 }
2403
2405
2407 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
2408 }
2409};
2410
2411}
2412
2413#endif
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
raw_ostream & operator<<(raw_ostream &OS, const binary_le_impl< value_type > &BLE)
#define LLVM_UNLIKELY(EXPR)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool isSigned(unsigned int Opcode)
static KnownBits extractBits(unsigned BitWidth, const KnownBits &SrcOpKnown, const KnownBits &OffsetKnown, const KnownBits &WidthKnown)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
static bool isAligned(const Value *Base, Align Alignment, const DataLayout &DL)
static bool isSplat(Value *V)
Return true if V is a splat of a value (which is used when multiplying a matrix with a scalar).
static const char * toString(MIToken::TokenKind TokenKind)
static uint64_t clearUnusedBits(uint64_t Val, unsigned Size)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static uint64_t umul_ov(uint64_t i, uint64_t j, bool &Overflow)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Class for arbitrary precision integers.
std::optional< uint64_t > tryZExtValue() const
Get zero extended value if possible.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
bool slt(int64_t RHS) const
Signed less than comparison.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
APInt relativeLShr(int RelativeShift) const
relative logical shift right
bool isNegatedPowerOf2() const
Check if this APInt's negated value is a power of two greater than zero.
APInt zext(unsigned width) const
Zero extend to a new width.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
APInt operator--(int)
Postfix decrement operator.
uint64_t getZExtValue() const
Get zero extended value.
uint64_t * pVal
Used to store the >64 bits integer value.
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
unsigned popcount() const
Count the number of bits set.
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
APInt operator<<(const APInt &Bits) const
Left logical shift operator.
APInt operator<<(unsigned Bits) const
Left logical shift operator.
unsigned getActiveBits() const
Compute the number of active bits in the value.
bool sgt(int64_t RHS) const
Signed greater than comparison.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
bool operator[](unsigned bitPosition) const
Array-indexing support.
bool operator!=(const APInt &RHS) const
Inequality operator.
void toStringUnsigned(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be unsigned and converts it into a string in the radix given.
APInt & operator&=(const APInt &RHS)
Bitwise AND assignment operator.
APInt abs() const
Get the absolute value.
unsigned ceilLogBase2() const
unsigned countLeadingOnes() const
APInt relativeLShl(int RelativeShift) const
relative logical shift left
APInt & operator=(const APInt &RHS)
Copy assignment operator.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
APInt(unsigned numBits, uint64_t val, bool isSigned=false, bool implicitTrunc=false)
Create a new APInt of numBits width, initialized as val.
APInt & operator^=(uint64_t RHS)
Bitwise XOR assignment operator.
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
APInt & operator|=(uint64_t RHS)
Bitwise OR assignment operator.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
static APInt floatToBits(float V)
Converts a float to APInt bits.
void setSignBit()
Set the sign bit to 1.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool sle(uint64_t RHS) const
Signed less or equal comparison.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
bool uge(uint64_t RHS) const
Unsigned greater or equal comparison.
bool operator!() const
Logical negation operation on this APInt returns true if zero, like normal integers.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
APInt & operator=(uint64_t RHS)
Assignment operator.
APInt relativeAShr(int RelativeShift) const
relative arithmetic shift right
friend hash_code hash_value(const APInt &Arg)
Overload to compute a hash_code for an APInt value.
APInt(const APInt &that)
Copy Constructor.
APInt & operator|=(const APInt &RHS)
Bitwise OR assignment operator.
bool isSingleWord() const
Determine if this APInt just has one word to store value.
bool operator==(uint64_t Val) const
Equality operator.
APInt operator++(int)
Postfix increment operator.
unsigned getNumWords() const
Get the number of words.
bool isMinValue() const
Determine if this is the smallest unsigned value.
APInt ashr(const APInt &ShiftAmt) const
Arithmetic right-shift function.
APInt()
Default constructor that creates an APInt with a 1-bit zero value.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
APInt(APInt &&that)
Move Constructor.
bool isNegative() const
Determine sign of this APInt.
APInt concat(const APInt &NewLSB) const
Concatenate the bits from "NewLSB" onto the bottom of *this.
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
bool eq(const APInt &RHS) const
Equality comparison.
int32_t exactLogBase2() const
APInt & operator<<=(unsigned ShiftAmt)
Left-shift assignment function.
double roundToDouble() const
Converts this unsigned APInt to a double value.
void clearAllBits()
Set every bit to 0.
APInt relativeAShl(int RelativeShift) const
relative arithmetic shift left
void ashrInPlace(unsigned ShiftAmt)
Arithmetic right-shift this APInt by ShiftAmt in place.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
void negate()
Negate this APInt in place.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
unsigned countr_zero() const
Count the number of trailing zero bits.
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
bool isOneBitSet(unsigned BitNo) const
Determine if this APInt Value only has the specified bit set.
unsigned countl_zero() const
The APInt version of std::countl_zero.
bool operator==(const APInt &RHS) const
Equality operator.
APInt shl(const APInt &ShiftAmt) const
Left-shift function.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
bool isShiftedMask(unsigned &MaskIdx, unsigned &MaskLen) const
Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
void setBitsWithWrap(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
APInt lshr(const APInt &ShiftAmt) const
Logical right-shift function.
bool isNonPositive() const
Determine if this APInt Value is non-positive (<= 0).
unsigned countTrailingZeros() const
unsigned getSignificantBits() const
Get the minimum bit size for this signed APInt.
unsigned countLeadingZeros() const
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
void flipAllBits()
Toggle every bit to its opposite value.
static unsigned getNumWords(unsigned BitWidth)
Get the number of words.
bool needsCleanup() const
Returns whether this instance allocated memory.
unsigned countl_one() const
Count the number of leading one bits.
void clearLowBits(unsigned loBits)
Set bottom loBits bits to 0.
unsigned logBase2() const
static APInt getZeroWidth()
Return an APInt zero bits wide.
double signedRoundToDouble() const
Converts this signed APInt to a double value.
bool isShiftedMask() const
Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
float bitsToFloat() const
Converts APInt bits to a float.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
bool ule(uint64_t RHS) const
Unsigned less or equal comparison.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
void setAllBits()
Set every bit to 1.
uint64_t VAL
Used to store the <= 64 bits integer value.
bool ugt(uint64_t RHS) const
Unsigned greater than comparison.
bool sge(int64_t RHS) const
Signed greater or equal comparison.
bool getBoolValue() const
Convert APInt to a boolean value.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
bool isMask(unsigned numBits) const
APInt & operator=(APInt &&that)
Move assignment operator.
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
APInt & operator^=(const APInt &RHS)
Bitwise XOR assignment operator.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
void setBits(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
APInt shl(unsigned shiftAmt) const
Left-shift function.
double bitsToDouble() const
Converts APInt bits to a double.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
bool ne(const APInt &RHS) const
Inequality comparison.
static bool isSameValue(const APInt &I1, const APInt &I2)
Determine if two APInts have the same value, after zero-extending one of them (if needed!...
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
bool slt(const APInt &RHS) const
Signed less than comparison.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
unsigned countTrailingOnes() const
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
std::optional< int64_t > trySExtValue() const
Get sign extended value if possible.
APInt & operator&=(uint64_t RHS)
Bitwise AND assignment operator.
double roundToDouble(bool isSigned) const
Converts this APInt to a double value.
bool isOne() const
Determine if this is a value of 1.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
void clearHighBits(unsigned hiBits)
Set top hiBits bits to 0.
int64_t getSExtValue() const
Get sign extended value.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
unsigned countr_one() const
Count the number of trailing one bits.
static APInt getBitsSetWithWrap(unsigned numBits, unsigned loBit, unsigned hiBit)
Wrap version of getBitsSet.
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
void setBitVal(unsigned BitPosition, bool BitValue)
Set a given bit to a given value.
void clearSignBit()
Set the sign bit to 0.
bool isMaxValue() const
Determine if this is the largest unsigned value.
void toStringSigned(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be signed and converts it into a string in the radix given.
bool ult(uint64_t RHS) const
Unsigned less than comparison.
bool operator!=(uint64_t Val) const
Inequality operator.
An arbitrary precision integer that knows its signedness.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class provides support for dynamic arbitrary-precision arithmetic.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
std::error_code fromString(StringRef String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
float RoundAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
const APInt abdu(const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be unsigned.
const APInt abds(const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be signed.
double RoundAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
APInt RoundFloatToAPInt(float Float, unsigned width)
Converts a float value into a APInt.
APInt RoundDoubleToAPInt(double Double, unsigned width)
Converts the given double value into a APInt.
double RoundSignedAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
float RoundSignedAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
constexpr T rotr(T V, int R)
int popcount(T Value) noexcept
Count the number of set bits in a value.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
APInt operator&(APInt a, const APInt &b)
APInt operator*(APInt a, uint64_t RHS)
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
bool operator!=(uint64_t V1, const APInt &V2)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator+=(DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator-=(DynamicAPInt &A, int64_t B)
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
APInt operator~(APInt v)
Unary bitwise complement operator.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator*=(DynamicAPInt &A, int64_t B)
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
APInt operator^(APInt a, const APInt &b)
constexpr bool isMask_64(uint64_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
int countl_one(T Value)
Count the number of ones from the most significant bit to the first zero bit.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
APInt operator+(APInt a, const APInt &b)
APInt operator|(APInt a, const APInt &b)
T reverseBits(T Val)
Reverse the bits in Val.
constexpr T rotl(T V, int R)
@ Keep
No function return thunk.
auto mask(ShuffFunc S, unsigned Length, OptArgs... args) -> MaskT
This struct is a compact representation of a valid (non-zero power of two) alignment.
static APInt getEmptyKey()
static APInt getTombstoneKey()
static bool isEqual(const APInt &LHS, const APInt &RHS)
static unsigned getHashValue(const APInt &Key)
An information struct used to provide DenseMap with the various necessary components for a given valu...