[Mlir-commits] [mlir] [MLIR][Python] Support `has_trait` for operations (PR #188492)

Maksim Levental llvmlistbot at llvm.org
Wed Mar 25 21:17:12 PDT 2026


================
@@ -651,6 +651,10 @@ MlirContext mlirOperationGetContext(MlirOperation op) {
   return wrap(unwrap(op)->getContext());
 }
 
+bool mlirOperationHasTrait(MlirOperation op, MlirTypeID traitTypeID) {
+  return unwrap(op)->getName().hasTrait(unwrap(traitTypeID));
----------------
makslevental wrote:

i won't block binding `OperationName` but i just don't think it's super useful? like what else from that type do you see us using in the future? here are all the members:

```
OperationName
    OperationName(StringRef name, MLIRContext* context)
    isRegistered() const -> bool
    getTypeID() const -> TypeID
    getRegisteredInfo() const -> std::optional<RegisteredOperationName>
    foldHook(Operation* op, ArrayRef<Attribute> operands, SmallVectorImpl<OpFoldResult>& results) const -> LogicalResult
    getCanonicalizationPatterns(RewritePatternSet& results, MLIRContext* context) const -> void
    hasTrait<Trait>() const -> bool
    hasTrait(TypeID traitID) const -> bool
    mightHaveTrait<Trait>() const -> bool
    mightHaveTrait(TypeID traitID) const -> bool
    getParseAssemblyFn() const -> ParseAssemblyFn
    populateDefaultAttrs(NamedAttrList& attrs) const -> void
    printAssembly(Operation* op, OpAsmPrinter& p, StringRef defaultDialect) const -> void
    verifyInvariants(Operation* op) const -> LogicalResult
    verifyRegionInvariants(Operation* op) const -> LogicalResult
    getAttributeNames() const -> ArrayRef<StringAttr>
    getInterface<T>() const -> T::Concept*
    attachInterface<Models...>() -> void
    hasPromiseOrImplementsInterface<InterfaceT>() const -> bool
    hasInterface<T>() const -> bool
    hasInterface(TypeID interfaceID) const -> bool
    mightHaveInterface<T>() const -> bool
    mightHaveInterface(TypeID interfaceID) const -> bool
    getInherentAttr(Operation* op, StringRef name) const -> std::optional<Attribute>
    setInherentAttr(Operation* op, StringAttr name, Attribute value) const -> void
    populateInherentAttrs(Operation* op, NamedAttrList& attrs) const -> void
    verifyInherentAttrs(NamedAttrList& attributes, function_ref<InFlightDiagnostic()> emitError) const -> LogicalResult
    getOpPropertyByteSize() const -> int
    destroyOpProperties(OpaqueProperties properties) const -> void
    initOpProperties(OpaqueProperties storage, OpaqueProperties init) const -> void
    populateDefaultProperties(OpaqueProperties properties) const -> void
    getOpPropertiesAsAttribute(Operation* op) const -> Attribute
    setOpPropertiesFromAttribute(OperationName opName, OpaqueProperties properties, Attribute attr, function_ref<InFlightDiagnostic()> emitError) const -> LogicalResult
    copyOpProperties(OpaqueProperties lhs, OpaqueProperties rhs) const -> void
    compareOpProperties(OpaqueProperties lhs, OpaqueProperties rhs) const -> bool
    hashOpProperties(OpaqueProperties properties) const -> llvm::hash_code
    getDialect() const -> Dialect*
    getDialectNamespace() const -> StringRef
    stripDialect() const -> StringRef
    getContext() -> MLIRContext*
    getStringRef() const -> StringRef
    getIdentifier() const -> StringAttr
    print(raw_ostream& os) const -> void
    dump() const -> void
    getAsOpaquePointer() const -> void*
    getFromOpaquePointer(const void* pointer) -> OperationName
    operator==(const OperationName& rhs) const -> bool
    operator!=(const OperationName& rhs) const -> bool
    OperationName(Impl* impl)
    getImpl() const -> Impl*
    setImpl(Impl* rhs) -> void
```

I don't see basically anything useful (maybe `hasInterface`).

https://github.com/llvm/llvm-project/pull/188492


More information about the Mlir-commits mailing list