LLVM 19.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"
16#include "llvm/IR/Attributes.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/InstrTypes.h"
21#include "llvm/IR/Intrinsics.h"
23#include "llvm/IR/Operator.h"
25#include "llvm/IR/Type.h"
26using namespace llvm;
27
29 : InsertAt(InsertBefore ? InsertBefore->getIterator()
30 : InstListType::iterator()) {}
32 : InsertAt(InsertAtEnd ? InsertAtEnd->end() : InstListType::iterator()) {}
33
34Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
35 InsertPosition InsertBefore)
36 : User(ty, Value::InstructionVal + it, Ops, NumOps) {
37 // When called with an iterator, there must be a block to insert into.
38 if (InstListType::iterator InsertIt = InsertBefore; InsertIt.isValid()) {
39 BasicBlock *BB = InsertIt.getNodeParent();
40 assert(BB && "Instruction to insert before is not in a basic block!");
41 insertInto(BB, InsertBefore);
42 }
43}
44
46 assert(!getParent() && "Instruction still linked in the program!");
47
48 // Replace any extant metadata uses of this instruction with undef to
49 // preserve debug info accuracy. Some alternatives include:
50 // - Treat Instruction like any other Value, and point its extant metadata
51 // uses to an empty ValueAsMetadata node. This makes extant dbg.value uses
52 // trivially dead (i.e. fair game for deletion in many passes), leading to
53 // stale dbg.values being in effect for too long.
54 // - Call salvageDebugInfoOrMarkUndef. Not needed to make instruction removal
55 // correct. OTOH results in wasted work in some common cases (e.g. when all
56 // instructions in a BasicBlock are deleted).
57 if (isUsedByMetadata())
59
60 // Explicitly remove DIAssignID metadata to clear up ID -> Instruction(s)
61 // mapping in LLVMContext.
62 setMetadata(LLVMContext::MD_DIAssignID, nullptr);
63}
64
66 return getParent()->getModule();
67}
68
70 return getParent()->getParent();
71}
72
74 // Perform any debug-info maintenence required.
76
77 getParent()->getInstList().remove(getIterator());
78}
79
81 if (!getParent()->IsNewDbgInfoFormat || !DebugMarker)
82 return;
83
85}
86
89 return getParent()->getInstList().erase(getIterator());
90}
91
93 insertBefore(InsertPos->getIterator());
94}
95
96/// Insert an unlinked instruction into a basic block immediately before the
97/// specified instruction.
99 insertBefore(*InsertPos->getParent(), InsertPos);
100}
101
102/// Insert an unlinked instruction into a basic block immediately after the
103/// specified instruction.
105 BasicBlock *DestParent = InsertPos->getParent();
106
107 DestParent->getInstList().insertAfter(InsertPos->getIterator(), this);
108}
109
112 assert(getParent() == nullptr && "Expected detached instruction");
113 assert((It == ParentBB->end() || It->getParent() == ParentBB) &&
114 "It not in ParentBB");
115 insertBefore(*ParentBB, It);
116 return getIterator();
117}
118
120
122 InstListType::iterator InsertPos) {
124
125 BB.getInstList().insert(InsertPos, this);
126
127 if (!BB.IsNewDbgInfoFormat)
128 return;
129
130 // We've inserted "this": if InsertAtHead is set then it comes before any
131 // DbgVariableRecords attached to InsertPos. But if it's not set, then any
132 // DbgRecords should now come before "this".
133 bool InsertAtHead = InsertPos.getHeadBit();
134 if (!InsertAtHead) {
135 DbgMarker *SrcMarker = BB.getMarker(InsertPos);
136 if (SrcMarker && !SrcMarker->empty()) {
137 // If this assertion fires, the calling code is about to insert a PHI
138 // after debug-records, which would form a sequence like:
139 // %0 = PHI
140 // #dbg_value
141 // %1 = PHI
142 // Which is de-normalised and undesired -- hence the assertion. To avoid
143 // this, you must insert at that position using an iterator, and it must
144 // be aquired by calling getFirstNonPHIIt / begin or similar methods on
145 // the block. This will signal to this behind-the-scenes debug-info
146 // maintenence code that you intend the PHI to be ahead of everything,
147 // including any debug-info.
148 assert(!isa<PHINode>(this) && "Inserting PHI after debug-records!");
149 adoptDbgRecords(&BB, InsertPos, false);
150 }
151 }
152
153 // If we're inserting a terminator, check if we need to flush out
154 // TrailingDbgRecords. Inserting instructions at the end of an incomplete
155 // block is handled by the code block above.
156 if (isTerminator())
157 getParent()->flushTerminatorDbgRecords();
158}
159
160/// Unlink this instruction from its current basic block and insert it into the
161/// basic block that MovePos lives in, right before MovePos.
163 moveBeforeImpl(*MovePos->getParent(), MovePos->getIterator(), false);
164}
165
167 moveBeforeImpl(*MovePos->getParent(), MovePos->getIterator(), true);
168}
169
171 auto NextIt = std::next(MovePos->getIterator());
172 // We want this instruction to be moved to before NextIt in the instruction
173 // list, but before NextIt's debug value range.
174 NextIt.setHeadBit(true);
175 moveBeforeImpl(*MovePos->getParent(), NextIt, false);
176}
177
179 auto NextIt = std::next(MovePos->getIterator());
180 // We want this instruction and its debug range to be moved to before NextIt
181 // in the instruction list, but before NextIt's debug value range.
182 NextIt.setHeadBit(true);
183 moveBeforeImpl(*MovePos->getParent(), NextIt, true);
184}
185
187 moveBeforeImpl(BB, I, false);
188}
189
192 moveBeforeImpl(BB, I, true);
193}
194
195void Instruction::moveBeforeImpl(BasicBlock &BB, InstListType::iterator I,
196 bool Preserve) {
197 assert(I == BB.end() || I->getParent() == &BB);
198 bool InsertAtHead = I.getHeadBit();
199
200 // If we've been given the "Preserve" flag, then just move the DbgRecords with
201 // the instruction, no more special handling needed.
202 if (BB.IsNewDbgInfoFormat && DebugMarker && !Preserve) {
203 if (I != this->getIterator() || InsertAtHead) {
204 // "this" is definitely moving in the list, or it's moving ahead of its
205 // attached DbgVariableRecords. Detach any existing DbgRecords.
207 }
208 }
209
210 // Move this single instruction. Use the list splice method directly, not
211 // the block splicer, which will do more debug-info things.
212 BB.getInstList().splice(I, getParent()->getInstList(), getIterator());
213
214 if (BB.IsNewDbgInfoFormat && !Preserve) {
215 DbgMarker *NextMarker = getParent()->getNextMarker(this);
216
217 // If we're inserting at point I, and not in front of the DbgRecords
218 // attached there, then we should absorb the DbgRecords attached to I.
219 if (!InsertAtHead && NextMarker && !NextMarker->empty()) {
220 adoptDbgRecords(&BB, I, false);
221 }
222 }
223
224 if (isTerminator())
225 getParent()->flushTerminatorDbgRecords();
226}
227
229 const Instruction *From, std::optional<DbgRecord::self_iterator> FromHere,
230 bool InsertAtHead) {
231 if (!From->DebugMarker)
233
234 assert(getParent()->IsNewDbgInfoFormat);
235 assert(getParent()->IsNewDbgInfoFormat ==
236 From->getParent()->IsNewDbgInfoFormat);
237
238 if (!DebugMarker)
239 getParent()->createMarker(this);
240
241 return DebugMarker->cloneDebugInfoFrom(From->DebugMarker, FromHere,
242 InsertAtHead);
243}
244
245std::optional<DbgRecord::self_iterator>
247 // Is there a marker on the next instruction?
248 DbgMarker *NextMarker = getParent()->getNextMarker(this);
249 if (!NextMarker)
250 return std::nullopt;
251
252 // Are there any DbgRecords in the next marker?
253 if (NextMarker->StoredDbgRecords.empty())
254 return std::nullopt;
255
256 return NextMarker->StoredDbgRecords.begin();
257}
258
259bool Instruction::hasDbgRecords() const { return !getDbgRecordRange().empty(); }
260
262 bool InsertAtHead) {
263 DbgMarker *SrcMarker = BB->getMarker(It);
264 auto ReleaseTrailingDbgRecords = [BB, It, SrcMarker]() {
265 if (BB->end() == It) {
266 SrcMarker->eraseFromParent();
268 }
269 };
270
271 if (!SrcMarker || SrcMarker->StoredDbgRecords.empty()) {
272 ReleaseTrailingDbgRecords();
273 return;
274 }
275
276 // If we have DbgMarkers attached to this instruction, we have to honour the
277 // ordering of DbgRecords between this and the other marker. Fall back to just
278 // absorbing from the source.
279 if (DebugMarker || It == BB->end()) {
280 // Ensure we _do_ have a marker.
281 getParent()->createMarker(this);
282 DebugMarker->absorbDebugValues(*SrcMarker, InsertAtHead);
283
284 // Having transferred everything out of SrcMarker, we _could_ clean it up
285 // and free the marker now. However, that's a lot of heap-accounting for a
286 // small amount of memory with a good chance of re-use. Leave it for the
287 // moment. It will be released when the Instruction is freed in the worst
288 // case.
289 // However: if we transferred from a trailing marker off the end of the
290 // block, it's important to not leave the empty marker trailing. It will
291 // give a misleading impression that some debug records have been left
292 // trailing.
293 ReleaseTrailingDbgRecords();
294 } else {
295 // Optimisation: we're transferring all the DbgRecords from the source
296 // marker onto this empty location: just adopt the other instructions
297 // marker.
298 DebugMarker = SrcMarker;
299 DebugMarker->MarkedInstr = this;
300 It->DebugMarker = nullptr;
301 }
302}
303
305 if (DebugMarker)
307}
308
311}
312
314 assert(getParent() && Other->getParent() &&
315 "instructions without BB parents have no order");
316 assert(getParent() == Other->getParent() &&
317 "cross-BB instruction order comparison");
318 if (!getParent()->isInstrOrderValid())
319 const_cast<BasicBlock *>(getParent())->renumberInstructions();
320 return Order < Other->Order;
321}
322
323std::optional<BasicBlock::iterator> Instruction::getInsertionPointAfterDef() {
324 assert(!getType()->isVoidTy() && "Instruction must define result");
325 BasicBlock *InsertBB;
326 BasicBlock::iterator InsertPt;
327 if (auto *PN = dyn_cast<PHINode>(this)) {
328 InsertBB = PN->getParent();
329 InsertPt = InsertBB->getFirstInsertionPt();
330 } else if (auto *II = dyn_cast<InvokeInst>(this)) {
331 InsertBB = II->getNormalDest();
332 InsertPt = InsertBB->getFirstInsertionPt();
333 } else if (isa<CallBrInst>(this)) {
334 // Def is available in multiple successors, there's no single dominating
335 // insertion point.
336 return std::nullopt;
337 } else {
338 assert(!isTerminator() && "Only invoke/callbr terminators return value");
339 InsertBB = getParent();
340 InsertPt = std::next(getIterator());
341 // Any instruction inserted immediately after "this" will come before any
342 // debug-info records take effect -- thus, set the head bit indicating that
343 // to debug-info-transfer code.
344 InsertPt.setHeadBit(true);
345 }
346
347 // catchswitch blocks don't have any legal insertion point (because they
348 // are both an exception pad and a terminator).
349 if (InsertPt == InsertBB->end())
350 return std::nullopt;
351 return InsertPt;
352}
353
355 return any_of(operands(), [](Value *V) { return V->hasOneUser(); });
356}
357
359 if (auto *Inst = dyn_cast<OverflowingBinaryOperator>(this))
360 Inst->setHasNoUnsignedWrap(b);
361 else
362 cast<TruncInst>(this)->setHasNoUnsignedWrap(b);
363}
364
366 if (auto *Inst = dyn_cast<OverflowingBinaryOperator>(this))
367 Inst->setHasNoSignedWrap(b);
368 else
369 cast<TruncInst>(this)->setHasNoSignedWrap(b);
370}
371
373 cast<PossiblyExactOperator>(this)->setIsExact(b);
374}
375
377 assert(isa<PossiblyNonNegInst>(this) && "Must be zext/uitofp");
380}
381
383 if (auto *Inst = dyn_cast<OverflowingBinaryOperator>(this))
384 return Inst->hasNoUnsignedWrap();
385
386 return cast<TruncInst>(this)->hasNoUnsignedWrap();
387}
388
390 if (auto *Inst = dyn_cast<OverflowingBinaryOperator>(this))
391 return Inst->hasNoSignedWrap();
392
393 return cast<TruncInst>(this)->hasNoSignedWrap();
394}
395
397 assert(isa<PossiblyNonNegInst>(this) && "Must be zext/uitofp");
399}
400
402 return cast<Operator>(this)->hasPoisonGeneratingFlags();
403}
404
406 switch (getOpcode()) {
407 case Instruction::Add:
408 case Instruction::Sub:
409 case Instruction::Mul:
410 case Instruction::Shl:
411 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(false);
412 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(false);
413 break;
414
415 case Instruction::UDiv:
416 case Instruction::SDiv:
417 case Instruction::AShr:
418 case Instruction::LShr:
419 cast<PossiblyExactOperator>(this)->setIsExact(false);
420 break;
421
422 case Instruction::Or:
423 cast<PossiblyDisjointInst>(this)->setIsDisjoint(false);
424 break;
425
426 case Instruction::GetElementPtr:
427 cast<GetElementPtrInst>(this)->setNoWrapFlags(GEPNoWrapFlags::none());
428 break;
429
430 case Instruction::UIToFP:
431 case Instruction::ZExt:
432 setNonNeg(false);
433 break;
434
435 case Instruction::Trunc:
436 cast<TruncInst>(this)->setHasNoUnsignedWrap(false);
437 cast<TruncInst>(this)->setHasNoSignedWrap(false);
438 break;
439 }
440
441 if (isa<FPMathOperator>(this)) {
442 setHasNoNaNs(false);
443 setHasNoInfs(false);
444 }
445
446 assert(!hasPoisonGeneratingFlags() && "must be kept in sync");
447}
448
450 return hasMetadata(LLVMContext::MD_range) ||
451 hasMetadata(LLVMContext::MD_nonnull) ||
452 hasMetadata(LLVMContext::MD_align);
453}
454
456 eraseMetadata(LLVMContext::MD_range);
457 eraseMetadata(LLVMContext::MD_nonnull);
458 eraseMetadata(LLVMContext::MD_align);
459}
460
462 if (const auto *CB = dyn_cast<CallBase>(this)) {
463 AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
464 return RetAttrs.hasAttribute(Attribute::Range) ||
465 RetAttrs.hasAttribute(Attribute::Alignment) ||
466 RetAttrs.hasAttribute(Attribute::NonNull);
467 }
468 return false;
469}
470
472 if (auto *CB = dyn_cast<CallBase>(this)) {
473 AttributeMask AM;
474 AM.addAttribute(Attribute::Range);
475 AM.addAttribute(Attribute::Alignment);
476 AM.addAttribute(Attribute::NonNull);
477 CB->removeRetAttrs(AM);
478 }
479 assert(!hasPoisonGeneratingReturnAttributes() && "must be kept in sync");
480}
481
483 ArrayRef<unsigned> KnownIDs) {
485 auto *CB = dyn_cast<CallBase>(this);
486 if (!CB)
487 return;
488 // For call instructions, we also need to drop parameter and return attributes
489 // that are can cause UB if the call is moved to a location where the
490 // attribute is not valid.
491 AttributeList AL = CB->getAttributes();
492 if (AL.isEmpty())
493 return;
494 AttributeMask UBImplyingAttributes =
496 for (unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
497 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
498 CB->removeRetAttrs(UBImplyingAttributes);
499}
500
502 // !annotation metadata does not impact semantics.
503 // !range, !nonnull and !align produce poison, so they are safe to speculate.
504 // !noundef and various AA metadata must be dropped, as it generally produces
505 // immediate undefined behavior.
506 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
507 LLVMContext::MD_nonnull, LLVMContext::MD_align};
509}
510
512 return cast<PossiblyExactOperator>(this)->isExact();
513}
514
516 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
517 cast<FPMathOperator>(this)->setFast(B);
518}
519
521 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
522 cast<FPMathOperator>(this)->setHasAllowReassoc(B);
523}
524
526 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
527 cast<FPMathOperator>(this)->setHasNoNaNs(B);
528}
529
531 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
532 cast<FPMathOperator>(this)->setHasNoInfs(B);
533}
534
536 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
537 cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
538}
539
541 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
542 cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
543}
544
546 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
547 cast<FPMathOperator>(this)->setHasAllowContract(B);
548}
549
551 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
552 cast<FPMathOperator>(this)->setHasApproxFunc(B);
553}
554
556 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
557 cast<FPMathOperator>(this)->setFastMathFlags(FMF);
558}
559
561 assert(isa<FPMathOperator>(this) && "copying fast-math flag on invalid op");
562 cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
563}
564
566 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
567 return cast<FPMathOperator>(this)->isFast();
568}
569
571 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
572 return cast<FPMathOperator>(this)->hasAllowReassoc();
573}
574
576 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
577 return cast<FPMathOperator>(this)->hasNoNaNs();
578}
579
581 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
582 return cast<FPMathOperator>(this)->hasNoInfs();
583}
584
586 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
587 return cast<FPMathOperator>(this)->hasNoSignedZeros();
588}
589
591 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
592 return cast<FPMathOperator>(this)->hasAllowReciprocal();
593}
594
596 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
597 return cast<FPMathOperator>(this)->hasAllowContract();
598}
599
601 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
602 return cast<FPMathOperator>(this)->hasApproxFunc();
603}
604
606 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
607 return cast<FPMathOperator>(this)->getFastMathFlags();
608}
609
611 copyFastMathFlags(I->getFastMathFlags());
612}
613
614void Instruction::copyIRFlags(const Value *V, bool IncludeWrapFlags) {
615 // Copy the wrapping flags.
616 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(this)) {
617 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
618 setHasNoSignedWrap(OB->hasNoSignedWrap());
619 setHasNoUnsignedWrap(OB->hasNoUnsignedWrap());
620 }
621 }
622
623 if (auto *TI = dyn_cast<TruncInst>(V)) {
624 if (isa<TruncInst>(this)) {
625 setHasNoSignedWrap(TI->hasNoSignedWrap());
626 setHasNoUnsignedWrap(TI->hasNoUnsignedWrap());
627 }
628 }
629
630 // Copy the exact flag.
631 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
632 if (isa<PossiblyExactOperator>(this))
633 setIsExact(PE->isExact());
634
635 if (auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
636 if (auto *DestPD = dyn_cast<PossiblyDisjointInst>(this))
637 DestPD->setIsDisjoint(SrcPD->isDisjoint());
638
639 // Copy the fast-math flags.
640 if (auto *FP = dyn_cast<FPMathOperator>(V))
641 if (isa<FPMathOperator>(this))
642 copyFastMathFlags(FP->getFastMathFlags());
643
644 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
645 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
646 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() |
647 DestGEP->getNoWrapFlags());
648
649 if (auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
650 if (isa<PossiblyNonNegInst>(this))
651 setNonNeg(NNI->hasNonNeg());
652}
653
655 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
656 if (isa<OverflowingBinaryOperator>(this)) {
657 setHasNoSignedWrap(hasNoSignedWrap() && OB->hasNoSignedWrap());
658 setHasNoUnsignedWrap(hasNoUnsignedWrap() && OB->hasNoUnsignedWrap());
659 }
660 }
661
662 if (auto *TI = dyn_cast<TruncInst>(V)) {
663 if (isa<TruncInst>(this)) {
664 setHasNoSignedWrap(hasNoSignedWrap() && TI->hasNoSignedWrap());
665 setHasNoUnsignedWrap(hasNoUnsignedWrap() && TI->hasNoUnsignedWrap());
666 }
667 }
668
669 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
670 if (isa<PossiblyExactOperator>(this))
671 setIsExact(isExact() && PE->isExact());
672
673 if (auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
674 if (auto *DestPD = dyn_cast<PossiblyDisjointInst>(this))
675 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
676
677 if (auto *FP = dyn_cast<FPMathOperator>(V)) {
678 if (isa<FPMathOperator>(this)) {
680 FM &= FP->getFastMathFlags();
682 }
683 }
684
685 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
686 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
687 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() &
688 DestGEP->getNoWrapFlags());
689
690 if (auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
691 if (isa<PossiblyNonNegInst>(this))
692 setNonNeg(hasNonNeg() && NNI->hasNonNeg());
693}
694
695const char *Instruction::getOpcodeName(unsigned OpCode) {
696 switch (OpCode) {
697 // Terminators
698 case Ret: return "ret";
699 case Br: return "br";
700 case Switch: return "switch";
701 case IndirectBr: return "indirectbr";
702 case Invoke: return "invoke";
703 case Resume: return "resume";
704 case Unreachable: return "unreachable";
705 case CleanupRet: return "cleanupret";
706 case CatchRet: return "catchret";
707 case CatchPad: return "catchpad";
708 case CatchSwitch: return "catchswitch";
709 case CallBr: return "callbr";
710
711 // Standard unary operators...
712 case FNeg: return "fneg";
713
714 // Standard binary operators...
715 case Add: return "add";
716 case FAdd: return "fadd";
717 case Sub: return "sub";
718 case FSub: return "fsub";
719 case Mul: return "mul";
720 case FMul: return "fmul";
721 case UDiv: return "udiv";
722 case SDiv: return "sdiv";
723 case FDiv: return "fdiv";
724 case URem: return "urem";
725 case SRem: return "srem";
726 case FRem: return "frem";
727
728 // Logical operators...
729 case And: return "and";
730 case Or : return "or";
731 case Xor: return "xor";
732
733 // Memory instructions...
734 case Alloca: return "alloca";
735 case Load: return "load";
736 case Store: return "store";
737 case AtomicCmpXchg: return "cmpxchg";
738 case AtomicRMW: return "atomicrmw";
739 case Fence: return "fence";
740 case GetElementPtr: return "getelementptr";
741
742 // Convert instructions...
743 case Trunc: return "trunc";
744 case ZExt: return "zext";
745 case SExt: return "sext";
746 case FPTrunc: return "fptrunc";
747 case FPExt: return "fpext";
748 case FPToUI: return "fptoui";
749 case FPToSI: return "fptosi";
750 case UIToFP: return "uitofp";
751 case SIToFP: return "sitofp";
752 case IntToPtr: return "inttoptr";
753 case PtrToInt: return "ptrtoint";
754 case BitCast: return "bitcast";
755 case AddrSpaceCast: return "addrspacecast";
756
757 // Other instructions...
758 case ICmp: return "icmp";
759 case FCmp: return "fcmp";
760 case PHI: return "phi";
761 case Select: return "select";
762 case Call: return "call";
763 case Shl: return "shl";
764 case LShr: return "lshr";
765 case AShr: return "ashr";
766 case VAArg: return "va_arg";
767 case ExtractElement: return "extractelement";
768 case InsertElement: return "insertelement";
769 case ShuffleVector: return "shufflevector";
770 case ExtractValue: return "extractvalue";
771 case InsertValue: return "insertvalue";
772 case LandingPad: return "landingpad";
773 case CleanupPad: return "cleanuppad";
774 case Freeze: return "freeze";
775
776 default: return "<Invalid operator> ";
777 }
778}
779
780/// This must be kept in sync with FunctionComparator::cmpOperations in
781/// lib/Transforms/IPO/MergeFunctions.cpp.
783 bool IgnoreAlignment) const {
784 auto I1 = this;
785 assert(I1->getOpcode() == I2->getOpcode() &&
786 "Can not compare special state of different instructions");
787
788 if (const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
789 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
790 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
791 IgnoreAlignment);
792 if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
793 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
794 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
795 IgnoreAlignment) &&
796 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
797 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
798 if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
799 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
800 (SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
801 IgnoreAlignment) &&
802 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
803 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
804 if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
805 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
806 if (const CallInst *CI = dyn_cast<CallInst>(I1))
807 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
808 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
809 CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
810 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
811 if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
812 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
813 CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
814 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
815 if (const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
816 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
817 CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
818 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
819 if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
820 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
821 if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
822 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
823 if (const FenceInst *FI = dyn_cast<FenceInst>(I1))
824 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
825 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
826 if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I1))
827 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
828 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
829 CXI->getSuccessOrdering() ==
830 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
831 CXI->getFailureOrdering() ==
832 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
833 CXI->getSyncScopeID() ==
834 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
835 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
836 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
837 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
838 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
839 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
840 if (const ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(I1))
841 return SVI->getShuffleMask() ==
842 cast<ShuffleVectorInst>(I2)->getShuffleMask();
843 if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I1))
844 return GEP->getSourceElementType() ==
845 cast<GetElementPtrInst>(I2)->getSourceElementType();
846
847 return true;
848}
849
851 return isIdenticalToWhenDefined(I) &&
852 SubclassOptionalData == I->SubclassOptionalData;
853}
854
856 if (getOpcode() != I->getOpcode() ||
857 getNumOperands() != I->getNumOperands() ||
858 getType() != I->getType())
859 return false;
860
861 // If both instructions have no operands, they are identical.
862 if (getNumOperands() == 0 && I->getNumOperands() == 0)
863 return this->hasSameSpecialState(I);
864
865 // We have two instructions of identical opcode and #operands. Check to see
866 // if all operands are the same.
867 if (!std::equal(op_begin(), op_end(), I->op_begin()))
868 return false;
869
870 // WARNING: this logic must be kept in sync with EliminateDuplicatePHINodes()!
871 if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
872 const PHINode *otherPHI = cast<PHINode>(I);
873 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
874 otherPHI->block_begin());
875 }
876
877 return this->hasSameSpecialState(I);
878}
879
880// Keep this in sync with FunctionComparator::cmpOperations in
881// lib/Transforms/IPO/MergeFunctions.cpp.
883 unsigned flags) const {
884 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
885 bool UseScalarTypes = flags & CompareUsingScalarTypes;
886
887 if (getOpcode() != I->getOpcode() ||
888 getNumOperands() != I->getNumOperands() ||
889 (UseScalarTypes ?
890 getType()->getScalarType() != I->getType()->getScalarType() :
891 getType() != I->getType()))
892 return false;
893
894 // We have two instructions of identical opcode and #operands. Check to see
895 // if all operands are the same type
896 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
897 if (UseScalarTypes ?
898 getOperand(i)->getType()->getScalarType() !=
899 I->getOperand(i)->getType()->getScalarType() :
900 getOperand(i)->getType() != I->getOperand(i)->getType())
901 return false;
902
903 return this->hasSameSpecialState(I, IgnoreAlignment);
904}
905
907 for (const Use &U : uses()) {
908 // PHI nodes uses values in the corresponding predecessor block. For other
909 // instructions, just check to see whether the parent of the use matches up.
910 const Instruction *I = cast<Instruction>(U.getUser());
911 const PHINode *PN = dyn_cast<PHINode>(I);
912 if (!PN) {
913 if (I->getParent() != BB)
914 return true;
915 continue;
916 }
917
918 if (PN->getIncomingBlock(U) != BB)
919 return true;
920 }
921 return false;
922}
923
925 switch (getOpcode()) {
926 default: return false;
927 case Instruction::VAArg:
928 case Instruction::Load:
929 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
930 case Instruction::AtomicCmpXchg:
931 case Instruction::AtomicRMW:
932 case Instruction::CatchPad:
933 case Instruction::CatchRet:
934 return true;
935 case Instruction::Call:
936 case Instruction::Invoke:
937 case Instruction::CallBr:
938 return !cast<CallBase>(this)->onlyWritesMemory();
939 case Instruction::Store:
940 return !cast<StoreInst>(this)->isUnordered();
941 }
942}
943
945 switch (getOpcode()) {
946 default: return false;
947 case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
948 case Instruction::Store:
949 case Instruction::VAArg:
950 case Instruction::AtomicCmpXchg:
951 case Instruction::AtomicRMW:
952 case Instruction::CatchPad:
953 case Instruction::CatchRet:
954 return true;
955 case Instruction::Call:
956 case Instruction::Invoke:
957 case Instruction::CallBr:
958 return !cast<CallBase>(this)->onlyReadsMemory();
959 case Instruction::Load:
960 return !cast<LoadInst>(this)->isUnordered();
961 }
962}
963
965 switch (getOpcode()) {
966 default:
967 return false;
968 case Instruction::AtomicCmpXchg:
969 case Instruction::AtomicRMW:
970 case Instruction::Fence:
971 return true;
972 case Instruction::Load:
973 return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
974 case Instruction::Store:
975 return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
976 }
977}
978
980 assert(isAtomic());
981 switch (getOpcode()) {
982 default:
983 return false;
984 case Instruction::AtomicCmpXchg:
985 case Instruction::AtomicRMW:
986 case Instruction::Load:
987 return true;
988 }
989}
990
992 assert(isAtomic());
993 switch (getOpcode()) {
994 default:
995 return false;
996 case Instruction::AtomicCmpXchg:
997 case Instruction::AtomicRMW:
998 case Instruction::Store:
999 return true;
1000 }
1001}
1002
1004 switch (getOpcode()) {
1005 default:
1006 return false;
1007 case Instruction::AtomicRMW:
1008 return cast<AtomicRMWInst>(this)->isVolatile();
1009 case Instruction::Store:
1010 return cast<StoreInst>(this)->isVolatile();
1011 case Instruction::Load:
1012 return cast<LoadInst>(this)->isVolatile();
1013 case Instruction::AtomicCmpXchg:
1014 return cast<AtomicCmpXchgInst>(this)->isVolatile();
1015 case Instruction::Call:
1016 case Instruction::Invoke:
1017 // There are a very limited number of intrinsics with volatile flags.
1018 if (auto *II = dyn_cast<IntrinsicInst>(this)) {
1019 if (auto *MI = dyn_cast<MemIntrinsic>(II))
1020 return MI->isVolatile();
1021 switch (II->getIntrinsicID()) {
1022 default: break;
1023 case Intrinsic::matrix_column_major_load:
1024 return cast<ConstantInt>(II->getArgOperand(2))->isOne();
1025 case Intrinsic::matrix_column_major_store:
1026 return cast<ConstantInt>(II->getArgOperand(3))->isOne();
1027 }
1028 }
1029 return false;
1030 }
1031}
1032
1034 switch (getOpcode()) {
1035 case Instruction::Store:
1036 return cast<StoreInst>(this)->getValueOperand()->getType();
1037 case Instruction::Load:
1038 case Instruction::AtomicRMW:
1039 return getType();
1040 case Instruction::AtomicCmpXchg:
1041 return cast<AtomicCmpXchgInst>(this)->getNewValOperand()->getType();
1042 case Instruction::Call:
1043 case Instruction::Invoke:
1044 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(this)) {
1045 switch (II->getIntrinsicID()) {
1046 case Intrinsic::masked_load:
1047 case Intrinsic::masked_gather:
1048 case Intrinsic::masked_expandload:
1049 case Intrinsic::vp_load:
1050 case Intrinsic::vp_gather:
1051 case Intrinsic::experimental_vp_strided_load:
1052 return II->getType();
1053 case Intrinsic::masked_store:
1054 case Intrinsic::masked_scatter:
1055 case Intrinsic::masked_compressstore:
1056 case Intrinsic::vp_store:
1057 case Intrinsic::vp_scatter:
1058 case Intrinsic::experimental_vp_strided_store:
1059 return II->getOperand(0)->getType();
1060 default:
1061 break;
1062 }
1063 }
1064 }
1065
1066 return nullptr;
1067}
1068
1070 bool IncludePhaseOneUnwind) {
1071 // Because phase one unwinding skips cleanup landingpads, we effectively
1072 // unwind past this frame, and callers need to have valid unwind info.
1073 if (LP->isCleanup())
1074 return IncludePhaseOneUnwind;
1075
1076 for (unsigned I = 0; I < LP->getNumClauses(); ++I) {
1077 Constant *Clause = LP->getClause(I);
1078 // catch ptr null catches all exceptions.
1079 if (LP->isCatch(I) && isa<ConstantPointerNull>(Clause))
1080 return false;
1081 // filter [0 x ptr] catches all exceptions.
1082 if (LP->isFilter(I) && Clause->getType()->getArrayNumElements() == 0)
1083 return false;
1084 }
1085
1086 // May catch only some subset of exceptions, in which case other exceptions
1087 // will continue unwinding.
1088 return true;
1089}
1090
1091bool Instruction::mayThrow(bool IncludePhaseOneUnwind) const {
1092 switch (getOpcode()) {
1093 case Instruction::Call:
1094 return !cast<CallInst>(this)->doesNotThrow();
1095 case Instruction::CleanupRet:
1096 return cast<CleanupReturnInst>(this)->unwindsToCaller();
1097 case Instruction::CatchSwitch:
1098 return cast<CatchSwitchInst>(this)->unwindsToCaller();
1099 case Instruction::Resume:
1100 return true;
1101 case Instruction::Invoke: {
1102 // Landingpads themselves don't unwind -- however, an invoke of a skipped
1103 // landingpad may continue unwinding.
1104 BasicBlock *UnwindDest = cast<InvokeInst>(this)->getUnwindDest();
1105 Instruction *Pad = UnwindDest->getFirstNonPHI();
1106 if (auto *LP = dyn_cast<LandingPadInst>(Pad))
1107 return canUnwindPastLandingPad(LP, IncludePhaseOneUnwind);
1108 return false;
1109 }
1110 case Instruction::CleanupPad:
1111 // Treat the same as cleanup landingpad.
1112 return IncludePhaseOneUnwind;
1113 default:
1114 return false;
1115 }
1116}
1117
1119 return mayWriteToMemory() || mayThrow() || !willReturn();
1120}
1121
1123 return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
1124 !this->isTerminator() && !this->isEHPad();
1125}
1126
1128 // Volatile store isn't guaranteed to return; see LangRef.
1129 if (auto *SI = dyn_cast<StoreInst>(this))
1130 return !SI->isVolatile();
1131
1132 if (const auto *CB = dyn_cast<CallBase>(this))
1133 return CB->hasFnAttr(Attribute::WillReturn);
1134 return true;
1135}
1136
1138 auto *II = dyn_cast<IntrinsicInst>(this);
1139 if (!II)
1140 return false;
1141 Intrinsic::ID ID = II->getIntrinsicID();
1142 return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end;
1143}
1144
1146 auto *II = dyn_cast<IntrinsicInst>(this);
1147 if (!II)
1148 return false;
1149 Intrinsic::ID ID = II->getIntrinsicID();
1150 return ID == Intrinsic::launder_invariant_group ||
1151 ID == Intrinsic::strip_invariant_group;
1152}
1153
1155 return isa<DbgInfoIntrinsic>(this) || isa<PseudoProbeInst>(this);
1156}
1157
1158const Instruction *
1160 for (const Instruction *I = getNextNode(); I; I = I->getNextNode())
1161 if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
1162 return I;
1163 return nullptr;
1164}
1165
1166const Instruction *
1168 for (const Instruction *I = getPrevNode(); I; I = I->getPrevNode())
1169 if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
1170 return I;
1171 return nullptr;
1172}
1173
1175 if (isa<DbgInfoIntrinsic>(this))
1176 if (const Instruction *Next = getNextNonDebugInstruction())
1177 return Next->getDebugLoc();
1178 return getDebugLoc();
1179}
1180
1182 if (auto *II = dyn_cast<IntrinsicInst>(this))
1183 return II->isAssociative();
1184 unsigned Opcode = getOpcode();
1185 if (isAssociative(Opcode))
1186 return true;
1187
1188 switch (Opcode) {
1189 case FMul:
1190 case FAdd:
1191 return cast<FPMathOperator>(this)->hasAllowReassoc() &&
1192 cast<FPMathOperator>(this)->hasNoSignedZeros();
1193 default:
1194 return false;
1195 }
1196}
1197
1199 if (auto *II = dyn_cast<IntrinsicInst>(this))
1200 return II->isCommutative();
1201 // TODO: Should allow icmp/fcmp?
1202 return isCommutative(getOpcode());
1203}
1204
1206 switch (getOpcode()) {
1207#define HANDLE_TERM_INST(N, OPC, CLASS) \
1208 case Instruction::OPC: \
1209 return static_cast<const CLASS *>(this)->getNumSuccessors();
1210#include "llvm/IR/Instruction.def"
1211 default:
1212 break;
1213 }
1214 llvm_unreachable("not a terminator");
1215}
1216
1218 switch (getOpcode()) {
1219#define HANDLE_TERM_INST(N, OPC, CLASS) \
1220 case Instruction::OPC: \
1221 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1222#include "llvm/IR/Instruction.def"
1223 default:
1224 break;
1225 }
1226 llvm_unreachable("not a terminator");
1227}
1228
1230 switch (getOpcode()) {
1231#define HANDLE_TERM_INST(N, OPC, CLASS) \
1232 case Instruction::OPC: \
1233 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1234#include "llvm/IR/Instruction.def"
1235 default:
1236 break;
1237 }
1238 llvm_unreachable("not a terminator");
1239}
1240
1242 for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1243 Idx != NumSuccessors; ++Idx)
1244 if (getSuccessor(Idx) == OldBB)
1245 setSuccessor(Idx, NewBB);
1246}
1247
1248Instruction *Instruction::cloneImpl() const {
1249 llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
1250}
1251
1253 MDNode *ProfileData = getBranchWeightMDNode(*this);
1254 if (!ProfileData)
1255 return;
1256 unsigned FirstIdx = getBranchWeightOffset(ProfileData);
1257 if (ProfileData->getNumOperands() != 2 + FirstIdx)
1258 return;
1259
1260 unsigned SecondIdx = FirstIdx + 1;
1262 // If there are more weights past the second, we can't swap them
1263 if (ProfileData->getNumOperands() > SecondIdx + 1)
1264 return;
1265 for (unsigned Idx = 0; Idx < FirstIdx; ++Idx) {
1266 Ops.push_back(ProfileData->getOperand(Idx));
1267 }
1268 // Switch the order of the weights
1269 Ops.push_back(ProfileData->getOperand(SecondIdx));
1270 Ops.push_back(ProfileData->getOperand(FirstIdx));
1271 setMetadata(LLVMContext::MD_prof,
1272 MDNode::get(ProfileData->getContext(), Ops));
1273}
1274
1276 ArrayRef<unsigned> WL) {
1277 if (!SrcInst.hasMetadata())
1278 return;
1279
1280 SmallDenseSet<unsigned, 4> WLS(WL.begin(), WL.end());
1281
1282 // Otherwise, enumerate and copy over metadata from the old instruction to the
1283 // new one.
1285 SrcInst.getAllMetadataOtherThanDebugLoc(TheMDs);
1286 for (const auto &MD : TheMDs) {
1287 if (WL.empty() || WLS.count(MD.first))
1288 setMetadata(MD.first, MD.second);
1289 }
1290 if (WL.empty() || WLS.count(LLVMContext::MD_dbg))
1291 setDebugLoc(SrcInst.getDebugLoc());
1292}
1293
1295 Instruction *New = nullptr;
1296 switch (getOpcode()) {
1297 default:
1298 llvm_unreachable("Unhandled Opcode.");
1299#define HANDLE_INST(num, opc, clas) \
1300 case Instruction::opc: \
1301 New = cast<clas>(this)->cloneImpl(); \
1302 break;
1303#include "llvm/IR/Instruction.def"
1304#undef HANDLE_INST
1305 }
1306
1307 New->SubclassOptionalData = SubclassOptionalData;
1308 New->copyMetadata(*this);
1309 return New;
1310}
amdgpu AMDGPU Register Bank Select
Rewrite undef for PHI
This file contains the simple types necessary to represent the attributes associated with functions a...
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseSet and SmallDenseSet classes.
Hexagon Common GEP
IRTranslator LLVM IR MI
static bool canUnwindPastLandingPad(const LandingPadInst *LP, bool IncludePhaseOneUnwind)
#define I(x, y, z)
Definition: MD5.cpp:58
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
uint64_t IntrinsicInst * II
llvm::cl::opt< bool > UseNewDbgInfoFormat
This file contains the declarations for profiling metadata utility functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
an instruction to allocate memory on the stack
Definition: Instructions.h:60
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:154
iterator begin() const
Definition: ArrayRef.h:153
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:494
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:695
AttributeMask & addAttribute(Attribute::AttrKind Val)
Add an attribute to the mask.
Definition: AttributeMask.h:44
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Definition: Attributes.cpp:909
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
iterator end()
Definition: BasicBlock.h:445
void deleteTrailingDbgRecords()
Delete any trailing DbgRecords at the end of this block, see setTrailingDbgRecords.
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:410
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:361
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:208
DbgMarker * getMarker(InstListType::iterator It)
Return the DbgMarker for the position given by It, so that DbgRecords can be inserted there.
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:166
bool IsNewDbgInfoFormat
Flag recording whether or not this block stores debug-info in the form of intrinsic instructions (fal...
Definition: BasicBlock.h:66
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:747
This is an important base class in LLVM.
Definition: Constant.h:41
Per-instruction record of debug-info.
static iterator_range< simple_ilist< DbgRecord >::iterator > getEmptyDbgRecordRange()
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(DbgMarker *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere, bool InsertAtHead=false)
Clone all DbgMarkers from From into this marker.
void removeMarker()
Handle the removal of a marker: the position of debug-info has gone away, but the stored debug record...
void absorbDebugValues(DbgMarker &Src, bool InsertAtHead)
Transfer any DbgRecords from Src into this DbgMarker.
void dropDbgRecords()
Erase all DbgRecords in this DbgMarker.
void dropOneDbgRecord(DbgRecord *DR)
Erase a single DbgRecord from this marker.
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
Base class for non-instruction debug metadata records that have positions within IR.
A debug info location.
Definition: DebugLoc.h:33
This instruction extracts a struct member or array element value from an aggregate value.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
An instruction for ordering other memory operations.
Definition: Instructions.h:419
static GEPNoWrapFlags none()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:914
bool isValid() const
Definition: Instruction.h:60
InsertPosition(std::nullptr_t)
Definition: Instruction.h:53
This instruction inserts a struct field of array element value into an aggregate value.
const DebugLoc & getStableDebugLoc() const
Fetch the debug location for this node, unless this is a debug intrinsic, in which case fetch the deb...
DbgMarker * DebugMarker
Optional marker recording the position for debugging information that takes effect immediately before...
Definition: Instruction.h:83
bool mayThrow(bool IncludePhaseOneUnwind=false) const LLVM_READONLY
Return true if this instruction may throw an exception.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
Definition: Instruction.cpp:73
bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
bool hasNoInfs() const LLVM_READONLY
Determine whether the no-infs flag is set.
bool isLifetimeStartOrEnd() const LLVM_READONLY
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const LLVM_READONLY
This function determines if the specified instruction executes the same operation as the current one.
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
void moveBeforePreserving(Instruction *MovePos)
Perform a moveBefore operation, while signalling that the caller intends to preserve the original ord...
bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)
Clone any debug-info attached to From onto this instruction.
bool hasPoisonGeneratingReturnAttributes() const LLVM_READONLY
Return true if this instruction has poison-generating attribute.
bool isDebugOrPseudoInst() const LLVM_READONLY
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
bool hasNoSignedWrap() const LLVM_READONLY
Determine whether the no signed wrap flag is set.
bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
bool hasAtomicStore() const LLVM_READONLY
Return true if this atomic instruction stores to memory.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
bool isOnlyUserOfAnyOperand()
It checks if this instruction is the only user of at least one of its operands.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange() const
Return a range over the DbgRecords attached to this instruction.
Definition: Instruction.h:103
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
Definition: Instruction.cpp:92
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:470
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
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
const Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the previous non-debug instruction in the same basic block as 'this',...
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
Definition: Instruction.h:357
bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:828
void dropPoisonGeneratingReturnAttributes()
Drops return attributes that may generate poison.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:87
bool isFast() const LLVM_READONLY
Determine whether all fast-math-flags are set.
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
bool isExact() const LLVM_READONLY
Determine whether the exact flag is set.
bool isIdenticalToWhenDefined(const Instruction *I) const LLVM_READONLY
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:69
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
void dropOneDbgRecord(DbgRecord *I)
Erase a single DbgRecord I that is attached to this instruction.
void setNonNeg(bool b=true)
Set or clear the nneg flag on this instruction, which must be a zext instruction.
bool isTerminator() const
Definition: Instruction.h:271
Type * getAccessType() const LLVM_READONLY
Return the type this instruction accesses in memory, if any.
bool hasSameSpecialState(const Instruction *I2, bool IgnoreAlignment=false) const LLVM_READONLY
This function determines if the speficied instruction has the same "special" characteristics as the c...
bool hasAllowReciprocal() const LLVM_READONLY
Determine whether the allow-reciprocal flag is set.
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
void dropUBImplyingAttrsAndMetadata()
Drop any attributes or metadata that can cause immediate undefined behavior.
bool hasNonNeg() const LLVM_READONLY
Determine whether the the nneg flag is set.
bool hasPoisonGeneratingFlags() const LLVM_READONLY
Return true if this operator has flags which may cause this instruction to evaluate to poison despite...
bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
bool isUsedOutsideOfBlock(const BasicBlock *BB) const LLVM_READONLY
Return true if there are any uses of this instruction in blocks other than the specified block.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1635
bool isVolatile() const LLVM_READONLY
Return true if this instruction has a volatile memory access.
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
void adoptDbgRecords(BasicBlock *BB, InstListType::iterator It, bool InsertAtHead)
Transfer any DbgRecords on the position It onto this instruction, by simply adopting the sequence of ...
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const char * getOpcodeName() const
Definition: Instruction.h:270
bool willReturn() const LLVM_READONLY
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
bool hasApproxFunc() const LLVM_READONLY
Determine whether the approximate-math-functions flag is set.
@ CompareIgnoringAlignment
Check for equivalence ignoring load/store alignment.
Definition: Instruction.h:894
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
Definition: Instruction.h:897
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:400
void moveAfterPreserving(Instruction *MovePos)
See moveBeforePreserving .
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:268
bool hasAtomicLoad() const LLVM_READONLY
Return true if this atomic instruction loads from memory.
void dropUnknownNonDebugMetadata()
Definition: Instruction.h:431
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void dropPoisonGeneratingMetadata()
Drops metadata that may generate poison.
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
void handleMarkerRemoval()
Handle the debug-info implications of this instruction being removed.
Definition: Instruction.cpp:80
std::optional< InstListType::iterator > getInsertionPointAfterDef()
Get the first insertion point at which the result of this instruction is defined.
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
void dropUBImplyingAttrsAndUnknownMetadata(ArrayRef< unsigned > KnownIDs={})
This function drops non-debug unknown metadata (through dropUnknownNonDebugMetadata).
bool isIdenticalTo(const Instruction *I) const LLVM_READONLY
Return true if the specified instruction is exactly identical to the current one.
std::optional< simple_ilist< DbgRecord >::iterator > getDbgReinsertionPosition()
Return an iterator to the position of the "Next" DbgRecord after this instruction,...
bool isLaunderOrStripInvariantGroup() const LLVM_READONLY
Return true if the instruction is a llvm.launder.invariant.group or llvm.strip.invariant....
bool hasAllowContract() const LLVM_READONLY
Determine whether the allow-contract flag is set.
bool hasPoisonGeneratingMetadata() const LLVM_READONLY
Return true if this instruction has poison-generating metadata.
Instruction(const Instruction &)=delete
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:467
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
bool hasAllowReassoc() const LLVM_READONLY
Determine whether the allow-reassociation flag is set.
void dropDbgRecords()
Erase any DbgRecords attached to this instruction.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isSafeToRemove() const LLVM_READONLY
Return true if the instruction can be removed if the result is unused.
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
bool hasDbgRecords() const
Returns true if any DbgRecords are attached to this instruction.
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:48
Invoke instruction.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
An instruction for reading from memory.
Definition: Instructions.h:173
Metadata node.
Definition: Metadata.h:1067
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1428
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1541
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1434
LLVMContext & getContext() const
Definition: Metadata.h:1231
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
const_block_iterator block_begin() const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Instruction that can have a nneg flag (zext/uitofp).
Definition: InstrTypes.h:722
This instruction constructs a fixed permutation of two input vectors.
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition: DenseSet.h:290
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
An instruction for storing to memory.
Definition: Instructions.h:289
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1795
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
op_range operands()
Definition: User.h:242
op_iterator op_begin()
Definition: User.h:234
Value * getOperand(unsigned i) const
Definition: User.h:169
unsigned getNumOperands() const
Definition: User.h:191
op_iterator op_end()
Definition: User.h:236
static void handleRAUW(Value *From, Value *To)
Definition: Metadata.cpp:538
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:84
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
Definition: Value.h:557
bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
Definition: Metadata.cpp:1532
iterator_range< use_iterator > uses()
Definition: Value.h:376
const ParentTy * getParent() const
Definition: ilist_node.h:32
void splice(iterator where, iplist_impl &L2)
Definition: ilist.h:266
base_list_type::iterator iterator
Definition: ilist.h:121
iterator insertAfter(iterator where, pointer New)
Definition: ilist.h:174
iterator insert(iterator where, pointer New)
Definition: ilist.h:165
A range adaptor for a pair of iterators.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
AttributeMask getUBImplyingAttributes()
Get param/return attributes which imply immediate undefined behavior if an invalid value is passed.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
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:1729
@ Other
Any other memory.
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ FMul
Product of floats.
@ And
Bitwise or logical AND of integers.
@ Add
Sum of integers.
@ FAdd
Sum of floats.