diff options
| author | Chris Lattner <clattner@google.com> | 2018-12-25 17:11:06 -0800 |
|---|---|---|
| committer | jpienaar <jpienaar@google.com> | 2019-03-29 14:36:20 -0700 |
| commit | 9a4060d3f50f046973d4e0b61f324bbc6ebbbdb9 (patch) | |
| tree | c11271b0b7c9be624d5324ba7e777a7a500ae90a /mlir/lib/IR/Operation.cpp | |
| parent | eadaa1101c4e107cc462153d28c1e4ae2bbe37ba (diff) | |
| download | bcm5719-llvm-9a4060d3f50f046973d4e0b61f324bbc6ebbbdb9.tar.gz bcm5719-llvm-9a4060d3f50f046973d4e0b61f324bbc6ebbbdb9.zip | |
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
Diffstat (limited to 'mlir/lib/IR/Operation.cpp')
| -rw-r--r-- | mlir/lib/IR/Operation.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
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<Instruction>(this)) - return llvm::cast<Instruction>(this)->getNumSuccessors(); + if (auto *inst = llvm::dyn_cast<Instruction>(this)) + return inst->getNumSuccessors(); - // OperationStmt currently only has a return terminator. - assert(llvm::cast<OperationStmt>(this)->isReturn() && - "Unhandled OperationStmt terminator."); - return 0; + return llvm::cast<OperationStmt>(this)->getNumSuccessors(); } unsigned Operation::getNumSuccessorOperands(unsigned index) const { assert(isTerminator() && "Only terminators have successors."); - assert(llvm::isa<Instruction>(this) && "Only instructions have successors."); - return llvm::cast<Instruction>(this)->getNumSuccessorOperands(index); + + if (auto *inst = llvm::dyn_cast<Instruction>(this)) + return inst->getNumSuccessorOperands(index); + + return llvm::cast<OperationStmt>(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<Instruction>(this)->setSuccessor(block, index); } -void Operation::addSuccessorOperand(unsigned index, SSAValue *value) { - assert(isTerminator() && "Only terminators have successors."); - assert(llvm::isa<Instruction>(this) && "Only instructions have successors."); - return llvm::cast<Instruction>(this)->addSuccessorOperand( - index, llvm::cast<CFGValue>(value)); -} + void Operation::eraseSuccessorOperand(unsigned succIndex, unsigned opIndex) { assert(isTerminator() && "Only terminators have successors."); assert(llvm::isa<Instruction>(this) && "Only instructions have successors."); |

