22 : Ctx(M.
getContext()), M(M), ParserContext(ParserContext),
31 if (
F.hasAddressTaken(
nullptr,
35 auto FuncObj =
allocate(0,
F.getPointerAlignment(DL).value(),
F.getName(),
40 ValidFuncTargets.try_emplace(FuncObj->getAddress(),
41 std::make_pair(&
F, FuncObj));
46 if (!BB.hasAddressTaken())
48 auto BlockObj =
allocate(0, 1, BB.getName(), DL.getProgramAddressSpace(),
52 ValidBlockTargets.try_emplace(BlockObj->getAddress(),
53 std::make_pair(&BB, BlockObj));
59 Type *ValueTy = GV.getValueType();
61 Align Alignment = GV.getPointerAlignment(DL);
65 allocate(
Size, Alignment.value(), GV.getName(), GV.getAddressSpace(),
71 Obj->setIsConstant(GV.isConstant());
76 if (!GV.hasInitializer())
79 MemoryObject *Obj = GlobalAddrMap.at(&GV).provenance().getMemoryObject();
80 assert(Obj &&
"global pointer should have memory object provenance");
88 store(*Obj, 0, *InitVal, GV.getValueType());
116 return MaterializedConstant(
117 std::vector<AnyValue>(
getEVL(VecTy->getElementCount()),
118 AnyValue(CI->getValue())),
120 return MaterializedConstant(CI->getValue(),
true);
125 return MaterializedConstant(
126 std::vector<AnyValue>(
getEVL(VecTy->getElementCount()),
127 AnyValue(CFP->getValue())),
129 return MaterializedConstant(CFP->getValue(),
true);
134 return MaterializedConstant(
135 std::vector<AnyValue>(
136 getEVL(VecTy->getElementCount()),
137 AnyValue(ByteValue(CB->getValue(), DL.isLittleEndian()))),
139 return MaterializedConstant(ByteValue(CB->getValue(), DL.isLittleEndian()),
144 std::vector<AnyValue> Elts;
145 Elts.reserve(CDS->getNumElements());
146 bool Cacheable =
true;
147 for (uint32_t
I = 0,
E = CDS->getNumElements();
I !=
E; ++
I) {
151 Cacheable &= Elt->isCacheable();
152 Elts.push_back(*Elt);
154 return MaterializedConstant(std::move(Elts), Cacheable);
158 std::vector<AnyValue> Elts;
159 Elts.reserve(CA->getNumOperands());
160 bool Cacheable =
true;
161 for (uint32_t
I = 0,
E = CA->getNumOperands();
I !=
E; ++
I) {
165 Cacheable &= Elt->isCacheable();
166 Elts.push_back(*Elt);
168 return MaterializedConstant(std::move(Elts), Cacheable);
172 return MaterializedConstant(BlockAddrMap.at(BA->getBasicBlock()),
176 return MaterializedConstant(GlobalAddrMap.at(GV),
true);
179 return MaterializedConstant(FuncAddrMap.at(
F),
true);
182 return evaluateConstantExpression(CE);
188 unsigned Opc =
CE->getOpcode();
190 case Instruction::Trunc: {
196 unsigned BitWidth =
CE->getType()->getScalarSizeInBits();
197 if (Src->isInteger())
198 return MaterializedConstant(Src->asInteger().trunc(
BitWidth),
200 std::vector<AnyValue> Vec = Src->asAggregate();
201 for (
auto &
V : Vec) {
205 return MaterializedConstant(std::move(Vec), Src->isCacheable());
207 case Instruction::BitCast: {
214 toBytes(*Src, SrcOp->getType(), Bytes);
215 return MaterializedConstant(fromBytes(Bytes,
CE->getType()),
218 case Instruction::InsertElement: {
228 auto &SrcVec = Src->asAggregate();
230 Src->isCacheable() && Val->isCacheable() &&
Idx->isCacheable();
231 if (
Idx->isPoison() ||
Idx->asInteger().uge(SrcVec.size()))
232 return MaterializedConstant(
234 std::vector<AnyValue> ResVec = SrcVec;
235 ResVec[
Idx->asInteger().getZExtValue()] = *Val;
236 return MaterializedConstant(std::move(ResVec), Cacheable);
238 case Instruction::ExtractElement: {
245 auto &SrcVec = Src->asAggregate();
246 bool Cacheable = Src->isCacheable() &&
Idx->isCacheable();
247 if (
Idx->isPoison() ||
Idx->asInteger().uge(SrcVec.size()))
248 return MaterializedConstant(
250 return MaterializedConstant(SrcVec[
Idx->asInteger().getZExtValue()],
253 case Instruction::ShuffleVector: {
260 auto &LHSVec =
LHS->asAggregate();
261 auto &RHSVec =
RHS->asAggregate();
265 std::vector<AnyValue> Res;
269 uint32_t Stride =
CE->getShuffleMask().size();
272 for (uint32_t
Off = 0;
Off != DstLen;
Off += Stride) {
273 for (
int Idx :
CE->getShuffleMask()) {
277 else if (Idx <
static_cast<int>(
Size))
278 Res.push_back(LHSVec[Idx]);
280 Res.push_back(RHSVec[Idx -
Size]);
283 return MaterializedConstant(std::move(Res),
284 LHS->isCacheable() &&
RHS->isCacheable());
286 case Instruction::GetElementPtr: {
290 AnyValue PoisonValue;
291 bool Cacheable =
true;
296 Cacheable &= Val->isCacheable();
302 if (!PoisonValue.isNone())
304 return MaterializedConstant(std::move(Res), Cacheable);
306 case Instruction::PtrToAddr:
307 case Instruction::PtrToInt: {
311 bool Cacheable =
Opc == Instruction::PtrToAddr && Src->isCacheable();
314 unsigned BitWidth =
CE->getType()->getScalarSizeInBits();
315 if (Src->isPointer()) {
316 if (
Opc == Instruction::PtrToInt)
318 return MaterializedConstant(
319 Src->asPointer().address().zextOrTrunc(
BitWidth), Cacheable);
321 std::vector<AnyValue> Vec = Src->asAggregate();
322 for (
auto &
V : Vec) {
324 if (
Opc == Instruction::PtrToInt)
326 V =
V.asPointer().address().zextOrTrunc(
BitWidth);
329 return MaterializedConstant(std::move(Vec), Cacheable);
331 case Instruction::IntToPtr: {
338 DL.getPointerSizeInBits(
CE->getType()->getPointerAddressSpace());
339 if (Src->isInteger())
340 return MaterializedConstant(
342 Src->asInteger().zextOrTrunc(
BitWidth)),
344 std::vector<AnyValue> Vec = Src->asAggregate();
345 for (
auto &
V : Vec) {
350 return MaterializedConstant(std::move(Vec),
false);
352 case Instruction::AddrSpaceCast:
366 HasNUW = OBO->hasNoUnsignedWrap();
367 HasNSW = OBO->hasNoSignedWrap();
370 auto ScalarEval = [&](
const AnyValue &
LHS,
371 const AnyValue &
RHS) -> AnyValue {
372 if (
LHS.isPoison() ||
RHS.isPoison())
374 auto &LHSVal =
LHS.asInteger();
375 auto &RHSVal =
RHS.asInteger();
377 case Instruction::Add:
378 return addNoWrap(LHSVal, RHSVal, HasNSW, HasNUW);
379 case Instruction::Sub:
380 return subNoWrap(LHSVal, RHSVal, HasNSW, HasNUW);
381 case Instruction::Xor:
382 return LHSVal ^ RHSVal;
388 bool Cacheable =
LHS->isCacheable() &&
RHS->isCacheable();
390 if (
CE->getType()->isVectorTy()) {
391 auto &LHSVec =
LHS->asAggregate();
392 auto &RHSVec =
RHS->asAggregate();
393 std::vector<AnyValue> ResVec;
394 ResVec.reserve(LHSVec.size());
395 for (
const auto &[ScalarLHS, ScalarRHS] :
zip(LHSVec, RHSVec))
396 ResVec.push_back(ScalarEval(ScalarLHS, ScalarRHS));
397 return MaterializedConstant(std::move(ResVec), Cacheable);
400 return MaterializedConstant(ScalarEval(*
LHS, *
RHS), Cacheable);
405 auto It = ConstCache.find(
C);
406 if (It != ConstCache.end())
413 assert(NoncacheableConstCount <= 1024 &&
"Unbounded temporary buffer.");
414 ++NoncacheableConstCount;
415 return new (NoncacheableConstBuffer.Allocate())
419 return &ConstCache.emplace(
C, std::move(Val)).first->second;
423 NoncacheableConstBuffer.DestroyAll();
424 NoncacheableConstCount = 0;
432 if (!Prov.getTag().
isZero())
433 return Prov.getTag();
438 if (
Tag.isZero() || !TaggedProvenances.try_emplace(
Tag, &Prov).second)
447 uint32_t OffsetInBits,
bool CheckPaddingBits,
448 bool *ContainsUndefinedBits) {
449 uint32_t NumBits =
DL.getTypeSizeInBits(Ty).getFixedValue();
450 uint32_t NewOffsetInBits = OffsetInBits + NumBits;
451 if (CheckPaddingBits)
452 NewOffsetInBits =
alignTo(NewOffsetInBits, 8);
453 bool NeedsPadding = NewOffsetInBits != OffsetInBits + NumBits;
454 uint32_t NumBitsToExtract = NewOffsetInBits - OffsetInBits;
458 bool IsByteType = Ty->isByteTy();
460 std::vector<Byte> LogicalBytes;
462 LogicalBytes.resize(
divideCeil(NumBitsToExtract, 8));
464 RawBits.resize(NumWords);
465 bool IsTagValid = Ty->isPointerTy();
467 if (Ty->isPointerTy())
468 RawTagBits.resize(NumWords);
469 for (
uint32_t I = 0;
I < NumBitsToExtract;
I += 8) {
472 uint32_t NumBitsInByte = std::min(8U, NumBitsToExtract -
I);
474 uint32_t BitsEnd = BitsStart + NumBitsInByte - 1;
477 if (((BitsStart ^ BitsEnd) & ~7) == 0)
478 LogicalByte = Bytes[BitsStart / 8].lshr(BitsStart % 8);
481 Byte::fshr(Bytes[BitsStart / 8], Bytes[BitsEnd / 8], BitsStart % 8);
483 uint32_t Mask = (1U << NumBitsInByte) - 1;
486 (~LogicalByte.ConcreteMask & ~LogicalByte.Value & Mask)) {
487 if (ContainsUndefinedBits)
488 *ContainsUndefinedBits =
true;
489 OffsetInBits = NewOffsetInBits;
492 uint8_t RandomBits = 0;
493 if (~LogicalByte.ConcreteMask & Mask) {
495 if (ContainsUndefinedBits)
496 *ContainsUndefinedBits =
true;
503 RandomBits =
static_cast<uint8_t
>(Rng());
511 LogicalByte.poisonBits(~LogicalByte.ConcreteMask);
512 LogicalBytes[
I / 8] = LogicalByte;
516 uint8_t ActualBits = ((LogicalByte.Value & LogicalByte.ConcreteMask) |
517 (RandomBits & ~LogicalByte.ConcreteMask)) &
522 assert((LogicalByte.TagMask & LogicalByte.ConcreteMask) ==
523 LogicalByte.TagMask);
526 uint32_t ValueBitsInByte = std::min(NumBitsInByte, NumBits -
I);
527 uint8_t TagBitsMask =
530 :
static_cast<uint8_t
>((1U << ValueBitsInByte) - 1);
531 if ((LogicalByte.TagMask & TagBitsMask) == TagBitsMask) {
532 uint8_t ActualTagBits = LogicalByte.TagValue & TagBitsMask;
541 OffsetInBits = NewOffsetInBits;
544 assert(!CheckPaddingBits &&
545 "Non-vector-element cases should be handled by the fast path.");
546 if (DL.isBigEndian())
547 std::reverse(LogicalBytes.begin(), LogicalBytes.end());
548 return ByteValue(NumBits, std::move(LogicalBytes), DL.isLittleEndian(),
552 APInt
Bits(NumBitsToExtract, RawBits);
557 if (!
Bits.isIntN(NumBits)) {
558 if (ContainsUndefinedBits)
559 *ContainsUndefinedBits =
true;
565 if (Ty->isIntegerTy())
567 if (Ty->isFloatingPointTy())
568 return APFloat(Ty->getFltSemantics(), Bits);
569 assert(Ty->isPointerTy() &&
"Expect a pointer type");
572 APInt
Tag(NumBits, RawTagBits);
573 if (
auto Prov = TaggedProvenances.lookup(
Tag))
574 return Pointer(std::move(Prov), Bits);
580 bool *ContainsUndefinedBits) {
582 "Invalid byte array size for the type");
583 if (Ty->isIntegerTy() || Ty->isFloatingPointTy() || Ty->isPointerTy())
585 true, ContainsUndefinedBits);
586 if (Ty->isByteTy()) {
587 unsigned BitWidth = Ty->getByteBitWidth();
590 bool HasUndefinedBits =
false;
592 if (
V.ConcreteMask != 255)
593 HasUndefinedBits =
true;
594 V.poisonBits(~
V.ConcreteMask);
596 if (ContainsUndefinedBits && HasUndefinedBits)
597 *ContainsUndefinedBits =
true;
606 uint32_t VecBits = ElemBits * NumElements;
611 uint32_t PaddingByteIndex = DL.isLittleEndian() ? Bytes.
size() - 1 : 0;
612 Byte SavedPaddingByte;
613 bool ModifiedPaddingByte =
false;
615 if (ModifiedPaddingByte)
616 Data[PaddingByteIndex] = SavedPaddingByte;
618 if (VecBits != AlignedVecBits) {
619 uint8_t PaddingMask =
static_cast<uint8_t>((~0U) << (VecBits & 7));
620 Byte &PaddingByte =
Data[PaddingByteIndex];
622 SavedPaddingByte = PaddingByte;
624 ModifiedPaddingByte =
true;
625 if (ContainsUndefinedBits)
626 *ContainsUndefinedBits =
true;
631 std::vector<AnyValue> ValVec;
632 ValVec.reserve(NumElements);
639 DL.isLittleEndian() ?
I * ElemBits
640 : VecBits - ElemBits -
I * ElemBits,
641 false, ContainsUndefinedBits));
648 uint32_t NumElements = ArrTy->getNumElements();
649 std::vector<AnyValue> ValVec;
650 ValVec.reserve(NumElements);
652 ValVec.push_back(fromBytes(Bytes.
slice(
I * Stride, StoreSize),
ElemTy,
653 ContainsUndefinedBits));
657 const StructLayout *Layout = DL.getStructLayout(StructTy);
658 std::vector<AnyValue> ValVec;
659 uint32_t NumElements = StructTy->getNumElements();
660 ValVec.reserve(NumElements);
663 ValVec.push_back(fromBytes(
666 ElemTy, ContainsUndefinedBits));
675 uint32_t NumBits =
DL.getTypeSizeInBits(Ty).getFixedValue();
676 uint32_t NewOffsetInBits = OffsetInBits + NumBits;
678 NewOffsetInBits =
alignTo(NewOffsetInBits, 8);
679 bool NeedsPadding = NewOffsetInBits != OffsetInBits + NumBits;
680 auto WriteBits = [&](
const APInt &Bits,
const APInt *TagBits) {
681 for (
uint32_t I = 0,
E = Bits.getBitWidth();
I <
E;
I += 8) {
684 uint32_t BitsEnd = BitsStart + NumBitsInByte - 1;
686 static_cast<uint8_t>(Bits.extractBitsAsZExtValue(NumBitsInByte,
I));
688 Bytes[BitsStart / 8].writeBits(
689 static_cast<uint8_t>(((1U << NumBitsInByte) - 1) << (BitsStart % 8)),
690 static_cast<uint8_t>(BitsVal << (BitsStart % 8)));
693 if (((BitsStart ^ BitsEnd) & ~7) != 0)
694 Bytes[BitsEnd / 8].writeBits(
695 static_cast<uint8_t>((1U << (BitsEnd % 8 + 1)) - 1),
696 static_cast<uint8_t>(BitsVal >> (8 - (BitsStart % 8))));
700 TagBits->extractBitsAsZExtValue(NumBitsInByte,
I));
701 Bytes[BitsStart / 8].writeTagBits(
702 static_cast<uint8_t>(((1U << NumBitsInByte) - 1)
704 static_cast<uint8_t>(TagBitsVal << (BitsStart % 8)));
707 if (((BitsStart ^ BitsEnd) & ~7) != 0)
708 Bytes[BitsEnd / 8].writeTagBits(
709 static_cast<uint8_t>((1U << (BitsEnd % 8 + 1)) - 1),
710 static_cast<uint8_t>(TagBitsVal >> (8 - (BitsStart % 8))));
715 for (uint32_t
I = 0,
E = NewOffsetInBits - OffsetInBits;
I <
E;) {
716 uint32_t BitsStart = OffsetInBits +
I;
717 uint32_t NumBitsInByte = std::min(8 - BitsStart % 8,
E -
I);
718 assert(((BitsStart ^ (BitsStart + NumBitsInByte - 1)) & ~7) == 0 &&
719 "Across byte boundary.");
720 Bytes[BitsStart / 8].poisonBits(
721 static_cast<uint8_t
>(((1U << NumBitsInByte) - 1) << (BitsStart % 8)));
726 WriteBits(NeedsPadding ?
Bits.zext(NewOffsetInBits - OffsetInBits) : Bits,
730 WriteBits(NeedsPadding ?
Bits.zext(NewOffsetInBits - OffsetInBits) : Bits,
736 Tag =
Tag.zext(NewOffsetInBits - OffsetInBits);
737 WriteBits(NeedsPadding ? AddressBits.zext(NewOffsetInBits - OffsetInBits)
742 "Non-vector-element cases should be handled by the fast path.");
743 auto &ByteVal = Val.
asByte();
745 for (uint32_t
I = 0,
E =
static_cast<uint32_t
>(SrcBytes.size());
I !=
E;
747 uint32_t NumBitsInByte = std::min(8U, NumBits -
I * 8);
748 uint32_t BitsStart = OffsetInBits +
I * 8;
749 uint32_t BitsEnd = BitsStart + NumBitsInByte - 1;
751 Bytes[BitsStart / 8].writeByte(
752 static_cast<uint8_t
>(((1U << NumBitsInByte) - 1) << (BitsStart % 8)),
753 SrcBytes[
I].shl(BitsStart % 8));
756 if (((BitsStart ^ BitsEnd) & ~7) != 0)
757 Bytes[BitsEnd / 8].writeByte(
758 static_cast<uint8_t
>((1U << (BitsEnd % 8 + 1)) - 1),
759 SrcBytes[
I].lshr(8 - (BitsStart % 8)));
769 "Invalid byte array size for the type");
770 if (Ty->isIntegerTy() || Ty->isFloatingPointTy() || Ty->isPointerTy()) {
775 if (Ty->isByteTy()) {
776 auto &ByteVal = Val.
asByte();
778 assert(Bytes.
size() == SrcBytes.
size() &&
"Mismatched byte array.");
787 uint32_t VecBits = ElemBits * NumElements;
793 if (DL.isLittleEndian()) {
795 toBytes(Val,
ElemTy, ElemBits *
I, View,
false);
798 toBytes(Val,
ElemTy, ElemBits *
I, View,
false);
802 if (VecBits != AlignedVecBits) {
803 Byte &PaddingByte = View[Bytes.
size() - 1];
830 const StructLayout *Layout = DL.getStructLayout(StructTy);
836 FillUndefBytes(LastAccessedOffset, ElemOffset);
838 Bytes.
slice(ElemOffset, ElemStoreSize));
839 LastAccessedOffset = ElemOffset + ElemStoreSize;
850 assert(OffsetInBits + DL.getTypeSizeInBits(Ty).getFixedValue() <=
852 "Bit range out of bounds");
853 return fromBytes(
ConstBytesView(Src.bytes(), DL), Ty, OffsetInBits,
860 assert(OffsetInBits + DL.getTypeSizeInBits(Ty).getFixedValue() <=
861 Base.getBitWidth() &&
862 "Bit range out of bounds");
869 bool *ContainsUndefinedBits) {
872 ContainsUndefinedBits);
891 static_assert(
decltype(Rng)::word_size >=
892 std::numeric_limits<APInt::WordType>::digits,
893 "Unexpected Rng result type.");
901 uint32_t Bits = DL.getTypeSizeInBits(Ty);
904 if (Ty->isIntegerTy())
906 else if (Ty->isFloatingPointTy())
908 else if (Ty->isPointerTy())
916 for (
Byte &
V : Bytes) {
917 if (
V.ConcreteMask == 255)
920 V.ConcreteMask = 255;
923 V.Value |= (Rng() & 255) & ~OldMask;
933 for (
auto &SubVal : SubVals)
937 for (
auto &SubVal : SubVals)
941 freeze(SubVals[
I], StructTy->getElementType(
I));
956 if (NewIndex.isPoison())
958 if (Flags.hasNoUnsignedSignedWrap()) {
963 if (
Offset.isNonNegative() ? NewIndex.asInteger().ult(IndexBits)
964 : NewIndex.asInteger().ugt(IndexBits))
970 MemoryObject *MO =
nullptr;
971 if (Flags.isInBounds()) {
975 if (!MO || !MO->inBounds(Ptr.
address()) || !MO->inBounds(NewAddr))
979 if (!AccumulatedOffset.
isPoison()) {
982 Flags.hasNoUnsignedSignedWrap(),
Flags.hasNoUnsignedWrap());
991 auto &Prov = Res.provenance();
1003 return computePtrAdd(Ptr.
asPointer(),
Offset, Flags, AccumulatedOffset);
1010 if (Ptr.
isPoison() || Index.isPoison())
1014 return computePtrAdd(Ptr, Index.
asInteger(), Flags, AccumulatedOffset);
1016 mulNoWrap(Index.asInteger(), Scale, Flags.hasNoUnsignedSignedWrap(),
1017 Flags.hasNoUnsignedWrap());
1018 if (ScaledOffset.isPoison())
1020 return computePtrAdd(Ptr, ScaledOffset.
asInteger(), Flags, AccumulatedOffset);
1027 auto &IdxInt = Idx.asInteger();
1028 if (IdxInt.getBitWidth() == IndexBitWidth)
1030 if (IdxInt.getBitWidth() > IndexBitWidth) {
1031 if (Flags.hasNoUnsignedSignedWrap() && !IdxInt.isSignedIntN(IndexBitWidth))
1034 if (Flags.hasNoUnsignedWrap() && !IdxInt.isIntN(IndexBitWidth))
1037 return IdxInt.trunc(IndexBitWidth);
1039 return IdxInt.sext(IndexBitWidth);
1046 DL.getIndexSizeInBits(
GEP.getType()->getPointerAddressSpace());
1053 auto ApplyScaledOffset = [&](
const AnyValue &Index,
const APInt &Scale) {
1054 if (Index.isAggregate()) {
1056 for (
auto &&[ResElem, IndexElem, OffsetElem] :
1065 for (
auto &&[ResElem, OffsetElem] :
1077 GTI != GTE; ++GTI) {
1078 Value *
V = GTI.getOperand();
1099 if (
StructType *STy = GTI.getStructTypeOrNull()) {
1100 unsigned ElementIdx =
1106 APInt(IndexBitWidth, 1));
1117 ApplyScaledOffset(GetValue(
V), Scale);
1126 : Address(Addr), Size(Size), Name(Name), AS(AS),
1129 AllocKind(AllocKind), IsIRGlobalValue(IsIRGlobalValue) {
1146 bool IsIRGlobalValue) {
1155 unsigned AddressBW = DL.getAddressSizeInBits(AS);
1157 if (!
isUIntN(AddressBW, AlignedAddr))
1160 AlignedAddr,
Size, Name, AS, InitKind, AllocKind, IsIRGlobalValue);
1161 MemoryObjects[AlignedAddr] = MemObj;
1164 AllocationBase = AlignedAddr + AllocateSize + 1;
1165 UsedMem += AllocateSize;
1171 auto It = MemoryObjects.find(
Address);
1172 if (It == MemoryObjects.end() || It->second.get() != &Obj)
1175 UsedMem -= std::max(It->second->getSize(),
static_cast<uint64_t>(1));
1179 MutableObj.Bytes.clear();
1180 for (
const APInt &
Tag : MutableObj.AssociatedTags)
1181 TaggedProvenances.erase(
Tag);
1182 MutableObj.AssociatedTags.clear();
1183 ExposedProvenances.erase(
Address);
1185 MemoryObjects.erase(It);
1190 assert(Obj &&
"Cannot determine the address space of a null memory object");
1192 APInt(DL.getPointerSizeInBits(Obj->getAddressSpace()),
1193 Obj->getAddress()));
1203 ExposedProvenanceSet &Set = ExposedProvenances[
Address];
1204 if (Set.Set.insert(&Prov).second)
1205 Set.List.push_back({&Prov, ++ExposedProvenanceSetGeneration});
1211 bool HasSideEffect) {
1217 return Prov.Obj.get();
1220 APInt &Mask = Prov.Wildcard->ActiveMask;
1223 if (Mask.isZero()) {
1226 auto Iter = ExposedProvenances.upper_bound(Addr);
1227 if (Iter == ExposedProvenances.begin())
1229 auto &[BaseAddress, Set] = *std::prev(Iter);
1230 auto &Obj = MemoryObjects.at(BaseAddress);
1231 if (!Obj->inBounds(Ptr.
address()))
1236 ProvenanceCount = std::distance(
1239 ExposedProvenance{nullptr, Prov.Wildcard->Generation}));
1240 if (HasSideEffect) {
1242 Prov.Wildcard->BaseAddress = BaseAddress;
1247 uint64_t BaseAddress = Prov.Wildcard->BaseAddress;
1248 auto Iter = ExposedProvenances.find(BaseAddress);
1250 if (Iter == ExposedProvenances.end())
1252 MO = MemoryObjects.at(BaseAddress).get();
1255 List = &Iter->second.List;
1256 ProvenanceCount = Mask.getBitWidth();
1261 if (Prov.Obj.get() != MO)
1267 assert((!HasSideEffect || !Mask.isZero()) &&
1268 "Mask must be initialized if HasSideEffect is true.");
1269 if (!Mask.isZero() && !Mask[
I])
1276 }
else if (HasSideEffect)
1280 return Valid ? MO :
nullptr;
1285 if (ExposedProvenanceSetGeneration == 0)
1297 if (It == ValidFuncTargets.end())
1300 return It->second.first;
1306 if (It == ValidBlockTargets.end())
1309 return It->second.first;
1321 return CurrentRoundingMode;
1325 return CurrentExceptionBehavior;
1329 CurrentRoundingMode = RM;
1333 CurrentExceptionBehavior = EB;
1343 return UndefBehavior;
1355 return static_cast<bool>(Rng() & 1);
1374 switch (AllocKind) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getActiveBits() const
Compute the number of active bits in the value.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
unsigned getNumWords() const
Get the number of words.
LLVM_ABI void insertBits(const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
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.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
bool isOne() const
Determine if this is a value of 1.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
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.
Registry of file location information for LLVM IR constructs.
LLVM Basic Block Representation.
This is an important base class in LLVM.
Represents flags for the getelementptr instruction/expression.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
A Module instance is used to store all the information related to an LLVM module.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
MutableArrayRef< T > slice(size_t N, size_t M) const
Chop off the first N elements of the array, and keep M elements in the array.
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
TypeSize getElementOffset(unsigned Idx) const
Class to represent struct types.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isByteTy() const
True if this is an instance of ByteType.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
static LLVM_ABI AnyValue getPoisonValue(Context &Ctx, Type *Ty)
static AnyValue poison()
Use getPoisonValue unless you know the scalar type is integer/fp/ptr!
const Pointer & asPointer() const
static LLVM_ABI AnyValue getVectorSplat(const AnyValue &Scalar, size_t NumElements)
const ByteValue & asByte() const
ByteValue & asMutableByte()
const APInt & asInteger() const
const APFloat & asFloat() const
static LLVM_ABI AnyValue getNullValue(Context &Ctx, Type *Ty)
const std::vector< AnyValue > & asAggregate() const
Represents a scalar byte value.
MutableArrayRef< Byte > mutableBytes()
The caller should call canonicalize after mutation.
@ FlushNonCanonicalToPoison
void canonicalize(CanonicalizeMode Mode)
Make sure the padding byte is canonical.
LLVM_ABI bool isDefaultFPEnv() const
uint32_t getEVL(ElementCount EC) const
Get the effective vector length for a vector type.
LLVM_ABI Pointer deriveFromMemoryObject(IntrusiveRefCntPtr< MemoryObject > Obj)
Derive a pointer from a memory object with offset 0.
LLVM_ABI UndefValueBehavior getEffectiveUndefValueBehavior() const
bool exceedsMaxObjectSize(uint64_t Size, unsigned AS) const
Returns true if an object of Size bytes in address space AS is larger than the largest signed integer...
LLVM_ABI void resetNoncacheableConstantBuffer()
LLVM_ABI void setCurrentRoundingMode(RoundingMode RM)
LLVM_ABI void setCurrentExceptionBehavior(fp::ExceptionBehavior EB)
LLVM_ABI bool initGlobalValues()
Initialize global variables and function/block objects.
LLVM_ABI IntrusiveRefCntPtr< MemoryObject > allocate(uint64_t Size, uint64_t Align, StringRef Name, unsigned AS, MemInitKind InitKind, MemAllocKind AllocKind, bool IsIRGlobalValue=false)
uint64_t getEffectiveTypeSize(TypeSize Size) const
The result is multiplied by VScale for scalable type sizes.
LLVM_ABI IntrusiveRefCntPtr< Provenance > getWildcardProvenance()
Returns the snapshot of currently exposed provenances.
LLVM_ABI Function * getTargetFunction(const Pointer &Ptr)
LLVM_ABI uint64_t getEffectiveTypeAllocSize(Type *Ty)
Returns DL.getTypeAllocSize/getTypeStoreSize for the given type.
LLVM_ABI uint64_t getEffectiveTypeStoreSize(Type *Ty)
LLVM_ABI AnyValue extractBits(const ByteValue &Src, uint32_t OffsetInBits, Type *Ty)
Read the bits [OffsetInBits, OffsetInBits + bitwidth(Ty)) of Src as a value of type Ty.
LLVM_ABI AnyValue computeGEP(GEPOperator &GEP, function_ref< const AnyValue &(Value *V)> GetValue)
const DataLayout & getDataLayout() const
const Triple & getTargetTriple() const
LLVM_ABI bool getRandomBool()
LLVM_ABI NaNPropagationBehavior getEffectiveNaNPropagationBehavior() const
LLVM_ABI void freeze(AnyValue &Val, Type *Ty)
Freeze the value in-place.
LLVM_ABI fp::ExceptionBehavior getCurrentExceptionBehavior() const
bool mayUseNonDeterminism() const
static LLVM_ABI AnyValue canonicalizeIndex(const AnyValue &Idx, unsigned IndexBitWidth, GEPNoWrapFlags Flags)
Sign extends or truncates the GEP index Idx to IndexBitWidth bits.
LLVMContext & getContext() const
LLVM_ABI Context(Module &M, const AsmParserContext *ParserContext)
LLVM_ABI const MaterializedConstant * getConstantValue(Constant *C)
Returns a pointer to an evaluated constant C.
LLVM_ABI bool free(const MemoryObject &Obj)
LLVM_ABI void insertBits(ByteValue &Base, uint32_t OffsetInBits, const AnyValue &Val, Type *Ty)
Overwrite the bits [OffsetInBits, OffsetInBits + bitwidth(Ty)) of Base with Val.
LLVM_ABI void store(MemoryObject &MO, uint64_t Offset, const AnyValue &Val, Type *ValTy)
Direct memory store without checks.
LLVM_ABI BasicBlock * getTargetBlock(const Pointer &Ptr)
LLVM_ABI void storeRawBytes(MemoryObject &MO, uint64_t Offset, const void *Data, uint64_t Size)
LLVM_ABI AnyValue computeScaledPtrAdd(const AnyValue &Ptr, const AnyValue &Index, const APInt &Scale, GEPNoWrapFlags Flags, AnyValue &AccumulatedOffset)
LLVM_ABI AnyValue load(MemoryObject &MO, uint64_t Offset, Type *ValTy, bool *ContainsUndefinedBits=nullptr)
Direct memory load without checks.
LLVM_ABI void exposeProvenance(Provenance &Prov)
Mark this provenance as exposed.
LLVM_ABI RoundingMode getCurrentRoundingMode() const
bool isDeterministic() const
LLVM_ABI MemoryObject * checkProvenance(const Pointer &Ptr, function_ref< bool(const Provenance &)> Check, bool HasSideEffect=true)
A helper to check both concrete and wildcard provenance.
LLVM_ABI uint64_t getRandomUInt64()
LLVM_ABI MemoryObject(uint64_t Addr, uint64_t Size, StringRef Name, unsigned AS, MemInitKind InitKind, MemAllocKind AllocKind, bool IsIRGlobalValue=false)
ArrayRef< Byte > getBytes() const
LLVM_ABI bool isHeapAllocated() const
LLVM_ABI bool isGlobal() const
bool inBounds(const APInt &NewAddr) const
LLVM_ABI bool isStackAllocated() const
const APInt & address() const
Pointer getWithNewAddr(const APInt &NewAddr) const
Provenance & provenance() const
Components of a pointer excluding address.
MemoryObject * getMemoryObject() const
static LLVM_ABI IntrusiveRefCntPtr< Provenance > nullary()
LLVM_ABI IntrusiveRefCntPtr< Provenance > getWithKnownMemoryObject(MemoryObject &Obj)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CE
Windows NT (Windows on ARM)
ExceptionBehavior
Exception behavior used for floating point operations.
AnyValue addNoWrap(const APInt &LHS, const APInt &RHS, bool HasNSW, bool HasNUW)
AnyValue subNoWrap(const APInt &LHS, const APInt &RHS, bool HasNSW, bool HasNUW)
BytesView< ArrayRef< Byte > > ConstBytesView
AnyValue mulNoWrap(const APInt &LHS, const APInt &RHS, bool HasNSW, bool HasNUW)
BytesView< MutableArrayRef< Byte > > MutableBytesView
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isDefaultFPEnvironment(fp::ExceptionBehavior EB, RoundingMode RM)
Returns true if the exception handling behavior and rounding mode match what is used in the default f...
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
IntrusiveRefCntPtr< T > makeIntrusiveRefCnt(Args &&...A)
Factory function for creating intrusive ref counted pointers.
gep_type_iterator gep_type_end(const User *GEP)
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
auto reverse(ContainerTy &&C)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
generic_gep_type_iterator<> gep_type_iterator
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
constexpr int PoisonMaskElem
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
RoundingMode
Rounding mode.
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
gep_type_iterator gep_type_begin(const User *GEP)
@ End
Run the machine verifier once, at the end of the pipeline.
std::enable_if_t< std::is_unsigned_v< T >, T > SaturatingAdd(T X, T Y, bool *ResultOverflowed=nullptr)
Add two unsigned integers, X and Y, of type T.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Representation of a byte in memory.
void poisonBits(uint8_t Mask)
static Byte concrete(uint8_t Val)
static Byte fshr(const Byte &Low, const Byte &High, uint32_t ShAmt)
Returns a logical byte that is part of two adjacent bytes.
void zeroBits(uint8_t Mask)
bool isCanonicalPaddingByte(uint8_t PaddingMask) const
Padding bits may carry pointer provenance.