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