137 changes: 0 additions & 137 deletions llvm/include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3991,143 +3991,6 @@ struct OperandTraits<CatchSwitchInst> : public HungoffOperandTraits<2> {};

DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchSwitchInst, Value)

//===----------------------------------------------------------------------===//
// TerminatePadInst Class
//===----------------------------------------------------------------------===//

class TerminatePadInst : public TerminatorInst {
private:
void init(Value *ParentPad, BasicBlock *BB, ArrayRef<Value *> Args);

TerminatePadInst(const TerminatePadInst &TPI);

explicit TerminatePadInst(Value *ParentPad, BasicBlock *BB,
ArrayRef<Value *> Args, unsigned Values,
Instruction *InsertBefore);
explicit TerminatePadInst(Value *ParentPad, BasicBlock *BB,
ArrayRef<Value *> Args, unsigned Values,
BasicBlock *InsertAtEnd);

protected:
// Note: Instruction needs to be a friend here to call cloneImpl.
friend class Instruction;
TerminatePadInst *cloneImpl() const;

public:
static TerminatePadInst *Create(Value *ParentPad, BasicBlock *BB = nullptr,
ArrayRef<Value *> Args = None,
Instruction *InsertBefore = nullptr) {
unsigned Values = unsigned(Args.size()) + 1;
if (BB)
++Values;
return new (Values)
TerminatePadInst(ParentPad, BB, Args, Values, InsertBefore);
}
static TerminatePadInst *Create(Value *ParentPad, BasicBlock *BB,
ArrayRef<Value *> Args,
BasicBlock *InsertAtEnd) {
unsigned Values = unsigned(Args.size()) + 1;
if (BB)
++Values;
return new (Values)
TerminatePadInst(ParentPad, BB, Args, Values, InsertAtEnd);
}

/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);

bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
bool unwindsToCaller() const { return !hasUnwindDest(); }

/// getNumArgOperands - Return the number of terminatepad arguments.
///
unsigned getNumArgOperands() const {
unsigned NumOperands = getNumOperands();
if (hasUnwindDest())
return NumOperands - 2;
return NumOperands - 1;
}

/// Convenience accessors
Value *getParentPad() const { return Op<-1>(); }
void setParentPad(Value *ParentPad) {
assert(ParentPad);
Op<-1>() = ParentPad;
}

/// getArgOperand/setArgOperand - Return/set the i-th terminatepad argument.
///
Value *getArgOperand(unsigned i) const { return getOperand(i); }
void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }

const_op_iterator arg_begin() const { return op_begin(); }
op_iterator arg_begin() { return op_begin(); }

const_op_iterator arg_end() const {
if (hasUnwindDest())
return op_end() - 2;
return op_end() - 1;
}

op_iterator arg_end() {
if (hasUnwindDest())
return op_end() - 2;
return op_end() - 1;
}

/// arg_operands - iteration adapter for range-for loops.
iterator_range<op_iterator> arg_operands() {
return make_range(arg_begin(), arg_end());
}

/// arg_operands - iteration adapter for range-for loops.
iterator_range<const_op_iterator> arg_operands() const {
return make_range(arg_begin(), arg_end());
}

/// \brief Wrappers for getting the \c Use of a terminatepad argument.
const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }

// get*Dest - Return the destination basic blocks...
BasicBlock *getUnwindDest() const {
if (!hasUnwindDest())
return nullptr;
return cast<BasicBlock>(Op<-2>());
}
void setUnwindDest(BasicBlock *B) {
assert(B && hasUnwindDest());
Op<-2>() = B;
}

unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }

// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::TerminatePad;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}

private:
BasicBlock *getSuccessorV(unsigned idx) const override;
unsigned getNumSuccessorsV() const override;
void setSuccessorV(unsigned idx, BasicBlock *B) override;

// Shadow Instruction::setInstructionSubclassData with a private forwarding
// method so that subclasses cannot accidentally use it.
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};

template <>
struct OperandTraits<TerminatePadInst>
: public VariadicOperandTraits<TerminatePadInst, /*MINARITY=*/1> {};

DEFINE_TRANSPARENT_OPERAND_ACCESSORS(TerminatePadInst, Value)

//===----------------------------------------------------------------------===//
// CleanupPadInst Class
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/Utils/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
DIBuilder &Builder, bool Deref, int Offset = 0);

