Skip to content

Commit

Permalink
Revert "Revert "Revert "[GlobalISel][IRTranslator] Emit trap intrinsi…
Browse files Browse the repository at this point in the history
…c for "unreachable""""

This reverts commit c93bc50.

Seems to break a different thing now.
  • Loading branch information
aemerson committed Oct 5, 2021
1 parent c6c13c5 commit de5b16d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 66 deletions.
5 changes: 3 additions & 2 deletions llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
Expand Up @@ -467,8 +467,9 @@ class IRTranslator : public MachineFunctionPass {
bool translateSIToFP(const User &U, MachineIRBuilder &MIRBuilder) {
return translateCast(TargetOpcode::G_SITOFP, U, MIRBuilder);
}
bool translateUnreachable(const User &U, MachineIRBuilder &MIRBuilder);

bool translateUnreachable(const User &U, MachineIRBuilder &MIRBuilder) {
return true;
}
bool translateSExt(const User &U, MachineIRBuilder &MIRBuilder) {
return translateCast(TargetOpcode::G_SEXT, U, MIRBuilder);
}
Expand Down
22 changes: 0 additions & 22 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Expand Up @@ -2701,28 +2701,6 @@ bool IRTranslator::translateVAArg(const User &U, MachineIRBuilder &MIRBuilder) {
return true;
}

bool IRTranslator::translateUnreachable(const User &U, MachineIRBuilder &MIRBuilder) {
if (!MF->getTarget().Options.TrapUnreachable)
return true;

auto &UI = cast<UnreachableInst>(U);
// We may be able to ignore unreachable behind a noreturn call.
if (MF->getTarget().Options.NoTrapAfterNoreturn) {
const BasicBlock &BB = *UI.getParent();
if (&UI != &BB.front()) {
BasicBlock::const_iterator PredI =
std::prev(BasicBlock::const_iterator(UI));
if (const CallInst *Call = dyn_cast<CallInst>(&*PredI)) {
if (Call->doesNotReturn())
return true;
}
}
}

MIRBuilder.buildIntrinsic(Intrinsic::trap, ArrayRef<Register>(), true);
return true;
}

bool IRTranslator::translateInsertElement(const User &U,
MachineIRBuilder &MIRBuilder) {
// If it is a <1 x Ty> vector, use the scalar as it is
Expand Down
18 changes: 0 additions & 18 deletions llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
Expand Up @@ -20,7 +20,6 @@
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
#include "llvm/CodeGen/GlobalISel/Utils.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
Expand Down Expand Up @@ -132,12 +131,8 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
const size_t NumBlocks = MF.size();
#endif

// Keep track of selected blocks, so we can delete unreachable ones later.
DenseSet<MachineBasicBlock *> SelectedBlocks;

for (MachineBasicBlock *MBB : post_order(&MF)) {
ISel->CurMBB = MBB;
SelectedBlocks.insert(MBB);
if (MBB->empty())
continue;

Expand Down Expand Up @@ -206,20 +201,10 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
}
}

SmallVector<MachineBasicBlock *> BlocksToDelete;
for (MachineBasicBlock &MBB : MF) {
if (MBB.empty())
continue;

if (!SelectedBlocks.contains(&MBB)) {
// This is an unreachable block and therefore hasn't been selected, since
// the main selection loop above uses a postorder block traversal. Mark
// the block for deletion.
if (!MBB.hasAddressTaken())
BlocksToDelete.push_back(&MBB);
continue;
}

// Try to find redundant copies b/w vregs of the same register class.
bool ReachedBegin = false;
for (auto MII = std::prev(MBB.end()), Begin = MBB.begin(); !ReachedBegin;) {
Expand Down Expand Up @@ -288,9 +273,6 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
return false;
}
#endif
for (auto *MBB : BlocksToDelete)
MBB->eraseFromParent();

// Determine if there are any calls in this machine function. Ported from
// SelectionDAG.
MachineFrameInfo &MFI = MF.getFrameInfo();
Expand Down
24 changes: 0 additions & 24 deletions llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unreachable.ll

This file was deleted.

0 comments on commit de5b16d

Please sign in to comment.