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