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