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