diff options
Diffstat (limited to 'mlir/lib')
| -rw-r--r-- | mlir/lib/Analysis/AffineAnalysis.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Analysis/AffineStructures.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Analysis/Dominance.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Analysis/LoopAnalysis.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Analysis/OpStats.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Analysis/SliceAnalysis.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Analysis/VectorAnalysis.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Analysis/Verifier.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/EDSC/MLIREmitter.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/IR/AsmPrinter.cpp | 10 | ||||
| -rw-r--r-- | mlir/lib/IR/Block.cpp | 13 | ||||
| -rw-r--r-- | mlir/lib/IR/Instruction.cpp | 455 | ||||
| -rw-r--r-- | mlir/lib/IR/Operation.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/IR/PatternMatch.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/IR/Value.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Transforms/SimplifyAffineStructures.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Transforms/StripDebugInfo.cpp | 1 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils/LoopUtils.cpp | 2 |
19 files changed, 240 insertions, 269 deletions
diff --git a/mlir/lib/Analysis/AffineAnalysis.cpp b/mlir/lib/Analysis/AffineAnalysis.cpp index d2366f1ce81..8b64f498ce8 100644 --- a/mlir/lib/Analysis/AffineAnalysis.cpp +++ b/mlir/lib/Analysis/AffineAnalysis.cpp @@ -27,7 +27,7 @@ #include "mlir/IR/AffineExprVisitor.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/IntegerSet.h" #include "mlir/StandardOps/StandardOps.h" #include "mlir/Support/MathExtras.h" diff --git a/mlir/lib/Analysis/AffineStructures.cpp b/mlir/lib/Analysis/AffineStructures.cpp index c794899d3e1..9d1f7481115 100644 --- a/mlir/lib/Analysis/AffineStructures.cpp +++ b/mlir/lib/Analysis/AffineStructures.cpp @@ -25,7 +25,7 @@ #include "mlir/IR/AffineExprVisitor.h" #include "mlir/IR/AffineMap.h" #include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/IntegerSet.h" #include "mlir/Support/MathExtras.h" #include "llvm/ADT/DenseSet.h" diff --git a/mlir/lib/Analysis/Dominance.cpp b/mlir/lib/Analysis/Dominance.cpp index 5cdeebbdf4a..c1f1074e2dd 100644 --- a/mlir/lib/Analysis/Dominance.cpp +++ b/mlir/lib/Analysis/Dominance.cpp @@ -21,7 +21,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Analysis/Dominance.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "llvm/Support/GenericDomTreeConstruction.h" using namespace mlir; diff --git a/mlir/lib/Analysis/LoopAnalysis.cpp b/mlir/lib/Analysis/LoopAnalysis.cpp index 249776d42c9..e3055c5530d 100644 --- a/mlir/lib/Analysis/LoopAnalysis.cpp +++ b/mlir/lib/Analysis/LoopAnalysis.cpp @@ -28,7 +28,7 @@ #include "mlir/Analysis/VectorAnalysis.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/StandardOps/StandardOps.h" #include "mlir/SuperVectorOps/SuperVectorOps.h" #include "mlir/Support/Functional.h" diff --git a/mlir/lib/Analysis/OpStats.cpp b/mlir/lib/Analysis/OpStats.cpp index c2fe3d06007..90c5c5fde0e 100644 --- a/mlir/lib/Analysis/OpStats.cpp +++ b/mlir/lib/Analysis/OpStats.cpp @@ -16,7 +16,7 @@ // ============================================================================= #include "mlir/IR/InstVisitor.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/Module.h" #include "mlir/IR/OperationSupport.h" #include "mlir/Pass.h" diff --git a/mlir/lib/Analysis/SliceAnalysis.cpp b/mlir/lib/Analysis/SliceAnalysis.cpp index 4025af936f3..5211893f055 100644 --- a/mlir/lib/Analysis/SliceAnalysis.cpp +++ b/mlir/lib/Analysis/SliceAnalysis.cpp @@ -23,7 +23,7 @@ #include "mlir/AffineOps/AffineOps.h" #include "mlir/Analysis/VectorAnalysis.h" #include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/Support/Functional.h" #include "mlir/Support/STLExtras.h" diff --git a/mlir/lib/Analysis/VectorAnalysis.cpp b/mlir/lib/Analysis/VectorAnalysis.cpp index 4865cb03bb4..7cafc81fc0e 100644 --- a/mlir/lib/Analysis/VectorAnalysis.cpp +++ b/mlir/lib/Analysis/VectorAnalysis.cpp @@ -20,7 +20,7 @@ #include "mlir/Analysis/AffineAnalysis.h" #include "mlir/Analysis/LoopAnalysis.h" #include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/IntegerSet.h" #include "mlir/StandardOps/StandardOps.h" #include "mlir/SuperVectorOps/SuperVectorOps.h" diff --git a/mlir/lib/Analysis/Verifier.cpp b/mlir/lib/Analysis/Verifier.cpp index a69831053ad..16264ad9515 100644 --- a/mlir/lib/Analysis/Verifier.cpp +++ b/mlir/lib/Analysis/Verifier.cpp @@ -36,7 +36,7 @@ #include "mlir/Analysis/Dominance.h" #include "mlir/IR/Attributes.h" #include "mlir/IR/Function.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/Module.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/raw_ostream.h" diff --git a/mlir/lib/EDSC/MLIREmitter.cpp b/mlir/lib/EDSC/MLIREmitter.cpp index f4d5d36d25b..5a96661dfff 100644 --- a/mlir/lib/EDSC/MLIREmitter.cpp +++ b/mlir/lib/EDSC/MLIREmitter.cpp @@ -27,7 +27,7 @@ #include "mlir/EDSC/Types.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/Location.h" #include "mlir/IR/Value.h" diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 0fb18fa0004..2ffdb19ea63 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -26,7 +26,7 @@ #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Function.h" #include "mlir/IR/InstVisitor.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Module.h" @@ -1043,7 +1043,6 @@ public: // Methods to print instructions. void print(const Instruction *inst); - void print(const OperationInst *inst); void print(const Block *block, bool printBlockArgs = true); void printOperation(const OperationInst *op); @@ -1365,13 +1364,6 @@ void FunctionPrinter::print(const Block *block, bool printBlockArgs) { } void FunctionPrinter::print(const Instruction *inst) { - switch (inst->getKind()) { - case Instruction::Kind::OperationInst: - return print(cast<OperationInst>(inst)); - } -} - -void FunctionPrinter::print(const OperationInst *inst) { os.indent(currentIndent); printOperation(inst); printTrailingLocation(inst->getLoc()); diff --git a/mlir/lib/IR/Block.cpp b/mlir/lib/IR/Block.cpp index f523f66565d..81e70e2b139 100644 --- a/mlir/lib/IR/Block.cpp +++ b/mlir/lib/IR/Block.cpp @@ -91,6 +91,19 @@ Instruction *Block::findAncestorInstInBlock(Instruction *inst) { return currInst; } +/// Returns the instructions's position in this block or -1 if the instruction +/// is not present. +/// TODO: This is needlessly inefficient, and should not be API on Block. +int64_t Block::findInstPositionInBlock(const Instruction &inst) const { + int64_t j = 0; + for (const auto &s : instructions) { + if (&s == &inst) + return j; + j++; + } + return -1; +} + /// This drops all operand uses from instructions within this block, which is /// an essential step in breaking cyclic dependences between references when /// they are to be deleted. diff --git a/mlir/lib/IR/Instruction.cpp b/mlir/lib/IR/Instruction.cpp index d8594bb02fa..f6cefda7fb8 100644 --- a/mlir/lib/IR/Instruction.cpp +++ b/mlir/lib/IR/Instruction.cpp @@ -15,6 +15,7 @@ // limitations under the License. // ============================================================================= +#include "mlir/IR/Instruction.h" #include "AttributeListStorage.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/AffineMap.h" @@ -22,7 +23,6 @@ #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Function.h" #include "mlir/IR/InstVisitor.h" -#include "mlir/IR/Instructions.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/MLIRContext.h" #include "llvm/ADT/DenseMap.h" @@ -131,24 +131,161 @@ void detail::OperandStorage::grow(ResizableStorage &resizeUtil, // Instruction //===----------------------------------------------------------------------===// -// Instructions are deleted through the destroy() member because we don't have -// a virtual destructor. +/// Create a new Instruction with the specific fields. +Instruction * +Instruction::create(Location location, OperationName name, + ArrayRef<Value *> operands, ArrayRef<Type> resultTypes, + ArrayRef<NamedAttribute> attributes, + ArrayRef<Block *> successors, unsigned numBlockLists, + bool resizableOperandList, MLIRContext *context) { + unsigned numSuccessors = successors.size(); + + // Input operands are nullptr-separated for each successors in the case of + // terminators, the nullptr aren't actually stored. + unsigned numOperands = operands.size() - numSuccessors; + + // Compute the byte size for the instruction and the operand storage. + auto byteSize = totalSizeToAlloc<InstResult, BlockOperand, unsigned, + BlockList, detail::OperandStorage>( + resultTypes.size(), numSuccessors, numSuccessors, numBlockLists, + /*detail::OperandStorage*/ 1); + byteSize += llvm::alignTo(detail::OperandStorage::additionalAllocSize( + numOperands, resizableOperandList), + alignof(Instruction)); + void *rawMem = malloc(byteSize); + + // Create the new Instruction. + auto inst = ::new (rawMem) + Instruction(location, name, resultTypes.size(), numSuccessors, + numBlockLists, attributes, context); + + assert((numSuccessors == 0 || inst->isTerminator()) && + "unexpected successors in a non-terminator operation"); + + // Initialize the block lists. + for (unsigned i = 0; i != numBlockLists; ++i) + new (&inst->getBlockList(i)) BlockList(inst); + + // Initialize the results and operands. + new (&inst->getOperandStorage()) + detail::OperandStorage(numOperands, resizableOperandList); + + auto instResults = inst->getInstResults(); + for (unsigned i = 0, e = resultTypes.size(); i != e; ++i) + new (&instResults[i]) InstResult(resultTypes[i], inst); + + auto InstOperands = inst->getInstOperands(); + + // Initialize normal operands. + unsigned operandIt = 0, operandE = operands.size(); + unsigned nextOperand = 0; + for (; operandIt != operandE; ++operandIt) { + // Null operands are used as sentinals between successor operand lists. If + // we encounter one here, break and handle the successor operands lists + // separately below. + if (!operands[operandIt]) + break; + new (&InstOperands[nextOperand++]) InstOperand(inst, operands[operandIt]); + } + + unsigned currentSuccNum = 0; + if (operandIt == operandE) { + // Verify that the amount of sentinal operands is equivalent to the number + // of successors. + assert(currentSuccNum == numSuccessors); + return inst; + } + + assert(inst->isTerminator() && + "Sentinal operand found in non terminator operand list."); + auto instBlockOperands = inst->getBlockOperands(); + unsigned *succOperandCountIt = inst->getTrailingObjects<unsigned>(); + unsigned *succOperandCountE = succOperandCountIt + numSuccessors; + (void)succOperandCountE; + + for (; operandIt != operandE; ++operandIt) { + // If we encounter a sentinal branch to the next operand update the count + // variable. + if (!operands[operandIt]) { + assert(currentSuccNum < numSuccessors); + + // After the first iteration update the successor operand count + // variable. + if (currentSuccNum != 0) { + ++succOperandCountIt; + assert(succOperandCountIt != succOperandCountE && + "More sentinal operands than successors."); + } + + new (&instBlockOperands[currentSuccNum]) + BlockOperand(inst, successors[currentSuccNum]); + *succOperandCountIt = 0; + ++currentSuccNum; + continue; + } + new (&InstOperands[nextOperand++]) InstOperand(inst, operands[operandIt]); + ++(*succOperandCountIt); + } + + // Verify that the amount of sentinal operands is equivalent to the number of + // successors. + assert(currentSuccNum == numSuccessors); + + return inst; +} + +Instruction::Instruction(Location location, OperationName name, + unsigned numResults, unsigned numSuccessors, + unsigned numBlockLists, + ArrayRef<NamedAttribute> attributes, + MLIRContext *context) + : location(location), numResults(numResults), numSuccs(numSuccessors), + numBlockLists(numBlockLists), name(name) { + assert(llvm::all_of(attributes, + [](const NamedAttribute &attr) { return attr.second; }) && + "Attributes cannot have null entries"); + this->attrs = AttributeListStorage::get(attributes, context); +} + +// Instructions are deleted through the destroy() member because they are +// allocated via malloc. Instruction::~Instruction() { assert(block == nullptr && "instruction destroyed but still in a block"); + + // Explicitly run the destructors for the operands and results. + getOperandStorage().~OperandStorage(); + + for (auto &result : getInstResults()) + result.~InstResult(); + + // Explicitly run the destructors for the successors. + if (isTerminator()) + for (auto &successor : getBlockOperands()) + successor.~BlockOperand(); + + // Explicitly destroy the block list. + for (auto &blockList : getBlockLists()) + blockList.~BlockList(); } /// Destroy this instruction or one of its subclasses. void Instruction::destroy() { - switch (this->getKind()) { - case Kind::OperationInst: - cast<OperationInst>(this)->destroy(); - break; - } + this->~Instruction(); + free(this); } /// Return the context this operation is associated with. MLIRContext *Instruction::getContext() const { - return cast<OperationInst>(this)->getContext(); + // If we have a result or operand type, that is a constant time way to get + // to the context. + if (getNumResults()) + return getResult(0)->getType().getContext(); + if (getNumOperands()) + return getOperand(0)->getType().getContext(); + + // In the very odd case where we have no operands or results, fall back to + // doing a find. + return getFunction()->getContext(); } Instruction *Instruction::getParentInst() const { @@ -159,14 +296,6 @@ Function *Instruction::getFunction() const { return block ? block->getFunction() : nullptr; } -Value *Instruction::getOperand(unsigned idx) { - return getInstOperand(idx).get(); -} - -const Value *Instruction::getOperand(unsigned idx) const { - return getInstOperand(idx).get(); -} - // Value can be used as a dimension id if it is valid as a symbol, or // it is an induction variable, or it is a result of affine apply operation // with dimension id arguments. @@ -203,24 +332,6 @@ bool Value::isValidSymbol() const { return arg && arg->isFunctionArgument(); } -void Instruction::setOperand(unsigned idx, Value *value) { - getInstOperand(idx).set(value); -} - -unsigned Instruction::getNumOperands() const { - switch (getKind()) { - case Kind::OperationInst: - return cast<OperationInst>(this)->getNumOperands(); - } -} - -MutableArrayRef<InstOperand> Instruction::getInstOperands() { - switch (getKind()) { - case Kind::OperationInst: - return cast<OperationInst>(this)->getInstOperands(); - } -} - /// Emit a note about this instruction, reporting up to any diagnostic /// handlers that may be listening. void Instruction::emitNote(const Twine &message) const { @@ -258,17 +369,36 @@ bool Instruction::isBeforeInBlock(const Instruction *other) const { return orderIndex < other->orderIndex; } -/// Returns whether the Instruction is a terminator. -bool Instruction::isTerminator() const { - if (auto *op = dyn_cast<OperationInst>(this)) - return op->isTerminator(); - return false; -} - //===----------------------------------------------------------------------===// // ilist_traits for Instruction //===----------------------------------------------------------------------===// +auto llvm::ilist_detail::SpecificNodeAccess< + typename llvm::ilist_detail::compute_node_options< + ::mlir::Instruction>::type>::getNodePtr(pointer N) -> node_type * { + return NodeAccess::getNodePtr<OptionsT>(N); +} + +auto llvm::ilist_detail::SpecificNodeAccess< + typename llvm::ilist_detail::compute_node_options< + ::mlir::Instruction>::type>::getNodePtr(const_pointer N) + -> const node_type * { + return NodeAccess::getNodePtr<OptionsT>(N); +} + +auto llvm::ilist_detail::SpecificNodeAccess< + typename llvm::ilist_detail::compute_node_options< + ::mlir::Instruction>::type>::getValuePtr(node_type *N) -> pointer { + return NodeAccess::getValuePtr<OptionsT>(N); +} + +auto llvm::ilist_detail::SpecificNodeAccess< + typename llvm::ilist_detail::compute_node_options< + ::mlir::Instruction>::type>::getValuePtr(const node_type *N) + -> const_pointer { + return NodeAccess::getValuePtr<OptionsT>(N); +} + void llvm::ilist_traits<::mlir::Instruction>::deleteNode(Instruction *inst) { inst->destroy(); } @@ -346,211 +476,48 @@ void Instruction::dropAllReferences() { for (auto &op : getInstOperands()) op.drop(); - switch (getKind()) { - case Kind::OperationInst: { - auto *opInst = cast<OperationInst>(this); - if (isTerminator()) - for (auto &dest : opInst->getBlockOperands()) - dest.drop(); - for (auto &blockList : opInst->getBlockLists()) - for (Block &block : blockList) - block.dropAllReferences(); - break; - } - } -} - -//===----------------------------------------------------------------------===// -// OperationInst -//===----------------------------------------------------------------------===// - -/// Create a new OperationInst with the specific fields. -OperationInst * -OperationInst::create(Location location, OperationName name, - ArrayRef<Value *> operands, ArrayRef<Type> resultTypes, - ArrayRef<NamedAttribute> attributes, - ArrayRef<Block *> successors, unsigned numBlockLists, - bool resizableOperandList, MLIRContext *context) { - unsigned numSuccessors = successors.size(); - - // Input operands are nullptr-separated for each successors in the case of - // terminators, the nullptr aren't actually stored. - unsigned numOperands = operands.size() - numSuccessors; - - // Compute the byte size for the instruction and the operand storage. - auto byteSize = totalSizeToAlloc<InstResult, BlockOperand, unsigned, - BlockList, detail::OperandStorage>( - resultTypes.size(), numSuccessors, numSuccessors, numBlockLists, - /*detail::OperandStorage*/ 1); - byteSize += llvm::alignTo(detail::OperandStorage::additionalAllocSize( - numOperands, resizableOperandList), - alignof(OperationInst)); - void *rawMem = malloc(byteSize); - - // Initialize the OperationInst part of the instruction. - auto inst = ::new (rawMem) - OperationInst(location, name, resultTypes.size(), numSuccessors, - numBlockLists, attributes, context); - - assert((numSuccessors == 0 || inst->isTerminator()) && - "unexpected successors in a non-terminator operation"); - - // Initialize the block lists. - for (unsigned i = 0; i != numBlockLists; ++i) - new (&inst->getBlockList(i)) BlockList(inst); - - // Initialize the results and operands. - new (&inst->getOperandStorage()) - detail::OperandStorage(numOperands, resizableOperandList); - - auto instResults = inst->getInstResults(); - for (unsigned i = 0, e = resultTypes.size(); i != e; ++i) - new (&instResults[i]) InstResult(resultTypes[i], inst); - - auto InstOperands = inst->getInstOperands(); - - // Initialize normal operands. - unsigned operandIt = 0, operandE = operands.size(); - unsigned nextOperand = 0; - for (; operandIt != operandE; ++operandIt) { - // Null operands are used as sentinals between successor operand lists. If - // we encounter one here, break and handle the successor operands lists - // separately below. - if (!operands[operandIt]) - break; - new (&InstOperands[nextOperand++]) InstOperand(inst, operands[operandIt]); - } - - unsigned currentSuccNum = 0; - if (operandIt == operandE) { - // Verify that the amount of sentinal operands is equivalent to the number - // of successors. - assert(currentSuccNum == numSuccessors); - return inst; - } - - assert(inst->isTerminator() && - "Sentinal operand found in non terminator operand list."); - auto instBlockOperands = inst->getBlockOperands(); - unsigned *succOperandCountIt = inst->getTrailingObjects<unsigned>(); - unsigned *succOperandCountE = succOperandCountIt + numSuccessors; - (void)succOperandCountE; - - for (; operandIt != operandE; ++operandIt) { - // If we encounter a sentinal branch to the next operand update the count - // variable. - if (!operands[operandIt]) { - assert(currentSuccNum < numSuccessors); - - // After the first iteration update the successor operand count - // variable. - if (currentSuccNum != 0) { - ++succOperandCountIt; - assert(succOperandCountIt != succOperandCountE && - "More sentinal operands than successors."); - } - - new (&instBlockOperands[currentSuccNum]) - BlockOperand(inst, successors[currentSuccNum]); - *succOperandCountIt = 0; - ++currentSuccNum; - continue; - } - new (&InstOperands[nextOperand++]) InstOperand(inst, operands[operandIt]); - ++(*succOperandCountIt); - } - - // Verify that the amount of sentinal operands is equivalent to the number of - // successors. - assert(currentSuccNum == numSuccessors); - - return inst; -} - -OperationInst::OperationInst(Location location, OperationName name, - unsigned numResults, unsigned numSuccessors, - unsigned numBlockLists, - ArrayRef<NamedAttribute> attributes, - MLIRContext *context) - : Instruction(location), numResults(numResults), numSuccs(numSuccessors), - numBlockLists(numBlockLists), name(name) { -#ifndef NDEBUG - for (auto elt : attributes) - assert(elt.second != nullptr && "Attributes cannot have null entries"); -#endif - - this->attrs = AttributeListStorage::get(attributes, context); -} - -OperationInst::~OperationInst() { - // Explicitly run the destructors for the operands and results. - getOperandStorage().~OperandStorage(); - - for (auto &result : getInstResults()) - result.~InstResult(); + for (auto &blockList : getBlockLists()) + for (Block &block : blockList) + block.dropAllReferences(); - // Explicitly run the destructors for the successors. if (isTerminator()) - for (auto &successor : getBlockOperands()) - successor.~BlockOperand(); - - // Explicitly destroy the block list. - for (auto &blockList : getBlockLists()) - blockList.~BlockList(); + for (auto &dest : getBlockOperands()) + dest.drop(); } /// Return true if there are no users of any results of this operation. -bool OperationInst::use_empty() const { +bool Instruction::use_empty() const { for (auto *result : getResults()) if (!result->use_empty()) return false; return true; } -ArrayRef<NamedAttribute> OperationInst::getAttrs() const { +ArrayRef<NamedAttribute> Instruction::getAttrs() const { if (!attrs) return {}; return attrs->getElements(); } -void OperationInst::destroy() { - this->~OperationInst(); - free(this); -} +bool Instruction::isReturn() const { return isa<ReturnOp>(); } -/// Return the context this operation is associated with. -MLIRContext *OperationInst::getContext() const { - // If we have a result or operand type, that is a constant time way to get - // to the context. - if (getNumResults()) - return getResult(0)->getType().getContext(); - if (getNumOperands()) - return getOperand(0)->getType().getContext(); - - // In the very odd case where we have no operands or results, fall back to - // doing a find. - return getFunction()->getContext(); -} - -bool OperationInst::isReturn() const { return isa<ReturnOp>(); } - -void OperationInst::setSuccessor(Block *block, unsigned index) { +void Instruction::setSuccessor(Block *block, unsigned index) { assert(index < getNumSuccessors()); getBlockOperands()[index].set(block); } -auto OperationInst::getNonSuccessorOperands() const +auto Instruction::getNonSuccessorOperands() const -> llvm::iterator_range<const_operand_iterator> { return {const_operand_iterator(this, 0), const_operand_iterator(this, getSuccessorOperandIndex(0))}; } -auto OperationInst::getNonSuccessorOperands() +auto Instruction::getNonSuccessorOperands() -> llvm::iterator_range<operand_iterator> { return {operand_iterator(this, 0), operand_iterator(this, getSuccessorOperandIndex(0))}; } -auto OperationInst::getSuccessorOperands(unsigned index) const +auto Instruction::getSuccessorOperands(unsigned index) const -> llvm::iterator_range<const_operand_iterator> { assert(isTerminator() && "Only terminators have successors."); unsigned succOperandIndex = getSuccessorOperandIndex(index); @@ -558,7 +525,7 @@ auto OperationInst::getSuccessorOperands(unsigned index) const const_operand_iterator(this, succOperandIndex + getNumSuccessorOperands(index))}; } -auto OperationInst::getSuccessorOperands(unsigned index) +auto Instruction::getSuccessorOperands(unsigned index) -> llvm::iterator_range<operand_iterator> { assert(isTerminator() && "Only terminators have successors."); unsigned succOperandIndex = getSuccessorOperandIndex(index); @@ -569,7 +536,7 @@ auto OperationInst::getSuccessorOperands(unsigned index) /// If an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. -void OperationInst::setAttr(Identifier name, Attribute value) { +void Instruction::setAttr(Identifier name, Attribute value) { assert(value && "attributes may never be null"); auto origAttrs = getAttrs(); @@ -591,7 +558,7 @@ void OperationInst::setAttr(Identifier name, Attribute value) { /// Remove the attribute with the specified name if it exists. The return /// value indicates whether the attribute was present or not. -auto OperationInst::removeAttr(Identifier name) -> RemoveResult { +auto Instruction::removeAttr(Identifier name) -> RemoveResult { auto origAttrs = getAttrs(); for (unsigned i = 0, e = origAttrs.size(); i != e; ++i) { if (origAttrs[i].first == name) { @@ -609,8 +576,8 @@ auto OperationInst::removeAttr(Identifier name) -> RemoveResult { /// Attempt to constant fold this operation with the specified constant /// operand values. If successful, this returns false and fills in the /// results vector. If not, this returns true and results is unspecified. -bool OperationInst::constantFold(ArrayRef<Attribute> operands, - SmallVectorImpl<Attribute> &results) const { +bool Instruction::constantFold(ArrayRef<Attribute> operands, + SmallVectorImpl<Attribute> &results) const { if (auto *abstractOp = getAbstractOperation()) { // If we have a registered operation definition matching this one, use it to // try to constant fold the operation. @@ -633,7 +600,7 @@ bool OperationInst::constantFold(ArrayRef<Attribute> operands, } /// Attempt to fold this operation using the Op's registered foldHook. -bool OperationInst::fold(SmallVectorImpl<Value *> &results) { +bool Instruction::fold(SmallVectorImpl<Value *> &results) { if (auto *abstractOp = getAbstractOperation()) { // If we have a registered operation definition matching this one, use it to // try to constant fold the operation. @@ -645,7 +612,7 @@ bool OperationInst::fold(SmallVectorImpl<Value *> &results) { /// Emit an error with the op name prefixed, like "'dim' op " which is /// convenient for verifiers. -bool OperationInst::emitOpError(const Twine &message) const { +bool Instruction::emitOpError(const Twine &message) const { return emitError(Twine('\'') + getName().getStringRef() + "' op " + message); } @@ -663,57 +630,55 @@ Instruction *Instruction::clone(BlockAndValueMapping &mapper, SmallVector<Value *, 8> operands; SmallVector<Block *, 2> successors; - auto *opInst = cast<OperationInst>(this); - operands.reserve(getNumOperands() + opInst->getNumSuccessors()); + operands.reserve(getNumOperands() + getNumSuccessors()); - if (!opInst->isTerminator()) { + if (!isTerminator()) { // Non-terminators just add all the operands. for (auto *opValue : getOperands()) operands.push_back(mapper.lookupOrDefault(const_cast<Value *>(opValue))); } else { // We add the operands separated by nullptr's for each successor. - unsigned firstSuccOperand = opInst->getNumSuccessors() - ? opInst->getSuccessorOperandIndex(0) - : opInst->getNumOperands(); - auto InstOperands = opInst->getInstOperands(); + unsigned firstSuccOperand = + getNumSuccessors() ? getSuccessorOperandIndex(0) : getNumOperands(); + auto InstOperands = getInstOperands(); unsigned i = 0; for (; i != firstSuccOperand; ++i) operands.push_back( mapper.lookupOrDefault(const_cast<Value *>(InstOperands[i].get()))); - successors.reserve(opInst->getNumSuccessors()); - for (unsigned succ = 0, e = opInst->getNumSuccessors(); succ != e; ++succ) { - successors.push_back(mapper.lookupOrDefault( - const_cast<Block *>(opInst->getSuccessor(succ)))); + successors.reserve(getNumSuccessors()); + for (unsigned succ = 0, e = getNumSuccessors(); succ != e; ++succ) { + successors.push_back( + mapper.lookupOrDefault(const_cast<Block *>(getSuccessor(succ)))); // Add sentinel to delineate successor operands. operands.push_back(nullptr); // Remap the successors operands. - for (auto *operand : opInst->getSuccessorOperands(succ)) + for (auto *operand : getSuccessorOperands(succ)) operands.push_back( mapper.lookupOrDefault(const_cast<Value *>(operand))); } } SmallVector<Type, 8> resultTypes; - resultTypes.reserve(opInst->getNumResults()); - for (auto *result : opInst->getResults()) + resultTypes.reserve(getNumResults()); + for (auto *result : getResults()) resultTypes.push_back(result->getType()); - unsigned numBlockLists = opInst->getNumBlockLists(); - auto *newOp = OperationInst::create( - getLoc(), opInst->getName(), operands, resultTypes, opInst->getAttrs(), - successors, numBlockLists, opInst->hasResizableOperandsList(), context); + unsigned numBlockLists = getNumBlockLists(); + auto *newOp = Instruction::create(getLoc(), getName(), operands, resultTypes, + getAttrs(), successors, numBlockLists, + hasResizableOperandsList(), context); // Clone the block lists. for (unsigned i = 0; i != numBlockLists; ++i) - opInst->getBlockList(i).cloneInto(&newOp->getBlockList(i), mapper, context); + getBlockList(i).cloneInto(&newOp->getBlockList(i), mapper, context); // Remember the mapping of any results. - for (unsigned i = 0, e = opInst->getNumResults(); i != e; ++i) - mapper.map(opInst->getResult(i), newOp->getResult(i)); + for (unsigned i = 0, e = getNumResults(); i != e; ++i) + mapper.map(getResult(i), newOp->getResult(i)); return newOp; } diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 2ab151f8913..94df36c94f6 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -17,7 +17,7 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/Function.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpImplementation.h" diff --git a/mlir/lib/IR/PatternMatch.cpp b/mlir/lib/IR/PatternMatch.cpp index 90d768c844e..49b3897f72f 100644 --- a/mlir/lib/IR/PatternMatch.cpp +++ b/mlir/lib/IR/PatternMatch.cpp @@ -16,7 +16,7 @@ // ============================================================================= #include "mlir/IR/PatternMatch.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/Value.h" using namespace mlir; diff --git a/mlir/lib/IR/Value.cpp b/mlir/lib/IR/Value.cpp index ca2ca5dbadf..94873c5e330 100644 --- a/mlir/lib/IR/Value.cpp +++ b/mlir/lib/IR/Value.cpp @@ -17,7 +17,7 @@ #include "mlir/IR/Value.h" #include "mlir/IR/Function.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" using namespace mlir; /// If this value is the result of an Instruction, return the instruction diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp index 3e3dbb8119f..96588874198 100644 --- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp @@ -20,7 +20,7 @@ //===----------------------------------------------------------------------===// #include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Module.h" #include "mlir/StandardOps/StandardOps.h" diff --git a/mlir/lib/Transforms/SimplifyAffineStructures.cpp b/mlir/lib/Transforms/SimplifyAffineStructures.cpp index ae003b3e495..80b2de130e7 100644 --- a/mlir/lib/Transforms/SimplifyAffineStructures.cpp +++ b/mlir/lib/Transforms/SimplifyAffineStructures.cpp @@ -21,7 +21,7 @@ #include "mlir/Analysis/AffineStructures.h" #include "mlir/IR/Function.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/IR/IntegerSet.h" #include "mlir/Pass.h" #include "mlir/Transforms/Passes.h" diff --git a/mlir/lib/Transforms/StripDebugInfo.cpp b/mlir/lib/Transforms/StripDebugInfo.cpp index a11276cfea6..6e1d5ff2d11 100644 --- a/mlir/lib/Transforms/StripDebugInfo.cpp +++ b/mlir/lib/Transforms/StripDebugInfo.cpp @@ -16,6 +16,7 @@ // ============================================================================= #include "mlir/IR/Function.h" +#include "mlir/IR/Instruction.h" #include "mlir/Pass.h" #include "mlir/Transforms/Passes.h" diff --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp index ce16656243d..99079119dab 100644 --- a/mlir/lib/Transforms/Utils/LoopUtils.cpp +++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp @@ -29,7 +29,7 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/InstVisitor.h" -#include "mlir/IR/Instructions.h" +#include "mlir/IR/Instruction.h" #include "mlir/StandardOps/StandardOps.h" #include "llvm/ADT/DenseMap.h" #include "llvm/Support/Debug.h" |

