LLVM: lib/IR/Constants.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
33#include
34
35using namespace llvm;
36using namespace PatternMatch;
37
38
40 "use-constant-int-for-fixed-length-splat", cl::init(false), cl::Hidden,
41 cl::desc("Use ConstantInt's native fixed-length vector splat support."));
43 "use-constant-fp-for-fixed-length-splat", cl::init(false), cl::Hidden,
44 cl::desc("Use ConstantFP's native fixed-length vector splat support."));
47 cl::desc("Use ConstantInt's native scalable vector splat support."));
50 cl::desc("Use ConstantFP's native scalable vector splat support."));
51
52
53
54
55
57
58 if (const ConstantFP *CFP = dyn_cast(this))
59 return CFP->isZero() && CFP->isNegative();
60
61
62 if (getType()->isVectorTy())
63 if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue()))
64 return SplatCFP->isNegativeZeroValue();
65
66
67 if (getType()->isFPOrFPVectorTy())
68 return false;
69
70
72}
73
74
75
77
78 if (const ConstantFP *CFP = dyn_cast(this))
79 return CFP->isZero();
80
81
82 if (getType()->isVectorTy())
83 if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue()))
84 return SplatCFP->isZero();
85
86
88}
89
91
92 if (const ConstantInt *CI = dyn_cast(this))
93 return CI->isZero();
94
95
96 if (const ConstantFP *CFP = dyn_cast(this))
97
98
99 return CFP->isExactlyValue(+0.0);
100
101
102
103 return isa(this) || isa(this) ||
104 isa(this) || isa(this);
105}
106
108
109 if (const ConstantInt *CI = dyn_cast(this))
110 return CI->isMinusOne();
111
112
113 if (const ConstantFP *CFP = dyn_cast(this))
114 return CFP->getValueAPF().bitcastToAPInt().isAllOnes();
115
116
117 if (getType()->isVectorTy())
119 return SplatVal->isAllOnesValue();
120
121 return false;
122}
123
125
126 if (const ConstantInt *CI = dyn_cast(this))
127 return CI->isOne();
128
129
130 if (const ConstantFP *CFP = dyn_cast(this))
131 return CFP->getValueAPF().bitcastToAPInt().isOne();
132
133
134 if (getType()->isVectorTy())
136 return SplatVal->isOneValue();
137
138 return false;
139}
140
142
143 if (const ConstantInt *CI = dyn_cast(this))
144 return !CI->isOneValue();
145
146
147 if (const ConstantFP *CFP = dyn_cast(this))
148 return !CFP->getValueAPF().bitcastToAPInt().isOne();
149
150
151 if (auto *VTy = dyn_cast(getType())) {
152 for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
155 return false;
156 }
157 return true;
158 }
159
160
161 if (getType()->isVectorTy())
163 return SplatVal->isNotOneValue();
164
165
166 return false;
167}
168
170
171 if (const ConstantInt *CI = dyn_cast(this))
172 return CI->isMinValue(true);
173
174
175 if (const ConstantFP *CFP = dyn_cast(this))
176 return CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
177
178
179 if (getType()->isVectorTy())
181 return SplatVal->isMinSignedValue();
182
183 return false;
184}
185
187
188 if (const ConstantInt *CI = dyn_cast(this))
189 return !CI->isMinValue(true);
190
191
192 if (const ConstantFP *CFP = dyn_cast(this))
193 return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
194
195
196 if (auto *VTy = dyn_cast(getType())) {
197 for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
200 return false;
201 }
202 return true;
203 }
204
205
206 if (getType()->isVectorTy())
208 return SplatVal->isNotMinSignedValue();
209
210
211 return false;
212}
213
215 if (auto *CFP = dyn_cast(this))
216 return CFP->getValueAPF().isFiniteNonZero();
217
218 if (auto *VTy = dyn_cast(getType())) {
219 for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
221 if (!CFP || !CFP->getValueAPF().isFiniteNonZero())
222 return false;
223 }
224 return true;
225 }
226
227 if (getType()->isVectorTy())
228 if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue()))
229 return SplatCFP->isFiniteNonZeroFP();
230
231
232 return false;
233}
234
236 if (auto *CFP = dyn_cast(this))
237 return CFP->getValueAPF().isNormal();
238
239 if (auto *VTy = dyn_cast(getType())) {
240 for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
242 if (!CFP || !CFP->getValueAPF().isNormal())
243 return false;
244 }
245 return true;
246 }
247
248 if (getType()->isVectorTy())
249 if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue()))
250 return SplatCFP->isNormalFP();
251
252
253 return false;
254}
255
257 if (auto *CFP = dyn_cast(this))
258 return CFP->getValueAPF().getExactInverse(nullptr);
259
260 if (auto *VTy = dyn_cast(getType())) {
261 for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
263 if (!CFP || !CFP->getValueAPF().getExactInverse(nullptr))
264 return false;
265 }
266 return true;
267 }
268
269 if (getType()->isVectorTy())
270 if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue()))
271 return SplatCFP->hasExactInverseFP();
272
273
274 return false;
275}
276
278 if (auto *CFP = dyn_cast(this))
279 return CFP->isNaN();
280
281 if (auto *VTy = dyn_cast(getType())) {
282 for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
284 if (!CFP || !CFP->isNaN())
285 return false;
286 }
287 return true;
288 }
289
290 if (getType()->isVectorTy())
291 if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue()))
292 return SplatCFP->isNaN();
293
294
295 return false;
296}
297
299
300 if (this == Y)
301 return true;
302
303
304 auto *VTy = dyn_cast(getType());
305 if (!isa(Y) || !VTy || VTy != Y->getType())
306 return false;
307
308
309 if (!(VTy->getElementType()->isIntegerTy() ||
310 VTy->getElementType()->isFloatingPointTy()))
311 return false;
312
313
314
319 return CmpEq && (isa(CmpEq) || match(CmpEq, m_One()));
320}
321
322static bool
325 if (auto *VTy = dyn_cast(C->getType())) {
326 if (HasFn(C))
327 return true;
328 if (isa(C))
329 return false;
330 if (isa(C->getType()))
331 return false;
332
333 for (unsigned i = 0, e = cast(VTy)->getNumElements();
334 i != e; ++i) {
335 if (Constant *Elem = C->getAggregateElement(i))
336 if (HasFn(Elem))
337 return true;
338 }
339 }
340
341 return false;
342}
343
346 this, [&](const auto *C) { return isa(C); });
347}
348
351 this, [&](const auto *C) { return isa(C); });
352}
353
357 });
358}
359
361 if (isa(this) || isa(this))
362 return false;
363
364 if (auto *VTy = dyn_cast(getType())) {
365 for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
367 return true;
368 }
369 return false;
370}
371
372
376 return ConstantInt::get(Ty, 0);
384 return ConstantFP::get(Ty->getContext(),
397 default:
398
399 llvm_unreachable("Cannot create a null constant of that type!");
400 }
401}
402
405
406
408
409
410 if (PointerType *PTy = dyn_cast(ScalarTy))
412
413
414 if (VectorType *VTy = dyn_cast(Ty))
416
417 return C;
418}
419
421 if (IntegerType *ITy = dyn_cast(Ty))
422 return ConstantInt::get(Ty->getContext(),
424
427 return ConstantFP::get(Ty->getContext(), FL);
428 }
429
430 VectorType *VTy = cast(Ty);
433}
434
437 "Must be an aggregate/vector constant");
438
439 if (const auto *CC = dyn_cast(this))
440 return Elt < CC->getNumOperands() ? CC->getOperand(Elt) : nullptr;
441
442 if (const auto *CAZ = dyn_cast(this))
443 return Elt < CAZ->getElementCount().getKnownMinValue()
444 ? CAZ->getElementValue(Elt)
445 : nullptr;
446
447 if (const auto *CI = dyn_cast(this))
448 return Elt < cast(getType())
449 ->getElementCount()
450 .getKnownMinValue()
451 ? ConstantInt::get(getContext(), CI->getValue())
452 : nullptr;
453
454 if (const auto *CFP = dyn_cast(this))
455 return Elt < cast(getType())
456 ->getElementCount()
457 .getKnownMinValue()
458 ? ConstantFP::get(getContext(), CFP->getValue())
459 : nullptr;
460
461
462 if (isa(getType()))
463 return nullptr;
464
465 if (const auto *PV = dyn_cast(this))
466 return Elt < PV->getNumElements() ? PV->getElementValue(Elt) : nullptr;
467
468 if (const auto *UV = dyn_cast(this))
469 return Elt < UV->getNumElements() ? UV->getElementValue(Elt) : nullptr;
470
471 if (const auto *CDS = dyn_cast(this))
472 return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
473 : nullptr;
474
475 return nullptr;
476}
477
479 assert(isa(Elt->getType()) && "Index must be an integer");
480 if (ConstantInt *CI = dyn_cast(Elt)) {
481
482 if (CI->getValue().getActiveBits() > 64)
483 return nullptr;
485 }
486 return nullptr;
487}
488
490
491
493 default:
495#define HANDLE_CONSTANT(Name) \
496 case Value::Name##Val: \
497 cast(this)->destroyConstantImpl(); \
498 break;
499#include "llvm/IR/Value.def"
500 }
501
502
503
504
505
506
507
508
511#ifndef NDEBUG
512 if (!isa(V)) {
513 dbgs() << "While deleting: " << *this
514 << "\n\nUse still stuck around after Def is destroyed: " << *V
515 << "\n\n";
516 }
517#endif
518 assert(isa(V) && "References remain to Constant being destroyed");
519 cast(V)->destroyConstant();
520
521
523 }
524
525
527}
528
530 switch (C->getValueID()) {
531 case Constant::ConstantIntVal:
533 break;
534 case Constant::ConstantFPVal:
536 break;
537 case Constant::ConstantAggregateZeroVal:
539 break;
540 case Constant::ConstantArrayVal:
542 break;
543 case Constant::ConstantStructVal:
545 break;
546 case Constant::ConstantVectorVal:
548 break;
549 case Constant::ConstantPointerNullVal:
551 break;
552 case Constant::ConstantDataArrayVal:
554 break;
555 case Constant::ConstantDataVectorVal:
557 break;
558 case Constant::ConstantTokenNoneVal:
560 break;
561 case Constant::BlockAddressVal:
563 break;
564 case Constant::DSOLocalEquivalentVal:
566 break;
567 case Constant::NoCFIValueVal:
569 break;
570 case Constant::ConstantPtrAuthVal:
572 break;
573 case Constant::UndefValueVal:
575 break;
576 case Constant::PoisonValueVal:
578 break;
579 case Constant::ConstantExprVal:
580 if (isa(C))
582 else if (isa(C))
584 else if (isa(C))
586 else if (isa(C))
588 else if (isa(C))
590 else if (isa(C))
592 else
594 break;
595 default:
597 }
598}
599
600
601static bool
603 bool (*Predicate)(const GlobalValue *)) {
608
609 while (!WorkList.empty()) {
611 if (const auto *GV = dyn_cast(WorkItem))
612 if (Predicate(GV))
613 return true;
615 const Constant *ConstOp = dyn_cast(Op);
616 if (!ConstOp)
617 continue;
618 if (Visited.insert(ConstOp).second)
620 }
621 }
622 return false;
623}
624
626 auto DLLImportPredicate = [](const GlobalValue *GV) {
627 return GV->isThreadLocal();
628 };
630}
631
633 auto DLLImportPredicate = [](const GlobalValue *GV) {
634 return GV->hasDLLImportStorageClass();
635 };
637}
638
641 const Constant *UC = dyn_cast(U);
642 if (!UC || isa(UC))
643 return true;
644
646 return true;
647 }
648 return false;
649}
650
652 return getRelocationInfo() == GlobalRelocation;
653}
654
656 return getRelocationInfo() != NoRelocation;
657}
658
659Constant::PossibleRelocationsTy Constant::getRelocationInfo() const {
660 if (isa(this))
661 return GlobalRelocation;
662
663 if (const BlockAddress *BA = dyn_cast(this))
664 return BA->getFunction()->getRelocationInfo();
665
666 if (const ConstantExpr *CE = dyn_cast(this)) {
667 if (CE->getOpcode() == Instruction::Sub) {
668 ConstantExpr *LHS = dyn_cast(CE->getOperand(0));
669 ConstantExpr *RHS = dyn_cast(CE->getOperand(1));
670 if (LHS && RHS && LHS->getOpcode() == Instruction::PtrToInt &&
671 RHS->getOpcode() == Instruction::PtrToInt) {
674
675
676
677
678
679 if (isa(LHSOp0) && isa(RHSOp0) &&
680 cast(LHSOp0)->getFunction() ==
681 cast(RHSOp0)->getFunction())
682 return NoRelocation;
683
684
685 if (auto *RHSGV =
688 if (auto *LHSGV = dyn_cast(LHS)) {
689 if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
690 return LocalRelocation;
691 } else if (isa(LHS)) {
692 if (RHSGV->isDSOLocal())
693 return LocalRelocation;
694 }
695 }
696 }
697 }
698 }
699
700 PossibleRelocationsTy Result = NoRelocation;
702 Result = std::max(cast(Op)->getRelocationInfo(), Result);
703
705}
706
707
708
709
711 if (isa(C)) return false;
712
714 while (I != E) {
716 if () return false;
718 return false;
719
720
721
722
723 if (RemoveDeadUsers)
725 else
726 ++I;
727 }
728
729 if (RemoveDeadUsers) {
730
731
733 const_cast<Constant *>(C)->destroyConstant();
734 }
735
736 return true;
737}
738
742 while (I != E) {
745 LastNonDeadUser = I;
746 ++I;
747 continue;
748 }
749
751
752
753 LastNonDeadUser = I;
754 ++I;
755 continue;
756 }
757
758
759 if (LastNonDeadUser == E)
761 else
762 I = std::next(LastNonDeadUser);
763 }
764}
765
767
769
770bool Constant::hasNLiveUses(unsigned N) const {
771 unsigned NumUses = 0;
772 for (const Use &U : uses()) {
773 const Constant *User = dyn_cast(U.getUser());
775 ++NumUses;
776
777 if (NumUses > N)
778 return false;
779 }
780 }
781 return NumUses == N;
782}
783
785 assert(C && Replacement && "Expected non-nullptr constant arguments");
788 assert(Ty == Replacement->getType() && "Expected matching types");
789 return Replacement;
790 }
791
792
793 auto *VTy = dyn_cast(Ty);
794 if (!VTy)
795 return C;
796
797 unsigned NumElts = VTy->getNumElements();
799 for (unsigned i = 0; i != NumElts; ++i) {
800 Constant *EltC = C->getAggregateElement(i);
802 "Expected matching types");
803 NewC[i] = EltC && match(EltC, m_Undef()) ? Replacement : EltC;
804 }
806}
807
809 assert(C && Other && "Expected non-nullptr constant arguments");
811 return C;
812
816
817 auto *VTy = dyn_cast(Ty);
818 if (!VTy)
819 return C;
820
821 Type *EltTy = VTy->getElementType();
822 unsigned NumElts = VTy->getNumElements();
823 assert(isa(Other->getType()) &&
824 cast(Other->getType())->getNumElements() == NumElts &&
825 "Type mismatch");
826
827 bool FoundExtraUndef = false;
829 for (unsigned I = 0; I != NumElts; ++I) {
830 NewC[I] = C->getAggregateElement(I);
832 assert(NewC[I] && OtherEltC && "Unknown vector element");
835 FoundExtraUndef = true;
836 }
837 }
838 if (FoundExtraUndef)
840 return C;
841}
842
844 if (isa(this))
845 return true;
846 if (isa(this) || isa(this)) {
849 return false;
850 return true;
851 }
852 return false;
853}
854
855
856
857
858
859ConstantInt::ConstantInt(Type *Ty, const APInt &V)
861 assert(V.getBitWidth() ==
862 cast(Ty->getScalarType())->getBitWidth() &&
863 "Invalid constant for type");
864}
865
871}
872
878}
879
882}
883
887 if (auto *VTy = dyn_cast(Ty))
889 return TrueC;
890}
891
895 if (auto *VTy = dyn_cast(Ty))
897 return FalseC;
898}
899
902}
903
904
906
908 std::unique_ptr &Slot =
912 if (!Slot) {
913
916 }
918 return Slot.get();
919}
920
921
923 const APInt &V) {
924
925 std::unique_ptr &Slot =
927 if (!Slot) {
931 }
932
933#ifndef NDEBUG
936 assert(Slot->getType() == VTy);
937#endif
938 return Slot.get();
939}
940
943
944
945 if (VectorType *VTy = dyn_cast(Ty))
947
948 return C;
949}
950
952
953
956}
957
961 "ConstantInt type doesn't match the type implied by its value!");
962
963
964 if (VectorType *VTy = dyn_cast(Ty))
966
967 return C;
968}
969
972}
973
974
975void ConstantInt::destroyConstantImpl() {
976 llvm_unreachable("You can't ConstantInt->destroyConstantImpl()!");
977}
978
979
980
981
982
985
991
992
993 if (VectorType *VTy = dyn_cast(Ty))
995
996 return C;
997}
998
1002 "ConstantFP type doesn't match the type implied by its value!");
1003
1004
1005 if (auto *VTy = dyn_cast(Ty))
1007
1008 return C;
1009}
1010
1013
1016
1017
1018 if (VectorType *VTy = dyn_cast(Ty))
1020
1021 return C;
1022}
1023
1028
1029 if (VectorType *VTy = dyn_cast(Ty))
1031
1032 return C;
1033}
1034
1039
1040 if (VectorType *VTy = dyn_cast(Ty))
1042
1043 return C;
1044}
1045
1050
1051 if (VectorType *VTy = dyn_cast(Ty))
1053
1054 return C;
1055}
1056
1061
1062 if (VectorType *VTy = dyn_cast(Ty))
1064
1065 return C;
1066}
1067
1068
1069
1072
1073 std::unique_ptr &Slot = pImpl->FPConstants[V];
1074
1075 if (!Slot) {
1078 }
1079
1080 return Slot.get();
1081}
1082
1083
1086
1087 std::unique_ptr &Slot =
1089 if (!Slot) {
1093 }
1094
1095#ifndef NDEBUG
1098 assert(Slot->getType() == VTy);
1099#endif
1100 return Slot.get();
1101}
1102
1106
1107 if (VectorType *VTy = dyn_cast(Ty))
1109
1110 return C;
1111}
1112
1113ConstantFP::ConstantFP(Type *Ty, const APFloat &V)
1116 "FP type Mismatch");
1117}
1118
1121}
1122
1123
1124void ConstantFP::destroyConstantImpl() {
1125 llvm_unreachable("You can't ConstantFP->destroyConstantImpl()!");
1126}
1127
1128
1129
1130
1131
1133 if (auto *AT = dyn_cast(getType()))
1136}
1137
1140}
1141
1143 if (isa(getType()) || isa(getType()))
1146}
1147
1149 if (isa(getType()) || isa(getType()))
1152}
1153
1156 if (auto *AT = dyn_cast(Ty))
1158 if (auto *VT = dyn_cast(Ty))
1159 return VT->getElementCount();
1161}
1162
1163
1164
1165
1166
1171}
1172
1175}
1176
1178 if (isa(getType()) || isa(getType()))
1181}
1182
1184 if (isa(getType()) || isa(getType()))
1187}
1188
1191 if (auto *AT = dyn_cast(Ty))
1192 return AT->getNumElements();
1193 if (auto *VT = dyn_cast(Ty))
1194 return cast(VT)->getNumElements();
1196}
1197
1198
1199
1200
1201
1206}
1207
1210}
1211
1213 if (isa(getType()) || isa(getType()))
1216}
1217
1219 if (isa(getType()) || isa(getType()))
1222}
1223
1224
1225
1226
1227
1228template <typename ItTy, typename EltTy>
1230 for (; Start != End; ++Start)
1231 if (*Start != Elt)
1232 return false;
1233 return true;
1234}
1235
1236template <typename SequentialTy, typename ElementTy>
1238 assert(!V.empty() && "Cannot get empty int sequence.");
1239
1242 if (auto *CI = dyn_cast(C))
1243 Elts.push_back(CI->getZExtValue());
1244 else
1245 return nullptr;
1246 return SequentialTy::get(V[0]->getContext(), Elts);
1247}
1248
1249template <typename SequentialTy, typename ElementTy>
1251 assert(!V.empty() && "Cannot get empty FP sequence.");
1252
1255 if (auto *CFP = dyn_cast(C))
1256 Elts.push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1257 else
1258 return nullptr;
1259 return SequentialTy::getFP(V[0]->getType(), Elts);
1260}
1261
1262template
1265
1266
1267
1268 if (ConstantInt *CI = dyn_cast(C)) {
1269 if (CI->getType()->isIntegerTy(8))
1270 return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1271 else if (CI->getType()->isIntegerTy(16))
1272 return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1273 else if (CI->getType()->isIntegerTy(32))
1274 return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1275 else if (CI->getType()->isIntegerTy(64))
1276 return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1277 } else if (ConstantFP *CFP = dyn_cast(C)) {
1278 if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1279 return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1280 else if (CFP->getType()->isFloatTy())
1281 return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1282 else if (CFP->getType()->isDoubleTy())
1283 return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1284 }
1285
1286 return nullptr;
1287}
1288
1294
1295
1296 if (auto *ST = dyn_cast(T)) {
1297 if (ST->isOpaque())
1298 return;
1299 for (unsigned I = 0, E = V.size(); I != E; ++I)
1301 "Initializer for struct element doesn't match!");
1302 }
1303}
1304
1308 assert(V.size() == T->getNumElements() &&
1309 "Invalid initializer for constant array");
1310}
1311
1313 if (Constant *C = getImpl(Ty, V))
1314 return C;
1316}
1317
1319
1320 if (V.empty())
1322
1325 "Wrong type in array element initializer");
1326 (void)C;
1327 }
1328
1329
1330
1331
1335
1338
1341
1342
1343
1345 return getSequenceIfElementsMatch(C, V);
1346
1347
1348 return nullptr;
1349}
1350
1353 bool Packed) {
1354 unsigned VecSize = V.size();
1356 for (unsigned i = 0; i != VecSize; ++i)
1357 EltTypes[i] = V[i]->getType();
1358
1360}
1361
1362
1364 bool Packed) {
1365 assert(!V.empty() &&
1366 "ConstantStruct::getTypeForElements cannot be called on empty list");
1368}
1369
1373 assert((T->isOpaque() || V.size() == T->getNumElements()) &&
1374 "Invalid initializer for constant struct");
1375}
1376
1377
1379 assert((ST->isOpaque() || ST->getNumElements() == V.size()) &&
1380 "Incorrect # elements specified to ConstantStruct::get");
1381
1382
1385 bool isPoison = false;
1386
1387 if (!V.empty()) {
1388 isUndef = isa(V[0]);
1389 isPoison = isa(V[0]);
1390 isZero = V[0]->isNullValue();
1391
1394 if (->isNullValue())
1396 if (!isa(C))
1397 isPoison = false;
1400 }
1401 }
1402 }
1405 if (isPoison)
1409
1410 return ST->getContext().pImpl->StructConstants.getOrCreate(ST, V);
1411}
1412
1416 assert(V.size() == cast(T)->getNumElements() &&
1417 "Invalid initializer for constant vector");
1418}
1419
1420
1423 return C;
1426}
1427
1429 assert(!V.empty() && "Vectors can't be empty");
1431
1432
1433
1435 bool isZero = C->isNullValue();
1437 bool isPoison = isa(C);
1440
1441 if (isZero || isUndef || isSplatFP || isSplatInt) {
1442 for (unsigned i = 1, e = V.size(); i != e; ++i)
1443 if (V[i] != C) {
1444 isZero = isUndef = isPoison = isSplatFP = isSplatInt = false;
1445 break;
1446 }
1447 }
1448
1451 if (isPoison)
1455 if (isSplatFP)
1456 return ConstantFP::get(C->getContext(), T->getElementCount(),
1457 cast(C)->getValue());
1458 if (isSplatInt)
1459 return ConstantInt::get(C->getContext(), T->getElementCount(),
1460 cast(C)->getValue());
1461
1462
1463
1465 return getSequenceIfElementsMatch(C, V);
1466
1467
1468
1469 return nullptr;
1470}
1471
1473 if (!EC.isScalable()) {
1474
1475 if (!V->isNullValue()) {
1477 return ConstantInt::get(V->getContext(), EC,
1478 cast(V)->getValue());
1480 return ConstantFP::get(V->getContext(), EC,
1481 cast(V)->getValue());
1482 }
1483
1484
1485
1486 if ((isa(V) || isa(V)) &&
1489
1491 return get(Elts);
1492 }
1493
1494
1495 if (!V->isNullValue()) {
1497 return ConstantInt::get(V->getContext(), EC,
1498 cast(V)->getValue());
1500 return ConstantFP::get(V->getContext(), EC,
1501 cast(V)->getValue());
1502 }
1503
1505
1506 if (V->isNullValue())
1508 else if (isa(V))
1510
1512
1513
1516
1518
1520}
1521
1527}
1528
1529
1530void ConstantTokenNone::destroyConstantImpl() {
1531 llvm_unreachable("You can't ConstantTokenNone->destroyConstantImpl()!");
1532}
1533
1534
1535
1536
1538
1540 return cast(this)->ShuffleMask;
1541}
1542
1544 return cast(this)->ShuffleMaskForBitcode;
1545}
1546
1548 bool OnlyIfReduced, Type *SrcTy) const {
1550
1551
1554
1555 Type *OnlyIfReducedTy = OnlyIfReduced ? Ty : nullptr;
1557 case Instruction::Trunc:
1558 case Instruction::ZExt:
1559 case Instruction::SExt:
1560 case Instruction::FPTrunc:
1561 case Instruction::FPExt:
1562 case Instruction::UIToFP:
1563 case Instruction::SIToFP:
1564 case Instruction::FPToUI:
1565 case Instruction::FPToSI:
1566 case Instruction::PtrToInt:
1567 case Instruction::IntToPtr:
1568 case Instruction::BitCast:
1569 case Instruction::AddrSpaceCast:
1571 case Instruction::InsertElement:
1573 OnlyIfReducedTy);
1574 case Instruction::ExtractElement:
1576 case Instruction::ShuffleVector:
1578 OnlyIfReducedTy);
1579 case Instruction::GetElementPtr: {
1580 auto *GEPO = cast(this);
1583 SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.slice(1),
1584 GEPO->getNoWrapFlags(), GEPO->getInRange(), OnlyIfReducedTy);
1585 }
1586 default:
1589 OnlyIfReducedTy);
1590 }
1591}
1592
1593
1594
1595
1596
1600 return Val == 0 || Val == 1;
1601 return isUIntN(NumBits, Val);
1602}
1603
1607 return Val == 0 || Val == 1 || Val == -1;
1608 return isIntN(NumBits, Val);
1609}
1610
1612
1614 bool losesInfo;
1616 default:
1617 return false;
1618
1619
1622 return true;
1624 return !losesInfo;
1625 }
1628 return true;
1630 return !losesInfo;
1631 }
1634 return true;
1636 return !losesInfo;
1637 }
1643 return true;
1645 return !losesInfo;
1646 }
1665 }
1666}
1667
1668
1669
1670
1671
1674 "Cannot create an aggregate zero of non-aggregate type!");
1675
1676 std::unique_ptr &Entry =
1678 if (!Entry)
1680
1681 return Entry.get();
1682}
1683
1684
1685void ConstantAggregateZero::destroyConstantImpl() {
1687}
1688
1689
1690void ConstantArray::destroyConstantImpl() {
1692}
1693
1694
1695
1696
1697
1698
1699void ConstantStruct::destroyConstantImpl() {
1701}
1702
1703
1704void ConstantVector::destroyConstantImpl() {
1706}
1707
1709 assert(this->getType()->isVectorTy() && "Only valid for vectors!");
1710 if (isa(this))
1712 if (auto *CI = dyn_cast(this))
1713 return ConstantInt::get(getContext(), CI->getValue());
1714 if (auto *CFP = dyn_cast(this))
1715 return ConstantFP::get(getContext(), CFP->getValue());
1716 if (const ConstantDataVector *CV = dyn_cast(this))
1717 return CV->getSplatValue();
1718 if (const ConstantVector *CV = dyn_cast(this))
1719 return CV->getSplatValue(AllowPoison);
1720
1721
1722
1723 const auto *Shuf = dyn_cast(this);
1724 if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1725 isa(Shuf->getOperand(1))) {
1726
1727 const auto *IElt = dyn_cast(Shuf->getOperand(0));
1728 if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1729 isa(IElt->getOperand(0))) {
1730
1733 ConstantInt *Index = dyn_cast(IElt->getOperand(2));
1734
1735 if (Index && Index->getValue() == 0 &&
1736 llvm::all_of(Mask, [](int I) { return I == 0; }))
1737 return SplatVal;
1738 }
1739 }
1740
1741 return nullptr;
1742}
1743
1745
1747
1750 if (OpC == Elt)
1751 continue;
1752
1753
1754 if (!AllowPoison)
1755 return nullptr;
1756
1757
1758 if (isa(OpC))
1759 continue;
1760
1761
1762 if (isa(Elt))
1763 Elt = OpC;
1764
1765 if (OpC != Elt)
1766 return nullptr;
1767 }
1768 return Elt;
1769}
1770
1772 if (const ConstantInt *CI = dyn_cast(this))
1773 return CI->getValue();
1774
1775 if (isa(this))
1776 return cast(this->getSplatValue())->getValue();
1777
1778
1781 assert(C && isa(C) && "Not a vector of numbers!");
1782 return cast(C)->getValue();
1783}
1784
1786 if (auto *CI = dyn_cast(this))
1788
1790 if (()->isVectorTy())
1791 return ConstantRange::getFull(BitWidth);
1792
1793 if (auto *CI = dyn_cast_or_null(
1796
1797 if (auto *CDV = dyn_cast(this)) {
1799 for (unsigned I = 0, E = CDV->getNumElements(); I < E; ++I)
1800 CR = CR.unionWith(CDV->getElementAsAPInt(I));
1801 return CR;
1802 }
1803
1804 if (auto *CV = dyn_cast(this)) {
1806 for (unsigned I = 0, E = CV->getNumOperands(); I < E; ++I) {
1808 if (!Elem)
1809 return ConstantRange::getFull(BitWidth);
1810 if (isa(Elem))
1811 continue;
1812 auto *CI = dyn_cast(Elem);
1813 if (!CI)
1814 return ConstantRange::getFull(BitWidth);
1815 CR = CR.unionWith(CI->getValue());
1816 }
1817 return CR;
1818 }
1819
1820 return ConstantRange::getFull(BitWidth);
1821}
1822
1823
1824
1825
1827 std::unique_ptr &Entry =
1829 if (!Entry)
1831
1832 return Entry.get();
1833}
1834
1835
1836void ConstantPointerNull::destroyConstantImpl() {
1838}
1839
1840
1841
1842
1845 "Target extension type not allowed to have a zeroinitializer");
1846 std::unique_ptr &Entry =
1848 if (!Entry)
1850
1851 return Entry.get();
1852}
1853
1854
1855void ConstantTargetNone::destroyConstantImpl() {
1857}
1858
1861 if (!Entry)
1863
1864 return Entry.get();
1865}
1866
1867
1868void UndefValue::destroyConstantImpl() {
1869
1870 if (getValueID() == UndefValueVal) {
1872 } else if (getValueID() == PoisonValueVal) {
1874 }
1876}
1877
1880 if (!Entry)
1882
1883 return Entry.get();
1884}
1885
1886
1887void PoisonValue::destroyConstantImpl() {
1888
1890}
1891
1895}
1896
1899 F->getContext().pImpl->BlockAddresses[std::make_pair(F, BB)];
1900 if (!BA)
1902
1903 assert(BA->getFunction() == F && "Basic block moved between functions");
1904 return BA;
1905}
1906
1909 Value::BlockAddressVal, AllocMarker) {
1912 BB->AdjustBlockAddressRefCount(1);
1913}
1914
1917 return nullptr;
1918
1920 assert(F && "Block must have a parent");
1922 F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(F, BB));
1923 assert(BA && "Refcount and block address map disagree!");
1924 return BA;
1925}
1926
1927
1928void BlockAddress::destroyConstantImpl() {
1931 getBasicBlock()->AdjustBlockAddressRefCount(-1);
1932}
1933
1935
1936
1939
1940 if (From == NewF)
1942 else {
1943 assert(From == NewBB && "From does not match any operand");
1944 NewBB = cast(To);
1945 }
1946
1947
1948
1951 if (NewBA)
1952 return NewBA;
1953
1954 getBasicBlock()->AdjustBlockAddressRefCount(-1);
1955
1956
1957
1960 NewBA = this;
1964
1965
1966
1967 return nullptr;
1968}
1969
1972 if (!Equiv)
1974
1976 "DSOLocalFunction does not match the expected global value");
1977 return Equiv;
1978}
1979
1980DSOLocalEquivalent::DSOLocalEquivalent(GlobalValue *GV)
1983}
1984
1985
1986void DSOLocalEquivalent::destroyConstantImpl() {
1989}
1990
1991Value *DSOLocalEquivalent::handleOperandChangeImpl(Value *From, Value *To) {
1993 assert(isa(To) && "Can only replace the operands with a constant");
1994
1995
1996 if (const auto *ToObj = dyn_cast(To)) {
1999 if (NewEquiv)
2001 }
2002
2003
2004
2006 return To;
2007
2008
2009
2012 if (NewEquiv)
2014
2015
2017 NewEquiv = this;
2019
2021
2022
2024 }
2025 return nullptr;
2026}
2027
2030 if ()
2032
2033 assert(NC->getGlobalValue() == GV &&
2034 "NoCFIValue does not match the expected global value");
2035 return NC;
2036}
2037
2041}
2042
2043
2044void NoCFIValue::destroyConstantImpl() {
2047}
2048
2051
2053 assert(GV && "Can only replace the operands with a global value");
2054
2056 if (NewNC)
2058
2060 NewNC = this;
2062
2065
2066 return nullptr;
2067}
2068
2069
2070
2071
2074 Constant *ArgVec[] = {Ptr, Key, Disc, AddrDisc};
2078}
2079
2082}
2083
2087 assert(Ptr->getType()->isPointerTy());
2088 assert(Key->getBitWidth() == 32);
2095}
2096
2097
2098void ConstantPtrAuth::destroyConstantImpl() {
2100}
2101
2102Value *ConstantPtrAuth::handleOperandChangeImpl(Value *From, Value *ToV) {
2103 assert(isa(ToV) && "Cannot make Constant refer to non-constant!");
2104 Constant *To = cast(ToV);
2105
2108
2109 unsigned NumUpdated = 0;
2110
2112 unsigned OperandNo = 0;
2113 for (Use *O = OperandList, *E = OperandList + getNumOperands(); O != E; ++O) {
2114 Constant *Val = cast(O->get());
2115 if (Val == From) {
2116 OperandNo = (O - OperandList);
2117 Val = To;
2118 ++NumUpdated;
2119 }
2121 }
2122
2124 Values, this, From, To, NumUpdated, OperandNo);
2125}
2126
2129 if (!CastV || CastV->getOpcode() != Instruction::IntToPtr)
2130 return false;
2131
2132 const auto *IntVal = dyn_cast(CastV->getOperand(0));
2133 if (!IntVal)
2134 return false;
2135
2136 return IntVal->getValue() == Value;
2137}
2138
2140 const Value *Discriminator,
2142
2143 if (getKey() != Key)
2144 return false;
2145
2146
2147
2148
2149
2150
2151
2152
2153
2156
2157
2158 const Value *AddrDiscriminator = nullptr;
2159
2160
2162
2163
2164 if ((Discriminator,
2165 m_IntrinsicIntrinsic::ptrauth\_blend(
2167 return false;
2168 } else {
2169
2170 AddrDiscriminator = Discriminator;
2171 }
2172
2173
2174
2175
2176 if (auto *Cast = dyn_cast(AddrDiscriminator))
2177 AddrDiscriminator = Cast->getPointerOperand();
2178
2179
2181 return false;
2182
2183
2185 return true;
2186
2187
2190 DL, Off1, true);
2191
2192 APInt Off2(DL.getIndexTypeSizeInBits(AddrDiscriminator->getType()), 0);
2194 DL, Off2, true);
2195
2196 return Base1 == Base2 && Off1 == Off2;
2197}
2198
2199
2200
2201
2202
2203
2205 bool OnlyIfReduced = false) {
2207
2209 return FC;
2210
2211 if (OnlyIfReduced)
2212 return nullptr;
2213
2215
2216
2218
2219 return pImpl->ExprConstants.getOrCreate(Ty, Key);
2220}
2221
2223 bool OnlyIfReduced) {
2227 "Cast opcode not supported as constant expression");
2228 assert(C && Ty && "Null arguments to getCast");
2230
2231 switch (opc) {
2232 default:
2234 case Instruction::Trunc:
2235 return getTrunc(C, Ty, OnlyIfReduced);
2236 case Instruction::PtrToInt:
2238 case Instruction::IntToPtr:
2240 case Instruction::BitCast:
2241 return getBitCast(C, Ty, OnlyIfReduced);
2242 case Instruction::AddrSpaceCast:
2244 }
2245}
2246
2251}
2252
2256 "Invalid cast");
2257
2260
2264
2266}
2267
2272
2275
2277}
2278
2280#ifndef NDEBUG
2281 bool fromVec = isa(C->getType());
2282 bool toVec = isa(Ty);
2283#endif
2284 assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2285 assert(C->getType()->isIntOrIntVectorTy() && "Trunc operand must be integer");
2288 "SrcTy must be larger than DestTy for Trunc!");
2289
2290 return getFoldedCast(Instruction::Trunc, C, Ty, OnlyIfReduced);
2291}
2292
2294 bool OnlyIfReduced) {
2295 assert(C->getType()->isPtrOrPtrVectorTy() &&
2296 "PtrToInt source must be pointer or pointer vector");
2298 "PtrToInt destination must be integer or integer vector");
2299 assert(isa(C->getType()) == isa(DstTy));
2300 if (isa(C->getType()))
2301 assert(cast(C->getType())->getElementCount() ==
2302 cast(DstTy)->getElementCount() &&
2303 "Invalid cast between a different number of vector elements");
2304 return getFoldedCast(Instruction::PtrToInt, C, DstTy, OnlyIfReduced);
2305}
2306
2308 bool OnlyIfReduced) {
2309 assert(C->getType()->isIntOrIntVectorTy() &&
2310 "IntToPtr source must be integer or integer vector");
2312 "IntToPtr destination must be a pointer or pointer vector");
2313 assert(isa(C->getType()) == isa(DstTy));
2314 if (isa(C->getType()))
2315 assert(cast(C->getType())->getElementCount() ==
2316 cast(DstTy)->getElementCount() &&
2317 "Invalid cast between a different number of vector elements");
2318 return getFoldedCast(Instruction::IntToPtr, C, DstTy, OnlyIfReduced);
2319}
2320
2322 bool OnlyIfReduced) {
2324 "Invalid constantexpr bitcast!");
2325
2326
2327
2328 if (C->getType() == DstTy) return C;
2329
2330 return getFoldedCast(Instruction::BitCast, C, DstTy, OnlyIfReduced);
2331}
2332
2334 bool OnlyIfReduced) {
2336 "Invalid constantexpr addrspacecast!");
2337 return getFoldedCast(Instruction::AddrSpaceCast, C, DstTy, OnlyIfReduced);
2338}
2339
2341 unsigned Flags, Type *OnlyIfReducedTy) {
2342
2344 "Invalid opcode in binary constant expression");
2346 "Binop not supported as constant expression");
2348 "Operand types in binary constant expression should match");
2349
2350#ifndef NDEBUG
2351 switch (Opcode) {
2352 case Instruction::Add:
2353 case Instruction::Sub:
2354 case Instruction::Mul:
2356 "Tried to create an integer operation on a non-integer type!");
2357 break;
2358 case Instruction::And:
2359 case Instruction::Or:
2360 case Instruction::Xor:
2362 "Tried to create a logical operation on a non-integral type!");
2363 break;
2364 default:
2365 break;
2366 }
2367#endif
2368
2370 return FC;
2371
2372 if (OnlyIfReducedTy == C1->getType())
2373 return nullptr;
2374
2375 Constant *ArgVec[] = {C1, C2};
2377
2380}
2381
2383 switch (Opcode) {
2384 case Instruction::UDiv:
2385 case Instruction::SDiv:
2386 case Instruction::URem:
2387 case Instruction::SRem:
2388 case Instruction::FAdd:
2389 case Instruction::FSub:
2390 case Instruction::FMul:
2391 case Instruction::FDiv:
2392 case Instruction::FRem:
2393 case Instruction::And:
2394 case Instruction::Or:
2395 case Instruction::LShr:
2396 case Instruction::AShr:
2397 case Instruction::Shl:
2398 return false;
2399 case Instruction::Add:
2400 case Instruction::Sub:
2401 case Instruction::Mul:
2402 case Instruction::Xor:
2403 return true;
2404 default:
2406 }
2407}
2408
2410 switch (Opcode) {
2411 case Instruction::UDiv:
2412 case Instruction::SDiv:
2413 case Instruction::URem:
2414 case Instruction::SRem:
2415 case Instruction::FAdd:
2416 case Instruction::FSub:
2417 case Instruction::FMul:
2418 case Instruction::FDiv:
2419 case Instruction::FRem:
2420 case Instruction::And:
2421 case Instruction::Or:
2422 case Instruction::LShr:
2423 case Instruction::AShr:
2424 case Instruction::Shl:
2425 return false;
2426 case Instruction::Add:
2427 case Instruction::Sub:
2428 case Instruction::Mul:
2429 case Instruction::Xor:
2430 return true;
2431 default:
2433 }
2434}
2435
2437 switch (Opcode) {
2438 case Instruction::ZExt:
2439 case Instruction::SExt:
2440 case Instruction::FPTrunc:
2441 case Instruction::FPExt:
2442 case Instruction::UIToFP:
2443 case Instruction::SIToFP:
2444 case Instruction::FPToUI:
2445 case Instruction::FPToSI:
2446 return false;
2447 case Instruction::Trunc:
2448 case Instruction::PtrToInt:
2449 case Instruction::IntToPtr:
2450 case Instruction::BitCast:
2451 case Instruction::AddrSpaceCast:
2452 return true;
2453 default:
2455 }
2456}
2457
2459 switch (Opcode) {
2460 case Instruction::ZExt:
2461 case Instruction::SExt:
2462 case Instruction::FPTrunc:
2463 case Instruction::FPExt:
2464 case Instruction::UIToFP:
2465 case Instruction::SIToFP:
2466 case Instruction::FPToUI:
2467 case Instruction::FPToSI:
2468 return false;
2469 case Instruction::Trunc:
2470 case Instruction::PtrToInt:
2471 case Instruction::IntToPtr:
2472 case Instruction::BitCast:
2473 case Instruction::AddrSpaceCast:
2474 return true;
2475 default:
2477 }
2478}
2479
2481
2482
2488}
2489
2491
2492
2498 Constant *Indices[2] = {Zero, One};
2501}
2502
2506 std::optional InRange,
2507 Type *OnlyIfReducedTy) {
2508 assert(Ty && "Must specify element type");
2510
2512 return FC;
2513
2515 ;
2516
2517
2519 if (OnlyIfReducedTy == ReqTy)
2520 return nullptr;
2521
2523 if (VectorType *VecTy = dyn_cast(ReqTy))
2524 EltCount = VecTy->getElementCount();
2525
2526
2527 std::vector<Constant*> ArgVec;
2528 ArgVec.reserve(1 + Idxs.size());
2529 ArgVec.push_back(C);
2531 for (; GTI != GTE; ++GTI) {
2532 auto *Idx = cast(GTI.getOperand());
2534 (!isa(Idx->getType()) ||
2535 cast(Idx->getType())->getElementCount() == EltCount) &&
2536 "getelementptr index type missmatch");
2537
2538 if (GTI.isStruct() && Idx->getType()->isVectorTy()) {
2539 Idx = Idx->getSplatValue();
2540 } else if (GTI.isSequential() && EltCount.isNonZero() &&
2541 ->getType()->isVectorTy()) {
2543 }
2544 ArgVec.push_back(Idx);
2545 }
2546
2549
2551 return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
2552}
2553
2555 Type *OnlyIfReducedTy) {
2557 "Tried to create extractelement operation on non-vector type!");
2558 assert(Idx->getType()->isIntegerTy() &&
2559 "Extractelement index must be an integer type!");
2560
2562 return FC;
2563
2564 Type *ReqTy = cast(Val->getType())->getElementType();
2565 if (OnlyIfReducedTy == ReqTy)
2566 return nullptr;
2567
2568
2571
2573 return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
2574}
2575
2579 "Tried to create insertelement operation on non-vector type!");
2580 assert(Elt->getType() == cast(Val->getType())->getElementType() &&
2581 "Insertelement types must match!");
2582 assert(Idx->getType()->isIntegerTy() &&
2583 "Insertelement index must be i32 type!");
2584
2586 return FC;
2587
2588 if (OnlyIfReducedTy == Val->getType())
2589 return nullptr;
2590
2591
2594
2597}
2598
2601 Type *OnlyIfReducedTy) {
2603 "Invalid shuffle vector constant expr operands!");
2604
2606 return FC;
2607
2608 unsigned NElts = Mask.size();
2609 auto V1VTy = cast(V1->getType());
2610 Type *EltTy = V1VTy->getElementType();
2611 bool TypeIsScalable = isa(V1VTy);
2613
2614 if (OnlyIfReducedTy == ShufTy)
2615 return nullptr;
2616
2617
2618 Constant *ArgVec[] = {V1, V2};
2620
2622 return pImpl->ExprConstants.getOrCreate(ShufTy, Key);
2623}
2624
2626 assert(C->getType()->isIntOrIntVectorTy() &&
2627 "Cannot NEG a nonintegral value!");
2628 return getSub(ConstantInt::get(C->getType(), 0), C, false, HasNSW);
2629}
2630
2632 assert(C->getType()->isIntOrIntVectorTy() &&
2633 "Cannot NOT a nonintegral value!");
2635}
2636
2638 bool HasNUW, bool HasNSW) {
2641 return get(Instruction::Add, C1, C2, Flags);
2642}
2643
2645 bool HasNUW, bool HasNSW) {
2648 return get(Instruction::Sub, C1, C2, Flags);
2649}
2650
2652 bool HasNUW, bool HasNSW) {
2655 return get(Instruction::Mul, C1, C2, Flags);
2656}
2657
2659 return get(Instruction::Xor, C1, C2);
2660}
2661
2664 const APInt *IVal;
2666 return ConstantInt::get(Ty, IVal->logBase2());
2667
2668
2669 auto *VecTy = dyn_cast(Ty);
2670 if (!VecTy)
2671 return nullptr;
2672
2674 for (unsigned I = 0, E = VecTy->getNumElements(); I != E; ++I) {
2675 Constant *Elt = C->getAggregateElement(I);
2676 if (!Elt)
2677 return nullptr;
2678
2679 if (isa(Elt)) {
2681 continue;
2682 }
2684 return nullptr;
2686 }
2687
2689}
2690
2692 bool AllowRHSConstant, bool NSZ) {
2694
2695
2697 switch (Opcode) {
2698 case Instruction::Add:
2699 case Instruction::Or:
2700 case Instruction::Xor:
2702 case Instruction::Mul:
2703 return ConstantInt::get(Ty, 1);
2704 case Instruction::And:
2706 case Instruction::FAdd:
2708 case Instruction::FMul:
2709 return ConstantFP::get(Ty, 1.0);
2710 default:
2711 llvm_unreachable("Every commutative binop has an identity constant");
2712 }
2713 }
2714
2715
2716 if (!AllowRHSConstant)
2717 return nullptr;
2718
2719 switch (Opcode) {
2720 case Instruction::Sub:
2721 case Instruction::Shl:
2722 case Instruction::LShr:
2723 case Instruction::AShr:
2724 case Instruction::FSub:
2726 case Instruction::SDiv:
2727 case Instruction::UDiv:
2728 return ConstantInt::get(Ty, 1);
2729 case Instruction::FDiv:
2730 return ConstantFP::get(Ty, 1.0);
2731 default:
2732 return nullptr;
2733 }
2734}
2735
2737 switch (ID) {
2738 case Intrinsic::umax:
2740 case Intrinsic::umin:
2742 case Intrinsic::smax:
2745 case Intrinsic::smin:
2748 default:
2749 return nullptr;
2750 }
2751}
2752
2754 bool AllowRHSConstant, bool NSZ) {
2755 if (I->isBinaryOp())
2756 return getBinOpIdentity(I->getOpcode(), Ty, AllowRHSConstant, NSZ);
2759 return nullptr;
2760}
2761
2763 bool AllowLHSConstant) {
2764 switch (Opcode) {
2765 default:
2766 break;
2767
2768 case Instruction::Or:
2770
2771 case Instruction::And:
2772 case Instruction::Mul:
2774 }
2775
2776
2777 if (!AllowLHSConstant)
2778 return nullptr;
2779
2780 switch (Opcode) {
2781 default:
2782 return nullptr;
2783 case Instruction::Shl:
2784 case Instruction::LShr:
2785 case Instruction::AShr:
2786 case Instruction::SDiv:
2787 case Instruction::UDiv:
2788 case Instruction::URem:
2789 case Instruction::SRem:
2791 }
2792}
2793
2794
2795void ConstantExpr::destroyConstantImpl() {
2797}
2798
2801}
2802
2803GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2807 SrcElementTy(SrcElementTy),
2808 ResElementTy(GetElementPtrInst::getIndexedType(SrcElementTy, IdxList)),
2812 for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
2813 OperandList[i+1] = IdxList[i];
2814}
2815
2817 return SrcElementTy;
2818}
2819
2821 return ResElementTy;
2822}
2823
2825 return InRange;
2826}
2827
2828
2829
2830
2833 return ATy->getElementType();
2834 return cast(getType())->getElementType();
2835}
2836
2839}
2840
2843 return true;
2844 if (auto *IT = dyn_cast(Ty)) {
2845 switch (IT->getBitWidth()) {
2846 case 8:
2847 case 16:
2848 case 32:
2849 case 64:
2850 return true;
2851 default: break;
2852 }
2853 }
2854 return false;
2855}
2856
2859 return AT->getNumElements();
2860 return cast(getType())->getNumElements();
2861}
2862
2863
2866}
2867
2868
2869const char *ConstantDataSequential::getElementPointer(unsigned Elt) const {
2872}
2873
2874
2875
2877 for (char I : Arr)
2878 if (I != 0)
2879 return false;
2880 return true;
2881}
2882
2883
2884
2885
2886
2888#ifndef NDEBUG
2889 if (ArrayType *ATy = dyn_cast(Ty))
2891 else
2893#endif
2894
2895
2898
2899
2900 auto &Slot =
2903 .first;
2904
2905
2906
2907
2908
2909 std::unique_ptr *Entry = &Slot.second;
2910 for (; *Entry; Entry = &(*Entry)->Next)
2911 if ((*Entry)->getType() == Ty)
2912 return Entry->get();
2913
2914
2915
2916 if (isa(Ty)) {
2917
2919 return Entry->get();
2920 }
2921
2922 assert(isa(Ty));
2923
2925 return Entry->get();
2926}
2927
2928void ConstantDataSequential::destroyConstantImpl() {
2929
2932
2934
2935 assert(Slot != CDSConstants.end() && "CDS not found in uniquing table");
2936
2937 std::unique_ptr *Entry = &Slot->getValue();
2938
2939
2940 if (!(*Entry)->Next) {
2941
2942
2943 assert(Entry->get() == this && "Hash mismatch in ConstantDataSequential");
2945 return;
2946 }
2947
2948
2949
2950 while (true) {
2951 std::unique_ptr &Node = *Entry;
2952 assert(Node && "Didn't find entry in its uniquing hash table!");
2953
2954 if (Node.get() == this) {
2955 Node = std::move(Node->Next);
2956 return;
2957 }
2958
2960 }
2961}
2962
2963
2964
2965
2966
2967
2968
2970 assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
2971 "Element type is not a 16-bit float type");
2973 const char *Data = reinterpret_cast<const char *>(Elts.data());
2975}
2977 assert(ElementType->isFloatTy() && "Element type is not a 32-bit float type");
2979 const char *Data = reinterpret_cast<const char *>(Elts.data());
2981}
2983 assert(ElementType->isDoubleTy() &&
2984 "Element type is not a 64-bit float type");
2986 const char *Data = reinterpret_cast<const char *>(Elts.data());
2988}
2989
2992 if (!AddNull) {
2993 const uint8_t *Data = Str.bytes_begin();
2995 }
2996
2998 ElementVals.append(Str.begin(), Str.end());
3000 return get(Context, ElementVals);
3001}
3002
3003
3004
3005
3008 const char *Data = reinterpret_cast<const char *>(Elts.data());
3010}
3013 const char *Data = reinterpret_cast<const char *>(Elts.data());
3015}
3018 const char *Data = reinterpret_cast<const char *>(Elts.data());
3020}
3023 const char *Data = reinterpret_cast<const char *>(Elts.data());
3025}
3028 const char *Data = reinterpret_cast<const char *>(Elts.data());
3030}
3033 const char *Data = reinterpret_cast<const char *>(Elts.data());
3035}
3036
3037
3038
3039
3040
3041
3042
3045 assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
3046 "Element type is not a 16-bit float type");
3048 const char *Data = reinterpret_cast<const char *>(Elts.data());
3050}
3053 assert(ElementType->isFloatTy() && "Element type is not a 32-bit float type");
3055 const char *Data = reinterpret_cast<const char *>(Elts.data());
3057}
3060 assert(ElementType->isDoubleTy() &&
3061 "Element type is not a 64-bit float type");
3063 const char *Data = reinterpret_cast<const char *>(Elts.data());
3065}
3066
3069 "Element type not compatible with ConstantData");
3070 if (ConstantInt *CI = dyn_cast(V)) {
3071 if (CI->getType()->isIntegerTy(8)) {
3073 return get(V->getContext(), Elts);
3074 }
3075 if (CI->getType()->isIntegerTy(16)) {
3077 return get(V->getContext(), Elts);
3078 }
3079 if (CI->getType()->isIntegerTy(32)) {
3081 return get(V->getContext(), Elts);
3082 }
3083 assert(CI->getType()->isIntegerTy(64) && "Unsupported ConstantData type");
3085 return get(V->getContext(), Elts);
3086 }
3087
3088 if (ConstantFP *CFP = dyn_cast(V)) {
3089 if (CFP->getType()->isHalfTy()) {
3091 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3092 return getFP(V->getType(), Elts);
3093 }
3094 if (CFP->getType()->isBFloatTy()) {
3096 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3097 return getFP(V->getType(), Elts);
3098 }
3099 if (CFP->getType()->isFloatTy()) {
3101 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3102 return getFP(V->getType(), Elts);
3103 }
3104 if (CFP->getType()->isDoubleTy()) {
3106 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3107 return getFP(V->getType(), Elts);
3108 }
3109 }
3111}
3112
3113
3116 "Accessor can only be used when element is an integer");
3117 const char *EltPtr = getElementPointer(Elt);
3118
3119
3120
3123 case 8:
3124 return *reinterpret_cast<const uint8_t *>(EltPtr);
3125 case 16:
3126 return *reinterpret_cast<const uint16_t *>(EltPtr);
3127 case 32:
3128 return *reinterpret_cast<const uint32_t *>(EltPtr);
3129 case 64:
3130 return *reinterpret_cast<const uint64_t *>(EltPtr);
3131 }
3132}
3133
3136 "Accessor can only be used when element is an integer");
3137 const char *EltPtr = getElementPointer(Elt);
3138
3139
3140
3143 case 8: {
3144 auto EltVal = *reinterpret_cast<const uint8_t *>(EltPtr);
3145 return APInt(8, EltVal);
3146 }
3147 case 16: {
3148 auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3149 return APInt(16, EltVal);
3150 }
3151 case 32: {
3152 auto EltVal = *reinterpret_cast<const uint32_t *>(EltPtr);
3153 return APInt(32, EltVal);
3154 }
3155 case 64: {
3156 auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
3157 return APInt(64, EltVal);
3158 }
3159 }
3160}
3161
3163 const char *EltPtr = getElementPointer(Elt);
3164
3166 default:
3167 llvm_unreachable("Accessor can only be used when element is float/double!");
3169 auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3171 }
3173 auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3175 }
3177 auto EltVal = *reinterpret_cast<const uint32_t *>(EltPtr);
3179 }
3181 auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
3183 }
3184 }
3185}
3186
3189 "Accessor can only be used when element is a 'float'");
3190 return *reinterpret_cast<const float *>(getElementPointer(Elt));
3191}
3192
3195 "Accessor can only be used when element is a 'float'");
3196 return *reinterpret_cast<const double *>(getElementPointer(Elt));
3197}
3198
3203
3205}
3206
3209}
3210
3213 return false;
3214
3216
3217
3218 if (Str.back() != 0) return false;
3219
3220
3221 return !Str.drop_back().contains(0);
3222}
3223
3224bool ConstantDataVector::isSplatData() const {
3226
3227
3229 for (unsigned i = 1, e = getNumElements(); i != e; ++i)
3231 return false;
3232
3233 return true;
3234}
3235
3237 if (!IsSplatSet) {
3238 IsSplatSet = true;
3239 IsSplat = isSplatData();
3240 }
3241 return IsSplat;
3242}
3243
3245
3247}
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3264 Value *Replacement = nullptr;
3266 default:
3268#define HANDLE_CONSTANT(Name) \
3269 case Value::Name##Val: \
3270 Replacement = cast(this)->handleOperandChangeImpl(From, To); \
3271 break;
3272#include "llvm/IR/Value.def"
3273 }
3274
3275
3276
3277 if (!Replacement)
3278 return;
3279
3280
3281 assert(Replacement != this && "I didn't contain From!");
3282
3283
3285
3286
3288}
3289
3291 assert(isa(To) && "Cannot make Constant refer to non-constant!");
3292 Constant *ToC = cast(To);
3293
3296
3297
3298
3299 unsigned NumUpdated = 0;
3300
3301
3302 bool AllSame = true;
3304 unsigned OperandNo = 0;
3305 for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
3306 Constant *Val = cast(O->get());
3307 if (Val == From) {
3308 OperandNo = (O - OperandList);
3309 Val = ToC;
3310 ++NumUpdated;
3311 }
3313 AllSame &= Val == ToC;
3314 }
3315
3318
3319 if (AllSame && isa(ToC))
3321
3322
3324 return C;
3325
3326
3328 Values, this, From, ToC, NumUpdated, OperandNo);
3329}
3330
3332 assert(isa(To) && "Cannot make Constant refer to non-constant!");
3333 Constant *ToC = cast(To);
3334
3336
3339
3340
3341
3342 unsigned NumUpdated = 0;
3343 bool AllSame = true;
3344 unsigned OperandNo = 0;
3345 for (Use *O = OperandList, *E = OperandList + getNumOperands(); O != E; ++O) {
3346 Constant *Val = cast(O->get());
3347 if (Val == From) {
3348 OperandNo = (O - OperandList);
3349 Val = ToC;
3350 ++NumUpdated;
3351 }
3353 AllSame &= Val == ToC;
3354 }
3355
3358
3359 if (AllSame && isa(ToC))
3361
3362
3364 Values, this, From, ToC, NumUpdated, OperandNo);
3365}
3366
3368 assert(isa(To) && "Cannot make Constant refer to non-constant!");
3369 Constant *ToC = cast(To);
3370
3373 unsigned NumUpdated = 0;
3374 unsigned OperandNo = 0;
3375 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
3377 if (Val == From) {
3378 OperandNo = i;
3379 ++NumUpdated;
3380 Val = ToC;
3381 }
3383 }
3384
3385 if (Constant *C = getImpl(Values))
3386 return C;
3387
3388
3390 Values, this, From, ToC, NumUpdated, OperandNo);
3391}
3392
3394 assert(isa(ToV) && "Cannot make Constant refer to non-constant!");
3395 Constant *To = cast(ToV);
3396
3398 unsigned NumUpdated = 0;
3399 unsigned OperandNo = 0;
3400 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
3403 OperandNo = i;
3404 ++NumUpdated;
3405 Op = To;
3406 }
3408 }
3409 assert(NumUpdated && "I didn't contain From!");
3410
3412 return C;
3413
3414
3416 NewOps, this, From, To, NumUpdated, OperandNo);
3417}
3418
3422
3424 case Instruction::Trunc:
3425 case Instruction::PtrToInt:
3426 case Instruction::IntToPtr:
3427 case Instruction::BitCast:
3428 case Instruction::AddrSpaceCast:
3431 case Instruction::InsertElement:
3433 case Instruction::ExtractElement:
3435 case Instruction::ShuffleVector:
3437
3438 case Instruction::GetElementPtr: {
3439 const auto *GO = cast(this);
3441 Ops.slice(1), GO->getNoWrapFlags(), "");
3442 }
3443 default:
3447 if (isa(BO)) {
3452 }
3453 if (isa(BO))
3455 return BO;
3456 }
3457}
This file defines the StringMap class.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
BlockVerifier::State From
static bool isAllZeros(StringRef Arr)
Return true if the array is empty or all zeros.
static cl::opt< bool > UseConstantIntForScalableSplat("use-constant-int-for-scalable-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantInt's native scalable vector splat support."))
static cl::opt< bool > UseConstantIntForFixedLengthSplat("use-constant-int-for-fixed-length-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantInt's native fixed-length vector splat support."))
static Constant * getFPSequenceIfElementsMatch(ArrayRef< Constant * > V)
static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt)
static Constant * getIntSequenceIfElementsMatch(ArrayRef< Constant * > V)
static Constant * getSequenceIfElementsMatch(Constant *C, ArrayRef< Constant * > V)
static bool ConstHasGlobalValuePredicate(const Constant *C, bool(*Predicate)(const GlobalValue *))
Check if C contains a GlobalValue for which Predicate is true.
static cl::opt< bool > UseConstantFPForScalableSplat("use-constant-fp-for-scalable-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantFP's native scalable vector splat support."))
static bool constantIsDead(const Constant *C, bool RemoveDeadUsers)
Return true if the specified constantexpr is dead.
static bool containsUndefinedElement(const Constant *C, function_ref< bool(const Constant *)> HasFn)
static Constant * getFoldedCast(Instruction::CastOps opc, Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is a utility function to handle folding of casts and lookup of the cast in the ExprConstants map...
static cl::opt< bool > UseConstantFPForFixedLengthSplat("use-constant-fp-for-fixed-length-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantFP's native fixed-length vector splat support."))
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
static Function * getFunction(Constant *C)
static bool isSigned(unsigned int Opcode)
static char getTypeID(Type *Ty)
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static bool isUndef(ArrayRef< int > Mask)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Merge contiguous icmps into a memcmp
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
static unsigned getAddressSpace(const Value *V, unsigned MaxLookup)
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getNumElements(Type *Ty)
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
bool bitwiseIsEqual(const APFloat &RHS) const
static APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
const fltSemantics & getSemantics() const
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned logBase2() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Class to represent array types.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Type * getElementType() const
LLVM Basic Block Representation.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Function * getParent() const
Return the enclosing method, or null if none.
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
The address of a basic block.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Function * getFunction() const
BasicBlock * getBasicBlock() const
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
CastConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implement...
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
All zero aggregate value.
ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
Constant * getElementValue(Constant *C) const
Return a zero of the right value for the specified GEP index if we can, otherwise return null (e....
Constant * getStructElement(unsigned Elt) const
If this CAZ has struct type, return a zero with the right element type for the specified element.
static ConstantAggregateZero * get(Type *Ty)
Base class for aggregate constants (with operands).
ConstantAggregate(Type *T, ValueTy VT, ArrayRef< Constant * > V, AllocInfo AllocInfo)
ConstantArray - Constant Array Declarations.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
APInt getElementAsAPInt(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element as an APInt...
double getElementAsDouble(unsigned i) const
If this is an sequential container of doubles, return the specified element as a double.
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
float getElementAsFloat(unsigned i) const
If this is an sequential container of floats, return the specified element as a float.
bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
static Constant * getImpl(StringRef Bytes, Type *Ty)
This is the underlying implementation of all of the ConstantDataSequential::get methods.
unsigned getNumElements() const
Return the number of elements in the array or vector.
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
Type * getElementType() const
Return the element type of the array/vector.
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
APFloat getElementAsAPFloat(unsigned i) const
If this is a sequential container of floating point type, return the specified element as an APFloat.
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
static bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value,...
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
bool isSplat() const
Returns true if this is a splat constant, meaning that all elements have the same value.
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of vector type with a float element type taken from argument...
Base class for constants with no operands.
A constant value that is initialized with an expression using other constant values.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
bool isCast() const
Return true if this is a convert constant expression.
static Constant * getIdentity(Instruction *I, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary or intrinsic Instruction.
static bool isDesirableCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is desirable.
Constant * getShuffleMaskForBitcode() const
Assert that this is a shufflevector and return the mask.
static Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty, bool AllowLHSConstant=false)
Return the absorbing element for the given binary operation, i.e.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getNot(Constant *C)
const char * getOpcodeName() const
Return a string representation for an opcode.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static Constant * getIntrinsicIdentity(Intrinsic::ID, Type *Ty)
static Constant * getXor(Constant *C1, Constant *C2)
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
static bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
ArrayRef< int > getShuffleMask() const
Assert that this is a shufflevector and return the mask.
static bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static bool isSupportedCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is supported.
static Constant * getNeg(Constant *C, bool HasNSW=false)
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getExactLogBase2(Constant *C)
If C is a scalar/fixed width vector of known powers of 2, then this function returns a new scalar/fix...
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values.
Instruction * getAsInstruction() const
Returns an Instruction which implements the same operation as this ConstantExpr.
ConstantFP - Floating Point Values [float, double].
static Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
static Constant * getInfinity(Type *Ty, bool Negative=false)
static Constant * getZero(Type *Ty, bool Negative=false)
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
static Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
This is the shared class of boolean and integer constants.
static bool isValueValidForType(Type *Ty, uint64_t V)
This static method returns true if the type Ty is big enough to represent the value V.
static ConstantInt * getTrue(LLVMContext &Context)
static ConstantInt * getFalse(LLVMContext &Context)
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
static ConstantInt * getBool(LLVMContext &Context, bool V)
A constant pointer value that points to null.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
A signed pointer, in the ptrauth sense.
Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
bool isKnownCompatibleWith(const Value *Key, const Value *Discriminator, const DataLayout &DL) const
Check whether an authentication operation with key Key and (possibly blended) discriminator Discrimin...
bool hasSpecialAddressDiscriminator(uint64_t Value) const
Whether the address uses a special address discriminator.
static ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc)
Return a pointer signed with the specified parameters.
ConstantPtrAuth * getWithSameSchema(Constant *Pointer) const
Produce a new ptrauth expression signing the given value using the same schema as is stored in one.
ConstantInt * getKey() const
The Key ID, an i32 constant.
bool hasAddressDiscriminator() const
Whether there is any non-null address discriminator.
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
This class represents a range of values.
ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static StructType * getTypeForElements(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct type to use for a constant with the specified set of elements.
StructType * getType() const
Specialization - reduce amount of casting.
A constant target extension type default initializer.
static ConstantTargetNone * get(TargetExtType *T)
Static factory methods - Return objects of the specified value.
TargetExtType * getType() const
Specialize the getType() method to always return an TargetExtType, which reduces the amount of castin...
A constant token which is empty.
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
void remove(ConstantClass *CP)
Remove this constant from the map.
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
Constant Vector Declarations.
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
static Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
bool hasExactInverseFP() const
Return true if this scalar has an exact multiplicative inverse or this vector has an exact multiplica...
static Constant * replaceUndefsWith(Constant *C, Constant *Replacement)
Try to replace undefined constant C or undefined elements in C with Replacement.
Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
bool containsUndefElement() const
Return true if this is a vector constant that includes any strictly undef (not poison) elements.
static Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
ConstantRange toConstantRange() const
Convert constant to an approximate constant range.
static Constant * getAllOnesValue(Type *Ty)
bool hasZeroLiveUses() const
Return true if the constant has no live uses.
bool isOneValue() const
Returns true if the value is one.
bool isManifestConstant() const
Return true if a constant is ConstantData or a ConstantAggregate or ConstantExpr that contain only Co...
bool isNegativeZeroValue() const
Return true if the value is what would be returned by getZeroValueForNegation.
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
bool hasOneLiveUse() const
Return true if the constant has exactly one live use.
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry (eith...
bool isDLLImportDependent() const
Return true if the value is dependent on a dllimport variable.
const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
bool containsConstantExpression() const
Return true if this is a fixed width vector constant that includes any constant expressions.
bool isFiniteNonZeroFP() const
Return true if this is a finite and non-zero floating-point scalar constant or a fixed width vector c...
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
bool isNormalFP() const
Return true if this is a normal (as opposed to denormal, infinity, nan, or zero) floating-point scala...
bool needsDynamicRelocation() const
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
bool isNaN() const
Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN...
bool isMinSignedValue() const
Return true if the value is the smallest signed value.
bool isConstantUsed() const
Return true if the constant has users other than constant expressions and other dangling things.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
bool isThreadDependent() const
Return true if the value can vary between threads.
bool isZeroValue() const
Return true if the value is negative zero or null value.
void destroyConstant()
Called if some element of this constant is no longer valid.
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
bool isNotOneValue() const
Return true if the value is not the one value, or, for vectors, does not contain one value elements.
bool isElementWiseEqual(Value *Y) const
Return true if this constant and a constant 'Y' are element-wise equal.
bool containsUndefOrPoisonElement() const
Return true if this is a vector constant that includes any undef or poison elements.
bool containsPoisonElement() const
Return true if this is a vector constant that includes any poison elements.
void handleOperandChange(Value *, Value *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does...
Wrapper for a function that represents a value that functionally represents the original function.
GlobalValue * getGlobalValue() const
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
static constexpr ElementCount getFixed(ScalarTy MinVal)
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Represents flags for the getelementptr instruction/expression.
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
std::optional< ConstantRange > getInRange() const
Type * getResultElementType() const
Type * getSourceElementType() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
PointerType * getType() const
Global values are always pointers.
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
const char * getOpcodeName() const
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Class to represent integer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
A wrapper class for inspecting calls to intrinsic functions.
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntOneConstants
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntZeroConstants
DenseMap< APFloat, std::unique_ptr< ConstantFP > > FPConstants
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
ConstantInt * TheFalseVal
DenseMap< Type *, std::unique_ptr< PoisonValue > > PVConstants
DenseMap< std::pair< const Function *, const BasicBlock * >, BlockAddress * > BlockAddresses
DenseMap< APInt, std::unique_ptr< ConstantInt > > IntConstants
std::unique_ptr< ConstantTokenNone > TheNoneToken
VectorConstantsTy VectorConstants
DenseMap< const GlobalValue *, NoCFIValue * > NoCFIValues
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
StringMap< std::unique_ptr< ConstantDataSequential > > CDSConstants
StructConstantsTy StructConstants
ConstantUniqueMap< ConstantPtrAuth > ConstantPtrAuths
DenseMap< TargetExtType *, std::unique_ptr< ConstantTargetNone > > CTNConstants
ConstantUniqueMap< ConstantExpr > ExprConstants
DenseMap< std::pair< ElementCount, APInt >, std::unique_ptr< ConstantInt > > IntSplatConstants
ArrayConstantsTy ArrayConstants
DenseMap< const GlobalValue *, DSOLocalEquivalent * > DSOLocalEquivalents
DenseMap< std::pair< ElementCount, APFloat >, std::unique_ptr< ConstantFP > > FPSplatConstants
This is an important class for using LLVM in a threaded context.
LLVMContextImpl *const pImpl
Wrapper for a value that won't be replaced with a CFI jump table pointer in LowerTypeTestsModule.
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
PointerType * getType() const
NoCFIValue is always a pointer.
GlobalValue * getGlobalValue() const
Class to represent pointers.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
PoisonValue * getStructElement(unsigned Elt) const
If this poison has struct type, return a poison with the right element type for the specified element...
PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
PoisonValue * getElementValue(Constant *C) const
Return an poison of the right value for the specified GEP index if we can, otherwise return null (e....
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
This instruction constructs a fixed permutation of two input vectors.
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Class to represent struct types.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
@ HasZeroInit
zeroinitializer is valid for this target extension type.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getIntegerBitWidth() const
static Type * getDoubleTy(LLVMContext &C)
const fltSemantics & getFltSemantics() const
bool isVectorTy() const
True if this is an instance of VectorType.
static Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
static IntegerType * getInt1Ty(LLVMContext &C)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
unsigned getStructNumElements() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isStructTy() const
True if this is an instance of StructType.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
static IntegerType * getInt16Ty(LLVMContext &C)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt8Ty(LLVMContext &C)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
'undef' values are things that do not have specified contents.
UndefValue * getElementValue(Constant *C) const
Return an undef of the right value for the specified GEP index if we can, otherwise return null (e....
UndefValue * getStructElement(unsigned Elt) const
If this undef has struct type, return a undef with the right element type for the specified element.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
A Use represents the edge between a Value definition and its users.
const Use * getOperandList() const
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
iterator_range< value_op_iterator > operand_values()
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
user_iterator_impl< const User > const_user_iterator
user_iterator user_begin()
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
Accumulate the constant offset this value has compared to a base pointer.
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
unsigned getValueID() const
Return an ID for the concrete type of this object.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
ValueTy
Concrete subclass of this.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Type * getElementType() const
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
auto m_Undef()
Match an arbitrary undef constant.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
gep_type_iterator gep_type_end(const User *GEP)
void deleteConstant(Constant *C)
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, std::optional< ConstantRange > InRange, ArrayRef< Value * > Idxs)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
gep_type_iterator gep_type_begin(const User *GEP)
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, ArrayRef< int > Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and mask.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
Implement std::hash so that hash_code can be used in STL containers.
static const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToEven
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
static const fltSemantics & IEEEquad() LLVM_READNONE
static const fltSemantics & IEEEdouble() LLVM_READNONE
static const fltSemantics & IEEEhalf() LLVM_READNONE
static const fltSemantics & BFloat() LLVM_READNONE
Summary of memprof metadata on allocations.
Information about how a User object was allocated, to be passed into the User constructor.