forked from OSchip/llvm-project
Fold IROperandOwner into Instruction.
PiperOrigin-RevId: 232159334
This commit is contained in:
parent
38f8dc67be
commit
dae0263e0b
|
@ -68,14 +68,11 @@ template <typename ObjectType, typename ElementType> class OperandIterator;
|
|||
/// Instructions can be nested within for and if instructions effectively
|
||||
/// forming a tree. Child instructions are organized into instruction blocks
|
||||
/// represented by a 'Block' class.
|
||||
class Instruction : public IROperandOwner,
|
||||
public llvm::ilist_node_with_parent<Instruction, Block> {
|
||||
class Instruction : public llvm::ilist_node_with_parent<Instruction, Block> {
|
||||
public:
|
||||
enum class Kind {
|
||||
OperationInst = (int)IROperandOwner::Kind::OperationInst,
|
||||
};
|
||||
enum class Kind { OperationInst };
|
||||
|
||||
Kind getKind() const { return (Kind)IROperandOwner::getKind(); }
|
||||
Kind getKind() const { return Kind::OperationInst; }
|
||||
|
||||
/// Remove this instruction from its parent block and delete it.
|
||||
void erase();
|
||||
|
@ -92,6 +89,15 @@ public:
|
|||
const Block *getBlock() const { return block; }
|
||||
Block *getBlock() { return block; }
|
||||
|
||||
/// Return the context this operation is associated with.
|
||||
MLIRContext *getContext() const;
|
||||
|
||||
/// The source location the operation was defined or derived from.
|
||||
Location getLoc() const { return location; }
|
||||
|
||||
/// Set the source location the operation was defined or derived from.
|
||||
void setLoc(Location loc) { location = loc; }
|
||||
|
||||
/// Returns the closest surrounding instruction that contains this instruction
|
||||
/// or nullptr if this is a top-level instruction.
|
||||
Instruction *getParentInst() const;
|
||||
|
@ -186,14 +192,8 @@ public:
|
|||
/// handlers that may be listening.
|
||||
void emitNote(const Twine &message) const;
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast.
|
||||
static bool classof(const IROperandOwner *ptr) {
|
||||
return ptr->getKind() <= IROperandOwner::Kind::INST_LAST;
|
||||
}
|
||||
|
||||
protected:
|
||||
Instruction(Kind kind, Location location)
|
||||
: IROperandOwner((IROperandOwner::Kind)kind, location) {}
|
||||
Instruction(Location location) : location(location) {}
|
||||
|
||||
// Instructions are deleted through the destroy() member because this class
|
||||
// does not have a virtual destructor.
|
||||
|
@ -203,6 +203,10 @@ private:
|
|||
/// The instruction block that containts this instruction.
|
||||
Block *block = nullptr;
|
||||
|
||||
/// This holds information about the source location the operation was defined
|
||||
/// or derived from.
|
||||
Location location;
|
||||
|
||||
/// Relative order of this instruction in its parent block. Used for
|
||||
/// O(1) local dominance checks between instructions.
|
||||
mutable unsigned orderIndex = 0;
|
||||
|
|
|
@ -570,9 +570,7 @@ public:
|
|||
void destroy();
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast.
|
||||
static bool classof(const IROperandOwner *ptr) {
|
||||
return ptr->getKind() == IROperandOwner::Kind::OperationInst;
|
||||
}
|
||||
static bool classof(const Instruction *ptr) { return true; }
|
||||
|
||||
private:
|
||||
const unsigned numResults, numSuccs, numBlockLists;
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
|
||||
namespace mlir {
|
||||
|
||||
class Instruction;
|
||||
class IROperand;
|
||||
class IROperandOwner;
|
||||
template <typename OperandType, typename OwnerType> class ValueUseIterator;
|
||||
|
||||
class IRObjectWithUseList {
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
/// Returns true if this value has exactly one use.
|
||||
inline bool hasOneUse() const;
|
||||
|
||||
using use_iterator = ValueUseIterator<IROperand, IROperandOwner>;
|
||||
using use_iterator = ValueUseIterator<IROperand, Instruction>;
|
||||
using use_range = llvm::iterator_range<use_iterator>;
|
||||
|
||||
inline use_iterator use_begin() const;
|
||||
|
@ -74,44 +74,11 @@ private:
|
|||
IROperand *firstUse = nullptr;
|
||||
};
|
||||
|
||||
/// Subclasses of IROperandOwner can be the owner of an IROperand. In practice
|
||||
/// this is the common base between Instructions.
|
||||
class IROperandOwner {
|
||||
public:
|
||||
enum class Kind {
|
||||
OperationInst,
|
||||
|
||||
/// These enums define ranges used for classof implementations.
|
||||
INST_LAST = OperationInst,
|
||||
};
|
||||
|
||||
Kind getKind() const { return locationAndKind.getInt(); }
|
||||
|
||||
/// The source location the operation was defined or derived from.
|
||||
Location getLoc() const { return locationAndKind.getPointer(); }
|
||||
|
||||
/// Set the source location the operation was defined or derived from.
|
||||
void setLoc(Location loc) { locationAndKind.setPointer(loc); }
|
||||
|
||||
/// Return the context this operation is associated with.
|
||||
MLIRContext *getContext() const;
|
||||
|
||||
protected:
|
||||
IROperandOwner(Kind kind, Location location)
|
||||
: locationAndKind(location, kind) {}
|
||||
|
||||
private:
|
||||
/// This holds information about the source location the operation was defined
|
||||
/// or derived from, along with the kind of subclass this is.
|
||||
llvm::PointerIntPair<Location, 3, Kind> locationAndKind;
|
||||
};
|
||||
|
||||
/// A reference to a value, suitable for use as an operand of an instruction,
|
||||
/// instruction, etc.
|
||||
/// A reference to a value, suitable for use as an operand of an instruction.
|
||||
class IROperand {
|
||||
public:
|
||||
IROperand(IROperandOwner *owner) : owner(owner) {}
|
||||
IROperand(IROperandOwner *owner, IRObjectWithUseList *value)
|
||||
IROperand(Instruction *owner) : owner(owner) {}
|
||||
IROperand(Instruction *owner, IRObjectWithUseList *value)
|
||||
: value(value), owner(owner) {
|
||||
insertIntoCurrent();
|
||||
}
|
||||
|
@ -130,8 +97,8 @@ public:
|
|||
|
||||
/// Return the owner of this operand, for example, the OperationInst that
|
||||
/// contains an InstOperand.
|
||||
IROperandOwner *getOwner() { return owner; }
|
||||
const IROperandOwner *getOwner() const { return owner; }
|
||||
Instruction *getOwner() { return owner; }
|
||||
const Instruction *getOwner() const { return owner; }
|
||||
|
||||
/// \brief Remove this use of the operand.
|
||||
void drop() {
|
||||
|
@ -176,9 +143,8 @@ private:
|
|||
/// This points to the previous link in the use-chain.
|
||||
IROperand **back = nullptr;
|
||||
|
||||
/// The owner of this operand, for example, the OperationInst that contains an
|
||||
/// InstOperand.
|
||||
IROperandOwner *const owner;
|
||||
/// The instruction owner of this operand.
|
||||
Instruction *const owner;
|
||||
|
||||
/// Operands are not copyable or assignable.
|
||||
IROperand(const IROperand &use) = delete;
|
||||
|
|
|
@ -100,7 +100,7 @@ protected:
|
|||
Value(Kind kind, Type type) : typeAndKind(type, kind) {}
|
||||
|
||||
private:
|
||||
const llvm::PointerIntPair<Type, 3, Kind> typeAndKind;
|
||||
const llvm::PointerIntPair<Type, 1, Kind> typeAndKind;
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &os, const Value &value) {
|
||||
|
|
|
@ -146,6 +146,11 @@ void Instruction::destroy() {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the context this operation is associated with.
|
||||
MLIRContext *Instruction::getContext() const {
|
||||
return cast<OperationInst>(this)->getContext();
|
||||
}
|
||||
|
||||
Instruction *Instruction::getParentInst() const {
|
||||
return block ? block->getContainingInst() : nullptr;
|
||||
}
|
||||
|
@ -467,8 +472,8 @@ OperationInst::OperationInst(Location location, OperationName name,
|
|||
unsigned numBlockLists,
|
||||
ArrayRef<NamedAttribute> attributes,
|
||||
MLIRContext *context)
|
||||
: Instruction(Kind::OperationInst, location), numResults(numResults),
|
||||
numSuccs(numSuccessors), numBlockLists(numBlockLists), name(name) {
|
||||
: 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");
|
||||
|
|
|
@ -39,7 +39,7 @@ Function *Value::getFunction() {
|
|||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// IROperandOwner implementation.
|
||||
// IRObjectWithUseList implementation.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Replace all uses of 'this' value with the new value, updating anything in
|
||||
|
@ -59,14 +59,6 @@ void IRObjectWithUseList::dropAllUses() {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the context this operation is associated with.
|
||||
MLIRContext *IROperandOwner::getContext() const {
|
||||
switch (getKind()) {
|
||||
case Kind::OperationInst:
|
||||
return cast<OperationInst>(this)->getContext();
|
||||
}
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// BlockArgument implementation.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
Loading…
Reference in New Issue