diff options
Diffstat (limited to 'backend/lib/CodeGen')
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp | 9 | ||||
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | 341 | ||||
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/RegBankSelect.cpp | 4 | ||||
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/Utils.cpp | 13 | ||||
| -rw-r--r-- | backend/lib/CodeGen/InlineSpiller.cpp | 13 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineCFGUpdater.cpp | 2 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineCSE.cpp | 5 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineCombiner.cpp | 11 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineCopyPropagation.cpp | 7 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineDCE.cpp | 2 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineInstr.cpp | 6 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineLICM.cpp | 2 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineOutliner.cpp | 2 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineScheduler.cpp | 5 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineSink.cpp | 2 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineStripDebug.cpp | 2 | ||||
| -rw-r--r-- | backend/lib/CodeGen/PHIElimination.cpp | 9 | ||||
| -rw-r--r-- | backend/lib/CodeGen/TwoAddressInstructionPass.cpp | 18 |
18 files changed, 107 insertions, 346 deletions
diff --git a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp index 88bc78e..0814641 100644 --- a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp +++ b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp @@ -215,10 +215,9 @@ Expected<MachinePassResult> InstructionSelect::run(MachineFunction &Function, return runImplementation(Function, Target, Analyses); } -Expected<MachinePassResult> InstructionSelect::runImplementation(MachineFunction &Function, - const TargetDescription &Target, - MachineFunctionAnalysisManager - &Analyses) { +Expected<MachinePassResult> +InstructionSelect::runImplementation(MachineFunction &Function, const TargetDescription &Target, + MachineFunctionAnalysisManager &Analyses) { MachinePassResult Result; std::vector<MachineInstr *> Worklist; @@ -378,7 +377,7 @@ Expected<MachinePassResult> InstructionSelect::runImplementation(MachineFunction auto Replaced = Function.registerInfo().replaceRegWith(*Destination, *Source); if (!Replaced) return std::unexpected(Replaced.error()); - auto Removed = Block->removeInstruction(*Instruction); + auto Removed = Instruction->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); Result.Changed = true; diff --git a/backend/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/backend/lib/CodeGen/GlobalISel/LegalizerHelper.cpp index 2f1d329..06ec01e 100644 --- a/backend/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ b/backend/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -650,11 +650,7 @@ Expected<void> LegalizerHelper::widenScalarMergeValues(MachineInstr &Instruction return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_MERGE_VALUES became detached during widening"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } auto GCDType = LowLevelType::makeCategoryNeutralScalar(std::gcd(SourceSize, WideSize)); @@ -721,11 +717,7 @@ Expected<void> LegalizerHelper::widenScalarMergeValues(MachineInstr &Instruction return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_MERGE_VALUES became detached during widening"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::widenScalarUnmergeValues(MachineInstr &Instruction, @@ -804,11 +796,7 @@ Expected<void> LegalizerHelper::widenScalarUnmergeValues(MachineInstr &Instructi return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_UNMERGE_VALUES became detached during widening"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } auto LCMType = getLCMType(*SourceType, WideType); @@ -890,11 +878,7 @@ Expected<void> LegalizerHelper::widenScalarUnmergeValues(MachineInstr &Instructi } } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_UNMERGE_VALUES became detached during widening"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::insertParts(Register Destination, LowLevelType ResultType, @@ -1471,11 +1455,7 @@ Expected<void> LegalizerHelper::widenScalarAddSubOverflow(MachineInstr &Instruct if (auto Built = MIRBuilder.buildTrunc(*Destination, *WideResult); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "add/sub overflow instruction became detached during widening"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::widenScalarMulo(MachineInstr &Instruction, std::size_t TypeIndex, @@ -1588,11 +1568,7 @@ Expected<void> LegalizerHelper::widenScalarMulo(MachineInstr &Instruction, std:: return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "multiply-overflow instruction became detached during widening"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::widenScalar(MachineInstr &Instruction, std::size_t TypeIndex, @@ -1815,11 +1791,7 @@ Expected<void> LegalizerHelper::widenScalar(MachineInstr &Instruction, std::size if (auto Built = MIRBuilder.buildZExtOrTrunc(*Destination, *Result); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "bit-count instruction became detached during widening"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_BSWAP: { @@ -2426,11 +2398,7 @@ Expected<void> LegalizerHelper::narrowScalarAddSub(MachineInstr &Instruction, st LeftoverType, LeftoverDestinations); if (!Inserted) return std::unexpected(Inserted.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "add/sub instruction became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalarMul(MachineInstr &Instruction, std::size_t TypeIndex, @@ -2492,11 +2460,7 @@ Expected<void> LegalizerHelper::narrowScalarMul(MachineInstr &Instruction, std:: TemporaryDestinations.end()); if (auto Built = MIRBuilder.buildMergeLikeInstr(*Destination, ResultParts); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "multiply instruction became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalarExt(MachineInstr &Instruction, std::size_t TypeIndex, @@ -2528,11 +2492,7 @@ Expected<void> LegalizerHelper::narrowScalarExt(MachineInstr &Instruction, std:: if (!Remerged) return std::unexpected(Remerged.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "extension instruction became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalarBasic(MachineInstr &Instruction, std::size_t TypeIndex, @@ -2602,11 +2562,7 @@ Expected<void> LegalizerHelper::narrowScalarBasic(MachineInstr &Instruction, std !Inserted) { return std::unexpected(Inserted.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "basic scalar instruction became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalarSelect(MachineInstr &Instruction, std::size_t TypeIndex, @@ -2683,10 +2639,7 @@ Expected<void> LegalizerHelper::narrowScalarSelect(MachineInstr &Instruction, st !Inserted) { return std::unexpected(Inserted.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_SELECT became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalarShiftByConstant(MachineInstr &Instruction, @@ -2711,11 +2664,7 @@ Expected<void> LegalizerHelper::narrowScalarShiftByConstant(MachineInstr &Instru if (Amount.isZero()) { if (auto Built = MIRBuilder.buildMergeLikeInstr(*Destination, {*LowPart, *HighPart}); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "constant shift became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } const std::uint64_t HalfBits = HalfType.minimumBitWidth(); @@ -2880,11 +2829,7 @@ Expected<void> LegalizerHelper::narrowScalarShiftByConstant(MachineInstr &Instru if (auto Built = MIRBuilder.buildMergeLikeInstr(*Destination, {LowResult, HighResult}); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "constant shift became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalarShift(MachineInstr &Instruction, std::size_t TypeIndex, @@ -3057,10 +3002,7 @@ Expected<void> LegalizerHelper::narrowScalarShift(MachineInstr &Instruction, std if (auto Built = MIRBuilder.buildMergeLikeInstr(*Destination, {LowResult, HighResult}); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "shift became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<Register> LegalizerHelper::buildConstantShiftPart(GenericOpcode Generic, @@ -3225,10 +3167,7 @@ Expected<void> LegalizerHelper::narrowScalarShiftByConstantMultiway(MachineInstr if (Amount.isZero()) { if (auto Built = MIRBuilder.buildMergeLikeInstr(*Destination, SourceParts); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "constant multiway shift became detached"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } const std::uint64_t AmountValue = Amount.word(0); @@ -3279,10 +3218,7 @@ Expected<void> LegalizerHelper::narrowScalarShiftByConstantMultiway(MachineInstr } if (auto Built = MIRBuilder.buildMergeLikeInstr(*Destination, DestinationParts); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "constant multiway shift became detached"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalarShiftMultiway(MachineInstr &Instruction, @@ -3419,10 +3355,7 @@ Expected<void> LegalizerHelper::narrowScalarShiftMultiway(MachineInstr &Instruct if (auto Built = MIRBuilder.buildMergeLikeInstr(*Destination, DestinationParts); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "multiway shift became detached"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalarLoadStore(MachineInstr &Instruction, @@ -3508,12 +3441,7 @@ Expected<void> LegalizerHelper::narrowScalarLoadStore(MachineInstr &Instruction, return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) { - return makeUnexpected(ErrorCode::InternalError, - "memory instruction became detached during scalar narrowing"); - } - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } return reduceLoadStoreWidth(Instruction, TypeIndex, NarrowType); @@ -3667,12 +3595,7 @@ Expected<void> LegalizerHelper::reduceLoadStoreWidth(MachineInstr &Instruction, return std::unexpected(Inserted.error()); } } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) { - return makeUnexpected(ErrorCode::InternalError, - "memory instruction became detached during width reduction"); - } - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::narrowScalar(MachineInstr &Instruction, std::size_t TypeIndex, @@ -3730,11 +3653,7 @@ Expected<void> LegalizerHelper::narrowScalar(MachineInstr &Instruction, std::siz return std::unexpected(Merged.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_IMPLICIT_DEF became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_CONSTANT: { const Register *Destination = Instruction.operandAt(0)->getIf<Register>(); @@ -3803,11 +3722,7 @@ Expected<void> LegalizerHelper::narrowScalar(MachineInstr &Instruction, std::siz !Inserted) { return std::unexpected(Inserted.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_CONSTANT became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_ADD: case GenericOpcode::G_SUB: @@ -3935,7 +3850,7 @@ Expected<void> LegalizerHelper::narrowScalar(MachineInstr &Instruction, std::siz if (auto Merged = MIRBuilder.buildMergeLikeInstr(*Destination, Destinations); !Merged) return std::unexpected(Merged.error()); Observer.changedInstr(Instruction); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_FCMP: if (TypeIndex != 0) @@ -4055,11 +3970,7 @@ Expected<void> LegalizerHelper::narrowScalar(MachineInstr &Instruction, std::siz if (auto Merged = MIRBuilder.buildMergeLikeInstr(*Destination, DestinationParts); !Merged) return std::unexpected(Merged.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_SEXT_INREG became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_AND: case GenericOpcode::G_OR: @@ -4232,10 +4143,7 @@ Expected<void> LegalizerHelper::narrowScalar(MachineInstr &Instruction, std::siz } } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_ICMP became detached during narrowing"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } default: return makeUnexpected(ErrorCode::Unsupported, @@ -4356,12 +4264,7 @@ Expected<void> LegalizerHelper::fewerElements(MachineInstr &Instruction, std::si } } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) { - return makeUnexpected(ErrorCode::InternalError, - "vector instruction became detached during legalization"); - } - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerVAArg(MachineInstr &Instruction) { @@ -4496,10 +4399,7 @@ Expected<void> LegalizerHelper::lowerVAArg(MachineInstr &Instruction) { return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::VerificationError, "G_VAARG is detached during legalization"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerLoad(MachineInstr &Instruction) { @@ -4629,10 +4529,7 @@ Expected<void> LegalizerHelper::lowerLoad(MachineInstr &Instruction) { if (auto Truncated = MIRBuilder.buildTrunc(*Destination, LoadDestination); !Truncated) return std::unexpected(Truncated.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "load became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } std::uint64_t LargeSplitBits = 0; @@ -4718,10 +4615,7 @@ Expected<void> LegalizerHelper::lowerLoad(MachineInstr &Instruction) { } } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "load became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerStore(MachineInstr &Instruction) { @@ -4821,10 +4715,7 @@ Expected<void> LegalizerHelper::lowerStore(MachineInstr &Instruction) { return std::unexpected(WideMemory.error()); if (auto Built = BuildStore(*ZeroExtended, *Address, **WideMemory); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "store became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } std::uint64_t LargeSplitBits = 0; @@ -4900,10 +4791,7 @@ Expected<void> LegalizerHelper::lowerStore(MachineInstr &Instruction) { if (auto Built = BuildStore(*SmallValue, *SmallAddress, **SmallMemory); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "store became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lower(MachineInstr &Instruction, @@ -5045,12 +4933,7 @@ Expected<void> LegalizerHelper::lower(MachineInstr &Instruction, if (auto Built = MIRBuilder.buildAShr(Destination, *Temporary, *ShiftAmount); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) { - return makeUnexpected(ErrorCode::InternalError, - "G_SEXT_INREG became detached during lowering"); - } - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_VAARG: return lowerVAArg(Instruction); @@ -5088,12 +4971,7 @@ Expected<void> LegalizerHelper::lower(MachineInstr &Instruction, if (auto Built = MIRBuilder.buildCopy(OldValue, *NewOldValue); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) { - return makeUnexpected(ErrorCode::InternalError, - "G_ATOMIC_CMPXCHG_WITH_SUCCESS became detached during lowering"); - } - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_ATOMICRMW_SUB: { const Register Result = *Instruction.operandAt(0)->getIf<Register>(); @@ -5127,11 +5005,7 @@ Expected<void> LegalizerHelper::lower(MachineInstr &Instruction, if (auto Built = AtomicAdd->build(); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_ATOMICRMW_SUB became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_UADDO: { const Register Result = *Instruction.operandAt(0)->getIf<Register>(); @@ -5151,10 +5025,7 @@ Expected<void> LegalizerHelper::lower(MachineInstr &Instruction, return std::unexpected(Built.error()); if (auto Built = MIRBuilder.buildCopy(Result, *NewResult); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_UADDO became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_UADDE: { const Register Result = *Instruction.operandAt(0)->getIf<Register>(); @@ -5211,10 +5082,7 @@ Expected<void> LegalizerHelper::lower(MachineInstr &Instruction, return std::unexpected(Built.error()); if (auto Built = MIRBuilder.buildCopy(Result, *NewResult); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_UADDE became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_USUBO: { const Register Result = *Instruction.operandAt(0)->getIf<Register>(); @@ -5229,10 +5097,7 @@ Expected<void> LegalizerHelper::lower(MachineInstr &Instruction, MIRBuilder.buildICmp(IntegerPredicate::UnsignedLessThan, BorrowOut, Left, Right); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_USUBO became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } case GenericOpcode::G_USUBE: { const Register Result = *Instruction.operandAt(0)->getIf<Register>(); @@ -5284,10 +5149,7 @@ Expected<void> LegalizerHelper::lower(MachineInstr &Instruction, return std::unexpected(Built.error()); if (auto Built = MIRBuilder.buildOr(BorrowOut, *Borrow, *SecondBorrow); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_USUBE became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } default: { const InstructionDescriptor *Descriptor = @@ -5396,11 +5258,7 @@ Expected<void> LegalizerHelper::lowerDynStackAlloc(MachineInstr &Instruction) { if (auto Built = MIRBuilder.buildCopy(*Destination, *TargetPointer); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_DYN_STACKALLOC became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerStackSave(MachineInstr &Instruction) { @@ -5420,10 +5278,7 @@ Expected<void> LegalizerHelper::lowerStackSave(MachineInstr &Instruction) { !Built) { return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_STACKSAVE became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerStackRestore(MachineInstr &Instruction) { @@ -5440,12 +5295,7 @@ Expected<void> LegalizerHelper::lowerStackRestore(MachineInstr &Instruction) { return std::unexpected(Point.error()); if (auto Built = MIRBuilder.buildCopy(Register::fromPhysical(StackPointer), *Source); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) { - return makeUnexpected(ErrorCode::InternalError, - "G_STACKRESTORE became detached during lowering"); - } - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerMemcpyInline(MachineInstr &Instruction) { @@ -5485,11 +5335,7 @@ Expected<void> LegalizerHelper::lowerMemcpyInline(MachineInstr &Instruction) { } const std::uint64_t KnownLength = ConstantLength->Value.words().front(); if (KnownLength == 0) { - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_MEMCPY_INLINE became detached during legalization"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } auto ByteType = LowLevelType::makeCategoryNeutralScalar(8); @@ -5540,11 +5386,7 @@ Expected<void> LegalizerHelper::lowerMemcpyInline(MachineInstr &Instruction) { return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_MEMCPY_INLINE became detached during legalization"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerAbsToAddXor(MachineInstr &Instruction) { @@ -5574,10 +5416,7 @@ Expected<void> LegalizerHelper::lowerAbsToAddXor(MachineInstr &Instruction) { if (auto Built = MIRBuilder.buildXor(Destination, *Add, *Shift); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_ABS became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerAbsDiffToSelect(MachineInstr &Instruction) { @@ -5618,11 +5457,7 @@ Expected<void> LegalizerHelper::lowerAbsDiffToSelect(MachineInstr &Instruction) return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_ABDS/G_ABDU became detached during select lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerAbsDiffToMinMax(MachineInstr &Instruction) { @@ -5652,11 +5487,7 @@ Expected<void> LegalizerHelper::lowerAbsDiffToMinMax(MachineInstr &Instruction) if (auto Built = MIRBuilder.buildSub(Destination, *Maximum, *Minimum); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "G_ABDS/G_ABDU became detached during min/max lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerMinMax(MachineInstr &Instruction) { @@ -5686,11 +5517,7 @@ Expected<void> LegalizerHelper::lowerMinMax(MachineInstr &Instruction) { return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "integer min/max became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerThreewayCompare(MachineInstr &Instruction) { @@ -5770,11 +5597,7 @@ Expected<void> LegalizerHelper::lowerThreewayCompare(MachineInstr &Instruction) return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "three-way comparison became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerDivRem(MachineInstr &Instruction) { @@ -5797,10 +5620,7 @@ Expected<void> LegalizerHelper::lowerDivRem(MachineInstr &Instruction) { return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "DIVREM became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerHighMultiply(MachineInstr &Instruction) { @@ -5867,11 +5687,7 @@ Expected<void> LegalizerHelper::lowerHighMultiply(MachineInstr &Instruction) { if (auto Built = MIRBuilder.buildTrunc(*Destination, *Shifted); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "high multiply instruction became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerMulo(MachineInstr &Instruction) { @@ -5974,11 +5790,7 @@ Expected<void> LegalizerHelper::lowerBitCount(MachineInstr &Instruction) { Decision->Action == LegalizationAction::Custom; }; const auto EraseOriginal = [&Instruction]() -> Expected<void> { - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "bit-count instruction became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); }; switch (Generic) { @@ -6397,10 +6209,7 @@ Expected<void> LegalizerHelper::lowerBswap(MachineInstr &Instruction) { } } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "G_BSWAP became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerFunnelShift(MachineInstr &Instruction) { @@ -6514,11 +6323,7 @@ Expected<void> LegalizerHelper::lowerFunnelShift(MachineInstr &Instruction) { if (auto Built = Result->build(); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) { - return makeUnexpected(ErrorCode::InternalError, "funnel shift became detached during lowering"); - } - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerRotate(MachineInstr &Instruction) { @@ -6618,10 +6423,7 @@ Expected<void> LegalizerHelper::lowerRotate(MachineInstr &Instruction) { if (auto Built = Result->build(); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "rotate became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::libcall(MachineInstr &Instruction) { @@ -6810,10 +6612,7 @@ Expected<void> LegalizerHelper::libcall(MachineInstr &Instruction) { return std::unexpected(Merged.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "libcall became detached during legalization"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerSignedAddSubOverflow(MachineInstr &Instruction) { @@ -6909,11 +6708,7 @@ Expected<void> LegalizerHelper::lowerSignedAddSubOverflow(MachineInstr &Instruct return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "signed extended add/sub instruction became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } const bool IsAdd = Instruction.opcode() == opcode(GenericOpcode::G_SADDO); @@ -6978,11 +6773,7 @@ Expected<void> LegalizerHelper::lowerSignedAddSubOverflow(MachineInstr &Instruct if (auto Built = MIRBuilder.buildCopy(Destination, *Result); !Built) return std::unexpected(Built.error()); - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "signed add/sub overflow instruction became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerSaturatingAddSubToMinMax(MachineInstr &Instruction) { @@ -7118,11 +6909,7 @@ Expected<void> LegalizerHelper::lowerSaturatingAddSubToMinMax(MachineInstr &Inst } } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "saturating add/sub became detached during min/max lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerSaturatingAddSubToOverflow(MachineInstr &Instruction) { @@ -7213,11 +7000,7 @@ Expected<void> LegalizerHelper::lowerSaturatingAddSubToOverflow(MachineInstr &In !Built) { return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "saturating add/sub became detached during overflow lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::lowerSaturatingShiftLeft(MachineInstr &Instruction) { @@ -7305,11 +7088,7 @@ Expected<void> LegalizerHelper::lowerSaturatingShiftLeft(MachineInstr &Instructi return std::unexpected(Built.error()); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, - "saturating shift-left became detached during lowering"); - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } Expected<void> LegalizerHelper::legalize(MachineInstr &Instruction, diff --git a/backend/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/backend/lib/CodeGen/GlobalISel/RegBankSelect.cpp index 3b7932b..b09fdac 100644 --- a/backend/lib/CodeGen/GlobalISel/RegBankSelect.cpp +++ b/backend/lib/CodeGen/GlobalISel/RegBankSelect.cpp @@ -169,7 +169,7 @@ struct MappingMutation final { auto Replaced = Operand.setRegister(*Fresh); if (!Replaced) { if ((*Copy)->parent() != nullptr) { - auto Removed = (*Copy)->parent()->removeInstruction(**Copy); + auto Removed = (*Copy)->eraseFromParent(); (void)Removed; } auto Erased = Function.registerInfo().eraseVirtualRegister(*Fresh); @@ -188,7 +188,7 @@ struct MappingMutation final { if (!Restored) return std::unexpected(Restored.error()); if (Iterator->Copy != nullptr && Iterator->Copy->parent() != nullptr) { - auto Removed = Iterator->Copy->parent()->removeInstruction(*Iterator->Copy); + auto Removed = Iterator->Copy->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); } diff --git a/backend/lib/CodeGen/GlobalISel/Utils.cpp b/backend/lib/CodeGen/GlobalISel/Utils.cpp index 7e594ce..0f8d638 100644 --- a/backend/lib/CodeGen/GlobalISel/Utils.cpp +++ b/backend/lib/CodeGen/GlobalISel/Utils.cpp @@ -65,10 +65,7 @@ namespace { if (Definition != nullptr && Definition != &Instruction) DeadChain.push_back(Definition); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return {}; - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } [[nodiscard]] Expected<LowLevelType> makeVectorType(std::uint64_t ElementCount, bool IsScalable, @@ -248,8 +245,9 @@ Expected<void> eraseInstrs(std::span<MachineInstr *const> Instructions, MachineR const TargetDescription &Target) { std::vector<MachineInstr *> DeadChain; for (MachineInstr *Instruction : Instructions) { - if (Instruction == nullptr || Instruction->parent() == nullptr) - continue; + if (Instruction == nullptr) + return makeUnexpected(ErrorCode::InvalidArgument, + "instruction erasure list contains a null instruction"); auto Removed = saveUsesAndErase(*Instruction, MRI, DeadChain); if (!Removed) return std::unexpected(Removed.error()); @@ -258,8 +256,7 @@ Expected<void> eraseInstrs(std::span<MachineInstr *const> Instructions, MachineR while (!DeadChain.empty()) { MachineInstr *Instruction = DeadChain.back(); DeadChain.pop_back(); - if (Instruction == nullptr || Instruction->parent() == nullptr || - !isTriviallyDead(*Instruction, MRI, Target)) + if (Instruction->parent() == nullptr || !isTriviallyDead(*Instruction, MRI, Target)) continue; auto Removed = saveUsesAndErase(*Instruction, MRI, DeadChain); if (!Removed) diff --git a/backend/lib/CodeGen/InlineSpiller.cpp b/backend/lib/CodeGen/InlineSpiller.cpp index 4aa43ce..4243e84 100644 --- a/backend/lib/CodeGen/InlineSpiller.cpp +++ b/backend/lib/CodeGen/InlineSpiller.cpp @@ -80,8 +80,8 @@ Expected<std::optional<std::vector<Register>>> Spiller::tryRematerialize(Registe if (ActionAnalyses != nullptr) { for (const UseSite &Site : Sites) { - auto Accepted = ActionAnalyses->requestAction("rematerialize", *Function, - Site.Instruction->stableID()); + auto Accepted = + ActionAnalyses->requestAction("rematerialize", *Function, Site.Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) @@ -123,8 +123,7 @@ Expected<std::optional<std::vector<Register>>> Spiller::tryRematerialize(Registe } } if (!HasNonDebugUse) { - MachineBasicBlock *Block = const_cast<MachineBasicBlock *>(DefiningInstruction->parent()); - auto Removed = Block->removeInstruction(*const_cast<MachineInstr *>(DefiningInstruction)); + auto Removed = const_cast<MachineInstr *>(DefiningInstruction)->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); } @@ -288,9 +287,9 @@ Expected<std::vector<Register>> Spiller::spill(Register VirtualReg) { if (ActionAnalyses != nullptr) { const MachineOperand *Definition = Function->registerInfo().getUniqueVRegDef(VirtualReg); const MachineInstr *Instruction = Definition == nullptr ? nullptr : Definition->parent(); - auto Accepted = ActionAnalyses->requestAction( - "spill", *Function, - Instruction == nullptr ? MachineInstrStableID{} : Instruction->stableID()); + auto Accepted = ActionAnalyses->requestAction("spill", *Function, + Instruction == nullptr ? MachineInstrStableID{} + : Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) { diff --git a/backend/lib/CodeGen/MachineCFGUpdater.cpp b/backend/lib/CodeGen/MachineCFGUpdater.cpp index 4aacdf5..050071e 100644 --- a/backend/lib/CodeGen/MachineCFGUpdater.cpp +++ b/backend/lib/CodeGen/MachineCFGUpdater.cpp @@ -489,7 +489,7 @@ Expected<MachineBasicBlock *> MachineCFGUpdater::splitBlock(MachineBasicBlock &B MachineInstr *Instruction = &SplitBefore; while (Instruction != nullptr) { MachineInstr *Next = Instruction->next(); - auto Removed = Block.removeInstruction(*Instruction); + auto Removed = Instruction->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); auto Appended = NewBlock->appendInstruction(*Instruction); diff --git a/backend/lib/CodeGen/MachineCSE.cpp b/backend/lib/CodeGen/MachineCSE.cpp index 7bd5a22..353cbaa 100644 --- a/backend/lib/CodeGen/MachineCSE.cpp +++ b/backend/lib/CodeGen/MachineCSE.cpp @@ -258,15 +258,12 @@ replacementPairs(const MachineInstr &Available, const MachineInstr &Redundant, replaceAndErase(MachineInstr &Redundant, const std::vector<std::pair<Register, Register>> &Replacements, MachineRegisterInfo &Registers) { - MachineBasicBlock *Block = Redundant.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "machine CSE candidate is detached"); for (const auto &[OldReg, NewReg] : Replacements) { auto Replaced = Registers.replaceRegWith(OldReg, NewReg); if (!Replaced) return std::unexpected(Replaced.error()); } - auto Removed = Block->removeInstruction(Redundant); + auto Removed = Redundant.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); for (const auto &[OldReg, NewReg] : Replacements) { diff --git a/backend/lib/CodeGen/MachineCombiner.cpp b/backend/lib/CodeGen/MachineCombiner.cpp index 4c2ff88..4341700 100644 --- a/backend/lib/CodeGen/MachineCombiner.cpp +++ b/backend/lib/CodeGen/MachineCombiner.cpp @@ -175,18 +175,11 @@ namespace { if (!Fused) return std::unexpected(Fused.error()); - MachineBasicBlock *Block = Root.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "machine combiner root is detached"); - auto Removed = Block->removeInstruction(Root); + auto Removed = Root.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); if (EraseProducer) { - MachineBasicBlock *ProducerBlock = Producer.parent(); - if (ProducerBlock == nullptr) { - return makeUnexpected(ErrorCode::InternalError, "machine combiner producer is detached"); - } - Removed = ProducerBlock->removeInstruction(Producer); + Removed = Producer.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); } diff --git a/backend/lib/CodeGen/MachineCopyPropagation.cpp b/backend/lib/CodeGen/MachineCopyPropagation.cpp index 9cb64cb..94d83e3 100644 --- a/backend/lib/CodeGen/MachineCopyPropagation.cpp +++ b/backend/lib/CodeGen/MachineCopyPropagation.cpp @@ -232,7 +232,7 @@ struct CopyOperands final { if (*Destination == *Source) { if (!IsGenericCopy) return false; - auto Removed = Block->removeInstruction(Copy); + auto Removed = Copy.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); return true; @@ -285,7 +285,7 @@ struct CopyOperands final { if (IsGenericCopy && Operands.DestinationOperand->registerFlags().has(RegisterOperandFlag::Renamable) && !valueUsedAfter(Copy, *Destination, Target)) { - auto Removed = Block->removeInstruction(Copy); + auto Removed = Copy.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); Changed = true; @@ -326,8 +326,7 @@ MachineCopyPropagationPass::runImplementation(MachineFunction &Function, Instruction = Next; continue; } - auto Accepted = - Analyses.requestAction("propagate-copy", Function, Instruction->stableID()); + auto Accepted = Analyses.requestAction("propagate-copy", Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) { diff --git a/backend/lib/CodeGen/MachineDCE.cpp b/backend/lib/CodeGen/MachineDCE.cpp index 269999b..734509f 100644 --- a/backend/lib/CodeGen/MachineDCE.cpp +++ b/backend/lib/CodeGen/MachineDCE.cpp @@ -140,7 +140,7 @@ Expected<MachinePassResult> MachineDCEPass::runImplementation(MachineFunction &F if (!Cleared) return std::unexpected(Cleared.error()); } - auto Removed = Block->removeInstruction(*Instruction); + auto Removed = Instruction->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); for (const Register Reg : DefinitionList) { diff --git a/backend/lib/CodeGen/MachineInstr.cpp b/backend/lib/CodeGen/MachineInstr.cpp index 55b4ce9..3b200c5 100644 --- a/backend/lib/CodeGen/MachineInstr.cpp +++ b/backend/lib/CodeGen/MachineInstr.cpp @@ -43,6 +43,12 @@ Expected<void> MachineInstr::setOpcode(Opcode NewOpcode) { return {}; } +Expected<void> MachineInstr::eraseFromParent() { + if (ParentBlock == nullptr) + return makeUnexpected(ErrorCode::InternalError, "cannot erase a detached machine instruction"); + return ParentBlock->removeInstruction(*this); +} + Expected<void> MachineInstr::setDebugInstrNumber(std::uint64_t Number) { if (Number == 0 || Number > std::numeric_limits<std::uint32_t>::max()) { return makeUnexpected(ErrorCode::InvalidArgument, diff --git a/backend/lib/CodeGen/MachineLICM.cpp b/backend/lib/CodeGen/MachineLICM.cpp index 6ab15dc..3863388 100644 --- a/backend/lib/CodeGen/MachineLICM.cpp +++ b/backend/lib/CodeGen/MachineLICM.cpp @@ -303,7 +303,7 @@ operandsAreInvariant(const MachineInstr &Instruction, const MachineLoop &Loop, auto Anchor = firstTerminator(Preheader, Target); if (!Anchor) return std::unexpected(Anchor.error()); - auto Removed = Source->removeInstruction(Instruction); + auto Removed = Instruction.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); if (*Anchor != nullptr) diff --git a/backend/lib/CodeGen/MachineOutliner.cpp b/backend/lib/CodeGen/MachineOutliner.cpp index bdc4d2b..a36a740 100644 --- a/backend/lib/CodeGen/MachineOutliner.cpp +++ b/backend/lib/CodeGen/MachineOutliner.cpp @@ -473,7 +473,7 @@ buildSequenceGroups(std::vector<InstructionSegment> &Segments, if (!Inserted) return std::unexpected(Inserted.error()); for (MachineInstr *Instruction : Candidate.Instructions) { - auto Removed = Candidate.Block->removeInstruction(*Instruction); + auto Removed = Instruction->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); } diff --git a/backend/lib/CodeGen/MachineScheduler.cpp b/backend/lib/CodeGen/MachineScheduler.cpp index dfc7b24..65f1e01 100644 --- a/backend/lib/CodeGen/MachineScheduler.cpp +++ b/backend/lib/CodeGen/MachineScheduler.cpp @@ -302,7 +302,7 @@ scheduleRegion(MachineBasicBlock &Block, std::span<MachineInstr *const> Instruct MachineInstr *Anchor = Instructions.back()->next(); for (MachineInstr *Instruction : Instructions) { - auto Removed = Block.removeInstruction(*Instruction); + auto Removed = Instruction->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); } @@ -323,8 +323,7 @@ runMachineScheduler(MachineFunction &Function, const TargetDescription &Target, const TargetSchedulingModel &Model, ScheduleDAGMode Mode, const LiveVariablesAnalysis::Result &Liveness, const MachineBlockFrequencyAnalysis::Result &Frequencies, - MachineSchedulerOptions Options, - MachineFunctionAnalysisManager &Analyses) { + MachineSchedulerOptions Options, MachineFunctionAnalysisManager &Analyses) { if (Options.MaximumRegionSize == 0) { return makeUnexpected(ErrorCode::InvalidArgument, "machine scheduler region budget must be nonzero"); diff --git a/backend/lib/CodeGen/MachineSink.cpp b/backend/lib/CodeGen/MachineSink.cpp index dda2048..f82f3a7 100644 --- a/backend/lib/CodeGen/MachineSink.cpp +++ b/backend/lib/CodeGen/MachineSink.cpp @@ -327,7 +327,7 @@ findPostRADestination(MachineInstr &Instruction, const MachineFunction &Function MachineBasicBlock *Source = Instruction.parent(); if (Source == nullptr || Destination.Block == nullptr || Destination.FirstUse == nullptr) return makeUnexpected(ErrorCode::InternalError, "machine sink has an invalid move plan"); - auto Removed = Source->removeInstruction(Instruction); + auto Removed = Instruction.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); return Destination.Block->insertInstructionBefore(*Destination.FirstUse, Instruction); diff --git a/backend/lib/CodeGen/MachineStripDebug.cpp b/backend/lib/CodeGen/MachineStripDebug.cpp index 4699ef0..46d92d1 100644 --- a/backend/lib/CodeGen/MachineStripDebug.cpp +++ b/backend/lib/CodeGen/MachineStripDebug.cpp @@ -14,7 +14,7 @@ Expected<bool> stripDebugMachineFunction(MachineFunction &Function) { for (MachineInstr *Instruction = Block->firstInstruction(); Instruction != nullptr;) { MachineInstr *Next = Instruction->next(); if (Instruction->isDebugInstr() && Instruction->operandCount() > 1) { - auto Removed = Block->removeInstruction(*Instruction); + auto Removed = Instruction->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); Changed = true; diff --git a/backend/lib/CodeGen/PHIElimination.cpp b/backend/lib/CodeGen/PHIElimination.cpp index 677a04c..8ad785e 100644 --- a/backend/lib/CodeGen/PHIElimination.cpp +++ b/backend/lib/CodeGen/PHIElimination.cpp @@ -479,10 +479,9 @@ Expected<MachinePassResult> PHIEliminationPass::run(MachineFunction &Function, return runImplementation(Function, Target, Analyses); } -Expected<MachinePassResult> PHIEliminationPass::runImplementation(MachineFunction &Function, - const TargetDescription &Target, - MachineFunctionAnalysisManager - &Analyses) { +Expected<MachinePassResult> +PHIEliminationPass::runImplementation(MachineFunction &Function, const TargetDescription &Target, + MachineFunctionAnalysisManager &Analyses) { MachinePassResult Result; std::unordered_map<EdgeKey, MachineBasicBlock *, EdgeKeyHash> SplitEdges; const std::vector<MachineBasicBlock *> Blocks(Function.allBlocks().begin(), @@ -552,7 +551,7 @@ Expected<MachinePassResult> PHIEliminationPass::runImplementation(MachineFunctio } for (PhiPlan &Plan : *Plans) { - auto Removed = Block->removeInstruction(*Plan.Instruction); + auto Removed = Plan.Instruction->eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); } diff --git a/backend/lib/CodeGen/TwoAddressInstructionPass.cpp b/backend/lib/CodeGen/TwoAddressInstructionPass.cpp index 80da2e8..d7a5ef1 100644 --- a/backend/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/backend/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -175,13 +175,6 @@ buildImplicitDef(MachineFunction &Function, const TargetDescription &Target, return *Composed; } -[[nodiscard]] Expected<void> removeInstruction(MachineInstr &Instruction) { - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "rewritten instruction is not linked"); - return Block->removeInstruction(Instruction); -} - [[nodiscard]] Expected<void> expandRegSequence(MachineInstr &Instruction, MachineFunction &Function, const TargetDescription &Target, const TargetInstrInfo &TargetInfo) { @@ -240,7 +233,7 @@ buildImplicitDef(MachineFunction &Function, const TargetDescription &Target, if (!Copy) return std::unexpected(Copy.error()); } - return removeInstruction(Instruction); + return Instruction.eraseFromParent(); } [[nodiscard]] Expected<void> expandInsertSubreg(MachineInstr &Instruction, @@ -309,7 +302,7 @@ buildImplicitDef(MachineFunction &Function, const TargetDescription &Target, if (!Copy) return std::unexpected(Copy.error()); } - return removeInstruction(Instruction); + return Instruction.eraseFromParent(); } [[nodiscard]] Expected<void> swapRegisterUses(MachineOperand &Left, MachineOperand &Right) { @@ -450,9 +443,10 @@ TwoAddressInstructionPass::run(MachineFunction &Function, const TargetDescriptio return runImplementation(Function, Target, Analyses); } -Expected<MachinePassResult> TwoAddressInstructionPass::runImplementation( - MachineFunction &Function, const TargetDescription &Target, - MachineFunctionAnalysisManager &Analyses) { +Expected<MachinePassResult> +TwoAddressInstructionPass::runImplementation(MachineFunction &Function, + const TargetDescription &Target, + MachineFunctionAnalysisManager &Analyses) { MachinePassResult Result; const std::vector<MachineInstr *> Instructions(Function.allInstructions().begin(), Function.allInstructions().end()); |
