Lines Matching full:instruction

1 //===-- Instruction.cpp - Implement the Instruction class -----------------===//
9 // This file implements the Instruction class for the IR library.
13 #include "llvm/IR/Instruction.h"
29 InsertPosition::InsertPosition(Instruction *InsertBefore)
35 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
41 assert(BB && "Instruction to insert before is not in a basic block!");
46 Instruction::~Instruction() {
47 assert(!getParent() && "Instruction still linked in the program!");
49 // Replace any extant metadata uses of this instruction with undef to
51 // - Treat Instruction like any other Value, and point its extant metadata
55 // - Call salvageDebugInfoOrMarkUndef. Not needed to make instruction removal
61 // Explicitly remove DIAssignID metadata to clear up ID -> Instruction(s)
66 const Module *Instruction::getModule() const {
70 const Function *Instruction::getFunction() const {
74 const DataLayout &Instruction::getDataLayout() const {
78 void Instruction::removeFromParent() {
85 void Instruction::handleMarkerRemoval() {
92 BasicBlock::iterator Instruction::eraseFromParent() {
97 void Instruction::insertBefore(Instruction *InsertPos) {
101 /// Insert an unlinked instruction into a basic block immediately before the
102 /// specified instruction.
103 void Instruction::insertBefore(BasicBlock::iterator InsertPos) {
107 /// Insert an unlinked instruction into a basic block immediately after the
108 /// specified instruction.
109 void Instruction::insertAfter(Instruction *InsertPos) {
115 BasicBlock::iterator Instruction::insertInto(BasicBlock *ParentBB,
117 assert(getParent() == nullptr && "Expected detached instruction");
126 void Instruction::insertBefore(BasicBlock &BB,
165 /// Unlink this instruction from its current basic block and insert it into the
167 void Instruction::moveBefore(Instruction *MovePos) {
171 void Instruction::moveBeforePreserving(Instruction *MovePos) {
175 void Instruction::moveAfter(Instruction *MovePos) {
177 // We want this instruction to be moved to before NextIt in the instruction
183 void Instruction::moveAfterPreserving(Instruction *MovePos) {
185 // We want this instruction and its debug range to be moved to before NextIt
186 // in the instruction list, but before NextIt's debug value range.
191 void Instruction::moveBefore(BasicBlock &BB, InstListType::iterator I) {
195 void Instruction::moveBeforePreserving(BasicBlock &BB,
200 void Instruction::moveBeforeImpl(BasicBlock &BB, InstListType::iterator I,
206 // the instruction, no more special handling needed.
215 // Move this single instruction. Use the list splice method directly, not
233 iterator_range<DbgRecord::self_iterator> Instruction::cloneDebugInfoFrom(
234 const Instruction *From, std::optional<DbgRecord::self_iterator> FromHere,
251 Instruction::getDbgReinsertionPosition() {
252 // Is there a marker on the next instruction?
264 bool Instruction::hasDbgRecords() const { return !getDbgRecordRange().empty(); }
266 void Instruction::adoptDbgRecords(BasicBlock *BB, BasicBlock::iterator It,
281 // If we have DbgMarkers attached to this instruction, we have to honour the
292 // moment. It will be released when the Instruction is freed in the worst
309 void Instruction::dropDbgRecords() {
314 void Instruction::dropOneDbgRecord(DbgRecord *DVR) {
318 bool Instruction::comesBefore(const Instruction *Other) const {
322 "cross-BB instruction order comparison");
328 std::optional<BasicBlock::iterator> Instruction::getInsertionPointAfterDef() {
329 assert(!getType()->isVoidTy() && "Instruction must define result");
346 // Any instruction inserted immediately after "this" will come before any
359 bool Instruction::isOnlyUserOfAnyOperand() {
363 void Instruction::setHasNoUnsignedWrap(bool b) {
370 void Instruction::setHasNoSignedWrap(bool b) {
377 void Instruction::setIsExact(bool b) {
381 void Instruction::setNonNeg(bool b) {
387 bool Instruction::hasNoUnsignedWrap() const {
394 bool Instruction::hasNoSignedWrap() const {
401 bool Instruction::hasNonNeg() const {
406 bool Instruction::hasPoisonGeneratingFlags() const {
410 void Instruction::dropPoisonGeneratingFlags() {
412 case Instruction::Add:
413 case Instruction::Sub:
414 case Instruction::Mul:
415 case Instruction::Shl:
420 case Instruction::UDiv:
421 case Instruction::SDiv:
422 case Instruction::AShr:
423 case Instruction::LShr:
427 case Instruction::Or:
431 case Instruction::GetElementPtr:
435 case Instruction::UIToFP:
436 case Instruction::ZExt:
440 case Instruction::Trunc:
454 bool Instruction::hasPoisonGeneratingMetadata() const {
460 void Instruction::dropPoisonGeneratingMetadata() {
466 bool Instruction::hasPoisonGeneratingReturnAttributes() const {
476 void Instruction::dropPoisonGeneratingReturnAttributes() {
487 void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
506 void Instruction::dropUBImplyingAttrsAndMetadata() {
516 bool Instruction::isExact() const {
520 void Instruction::setFast(bool B) {
525 void Instruction::setHasAllowReassoc(bool B) {
530 void Instruction::setHasNoNaNs(bool B) {
535 void Instruction::setHasNoInfs(bool B) {
540 void Instruction::setHasNoSignedZeros(bool B) {
545 void Instruction::setHasAllowReciprocal(bool B) {
550 void Instruction::setHasAllowContract(bool B) {
555 void Instruction::setHasApproxFunc(bool B) {
560 void Instruction::setFastMathFlags(FastMathFlags FMF) {
565 void Instruction::copyFastMathFlags(FastMathFlags FMF) {
570 bool Instruction::isFast() const {
575 bool Instruction::hasAllowReassoc() const {
580 bool Instruction::hasNoNaNs() const {
585 bool Instruction::hasNoInfs() const {
590 bool Instruction::hasNoSignedZeros() const {
595 bool Instruction::hasAllowReciprocal() const {
600 bool Instruction::hasAllowContract() const {
605 bool Instruction::hasApproxFunc() const {
610 FastMathFlags Instruction::getFastMathFlags() const {
615 void Instruction::copyFastMathFlags(const Instruction *I) {
619 void Instruction::copyIRFlags(const Value *V, bool IncludeWrapFlags) {
659 void Instruction::andIRFlags(const Value *V) {
700 const char *Instruction::getOpcodeName(unsigned OpCode) {
787 bool Instruction::hasSameSpecialState(const Instruction *I2,
855 bool Instruction::isIdenticalTo(const Instruction *I) const {
860 bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const {
887 bool Instruction::isSameOperationAs(const Instruction *I,
911 bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const {
915 const Instruction *I = cast<Instruction>(U.getUser());
929 bool Instruction::mayReadFromMemory() const {
932 case Instruction::VAArg:
933 case Instruction::Load:
934 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
935 case Instruction::AtomicCmpXchg:
936 case Instruction::AtomicRMW:
937 case Instruction::CatchPad:
938 case Instruction::CatchRet:
940 case Instruction::Call:
941 case Instruction::Invoke:
942 case Instruction::CallBr:
944 case Instruction::Store:
949 bool Instruction::mayWriteToMemory() const {
952 case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
953 case Instruction::Store:
954 case Instruction::VAArg:
955 case Instruction::AtomicCmpXchg:
956 case Instruction::AtomicRMW:
957 case Instruction::CatchPad:
958 case Instruction::CatchRet:
960 case Instruction::Call:
961 case Instruction::Invoke:
962 case Instruction::CallBr:
964 case Instruction::Load:
969 bool Instruction::isAtomic() const {
973 case Instruction::AtomicCmpXchg:
974 case Instruction::AtomicRMW:
975 case Instruction::Fence:
977 case Instruction::Load:
979 case Instruction::Store:
984 bool Instruction::hasAtomicLoad() const {
989 case Instruction::AtomicCmpXchg:
990 case Instruction::AtomicRMW:
991 case Instruction::Load:
996 bool Instruction::hasAtomicStore() const {
1001 case Instruction::AtomicCmpXchg:
1002 case Instruction::AtomicRMW:
1003 case Instruction::Store:
1008 bool Instruction::isVolatile() const {
1012 case Instruction::AtomicRMW:
1014 case Instruction::Store:
1016 case Instruction::Load:
1018 case Instruction::AtomicCmpXchg:
1020 case Instruction::Call:
1021 case Instruction::Invoke:
1038 Type *Instruction::getAccessType() const {
1040 case Instruction::Store:
1042 case Instruction::Load:
1043 case Instruction::AtomicRMW:
1045 case Instruction::AtomicCmpXchg:
1047 case Instruction::Call:
1048 case Instruction::Invoke:
1096 bool Instruction::mayThrow(bool IncludePhaseOneUnwind) const {
1098 case Instruction::Call:
1100 case Instruction::CleanupRet:
1102 case Instruction::CatchSwitch:
1104 case Instruction::Resume:
1106 case Instruction::Invoke: {
1110 Instruction *Pad = UnwindDest->getFirstNonPHI();
1115 case Instruction::CleanupPad:
1123 bool Instruction::mayHaveSideEffects() const {
1127 bool Instruction::isSafeToRemove() const {
1132 bool Instruction::willReturn() const {
1142 bool Instruction::isLifetimeStartOrEnd() const {
1150 bool Instruction::isLaunderOrStripInvariantGroup() const {
1159 bool Instruction::isDebugOrPseudoInst() const {
1163 const Instruction *
1164 Instruction::getNextNonDebugInstruction(bool SkipPseudoOp) const {
1165 for (const Instruction *I = getNextNode(); I; I = I->getNextNode())
1171 const Instruction *
1172 Instruction::getPrevNonDebugInstruction(bool SkipPseudoOp) const {
1173 for (const Instruction *I = getPrevNode(); I; I = I->getPrevNode())
1179 const DebugLoc &Instruction::getStableDebugLoc() const {
1181 if (const Instruction *Next = getNextNonDebugInstruction())
1186 bool Instruction::isAssociative() const {
1203 bool Instruction::isCommutative() const {
1210 unsigned Instruction::getNumSuccessors() const {
1213 case Instruction::OPC: \
1215 #include "llvm/IR/Instruction.def"
1222 BasicBlock *Instruction::getSuccessor(unsigned idx) const {
1225 case Instruction::OPC: \
1227 #include "llvm/IR/Instruction.def"
1234 void Instruction::setSuccessor(unsigned idx, BasicBlock *B) {
1237 case Instruction::OPC: \
1239 #include "llvm/IR/Instruction.def"
1246 void Instruction::replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB) {
1247 for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1253 Instruction *Instruction::cloneImpl() const {
1254 llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
1257 void Instruction::swapProfMetadata() {
1280 void Instruction::copyMetadata(const Instruction &SrcInst,
1287 // Otherwise, enumerate and copy over metadata from the old instruction to the
1299 Instruction *Instruction::clone() const {
1300 Instruction *New = nullptr;
1305 case Instruction::opc: \
1308 #include "llvm/IR/Instruction.def"