forked from OSchip/llvm-project
Add a utility Instruction::getDialect method to return the dialect an operation is associated with, or nullptr if the associated dialect has not been registered.
PiperOrigin-RevId: 240402300
This commit is contained in:
parent
bee7b53031
commit
97db10d413
|
@ -92,6 +92,10 @@ public:
|
||||||
/// Return the context this operation is associated with.
|
/// Return the context this operation is associated with.
|
||||||
MLIRContext *getContext();
|
MLIRContext *getContext();
|
||||||
|
|
||||||
|
/// Return the dialact this operation is associated with, or nullptr if the
|
||||||
|
/// associated dialect is not registered.
|
||||||
|
Dialect *getDialect();
|
||||||
|
|
||||||
/// The source location the operation was defined or derived from.
|
/// The source location the operation was defined or derived from.
|
||||||
Location getLoc() { return location; }
|
Location getLoc() { return location; }
|
||||||
|
|
||||||
|
|
|
@ -300,6 +300,19 @@ MLIRContext *Instruction::getContext() {
|
||||||
return getFunction()->getContext();
|
return getFunction()->getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the dialact this operation is associated with, or nullptr if the
|
||||||
|
/// associated dialect is not registered.
|
||||||
|
Dialect *Instruction::getDialect() {
|
||||||
|
if (auto *abstractOp = getAbstractOperation())
|
||||||
|
return &abstractOp->dialect;
|
||||||
|
|
||||||
|
// If this operation hasn't been registered or doesn't have abstract
|
||||||
|
// operation, fall back to a dialect which matches the prefix.
|
||||||
|
auto opName = getName().getStringRef();
|
||||||
|
auto dialectPrefix = opName.split('.').first;
|
||||||
|
return getContext()->getRegisteredDialect(dialectPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
Instruction *Instruction::getParentInst() {
|
Instruction *Instruction::getParentInst() {
|
||||||
return block ? block->getContainingInst() : nullptr;
|
return block ? block->getContainingInst() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue