LLVM  13.0.0git
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/DebugInfo.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/DerivedUser.h"
25 #include "llvm/IR/InstrTypes.h"
26 #include "llvm/IR/Instructions.h"
27 #include "llvm/IR/IntrinsicInst.h"
28 #include "llvm/IR/Module.h"
29 #include "llvm/IR/Operator.h"
30 #include "llvm/IR/ValueHandle.h"
33 #include "llvm/Support/Debug.h"
37 #include <algorithm>
38 
39 using namespace llvm;
40 
42  "use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false),
43  cl::desc("Deref attributes and metadata infer facts at definition only"));
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), HasValueHandle(0),
55  SubclassOptionalData(0), SubclassData(0), NumUserOperands(0),
56  IsUsedByMD(false), HasName(false), HasMetadata(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  // Remove associated metadata from context.
81  if (HasMetadata)
82  clearMetadata();
83 
84 #ifndef NDEBUG // Only in -g mode...
85  // Check to make sure that there are no uses of this value that are still
86  // around when the value is destroyed. If there are, then we have a dangling
87  // reference and something is wrong. This code is here to print out where
88  // the value is still being referenced.
89  //
90  // Note that use_empty() cannot be called here, as it eventually downcasts
91  // 'this' to GlobalValue (derived class of Value), but GlobalValue has already
92  // been destructed, so accessing it is UB.
93  //
94  if (!materialized_use_empty()) {
95  dbgs() << "While deleting: " << *VTy << " %" << getName() << "\n";
96  for (auto *U : users())
97  dbgs() << "Use still stuck around after Def is destroyed:" << *U << "\n";
98  }
99 #endif
100  assert(materialized_use_empty() && "Uses remain when a value is destroyed!");
101 
102  // If this value is named, destroy the name. This should not be in a symtab
103  // at this point.
104  destroyValueName();
105 }
106 
108  switch (getValueID()) {
109 #define HANDLE_VALUE(Name) \
110  case Value::Name##Val: \
111  delete static_cast<Name *>(this); \
112  break;
113 #define HANDLE_MEMORY_VALUE(Name) \
114  case Value::Name##Val: \
115  static_cast<DerivedUser *>(this)->DeleteValue( \
116  static_cast<DerivedUser *>(this)); \
117  break;
118 #define HANDLE_CONSTANT(Name) \
119  case Value::Name##Val: \
120  llvm_unreachable("constants should be destroyed with destroyConstant"); \
121  break;
122 #define HANDLE_INSTRUCTION(Name) /* nothing */
123 #include "llvm/IR/Value.def"
124 
125 #define HANDLE_INST(N, OPC, CLASS) \
126  case Value::InstructionVal + Instruction::OPC: \
127  delete static_cast<CLASS *>(this); \
128  break;
129 #define HANDLE_USER_INST(N, OPC, CLASS)
130 #include "llvm/IR/Instruction.def"
131 
132  default:
133  llvm_unreachable("attempting to delete unknown value kind");
134  }
135 }
136 
137 void Value::destroyValueName() {
139  if (Name) {
141  Name->Destroy(Allocator);
142  }
143  setValueName(nullptr);
144 }
145 
146 bool Value::hasNUses(unsigned N) const {
147  return hasNItems(use_begin(), use_end(), N);
148 }
149 
150 bool Value::hasNUsesOrMore(unsigned N) const {
151  return hasNItemsOrMore(use_begin(), use_end(), N);
152 }
153 
154 bool Value::hasOneUser() const {
155  if (use_empty())
156  return false;
157  if (hasOneUse())
158  return true;
159  return std::equal(++user_begin(), user_end(), user_begin());
160 }
161 
162 static bool isUnDroppableUser(const User *U) { return !U->isDroppable(); }
163 
165  Use *Result = nullptr;
166  for (Use &U : uses()) {
167  if (!U.getUser()->isDroppable()) {
168  if (Result)
169  return nullptr;
170  Result = &U;
171  }
172  }
173  return Result;
174 }
175 
176 bool Value::hasNUndroppableUses(unsigned int N) const {
178 }
179 
180 bool Value::hasNUndroppableUsesOrMore(unsigned int N) const {
182 }
183 
185  llvm::function_ref<bool(const Use *)> ShouldDrop) {
186  SmallVector<Use *, 8> ToBeEdited;
187  for (Use &U : uses())
188  if (U.getUser()->isDroppable() && ShouldDrop(&U))
189  ToBeEdited.push_back(&U);
190  for (Use *U : ToBeEdited)
191  dropDroppableUse(*U);
192 }
193 
195  assert(Usr.isDroppable() && "Expected a droppable user!");
196  for (Use &UsrOp : Usr.operands()) {
197  if (UsrOp.get() == this)
198  dropDroppableUse(UsrOp);
199  }
200 }
201 
203  U.removeFromList();
204  if (auto *Assume = dyn_cast<AssumeInst>(U.getUser())) {
205  unsigned OpNo = U.getOperandNo();
206  if (OpNo == 0)
207  U.set(ConstantInt::getTrue(Assume->getContext()));
208  else {
209  U.set(UndefValue::get(U.get()->getType()));
210  CallInst::BundleOpInfo &BOI = Assume->getBundleOpInfoForOperand(OpNo);
211  BOI.Tag = Assume->getContext().pImpl->getOrInsertBundleTag("ignore");
212  }
213  return;
214  }
215 
216  llvm_unreachable("unkown droppable use");
217 }
218 
220  // This can be computed either by scanning the instructions in BB, or by
221  // scanning the use list of this Value. Both lists can be very long, but
222  // usually one is quite short.
223  //
224  // Scan both lists simultaneously until one is exhausted. This limits the
225  // search to the shorter list.
226  BasicBlock::const_iterator BI = BB->begin(), BE = BB->end();
227  const_user_iterator UI = user_begin(), UE = user_end();
228  for (; BI != BE && UI != UE; ++BI, ++UI) {
229  // Scan basic block: Check if this Value is used by the instruction at BI.
230  if (is_contained(BI->operands(), this))
231  return true;
232  // Scan use list: Check if the use at UI is in BB.
233  const auto *User = dyn_cast<Instruction>(*UI);
234  if (User && User->getParent() == BB)
235  return true;
236  }
237  return false;
238 }
239 
240 unsigned Value::getNumUses() const {
241  return (unsigned)std::distance(use_begin(), use_end());
242 }
243 
244 static bool getSymTab(Value *V, ValueSymbolTable *&ST) {
245  ST = nullptr;
246  if (Instruction *I = dyn_cast<Instruction>(V)) {
247  if (BasicBlock *P = I->getParent())
248  if (Function *PP = P->getParent())
249  ST = PP->getValueSymbolTable();
250  } else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
251  if (Function *P = BB->getParent())
252  ST = P->getValueSymbolTable();
253  } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
254  if (Module *P = GV->getParent())
255  ST = &P->getValueSymbolTable();
256  } else if (Argument *A = dyn_cast<Argument>(V)) {
257  if (Function *P = A->getParent())
258  ST = P->getValueSymbolTable();
259  } else {
260  assert(isa<Constant>(V) && "Unknown value type!");
261  return true; // no name is setable for this.
262  }
263  return false;
264 }
265 
267  if (!HasName) return nullptr;
268 
269  LLVMContext &Ctx = getContext();
270  auto I = Ctx.pImpl->ValueNames.find(this);
271  assert(I != Ctx.pImpl->ValueNames.end() &&
272  "No name entry found!");
273 
274  return I->second;
275 }
276 
278  LLVMContext &Ctx = getContext();
279 
280  assert(HasName == Ctx.pImpl->ValueNames.count(this) &&
281  "HasName bit out of sync!");
282 
283  if (!VN) {
284  if (HasName)
285  Ctx.pImpl->ValueNames.erase(this);
286  HasName = false;
287  return;
288  }
289 
290  HasName = true;
291  Ctx.pImpl->ValueNames[this] = VN;
292 }
293 
295  // Make sure the empty string is still a C string. For historical reasons,
296  // some clients want to call .data() on the result and expect it to be null
297  // terminated.
298  if (!hasName())
299  return StringRef("", 0);
300  return getValueName()->getKey();
301 }
302 
303 void Value::setNameImpl(const Twine &NewName) {
304  // Fast-path: LLVMContext can be set to strip out non-GlobalValue names
305  if (getContext().shouldDiscardValueNames() && !isa<GlobalValue>(this))
306  return;
307 
308  // Fast path for common IRBuilder case of setName("") when there is no name.
309  if (NewName.isTriviallyEmpty() && !hasName())
310  return;
311 
312  SmallString<256> NameData;
313  StringRef NameRef = NewName.toStringRef(NameData);
314  assert(NameRef.find_first_of(0) == StringRef::npos &&
315  "Null bytes are not allowed in names");
316 
317  // Name isn't changing?
318  if (getName() == NameRef)
319  return;
320 
321  assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
322 
323  // Get the symbol table to update for this object.
325  if (getSymTab(this, ST))
326  return; // Cannot set a name on this value (e.g. constant).
327 
328  if (!ST) { // No symbol table to update? Just do the change.
329  if (NameRef.empty()) {
330  // Free the name for this value.
331  destroyValueName();
332  return;
333  }
334 
335  // NOTE: Could optimize for the case the name is shrinking to not deallocate
336  // then reallocated.
337  destroyValueName();
338 
339  // Create the new name.
342  getValueName()->setValue(this);
343  return;
344  }
345 
346  // NOTE: Could optimize for the case the name is shrinking to not deallocate
347  // then reallocated.
348  if (hasName()) {
349  // Remove old name.
350  ST->removeValueName(getValueName());
351  destroyValueName();
352 
353  if (NameRef.empty())
354  return;
355  }
356 
357  // Name is changing to something new.
358  setValueName(ST->createValueName(NameRef, this));
359 }
360 
361 void Value::setName(const Twine &NewName) {
362  setNameImpl(NewName);
363  if (Function *F = dyn_cast<Function>(this))
364  F->recalculateIntrinsicID();
365 }
366 
368  ValueSymbolTable *ST = nullptr;
369  // If this value has a name, drop it.
370  if (hasName()) {
371  // Get the symtab this is in.
372  if (getSymTab(this, ST)) {
373  // We can't set a name on this value, but we need to clear V's name if
374  // it has one.
375  if (V->hasName()) V->setName("");
376  return; // Cannot set a name on this value (e.g. constant).
377  }
378 
379  // Remove old name.
380  if (ST)
381  ST->removeValueName(getValueName());
382  destroyValueName();
383  }
384 
385  // Now we know that this has no name.
386 
387  // If V has no name either, we're done.
388  if (!V->hasName()) return;
389 
390  // Get this's symtab if we didn't before.
391  if (!ST) {
392  if (getSymTab(this, ST)) {
393  // Clear V's name.
394  V->setName("");
395  return; // Cannot set a name on this value (e.g. constant).
396  }
397  }
398 
399  // Get V's ST, this should always succed, because V has a name.
400  ValueSymbolTable *VST;
401  bool Failure = getSymTab(V, VST);
402  assert(!Failure && "V has a name, so it should have a ST!"); (void)Failure;
403 
404  // If these values are both in the same symtab, we can do this very fast.
405  // This works even if both values have no symtab yet.
406  if (ST == VST) {
407  // Take the name!
409  V->setValueName(nullptr);
410  getValueName()->setValue(this);
411  return;
412  }
413 
414  // Otherwise, things are slightly more complex. Remove V's name from VST and
415  // then reinsert it into ST.
416 
417  if (VST)
418  VST->removeValueName(V->getValueName());
420  V->setValueName(nullptr);
421  getValueName()->setValue(this);
422 
423  if (ST)
424  ST->reinsertValue(this);
425 }
426 
427 #ifndef NDEBUG
428 std::string Value::getNameOrAsOperand() const {
429  if (!getName().empty())
430  return std::string(getName());
431 
432  std::string BBName;
433  raw_string_ostream OS(BBName);
434  printAsOperand(OS, false);
435  return OS.str();
436 }
437 #endif
438 
440 #ifndef NDEBUG
441  const GlobalValue *GV = dyn_cast<GlobalValue>(this);
442  if (!GV)
443  return;
444  const Module *M = GV->getParent();
445  if (!M)
446  return;
447  assert(M->isMaterialized());
448 #endif
449 }
450 
451 #ifndef NDEBUG
453  Constant *C) {
454  if (!Cache.insert(Expr).second)
455  return false;
456 
457  for (auto &O : Expr->operands()) {
458  if (O == C)
459  return true;
460  auto *CE = dyn_cast<ConstantExpr>(O);
461  if (!CE)
462  continue;
463  if (contains(Cache, CE, C))
464  return true;
465  }
466  return false;
467 }
468 
469 static bool contains(Value *Expr, Value *V) {
470  if (Expr == V)
471  return true;
472 
473  auto *C = dyn_cast<Constant>(V);
474  if (!C)
475  return false;
476 
477  auto *CE = dyn_cast<ConstantExpr>(Expr);
478  if (!CE)
479  return false;
480 
482  return contains(Cache, CE, C);
483 }
484 #endif // NDEBUG
485 
486 void Value::doRAUW(Value *New, ReplaceMetadataUses ReplaceMetaUses) {
487  assert(New && "Value::replaceAllUsesWith(<null>) is invalid!");
488  assert(!contains(New, this) &&
489  "this->replaceAllUsesWith(expr(this)) is NOT valid!");
490  assert(New->getType() == getType() &&
491  "replaceAllUses of value with new value of different type!");
492 
493  // Notify all ValueHandles (if present) that this value is going away.
494  if (HasValueHandle)
496  if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
497  ValueAsMetadata::handleRAUW(this, New);
498 
499  while (!materialized_use_empty()) {
500  Use &U = *UseList;
501  // Must handle Constants specially, we cannot call replaceUsesOfWith on a
502  // constant because they are uniqued.
503  if (auto *C = dyn_cast<Constant>(U.getUser())) {
504  if (!isa<GlobalValue>(C)) {
505  C->handleOperandChange(this, New);
506  continue;
507  }
508  }
509 
510  U.set(New);
511  }
512 
513  if (BasicBlock *BB = dyn_cast<BasicBlock>(this))
514  BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
515 }
516 
518  doRAUW(New, ReplaceMetadataUses::Yes);
519 }
520 
522  doRAUW(New, ReplaceMetadataUses::No);
523 }
524 
526  llvm::function_ref<bool(Use &U)> ShouldReplace) {
527  assert(New && "Value::replaceUsesWithIf(<null>) is invalid!");
528  assert(New->getType() == getType() &&
529  "replaceUses of value with new value of different type!");
530 
531  for (use_iterator UI = use_begin(), E = use_end(); UI != E;) {
532  Use &U = *UI;
533  ++UI;
534  if (!ShouldReplace(U))
535  continue;
536  // Must handle Constants specially, we cannot call replaceUsesOfWith on a
537  // constant because they are uniqued.
538  if (auto *C = dyn_cast<Constant>(U.getUser())) {
539  if (!isa<GlobalValue>(C)) {
540  C->handleOperandChange(this, New);
541  continue;
542  }
543  }
544  U.set(New);
545  }
546 }
547 
548 /// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
549 /// with New.
552  findDbgUsers(DbgUsers, V);
553  for (auto *DVI : DbgUsers) {
554  if (DVI->getParent() != BB)
555  DVI->replaceVariableLocationOp(V, New);
556  }
557 }
558 
559 // Like replaceAllUsesWith except it does not handle constants or basic blocks.
560 // This routine leaves uses within BB.
562  assert(New && "Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
563  assert(!contains(New, this) &&
564  "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
565  assert(New->getType() == getType() &&
566  "replaceUses of value with new value of different type!");
567  assert(BB && "Basic block that may contain a use of 'New' must be defined\n");
568 
569  replaceDbgUsesOutsideBlock(this, New, BB);
570  replaceUsesWithIf(New, [BB](Use &U) {
571  auto *I = dyn_cast<Instruction>(U.getUser());
572  // Don't replace if it's an instruction in the BB basic block.
573  return !I || I->getParent() != BB;
574  });
575 }
576 
577 namespace {
578 // Various metrics for how much to strip off of pointers.
579 enum PointerStripKind {
580  PSK_ZeroIndices,
581  PSK_ZeroIndicesAndAliases,
582  PSK_ZeroIndicesSameRepresentation,
583  PSK_ForAliasAnalysis,
584  PSK_InBoundsConstantIndices,
585  PSK_InBounds
586 };
587 
588 template <PointerStripKind StripKind> static void NoopCallback(const Value *) {}
589 
590 template <PointerStripKind StripKind>
591 static const Value *stripPointerCastsAndOffsets(
592  const Value *V,
593  function_ref<void(const Value *)> Func = NoopCallback<StripKind>) {
594  if (!V->getType()->isPointerTy())
595  return V;
596 
597  // Even though we don't look through PHI nodes, we could be called on an
598  // instruction in an unreachable block, which may be on a cycle.
600 
601  Visited.insert(V);
602  do {
603  Func(V);
604  if (auto *GEP = dyn_cast<GEPOperator>(V)) {
605  switch (StripKind) {
606  case PSK_ZeroIndices:
607  case PSK_ZeroIndicesAndAliases:
608  case PSK_ZeroIndicesSameRepresentation:
609  case PSK_ForAliasAnalysis:
610  if (!GEP->hasAllZeroIndices())
611  return V;
612  break;
613  case PSK_InBoundsConstantIndices:
614  if (!GEP->hasAllConstantIndices())
615  return V;
617  case PSK_InBounds:
618  if (!GEP->isInBounds())
619  return V;
620  break;
621  }
622  V = GEP->getPointerOperand();
623  } else if (Operator::getOpcode(V) == Instruction::BitCast) {
624  V = cast<Operator>(V)->getOperand(0);
625  if (!V->getType()->isPointerTy())
626  return V;
627  } else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
628  Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
629  // TODO: If we know an address space cast will not change the
630  // representation we could look through it here as well.
631  V = cast<Operator>(V)->getOperand(0);
632  } else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
633  V = cast<GlobalAlias>(V)->getAliasee();
634  } else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
635  cast<PHINode>(V)->getNumIncomingValues() == 1) {
636  V = cast<PHINode>(V)->getIncomingValue(0);
637  } else {
638  if (const auto *Call = dyn_cast<CallBase>(V)) {
639  if (const Value *RV = Call->getReturnedArgOperand()) {
640  V = RV;
641  continue;
642  }
643  // The result of launder.invariant.group must alias it's argument,
644  // but it can't be marked with returned attribute, that's why it needs
645  // special case.
646  if (StripKind == PSK_ForAliasAnalysis &&
647  (Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
648  Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
649  V = Call->getArgOperand(0);
650  continue;
651  }
652  }
653  return V;
654  }
655  assert(V->getType()->isPointerTy() && "Unexpected operand type!");
656  } while (Visited.insert(V).second);
657 
658  return V;
659 }
660 } // end anonymous namespace
661 
663  return stripPointerCastsAndOffsets<PSK_ZeroIndices>(this);
664 }
665 
667  return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(this);
668 }
669 
671  return stripPointerCastsAndOffsets<PSK_ZeroIndicesSameRepresentation>(this);
672 }
673 
675  return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(this);
676 }
677 
679  return stripPointerCastsAndOffsets<PSK_ForAliasAnalysis>(this);
680 }
681 
683  const DataLayout &DL, APInt &Offset, bool AllowNonInbounds,
684  function_ref<bool(Value &, APInt &)> ExternalAnalysis) const {
685  if (!getType()->isPtrOrPtrVectorTy())
686  return this;
687 
688  unsigned BitWidth = Offset.getBitWidth();
689  assert(BitWidth == DL.getIndexTypeSizeInBits(getType()) &&
690  "The offset bit width does not match the DL specification.");
691 
692  // Even though we don't look through PHI nodes, we could be called on an
693  // instruction in an unreachable block, which may be on a cycle.
695  Visited.insert(this);
696  const Value *V = this;
697  do {
698  if (auto *GEP = dyn_cast<GEPOperator>(V)) {
699  // If in-bounds was requested, we do not strip non-in-bounds GEPs.
700  if (!AllowNonInbounds && !GEP->isInBounds())
701  return V;
702 
703  // If one of the values we have visited is an addrspacecast, then
704  // the pointer type of this GEP may be different from the type
705  // of the Ptr parameter which was passed to this function. This
706  // means when we construct GEPOffset, we need to use the size
707  // of GEP's pointer type rather than the size of the original
708  // pointer type.
709  APInt GEPOffset(DL.getIndexTypeSizeInBits(V->getType()), 0);
710  if (!GEP->accumulateConstantOffset(DL, GEPOffset, ExternalAnalysis))
711  return V;
712 
713  // Stop traversal if the pointer offset wouldn't fit in the bit-width
714  // provided by the Offset argument. This can happen due to AddrSpaceCast
715  // stripping.
716  if (GEPOffset.getMinSignedBits() > BitWidth)
717  return V;
718 
719  // External Analysis can return a result higher/lower than the value
720  // represents. We need to detect overflow/underflow.
721  APInt GEPOffsetST = GEPOffset.sextOrTrunc(BitWidth);
722  if (!ExternalAnalysis) {
723  Offset += GEPOffsetST;
724  } else {
725  bool Overflow = false;
726  APInt OldOffset = Offset;
727  Offset = Offset.sadd_ov(GEPOffsetST, Overflow);
728  if (Overflow) {
729  Offset = OldOffset;
730  return V;
731  }
732  }
733  V = GEP->getPointerOperand();
734  } else if (Operator::getOpcode(V) == Instruction::BitCast ||
735  Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
736  V = cast<Operator>(V)->getOperand(0);
737  } else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
738  if (!GA->isInterposable())
739  V = GA->getAliasee();
740  } else if (const auto *Call = dyn_cast<CallBase>(V)) {
741  if (const Value *RV = Call->getReturnedArgOperand())
742  V = RV;
743  }
744  assert(V->getType()->isPtrOrPtrVectorTy() && "Unexpected operand type!");
745  } while (Visited.insert(V).second);
746 
747  return V;
748 }
749 
750 const Value *
751 Value::stripInBoundsOffsets(function_ref<void(const Value *)> Func) const {
752  return stripPointerCastsAndOffsets<PSK_InBounds>(this, Func);
753 }
754 
755 bool Value::canBeFreed() const {
756  assert(getType()->isPointerTy());
757 
758  // Cases that can simply never be deallocated
759  // *) Constants aren't allocated per se, thus not deallocated either.
760  if (isa<Constant>(this))
761  return false;
762 
763  // Handle byval/byref/sret/inalloca/preallocated arguments. The storage
764  // lifetime is guaranteed to be longer than the callee's lifetime.
765  if (auto *A = dyn_cast<Argument>(this)) {
766  if (A->hasPointeeInMemoryValueAttr())
767  return false;
768  // A pointer to an object in a function which neither frees, nor can arrange
769  // for another thread to free on its behalf, can not be freed in the scope
770  // of the function. Note that this logic is restricted to memory
771  // allocations in existance before the call; a nofree function *is* allowed
772  // to free memory it allocated.
773  const Function *F = A->getParent();
774  if (F->doesNotFreeMemory() && F->hasNoSync())
775  return false;
776  }
777 
778  const Function *F = nullptr;
779  if (auto *I = dyn_cast<Instruction>(this))
780  F = I->getFunction();
781  if (auto *A = dyn_cast<Argument>(this))
782  F = A->getParent();
783 
784  if (!F)
785  return true;
786 
787  // With garbage collection, deallocation typically occurs solely at or after
788  // safepoints. If we're compiling for a collector which uses the
789  // gc.statepoint infrastructure, safepoints aren't explicitly present
790  // in the IR until after lowering from abstract to physical machine model.
791  // The collector could chose to mix explicit deallocation and gc'd objects
792  // which is why we need the explicit opt in on a per collector basis.
793  if (!F->hasGC())
794  return true;
795 
796  const auto &GCName = F->getGC();
797  if (GCName == "statepoint-example") {
798  auto *PT = cast<PointerType>(this->getType());
799  if (PT->getAddressSpace() != 1)
800  // For the sake of this example GC, we arbitrarily pick addrspace(1) as
801  // our GC managed heap. This must match the same check in
802  // RewriteStatepointsForGC (and probably needs better factored.)
803  return true;
804 
805  // It is cheaper to scan for a declaration than to scan for a use in this
806  // function. Note that gc.statepoint is a type overloaded function so the
807  // usual trick of requesting declaration of the intrinsic from the module
808  // doesn't work.
809  for (auto &Fn : *F->getParent())
810  if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
811  return true;
812  return false;
813  }
814  return true;
815 }
816 
818  bool &CanBeNull,
819  bool &CanBeFreed) const {
820  assert(getType()->isPointerTy() && "must be pointer");
821 
822  uint64_t DerefBytes = 0;
823  CanBeNull = false;
824  CanBeFreed = UseDerefAtPointSemantics && canBeFreed();
825  if (const Argument *A = dyn_cast<Argument>(this)) {
826  DerefBytes = A->getDereferenceableBytes();
827  if (DerefBytes == 0) {
828  // Handle byval/byref/inalloca/preallocated arguments
829  if (Type *ArgMemTy = A->getPointeeInMemoryValueType()) {
830  if (ArgMemTy->isSized()) {
831  // FIXME: Why isn't this the type alloc size?
832  DerefBytes = DL.getTypeStoreSize(ArgMemTy).getKnownMinSize();
833  }
834  }
835  }
836 
837  if (DerefBytes == 0) {
838  DerefBytes = A->getDereferenceableOrNullBytes();
839  CanBeNull = true;
840  }
841  } else if (const auto *Call = dyn_cast<CallBase>(this)) {
842  DerefBytes = Call->getDereferenceableBytes(AttributeList::ReturnIndex);
843  if (DerefBytes == 0) {
844  DerefBytes =
845  Call->getDereferenceableOrNullBytes(AttributeList::ReturnIndex);
846  CanBeNull = true;
847  }
848  } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
849  if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
850  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
851  DerefBytes = CI->getLimitedValue();
852  }
853  if (DerefBytes == 0) {
854  if (MDNode *MD =
855  LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
856  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
857  DerefBytes = CI->getLimitedValue();
858  }
859  CanBeNull = true;
860  }
861  } else if (auto *IP = dyn_cast<IntToPtrInst>(this)) {
862  if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
863  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
864  DerefBytes = CI->getLimitedValue();
865  }
866  if (DerefBytes == 0) {
867  if (MDNode *MD =
868  IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
869  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
870  DerefBytes = CI->getLimitedValue();
871  }
872  CanBeNull = true;
873  }
874  } else if (auto *AI = dyn_cast<AllocaInst>(this)) {
875  if (!AI->isArrayAllocation()) {
876  DerefBytes =
877  DL.getTypeStoreSize(AI->getAllocatedType()).getKnownMinSize();
878  CanBeNull = false;
879  CanBeFreed = false;
880  }
881  } else if (auto *GV = dyn_cast<GlobalVariable>(this)) {
882  if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
883  // TODO: Don't outright reject hasExternalWeakLinkage but set the
884  // CanBeNull flag.
885  DerefBytes = DL.getTypeStoreSize(GV->getValueType()).getFixedSize();
886  CanBeNull = false;
887  }
888  }
889  return DerefBytes;
890 }
891 
893  assert(getType()->isPointerTy() && "must be pointer");
894  if (auto *GO = dyn_cast<GlobalObject>(this)) {
895  if (isa<Function>(GO)) {
896  Align FunctionPtrAlign = DL.getFunctionPtrAlign().valueOrOne();
897  switch (DL.getFunctionPtrAlignType()) {
899  return FunctionPtrAlign;
901  return std::max(FunctionPtrAlign, GO->getAlign().valueOrOne());
902  }
903  llvm_unreachable("Unhandled FunctionPtrAlignType");
904  }
905  const MaybeAlign Alignment(GO->getAlignment());
906  if (!Alignment) {
907  if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
908  Type *ObjectType = GVar->getValueType();
909  if (ObjectType->isSized()) {
910  // If the object is defined in the current Module, we'll be giving
911  // it the preferred alignment. Otherwise, we have to assume that it
912  // may only have the minimum ABI alignment.
913  if (GVar->isStrongDefinitionForLinker())
914  return DL.getPreferredAlign(GVar);
915  else
916  return DL.getABITypeAlign(ObjectType);
917  }
918  }
919  }
920  return Alignment.valueOrOne();
921  } else if (const Argument *A = dyn_cast<Argument>(this)) {
922  const MaybeAlign Alignment = A->getParamAlign();
923  if (!Alignment && A->hasStructRetAttr()) {
924  // An sret parameter has at least the ABI alignment of the return type.
925  Type *EltTy = A->getParamStructRetType();
926  if (EltTy->isSized())
927  return DL.getABITypeAlign(EltTy);
928  }
929  return Alignment.valueOrOne();
930  } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
931  return AI->getAlign();
932  } else if (const auto *Call = dyn_cast<CallBase>(this)) {
933  MaybeAlign Alignment = Call->getRetAlign();
934  if (!Alignment && Call->getCalledFunction())
935  Alignment = Call->getCalledFunction()->getAttributes().getRetAlignment();
936  return Alignment.valueOrOne();
937  } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
938  if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
939  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
940  return Align(CI->getLimitedValue());
941  }
942  } else if (auto *CstPtr = dyn_cast<Constant>(this)) {
943  if (auto *CstInt = dyn_cast_or_null<ConstantInt>(ConstantExpr::getPtrToInt(
944  const_cast<Constant *>(CstPtr), DL.getIntPtrType(getType()),
945  /*OnlyIfReduced=*/true))) {
946  size_t TrailingZeros = CstInt->getValue().countTrailingZeros();
947  // While the actual alignment may be large, elsewhere we have
948  // an arbitrary upper alignmet limit, so let's clamp to it.
949  return Align(TrailingZeros < Value::MaxAlignmentExponent
950  ? uint64_t(1) << TrailingZeros
952  }
953  }
954  return Align(1);
955 }
956 
958  const BasicBlock *PredBB) const {
959  auto *PN = dyn_cast<PHINode>(this);
960  if (PN && PN->getParent() == CurBB)
961  return PN->getIncomingValueForBlock(PredBB);
962  return this;
963 }
964 
965 LLVMContext &Value::getContext() const { return VTy->getContext(); }
966 
968  if (!UseList || !UseList->Next)
969  // No need to reverse 0 or 1 uses.
970  return;
971 
972  Use *Head = UseList;
973  Use *Current = UseList->Next;
974  Head->Next = nullptr;
975  while (Current) {
976  Use *Next = Current->Next;
977  Current->Next = Head;
978  Head->Prev = &Current->Next;
979  Head = Current;
980  Current = Next;
981  }
982  UseList = Head;
983  Head->Prev = &UseList;
984 }
985 
986 bool Value::isSwiftError() const {
987  auto *Arg = dyn_cast<Argument>(this);
988  if (Arg)
989  return Arg->hasSwiftErrorAttr();
990  auto *Alloca = dyn_cast<AllocaInst>(this);
991  if (!Alloca)
992  return false;
993  return Alloca->isSwiftError();
994 }
995 
997  if (use_empty())
998  return false;
1001  WorkList.insert(WorkList.begin(), user_begin(), user_end());
1002  while (!WorkList.empty()) {
1003  const User *U = WorkList.back();
1004  WorkList.pop_back();
1005  Visited.insert(U);
1006  // If it is transitively used by a global value or a non-constant value,
1007  // it's obviously not only used by metadata.
1008  if (!isa<Constant>(U) || isa<GlobalValue>(U))
1009  return false;
1010  for (const User *UU : U->users())
1011  if (!Visited.count(UU))
1012  WorkList.push_back(UU);
1013  }
1014  return true;
1015 }
1016 
1017 //===----------------------------------------------------------------------===//
1018 // ValueHandleBase Class
1019 //===----------------------------------------------------------------------===//
1020 
1021 void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1022  assert(List && "Handle list is null?");
1023 
1024  // Splice ourselves into the list.
1025  Next = *List;
1026  *List = this;
1027  setPrevPtr(List);
1028  if (Next) {
1029  Next->setPrevPtr(&Next);
1030  assert(getValPtr() == Next->getValPtr() && "Added to wrong list?");
1031  }
1032 }
1033 
1034 void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1035  assert(List && "Must insert after existing node");
1036 
1037  Next = List->Next;
1038  setPrevPtr(&List->Next);
1039  List->Next = this;
1040  if (Next)
1041  Next->setPrevPtr(&Next);
1042 }
1043 
1044 void ValueHandleBase::AddToUseList() {
1045  assert(getValPtr() && "Null pointer doesn't have a use list!");
1046 
1047  LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1048 
1049  if (getValPtr()->HasValueHandle) {
1050  // If this value already has a ValueHandle, then it must be in the
1051  // ValueHandles map already.
1052  ValueHandleBase *&Entry = pImpl->ValueHandles[getValPtr()];
1053  assert(Entry && "Value doesn't have any handles?");
1054  AddToExistingUseList(&Entry);
1055  return;
1056  }
1057 
1058  // Ok, it doesn't have any handles yet, so we must insert it into the
1059  // DenseMap. However, doing this insertion could cause the DenseMap to
1060  // reallocate itself, which would invalidate all of the PrevP pointers that
1061  // point into the old table. Handle this by checking for reallocation and
1062  // updating the stale pointers only if needed.
1064  const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
1065 
1066  ValueHandleBase *&Entry = Handles[getValPtr()];
1067  assert(!Entry && "Value really did already have handles?");
1068  AddToExistingUseList(&Entry);
1069  getValPtr()->HasValueHandle = true;
1070 
1071  // If reallocation didn't happen or if this was the first insertion, don't
1072  // walk the table.
1073  if (Handles.isPointerIntoBucketsArray(OldBucketPtr) ||
1074  Handles.size() == 1) {
1075  return;
1076  }
1077 
1078  // Okay, reallocation did happen. Fix the Prev Pointers.
1080  E = Handles.end(); I != E; ++I) {
1081  assert(I->second && I->first == I->second->getValPtr() &&
1082  "List invariant broken!");
1083  I->second->setPrevPtr(&I->second);
1084  }
1085 }
1086 
1088  assert(getValPtr() && getValPtr()->HasValueHandle &&
1089  "Pointer doesn't have a use list!");
1090 
1091  // Unlink this from its use list.
1092  ValueHandleBase **PrevPtr = getPrevPtr();
1093  assert(*PrevPtr == this && "List invariant broken");
1094 
1095  *PrevPtr = Next;
1096  if (Next) {
1097  assert(Next->getPrevPtr() == &Next && "List invariant broken");
1098  Next->setPrevPtr(PrevPtr);
1099  return;
1100  }
1101 
1102  // If the Next pointer was null, then it is possible that this was the last
1103  // ValueHandle watching VP. If so, delete its entry from the ValueHandles
1104  // map.
1105  LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1107  if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
1108  Handles.erase(getValPtr());
1109  getValPtr()->HasValueHandle = false;
1110  }
1111 }
1112 
1114  assert(V->HasValueHandle && "Should only be called if ValueHandles present");
1115 
1116  // Get the linked list base, which is guaranteed to exist since the
1117  // HasValueHandle flag is set.
1118  LLVMContextImpl *pImpl = V->getContext().pImpl;
1119  ValueHandleBase *Entry = pImpl->ValueHandles[V];
1120  assert(Entry && "Value bit set but no entries exist");
1121 
1122  // We use a local ValueHandleBase as an iterator so that ValueHandles can add
1123  // and remove themselves from the list without breaking our iteration. This
1124  // is not really an AssertingVH; we just have to give ValueHandleBase a kind.
1125  // Note that we deliberately do not the support the case when dropping a value
1126  // handle results in a new value handle being permanently added to the list
1127  // (as might occur in theory for CallbackVH's): the new value handle will not
1128  // be processed and the checking code will mete out righteous punishment if
1129  // the handle is still present once we have finished processing all the other
1130  // value handles (it is fine to momentarily add then remove a value handle).
1131  for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
1132  Iterator.RemoveFromUseList();
1133  Iterator.AddToExistingUseListAfter(Entry);
1134  assert(Entry->Next == &Iterator && "Loop invariant broken.");
1135 
1136  switch (Entry->getKind()) {
1137  case Assert:
1138  break;
1139  case Weak:
1140  case WeakTracking:
1141  // WeakTracking and Weak just go to null, which unlinks them
1142  // from the list.
1143  Entry->operator=(nullptr);
1144  break;
1145  case Callback:
1146  // Forward to the subclass's implementation.
1147  static_cast<CallbackVH*>(Entry)->deleted();
1148  break;
1149  }
1150  }
1151 
1152  // All callbacks, weak references, and assertingVHs should be dropped by now.
1153  if (V->HasValueHandle) {
1154 #ifndef NDEBUG // Only in +Asserts mode...
1155  dbgs() << "While deleting: " << *V->getType() << " %" << V->getName()
1156  << "\n";
1157  if (pImpl->ValueHandles[V]->getKind() == Assert)
1158  llvm_unreachable("An asserting value handle still pointed to this"
1159  " value!");
1160 
1161 #endif
1162  llvm_unreachable("All references to V were not removed?");
1163  }
1164 }
1165 
1167  assert(Old->HasValueHandle &&"Should only be called if ValueHandles present");
1168  assert(Old != New && "Changing value into itself!");
1169  assert(Old->getType() == New->getType() &&
1170  "replaceAllUses of value with new value of different type!");
1171 
1172  // Get the linked list base, which is guaranteed to exist since the
1173  // HasValueHandle flag is set.
1174  LLVMContextImpl *pImpl = Old->getContext().pImpl;
1175  ValueHandleBase *Entry = pImpl->ValueHandles[Old];
1176 
1177  assert(Entry && "Value bit set but no entries exist");
1178 
1179  // We use a local ValueHandleBase as an iterator so that
1180  // ValueHandles can add and remove themselves from the list without
1181  // breaking our iteration. This is not really an AssertingVH; we
1182  // just have to give ValueHandleBase some kind.
1183  for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
1184  Iterator.RemoveFromUseList();
1185  Iterator.AddToExistingUseListAfter(Entry);
1186  assert(Entry->Next == &Iterator && "Loop invariant broken.");
1187 
1188  switch (Entry->getKind()) {
1189  case Assert:
1190  case Weak:
1191  // Asserting and Weak handles do not follow RAUW implicitly.
1192  break;
1193  case WeakTracking:
1194  // Weak goes to the new value, which will unlink it from Old's list.
1195  Entry->operator=(New);
1196  break;
1197  case Callback:
1198  // Forward to the subclass's implementation.
1199  static_cast<CallbackVH*>(Entry)->allUsesReplacedWith(New);
1200  break;
1201  }
1202  }
1203 
1204 #ifndef NDEBUG
1205  // If any new weak value handles were added while processing the
1206  // list, then complain about it now.
1207  if (Old->HasValueHandle)
1208  for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
1209  switch (Entry->getKind()) {
1210  case WeakTracking:
1211  dbgs() << "After RAUW from " << *Old->getType() << " %"
1212  << Old->getName() << " to " << *New->getType() << " %"
1213  << New->getName() << "\n";
1215  "A weak tracking value handle still pointed to the old value!\n");
1216  default:
1217  break;
1218  }
1219 #endif
1220 }
1221 
1222 // Pin the vtable to this file.
1223 void CallbackVH::anchor() {}
llvm::LLVMContext::pImpl
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:70
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
llvm::Type::isSized
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:272
llvm::Value::const_user_iterator
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:392
llvm::Value::stripPointerCastsAndAliases
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition: Value.cpp:666
llvm
Definition: AllocatorList.h:23
llvm::Value::isUsedInBasicBlock
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
Definition: Value.cpp:219
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::Value::dropDroppableUse
static void dropDroppableUse(Use &U)
Remove the droppable use U.
Definition: Value.cpp:202
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::Value::getPointerAlignment
Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
Definition: Value.cpp:892
llvm::StringMapEntry
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMapEntry.h:98
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::StringMapEntry::Create
static StringMapEntry * Create(StringRef key, AllocatorTy &allocator, InitTy &&... initVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
Definition: StringMapEntry.h:120
llvm::Value::hasOneUse
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition: Value.h:435
llvm::User::operands
op_range operands()
Definition: User.h:242
IntrinsicInst.h
llvm::Type::isPointerTy
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:229
llvm::hasNItems
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)>>::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
Definition: STLExtras.h:1935
llvm::ValueHandleBase
This is the common base class of value handles.
Definition: ValueHandle.h:29
checkType
static Type * checkType(Type *Ty)
Definition: Value.cpp:48
llvm::Function
Definition: Function.h:61
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::DataLayout::FunctionPtrAlignType::Independent
@ Independent
The function pointer alignment is independent of the function alignment.
llvm::CallBase::BundleOpInfo::Tag
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
Definition: InstrTypes.h:2107
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:614
GetElementPtrTypeIterator.h
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:60
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1167
llvm::Value::hasName
bool hasName() const
Definition: Value.h:262
ErrorHandling.h
ManagedStatic.h
llvm::Use::get
Value * get() const
Definition: Use.h:67
llvm::findDbgUsers
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: DebugInfo.cpp:102
llvm::ValueHandleBase::Callback
@ Callback
Definition: ValueHandle.h:37
llvm::ValueAsMetadata::handleDeletion
static void handleDeletion(Value *V)
Definition: Metadata.cpp:386
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::DenseMapBase::erase
bool erase(const KeyT &Val)
Definition: DenseMap.h:302
llvm::ConstantInt::getLimitedValue
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:242
llvm::DenseMapBase::begin
iterator begin()
Definition: DenseMap.h:74
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::Twine::isTriviallyEmpty
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
DenseMap.h
Module.h
llvm::MaybeAlign::valueOrOne
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition: Alignment.h:134
llvm::Value::stripAndAccumulateConstantOffsets
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
Accumulate the constant offset this value has compared to a base pointer.
llvm::Use::getOperandNo
unsigned getOperandNo() const
Return the operand # of this use in its User.
Definition: Use.cpp:33
llvm::ValueHandleBase::getValPtr
Value * getValPtr() const
Definition: ValueHandle.h:99
llvm::ValueHandleBase::WeakTracking
@ WeakTracking
Definition: ValueHandle.h:37
llvm::Value::hasOneUser
bool hasOneUser() const
Return true if there is exactly one user of this value.
Definition: Value.cpp:154
llvm::DenseMapBase::isPointerIntoBucketsArray
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap's...
Definition: DenseMap.h:348
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
Operator.h
llvm::Value::user_begin
user_iterator user_begin()
Definition: Value.h:398
DerivedUser.h
llvm::LLVMContextImpl::ValueNames
DenseMap< const Value *, ValueName * > ValueNames
Definition: LLVMContextImpl.h:1380
llvm::Value::dropDroppableUses
void dropDroppableUses(llvm::function_ref< bool(const Use *)> ShouldDrop=[](const Use *) { return true;})
Remove every uses that can safely be removed.
Definition: Value.cpp:184
llvm::DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
contains
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:452
F
#define F(x, y, z)
Definition: MD5.cpp:56
UseDerefAtPointSemantics
static cl::opt< unsigned > UseDerefAtPointSemantics("use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false), cl::desc("Deref attributes and metadata infer facts at definition only"))
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::lltok::equal
@ equal
Definition: LLToken.h:25
llvm::Value::isSwiftError
bool isSwiftError() const
Return true if this value is a swifterror value.
Definition: Value.cpp:986
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
CommandLine.h
llvm::Value::reverseUseList
void reverseUseList()
Reverse the use-list.
Definition: Value.cpp:967
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:77
llvm::Value::HasName
unsigned HasName
Definition: Value.h:119
Constants.h
llvm::Value::use_iterator
use_iterator_impl< Use > use_iterator
Definition: Value.h:354
llvm::LLVMContextImpl::ValueHandles
ValueHandlesTy ValueHandles
Definition: LLVMContextImpl.h:1457
SmallString.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::User
Definition: User.h:44
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::LLVMContextImpl
Definition: LLVMContextImpl.h:1324
llvm::Value::getSingleUndroppableUse
Use * getSingleUndroppableUse()
Return true if there is exactly one use of this value that cannot be dropped.
Definition: Value.cpp:164
InstrTypes.h
llvm::Value::assertModuleIsMaterializedImpl
void assertModuleIsMaterializedImpl() const
Definition: Value.cpp:439
llvm::ConstantExpr::getPtrToInt
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2192
IP
Definition: NVPTXLowerArgs.cpp:166
llvm::Value::uses
iterator_range< use_iterator > uses()
Definition: Value.h:377
false
Definition: StackSlotColoring.cpp:142
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
llvm::Value::getValueID
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:529
llvm::Instruction
Definition: Instruction.h:45
LLVMContextImpl.h
llvm::Operator::getOpcode
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition: Operator.h:40
llvm::Value::setName
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:361
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1783
llvm::Use::getUser
User * getUser() const
Returns the User that contains this Use.
Definition: Use.h:73
llvm::hasNItemsOrMore
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)>>::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
Definition: STLExtras.h:1960
llvm::CallBase::BundleOpInfo
Used to keep track of an operand bundle.
Definition: InstrTypes.h:2104
llvm::DenseMapBase::getPointerIntoBucketsArray
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
Definition: DenseMap.h:355
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:153
llvm::Value::isTransitiveUsedByMetadataOnly
bool isTransitiveUsedByMetadataOnly() const
Definition: Value.cpp:996
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:345
llvm::SmallString< 256 >
llvm::Value::dropDroppableUsesIn
void dropDroppableUsesIn(User &Usr)
Remove every use of this value in User that can safely be removed.
Definition: Value.cpp:194
llvm::ValueHandleBase::ValueIsRAUWd
static void ValueIsRAUWd(Value *Old, Value *New)
Definition: Value.cpp:1166
ValueSymbolTable.h
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
llvm::Value::user_end
user_iterator user_end()
Definition: Value.h:406
llvm::Value::stripPointerCastsSameRepresentation
const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
Definition: Value.cpp:670
llvm::Value::Value
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:53
llvm::Value::hasNUndroppableUsesOrMore
bool hasNUndroppableUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
Definition: Value.cpp:180
llvm::Use::set
void set(Value *Val)
Definition: Value.h:860
llvm::cl::opt
Definition: CommandLine.h:1422
llvm::AttributeList::ReturnIndex
@ ReturnIndex
Definition: Attributes.h:388
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:179
llvm::ValueHandleBase::Assert
@ Assert
Definition: ValueHandle.h:37
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::Value::getNameOrAsOperand
std::string getNameOrAsOperand() const
Definition: Value.cpp:428
llvm::Value::getPointerDereferenceableBytes
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull, bool &CanBeFreed) const
Returns the number of bytes known to be dereferenceable for the pointer value.
Definition: Value.cpp:817
llvm::ValueHandleBase::RemoveFromUseList
void RemoveFromUseList()
Remove this ValueHandle from its current use list.
Definition: Value.cpp:1087
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:572
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::Value::hasNUsesOrMore
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
Definition: Value.cpp:150
llvm::Value::materialized_use_empty
bool materialized_use_empty() const
Definition: Value.h:350
llvm::DenseMap< Value *, ValueHandleBase * >
DebugInfo.h
llvm::StringMapEntryStorage::setValue
void setValue(const ValueTy &V)
Definition: StringMapEntry.h:82
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::ValueHandleBase::Weak
@ Weak
Definition: ValueHandle.h:37
llvm::is_contained
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:1547
llvm::Value::getValueName
ValueName * getValueName() const
Definition: Value.cpp:266
llvm::Value::replaceNonMetadataUsesWith
void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
Definition: Value.cpp:521
llvm::StringMapEntry::getKey
StringRef getKey() const
Definition: StringMapEntry.h:102
llvm::Value::MaximumAlignment
static const unsigned MaximumAlignment
Definition: Value.h:785
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::Value::setValueName
void setValueName(ValueName *VN)
Definition: Value.cpp:277
llvm::elfabi::ELFSymbolType::Func
@ Func
llvm::Value::replaceUsesOutsideBlock
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:561
llvm::Value::stripPointerCastsForAliasAnalysis
const Value * stripPointerCastsForAliasAnalysis() const
Strip off pointer casts, all-zero GEPs, single-argument phi nodes and invariant group info.
Definition: Value.cpp:678
llvm::Value::use_begin
use_iterator use_begin()
Definition: Value.h:361
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
llvm::Value::clearMetadata
void clearMetadata()
Erase all metadata attached to this Value.
Definition: Metadata.cpp:1285
llvm::SmallPtrSetImpl::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:382
llvm::User::isDroppable
bool isDroppable() const
A droppable user is a user for which uses can be dropped without affecting correctness and should be ...
Definition: User.cpp:109
llvm::Value::printAsOperand
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Definition: AsmWriter.cpp:4700
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:70
llvm::ValueHandleBase::ValueIsDeleted
static void ValueIsDeleted(Value *V)
Definition: Value.cpp:1113
DataLayout.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::Value::getNumUses
unsigned getNumUses() const
This method computes the number of uses of this Value.
Definition: Value.cpp:240
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:517
llvm::ms_demangle::IntrinsicFunctionKind::New
@ New
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:965
llvm::Value::use_end
use_iterator use_end()
Definition: Value.h:369
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::Type::isPtrOrPtrVectorTy
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:232
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:281
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:294
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:174
ValueHandle.h
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:662
llvm::Value::stripInBoundsOffsets
const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
Definition: Value.cpp:751
llvm::Value::HasMetadata
unsigned HasMetadata
Definition: Value.h:120
Constant.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:931
llvm::empty
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition: STLExtras.h:254
llvm::ConstantInt::getTrue
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:846
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
isUnDroppableUser
static bool isUnDroppableUser(const User *U)
Definition: Value.cpp:162
llvm::MallocAllocator
Definition: AllocatorBase.h:80
llvm::Value::hasNUndroppableUses
bool hasNUndroppableUses(unsigned N) const
Return true if there this value.
Definition: Value.cpp:176
llvm::Value::~Value
~Value()
Value's destructor should be virtual by design, but that would require that Value and all of its subc...
Definition: Value.cpp:73
llvm::DenseMapBase::end
iterator end()
Definition: DenseMap.h:83
replaceDbgUsesOutsideBlock
static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB)
Replace llvm.dbg.
Definition: Value.cpp:550
llvm::APInt::sextOrTrunc
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:960
llvm::Value::MaxAlignmentExponent
static const unsigned MaxAlignmentExponent
The maximum alignment for instructions.
Definition: Value.h:784
NodeList::Next
NodeList * Next
Definition: MicrosoftDemangle.cpp:39
llvm::Value::hasNUses
bool hasNUses(unsigned N) const
Return true if this Value has exactly N uses.
Definition: Value.cpp:146
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
llvm::DenseMapBase::size
unsigned size() const
Definition: DenseMap.h:100
llvm::CallbackVH
Value handle with callbacks on RAUW and destruction.
Definition: ValueHandle.h:383
llvm::ValueAsMetadata::handleRAUW
static void handleRAUW(Value *From, Value *To)
Definition: Metadata.cpp:405
llvm::Value::canBeFreed
bool canBeFreed() const
Return true if the memory object referred to by V can by freed in the scope for which the SSA value d...
Definition: Value.cpp:755
Instructions.h
llvm::Type::isStructTy
bool isStructTy() const
True if this is an instance of StructType.
Definition: Type.h:223
llvm::ValueSymbolTable
This class provides a symbol table of name/value pairs.
Definition: ValueSymbolTable.h:37
llvm::Value::isUsedByMetadata
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
Definition: Value.h:554
llvm::Value::stripInBoundsConstantOffsets
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
Definition: Value.cpp:674
llvm::Value::DoPHITranslation
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
Definition: Value.cpp:957
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
getSymTab
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
Definition: Value.cpp:244
List
const NodeList & List
Definition: RDFGraph.cpp:201
N
#define N
llvm::Value::deleteValue
void deleteValue()
Delete a pointer to a generic Value.
Definition: Value.cpp:107
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
DerivedTypes.h
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
llvm::Twine::toStringRef
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
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
GEP
Hexagon Common GEP
Definition: HexagonCommonGEP.cpp:171
llvm::StringRef::find_first_of
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:410
llvm::Value::replaceUsesWithIf
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.cpp:525
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:367
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:61
llvm::cl::desc
Definition: CommandLine.h:414
raw_ostream.h
Value.h
llvm::raw_string_ostream::str
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:632
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
Debug.h
llvm::Value::users
iterator_range< user_iterator > users()
Definition: Value.h:422
SetVector.h
llvm::BasicBlock::const_iterator
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:91
llvm::Type::isFirstClassType
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
Definition: Type.h:251
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:44
llvm::SmallPtrSetImpl::insert
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:364
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:772