LLVM  16.0.0git
Instruction.cpp
Go to the documentation of this file.
1 //===-- Instruction.cpp - Implement the Instruction 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 Instruction class for the IR library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/IR/Instruction.h"
14 #include "llvm/ADT/DenseSet.h"
15 #include "llvm/IR/Constants.h"
16 #include "llvm/IR/Instructions.h"
17 #include "llvm/IR/IntrinsicInst.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/IR/Operator.h"
20 #include "llvm/IR/Type.h"
21 using namespace llvm;
22 
23 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
24  Instruction *InsertBefore)
25  : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
26 
27  // If requested, insert this instruction into a basic block...
28  if (InsertBefore) {
29  BasicBlock *BB = InsertBefore->getParent();
30  assert(BB && "Instruction to insert before is not in a basic block!");
31  BB->getInstList().insert(InsertBefore->getIterator(), this);
32  }
33 }
34 
35 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
36  BasicBlock *InsertAtEnd)
37  : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
38 
39  // append this instruction into the basic block
40  assert(InsertAtEnd && "Basic block to append to may not be NULL!");
41  InsertAtEnd->getInstList().push_back(this);
42 }
43 
45  assert(!Parent && "Instruction still linked in the program!");
46 
47  // Replace any extant metadata uses of this instruction with undef to
48  // preserve debug info accuracy. Some alternatives include:
49  // - Treat Instruction like any other Value, and point its extant metadata
50  // uses to an empty ValueAsMetadata node. This makes extant dbg.value uses
51  // trivially dead (i.e. fair game for deletion in many passes), leading to
52  // stale dbg.values being in effect for too long.
53  // - Call salvageDebugInfoOrMarkUndef. Not needed to make instruction removal
54  // correct. OTOH results in wasted work in some common cases (e.g. when all
55  // instructions in a BasicBlock are deleted).
56  if (isUsedByMetadata())
58 }
59 
60 
61 void Instruction::setParent(BasicBlock *P) {
62  Parent = P;
63 }
64 
66  return getParent()->getModule();
67 }
68 
70  return getParent()->getParent();
71 }
72 
74  getParent()->getInstList().remove(getIterator());
75 }
76 
78  return getParent()->getInstList().erase(getIterator());
79 }
80 
81 /// Insert an unlinked instruction into a basic block immediately before the
82 /// specified instruction.
84  InsertPos->getParent()->getInstList().insert(InsertPos->getIterator(), this);
85 }
86 
87 /// Insert an unlinked instruction into a basic block immediately after the
88 /// specified instruction.
90  InsertPos->getParent()->getInstList().insertAfter(InsertPos->getIterator(),
91  this);
92 }
93 
94 /// Unlink this instruction from its current basic block and insert it into the
95 /// basic block that MovePos lives in, right before MovePos.
97  moveBefore(*MovePos->getParent(), MovePos->getIterator());
98 }
99 
101  moveBefore(*MovePos->getParent(), ++MovePos->getIterator());
102 }
103 
106  assert(I == BB.end() || I->getParent() == &BB);
107  BB.getInstList().splice(I, getParent()->getInstList(), getIterator());
108 }
109 
110 bool Instruction::comesBefore(const Instruction *Other) const {
111  assert(Parent && Other->Parent &&
112  "instructions without BB parents have no order");
113  assert(Parent == Other->Parent && "cross-BB instruction order comparison");
114  if (!Parent->isInstrOrderValid())
115  Parent->renumberInstructions();
116  return Order < Other->Order;
117 }
118 
120  assert(!getType()->isVoidTy() && "Instruction must define result");
121  BasicBlock *InsertBB;
122  BasicBlock::iterator InsertPt;
123  if (auto *PN = dyn_cast<PHINode>(this)) {
124  InsertBB = PN->getParent();
125  InsertPt = InsertBB->getFirstInsertionPt();
126  } else if (auto *II = dyn_cast<InvokeInst>(this)) {
127  InsertBB = II->getNormalDest();
128  InsertPt = InsertBB->getFirstInsertionPt();
129  } else if (auto *CB = dyn_cast<CallBrInst>(this)) {
130  InsertBB = CB->getDefaultDest();
131  InsertPt = InsertBB->getFirstInsertionPt();
132  } else {
133  assert(!isTerminator() && "Only invoke/callbr terminators return value");
134  InsertBB = getParent();
135  InsertPt = std::next(getIterator());
136  }
137 
138  // catchswitch blocks don't have any legal insertion point (because they
139  // are both an exception pad and a terminator).
140  if (InsertPt == InsertBB->end())
141  return nullptr;
142  return &*InsertPt;
143 }
144 
146  return any_of(operands(), [](Value *V) { return V->hasOneUser(); });
147 }
148 
150  cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(b);
151 }
152 
154  cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(b);
155 }
156 
158  cast<PossiblyExactOperator>(this)->setIsExact(b);
159 }
160 
162  return cast<OverflowingBinaryOperator>(this)->hasNoUnsignedWrap();
163 }
164 
166  return cast<OverflowingBinaryOperator>(this)->hasNoSignedWrap();
167 }
168 
170  return cast<Operator>(this)->hasPoisonGeneratingFlags();
171 }
172 
174  switch (getOpcode()) {
175  case Instruction::Add:
176  case Instruction::Sub:
177  case Instruction::Mul:
178  case Instruction::Shl:
179  cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(false);
180  cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(false);
181  break;
182 
183  case Instruction::UDiv:
184  case Instruction::SDiv:
185  case Instruction::AShr:
186  case Instruction::LShr:
187  cast<PossiblyExactOperator>(this)->setIsExact(false);
188  break;
189 
190  case Instruction::GetElementPtr:
191  cast<GetElementPtrInst>(this)->setIsInBounds(false);
192  break;
193  }
194  if (isa<FPMathOperator>(this)) {
195  setHasNoNaNs(false);
196  setHasNoInfs(false);
197  }
198 
199  assert(!hasPoisonGeneratingFlags() && "must be kept in sync");
200 }
201 
203  ArrayRef<unsigned> KnownIDs) {
204  dropUnknownNonDebugMetadata(KnownIDs);
205  auto *CB = dyn_cast<CallBase>(this);
206  if (!CB)
207  return;
208  // For call instructions, we also need to drop parameter and return attributes
209  // that are can cause UB if the call is moved to a location where the
210  // attribute is not valid.
211  AttributeList AL = CB->getAttributes();
212  if (AL.isEmpty())
213  return;
214  AttributeMask UBImplyingAttributes =
216  for (unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
217  CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
218  CB->removeRetAttrs(UBImplyingAttributes);
219 }
220 
221 bool Instruction::isExact() const {
222  return cast<PossiblyExactOperator>(this)->isExact();
223 }
224 
226  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
227  cast<FPMathOperator>(this)->setFast(B);
228 }
229 
231  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
232  cast<FPMathOperator>(this)->setHasAllowReassoc(B);
233 }
234 
236  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
237  cast<FPMathOperator>(this)->setHasNoNaNs(B);
238 }
239 
241  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
242  cast<FPMathOperator>(this)->setHasNoInfs(B);
243 }
244 
246  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
247  cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
248 }
249 
251  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
252  cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
253 }
254 
256  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
257  cast<FPMathOperator>(this)->setHasAllowContract(B);
258 }
259 
261  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
262  cast<FPMathOperator>(this)->setHasApproxFunc(B);
263 }
264 
266  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
267  cast<FPMathOperator>(this)->setFastMathFlags(FMF);
268 }
269 
271  assert(isa<FPMathOperator>(this) && "copying fast-math flag on invalid op");
272  cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
273 }
274 
275 bool Instruction::isFast() const {
276  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
277  return cast<FPMathOperator>(this)->isFast();
278 }
279 
281  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
282  return cast<FPMathOperator>(this)->hasAllowReassoc();
283 }
284 
286  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
287  return cast<FPMathOperator>(this)->hasNoNaNs();
288 }
289 
291  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
292  return cast<FPMathOperator>(this)->hasNoInfs();
293 }
294 
296  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
297  return cast<FPMathOperator>(this)->hasNoSignedZeros();
298 }
299 
301  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
302  return cast<FPMathOperator>(this)->hasAllowReciprocal();
303 }
304 
306  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
307  return cast<FPMathOperator>(this)->hasAllowContract();
308 }
309 
311  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
312  return cast<FPMathOperator>(this)->hasApproxFunc();
313 }
314 
316  assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
317  return cast<FPMathOperator>(this)->getFastMathFlags();
318 }
319 
321  copyFastMathFlags(I->getFastMathFlags());
322 }
323 
324 void Instruction::copyIRFlags(const Value *V, bool IncludeWrapFlags) {
325  // Copy the wrapping flags.
326  if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(this)) {
327  if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
328  setHasNoSignedWrap(OB->hasNoSignedWrap());
329  setHasNoUnsignedWrap(OB->hasNoUnsignedWrap());
330  }
331  }
332 
333  // Copy the exact flag.
334  if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
335  if (isa<PossiblyExactOperator>(this))
336  setIsExact(PE->isExact());
337 
338  // Copy the fast-math flags.
339  if (auto *FP = dyn_cast<FPMathOperator>(V))
340  if (isa<FPMathOperator>(this))
341  copyFastMathFlags(FP->getFastMathFlags());
342 
343  if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
344  if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
345  DestGEP->setIsInBounds(SrcGEP->isInBounds() || DestGEP->isInBounds());
346 }
347 
349  if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
350  if (isa<OverflowingBinaryOperator>(this)) {
351  setHasNoSignedWrap(hasNoSignedWrap() && OB->hasNoSignedWrap());
352  setHasNoUnsignedWrap(hasNoUnsignedWrap() && OB->hasNoUnsignedWrap());
353  }
354  }
355 
356  if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
357  if (isa<PossiblyExactOperator>(this))
358  setIsExact(isExact() && PE->isExact());
359 
360  if (auto *FP = dyn_cast<FPMathOperator>(V)) {
361  if (isa<FPMathOperator>(this)) {
363  FM &= FP->getFastMathFlags();
364  copyFastMathFlags(FM);
365  }
366  }
367 
368  if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
369  if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
370  DestGEP->setIsInBounds(SrcGEP->isInBounds() && DestGEP->isInBounds());
371 }
372 
373 const char *Instruction::getOpcodeName(unsigned OpCode) {
374  switch (OpCode) {
375  // Terminators
376  case Ret: return "ret";
377  case Br: return "br";
378  case Switch: return "switch";
379  case IndirectBr: return "indirectbr";
380  case Invoke: return "invoke";
381  case Resume: return "resume";
382  case Unreachable: return "unreachable";
383  case CleanupRet: return "cleanupret";
384  case CatchRet: return "catchret";
385  case CatchPad: return "catchpad";
386  case CatchSwitch: return "catchswitch";
387  case CallBr: return "callbr";
388 
389  // Standard unary operators...
390  case FNeg: return "fneg";
391 
392  // Standard binary operators...
393  case Add: return "add";
394  case FAdd: return "fadd";
395  case Sub: return "sub";
396  case FSub: return "fsub";
397  case Mul: return "mul";
398  case FMul: return "fmul";
399  case UDiv: return "udiv";
400  case SDiv: return "sdiv";
401  case FDiv: return "fdiv";
402  case URem: return "urem";
403  case SRem: return "srem";
404  case FRem: return "frem";
405 
406  // Logical operators...
407  case And: return "and";
408  case Or : return "or";
409  case Xor: return "xor";
410 
411  // Memory instructions...
412  case Alloca: return "alloca";
413  case Load: return "load";
414  case Store: return "store";
415  case AtomicCmpXchg: return "cmpxchg";
416  case AtomicRMW: return "atomicrmw";
417  case Fence: return "fence";
418  case GetElementPtr: return "getelementptr";
419 
420  // Convert instructions...
421  case Trunc: return "trunc";
422  case ZExt: return "zext";
423  case SExt: return "sext";
424  case FPTrunc: return "fptrunc";
425  case FPExt: return "fpext";
426  case FPToUI: return "fptoui";
427  case FPToSI: return "fptosi";
428  case UIToFP: return "uitofp";
429  case SIToFP: return "sitofp";
430  case IntToPtr: return "inttoptr";
431  case PtrToInt: return "ptrtoint";
432  case BitCast: return "bitcast";
433  case AddrSpaceCast: return "addrspacecast";
434 
435  // Other instructions...
436  case ICmp: return "icmp";
437  case FCmp: return "fcmp";
438  case PHI: return "phi";
439  case Select: return "select";
440  case Call: return "call";
441  case Shl: return "shl";
442  case LShr: return "lshr";
443  case AShr: return "ashr";
444  case VAArg: return "va_arg";
445  case ExtractElement: return "extractelement";
446  case InsertElement: return "insertelement";
447  case ShuffleVector: return "shufflevector";
448  case ExtractValue: return "extractvalue";
449  case InsertValue: return "insertvalue";
450  case LandingPad: return "landingpad";
451  case CleanupPad: return "cleanuppad";
452  case Freeze: return "freeze";
453 
454  default: return "<Invalid operator> ";
455  }
456 }
457 
458 /// Return true if both instructions have the same special state. This must be
459 /// kept in sync with FunctionComparator::cmpOperations in
460 /// lib/Transforms/IPO/MergeFunctions.cpp.
461 static bool haveSameSpecialState(const Instruction *I1, const Instruction *I2,
462  bool IgnoreAlignment = false) {
463  assert(I1->getOpcode() == I2->getOpcode() &&
464  "Can not compare special state of different instructions");
465 
466  if (const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
467  return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
468  (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
469  IgnoreAlignment);
470  if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
471  return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
472  (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
473  IgnoreAlignment) &&
474  LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
475  LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
476  if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
477  return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
478  (SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
479  IgnoreAlignment) &&
480  SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
481  SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
482  if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
483  return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
484  if (const CallInst *CI = dyn_cast<CallInst>(I1))
485  return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
486  CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
487  CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
488  CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
489  if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
490  return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
491  CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
492  CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
493  if (const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
494  return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
495  CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
496  CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
497  if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
498  return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
499  if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
500  return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
501  if (const FenceInst *FI = dyn_cast<FenceInst>(I1))
502  return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
503  FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
504  if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I1))
505  return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
506  CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
507  CXI->getSuccessOrdering() ==
508  cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
509  CXI->getFailureOrdering() ==
510  cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
511  CXI->getSyncScopeID() ==
512  cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
513  if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
514  return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
515  RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
516  RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
517  RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
518  if (const ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(I1))
519  return SVI->getShuffleMask() ==
520  cast<ShuffleVectorInst>(I2)->getShuffleMask();
521  if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I1))
522  return GEP->getSourceElementType() ==
523  cast<GetElementPtrInst>(I2)->getSourceElementType();
524 
525  return true;
526 }
527 
529  return isIdenticalToWhenDefined(I) &&
530  SubclassOptionalData == I->SubclassOptionalData;
531 }
532 
534  if (getOpcode() != I->getOpcode() ||
535  getNumOperands() != I->getNumOperands() ||
536  getType() != I->getType())
537  return false;
538 
539  // If both instructions have no operands, they are identical.
540  if (getNumOperands() == 0 && I->getNumOperands() == 0)
541  return haveSameSpecialState(this, I);
542 
543  // We have two instructions of identical opcode and #operands. Check to see
544  // if all operands are the same.
545  if (!std::equal(op_begin(), op_end(), I->op_begin()))
546  return false;
547 
548  // WARNING: this logic must be kept in sync with EliminateDuplicatePHINodes()!
549  if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
550  const PHINode *otherPHI = cast<PHINode>(I);
551  return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
552  otherPHI->block_begin());
553  }
554 
555  return haveSameSpecialState(this, I);
556 }
557 
558 // Keep this in sync with FunctionComparator::cmpOperations in
559 // lib/Transforms/IPO/MergeFunctions.cpp.
561  unsigned flags) const {
562  bool IgnoreAlignment = flags & CompareIgnoringAlignment;
563  bool UseScalarTypes = flags & CompareUsingScalarTypes;
564 
565  if (getOpcode() != I->getOpcode() ||
566  getNumOperands() != I->getNumOperands() ||
567  (UseScalarTypes ?
568  getType()->getScalarType() != I->getType()->getScalarType() :
569  getType() != I->getType()))
570  return false;
571 
572  // We have two instructions of identical opcode and #operands. Check to see
573  // if all operands are the same type
574  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
575  if (UseScalarTypes ?
576  getOperand(i)->getType()->getScalarType() !=
577  I->getOperand(i)->getType()->getScalarType() :
578  getOperand(i)->getType() != I->getOperand(i)->getType())
579  return false;
580 
581  return haveSameSpecialState(this, I, IgnoreAlignment);
582 }
583 
585  for (const Use &U : uses()) {
586  // PHI nodes uses values in the corresponding predecessor block. For other
587  // instructions, just check to see whether the parent of the use matches up.
588  const Instruction *I = cast<Instruction>(U.getUser());
589  const PHINode *PN = dyn_cast<PHINode>(I);
590  if (!PN) {
591  if (I->getParent() != BB)
592  return true;
593  continue;
594  }
595 
596  if (PN->getIncomingBlock(U) != BB)
597  return true;
598  }
599  return false;
600 }
601 
603  switch (getOpcode()) {
604  default: return false;
605  case Instruction::VAArg:
606  case Instruction::Load:
607  case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
608  case Instruction::AtomicCmpXchg:
609  case Instruction::AtomicRMW:
610  case Instruction::CatchPad:
611  case Instruction::CatchRet:
612  return true;
613  case Instruction::Call:
614  case Instruction::Invoke:
615  case Instruction::CallBr:
616  return !cast<CallBase>(this)->onlyWritesMemory();
617  case Instruction::Store:
618  return !cast<StoreInst>(this)->isUnordered();
619  }
620 }
621 
623  switch (getOpcode()) {
624  default: return false;
625  case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
626  case Instruction::Store:
627  case Instruction::VAArg:
628  case Instruction::AtomicCmpXchg:
629  case Instruction::AtomicRMW:
630  case Instruction::CatchPad:
631  case Instruction::CatchRet:
632  return true;
633  case Instruction::Call:
634  case Instruction::Invoke:
635  case Instruction::CallBr:
636  return !cast<CallBase>(this)->onlyReadsMemory();
637  case Instruction::Load:
638  return !cast<LoadInst>(this)->isUnordered();
639  }
640 }
641 
642 bool Instruction::isAtomic() const {
643  switch (getOpcode()) {
644  default:
645  return false;
646  case Instruction::AtomicCmpXchg:
647  case Instruction::AtomicRMW:
648  case Instruction::Fence:
649  return true;
650  case Instruction::Load:
651  return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
652  case Instruction::Store:
653  return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
654  }
655 }
656 
658  assert(isAtomic());
659  switch (getOpcode()) {
660  default:
661  return false;
662  case Instruction::AtomicCmpXchg:
663  case Instruction::AtomicRMW:
664  case Instruction::Load:
665  return true;
666  }
667 }
668 
670  assert(isAtomic());
671  switch (getOpcode()) {
672  default:
673  return false;
674  case Instruction::AtomicCmpXchg:
675  case Instruction::AtomicRMW:
676  case Instruction::Store:
677  return true;
678  }
679 }
680 
682  switch (getOpcode()) {
683  default:
684  return false;
685  case Instruction::AtomicRMW:
686  return cast<AtomicRMWInst>(this)->isVolatile();
687  case Instruction::Store:
688  return cast<StoreInst>(this)->isVolatile();
689  case Instruction::Load:
690  return cast<LoadInst>(this)->isVolatile();
691  case Instruction::AtomicCmpXchg:
692  return cast<AtomicCmpXchgInst>(this)->isVolatile();
693  case Instruction::Call:
694  case Instruction::Invoke:
695  // There are a very limited number of intrinsics with volatile flags.
696  if (auto *II = dyn_cast<IntrinsicInst>(this)) {
697  if (auto *MI = dyn_cast<MemIntrinsic>(II))
698  return MI->isVolatile();
699  switch (II->getIntrinsicID()) {
700  default: break;
701  case Intrinsic::matrix_column_major_load:
702  return cast<ConstantInt>(II->getArgOperand(2))->isOne();
703  case Intrinsic::matrix_column_major_store:
704  return cast<ConstantInt>(II->getArgOperand(3))->isOne();
705  }
706  }
707  return false;
708  }
709 }
710 
711 bool Instruction::mayThrow() const {
712  if (const CallInst *CI = dyn_cast<CallInst>(this))
713  return !CI->doesNotThrow();
714  if (const auto *CRI = dyn_cast<CleanupReturnInst>(this))
715  return CRI->unwindsToCaller();
716  if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(this))
717  return CatchSwitch->unwindsToCaller();
718  return isa<ResumeInst>(this);
719 }
720 
722  return mayWriteToMemory() || mayThrow() || !willReturn();
723 }
724 
726  return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
727  !this->isTerminator() && !this->isEHPad();
728 }
729 
731  // Volatile store isn't guaranteed to return; see LangRef.
732  if (auto *SI = dyn_cast<StoreInst>(this))
733  return !SI->isVolatile();
734 
735  if (const auto *CB = dyn_cast<CallBase>(this))
736  // FIXME: Temporarily assume that all side-effect free intrinsics will
737  // return. Remove this workaround once all intrinsics are appropriately
738  // annotated.
739  return CB->hasFnAttr(Attribute::WillReturn) ||
740  (isa<IntrinsicInst>(CB) && CB->onlyReadsMemory());
741  return true;
742 }
743 
745  auto *II = dyn_cast<IntrinsicInst>(this);
746  if (!II)
747  return false;
748  Intrinsic::ID ID = II->getIntrinsicID();
749  return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end;
750 }
751 
753  auto *II = dyn_cast<IntrinsicInst>(this);
754  if (!II)
755  return false;
756  Intrinsic::ID ID = II->getIntrinsicID();
757  return ID == Intrinsic::launder_invariant_group ||
758  ID == Intrinsic::strip_invariant_group;
759 }
760 
762  return isa<DbgInfoIntrinsic>(this) || isa<PseudoProbeInst>(this);
763 }
764 
765 const Instruction *
766 Instruction::getNextNonDebugInstruction(bool SkipPseudoOp) const {
767  for (const Instruction *I = getNextNode(); I; I = I->getNextNode())
768  if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
769  return I;
770  return nullptr;
771 }
772 
773 const Instruction *
774 Instruction::getPrevNonDebugInstruction(bool SkipPseudoOp) const {
775  for (const Instruction *I = getPrevNode(); I; I = I->getPrevNode())
776  if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
777  return I;
778  return nullptr;
779 }
780 
782  unsigned Opcode = getOpcode();
783  if (isAssociative(Opcode))
784  return true;
785 
786  switch (Opcode) {
787  case FMul:
788  case FAdd:
789  return cast<FPMathOperator>(this)->hasAllowReassoc() &&
790  cast<FPMathOperator>(this)->hasNoSignedZeros();
791  default:
792  return false;
793  }
794 }
795 
797  if (auto *II = dyn_cast<IntrinsicInst>(this))
798  return II->isCommutative();
799  // TODO: Should allow icmp/fcmp?
800  return isCommutative(getOpcode());
801 }
802 
804  switch (getOpcode()) {
805 #define HANDLE_TERM_INST(N, OPC, CLASS) \
806  case Instruction::OPC: \
807  return static_cast<const CLASS *>(this)->getNumSuccessors();
808 #include "llvm/IR/Instruction.def"
809  default:
810  break;
811  }
812  llvm_unreachable("not a terminator");
813 }
814 
815 BasicBlock *Instruction::getSuccessor(unsigned idx) const {
816  switch (getOpcode()) {
817 #define HANDLE_TERM_INST(N, OPC, CLASS) \
818  case Instruction::OPC: \
819  return static_cast<const CLASS *>(this)->getSuccessor(idx);
820 #include "llvm/IR/Instruction.def"
821  default:
822  break;
823  }
824  llvm_unreachable("not a terminator");
825 }
826 
827 void Instruction::setSuccessor(unsigned idx, BasicBlock *B) {
828  switch (getOpcode()) {
829 #define HANDLE_TERM_INST(N, OPC, CLASS) \
830  case Instruction::OPC: \
831  return static_cast<CLASS *>(this)->setSuccessor(idx, B);
832 #include "llvm/IR/Instruction.def"
833  default:
834  break;
835  }
836  llvm_unreachable("not a terminator");
837 }
838 
840  for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
841  Idx != NumSuccessors; ++Idx)
842  if (getSuccessor(Idx) == OldBB)
843  setSuccessor(Idx, NewBB);
844 }
845 
846 Instruction *Instruction::cloneImpl() const {
847  llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
848 }
849 
851  MDNode *ProfileData = getMetadata(LLVMContext::MD_prof);
852  if (!ProfileData || ProfileData->getNumOperands() != 3 ||
853  !isa<MDString>(ProfileData->getOperand(0)))
854  return;
855 
856  MDString *MDName = cast<MDString>(ProfileData->getOperand(0));
857  if (MDName->getString() != "branch_weights")
858  return;
859 
860  // The first operand is the name. Fetch them backwards and build a new one.
861  Metadata *Ops[] = {ProfileData->getOperand(0), ProfileData->getOperand(2),
862  ProfileData->getOperand(1)};
863  setMetadata(LLVMContext::MD_prof,
864  MDNode::get(ProfileData->getContext(), Ops));
865 }
866 
868  ArrayRef<unsigned> WL) {
869  if (!SrcInst.hasMetadata())
870  return;
871 
873  for (unsigned M : WL)
874  WLS.insert(M);
875 
876  // Otherwise, enumerate and copy over metadata from the old instruction to the
877  // new one.
879  SrcInst.getAllMetadataOtherThanDebugLoc(TheMDs);
880  for (const auto &MD : TheMDs) {
881  if (WL.empty() || WLS.count(MD.first))
882  setMetadata(MD.first, MD.second);
883  }
884  if (WL.empty() || WLS.count(LLVMContext::MD_dbg))
885  setDebugLoc(SrcInst.getDebugLoc());
886 }
887 
889  Instruction *New = nullptr;
890  switch (getOpcode()) {
891  default:
892  llvm_unreachable("Unhandled Opcode.");
893 #define HANDLE_INST(num, opc, clas) \
894  case Instruction::opc: \
895  New = cast<clas>(this)->cloneImpl(); \
896  break;
897 #include "llvm/IR/Instruction.def"
898 #undef HANDLE_INST
899  }
900 
901  New->SubclassOptionalData = SubclassOptionalData;
902  New->copyMetadata(*this);
903  return New;
904 }
llvm::Instruction::getPrevNonDebugInstruction
const Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the previous non-debug instruction in the same basic block as 'this',...
Definition: Instruction.cpp:774
i
i
Definition: README.txt:29
llvm::Instruction::isTerminator
bool isTerminator() const
Definition: Instruction.h:167
CmpMode::FP
@ FP
llvm::BasicBlock::end
iterator end()
Definition: BasicBlock.h:308
llvm::Instruction::isAssociative
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
Definition: Instruction.cpp:781
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:108
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Instruction::replaceSuccessorWith
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
Definition: Instruction.cpp:839
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::Instruction::getModule
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:65
llvm::AArch64CC::AL
@ AL
Definition: AArch64BaseInfo.h:269
it
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in it
Definition: README-SSE.txt:81
llvm::RecurKind::Or
@ Or
Bitwise or logical OR of integers.
llvm::Instruction::getInsertionPointAfterDef
Instruction * getInsertionPointAfterDef()
Get the first insertion point at which the result of this instruction is defined.
Definition: Instruction.cpp:119
llvm::RecurKind::FMul
@ FMul
Product of floats.
llvm::User::operands
op_range operands()
Definition: User.h:242
llvm::BasicBlock::iterator
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:87
llvm::Value::SubclassOptionalData
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:90
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:104
IntrinsicInst.h
llvm::Instruction::getNextNonDebugInstruction
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
Definition: Instruction.cpp:766
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::Instruction::isVolatile
bool isVolatile() const
Return true if this instruction has a volatile memory access.
Definition: Instruction.cpp:681
llvm::ARMISD::WLS
@ WLS
Definition: ARMISelLowering.h:135
llvm::Instruction::getAllMetadataOtherThanDebugLoc
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
Definition: Instruction.h:294
llvm::ilist_node_with_parent< Instruction, BasicBlock >::getNextNode
Instruction * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:289
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1182
llvm::Instruction::setHasAllowContract
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
Definition: Instruction.cpp:255
llvm::AttributeFuncs::getUBImplyingAttributes
AttributeMask getUBImplyingAttributes()
Get param/return attributes which imply immediate undefined behavior if an invalid value is passed.
Definition: Attributes.cpp:1860
llvm::Instruction::hasNoUnsignedWrap
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
Definition: Instruction.cpp:161
llvm::Instruction::insertBefore
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
Definition: Instruction.cpp:83
llvm::Instruction::hasAllowReciprocal
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
Definition: Instruction.cpp:300
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::AttributeList
Definition: Attributes.h:425
llvm::AttributeMask
Definition: Attributes.h:969
llvm::Instruction::hasApproxFunc
bool hasApproxFunc() const
Determine whether the approximate-math-functions flag is set.
Definition: Instruction.cpp:310
llvm::Instruction::comesBefore
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
Definition: Instruction.cpp:110
llvm::Instruction::setHasNoUnsignedWrap
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
Definition: Instruction.cpp:149
llvm::Value::hasOneUser
bool hasOneUser() const
Return true if there is exactly one user of this value.
Definition: Value.cpp:156
llvm::FenceInst
An instruction for ordering other memory operations.
Definition: Instructions.h:433
llvm::Instruction::mayThrow
bool mayThrow() const
Return true if this instruction may throw an exception.
Definition: Instruction.cpp:711
Operator.h
llvm::Instruction::copyMetadata
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Definition: Instruction.cpp:867
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::FastMathFlags
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:21
llvm::Instruction::~Instruction
~Instruction()
Definition: Instruction.cpp:44
llvm::Instruction::setIsExact
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Definition: Instruction.cpp:157
llvm::SPII::Load
@ Load
Definition: SparcInstrInfo.h:32
llvm::Instruction::dropUnknownNonDebugMetadata
void dropUnknownNonDebugMetadata()
Definition: Instruction.h:322
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1400
llvm::Instruction::mayHaveSideEffects
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
Definition: Instruction.cpp:721
llvm::Instruction::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1428
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::lltok::equal
@ equal
Definition: LLToken.h:25
llvm::MDNode::getNumOperands
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1298
llvm::X86II::OB
@ OB
Definition: X86BaseInfo.h:801
Instruction.h
llvm::Instruction::getNumSuccessors
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
Definition: Instruction.cpp:803
llvm::Instruction::insertAfter
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
Definition: Instruction.cpp:89
llvm::Instruction::getOpcode
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:164
llvm::Instruction::willReturn
bool willReturn() const
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
Definition: Instruction.cpp:730
llvm::RecurKind::And
@ And
Bitwise or logical AND of integers.
Constants.h
llvm::Instruction::setHasNoSignedWrap
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
Definition: Instruction.cpp:153
llvm::User
Definition: User.h:44
Intrinsics.h
llvm::Instruction::isIdenticalToWhenDefined
bool isIdenticalToWhenDefined(const Instruction *I) const
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
Definition: Instruction.cpp:533
b
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int b
Definition: README.txt:418
llvm::SPII::Store
@ Store
Definition: SparcInstrInfo.h:33
llvm::Value::uses
iterator_range< use_iterator > uses()
Definition: Value.h:376
DenseSet.h
llvm::BasicBlock::getFirstInsertionPt
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:246
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::Instruction::getOpcodeName
const char * getOpcodeName() const
Definition: Instruction.h:166
llvm::Instruction
Definition: Instruction.h:42
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1708
llvm::Instruction::getSuccessor
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
Definition: Instruction.cpp:815
llvm::BasicBlock::getModule
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:147
llvm::Instruction::removeFromParent
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
Definition: Instruction.cpp:73
llvm::Instruction::isSafeToRemove
bool isSafeToRemove() const
Return true if the instruction can be removed if the result is unused.
Definition: Instruction.cpp:725
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:155
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::Instruction::mayWriteToMemory
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
Definition: Instruction.cpp:622
llvm::Instruction::isLifetimeStartOrEnd
bool isLifetimeStartOrEnd() const
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
Definition: Instruction.cpp:744
llvm::Instruction::isLaunderOrStripInvariantGroup
bool isLaunderOrStripInvariantGroup() const
Return true if the instruction is a llvm.launder.invariant.group or llvm.strip.invariant....
Definition: Instruction.cpp:752
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Type.h
llvm::BasicBlock::renumberInstructions
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:520
llvm::Instruction::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:271
llvm::Instruction::isCommutative
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
Definition: Instruction.cpp:796
llvm::Instruction::setHasNoNaNs
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
Definition: Instruction.cpp:235
llvm::Instruction::hasAtomicLoad
bool hasAtomicLoad() const
Return true if this atomic instruction loads from memory.
Definition: Instruction.cpp:657
llvm::InvokeInst
Invoke instruction.
Definition: Instructions.h:3811
llvm::CmpInst
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:709
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1292
llvm::Instruction::andIRFlags
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
Definition: Instruction.cpp:348
llvm::DenseSet< unsigned >
llvm::StoreInst
An instruction for storing to memory.
Definition: Instructions.h:298
llvm::Instruction::eraseFromParent
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:77
llvm::Instruction::setFast
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
Definition: Instruction.cpp:225
haveSameSpecialState
static bool haveSameSpecialState(const Instruction *I1, const Instruction *I2, bool IgnoreAlignment=false)
Return true if both instructions have the same special state.
Definition: Instruction.cpp:461
llvm::Instruction::hasAllowContract
bool hasAllowContract() const
Determine whether the allow-contract flag is set.
Definition: Instruction.cpp:305
llvm::CallBrInst
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
Definition: Instructions.h:4020
llvm::Instruction::isIdenticalTo
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one.
Definition: Instruction.cpp:528
llvm::Instruction::moveAfter
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Definition: Instruction.cpp:100
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:54
llvm::Instruction::isOnlyUserOfAnyOperand
bool isOnlyUserOfAnyOperand()
It checks if this instruction is the only user of at least one of its operands.
Definition: Instruction.cpp:145
llvm::BasicBlock::isInstrOrderValid
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
Definition: BasicBlock.h:500
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::Instruction::hasAtomicStore
bool hasAtomicStore() const
Return true if this atomic instruction stores to memory.
Definition: Instruction.cpp:669
llvm::GetElementPtrInst
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:929
llvm::Instruction::setDebugLoc
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:351
llvm::ilist_node_with_parent< Instruction, BasicBlock >::getPrevNode
Instruction * getPrevNode()
Definition: ilist_node.h:275
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::Instruction::hasMetadata
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
Definition: Instruction.h:253
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::Instruction::isFast
bool isFast() const
Determine whether all fast-math-flags are set.
Definition: Instruction.cpp:275
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:944
llvm::PHINode::block_begin
block_iterator block_begin()
Definition: Instructions.h:2761
llvm::Instruction::clone
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
Definition: Instruction.cpp:888
llvm::Instruction::dropUndefImplyingAttrsAndUnknownMetadata
void dropUndefImplyingAttrsAndUnknownMetadata(ArrayRef< unsigned > KnownIDs={})
This function drops non-debug unknown metadata (through dropUnknownNonDebugMetadata).
Definition: Instruction.cpp:202
llvm::ArrayRef< unsigned >
llvm::Instruction::getFastMathFlags
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Definition: Instruction.cpp:315
Mul
BinaryOperator * Mul
Definition: X86PartialReduction.cpp:70
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1597
llvm::SymbolTableList
List that automatically updates parent links and symbol tables.
Definition: SymbolTableListTraits.h:60
llvm::Instruction::setSuccessor
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
Definition: Instruction.cpp:827
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::Instruction::getFunction
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:69
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition: ilist_node.h:82
llvm::Instruction::isExact
bool isExact() const
Determine whether the exact flag is set.
Definition: Instruction.cpp:221
llvm::Instruction::copyFastMathFlags
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
Definition: Instruction.cpp:270
llvm::Instruction::mayReadFromMemory
bool mayReadFromMemory() const
Return true if this instruction may read memory.
Definition: Instruction.cpp:602
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:174
llvm::AtomicRMWInst
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:715
llvm::MDNode::getContext
LLVMContext & getContext() const
Definition: Metadata.h:1108
llvm::MCID::Select
@ Select
Definition: MCInstrDesc.h:164
llvm::Instruction::setFastMathFlags
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
Definition: Instruction.cpp:265
llvm::Instruction::isAtomic
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
Definition: Instruction.cpp:642
llvm::Instruction::setHasApproxFunc
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
Definition: Instruction.cpp:260
llvm::Instruction::CompareIgnoringAlignment
@ CompareIgnoringAlignment
Check for equivalence ignoring load/store alignment.
Definition: Instruction.h:715
llvm::Instruction::Instruction
Instruction(const Instruction &)=delete
llvm::Instruction::isUsedOutsideOfBlock
bool isUsedOutsideOfBlock(const BasicBlock *BB) const
Return true if there are any uses of this instruction in blocks other than the specified block.
Definition: Instruction.cpp:584
llvm::ilist_iterator
Iterator for intrusive lists based on ilist_node.
Definition: ilist_iterator.h:57
llvm::ExtractValueInst
This instruction extracts a struct member or array element value from an aggregate value.
Definition: Instructions.h:2446
llvm::Instruction::isEHPad
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:649
llvm::MCID::Add
@ Add
Definition: MCInstrDesc.h:185
llvm::Instruction::hasAllowReassoc
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
Definition: Instruction.cpp:280
llvm::Instruction::isDebugOrPseudoInst
bool isDebugOrPseudoInst() const
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
Definition: Instruction.cpp:761
llvm::Instruction::hasNoNaNs
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
Definition: Instruction.cpp:285
llvm::ValueAsMetadata::handleRAUW
static void handleRAUW(Value *From, Value *To)
Definition: Metadata.cpp:436
llvm::Instruction::hasPoisonGeneratingFlags
bool hasPoisonGeneratingFlags() const
Return true if this operator has flags which may cause this instruction to evaluate to poison despite...
Definition: Instruction.cpp:169
llvm::Instruction::setHasAllowReciprocal
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
Definition: Instruction.cpp:250
llvm::BasicBlock::getInstList
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:373
llvm::ShuffleVectorInst
This instruction constructs a fixed permutation of two input vectors.
Definition: Instructions.h:2008
llvm::RecurKind::FAdd
@ FAdd
Sum of floats.
Instructions.h
llvm::User::getNumOperands
unsigned getNumOperands() const
Definition: User.h:191
llvm::Instruction::setHasNoInfs
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
Definition: Instruction.cpp:240
llvm::Instruction::getDebugLoc
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:354
llvm::Instruction::setHasNoSignedZeros
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
Definition: Instruction.cpp:245
llvm::Value::isUsedByMetadata
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
Definition: Value.h:557
llvm::Instruction::hasNoSignedWrap
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
Definition: Instruction.cpp:165
llvm::User::op_begin
op_iterator op_begin()
Definition: User.h:234
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:91
llvm::PHINode::getIncomingBlock
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Definition: Instructions.h:2815
llvm::Instruction::CompareUsingScalarTypes
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
Definition: Instruction.h:718
llvm::Instruction::swapProfMetadata
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
Definition: Instruction.cpp:850
llvm::PHINode
Definition: Instructions.h:2699
llvm::Instruction::copyIRFlags
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
Definition: Instruction.cpp:324
llvm::Instruction::hasNoInfs
bool hasNoInfs() const
Determine whether the no-infs flag is set.
Definition: Instruction.cpp:290
llvm::Instruction::hasNoSignedZeros
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
Definition: Instruction.cpp:295
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
GEP
Hexagon Common GEP
Definition: HexagonCommonGEP.cpp:171
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:59
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::MDString::getString
StringRef getString() const
Definition: Metadata.cpp:508
llvm::Instruction::isSameOperationAs
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
This function determines if the specified instruction executes the same operation as the current one.
Definition: Instruction.cpp:560
llvm::InsertValueInst
This instruction inserts a struct field of array element value into an aggregate value.
Definition: Instructions.h:2557
llvm::MDString
A single uniqued string.
Definition: Metadata.h:612
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::AtomicCmpXchgInst
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:510
llvm::Instruction::setHasAllowReassoc
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
Definition: Instruction.cpp:230
llvm::Instruction::dropPoisonGeneratingFlags
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
Definition: Instruction.cpp:173
llvm::AtomicOrdering::NotAtomic
@ NotAtomic
llvm::RecurKind::Xor
@ Xor
Bitwise or logical XOR of integers.
llvm::Instruction::moveBefore
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Definition: Instruction.cpp:96
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1247
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::User::op_end
op_iterator op_end()
Definition: User.h:236