forked from OSchip/llvm-project
[mlir][SymbolTable] Small optimization to walking symbol references
* Check region count for unknown symbol tables first, as it is a faster check * Add an accessor to MutableDictionaryAttr to get the internal dictionary without creating a new one if it is empty. This avoids an otherwise unnecessary lookup of an MLIRContext.
This commit is contained in:
parent
fa4174792a
commit
73547b08de
|
@ -1621,6 +1621,10 @@ public:
|
|||
/// Return the underlying dictionary attribute.
|
||||
DictionaryAttr getDictionary(MLIRContext *context) const;
|
||||
|
||||
/// Return the underlying dictionary attribute or null if there are no
|
||||
/// attributes within this dictionary.
|
||||
DictionaryAttr getDictionaryOrNull() const { return attrs; }
|
||||
|
||||
/// Return all of the attributes on this operation.
|
||||
ArrayRef<NamedAttribute> getAttrs() const;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ using namespace mlir;
|
|||
/// Return true if the given operation is unknown and may potentially define a
|
||||
/// symbol table.
|
||||
static bool isPotentiallyUnknownSymbolTable(Operation *op) {
|
||||
return !op->getDialect() && op->getNumRegions() == 1;
|
||||
return op->getNumRegions() == 1 && !op->getDialect();
|
||||
}
|
||||
|
||||
/// Returns the string name of the given symbol, or None if this is not a
|
||||
|
@ -442,9 +442,9 @@ static WalkResult walkSymbolRefs(
|
|||
Operation *op,
|
||||
function_ref<WalkResult(SymbolTable::SymbolUse, ArrayRef<int>)> callback) {
|
||||
// Check to see if the operation has any attributes.
|
||||
if (op->getMutableAttrDict().empty())
|
||||
DictionaryAttr attrDict = op->getMutableAttrDict().getDictionaryOrNull();
|
||||
if (!attrDict)
|
||||
return WalkResult::advance();
|
||||
DictionaryAttr attrDict = op->getAttrDictionary();
|
||||
|
||||
// A worklist of a container attribute and the current index into the held
|
||||
// attribute list.
|
||||
|
|
Loading…
Reference in New Issue