From 9a4060d3f50f046973d4e0b61f324bbc6ebbbdb9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 25 Dec 2018 17:11:06 -0800 Subject: Eliminate the ability to add operands to an instruction, used in a narrow case for SSA values in terminators, but easily worked around. At the same time, move the StmtOperand list in a OperationStmt to the end of its trailing objects list so we can *reduce* the number of operands, without affecting offsets to the other stuff in the allocation. This is important because we want OperationStmts to be consequtive, including their operands - we don't want to use an std::vector of operands like Instructions have. This is patch 4/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 226865727 --- mlir/lib/IR/Operation.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'mlir/lib/IR/Operation.cpp') diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index af295782718..d3a618d7da5 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -144,19 +144,19 @@ SSAValue *Operation::getResult(unsigned idx) { unsigned Operation::getNumSuccessors() const { assert(isTerminator() && "Only terminators have successors."); - if (llvm::isa(this)) - return llvm::cast(this)->getNumSuccessors(); + if (auto *inst = llvm::dyn_cast(this)) + return inst->getNumSuccessors(); - // OperationStmt currently only has a return terminator. - assert(llvm::cast(this)->isReturn() && - "Unhandled OperationStmt terminator."); - return 0; + return llvm::cast(this)->getNumSuccessors(); } unsigned Operation::getNumSuccessorOperands(unsigned index) const { assert(isTerminator() && "Only terminators have successors."); - assert(llvm::isa(this) && "Only instructions have successors."); - return llvm::cast(this)->getNumSuccessorOperands(index); + + if (auto *inst = llvm::dyn_cast(this)) + return inst->getNumSuccessorOperands(index); + + return llvm::cast(this)->getNumSuccessorOperands(index); } BasicBlock *Operation::getSuccessor(unsigned index) { assert(isTerminator() && "Only terminators have successors."); @@ -170,12 +170,7 @@ void Operation::setSuccessor(BasicBlock *block, unsigned index) { "Only instructions have basic block successors."); llvm::cast(this)->setSuccessor(block, index); } -void Operation::addSuccessorOperand(unsigned index, SSAValue *value) { - assert(isTerminator() && "Only terminators have successors."); - assert(llvm::isa(this) && "Only instructions have successors."); - return llvm::cast(this)->addSuccessorOperand( - index, llvm::cast(value)); -} + void Operation::eraseSuccessorOperand(unsigned succIndex, unsigned opIndex) { assert(isTerminator() && "Only terminators have successors."); assert(llvm::isa(this) && "Only instructions have successors."); -- cgit v1.2.3