/// Replace 'BB's terminator with one that does not have an unwind successor
/// block. Rewrites `invoke` to `call`, `terminatepad unwind label %foo` to
/// `terminatepad unwind to caller`, etc. Updates any PHIs in unwind successor.
/// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
/// successor.
///
/// \param BB Block whose terminator will be replaced. Its terminator must
/// have an unwind successor.
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Analysis/EHPersonalities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ DenseMap<BasicBlock *, ColorVector> llvm::colorEHFunclets(Function &F) {
// contain" is used to distinguish from being "transitively contained" in
// a nested funclet).
//
// Note: Despite not being funclets in the truest sense, terminatepad and
// catchswitch are considered to belong to their own funclet for the purposes
// of coloring.
// Note: Despite not being a funclet in the truest sense, a catchswitch is
// considered to belong to its own funclet for the purposes of coloring.

DEBUG_WITH_TYPE("winehprepare-coloring", dbgs() << "\nColoring funclets for "
<< F.getName() << "\n");
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Analysis/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ static BasicBlock::iterator findInsertPointAfter(Instruction *I,
while (IP->isEHPad()) {
if (isa<FuncletPadInst>(IP) || isa<LandingPadInst>(IP)) {
++IP;
} else if (auto *TPI = dyn_cast<TerminatePadInst>(IP)) {
IP = TPI->getUnwindDest()->getFirstNonPHI()->getIterator();
} else if (isa<CatchSwitchInst>(IP)) {
IP = MustDominate->getFirstInsertionPt();
} else {
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3436,7 +3436,6 @@ bool llvm::isSafeToSpeculativelyExecute(const Value *V,
case Instruction::CatchRet:
case Instruction::CleanupPad:
case Instruction::CleanupRet:
case Instruction::TerminatePad:
return false; // Misc instructions which have effects
}
}
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/AsmParser/LLLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,6 @@ lltok::Kind LLLexer::LexIdentifier() {
INSTKEYWORD(catchret, CatchRet);
INSTKEYWORD(catchswitch, CatchSwitch);
INSTKEYWORD(catchpad, CatchPad);
INSTKEYWORD(terminatepad, TerminatePad);
INSTKEYWORD(cleanuppad, CleanupPad);
#undef INSTKEYWORD

Expand Down
38 changes: 0 additions & 38 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4723,7 +4723,6 @@ int LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
case lltok::kw_catchret: return ParseCatchRet(Inst, PFS);
case lltok::kw_catchswitch: return ParseCatchSwitch(Inst, PFS);
case lltok::kw_catchpad: return ParseCatchPad(Inst, PFS);
case lltok::kw_terminatepad:return ParseTerminatePad(Inst, PFS);
case lltok::kw_cleanuppad: return ParseCleanupPad(Inst, PFS);
// Binary Operators.
case lltok::kw_add:
Expand Down Expand Up @@ -5285,43 +5284,6 @@ bool LLParser::ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS) {
return false;
}

/// ParseTerminatePad
/// ::= 'terminatepad' within Parent ParamList 'to' TypeAndValue
bool LLParser::ParseTerminatePad(Instruction *&Inst, PerFunctionState &PFS) {
Value *ParentPad = nullptr;

if (ParseToken(lltok::kw_within, "expected 'within' after terminatepad"))
return true;

if (Lex.getKind() != lltok::kw_none && Lex.getKind() != lltok::LocalVar &&
Lex.getKind() != lltok::LocalVarID)
return TokError("expected scope value for terminatepad");

if (ParseValue(Type::getTokenTy(Context), ParentPad, PFS))
return true;

SmallVector<Value *, 8> Args;
if (ParseExceptionArgs(Args, PFS))
return true;

if (ParseToken(lltok::kw_unwind, "expected 'unwind' in terminatepad"))
return true;

BasicBlock *UnwindBB = nullptr;
if (Lex.getKind() == lltok::kw_to) {
Lex.Lex();
if (ParseToken(lltok::kw_caller, "expected 'caller' in terminatepad"))
return true;
} else {
if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
return true;
}
}

Inst = TerminatePadInst::Create(ParentPad, UnwindBB, Args);
return false;
}

/// ParseCleanupPad
/// ::= 'cleanuppad' within Parent ParamList
bool LLParser::ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS) {
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/AsmParser/LLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ namespace llvm {
bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
bool ParseTerminatePad(Instruction *&Inst, PerFunctionState &PFS);
bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);

bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/AsmParser/LLToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ namespace lltok {

kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_resume,
kw_unreachable, kw_cleanupret, kw_catchswitch, kw_catchret, kw_catchpad,
kw_terminatepad, kw_cleanuppad,
kw_cleanuppad,

kw_alloca, kw_load, kw_store, kw_fence, kw_cmpxchg, kw_atomicrmw,
kw_getelementptr,
Expand Down
34 changes: 0 additions & 34 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4484,40 +4484,6 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
InstructionList.push_back(I);
break;
}
case bitc::FUNC_CODE_INST_TERMINATEPAD: { // TERMINATEPAD: [tok,bb#,num,(ty,val)*]
// We must have, at minimum, the outer scope and the number of arguments.
if (Record.size() < 2)
return error("Invalid record");

unsigned Idx = 0;

Value *ParentPad =
getValue(Record, Idx++, NextValueNo, Type::getTokenTy(Context));

unsigned NumArgOperands = Record[Idx++];

SmallVector<Value *, 2> Args;
for (unsigned Op = 0; Op != NumArgOperands; ++Op) {
Value *Val;
if (getValueTypePair(Record, Idx, NextValueNo, Val))
return error("Invalid record");
Args.push_back(Val);
}

BasicBlock *UnwindDest = nullptr;
if (Idx + 1 == Record.size()) {
UnwindDest = getBasicBlock(Record[Idx++]);
if (!UnwindDest)
return error("Invalid record");
}

if (Record.size() != Idx)
return error("Invalid record");

I = TerminatePadInst::Create(ParentPad, UnwindDest, Args);
InstructionList.push_back(I);
break;
}
case bitc::FUNC_CODE_INST_CATCHPAD:
case bitc::FUNC_CODE_INST_CLEANUPPAD: { // [tok,num,(ty,val)*]
// We must have, at minimum, the outer scope and the number of arguments.
Expand Down
15 changes: 0 additions & 15 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2025,21 +2025,6 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
Vals.push_back(VE.getValueID(CatchSwitch.getUnwindDest()));
break;
}
case Instruction::TerminatePad: {
Code = bitc::FUNC_CODE_INST_TERMINATEPAD;
const auto &TPI = cast<TerminatePadInst>(I);

pushValue(TPI.getParentPad(), InstID, Vals, VE);

unsigned NumArgOperands = TPI.getNumArgOperands();
Vals.push_back(NumArgOperands);
for (unsigned Op = 0; Op != NumArgOperands; ++Op)
PushValueAndType(TPI.getArgOperand(Op), InstID, Vals, VE);

if (TPI.hasUnwindDest())
Vals.push_back(VE.getValueID(TPI.getUnwindDest()));
break;
}
case Instruction::Unreachable:
Code = bitc::FUNC_CODE_INST_UNREACHABLE;
AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
Expand Down
8 changes: 2 additions & 6 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,8 +1230,8 @@ void SelectionDAGBuilder::visitCleanupPad(const CleanupPadInst &CPI) {
/// When an invoke or a cleanupret unwinds to the next EH pad, there are
/// many places it could ultimately go. In the IR, we have a single unwind
/// destination, but in the machine CFG, we enumerate all the possible blocks.
/// This function skips over imaginary basic blocks that hold catchswitch or
/// terminatepad instructions, and finds all the "real" machine
/// This function skips over imaginary basic blocks that hold catchswitch
/// instructions, and finds all the "real" machine
/// basic block destinations. As those destinations may not be successors of
/// EHPadBB, here we also calculate the edge probability to those destinations.
/// The passed-in Prob is the edge probability to EHPadBB.
Expand Down Expand Up @@ -1300,10 +1300,6 @@ void SelectionDAGBuilder::visitCleanupRet(const CleanupReturnInst &I) {
DAG.setRoot(Ret);
}

void SelectionDAGBuilder::visitTerminatePad(const TerminatePadInst &TPI) {
report_fatal_error("visitTerminatePad not yet implemented!");
}

void SelectionDAGBuilder::visitCatchSwitch(const CatchSwitchInst &CSI) {
report_fatal_error("visitCatchSwitch not yet implemented!");
}
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,6 @@ class SelectionDAGBuilder {
void visitCatchSwitch(const CatchSwitchInst &I);
void visitCatchRet(const CatchReturnInst &I);
void visitCatchPad(const CatchPadInst &I);
void visitTerminatePad(const TerminatePadInst &TPI);
void visitCleanupPad(const CleanupPadInst &CPI);

BranchProbability getEdgeProbability(const MachineBasicBlock *Src,
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,6 @@ int TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode) const {
case CatchRet: return 0;
case CatchPad: return 0;
case CatchSwitch: return 0;
case TerminatePad: return 0;
case CleanupPad: return 0;
case Add: return ISD::ADD;
case FAdd: return ISD::FADD;
Expand Down
42 changes: 0 additions & 42 deletions llvm/lib/CodeGen/WinEHPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class WinEHPrepare : public FunctionPass {
void replaceUseWithLoad(Value *V, Use &U, AllocaInst *&SpillSlot,
DenseMap<BasicBlock *, Value *> &Loads, Function &F);
bool prepareExplicitEH(Function &F);
void replaceTerminatePadWithCleanup(Function &F);
void colorFunclets(Function &F);

void demotePHIsOnFunclets(Function &F);
Expand Down Expand Up @@ -523,45 +522,6 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn,
calculateStateNumbersForInvokes(Fn, FuncInfo);
}

void WinEHPrepare::replaceTerminatePadWithCleanup(Function &F) {
if (Personality != EHPersonality::MSVC_CXX)
return;
for (BasicBlock &BB : F) {
Instruction *First = BB.getFirstNonPHI();
auto *TPI = dyn_cast<TerminatePadInst>(First);
if (!TPI)
continue;

if (TPI->getNumArgOperands() != 1)
report_fatal_error(
"Expected a unary terminatepad for MSVC C++ personalities!");

auto *TerminateFn = dyn_cast<Function>(TPI->getArgOperand(0));
if (!TerminateFn)
report_fatal_error("Function operand expected in terminatepad for MSVC "
"C++ personalities!");

// Insert the cleanuppad instruction.
auto *CPI =
CleanupPadInst::Create(TPI->getParentPad(), {},
Twine("terminatepad.for.", BB.getName()), &BB);

// Insert the call to the terminate instruction.
auto *CallTerminate = CallInst::Create(TerminateFn, {}, &BB);
CallTerminate->setDoesNotThrow();
CallTerminate->setDoesNotReturn();
CallTerminate->setCallingConv(TerminateFn->getCallingConv());

// Insert a new terminator for the cleanuppad using the same successor as
// the terminatepad.
CleanupReturnInst::Create(CPI, TPI->getUnwindDest(), &BB);

// Let's remove the terminatepad now that we've inserted the new
// instructions.
TPI->eraseFromParent();
}
}

void WinEHPrepare::colorFunclets(Function &F) {
BlockColors = colorEHFunclets(F);

Expand Down Expand Up @@ -885,8 +845,6 @@ bool WinEHPrepare::prepareExplicitEH(Function &F) {
// not.
removeUnreachableBlocks(F);

replaceTerminatePadWithCleanup(F);

// Determine which blocks are reachable from which funclet entries.
colorFunclets(F);

Expand Down
15 changes: 0 additions & 15 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2917,21 +2917,6 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
writeOperand(FPI->getArgOperand(Op), /*PrintType=*/true);
}
Out << ']';
} else if (const auto *TPI = dyn_cast<TerminatePadInst>(&I)) {
Out << " within ";
writeOperand(TPI->getParentPad(), /*PrintType=*/false);
Out << " [";
for (unsigned Op = 0, NumOps = TPI->getNumArgOperands(); Op < NumOps;
++Op) {
if (Op > 0)
Out << ", ";
writeOperand(TPI->getArgOperand(Op), /*PrintType=*/true);
}
Out << "] unwind ";
if (TPI->hasUnwindDest())
writeOperand(TPI->getUnwindDest(), /*PrintType=*/true);
else
Out << "to caller";
} else if (isa<ReturnInst>(I) && !Operand) {
Out << " void";
} else if (const auto *CRI = dyn_cast<CatchReturnInst>(&I)) {
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
case CatchRet: return "catchret";
case CatchPad: return "catchpad";
case CatchSwitch: return "catchswitch";
case TerminatePad: return "terminatepad";

// Standard binary operators...
case Add: return "add";
Expand Down Expand Up @@ -421,7 +420,6 @@ bool Instruction::mayReadFromMemory() const {
case Instruction::AtomicRMW:
case Instruction::CatchPad:
case Instruction::CatchRet:
case Instruction::TerminatePad:
return true;
case Instruction::Call:
return !cast<CallInst>(this)->doesNotAccessMemory();
Expand All @@ -444,7 +442,6 @@ bool Instruction::mayWriteToMemory() const {
case Instruction::AtomicRMW:
case Instruction::CatchPad:
case Instruction::CatchRet:
case Instruction::TerminatePad:
return true;
case Instruction::Call:
return !cast<CallInst>(this)->onlyReadsMemory();
Expand Down Expand Up @@ -477,8 +474,6 @@ bool Instruction::mayThrow() const {
return CRI->unwindsToCaller();
if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(this))
return CatchSwitch->unwindsToCaller();
if (const auto *TPI = dyn_cast<TerminatePadInst>(this))
return TPI->unwindsToCaller();
return isa<ResumeInst>(this);
}

Expand Down
58 changes: 0 additions & 58 deletions llvm/lib/IR/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,60 +980,6 @@ FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
init(ParentPad, Args, NameStr);
}

//===----------------------------------------------------------------------===//
// TerminatePadInst Implementation
//===----------------------------------------------------------------------===//
void TerminatePadInst::init(Value *ParentPad, BasicBlock *BB,
ArrayRef<Value *> Args) {
if (BB) {
setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
setUnwindDest(BB);
}
std::copy(Args.begin(), Args.end(), arg_begin());
setParentPad(ParentPad);
}

TerminatePadInst::TerminatePadInst(const TerminatePadInst &TPI)
: TerminatorInst(TPI.getType(), Instruction::TerminatePad,
OperandTraits<TerminatePadInst>::op_end(this) -
TPI.getNumOperands(),
TPI.getNumOperands()) {
setInstructionSubclassData(TPI.getSubclassDataFromInstruction());
std::copy(TPI.op_begin(), TPI.op_end(), op_begin());
}

TerminatePadInst::TerminatePadInst(Value *ParentPad, BasicBlock *BB,
ArrayRef<Value *> Args, unsigned Values,
Instruction *InsertBefore)
: TerminatorInst(Type::getVoidTy(ParentPad->getContext()),
Instruction::TerminatePad,
OperandTraits<TerminatePadInst>::op_end(this) - Values,
Values, InsertBefore) {
init(ParentPad, BB, Args);
}

TerminatePadInst::TerminatePadInst(Value *ParentPad, BasicBlock *BB,
ArrayRef<Value *> Args, unsigned Values,
BasicBlock *InsertAtEnd)
: TerminatorInst(Type::getVoidTy(ParentPad->getContext()),
Instruction::TerminatePad,
OperandTraits<TerminatePadInst>::op_end(this) - Values,
Values, InsertAtEnd) {
init(ParentPad, BB, Args);
}

BasicBlock *TerminatePadInst::getSuccessorV(unsigned Idx) const {
assert(Idx == 0);
return getUnwindDest();
}
unsigned TerminatePadInst::getNumSuccessorsV() const {
return getNumSuccessors();
}
void TerminatePadInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
assert(Idx == 0);
return setUnwindDest(B);
}

//===----------------------------------------------------------------------===//
// UnreachableInst Implementation
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -4025,10 +3971,6 @@ FuncletPadInst *FuncletPadInst::cloneImpl() const {
return new (getNumOperands()) FuncletPadInst(*this);
}

TerminatePadInst *TerminatePadInst::cloneImpl() const {
return new (getNumOperands()) TerminatePadInst(*this);
}

UnreachableInst *UnreachableInst::cloneImpl() const {
LLVMContext &Context = getContext();
return new UnreachableInst(Context);
Expand Down
38 changes: 2 additions & 36 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
void visitCleanupPadInst(CleanupPadInst &CPI);
void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch);
void visitCleanupReturnInst(CleanupReturnInst &CRI);
void visitTerminatePadInst(TerminatePadInst &TPI);

void VerifyCallSite(CallSite CS);
void verifyMustTailCall(CallInst &CI);
Expand Down Expand Up @@ -2899,8 +2898,7 @@ void Verifier::visitEHPadPredecessors(Instruction &I) {
if (auto *II = dyn_cast<InvokeInst>(TI)) {
Assert(II->getUnwindDest() == BB && II->getNormalDest() != BB,
"EH pad must be jumped to via an unwind edge", &I, II);
} else if (!isa<CleanupReturnInst>(TI) && !isa<TerminatePadInst>(TI) &&
!isa<CatchSwitchInst>(TI)) {
} else if (!isa<CleanupReturnInst>(TI) && !isa<CatchSwitchInst>(TI)) {
Assert(false, "EH pad must be jumped to via an unwind edge", &I, TI);
}
}
Expand Down Expand Up @@ -3002,8 +3000,7 @@ void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) {
BasicBlock *UnwindDest;
if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(U)) {
UnwindDest = CRI->getUnwindDest();
} else if (isa<CleanupPadInst>(U) || isa<CatchSwitchInst>(U) ||
isa<TerminatePadInst>(U)) {
} else if (isa<CleanupPadInst>(U) || isa<CatchSwitchInst>(U)) {
continue;
} else {
Assert(false, "bogus cleanuppad use", &CPI);
Expand Down Expand Up @@ -3072,37 +3069,6 @@ void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
visitTerminatorInst(CRI);
}

void Verifier::visitTerminatePadInst(TerminatePadInst &TPI) {
visitEHPadPredecessors(TPI);

BasicBlock *BB = TPI.getParent();
Function *F = BB->getParent();
Assert(F->hasPersonalityFn(),
"TerminatePadInst needs to be in a function with a personality.",
&TPI);

// The terminatepad instruction must be the first non-PHI instruction in the
// block.
Assert(BB->getFirstNonPHI() == &TPI,
"TerminatePadInst not the first non-PHI instruction in the block.",
&TPI);

if (BasicBlock *UnwindDest = TPI.getUnwindDest()) {
Instruction *I = UnwindDest->getFirstNonPHI();
Assert(I->isEHPad() && !isa<LandingPadInst>(I),
"TerminatePadInst must unwind to an EH block which is not a "
"landingpad.",
&TPI);
}

auto *ParentPad = TPI.getParentPad();
Assert(isa<CatchSwitchInst>(ParentPad) || isa<ConstantTokenNone>(ParentPad) ||
isa<CleanupPadInst>(ParentPad) || isa<CatchPadInst>(ParentPad),
"TerminatePadInst has an invalid parent.", ParentPad);

visitTerminatorInst(TPI);
}

void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
Instruction *Op = cast<Instruction>(I.getOperand(i));
// If the we have an invalid invoke, don't try to compute the dominance.
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2695,11 +2695,6 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
setOrigin(&I, getCleanOrigin());
}

void visitTerminatePad(TerminatePadInst &I) {
DEBUG(dbgs() << "TerminatePad: " << I << "\n");
// Nothing to do here.
}

void visitGetElementPtrInst(GetElementPtrInst &I) {
handleShadowOr(I);
}
Expand Down
15 changes: 2 additions & 13 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,7 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
continue;

Instruction *Replacement = nullptr;
if (auto *TPI = dyn_cast<TerminatePadInst>(I)) {
if (TPI->unwindsToCaller()) {
SmallVector<Value *, 3> TerminatePadArgs;
for (Value *ArgOperand : TPI->arg_operands())
TerminatePadArgs.push_back(ArgOperand);
Replacement = TerminatePadInst::Create(TPI->getParentPad(), UnwindDest,
TerminatePadArgs, TPI);
}
} else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I)) {
if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I)) {
if (CatchSwitch->unwindsToCaller()) {
auto *NewCatchSwitch = CatchSwitchInst::Create(
CatchSwitch->getParentPad(), UnwindDest,
Expand Down Expand Up @@ -1441,10 +1433,7 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
if (!I->isEHPad())
continue;

if (auto *TPI = dyn_cast<TerminatePadInst>(I)) {
if (isa<ConstantTokenNone>(TPI->getParentPad()))
TPI->setParentPad(CallSiteEHPad);
} else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I)) {
if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I)) {
if (isa<ConstantTokenNone>(CatchSwitch->getParentPad()))
CatchSwitch->setParentPad(CallSiteEHPad);
} else {
Expand Down
7 changes: 0 additions & 7 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,13 +1338,6 @@ void llvm::removeUnwindEdge(BasicBlock *BB) {
if (auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
NewTI = CleanupReturnInst::Create(CRI->getCleanupPad(), nullptr, CRI);
UnwindDest = CRI->getUnwindDest();
} else if (auto *TPI = dyn_cast<TerminatePadInst>(TI)) {
SmallVector<Value *, 3> TerminatePadArgs;
for (Value *Operand : TPI->arg_operands())
TerminatePadArgs.push_back(Operand);
NewTI = TerminatePadInst::Create(TPI->getParentPad(), nullptr,
TerminatePadArgs, TPI);
UnwindDest = TPI->getUnwindDest();
} else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(TI)) {
auto *NewCatchSwitch = CatchSwitchInst::Create(
CatchSwitch->getParentPad(), nullptr, CatchSwitch->getNumHandlers(),
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,7 @@ bool SimplifyCFGOpt::SimplifyUnreachable(UnreachableInst *UI) {
}
} else if ((isa<InvokeInst>(TI) &&
cast<InvokeInst>(TI)->getUnwindDest() == BB) ||
isa<TerminatePadInst>(TI) || isa<CatchSwitchInst>(TI)) {
isa<CatchSwitchInst>(TI)) {
removeUnwindEdge(TI->getParent());
Changed = true;
} else if (isa<CleanupReturnInst>(TI)) {
Expand Down
23 changes: 7 additions & 16 deletions llvm/test/Bitcode/compatibility.ll
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ entry:
invoke void @f.ccc() to label %normal unwind label %catchswitch3

catchswitch1:
%cs1 = catchswitch within none [label %catchpad1] unwind label %terminate.1
%cs1 = catchswitch within none [label %catchpad1] unwind to caller

catchpad1:
catchpad within %cs1 []
Expand Down Expand Up @@ -802,20 +802,9 @@ catchpad3:

cleanuppad1:
%clean.1 = cleanuppad within none []
unreachable
; CHECK: %clean.1 = cleanuppad within none []
invoke void @f.ccc() to label %normal unwind label %terminate.2

terminate.1:
terminatepad within none [] unwind to caller
; CHECK: terminatepad within none [] unwind to caller

terminate.2:
terminatepad within %clean.1 [i32* %arg1] unwind label %normal.pre
; CHECK: terminatepad within %clean.1 [i32* %arg1] unwind label %normal.pre

normal.pre:
terminatepad within %clean.1 [i32* %arg1, i32* %arg2] unwind to caller
; CHECK: terminatepad within %clean.1 [i32* %arg1, i32* %arg2] unwind to caller
; CHECK-NEXT: unreachable

normal:
ret i32 0
Expand Down Expand Up @@ -852,8 +841,10 @@ return:
ret i32 0

terminate:
terminatepad within %cs [] unwind to caller
; CHECK: terminatepad within %cs [] unwind to caller
cleanuppad within %cs []
unreachable
; CHECK: cleanuppad within %cs []
; CHECK-NEXT: unreachable

continue:
ret i32 0
Expand Down
16 changes: 0 additions & 16 deletions llvm/test/CodeGen/WinEH/wineh-no-demotion.ll
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,6 @@ exit:
unreachable
}

; CHECK-LABEL: @test3(
define void @test3() personality i32 (...)* @__CxxFrameHandler3 {
entry:
invoke void @f()
to label %invoke.cont unwind label %terminate

invoke.cont:
ret void

terminate:
; CHECK: cleanuppad within none []
; CHECK: call void @__std_terminate()
; CHECK: unreachable
terminatepad within none [void ()* @__std_terminate] unwind to caller
}

; CHECK-LABEL: @test4(
define void @test4(i1 %x) personality i32 (...)* @__CxxFrameHandler3 {
entry:
Expand Down
22 changes: 0 additions & 22 deletions llvm/test/Feature/exception.ll
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,6 @@ exit:
ret i8 0
}

define void @terminatepad0() personality i32 (...)* @__gxx_personality_v0 {
entry:
br label %try.cont

try.cont:
invoke void @_Z3quxv() optsize
to label %try.cont unwind label %bb
bb:
terminatepad within none [i7 4] unwind label %bb
}

define void @terminatepad1() personality i32 (...)* @__gxx_personality_v0 {
entry:
br label %try.cont

try.cont:
invoke void @_Z3quxv() optsize
to label %try.cont unwind label %bb
bb:
terminatepad within none [i7 4] unwind to caller
}

define void @cleanuppad() personality i32 (...)* @__gxx_personality_v0 {
entry:
br label %try.cont
Expand Down
53 changes: 0 additions & 53 deletions llvm/test/Transforms/Inline/PR25155.ll

This file was deleted.

3 changes: 0 additions & 3 deletions llvm/test/Transforms/LoopStrengthReduce/funclet.ll
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ throw: ; preds = %throw, %entry

pad: ; preds = %throw
%phi2 = phi i8* [ %tmp96, %throw ]
terminatepad within none [] unwind label %blah

blah:
%cs = catchswitch within none [label %unreachable] unwind label %blah2

unreachable:
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/Transforms/MergeFunc/call-and-invoke-with-ranges.ll
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ lpad:
resume { i8*, i32 } zeroinitializer
}

define i8 @call_with_same_range() {
; CHECK-LABEL: @call_with_same_range
; CHECK: tail call i8 @call_with_range
bitcast i8 0 to i8
%out = call i8 @dummy(), !range !0
ret i8 %out
}

define i8 @invoke_with_same_range() personality i8* undef {
; CHECK-LABEL: @invoke_with_same_range()
; CHECK: tail call i8 @invoke_with_range()
Expand All @@ -84,6 +76,14 @@ lpad:
resume { i8*, i32 } zeroinitializer
}

define i8 @call_with_same_range() {
; CHECK-LABEL: @call_with_same_range
; CHECK: tail call i8 @call_with_range
bitcast i8 0 to i8
%out = call i8 @dummy(), !range !0
ret i8 %out
}



declare i8 @dummy();
Expand Down
55 changes: 0 additions & 55 deletions llvm/test/Transforms/SimplifyCFG/empty-cleanuppad.ll
Original file line number Diff line number Diff line change
Expand Up @@ -219,61 +219,6 @@ ehcleanup:
cleanupret from %cp2 unwind to caller
}

; This tests the case where a terminatepad unwinds to a cleanuppad.
; I'm not sure how this case would arise, but it seems to be syntactically
; legal so I'm testing it.
;
; CHECK-LABEL: define void @f5()
; CHECK: entry:
; CHECK: invoke void @g()
; CHECK: to label %try.cont unwind label %terminate
; CHECK: terminate:
; CHECK: terminatepad within none [i7 4] unwind to caller
; CHECK-NOT: cleanuppad
; CHECK: try.cont:
; CHECK: invoke void @g()
; CHECK: to label %try.cont.1 unwind label %terminate.1
; CHECK: terminate.1:
; CHECK: terminatepad within none [i7 4] unwind label %ehcleanup.2
; CHECK-NOT: ehcleanup.1:
; CHECK: ehcleanup.2:
; CHECK: [[TMP:\%.+]] = cleanuppad
; CHECK: call void @"\01??1S2@@QEAA@XZ"(%struct.S2* %a)
; CHECK: cleanupret from [[TMP]] unwind to caller
; CHECK: }
define void @f5() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
entry:
%a = alloca %struct.S2, align 1
invoke void @g()
to label %try.cont unwind label %terminate

terminate: ; preds = %entry
terminatepad within none [i7 4] unwind label %ehcleanup

ehcleanup: ; preds = %terminate
%0 = cleanuppad within none []
cleanupret from %0 unwind to caller

try.cont: ; preds = %entry
invoke void @g()
to label %try.cont.1 unwind label %terminate.1

terminate.1: ; preds = %try.cont
terminatepad within none [i7 4] unwind label %ehcleanup.1

ehcleanup.1: ; preds = %terminate.1
%1 = cleanuppad within none []
cleanupret from %1 unwind label %ehcleanup.2

ehcleanup.2: ; preds = %ehcleanup.1
%2 = cleanuppad within none []
call void @"\01??1S2@@QEAA@XZ"(%struct.S2* %a)
cleanupret from %2 unwind to caller

try.cont.1: ; preds = %try.cont
ret void
}

; This case tests simplification of an otherwise empty cleanup pad that contains
; a PHI node.
;
Expand Down
15 changes: 0 additions & 15 deletions llvm/test/Transforms/SimplifyCFG/wineh-unreachable.ll
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,6 @@ unreachable.unwind:
unreachable
}

; CHECK-LABEL: define void @test4()
define void @test4() personality i8* bitcast (void ()* @Personality to i8*) {
entry:
invoke void @f()
to label %exit unwind label %terminate.pad
terminate.pad:
; CHECK: terminatepad within none [] unwind to caller
terminatepad within none [] unwind label %unreachable.unwind
exit:
ret void
unreachable.unwind:
cleanuppad within none []
unreachable
}

; CHECK-LABEL: define void @test5()
define void @test5() personality i8* bitcast (void ()* @Personality to i8*) {
entry:
Expand Down
1 change: 0 additions & 1 deletion llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
STRINGIFY_CODE(FUNC_CODE, INST_CLEANUPRET)
STRINGIFY_CODE(FUNC_CODE, INST_CATCHRET)
STRINGIFY_CODE(FUNC_CODE, INST_CATCHPAD)
STRINGIFY_CODE(FUNC_CODE, INST_TERMINATEPAD)
STRINGIFY_CODE(FUNC_CODE, INST_PHI)
STRINGIFY_CODE(FUNC_CODE, INST_ALLOCA)
STRINGIFY_CODE(FUNC_CODE, INST_LOAD)
Expand Down