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 const 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->getAlign() == cast<AtomicCmpXchgInst>(I2)->getAlign() ||
922 IgnoreAlignment) &&
923 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
924 CXI->getSuccessOrdering() ==
925 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
926 CXI->getFailureOrdering() ==
927 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
928 CXI->getSyncScopeID() ==
929 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
930 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
931 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
932 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
933 (RMWI->getAlign() == cast<AtomicRMWInst>(I2)->getAlign() ||
934 IgnoreAlignment) &&
935 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
936 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
938 return SVI->getShuffleMask() ==
939 cast<ShuffleVectorInst>(I2)->getShuffleMask();
941 return GEP->getSourceElementType() ==
942 cast<GetElementPtrInst>(I2)->getSourceElementType();
943
944 return true;
945}
946
947bool Instruction::isIdenticalTo(const Instruction *I) const {
948 return isIdenticalToWhenDefined(I) &&
949 SubclassOptionalData == I->SubclassOptionalData;
950}
951
953 bool IntersectAttrs) const {
954 if (getOpcode() != I->getOpcode() ||
955 getNumOperands() != I->getNumOperands() || getType() != I->getType())
956 return false;
957
958 // If both instructions have no operands, they are identical.
959 if (getNumOperands() == 0 && I->getNumOperands() == 0)
960 return this->hasSameSpecialState(I, /*IgnoreAlignment=*/false,
961 IntersectAttrs);
962
963 // We have two instructions of identical opcode and #operands. Check to see
964 // if all operands are the same.
965 if (!equal(operands(), I->operands()))
966 return false;
967
968 // WARNING: this logic must be kept in sync with EliminateDuplicatePHINodes()!
969 if (const PHINode *Phi = dyn_cast<PHINode>(this)) {
970 const PHINode *OtherPhi = cast<PHINode>(I);
971 return equal(Phi->blocks(), OtherPhi->blocks());
972 }
973
974 return this->hasSameSpecialState(I, /*IgnoreAlignment=*/false,
975 IntersectAttrs);
976}
977
978// Keep this in sync with FunctionComparator::cmpOperations in
979// lib/Transforms/IPO/MergeFunctions.cpp.
981 unsigned flags) const {
982 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
983 bool UseScalarTypes = flags & CompareUsingScalarTypes;
984 bool IntersectAttrs = flags & CompareUsingIntersectedAttrs;
985
986 if (getOpcode() != I->getOpcode() ||
987 getNumOperands() != I->getNumOperands() ||
988 (UseScalarTypes ?
989 getType()->getScalarType() != I->getType()->getScalarType() :
990 getType() != I->getType()))
991 return false;
992
993 // We have two instructions of identical opcode and #operands. Check to see
994 // if all operands are the same type
995 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
996 if (UseScalarTypes ?
997 getOperand(i)->getType()->getScalarType() !=
998 I->getOperand(i)->getType()->getScalarType() :
999 getOperand(i)->getType() != I->getOperand(i)->getType())
1000 return false;
1001
1002 return this->hasSameSpecialState(I, IgnoreAlignment, IntersectAttrs);
1003}
1004
1005bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const {
1006 for (const Use &U : uses()) {
1007 // PHI nodes uses values in the corresponding predecessor block. For other
1008 // instructions, just check to see whether the parent of the use matches up.
1009 const Instruction *I = cast<Instruction>(U.getUser());
1010 const PHINode *PN = dyn_cast<PHINode>(I);
1011 if (!PN) {
1012 if (I->getParent() != BB)
1013 return true;
1014 continue;
1015 }
1016
1017 if (PN->getIncomingBlock(U) != BB)
1018 return true;
1019 }
1020 return false;
1021}
1022
1023bool Instruction::mayReadFromMemory() const {
1024 switch (getOpcode()) {
1025 default: return false;
1026 case Instruction::VAArg:
1027 case Instruction::Load:
1028 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
1029 case Instruction::AtomicCmpXchg:
1030 case Instruction::AtomicRMW:
1031 case Instruction::CatchPad:
1032 case Instruction::CatchRet:
1033 return true;
1034 case Instruction::Call:
1035 case Instruction::Invoke:
1036 case Instruction::CallBr:
1037 return !cast<CallBase>(this)->onlyWritesMemory();
1038 case Instruction::Store:
1039 return !cast<StoreInst>(this)->isUnordered();
1040 }
1041}
1042
1043bool Instruction::mayWriteToMemory() const {
1044 switch (getOpcode()) {
1045 default: return false;
1046 case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
1047 case Instruction::Store:
1048 case Instruction::VAArg:
1049 case Instruction::AtomicCmpXchg:
1050 case Instruction::AtomicRMW:
1051 case Instruction::CatchPad:
1052 case Instruction::CatchRet:
1053 return true;
1054 case Instruction::Call:
1055 case Instruction::Invoke:
1056 case Instruction::CallBr:
1057 return !cast<CallBase>(this)->onlyReadsMemory();
1058 case Instruction::Load:
1059 return !cast<LoadInst>(this)->isUnordered();
1060 }
1061}
1062
1063bool Instruction::isAtomic() const {
1064 switch (getOpcode()) {
1065 default:
1066 return false;
1067 case Instruction::AtomicCmpXchg:
1068 case Instruction::AtomicRMW:
1069 case Instruction::Fence:
1070 return true;
1071 case Instruction::Load:
1072 return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
1073 case Instruction::Store:
1074 return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
1075 }
1076}
1077
1078bool Instruction::hasAtomicLoad() const {
1079 assert(isAtomic());
1080 switch (getOpcode()) {
1081 default:
1082 return false;
1083 case Instruction::AtomicCmpXchg:
1084 case Instruction::AtomicRMW:
1085 case Instruction::Load:
1086 return true;
1087 }
1088}
1089
1090bool Instruction::hasAtomicStore() const {
1091 assert(isAtomic());
1092 switch (getOpcode()) {
1093 default:
1094 return false;
1095 case Instruction::AtomicCmpXchg:
1096 case Instruction::AtomicRMW:
1097 case Instruction::Store:
1098 return true;
1099 }
1100}
1101
1102bool Instruction::isVolatile() const {
1103 switch (getOpcode()) {
1104 default:
1105 return false;
1106 case Instruction::AtomicRMW:
1107 return cast<AtomicRMWInst>(this)->isVolatile();
1108 case Instruction::Store:
1109 return cast<StoreInst>(this)->isVolatile();
1110 case Instruction::Load:
1111 return cast<LoadInst>(this)->isVolatile();
1112 case Instruction::AtomicCmpXchg:
1113 return cast<AtomicCmpXchgInst>(this)->isVolatile();
1114 case Instruction::Call:
1115 case Instruction::Invoke:
1116 // There are a very limited number of intrinsics with volatile flags.
1117 if (auto *II = dyn_cast<IntrinsicInst>(this)) {
1118 if (auto *MI = dyn_cast<MemIntrinsic>(II))
1119 return MI->isVolatile();
1120 switch (II->getIntrinsicID()) {
1121 default: break;
1122 case Intrinsic::matrix_column_major_load:
1123 return cast<ConstantInt>(II->getArgOperand(2))->isOne();
1124 case Intrinsic::matrix_column_major_store:
1125 return cast<ConstantInt>(II->getArgOperand(3))->isOne();
1126 }
1127 }
1128 return false;
1129 }
1130}
1131
1132Type *Instruction::getAccessType() const {
1133 switch (getOpcode()) {
1134 case Instruction::Store:
1135 return cast<StoreInst>(this)->getValueOperand()->getType();
1136 case Instruction::Load:
1137 case Instruction::AtomicRMW:
1138 return getType();
1139 case Instruction::AtomicCmpXchg:
1140 return cast<AtomicCmpXchgInst>(this)->getNewValOperand()->getType();
1141 case Instruction::Call:
1142 case Instruction::Invoke:
1143 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(this)) {
1144 switch (II->getIntrinsicID()) {
1145 case Intrinsic::masked_load:
1146 case Intrinsic::masked_gather:
1147 case Intrinsic::masked_expandload:
1148 case Intrinsic::vp_load:
1149 case Intrinsic::vp_gather:
1150 case Intrinsic::experimental_vp_strided_load:
1151 return II->getType();
1152 case Intrinsic::masked_store:
1153 case Intrinsic::masked_scatter:
1154 case Intrinsic::masked_compressstore:
1155 case Intrinsic::vp_store:
1156 case Intrinsic::vp_scatter:
1157 case Intrinsic::experimental_vp_strided_store:
1158 return II->getOperand(0)->getType();
1159 default:
1160 break;
1161 }
1162 }
1163 }
1164
1165 return nullptr;
1166}
1167
1168static bool canUnwindPastLandingPad(const LandingPadInst *LP,
1169 bool IncludePhaseOneUnwind) {
1170 // Because phase one unwinding skips cleanup landingpads, we effectively
1171 // unwind past this frame, and callers need to have valid unwind info.
1172 if (LP->isCleanup())
1173 return IncludePhaseOneUnwind;
1174
1175 for (unsigned I = 0; I < LP->getNumClauses(); ++I) {
1176 Constant *Clause = LP->getClause(I);
1177 // catch ptr null catches all exceptions.
1178 if (LP->isCatch(I) && isa<ConstantPointerNull>(Clause))
1179 return false;
1180 // filter [0 x ptr] catches all exceptions.
1181 if (LP->isFilter(I) && Clause->getType()->getArrayNumElements() == 0)
1182 return false;
1183 }
1184
1185 // May catch only some subset of exceptions, in which case other exceptions
1186 // will continue unwinding.
1187 return true;
1188}
1189
1190bool Instruction::mayThrow(bool IncludePhaseOneUnwind) const {
1191 switch (getOpcode()) {
1192 case Instruction::Call:
1193 return !cast<CallInst>(this)->doesNotThrow();
1194 case Instruction::CleanupRet:
1195 return cast<CleanupReturnInst>(this)->unwindsToCaller();
1196 case Instruction::CatchSwitch:
1197 return cast<CatchSwitchInst>(this)->unwindsToCaller();
1198 case Instruction::Resume:
1199 return true;
1200 case Instruction::Invoke: {
1201 // Landingpads themselves don't unwind -- however, an invoke of a skipped
1202 // landingpad may continue unwinding.
1203 BasicBlock *UnwindDest = cast<InvokeInst>(this)->getUnwindDest();
1204 BasicBlock::iterator Pad = UnwindDest->getFirstNonPHIIt();
1205 if (auto *LP = dyn_cast<LandingPadInst>(Pad))
1206 return canUnwindPastLandingPad(LP, IncludePhaseOneUnwind);
1207 return false;
1208 }
1209 case Instruction::CleanupPad:
1210 // Treat the same as cleanup landingpad.
1211 return IncludePhaseOneUnwind;
1212 default:
1213 return false;
1214 }
1215}
1216
1218 return mayWriteToMemory() || mayThrow() || !willReturn();
1219}
1220
1221bool Instruction::isSafeToRemove() const {
1222 return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
1223 !this->isTerminator() && !this->isEHPad();
1224}
1225
1226bool Instruction::willReturn() const {
1227 // Volatile store isn't guaranteed to return; see LangRef.
1228 if (auto *SI = dyn_cast<StoreInst>(this))
1229 return !SI->isVolatile();
1230
1231 if (const auto *CB = dyn_cast<CallBase>(this))
1232 return CB->hasFnAttr(Attribute::WillReturn);
1233 return true;
1234}
1235
1237 auto *II = dyn_cast<IntrinsicInst>(this);
1238 if (!II)
1239 return false;
1240 Intrinsic::ID ID = II->getIntrinsicID();
1241 return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end;
1242}
1243
1245 auto *II = dyn_cast<IntrinsicInst>(this);
1246 if (!II)
1247 return false;
1248 Intrinsic::ID ID = II->getIntrinsicID();
1249 return ID == Intrinsic::launder_invariant_group ||
1250 ID == Intrinsic::strip_invariant_group;
1251}
1252
1254 return isa<DbgInfoIntrinsic>(this) || isa<PseudoProbeInst>(this);
1255}
1256
1258 return getDebugLoc();
1259}
1260
1261bool Instruction::isAssociative() const {
1262 if (auto *II = dyn_cast<IntrinsicInst>(this))
1263 return II->isAssociative();
1264 unsigned Opcode = getOpcode();
1265 if (isAssociative(Opcode))
1266 return true;
1267
1268 switch (Opcode) {
1269 case FMul:
1270 case FAdd:
1271 return cast<FPMathOperator>(this)->hasAllowReassoc() &&
1272 cast<FPMathOperator>(this)->hasNoSignedZeros();
1273 default:
1274 return false;
1275 }
1276}
1277
1278bool Instruction::isCommutative() const {
1279 if (auto *II = dyn_cast<IntrinsicInst>(this))
1280 return II->isCommutative();
1281 // TODO: Should allow icmp/fcmp?
1282 return isCommutative(getOpcode());
1283}
1284
1285unsigned Instruction::getNumSuccessors() const {
1286 switch (getOpcode()) {
1287#define HANDLE_TERM_INST(N, OPC, CLASS) \
1288 case Instruction::OPC: \
1289 return static_cast<const CLASS *>(this)->getNumSuccessors();
1290#include "llvm/IR/Instruction.def"
1291 default:
1292 break;
1293 }
1294 llvm_unreachable("not a terminator");
1295}
1296
1297BasicBlock *Instruction::getSuccessor(unsigned idx) const {
1298 switch (getOpcode()) {
1299#define HANDLE_TERM_INST(N, OPC, CLASS) \
1300 case Instruction::OPC: \
1301 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1302#include "llvm/IR/Instruction.def"
1303 default:
1304 break;
1305 }
1306 llvm_unreachable("not a terminator");
1307}
1308
1309void Instruction::setSuccessor(unsigned idx, BasicBlock *B) {
1310 switch (getOpcode()) {
1311#define HANDLE_TERM_INST(N, OPC, CLASS) \
1312 case Instruction::OPC: \
1313 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1314#include "llvm/IR/Instruction.def"
1315 default:
1316 break;
1317 }
1318 llvm_unreachable("not a terminator");
1319}
1320
1322 for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1323 Idx != NumSuccessors; ++Idx)
1324 if (getSuccessor(Idx) == OldBB)
1325 setSuccessor(Idx, NewBB);
1326}
1327
1328Instruction *Instruction::cloneImpl() const {
1329 llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
1330}
1331
1333 MDNode *ProfileData = getBranchWeightMDNode(*this);
1334 if (!ProfileData)
1335 return;
1336 unsigned FirstIdx = getBranchWeightOffset(ProfileData);
1337 if (ProfileData->getNumOperands() != 2 + FirstIdx)
1338 return;
1339
1340 unsigned SecondIdx = FirstIdx + 1;
1342 // If there are more weights past the second, we can't swap them
1343 if (ProfileData->getNumOperands() > SecondIdx + 1)
1344 return;
1345 for (unsigned Idx = 0; Idx < FirstIdx; ++Idx) {
1346 Ops.push_back(ProfileData->getOperand(Idx));
1347 }
1348 // Switch the order of the weights
1349 Ops.push_back(ProfileData->getOperand(SecondIdx));
1350 Ops.push_back(ProfileData->getOperand(FirstIdx));
1351 setMetadata(LLVMContext::MD_prof,
1352 MDNode::get(ProfileData->getContext(), Ops));
1353}
1354
1355void Instruction::copyMetadata(const Instruction &SrcInst,
1356 ArrayRef<unsigned> WL) {
1357 if (WL.empty() || is_contained(WL, LLVMContext::MD_dbg))
1358 setDebugLoc(SrcInst.getDebugLoc().orElse(getDebugLoc()));
1359
1360 if (!SrcInst.hasMetadata())
1361 return;
1362
1364
1365 // Otherwise, enumerate and copy over metadata from the old instruction to the
1366 // new one.
1368 SrcInst.getAllMetadataOtherThanDebugLoc(TheMDs);
1369 for (const auto &MD : TheMDs) {
1370 if (WL.empty() || WLS.count(MD.first))
1371 setMetadata(MD.first, MD.second);
1372 }
1373}
1374
1376 Instruction *New = nullptr;
1377 switch (getOpcode()) {
1378 default:
1379 llvm_unreachable("Unhandled Opcode.");
1380#define HANDLE_INST(num, opc, clas) \
1381 case Instruction::opc: \
1382 New = cast<clas>(this)->cloneImpl(); \
1383 break;
1384#include "llvm/IR/Instruction.def"
1385#undef HANDLE_INST
1386 }
1387
1388 New->SubclassOptionalData = SubclassOptionalData;
1389 New->copyMetadata(*this);
1390 return New;
1391}
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:1078
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1442
ArrayRef< MDOperand > operands() const
Definition Metadata.h:1440
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1569
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1448
LLVMContext & getContext() const
Definition Metadata.h:1242
Tracking metadata reference owned by Metadata.
Definition Metadata.h:900
static constexpr const unsigned PoisonGeneratingIDs[]
Metadata IDs that may generate poison.
Definition Metadata.h:146
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:291
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:546
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.cpp:1099
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
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:318
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:644
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:2116
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:1712
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:325
@ 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:560
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1877
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:2068
@ Keep
No function return thunk.
Definition CodeGen.h:156
Summary of memprof metadata on allocations.
Matching combinators.