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