LLVM  10.0.0
Value.cpp
Go to the documentation of this file.
1 //===-- Value.cpp - Implement the Value class -----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Value, ValueHandle, and User classes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/IR/Value.h"
14 #include "LLVMContextImpl.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/SetVector.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/IR/Constant.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/DerivedTypes.h"
22 #include "llvm/IR/DerivedUser.h"
24 #include "llvm/IR/InstrTypes.h"
25 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/IntrinsicInst.h"
27 #include "llvm/IR/Module.h"
28 #include "llvm/IR/Operator.h"
29 #include "llvm/IR/Statepoint.h"
30 #include "llvm/IR/ValueHandle.h"
33 #include "llvm/Support/Debug.h"
37 #include <algorithm>
38 
39 using namespace llvm;
40 
42  "non-global-value-max-name-size", cl::Hidden, cl::init(1024),
43  cl::desc("Maximum size for the name of non-global values."));
44 
45 //===----------------------------------------------------------------------===//
46 // Value Class
47 //===----------------------------------------------------------------------===//
48 static inline Type *checkType(Type *Ty) {
49  assert(Ty && "Value defined with a null type: Error!");
50  return Ty;
51 }
52 
53 Value::Value(Type *ty, unsigned scid)
54  : VTy(checkType(ty)), UseList(nullptr), SubclassID(scid),
55  HasValueHandle(0), SubclassOptionalData(0), SubclassData(0),
56  NumUserOperands(0), IsUsedByMD(false), HasName(false) {
57  static_assert(ConstantFirstVal == 0, "!(SubclassID < ConstantFirstVal)");
58  // FIXME: Why isn't this in the subclass gunk??
59  // Note, we cannot call isa<CallInst> before the CallInst has been
60  // constructed.
61  if (SubclassID == Instruction::Call || SubclassID == Instruction::Invoke ||
62  SubclassID == Instruction::CallBr)
63  assert((VTy->isFirstClassType() || VTy->isVoidTy() || VTy->isStructTy()) &&
64  "invalid CallInst type!");
65  else if (SubclassID != BasicBlockVal &&
66  (/*SubclassID < ConstantFirstVal ||*/ SubclassID > ConstantLastVal))
67  assert((VTy->isFirstClassType() || VTy->isVoidTy()) &&
68  "Cannot create non-first-class values except for constants!");
69  static_assert(sizeof(Value) == 2 * sizeof(void *) + 2 * sizeof(unsigned),
70  "Value too big");
71 }
72 
74  // Notify all ValueHandles (if present) that this value is going away.
75  if (HasValueHandle)
77  if (isUsedByMetadata())
79 
80 #ifndef NDEBUG // Only in -g mode...
81  // Check to make sure that there are no uses of this value that are still
82  // around when the value is destroyed. If there are, then we have a dangling
83  // reference and something is wrong. This code is here to print out where
84  // the value is still being referenced.
85  //
86  if (!use_empty()) {
87  dbgs() << "While deleting: " << *VTy << " %" << getName() << "\n";
88  for (auto *U : users())
89  dbgs() << "Use still stuck around after Def is destroyed:" << *U << "\n";
90  }
91 #endif
92  assert(use_empty() && "Uses remain when a value is destroyed!");
93 
94  // If this value is named, destroy the name. This should not be in a symtab
95  // at this point.
96  destroyValueName();
97 }
98 
100  switch (getValueID()) {
101 #define HANDLE_VALUE(Name) \
102  case Value::Name##Val: \
103  delete static_cast<Name *>(this); \
104  break;
105 #define HANDLE_MEMORY_VALUE(Name) \
106  case Value::Name##Val: \
107  static_cast<DerivedUser *>(this)->DeleteValue( \
108  static_cast<DerivedUser *>(this)); \
109  break;
110 #define HANDLE_INSTRUCTION(Name) /* nothing */
111 #include "llvm/IR/Value.def"
112 
113 #define HANDLE_INST(N, OPC, CLASS) \
114  case Value::InstructionVal + Instruction::OPC: \
115  delete static_cast<CLASS *>(this); \
116  break;
117 #define HANDLE_USER_INST(N, OPC, CLASS)
118 #include "llvm/IR/Instruction.def"
119 
120  default:
121  llvm_unreachable("attempting to delete unknown value kind");
122  }
123 }
124 
125 void Value::destroyValueName() {
127  if (Name)
128  Name->Destroy();
129  setValueName(nullptr);
130 }
131 
132 bool Value::hasNUses(unsigned N) const {
133  return hasNItems(use_begin(), use_end(), N);
134 }
135 
136 bool Value::hasNUsesOrMore(unsigned N) const {
137  return hasNItemsOrMore(use_begin(), use_end(), N);
138 }
139 
140 bool Value::isUsedInBasicBlock(const BasicBlock *BB) const {
141  // This can be computed either by scanning the instructions in BB, or by
142  // scanning the use list of this Value. Both lists can be very long, but
143  // usually one is quite short.
144  //
145  // Scan both lists simultaneously until one is exhausted. This limits the
146  // search to the shorter list.
147  BasicBlock::const_iterator BI = BB->begin(), BE = BB->end();
148  const_user_iterator UI = user_begin(), UE = user_end();
149  for (; BI != BE && UI != UE; ++BI, ++UI) {
150  // Scan basic block: Check if this Value is used by the instruction at BI.
151  if (is_contained(BI->operands(), this))
152  return true;
153  // Scan use list: Check if the use at UI is in BB.
154  const auto *User = dyn_cast<Instruction>(*UI);
155  if (User && User->getParent() == BB)
156  return true;
157  }
158  return false;
159 }
160 
161 unsigned Value::getNumUses() const {
162  return (unsigned)std::distance(use_begin(), use_end());
163 }
164 
165 static bool getSymTab(Value *V, ValueSymbolTable *&ST) {
166  ST = nullptr;
167  if (Instruction *I = dyn_cast<Instruction>(V)) {
168  if (BasicBlock *P = I->getParent())
169  if (Function *PP = P->getParent())
170  ST = PP->getValueSymbolTable();
171  } else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
172  if (Function *P = BB->getParent())
173  ST = P->getValueSymbolTable();
174  } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
175  if (Module *P = GV->getParent())
176  ST = &P->getValueSymbolTable();
177  } else if (Argument *A = dyn_cast<Argument>(V)) {
178  if (Function *P = A->getParent())
179  ST = P->getValueSymbolTable();
180  } else {
181  assert(isa<Constant>(V) && "Unknown value type!");
182  return true; // no name is setable for this.
183  }
184  return false;
185 }
186 
188  if (!HasName) return nullptr;
189 
190  LLVMContext &Ctx = getContext();
191  auto I = Ctx.pImpl->ValueNames.find(this);
192  assert(I != Ctx.pImpl->ValueNames.end() &&
193  "No name entry found!");
194 
195  return I->second;
196 }
197 
199  LLVMContext &Ctx = getContext();
200 
201  assert(HasName == Ctx.pImpl->ValueNames.count(this) &&
202  "HasName bit out of sync!");
203 
204  if (!VN) {
205  if (HasName)
206  Ctx.pImpl->ValueNames.erase(this);
207  HasName = false;
208  return;
209  }
210 
211  HasName = true;
212  Ctx.pImpl->ValueNames[this] = VN;
213 }
214 
216  // Make sure the empty string is still a C string. For historical reasons,
217  // some clients want to call .data() on the result and expect it to be null
218  // terminated.
219  if (!hasName())
220  return StringRef("", 0);
221  return getValueName()->getKey();
222 }
223 
224 void Value::setNameImpl(const Twine &NewName) {
225  // Fast-path: LLVMContext can be set to strip out non-GlobalValue names
226  if (getContext().shouldDiscardValueNames() && !isa<GlobalValue>(this))
227  return;
228 
229  // Fast path for common IRBuilder case of setName("") when there is no name.
230  if (NewName.isTriviallyEmpty() && !hasName())
231  return;
232 
233  SmallString<256> NameData;
234  StringRef NameRef = NewName.toStringRef(NameData);
235  assert(NameRef.find_first_of(0) == StringRef::npos &&
236  "Null bytes are not allowed in names");
237 
238  // Name isn't changing?
239  if (getName() == NameRef)
240  return;
241 
242  // Cap the size of non-GlobalValue names.
243  if (NameRef.size() > NonGlobalValueMaxNameSize && !isa<GlobalValue>(this))
244  NameRef =
245  NameRef.substr(0, std::max(1u, (unsigned)NonGlobalValueMaxNameSize));
246 
247  assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
248 
249  // Get the symbol table to update for this object.
251  if (getSymTab(this, ST))
252  return; // Cannot set a name on this value (e.g. constant).
253 
254  if (!ST) { // No symbol table to update? Just do the change.
255  if (NameRef.empty()) {
256  // Free the name for this value.
257  destroyValueName();
258  return;
259  }
260 
261  // NOTE: Could optimize for the case the name is shrinking to not deallocate
262  // then reallocated.
263  destroyValueName();
264 
265  // Create the new name.
267  getValueName()->setValue(this);
268  return;
269  }
270 
271  // NOTE: Could optimize for the case the name is shrinking to not deallocate
272  // then reallocated.
273  if (hasName()) {
274  // Remove old name.
275  ST->removeValueName(getValueName());
276  destroyValueName();
277 
278  if (NameRef.empty())
279  return;
280  }
281 
282  // Name is changing to something new.
283  setValueName(ST->createValueName(NameRef, this));
284 }
285 
286 void Value::setName(const Twine &NewName) {
287  setNameImpl(NewName);
288  if (Function *F = dyn_cast<Function>(this))
289  F->recalculateIntrinsicID();
290 }
291 
293  ValueSymbolTable *ST = nullptr;
294  // If this value has a name, drop it.
295  if (hasName()) {
296  // Get the symtab this is in.
297  if (getSymTab(this, ST)) {
298  // We can't set a name on this value, but we need to clear V's name if
299  // it has one.
300  if (V->hasName()) V->setName("");
301  return; // Cannot set a name on this value (e.g. constant).
302  }
303 
304  // Remove old name.
305  if (ST)
306  ST->removeValueName(getValueName());
307  destroyValueName();
308  }
309 
310  // Now we know that this has no name.
311 
312  // If V has no name either, we're done.
313  if (!V->hasName()) return;
314 
315  // Get this's symtab if we didn't before.
316  if (!ST) {
317  if (getSymTab(this, ST)) {
318  // Clear V's name.
319  V->setName("");
320  return; // Cannot set a name on this value (e.g. constant).
321  }
322  }
323 
324  // Get V's ST, this should always succed, because V has a name.
325  ValueSymbolTable *VST;
326  bool Failure = getSymTab(V, VST);
327  assert(!Failure && "V has a name, so it should have a ST!"); (void)Failure;
328 
329  // If these values are both in the same symtab, we can do this very fast.
330  // This works even if both values have no symtab yet.
331  if (ST == VST) {
332  // Take the name!
334  V->setValueName(nullptr);
335  getValueName()->setValue(this);
336  return;
337  }
338 
339  // Otherwise, things are slightly more complex. Remove V's name from VST and
340  // then reinsert it into ST.
341 
342  if (VST)
343  VST->removeValueName(V->getValueName());
345  V->setValueName(nullptr);
346  getValueName()->setValue(this);
347 
348  if (ST)
349  ST->reinsertValue(this);
350 }
351 
353 #ifndef NDEBUG
354  const GlobalValue *GV = dyn_cast<GlobalValue>(this);
355  if (!GV)
356  return;
357  const Module *M = GV->getParent();
358  if (!M)
359  return;
360  assert(M->isMaterialized());
361 #endif
362 }
363 
364 #ifndef NDEBUG
366  Constant *C) {
367  if (!Cache.insert(Expr).second)
368  return false;
369 
370  for (auto &O : Expr->operands()) {
371  if (O == C)
372  return true;
373  auto *CE = dyn_cast<ConstantExpr>(O);
374  if (!CE)
375  continue;
376  if (contains(Cache, CE, C))
377  return true;
378  }
379  return false;
380 }
381 
382 static bool contains(Value *Expr, Value *V) {
383  if (Expr == V)
384  return true;
385 
386  auto *C = dyn_cast<Constant>(V);
387  if (!C)
388  return false;
389 
390  auto *CE = dyn_cast<ConstantExpr>(Expr);
391  if (!CE)
392  return false;
393 
395  return contains(Cache, CE, C);
396 }
397 #endif // NDEBUG
398 
399 void Value::doRAUW(Value *New, ReplaceMetadataUses ReplaceMetaUses) {
400  assert(New && "Value::replaceAllUsesWith(<null>) is invalid!");
401  assert(!contains(New, this) &&
402  "this->replaceAllUsesWith(expr(this)) is NOT valid!");
403  assert(New->getType() == getType() &&
404  "replaceAllUses of value with new value of different type!");
405 
406  // Notify all ValueHandles (if present) that this value is going away.
407  if (HasValueHandle)
409  if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
410  ValueAsMetadata::handleRAUW(this, New);
411 
412  while (!materialized_use_empty()) {
413  Use &U = *UseList;
414  // Must handle Constants specially, we cannot call replaceUsesOfWith on a
415  // constant because they are uniqued.
416  if (auto *C = dyn_cast<Constant>(U.getUser())) {
417  if (!isa<GlobalValue>(C)) {
418  C->handleOperandChange(this, New);
419  continue;
420  }
421  }
422 
423  U.set(New);
424  }
425 
426  if (BasicBlock *BB = dyn_cast<BasicBlock>(this))
427  BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
428 }
429 
431  doRAUW(New, ReplaceMetadataUses::Yes);
432 }
433 
435  doRAUW(New, ReplaceMetadataUses::No);
436 }
437 
438 // Like replaceAllUsesWith except it does not handle constants or basic blocks.
439 // This routine leaves uses within BB.
441  assert(New && "Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
442  assert(!contains(New, this) &&
443  "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
444  assert(New->getType() == getType() &&
445  "replaceUses of value with new value of different type!");
446  assert(BB && "Basic block that may contain a use of 'New' must be defined\n");
447 
448  replaceUsesWithIf(New, [BB](Use &U) {
449  auto *I = dyn_cast<Instruction>(U.getUser());
450  // Don't replace if it's an instruction in the BB basic block.
451  return !I || I->getParent() != BB;
452  });
453 }
454 
455 namespace {
456 // Various metrics for how much to strip off of pointers.
458  PSK_ZeroIndices,
459  PSK_ZeroIndicesAndAliases,
460  PSK_ZeroIndicesSameRepresentation,
461  PSK_ZeroIndicesAndInvariantGroups,
462  PSK_InBoundsConstantIndices,
463  PSK_InBounds
464 };
465 
466 template <PointerStripKind StripKind>
467 static const Value *stripPointerCastsAndOffsets(const Value *V) {
468  if (!V->getType()->isPointerTy())
469  return V;
470 
471  // Even though we don't look through PHI nodes, we could be called on an
472  // instruction in an unreachable block, which may be on a cycle.
474 
475  Visited.insert(V);
476  do {
477  if (auto *GEP = dyn_cast<GEPOperator>(V)) {
478  switch (StripKind) {
479  case PSK_ZeroIndices:
480  case PSK_ZeroIndicesAndAliases:
481  case PSK_ZeroIndicesSameRepresentation:
482  case PSK_ZeroIndicesAndInvariantGroups:
483  if (!GEP->hasAllZeroIndices())
484  return V;
485  break;
486  case PSK_InBoundsConstantIndices:
487  if (!GEP->hasAllConstantIndices())
488  return V;
490  case PSK_InBounds:
491  if (!GEP->isInBounds())
492  return V;
493  break;
494  }
495  V = GEP->getPointerOperand();
496  } else if (Operator::getOpcode(V) == Instruction::BitCast) {
497  V = cast<Operator>(V)->getOperand(0);
498  } else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
499  Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
500  // TODO: If we know an address space cast will not change the
501  // representation we could look through it here as well.
502  V = cast<Operator>(V)->getOperand(0);
503  } else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
504  V = cast<GlobalAlias>(V)->getAliasee();
505  } else {
506  if (const auto *Call = dyn_cast<CallBase>(V)) {
507  if (const Value *RV = Call->getReturnedArgOperand()) {
508  V = RV;
509  continue;
510  }
511  // The result of launder.invariant.group must alias it's argument,
512  // but it can't be marked with returned attribute, that's why it needs
513  // special case.
514  if (StripKind == PSK_ZeroIndicesAndInvariantGroups &&
515  (Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
516  Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
517  V = Call->getArgOperand(0);
518  continue;
519  }
520  }
521  return V;
522  }
523  assert(V->getType()->isPointerTy() && "Unexpected operand type!");
524  } while (Visited.insert(V).second);
525 
526  return V;
527 }
528 } // end anonymous namespace
529 
531  return stripPointerCastsAndOffsets<PSK_ZeroIndices>(this);
532 }
533 
535  return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(this);
536 }
537 
539  return stripPointerCastsAndOffsets<PSK_ZeroIndicesSameRepresentation>(this);
540 }
541 
543  return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(this);
544 }
545 
547  return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndInvariantGroups>(this);
548 }
549 
550 const Value *
552  bool AllowNonInbounds) const {
553  if (!getType()->isPtrOrPtrVectorTy())
554  return this;
555 
556  unsigned BitWidth = Offset.getBitWidth();
557  assert(BitWidth == DL.getIndexTypeSizeInBits(getType()) &&
558  "The offset bit width does not match the DL specification.");
559 
560  // Even though we don't look through PHI nodes, we could be called on an
561  // instruction in an unreachable block, which may be on a cycle.
563  Visited.insert(this);
564  const Value *V = this;
565  do {
566  if (auto *GEP = dyn_cast<GEPOperator>(V)) {
567  // If in-bounds was requested, we do not strip non-in-bounds GEPs.
568  if (!AllowNonInbounds && !GEP->isInBounds())
569  return V;
570 
571  // If one of the values we have visited is an addrspacecast, then
572  // the pointer type of this GEP may be different from the type
573  // of the Ptr parameter which was passed to this function. This
574  // means when we construct GEPOffset, we need to use the size
575  // of GEP's pointer type rather than the size of the original
576  // pointer type.
577  APInt GEPOffset(DL.getIndexTypeSizeInBits(V->getType()), 0);
578  if (!GEP->accumulateConstantOffset(DL, GEPOffset))
579  return V;
580 
581  // Stop traversal if the pointer offset wouldn't fit in the bit-width
582  // provided by the Offset argument. This can happen due to AddrSpaceCast
583  // stripping.
584  if (GEPOffset.getMinSignedBits() > BitWidth)
585  return V;
586 
587  Offset += GEPOffset.sextOrTrunc(BitWidth);
588  V = GEP->getPointerOperand();
589  } else if (Operator::getOpcode(V) == Instruction::BitCast ||
590  Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
591  V = cast<Operator>(V)->getOperand(0);
592  } else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
593  if (!GA->isInterposable())
594  V = GA->getAliasee();
595  } else if (const auto *Call = dyn_cast<CallBase>(V)) {
596  if (const Value *RV = Call->getReturnedArgOperand())
597  V = RV;
598  }
599  assert(V->getType()->isPtrOrPtrVectorTy() && "Unexpected operand type!");
600  } while (Visited.insert(V).second);
601 
602  return V;
603 }
604 
606  return stripPointerCastsAndOffsets<PSK_InBounds>(this);
607 }
608 
610  bool &CanBeNull) const {
611  assert(getType()->isPointerTy() && "must be pointer");
612 
613  uint64_t DerefBytes = 0;
614  CanBeNull = false;
615  if (const Argument *A = dyn_cast<Argument>(this)) {
616  DerefBytes = A->getDereferenceableBytes();
617  if (DerefBytes == 0 && (A->hasByValAttr() || A->hasStructRetAttr())) {
618  Type *PT = cast<PointerType>(A->getType())->getElementType();
619  if (PT->isSized())
620  DerefBytes = DL.getTypeStoreSize(PT);
621  }
622  if (DerefBytes == 0) {
623  DerefBytes = A->getDereferenceableOrNullBytes();
624  CanBeNull = true;
625  }
626  } else if (const auto *Call = dyn_cast<CallBase>(this)) {
627  DerefBytes = Call->getDereferenceableBytes(AttributeList::ReturnIndex);
628  if (DerefBytes == 0) {
629  DerefBytes =
630  Call->getDereferenceableOrNullBytes(AttributeList::ReturnIndex);
631  CanBeNull = true;
632  }
633  } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
634  if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
635  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
636  DerefBytes = CI->getLimitedValue();
637  }
638  if (DerefBytes == 0) {
639  if (MDNode *MD =
640  LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
641  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
642  DerefBytes = CI->getLimitedValue();
643  }
644  CanBeNull = true;
645  }
646  } else if (auto *IP = dyn_cast<IntToPtrInst>(this)) {
647  if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
648  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
649  DerefBytes = CI->getLimitedValue();
650  }
651  if (DerefBytes == 0) {
652  if (MDNode *MD =
653  IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
654  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
655  DerefBytes = CI->getLimitedValue();
656  }
657  CanBeNull = true;
658  }
659  } else if (auto *AI = dyn_cast<AllocaInst>(this)) {
660  if (!AI->isArrayAllocation()) {
661  DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType());
662  CanBeNull = false;
663  }
664  } else if (auto *GV = dyn_cast<GlobalVariable>(this)) {
665  if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
666  // TODO: Don't outright reject hasExternalWeakLinkage but set the
667  // CanBeNull flag.
668  DerefBytes = DL.getTypeStoreSize(GV->getValueType());
669  CanBeNull = false;
670  }
671  }
672  return DerefBytes;
673 }
674 
676  assert(getType()->isPointerTy() && "must be pointer");
677  if (auto *GO = dyn_cast<GlobalObject>(this)) {
678  if (isa<Function>(GO)) {
679  const MaybeAlign FunctionPtrAlign = DL.getFunctionPtrAlign();
680  switch (DL.getFunctionPtrAlignType()) {
682  return FunctionPtrAlign;
684  return std::max(FunctionPtrAlign, MaybeAlign(GO->getAlignment()));
685  }
686  llvm_unreachable("Unhandled FunctionPtrAlignType");
687  }
688  const MaybeAlign Alignment(GO->getAlignment());
689  if (!Alignment) {
690  if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
691  Type *ObjectType = GVar->getValueType();
692  if (ObjectType->isSized()) {
693  // If the object is defined in the current Module, we'll be giving
694  // it the preferred alignment. Otherwise, we have to assume that it
695  // may only have the minimum ABI alignment.
696  if (GVar->isStrongDefinitionForLinker())
697  return MaybeAlign(DL.getPreferredAlignment(GVar));
698  else
699  return Align(DL.getABITypeAlignment(ObjectType));
700  }
701  }
702  }
703  return Alignment;
704  } else if (const Argument *A = dyn_cast<Argument>(this)) {
705  const MaybeAlign Alignment(A->getParamAlignment());
706  if (!Alignment && A->hasStructRetAttr()) {
707  // An sret parameter has at least the ABI alignment of the return type.
708  Type *EltTy = cast<PointerType>(A->getType())->getElementType();
709  if (EltTy->isSized())
710  return Align(DL.getABITypeAlignment(EltTy));
711  }
712  return Alignment;
713  } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
714  const MaybeAlign Alignment(AI->getAlignment());
715  if (!Alignment) {
716  Type *AllocatedType = AI->getAllocatedType();
717  if (AllocatedType->isSized())
718  return MaybeAlign(DL.getPrefTypeAlignment(AllocatedType));
719  }
720  return Alignment;
721  } else if (const auto *Call = dyn_cast<CallBase>(this)) {
722  const MaybeAlign Alignment(Call->getRetAlignment());
723  if (!Alignment && Call->getCalledFunction())
724  return MaybeAlign(
725  Call->getCalledFunction()->getAttributes().getRetAlignment());
726  return Alignment;
727  } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
728  if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
729  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
730  return MaybeAlign(CI->getLimitedValue());
731  }
732  }
733  return llvm::None;
734 }
735 
737  const BasicBlock *PredBB) const {
738  auto *PN = dyn_cast<PHINode>(this);
739  if (PN && PN->getParent() == CurBB)
740  return PN->getIncomingValueForBlock(PredBB);
741  return this;
742 }
743 
744 LLVMContext &Value::getContext() const { return VTy->getContext(); }
745 
747  if (!UseList || !UseList->Next)
748  // No need to reverse 0 or 1 uses.
749  return;
750 
751  Use *Head = UseList;
752  Use *Current = UseList->Next;
753  Head->Next = nullptr;
754  while (Current) {
755  Use *Next = Current->Next;
756  Current->Next = Head;
757  Head->setPrev(&Current->Next);
758  Head = Current;
759  Current = Next;
760  }
761  UseList = Head;
762  Head->setPrev(&UseList);
763 }
764 
765 bool Value::isSwiftError() const {
766  auto *Arg = dyn_cast<Argument>(this);
767  if (Arg)
768  return Arg->hasSwiftErrorAttr();
769  auto *Alloca = dyn_cast<AllocaInst>(this);
770  if (!Alloca)
771  return false;
772  return Alloca->isSwiftError();
773 }
774 
775 //===----------------------------------------------------------------------===//
776 // ValueHandleBase Class
777 //===----------------------------------------------------------------------===//
778 
779 void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
780  assert(List && "Handle list is null?");
781 
782  // Splice ourselves into the list.
783  Next = *List;
784  *List = this;
785  setPrevPtr(List);
786  if (Next) {
787  Next->setPrevPtr(&Next);
788  assert(getValPtr() == Next->getValPtr() && "Added to wrong list?");
789  }
790 }
791 
792 void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
793  assert(List && "Must insert after existing node");
794 
795  Next = List->Next;
796  setPrevPtr(&List->Next);
797  List->Next = this;
798  if (Next)
799  Next->setPrevPtr(&Next);
800 }
801 
802 void ValueHandleBase::AddToUseList() {
803  assert(getValPtr() && "Null pointer doesn't have a use list!");
804 
805  LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
806 
807  if (getValPtr()->HasValueHandle) {
808  // If this value already has a ValueHandle, then it must be in the
809  // ValueHandles map already.
810  ValueHandleBase *&Entry = pImpl->ValueHandles[getValPtr()];
811  assert(Entry && "Value doesn't have any handles?");
812  AddToExistingUseList(&Entry);
813  return;
814  }
815 
816  // Ok, it doesn't have any handles yet, so we must insert it into the
817  // DenseMap. However, doing this insertion could cause the DenseMap to
818  // reallocate itself, which would invalidate all of the PrevP pointers that
819  // point into the old table. Handle this by checking for reallocation and
820  // updating the stale pointers only if needed.
822  const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
823 
824  ValueHandleBase *&Entry = Handles[getValPtr()];
825  assert(!Entry && "Value really did already have handles?");
826  AddToExistingUseList(&Entry);
827  getValPtr()->HasValueHandle = true;
828 
829  // If reallocation didn't happen or if this was the first insertion, don't
830  // walk the table.
831  if (Handles.isPointerIntoBucketsArray(OldBucketPtr) ||
832  Handles.size() == 1) {
833  return;
834  }
835 
836  // Okay, reallocation did happen. Fix the Prev Pointers.
838  E = Handles.end(); I != E; ++I) {
839  assert(I->second && I->first == I->second->getValPtr() &&
840  "List invariant broken!");
841  I->second->setPrevPtr(&I->second);
842  }
843 }
844 
846  assert(getValPtr() && getValPtr()->HasValueHandle &&
847  "Pointer doesn't have a use list!");
848 
849  // Unlink this from its use list.
850  ValueHandleBase **PrevPtr = getPrevPtr();
851  assert(*PrevPtr == this && "List invariant broken");
852 
853  *PrevPtr = Next;
854  if (Next) {
855  assert(Next->getPrevPtr() == &Next && "List invariant broken");
856  Next->setPrevPtr(PrevPtr);
857  return;
858  }
859 
860  // If the Next pointer was null, then it is possible that this was the last
861  // ValueHandle watching VP. If so, delete its entry from the ValueHandles
862  // map.
863  LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
865  if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
866  Handles.erase(getValPtr());
867  getValPtr()->HasValueHandle = false;
868  }
869 }
870 
872  assert(V->HasValueHandle && "Should only be called if ValueHandles present");
873 
874  // Get the linked list base, which is guaranteed to exist since the
875  // HasValueHandle flag is set.
876  LLVMContextImpl *pImpl = V->getContext().pImpl;
877  ValueHandleBase *Entry = pImpl->ValueHandles[V];
878  assert(Entry && "Value bit set but no entries exist");
879 
880  // We use a local ValueHandleBase as an iterator so that ValueHandles can add
881  // and remove themselves from the list without breaking our iteration. This
882  // is not really an AssertingVH; we just have to give ValueHandleBase a kind.
883  // Note that we deliberately do not the support the case when dropping a value
884  // handle results in a new value handle being permanently added to the list
885  // (as might occur in theory for CallbackVH's): the new value handle will not
886  // be processed and the checking code will mete out righteous punishment if
887  // the handle is still present once we have finished processing all the other
888  // value handles (it is fine to momentarily add then remove a value handle).
889  for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
890  Iterator.RemoveFromUseList();
891  Iterator.AddToExistingUseListAfter(Entry);
892  assert(Entry->Next == &Iterator && "Loop invariant broken.");
893 
894  switch (Entry->getKind()) {
895  case Assert:
896  break;
897  case Weak:
898  case WeakTracking:
899  // WeakTracking and Weak just go to null, which unlinks them
900  // from the list.
901  Entry->operator=(nullptr);
902  break;
903  case Callback:
904  // Forward to the subclass's implementation.
905  static_cast<CallbackVH*>(Entry)->deleted();
906  break;
907  }
908  }
909 
910  // All callbacks, weak references, and assertingVHs should be dropped by now.
911  if (V->HasValueHandle) {
912 #ifndef NDEBUG // Only in +Asserts mode...
913  dbgs() << "While deleting: " << *V->getType() << " %" << V->getName()
914  << "\n";
915  if (pImpl->ValueHandles[V]->getKind() == Assert)
916  llvm_unreachable("An asserting value handle still pointed to this"
917  " value!");
918 
919 #endif
920  llvm_unreachable("All references to V were not removed?");
921  }
922 }
923 
925  assert(Old->HasValueHandle &&"Should only be called if ValueHandles present");
926  assert(Old != New && "Changing value into itself!");
927  assert(Old->getType() == New->getType() &&
928  "replaceAllUses of value with new value of different type!");
929 
930  // Get the linked list base, which is guaranteed to exist since the
931  // HasValueHandle flag is set.
932  LLVMContextImpl *pImpl = Old->getContext().pImpl;
933  ValueHandleBase *Entry = pImpl->ValueHandles[Old];
934 
935  assert(Entry && "Value bit set but no entries exist");
936 
937  // We use a local ValueHandleBase as an iterator so that
938  // ValueHandles can add and remove themselves from the list without
939  // breaking our iteration. This is not really an AssertingVH; we
940  // just have to give ValueHandleBase some kind.
941  for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
942  Iterator.RemoveFromUseList();
943  Iterator.AddToExistingUseListAfter(Entry);
944  assert(Entry->Next == &Iterator && "Loop invariant broken.");
945 
946  switch (Entry->getKind()) {
947  case Assert:
948  case Weak:
949  // Asserting and Weak handles do not follow RAUW implicitly.
950  break;
951  case WeakTracking:
952  // Weak goes to the new value, which will unlink it from Old's list.
953  Entry->operator=(New);
954  break;
955  case Callback:
956  // Forward to the subclass's implementation.
957  static_cast<CallbackVH*>(Entry)->allUsesReplacedWith(New);
958  break;
959  }
960  }
961 
962 #ifndef NDEBUG
963  // If any new weak value handles were added while processing the
964  // list, then complain about it now.
965  if (Old->HasValueHandle)
966  for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
967  switch (Entry->getKind()) {
968  case WeakTracking:
969  dbgs() << "After RAUW from " << *Old->getType() << " %"
970  << Old->getName() << " to " << *New->getType() << " %"
971  << New->getName() << "\n";
973  "A weak tracking value handle still pointed to the old value!\n");
974  default:
975  break;
976  }
977 #endif
978 }
979 
980 // Pin the vtable to this file.
981 void CallbackVH::anchor() {}
This is the common base class of value handles.
Definition: ValueHandle.h:29
uint64_t CallInst * C
use_iterator use_end()
Definition: Value.h:367
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This class provides a symbol table of name/value pairs.
static void ValueIsDeleted(Value *V)
Definition: Value.cpp:871
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:484
const Value * stripInBoundsOffsets() const
Strip off pointer casts and inbounds GEPs.
Definition: Value.cpp:605
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:158
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:265
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition: Value.cpp:534
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
Definition: Twine.h:400
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:455
The function pointer alignment is a multiple of the function alignment.
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Definition: Instructions.h:137
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:744
void deleteValue()
Delete a pointer to a generic Value.
Definition: Value.cpp:99
Metadata node.
Definition: Metadata.h:872
F(f)
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
Definition: DenseMap.h:325
An instruction for reading from memory.
Definition: Instructions.h:169
Hexagon Common GEP
#define Assert(C,...)
Definition: Lint.cpp:197
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
Definition: Value.cpp:736
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1566
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:130
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:273
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Definition: DataLayout.h:282
static Type * checkType(Type *Ty)
Definition: Value.cpp:48
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
A Use represents the edge between a Value definition and its users.
Definition: Use.h:55
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:286
void assertModuleIsMaterializedImpl() const
Definition: Value.cpp:352
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:600
DenseMap< const Value *, ValueName * > ValueNames
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
static StringMapEntry * Create(StringRef Key, AllocatorTy &Allocator, InitTy &&... InitVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
Definition: StringMap.h:178
void Destroy(AllocatorTy &Allocator)
Destroy - Destroy this StringMapEntry, releasing memory back to the specified allocator.
Definition: StringMap.h:223
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
Definition: Use.cpp:40
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:889
static void handleRAUW(Value *From, Value *To)
Definition: Metadata.cpp:391
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
Definition: Type.h:244
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:454
bool isSwiftError() const
Return true if this value is a swifterror value.
Definition: Value.cpp:765
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:963
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:151
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:430
static void ValueIsRAUWd(Value *Old, Value *New)
Definition: Value.cpp:924
void setValue(const ValueTy &V)
Definition: StringMap.h:141
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:292
void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
Definition: Value.h:301
bool isVoidTy() const
Return true if this is &#39;void&#39;.
Definition: Type.h:141
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:435
bool erase(const KeyT &Val)
Definition: DenseMap.h:272
void RemoveFromUseList()
Remove this ValueHandle from its current use list.
Definition: Value.cpp:845
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
Definition: Value.cpp:136
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
Definition: Value.cpp:132
void set(Value *Val)
Definition: Value.h:730
bool hasName() const
Definition: Value.h:252
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:63
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:41
void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
Definition: Value.cpp:434
Value * getIncomingValueForBlock(const BasicBlock *BB) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:224
StringRef getKey() const
Definition: StringMap.h:162
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:370
MaybeAlign getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
Definition: Value.cpp:675
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:765
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
Definition: Value.cpp:140
ValueHandlesTy ValueHandles
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
op_range operands()
Definition: User.h:237
unsigned size() const
Definition: DenseMap.h:99
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
Definition: DataLayout.cpp:687
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, typename std::enable_if< !std::is_same< typename std::iterator_traits< typename std::remove_reference< decltype(Begin)>::type >::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
Definition: STLExtras.h:1560
const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
Definition: Value.cpp:538
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:530
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:65
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:227
Iterator for intrusive lists based on ilist_node.
static cl::opt< unsigned > NonGlobalValueMaxNameSize("non-global-value-max-name-size", cl::Hidden, cl::init(1024), cl::desc("Maximum size for the name of non-global values."))
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:443
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
Definition: Constants.h:250
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
bool materialized_use_empty() const
Definition: Value.h:348
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
iterator end()
Definition: BasicBlock.h:275
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Definition: Alignment.h:117
Module.h This file contains the declarations for the Module class.
ValueName * getValueName() const
Definition: Value.cpp:187
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:755
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
Definition: Value.cpp:609
PointerStripKind
Definition: Value.cpp:457
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap&#39;s...
Definition: DenseMap.h:318
const Value * stripPointerCastsAndInvariantGroups() const
Strip off pointer casts, all-zero GEPs and invariant group info.
Definition: Value.cpp:546
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
Definition: Value.h:509
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition: DataLayout.cpp:837
Class for arbitrary precision integers.
Definition: APInt.h:69
iterator_range< user_iterator > users()
Definition: Value.h:420
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:390
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds) const
Accumulate the constant offset this value has compared to a base pointer.
Definition: Value.cpp:551
void reverseUseList()
Reverse the use-list.
Definition: Value.cpp:746
use_iterator use_begin()
Definition: Value.h:359
bool isMaterialized() const
Definition: Module.h:509
unsigned getNumUses() const
This method computes the number of uses of this Value.
Definition: Value.cpp:161
unsigned HasName
Definition: Value.h:120
static const size_t npos
Definition: StringRef.h:56
iterator begin()
Definition: DenseMap.h:73
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:215
const NodeList & List
Definition: RDFGraph.cpp:201
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:401
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
Definition: Value.cpp:165
iterator end()
Definition: DenseMap.h:82
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
~Value()
Value&#39;s destructor should be virtual by design, but that would require that Value and all of its subc...
Definition: Value.cpp:73
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
Definition: APInt.h:1609
user_iterator user_begin()
Definition: Value.h:396
static void handleDeletion(Value *V)
Definition: Metadata.cpp:372
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:74
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition: Operator.h:40
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, typename std::enable_if< !std::is_same< typename std::iterator_traits< typename std::remove_reference< decltype(Begin)>::type >::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
Definition: STLExtras.h:1543
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:279
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
Definition: DataLayout.h:278
void setValueName(ValueName *VN)
Definition: Value.cpp:198
Value handle with callbacks on RAUW and destruction.
Definition: ValueHandle.h:399
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
void replaceUsesOutsideBlock(Value *V, BasicBlock *BB)
replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V"...
Definition: Value.cpp:440
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
Definition: Value.cpp:542
static bool contains(SmallPtrSetImpl< ConstantExpr *> &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:365
The function pointer alignment is independent of the function alignment.
bool use_empty() const
Definition: Value.h:343
bool isStructTy() const
True if this is an instance of StructType.
Definition: Type.h:218
an instruction to allocate memory on the stack
Definition: Instructions.h:59
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1241
user_iterator user_end()
Definition: Value.h:404