26 "Cannot call User::replaceUsesOfWith on a constant!");
28 for (
unsigned i = 0,
E = getNumOperands(); i !=
E; ++i)
29 if (getOperand(i) == From) {
45 assert(HasHungOffUses &&
"alloc must have hung off uses");
47 static_assert(
alignof(
Use) >=
alignof(Value *),
48 "Alignment is insufficient for 'hung-off-uses' pieces");
53 size +=
N *
sizeof(Value *);
54 Use *Begin =
static_cast<Use*
>(::operator
new(
size));
56 setOperandList(Begin);
57 for (; Begin !=
End; Begin++)
58 new (Begin)
Use(
this);
62 assert(HasHungOffUses &&
"realloc must have hung off uses");
64 unsigned OldNumUses = getNumOperands();
68 assert(NewNumUses > OldNumUses &&
"realloc must grow num uses");
70 Use *OldOps = getOperandList();
71 allocHungoffUses(NewNumUses, WithExtraValues);
72 Use *NewOps = getOperandList();
75 std::copy(OldOps, OldOps + OldNumUses, NewOps);
79 if (WithExtraValues) {
80 auto *OldPtr =
reinterpret_cast<char *
>(OldOps + OldNumUses);
81 auto *NewPtr =
reinterpret_cast<char *
>(NewOps + NewNumUses);
82 std::copy(OldPtr, OldPtr + (OldNumUses *
sizeof(Value *)), NewPtr);
84 Use::zap(OldOps, OldOps + OldNumUses,
true);
95 return {MutableARef.begin(), MutableARef.end()};
99 assert(HasDescriptor &&
"Don't call otherwise!");
100 assert(!HasHungOffUses &&
"Invariant!");
102 auto *DI =
reinterpret_cast<DescriptorInfo *
>(getIntrusiveOperands()) - 1;
103 assert(DI->SizeInBytes != 0 &&
"Should not have had a descriptor otherwise!");
106 reinterpret_cast<uint8_t *
>(DI) - DI->SizeInBytes, DI->SizeInBytes);
111 switch (
II->getIntrinsicID()) {
114 case Intrinsic::assume:
115 case Intrinsic::pseudoprobe:
116 case Intrinsic::experimental_noalias_scope_decl:
127void *User::allocateFixedOperandUser(
size_t Size,
unsigned Us,
128 unsigned DescBytes) {
129 assert(Us < (1u << NumUserOperandsBits) &&
"Too many operands");
131 static_assert(
sizeof(
DescriptorInfo) %
sizeof(
void *) == 0,
"Required below");
133 unsigned DescBytesToAllocate =
135 assert(DescBytesToAllocate %
sizeof(
void *) == 0 &&
136 "We need this to satisfy alignment constraints for Uses");
138 size_t LeadingSize = DescBytesToAllocate +
sizeof(
Use) * Us;
143 LeadingSize = std::max(LeadingSize,
sizeof(
void *));
146 User *
Obj =
reinterpret_cast<User *
>(Storage + LeadingSize);
148 Obj->NumUserOperands = Us;
149 Obj->HasHungOffUses =
false;
150 Obj->HasDescriptor = DescBytes != 0;
152 if (DescBytes != 0) {
160void *User::operator
new(
size_t Size, IntrusiveOperandsAllocMarker allocTrait) {
161 return allocateFixedOperandUser(
Size, allocTrait.NumOps, 0);
164void *User::operator
new(
size_t Size,
165 IntrusiveOperandsAndDescriptorAllocMarker allocTrait) {
166 return allocateFixedOperandUser(
Size, allocTrait.NumOps,
167 allocTrait.DescBytes);
170void *User::operator
new(
size_t Size, HungOffOperandsAllocMarker) {
172 void *Storage = ::operator
new(
Size +
sizeof(
Use *));
173 Use **HungOffOperandList =
static_cast<Use **
>(Storage);
174 User *
Obj =
reinterpret_cast<User *
>(HungOffOperandList + 1);
175 Obj->NumUserOperands = 0;
176 Obj->HasHungOffUses =
true;
177 Obj->HasDescriptor =
false;
178 *HungOffOperandList =
nullptr;
189 void *AllocStart =
nullptr;
190 if (HasHungOffUses) {
191 assert(!HasDescriptor &&
"not supported!");
193 Use **HungOffOperandList =
reinterpret_cast<Use **
>(
this) - 1;
195 Use::zap(*HungOffOperandList, *HungOffOperandList + NumUserOperands,
197 AllocStart = HungOffOperandList;
198 }
else if (HasDescriptor) {
199 Use *UseBegin =
reinterpret_cast<Use *
>(
this) - NumUserOperands;
200 Use::zap(UseBegin, UseBegin + NumUserOperands,
false);
203 AllocStart =
reinterpret_cast<uint8_t *
>(DI) - DI->SizeInBytes;
204 }
else if (NumUserOperands > 0) {
205 Use *Storage =
reinterpret_cast<Use *
>(
this) - NumUserOperands;
206 Use::zap(Storage, Storage + NumUserOperands,
208 AllocStart = Storage;
211 AllocStart = (
void **)(
this) - 1;
221 ((
void **)
this)[-1] = AllocStart;
224void User::operator
delete(
void *Usr) { ::operator
delete(((
void **)Usr)[-1]); }
226void User::operator
delete(
void *Usr, HungOffOperandsAllocMarker) {
227 Use **HungOffOperandList =
static_cast<Use **
>(Usr) - 1;
228 ::operator
delete(HungOffOperandList);
231void User::operator
delete(
void *Usr,
232 IntrusiveOperandsAndDescriptorAllocMarker Marker) {
233 unsigned NumOps = Marker.NumOps;
236 uint8_t *Storage =
reinterpret_cast<uint8_t *
>(DI) - DI->SizeInBytes;
237 ::operator
delete(Storage);
240void User::operator
delete(
void *Usr, IntrusiveOperandsAllocMarker Marker) {
241 unsigned NumOps = Marker.NumOps;
242 size_t LeadingSize =
sizeof(
Use) *
NumOps;
244 LeadingSize = std::max(LeadingSize,
sizeof(
void *));
246 ::operator
delete(Storage);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
uint64_t IntrinsicInst * II
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
A Use represents the edge between a Value definition and its users.
static LLVM_ABI void zap(Use *Start, const Use *Stop, bool del=false)
Destroys Use operands when the number of operands of a User changes.
LLVM_ABI void allocHungoffUses(unsigned N, bool WithExtraValues=false)
Allocate the array of Uses, followed by a pointer (with bottom bit set) to the User.
LLVM_ABI ArrayRef< const uint8_t > getDescriptor() const
Returns the descriptor co-allocated with this User instance.
LLVM_ABI bool isDroppable() const
A droppable user is a user for which uses can be dropped without affecting correctness and should be ...
LLVM_ABI bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
LLVM_ABI void growHungoffUses(unsigned N, bool WithExtraValues=false)
Grow the number of hung off uses.
LLVM_ABI const descriptor::Clause & getDescriptor(Clause C)
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
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...
@ End
Run the machine verifier once, at the end of the pipeline.