[Mlir-commits] [mlir] 78d00a1 - [mlir][LLVM] Convert alias metadata to using attributes instead of ops

Markus Böck llvmlistbot at llvm.org
Fri Jul 14 02:14:49 PDT 2023


Author: Markus Böck
Date: 2023-07-14T11:14:42+02:00
New Revision: 78d00a160f34bffd25fef6e29e35a6b3906d6752

URL: https://github.com/llvm/llvm-project/commit/78d00a160f34bffd25fef6e29e35a6b3906d6752
DIFF: https://github.com/llvm/llvm-project/commit/78d00a160f34bffd25fef6e29e35a6b3906d6752.diff

LOG: [mlir][LLVM] Convert alias metadata to using attributes instead of ops

Using MLIR attributes instead of metadata has many advantages:
* No indirection: Attributes can simply refer to each other seemlessly without having to use the indirection of `SymbolRefAttr`. This also gives us correctness by construction in a lot of places as well
* Multithreading save: The Attribute infrastructure gives us thread-safety for free. Creating operations and inserting them into a block is not thread-safe. This is a major use case for e.g. the inliner in MLIR which runs in parallel
* Easier to create: There is no need for a builder or a metadata region

This patch therefore does exactly that. It leverages the new distinct attributes to create distinct alias domains and scopes in a deterministic and threadsafe manner.

Differential Revision: https://reviews.llvm.org/D155159

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
    mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
    mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
    mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    mlir/include/mlir/Target/LLVMIR/ModuleImport.h
    mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
    mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
    mlir/lib/Dialect/LLVMIR/IR/LLVMInterfaces.cpp
    mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
    mlir/lib/Target/LLVMIR/ModuleImport.cpp
    mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
    mlir/test/Dialect/LLVMIR/invalid.mlir
    mlir/test/Dialect/LLVMIR/roundtrip.mlir
    mlir/test/Target/LLVMIR/Import/metadata-alias-scopes.ll
    mlir/test/Target/LLVMIR/llvmir.mlir
    mlir/test/mlir-tblgen/llvm-intrinsics.td
    mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 95dbdcd42af109..56a5682d0bc93f 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -562,4 +562,92 @@ def LLVM_MemoryEffectsAttr : LLVM_Attr<"MemoryEffects", "memory_effects"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===----------------------------------------------------------------------===//
+// AliasScopeDomainAttr
+//===----------------------------------------------------------------------===//
+
+def LLVM_AliasScopeDomainAttr : LLVM_Attr<"AliasScopeDomain",
+                                          "alias_scope_domain"> {
+  let parameters = (ins
+    "DistinctAttr":$id,
+    OptionalParameter<"StringAttr">:$description
+  );
+
+  let builders = [
+    AttrBuilder<(ins CArg<"StringAttr", "{}">:$description), [{
+      return $_get($_ctxt, DistinctAttr::create(UnitAttr::get($_ctxt)), description);
+    }]>
+  ];
+
+  let summary = "LLVM dialect alias scope domain metadata";
+
+  let description = [{
+    Defines a domain that may be associated with an alias scope.
+
+    See the following link for more details:
+    https://llvm.org/docs/LangRef.html#noalias-and-alias-scope-metadata
+  }];
+
+  let assemblyFormat = "`<` struct(params) `>`";
+}
+
+//===----------------------------------------------------------------------===//
+// AliasScopeAttr
+//===----------------------------------------------------------------------===//
+
+def LLVM_AliasScopeAttr : LLVM_Attr<"AliasScope", "alias_scope"> {
+  let parameters = (ins
+    "DistinctAttr":$id,
+    "AliasScopeDomainAttr":$domain,
+    OptionalParameter<"StringAttr">:$description
+  );
+
+  let builders = [
+    AttrBuilderWithInferredContext<(ins
+      "AliasScopeDomainAttr":$domain,
+      CArg<"StringAttr", "{}">:$description
+    ), [{
+      MLIRContext *ctx = domain.getContext();
+      return $_get(ctx, DistinctAttr::create(UnitAttr::get(ctx)), domain, description);
+    }]>
+  ];
+
+  let description = [{
+    Defines an alias scope that can be attached to a memory-accessing operation.
+    Such scopes can be used in combination with `noalias` metadata to indicate
+    that sets of memory-affecting operations in one scope do not alias with
+    memory-affecting operations in another scope.
+
+    Example:
+    ```mlir
+    #domain = #llvm.alias_scope_domain<id = distinct[1]<>, description = "Optional domain description">
+    #scope1 = #llvm.alias_scope<id = distinct[2]<>, domain = #domain>
+    #scope2 = #llvm.alias_scope<id = distinct[3]<>, domain = #domain, description = "Optional scope description">
+    llvm.func @foo(%ptr1 : !llvm.ptr<i32>) {
+        %c0 = llvm.mlir.constant(0 : i32) : i32
+        %c4 = llvm.mlir.constant(4 : i32) : i32
+        %1 = llvm.ptrtoint %ptr1 : !llvm.ptr<i32> to i32
+        %2 = llvm.add %1, %c1 : i32
+        %ptr2 = llvm.inttoptr %2 : i32 to !llvm.ptr<i32>
+        llvm.store %c0, %ptr1 { alias_scopes = [#scope1], llvm.noalias = [#scope2] } : !llvm.ptr<i32>
+        llvm.store %c4, %ptr2 { alias_scopes = [#scope2], llvm.noalias = [#scope1] } : !llvm.ptr<i32>
+        llvm.return
+    }
+    ```
+
+    See the following link for more details:
+    https://llvm.org/docs/LangRef.html#noalias-and-alias-scope-metadata
+  }];
+
+  let summary = "LLVM dialect alias scope";
+
+  let assemblyFormat = "`<` struct(params) `>`";
+}
+
+def LLVM_AliasScopeArrayAttr
+    : TypedArrayAttrBase<LLVM_AliasScopeAttr,
+                         LLVM_AliasScopeAttr.summary # " array"> {
+  let constBuilderCall = ?;
+}
+
 #endif // LLVMIR_ATTRDEFS

diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index 010ffb9eccb1bc..d131a493d1e5ea 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -325,15 +325,15 @@ def LLVM_MemsetOp : LLVM_ZeroResultIntrOp<"memset", [0, 2],
 
 def LLVM_NoAliasScopeDeclOp
     : LLVM_ZeroResultIntrOp<"experimental.noalias.scope.decl"> {
-  let arguments = (ins SymbolRefAttr:$scope);
+  let arguments = (ins LLVM_AliasScopeAttr:$scope);
   string llvmBuilder = [{
     // Wrap the scope argument into a list since the LLVM IR intrinsic takes
     // a list containing exactly one scope rather than a scope itself.
-    llvm::MDNode* node = moduleTranslation.getAliasScopes(op, {$scope});
+    llvm::MDNode* node = moduleTranslation.getAliasScopes({$scope});
     builder.CreateNoAliasScopeDeclaration(node);
   }];
   string mlirBuilder = [{
-    FailureOr<SmallVector<SymbolRefAttr>> scopeAttrs =
+    FailureOr<SmallVector<LLVM::AliasScopeAttr>> scopeAttrs =
       moduleImport.matchAliasScopeAttrs(llvmOperands[0]);
     // Drop the intrinsic if the alias scope translation fails since the scope
     // is not used by an aliasing operation, such as a load or store, that is

diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
index 3d635729821830..2351da9309842c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
@@ -279,8 +279,8 @@ class LLVM_MemAccessOpBase<string mnemonic, list<Trait> traits = []> :
       DeclareOpInterfaceMethods<AliasAnalysisOpInterface>], traits)>,
     LLVM_MemOpPatterns {
   dag aliasAttrs = (ins OptionalAttr<SymbolRefArrayAttr>:$access_groups,
-                    OptionalAttr<SymbolRefArrayAttr>:$alias_scopes,
-                    OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes,
+                    OptionalAttr<LLVM_AliasScopeArrayAttr>:$alias_scopes,
+                    OptionalAttr<LLVM_AliasScopeArrayAttr>:$noalias_scopes,
                     OptionalAttr<SymbolRefArrayAttr>:$tbaa);
 }
 
@@ -324,8 +324,8 @@ class LLVM_IntrOpBase<Dialect dialect, string opName, string enumName,
             (ins OptionalAttr<SymbolRefArrayAttr>:$access_groups),
             (ins )),
         !if(!gt(requiresAliasAnalysis, 0),
-            (ins OptionalAttr<SymbolRefArrayAttr>:$alias_scopes,
-                 OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes,
+            (ins OptionalAttr<LLVM_AliasScopeArrayAttr>:$alias_scopes,
+                 OptionalAttr<LLVM_AliasScopeArrayAttr>:$noalias_scopes,
                  OptionalAttr<SymbolRefArrayAttr>:$tbaa),
             (ins )));
   string resultPattern = !if(!gt(numResults, 1),

diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 98f5b844047070..81374930bd5386 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1101,68 +1101,6 @@ def LLVM_MetadataOp : LLVM_Op<"metadata", [
   let hasRegionVerifier = 1;
 }
 
-def LLVM_AliasScopeDomainMetadataOp : LLVM_Op<"alias_scope_domain", [
-  HasParent<"MetadataOp">, Symbol
-]> {
-  let arguments = (ins
-    SymbolNameAttr:$sym_name,
-    OptionalAttr<StrAttr>:$description
-  );
-  let summary = "LLVM dialect alias.scope domain metadata.";
-  let description = [{
-    Defines a domain that may be associated with an alias scope.
-
-    See the following link for more details:
-    https://llvm.org/docs/LangRef.html#noalias-and-alias-scope-metadata
-  }];
-  let assemblyFormat = "$sym_name attr-dict";
-}
-
-def LLVM_AliasScopeMetadataOp : LLVM_Op<"alias_scope", [
-  HasParent<"MetadataOp">, Symbol
-]> {
-  let arguments = (ins
-    SymbolNameAttr:$sym_name,
-    FlatSymbolRefAttr:$domain,
-    OptionalAttr<StrAttr>:$description
-  );
-  let summary = "LLVM dialect alias.scope metadata.";
-  let description = [{
-    Defines an alias scope that can be attached to a memory-accessing operation.
-    Such scopes can be used in combination with `noalias` metadata to indicate
-    that sets of memory-affecting operations in one scope do not alias with
-    memory-affecting operations in another scope.
-
-    Example:
-    ```mlir
-    module {
-      llvm.func @foo(%ptr1 : !llvm.ptr<i32>) {
-          %c0 = llvm.mlir.constant(0 : i32) : i32
-          %c4 = llvm.mlir.constant(4 : i32) : i32
-          %1 = llvm.ptrtoint %ptr1 : !llvm.ptr<i32> to i32
-          %2 = llvm.add %1, %c1 : i32
-          %ptr2 = llvm.inttoptr %2 : i32 to !llvm.ptr<i32>
-          llvm.store %c0, %ptr1 { alias_scopes = [@metadata::@scope1], llvm.noalias = [@metadata::@scope2] } : !llvm.ptr<i32>
-          llvm.store %c4, %ptr2 { alias_scopes = [@metadata::@scope2], llvm.noalias = [@metadata::@scope1] } : !llvm.ptr<i32>
-          llvm.return
-      }
-
-      llvm.metadata @metadata {
-        llvm.alias_scope_domain @unused_domain
-        llvm.alias_scope_domain @domain { description = "Optional domain description"}
-        llvm.alias_scope @scope1 { domain = @domain }
-        llvm.alias_scope @scope2 { domain = @domain, description = "Optional scope description" }
-      }
-    }
-    ```
-
-    See the following link for more details:
-    https://llvm.org/docs/LangRef.html#noalias-and-alias-scope-metadata
-  }];
-  let assemblyFormat = "$sym_name attr-dict";
-  let hasVerifier = 1;
-}
-
 def LLVM_AccessGroupMetadataOp : LLVM_Op<"access_group", [
   HasParent<"MetadataOp">, Symbol
 ]> {

diff  --git a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
index b2206e98c1e157..14263889d5cb1d 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
@@ -151,9 +151,9 @@ class ModuleImport {
   /// Converts `value` to a label attribute. Asserts if the matching fails.
   DILabelAttr matchLabelAttr(llvm::Value *value);
 
-  /// Converts `value` to an array of symbol references pointing to alias scope
-  /// operations, or returns failure if the conversion fails.
-  FailureOr<SmallVector<SymbolRefAttr>>
+  /// Converts `value` to an array of alias scopes or returns failure if the
+  /// conversion fails.
+  FailureOr<SmallVector<AliasScopeAttr>>
   matchAliasScopeAttrs(llvm::Value *value);
 
   /// Translates the debug location.
@@ -202,10 +202,10 @@ class ModuleImport {
   LoopAnnotationAttr translateLoopAnnotationAttr(const llvm::MDNode *node,
                                                  Location loc) const;
 
-  /// Returns the symbol references pointing to the alias scope operations that
-  /// map to the alias scope nodes starting from the metadata `node`. Returns
-  /// failure, if any of the symbol references cannot be found.
-  FailureOr<SmallVector<SymbolRefAttr>>
+  /// Returns the alias scope attributes that map to the alias scope nodes
+  /// starting from the metadata `node`. Returns failure, if any of the
+  /// attributes cannot be found.
+  FailureOr<SmallVector<AliasScopeAttr>>
   lookupAliasScopeAttrs(const llvm::MDNode *node) const;
 
 private:
@@ -349,9 +349,9 @@ class ModuleImport {
   /// operations for all operations that return no result. All operations that
   /// return a result have a valueMapping entry instead.
   DenseMap<llvm::Instruction *, Operation *> noResultOpMapping;
-  /// Mapping between LLVM alias scope and domain metadata nodes and symbol
-  /// references to the LLVM dialect operations corresponding to these nodes.
-  DenseMap<const llvm::MDNode *, SymbolRefAttr> aliasScopeMapping;
+  /// Mapping between LLVM alias scope and domain metadata nodes and
+  /// attributes in the LLVM dialect corresponding to these nodes.
+  DenseMap<const llvm::MDNode *, Attribute> aliasScopeMapping;
   /// Mapping between LLVM TBAA metadata nodes and symbol references to the LLVM
   /// dialect TBAA operations corresponding to these nodes.
   DenseMap<const llvm::MDNode *, SymbolRefAttr> tbaaMapping;

diff  --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
index 9647c8db1bf3bd..f8e621009317b0 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -122,14 +122,13 @@ class ModuleTranslation {
   /// in these blocks.
   void forgetMapping(Region &region);
 
-  /// Returns the LLVM metadata corresponding to a symbol reference to an mlir
-  /// LLVM dialect alias scope operation.
-  llvm::MDNode *getAliasScope(Operation *op, SymbolRefAttr aliasScopeRef) const;
+  /// Returns the LLVM metadata corresponding to a mlir LLVM dialect alias scope
+  /// attribute.
+  llvm::MDNode *getAliasScope(AliasScopeAttr aliasScopeAttr) const;
 
-  /// Returns the LLVM metadata corresponding to an array of symbol references
-  /// to mlir LLVM dialect alias scope operations.
-  llvm::MDNode *getAliasScopes(Operation *op,
-                               ArrayRef<SymbolRefAttr> aliasScopeRefs) const;
+  /// Returns the LLVM metadata corresponding to an array of mlir LLVM dialect
+  /// alias scope attributes.
+  llvm::MDNode *getAliasScopes(ArrayRef<AliasScopeAttr> aliasScopeAttrs) const;
 
   // Sets LLVM metadata for memory operations that are in a parallel loop.
   void setAccessGroupsMetadata(AccessGroupOpInterface op,
@@ -335,7 +334,7 @@ class ModuleTranslation {
 
   /// Mapping from an alias scope metadata operation to its LLVM metadata.
   /// This map is populated on module entry.
-  DenseMap<Operation *, llvm::MDNode *> aliasScopeMetadataMapping;
+  DenseMap<Attribute, llvm::MDNode *> aliasScopeMetadataMapping;
 
   /// Mapping from a tbaa metadata operation to its LLVM metadata.
   /// This map is populated on module entry.

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 708f916125b34e..b0369094e6ecf2 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -3084,21 +3084,6 @@ LogicalResult TBAATypeDescriptorOp::verify() {
   return success();
 }
 
-//===----------------------------------------------------------------------===//
-// AliasScopeMetadataOp
-//===----------------------------------------------------------------------===//
-
-LogicalResult AliasScopeMetadataOp::verify() {
-  Operation *domainOp = SymbolTable::lookupNearestSymbolFrom(
-      this->getOperation(), getDomainAttr());
-  if (!isa_and_nonnull<AliasScopeDomainMetadataOp>(domainOp)) {
-    return this->emitOpError()
-           << "expected '" << getDomain()
-           << "' to reference a domain operation in the same region";
-  }
-  return success();
-}
-
 //===----------------------------------------------------------------------===//
 // OpAsmDialectInterface
 //===----------------------------------------------------------------------===//
@@ -3109,8 +3094,9 @@ struct LLVMOpAsmDialectInterface : public OpAsmDialectInterface {
 
   AliasResult getAlias(Attribute attr, raw_ostream &os) const override {
     return TypeSwitch<Attribute, AliasResult>(attr)
-        .Case<DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
-              DIDerivedTypeAttr, DIFileAttr, DILabelAttr, DILexicalBlockAttr,
+        .Case<AliasScopeAttr, AliasScopeDomainAttr, DIBasicTypeAttr,
+              DICompileUnitAttr, DICompositeTypeAttr, DIDerivedTypeAttr,
+              DIFileAttr, DILabelAttr, DILexicalBlockAttr,
               DILexicalBlockFileAttr, DILocalVariableAttr, DINamespaceAttr,
               DINullTypeAttr, DISubprogramAttr, DISubroutineTypeAttr,
               LoopAnnotationAttr, LoopVectorizeAttr, LoopInterleaveAttr,

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMInterfaces.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMInterfaces.cpp
index 4b5c1eace52c3e..6f70e4e4069295 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMInterfaces.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMInterfaces.cpp
@@ -100,12 +100,6 @@ LogicalResult mlir::LLVM::detail::verifyAccessGroupOpInterface(Operation *op) {
 LogicalResult
 mlir::LLVM::detail::verifyAliasAnalysisOpInterface(Operation *op) {
   auto iface = cast<AliasAnalysisOpInterface>(op);
-  if (failed(verifySymbolRefsPointTo<LLVM::AliasScopeMetadataOp>(
-          iface, "alias scopes", iface.getAliasScopesOrNull())))
-    return failure();
-  if (failed(verifySymbolRefsPointTo<LLVM::AliasScopeMetadataOp>(
-          iface, "noalias scopes", iface.getNoAliasScopesOrNull())))
-    return failure();
   if (failed(verifySymbolRefsPointTo<LLVM::TBAATagOp>(
           iface, "tbaa tags", iface.getTBAATagsOrNull())))
     return failure();

diff  --git a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
index 2a6093c12e753a..f59dd7616103dd 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
@@ -191,13 +191,12 @@ static LogicalResult setLoopAttr(const llvm::MDNode *node, Operation *op,
       .Default([](auto) { return failure(); });
 }
 
-/// Looks up all the symbol references pointing to the alias scope operations
-/// that map to the alias scope nodes starting from the alias scope metadata
-/// `node`, and attaches all of them to the imported operation if the lookups
-/// succeed. Returns failure otherwise.
+/// Looks up all the alias scope attributes that map to the alias scope nodes
+/// starting from the alias scope metadata `node`, and attaches all of them to
+/// the imported operation if the lookups succeed. Returns failure otherwise.
 static LogicalResult setAliasScopesAttr(const llvm::MDNode *node, Operation *op,
                                         LLVM::ModuleImport &moduleImport) {
-  FailureOr<SmallVector<SymbolRefAttr>> aliasScopes =
+  FailureOr<SmallVector<AliasScopeAttr>> aliasScopes =
       moduleImport.lookupAliasScopeAttrs(node);
   if (failed(aliasScopes))
     return failure();
@@ -207,8 +206,7 @@ static LogicalResult setAliasScopesAttr(const llvm::MDNode *node, Operation *op,
     return failure();
 
   iface.setAliasScopes(ArrayAttr::get(
-      iface.getContext(),
-      SmallVector<Attribute>{aliasScopes->begin(), aliasScopes->end()}));
+      iface.getContext(), llvm::to_vector_of<Attribute>(*aliasScopes)));
   return success();
 }
 
@@ -219,7 +217,7 @@ static LogicalResult setAliasScopesAttr(const llvm::MDNode *node, Operation *op,
 static LogicalResult setNoaliasScopesAttr(const llvm::MDNode *node,
                                           Operation *op,
                                           LLVM::ModuleImport &moduleImport) {
-  FailureOr<SmallVector<SymbolRefAttr>> noAliasScopes =
+  FailureOr<SmallVector<AliasScopeAttr>> noAliasScopes =
       moduleImport.lookupAliasScopeAttrs(node);
   if (failed(noAliasScopes))
     return failure();
@@ -229,8 +227,7 @@ static LogicalResult setNoaliasScopesAttr(const llvm::MDNode *node,
     return failure();
 
   iface.setNoAliasScopes(ArrayAttr::get(
-      iface.getContext(),
-      SmallVector<Attribute>{noAliasScopes->begin(), noAliasScopes->end()}));
+      iface.getContext(), llvm::to_vector_of<Attribute>(*noAliasScopes)));
   return success();
 }
 

diff  --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index e877ff29bfd400..e47af5acba0aaa 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -454,14 +454,14 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) {
     return idx >= node->getNumOperands() ||
            isa<llvm::MDString>(node->getOperand(idx));
   };
-  // Helper that creates an alias scope domain operation.
+  // Helper that creates an alias scope domain attribute.
   auto createAliasScopeDomainOp = [&](const llvm::MDNode *aliasDomain) {
     StringAttr description = nullptr;
     if (aliasDomain->getNumOperands() >= 2)
       if (auto *operand = dyn_cast<llvm::MDString>(aliasDomain->getOperand(1)))
         description = builder.getStringAttr(operand->getString());
-    std::string name = llvm::formatv("domain_{0}", aliasScopeMapping.size());
-    return builder.create<AliasScopeDomainMetadataOp>(loc, name, description);
+    return builder.getAttr<AliasScopeDomainAttr>(
+        DistinctAttr::create(builder.getUnitAttr()), description);
   };
 
   // Collect the alias scopes and domains to translate them.
@@ -484,49 +484,34 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) {
       if (aliasScopeMapping.contains(scope))
         continue;
 
-      // Set the insertion point to the end of the global metadata operation.
-      MetadataOp metadataOp = getGlobalMetadataOp();
-      StringAttr metadataOpName =
-          SymbolTable::getSymbolName(getGlobalMetadataOp());
-      OpBuilder::InsertionGuard guard(builder);
-      builder.setInsertionPointToEnd(&metadataOp.getBody().back());
-
       // Convert the domain metadata node if it has not been translated before.
       auto it = aliasScopeMapping.find(aliasScope.getDomain());
       if (it == aliasScopeMapping.end()) {
         auto aliasScopeDomainOp = createAliasScopeDomainOp(domain);
-        auto symbolRef = SymbolRefAttr::get(
-            builder.getContext(), metadataOpName,
-            FlatSymbolRefAttr::get(builder.getContext(),
-                                   aliasScopeDomainOp.getSymName()));
-        it = aliasScopeMapping.try_emplace(domain, symbolRef).first;
+        it = aliasScopeMapping.try_emplace(domain, aliasScopeDomainOp).first;
       }
 
       // Convert the scope metadata node if it has not been converted before.
       StringAttr description = nullptr;
       if (!aliasScope.getName().empty())
         description = builder.getStringAttr(aliasScope.getName());
-      std::string name = llvm::formatv("scope_{0}", aliasScopeMapping.size());
-      auto aliasScopeOp = builder.create<AliasScopeMetadataOp>(
-          loc, name, it->getSecond().getLeafReference().getValue(),
-          description);
-      auto symbolRef =
-          SymbolRefAttr::get(builder.getContext(), metadataOpName,
-                             FlatSymbolRefAttr::get(builder.getContext(),
-                                                    aliasScopeOp.getSymName()));
-      aliasScopeMapping.try_emplace(aliasScope.getNode(), symbolRef);
+      auto aliasScopeOp = builder.getAttr<AliasScopeAttr>(
+          DistinctAttr::create(builder.getUnitAttr()),
+          cast<AliasScopeDomainAttr>(it->second), description);
+      aliasScopeMapping.try_emplace(aliasScope.getNode(), aliasScopeOp);
     }
   }
   return success();
 }
 
-FailureOr<SmallVector<SymbolRefAttr>>
+FailureOr<SmallVector<AliasScopeAttr>>
 ModuleImport::lookupAliasScopeAttrs(const llvm::MDNode *node) const {
-  SmallVector<SymbolRefAttr> aliasScopes;
+  SmallVector<AliasScopeAttr> aliasScopes;
   aliasScopes.reserve(node->getNumOperands());
   for (const llvm::MDOperand &operand : node->operands()) {
     auto *node = cast<llvm::MDNode>(operand.get());
-    aliasScopes.push_back(aliasScopeMapping.lookup(node));
+    aliasScopes.push_back(
+        dyn_cast_or_null<AliasScopeAttr>(aliasScopeMapping.lookup(node)));
   }
   // Return failure if one of the alias scope lookups failed.
   if (llvm::is_contained(aliasScopes, nullptr))
@@ -1261,7 +1246,7 @@ DILabelAttr ModuleImport::matchLabelAttr(llvm::Value *value) {
   return debugImporter->translate(node);
 }
 
-FailureOr<SmallVector<SymbolRefAttr>>
+FailureOr<SmallVector<AliasScopeAttr>>
 ModuleImport::matchAliasScopeAttrs(llvm::Value *value) {
   auto *nodeAsVal = cast<llvm::MetadataAsValue>(value);
   auto *node = cast<llvm::MDNode>(nodeAsVal->getMetadata());

diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index d11c0826c589cf..7b18388a44627d 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -22,6 +22,7 @@
 #include "mlir/Dialect/LLVMIR/Transforms/LegalizeForExport.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
+#include "mlir/IR/AttrTypeSubElements.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/BuiltinTypes.h"
@@ -1093,60 +1094,56 @@ void ModuleTranslation::setAccessGroupsMetadata(AccessGroupOpInterface op,
 }
 
 LogicalResult ModuleTranslation::createAliasScopeMetadata() {
-  mlirModule->walk([&](LLVM::MetadataOp metadatas) {
-    // Create the domains first, so they can be reference below in the scopes.
-    DenseMap<Operation *, llvm::MDNode *> aliasScopeDomainMetadataMapping;
-    metadatas.walk([&](LLVM::AliasScopeDomainMetadataOp op) {
-      llvm::LLVMContext &ctx = llvmModule->getContext();
-      llvm::SmallVector<llvm::Metadata *, 2> operands;
-      operands.push_back({}); // Placeholder for self-reference
-      if (std::optional<StringRef> description = op.getDescription())
-        operands.push_back(llvm::MDString::get(ctx, *description));
-      llvm::MDNode *domain = llvm::MDNode::get(ctx, operands);
-      domain->replaceOperandWith(0, domain); // Self-reference for uniqueness
-      aliasScopeDomainMetadataMapping.insert({op, domain});
-    });
-
-    // Now create the scopes, referencing the domains created above.
-    metadatas.walk([&](LLVM::AliasScopeMetadataOp op) {
-      llvm::LLVMContext &ctx = llvmModule->getContext();
-      assert(isa<LLVM::MetadataOp>(op->getParentOp()));
-      auto metadataOp = dyn_cast<LLVM::MetadataOp>(op->getParentOp());
-      Operation *domainOp =
-          SymbolTable::lookupNearestSymbolFrom(metadataOp, op.getDomainAttr());
-      llvm::MDNode *domain = aliasScopeDomainMetadataMapping.lookup(domainOp);
-      assert(domain && "Scope's domain should already be valid");
-      llvm::SmallVector<llvm::Metadata *, 3> operands;
-      operands.push_back({}); // Placeholder for self-reference
-      operands.push_back(domain);
-      if (std::optional<StringRef> description = op.getDescription())
-        operands.push_back(llvm::MDString::get(ctx, *description));
-      llvm::MDNode *scope = llvm::MDNode::get(ctx, operands);
-      scope->replaceOperandWith(0, scope); // Self-reference for uniqueness
-      aliasScopeMetadataMapping.insert({op, scope});
-    });
+  DenseMap<Attribute, llvm::MDNode *> aliasScopeDomainMetadataMapping;
+
+  AttrTypeWalker walker;
+  walker.addWalk([&](LLVM::AliasScopeDomainAttr op) {
+    llvm::LLVMContext &ctx = llvmModule->getContext();
+    llvm::SmallVector<llvm::Metadata *, 2> operands;
+    operands.push_back({}); // Placeholder for self-reference
+    if (StringAttr description = op.getDescription())
+      operands.push_back(llvm::MDString::get(ctx, description));
+    llvm::MDNode *domain = llvm::MDNode::get(ctx, operands);
+    domain->replaceOperandWith(0, domain); // Self-reference for uniqueness
+    aliasScopeDomainMetadataMapping.insert({op, domain});
   });
+
+  walker.addWalk([&](LLVM::AliasScopeAttr op) {
+    llvm::LLVMContext &ctx = llvmModule->getContext();
+    llvm::MDNode *domain =
+        aliasScopeDomainMetadataMapping.lookup(op.getDomain());
+    assert(domain && "Scope's domain should already be valid");
+    llvm::SmallVector<llvm::Metadata *, 3> operands;
+    operands.push_back({}); // Placeholder for self-reference
+    operands.push_back(domain);
+    if (StringAttr description = op.getDescription())
+      operands.push_back(llvm::MDString::get(ctx, description));
+    llvm::MDNode *scope = llvm::MDNode::get(ctx, operands);
+    scope->replaceOperandWith(0, scope); // Self-reference for uniqueness
+    aliasScopeMetadataMapping.insert({op, scope});
+  });
+
+  mlirModule->walk([&](AliasAnalysisOpInterface op) {
+    if (auto aliasScopes = op.getAliasScopesOrNull())
+      walker.walk(aliasScopes);
+    if (auto noAliasScopes = op.getNoAliasScopesOrNull())
+      walker.walk(noAliasScopes);
+  });
+
   return success();
 }
 
 llvm::MDNode *
-ModuleTranslation::getAliasScope(Operation *op,
-                                 SymbolRefAttr aliasScopeRef) const {
-  StringAttr metadataName = aliasScopeRef.getRootReference();
-  StringAttr scopeName = aliasScopeRef.getLeafReference();
-  auto metadataOp = SymbolTable::lookupNearestSymbolFrom<LLVM::MetadataOp>(
-      op->getParentOp(), metadataName);
-  Operation *aliasScopeOp =
-      SymbolTable::lookupNearestSymbolFrom(metadataOp, scopeName);
-  return aliasScopeMetadataMapping.lookup(aliasScopeOp);
+ModuleTranslation::getAliasScope(AliasScopeAttr aliasScopeAttr) const {
+  return aliasScopeMetadataMapping.lookup(aliasScopeAttr);
 }
 
 llvm::MDNode *ModuleTranslation::getAliasScopes(
-    Operation *op, ArrayRef<SymbolRefAttr> aliasScopeRefs) const {
+    ArrayRef<AliasScopeAttr> aliasScopeAttrs) const {
   SmallVector<llvm::Metadata *> nodes;
-  nodes.reserve(aliasScopeRefs.size());
-  for (SymbolRefAttr aliasScopeRef : aliasScopeRefs)
-    nodes.push_back(getAliasScope(op, aliasScopeRef));
+  nodes.reserve(aliasScopeAttrs.size());
+  for (AliasScopeAttr aliasScopeRef : aliasScopeAttrs)
+    nodes.push_back(getAliasScope(aliasScopeRef));
   return llvm::MDNode::get(getLLVMContext(), nodes);
 }
 
@@ -1156,7 +1153,7 @@ void ModuleTranslation::setAliasScopeMetadata(AliasAnalysisOpInterface op,
     if (!aliasScopeRefs || aliasScopeRefs.empty())
       return;
     llvm::MDNode *node = getAliasScopes(
-        op, llvm::to_vector(aliasScopeRefs.getAsRange<SymbolRefAttr>()));
+        llvm::to_vector(aliasScopeRefs.getAsRange<AliasScopeAttr>()));
     inst->setMetadata(kind, node);
   };
 

diff  --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 65b1d2fa2511dc..d1c6849c6ce3e5 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -982,8 +982,7 @@ module {
       llvm.return
   }
   llvm.metadata @metadata {
-    llvm.alias_scope_domain @domain
-    llvm.alias_scope @scope { domain = @domain }
+    llvm.func @scope()
   }
 }
 
@@ -991,7 +990,7 @@ module {
 
 module {
   llvm.func @aliasScope(%arg0 : !llvm.ptr, %arg1 : i32, %arg2 : i32) {
-      // expected-error at below {{attribute 'alias_scopes' failed to satisfy constraint: symbol ref array attribute}}
+      // expected-error at below {{attribute 'alias_scopes' failed to satisfy constraint: LLVM dialect alias scope array}}
       %0 = llvm.cmpxchg %arg0, %arg1, %arg2 acq_rel monotonic { "alias_scopes" = "test" } : !llvm.ptr, i32
       llvm.return
   }
@@ -1001,7 +1000,7 @@ module {
 
 module {
   llvm.func @noAliasScopes(%arg0 : !llvm.ptr) {
-      // expected-error at below {{attribute 'noalias_scopes' failed to satisfy constraint: symbol ref array attribute}}
+      // expected-error at below {{attribute 'noalias_scopes' failed to satisfy constraint: LLVM dialect alias scope array}}
       %0 = llvm.load %arg0 { "noalias_scopes" = "test" } : !llvm.ptr -> i32
       llvm.return
   }
@@ -1009,54 +1008,6 @@ module {
 
 // -----
 
-module {
-  llvm.func @aliasScope(%arg0 : i32, %arg1 : !llvm.ptr) {
-      // expected-error at below {{expected '@metadata::@group' to resolve to a llvm.alias_scope}}
-      llvm.store %arg0, %arg1 { "alias_scopes" = [@metadata::@group] } : i32, !llvm.ptr
-      llvm.return
-  }
-  llvm.metadata @metadata {
-    llvm.access_group @group
-  }
-}
-
-// -----
-
-module {
-  llvm.func @aliasScope(%arg0 : !llvm.ptr, %arg1 : f32) {
-      // expected-error at below {{expected '@metadata::@group' to resolve to a llvm.alias_scope}}
-      %0 = llvm.atomicrmw fadd %arg0, %arg1 monotonic { "noalias_scopes" = [@metadata::@group] } : !llvm.ptr, f32
-      llvm.return
-  }
-  llvm.metadata @metadata {
-    llvm.access_group @group
-  }
-}
-
-// -----
-
-module {
-  llvm.metadata @metadata {
-    llvm.access_group @group
-    // expected-error at below {{expected 'group' to reference a domain operation in the same region}}
-    llvm.alias_scope @scope { domain = @group }
-  }
-}
-
-// -----
-
-module {
-  llvm.metadata @metadata {
-    // expected-error at below {{expected 'domain' to reference a domain operation in the same region}}
-    llvm.alias_scope @scope { domain = @domain }
-  }
-  llvm.metadata @other_metadata {
-    llvm.alias_scope_domain @domain
-  }
-}
-
-// -----
-
 llvm.func @wmmaLoadOp_invalid_mem_space(%arg0: !llvm.ptr<5>, %arg1: i32) {
   // expected-error at +1 {{'nvvm.wmma.load' op expected source pointer in memory space 0, 1, 3}}
   %0 = nvvm.wmma.load %arg0, %arg1

diff  --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
index 6f220fda5d78b5..ecf73a29bed29e 100644
--- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir
+++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
@@ -566,14 +566,12 @@ llvm.func @stackrestore(%arg0: !llvm.ptr)  {
   llvm.return
 }
 
+#alias_scope_domain = #llvm.alias_scope_domain<id = distinct[0]<>, description = "The domain">
+#alias_scope = #llvm.alias_scope<id = distinct[0]<>, domain = #alias_scope_domain, description = "The domain">
+
 // CHECK-LABEL: @experimental_noalias_scope_decl
 llvm.func @experimental_noalias_scope_decl() {
-  // CHECK: llvm.intr.experimental.noalias.scope.decl @metadata::@scope
-  llvm.intr.experimental.noalias.scope.decl @metadata::@scope
+  // CHECK: llvm.intr.experimental.noalias.scope.decl #{{.*}}
+  llvm.intr.experimental.noalias.scope.decl #alias_scope
   llvm.return
 }
-
-llvm.metadata @metadata {
-  llvm.alias_scope_domain @domain {description = "The domain"}
-  llvm.alias_scope @scope {domain = @domain, description = "The first scope"}
-}

diff  --git a/mlir/test/Target/LLVMIR/Import/metadata-alias-scopes.ll b/mlir/test/Target/LLVMIR/Import/metadata-alias-scopes.ll
index 19abc95a4a268f..f5128ff76bc5ff 100644
--- a/mlir/test/Target/LLVMIR/Import/metadata-alias-scopes.ll
+++ b/mlir/test/Target/LLVMIR/Import/metadata-alias-scopes.ll
@@ -1,25 +1,23 @@
 ; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
 
-; CHECK: llvm.metadata @__llvm_global_metadata {
-; CHECK:   llvm.alias_scope_domain @[[DOMAIN:.*]] {description = "The domain"}
-; CHECK:   llvm.alias_scope @[[$SCOPE0:.*]] {description = "The first scope", domain = @[[DOMAIN]]}
-; CHECK:   llvm.alias_scope @[[$SCOPE1:.*]] {domain = @[[DOMAIN]]}
-; CHECK:   llvm.alias_scope @[[$SCOPE2:.*]] {domain = @[[DOMAIN]]}
-; CHECK: }
+; CHECK: #[[DOMAIN:.*]] = #llvm.alias_scope_domain<id = {{.*}}, description = "The domain">
+; CHECK: #[[$SCOPE0:.*]] = #llvm.alias_scope<id = {{.*}}, domain = #[[DOMAIN]], description = "The first scope">
+; CHECK: #[[$SCOPE1:.*]] = #llvm.alias_scope<id = {{.*}}, domain = #[[DOMAIN]]>
+; CHECK: #[[$SCOPE2:.*]] = #llvm.alias_scope<id = {{.*}}, domain = #[[DOMAIN]]>
 
 ; CHECK-LABEL: llvm.func @alias_scope
 define void @alias_scope(ptr %arg1) {
   ; CHECK: llvm.load
-  ; CHECK-SAME:  alias_scopes = [@__llvm_global_metadata::@[[$SCOPE0]]]
-  ; CHECK-SAME:  noalias_scopes = [@__llvm_global_metadata::@[[$SCOPE1]], @__llvm_global_metadata::@[[$SCOPE2]]]
+  ; CHECK-SAME:  alias_scopes = [#[[$SCOPE0]]]
+  ; CHECK-SAME:  noalias_scopes = [#[[$SCOPE1]], #[[$SCOPE2]]]
   %1 = load i32, ptr %arg1, !alias.scope !4, !noalias !7
   ; CHECK: llvm.load
-  ; CHECK-SAME:  alias_scopes = [@__llvm_global_metadata::@[[$SCOPE1]]]
-  ; CHECK-SAME:  noalias_scopes = [@__llvm_global_metadata::@[[$SCOPE0]], @__llvm_global_metadata::@[[$SCOPE2]]]
+  ; CHECK-SAME:  alias_scopes = [#[[$SCOPE1]]]
+  ; CHECK-SAME:  noalias_scopes = [#[[$SCOPE0]], #[[$SCOPE2]]]
   %2 = load i32, ptr %arg1, !alias.scope !5, !noalias !8
   ; CHECK: llvm.load
-  ; CHECK-SAME:  alias_scopes = [@__llvm_global_metadata::@[[$SCOPE2]]]
-  ; CHECK-SAME:  noalias_scopes = [@__llvm_global_metadata::@[[$SCOPE0]], @__llvm_global_metadata::@[[$SCOPE1]]]
+  ; CHECK-SAME:  alias_scopes = [#[[$SCOPE2]]]
+  ; CHECK-SAME:  noalias_scopes = [#[[$SCOPE0]], #[[$SCOPE1]]]
   %3 = load i32, ptr %arg1, !alias.scope !6, !noalias !9
   ret void
 }
@@ -37,18 +35,16 @@ define void @alias_scope(ptr %arg1) {
 
 ; // -----
 
-; CHECK: llvm.metadata @__llvm_global_metadata {
-; CHECK:   llvm.alias_scope_domain @[[DOMAIN0:.*]] {description = "The domain"}
-; CHECK:   llvm.alias_scope @[[$SCOPE0:.*]] {domain = @[[DOMAIN0]]}
-; CHECK:   llvm.alias_scope_domain @[[DOMAIN1:.*]]
-; CHECK:   llvm.alias_scope @[[$SCOPE1:.*]] {domain = @[[DOMAIN1]]}
-; CHECK: }
+; CHECK: #[[DOMAIN0:.*]] = #llvm.alias_scope_domain<id = {{.*}}, description = "The domain">
+; CHECK: #[[DOMAIN1:.*]] = #llvm.alias_scope_domain<id = {{.*}}>
+; CHECK: #[[$SCOPE0:.*]] = #llvm.alias_scope<id = {{.*}}, domain = #[[DOMAIN0]]>
+; CHECK: #[[$SCOPE1:.*]] = #llvm.alias_scope<id = {{.*}}, domain = #[[DOMAIN1]]>
 
 ; CHECK-LABEL: llvm.func @two_domains
 define void @two_domains(ptr %arg1) {
   ; CHECK: llvm.load
-  ; CHECK-SAME:  alias_scopes = [@__llvm_global_metadata::@[[$SCOPE0]]]
-  ; CHECK-SAME:  noalias_scopes = [@__llvm_global_metadata::@[[$SCOPE1]]]
+  ; CHECK-SAME:  alias_scopes = [#[[$SCOPE0]]]
+  ; CHECK-SAME:  noalias_scopes = [#[[$SCOPE1]]]
   %1 = load i32, ptr %arg1, !alias.scope !4, !noalias !5
   ret void
 }
@@ -62,30 +58,28 @@ define void @two_domains(ptr %arg1) {
 
 ; // -----
 
-; CHECK: llvm.metadata @__llvm_global_metadata {
-; CHECK:   llvm.alias_scope_domain @[[DOMAIN:.*]] {description = "The domain"}
-; CHECK:   llvm.alias_scope @[[$SCOPE:.*]] {domain = @[[DOMAIN]]}
-; CHECK: }
+; CHECK: #[[DOMAIN:.*]] = #llvm.alias_scope_domain<id = {{.*}}, description = "The domain">
+; CHECK: #[[$SCOPE:.*]] = #llvm.alias_scope<id = {{.*}}, domain = #[[DOMAIN]]>
 
 ; CHECK-LABEL: llvm.func @supported_ops
 define void @supported_ops(ptr %arg1, float %arg2, i32 %arg3, i32 %arg4) {
-  ; CHECK: llvm.intr.experimental.noalias.scope.decl @__llvm_global_metadata::@[[$SCOPE]]
+  ; CHECK: llvm.intr.experimental.noalias.scope.decl #[[$SCOPE]]
   call void @llvm.experimental.noalias.scope.decl(metadata !2)
-  ; CHECK: llvm.load {{.*}}alias_scopes = [@__llvm_global_metadata::@[[$SCOPE]]]
+  ; CHECK: llvm.load {{.*}}alias_scopes = [#[[$SCOPE]]]
   %1 = load i32, ptr %arg1, !alias.scope !2
-  ; CHECK: llvm.store {{.*}}alias_scopes = [@__llvm_global_metadata::@[[$SCOPE]]]
+  ; CHECK: llvm.store {{.*}}alias_scopes = [#[[$SCOPE]]]
   store i32 %1, ptr %arg1, !alias.scope !2
-  ; CHECK: llvm.atomicrmw {{.*}}alias_scopes = [@__llvm_global_metadata::@[[$SCOPE]]]
+  ; CHECK: llvm.atomicrmw {{.*}}alias_scopes = [#[[$SCOPE]]]
   %2 = atomicrmw fmax ptr %arg1, float %arg2 acquire, !alias.scope !2
-  ; CHECK: llvm.cmpxchg {{.*}}alias_scopes = [@__llvm_global_metadata::@[[$SCOPE]]]
+  ; CHECK: llvm.cmpxchg {{.*}}alias_scopes = [#[[$SCOPE]]]
   %3 = cmpxchg ptr %arg1, i32 %arg3, i32 %arg4 monotonic seq_cst, !alias.scope !2
-  ; CHECK: "llvm.intr.memcpy"{{.*}}alias_scopes = [@__llvm_global_metadata::@[[$SCOPE]]]
+  ; CHECK: "llvm.intr.memcpy"{{.*}}alias_scopes = [#[[$SCOPE]]]
   call void @llvm.memcpy.p0.p0.i32(ptr %arg1, ptr %arg1, i32 4, i1 false), !alias.scope !2
-  ; CHECK: "llvm.intr.memset"{{.*}}alias_scopes = [@__llvm_global_metadata::@[[$SCOPE]]]
+  ; CHECK: "llvm.intr.memset"{{.*}}alias_scopes = [#[[$SCOPE]]]
   call void @llvm.memset.p0.i32(ptr %arg1, i8 42, i32 4, i1 false), !alias.scope !2
-  ; CHECK: llvm.call{{.*}}alias_scopes = [@__llvm_global_metadata::@[[$SCOPE]]]
+  ; CHECK: llvm.call{{.*}}alias_scopes = [#[[$SCOPE]]]
   call void @foo(ptr %arg1), !alias.scope !2
-  ; CHECK: llvm.call{{.*}}noalias_scopes = [@__llvm_global_metadata::@[[$SCOPE]]]
+  ; CHECK: llvm.call{{.*}}noalias_scopes = [#[[$SCOPE]]]
   call void @foo(ptr %arg1), !noalias !2
   ret void
 }

diff  --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index f37ed750412a3a..2500de25f49891 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -2080,38 +2080,36 @@ llvm.func @switch_weights(%arg0: i32) -> i32 {
 
 llvm.func @foo(%arg0: !llvm.ptr)
 
+#alias_scope_domain = #llvm.alias_scope_domain<id = distinct[0]<>, description = "The domain">
+#alias_scope1 = #llvm.alias_scope<id = distinct[1]<>, domain = #alias_scope_domain, description = "The first scope">
+#alias_scope2 = #llvm.alias_scope<id = distinct[2]<>, domain = #alias_scope_domain>
+#alias_scope3 = #llvm.alias_scope<id = distinct[3]<>, domain = #alias_scope_domain>
+
 // CHECK-LABEL: aliasScope
 llvm.func @aliasScope(%arg1 : !llvm.ptr) {
   %0 = llvm.mlir.constant(0 : i32) : i32
   // CHECK:  call void @llvm.experimental.noalias.scope.decl(metadata ![[SCOPES1:[0-9]+]])
-  llvm.intr.experimental.noalias.scope.decl @metadata::@scope1
+  llvm.intr.experimental.noalias.scope.decl #alias_scope1
   // CHECK:  store {{.*}}, !alias.scope ![[SCOPES1]], !noalias ![[SCOPES23:[0-9]+]]
-  llvm.store %0, %arg1 {alias_scopes = [@metadata::@scope1], noalias_scopes = [@metadata::@scope2, @metadata::@scope3]} : i32, !llvm.ptr
+  llvm.store %0, %arg1 {alias_scopes = [#alias_scope1], noalias_scopes = [#alias_scope2, #alias_scope3]} : i32, !llvm.ptr
   // CHECK:  load {{.*}}, !alias.scope ![[SCOPES2:[0-9]+]], !noalias ![[SCOPES13:[0-9]+]]
-  %1 = llvm.load %arg1 {alias_scopes = [@metadata::@scope2], noalias_scopes = [@metadata::@scope1, @metadata::@scope3]} : !llvm.ptr -> i32
+  %1 = llvm.load %arg1 {alias_scopes = [#alias_scope2], noalias_scopes = [#alias_scope1, #alias_scope3]} : !llvm.ptr -> i32
   // CHECK:  atomicrmw {{.*}}, !alias.scope ![[SCOPES3:[0-9]+]], !noalias ![[SCOPES12:[0-9]+]]
-  %2 = llvm.atomicrmw add %arg1, %0 monotonic {alias_scopes = [@metadata::@scope3], noalias_scopes = [@metadata::@scope1, @metadata::@scope2]} : !llvm.ptr, i32
+  %2 = llvm.atomicrmw add %arg1, %0 monotonic {alias_scopes = [#alias_scope3], noalias_scopes = [#alias_scope1, #alias_scope2]} : !llvm.ptr, i32
   // CHECK:  cmpxchg {{.*}}, !alias.scope ![[SCOPES3]]
-  %3 = llvm.cmpxchg %arg1, %1, %2 acq_rel monotonic {alias_scopes = [@metadata::@scope3]} : !llvm.ptr, i32
+  %3 = llvm.cmpxchg %arg1, %1, %2 acq_rel monotonic {alias_scopes = [#alias_scope3]} : !llvm.ptr, i32
   %5 = llvm.mlir.constant(42 : i8) : i8
   // CHECK:  llvm.memcpy{{.*}}, !alias.scope ![[SCOPES3]]
-  "llvm.intr.memcpy"(%arg1, %arg1, %0) <{isVolatile = false}> {alias_scopes = [@metadata::@scope3]} : (!llvm.ptr, !llvm.ptr, i32) -> ()
+  "llvm.intr.memcpy"(%arg1, %arg1, %0) <{isVolatile = false}> {alias_scopes = [#alias_scope3]} : (!llvm.ptr, !llvm.ptr, i32) -> ()
   // CHECK:  llvm.memset{{.*}}, !noalias ![[SCOPES3]]
-  "llvm.intr.memset"(%arg1, %5, %0) <{isVolatile = false}> {noalias_scopes = [@metadata::@scope3]} : (!llvm.ptr, i8, i32) -> ()
+  "llvm.intr.memset"(%arg1, %5, %0) <{isVolatile = false}> {noalias_scopes = [#alias_scope3]} : (!llvm.ptr, i8, i32) -> ()
   // CHECK: call void @foo({{.*}} !alias.scope ![[SCOPES3]]
-  llvm.call @foo(%arg1) {alias_scopes = [@metadata::@scope3]} : (!llvm.ptr) -> ()
+  llvm.call @foo(%arg1) {alias_scopes = [#alias_scope3]} : (!llvm.ptr) -> ()
   // CHECK: call void @foo({{.*}} !noalias ![[SCOPES3]]
-  llvm.call @foo(%arg1) {noalias_scopes = [@metadata::@scope3]} : (!llvm.ptr) -> ()
+  llvm.call @foo(%arg1) {noalias_scopes = [#alias_scope3]} : (!llvm.ptr) -> ()
   llvm.return
 }
 
-llvm.metadata @metadata {
-  llvm.alias_scope_domain @domain {description = "The domain"}
-  llvm.alias_scope @scope1 {domain = @domain, description = "The first scope"}
-  llvm.alias_scope @scope2 {domain = @domain}
-  llvm.alias_scope @scope3 {domain = @domain}
-}
-
 // Check the intrinsic declarations.
 // CHECK-DAG: declare void @llvm.experimental.noalias.scope.decl(metadata)
 // CHECK-DAG: declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg)

diff  --git a/mlir/test/mlir-tblgen/llvm-intrinsics.td b/mlir/test/mlir-tblgen/llvm-intrinsics.td
index 1025ed908b1294..2594674564df16 100644
--- a/mlir/test/mlir-tblgen/llvm-intrinsics.td
+++ b/mlir/test/mlir-tblgen/llvm-intrinsics.td
@@ -72,8 +72,8 @@
 // It implements the alias analysis interface.
 // ALIAS: 1>
 // It has alias scopes, noalias, and tbaa.
-// ALIAS: OptionalAttr<SymbolRefArrayAttr>:$alias_scopes
-// ALIAS: OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes
+// ALIAS: OptionalAttr<LLVM_AliasScopeArrayAttr>:$alias_scopes
+// ALIAS: OptionalAttr<LLVM_AliasScopeArrayAttr>:$noalias_scopes
 // ALIAS: OptionalAttr<SymbolRefArrayAttr>:$tbaa
 
 //---------------------------------------------------------------------------//

diff  --git a/mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp b/mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp
index 4fa037aafde783..fef08cd8f3d114 100644
--- a/mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp
+++ b/mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp
@@ -219,8 +219,9 @@ static bool emitIntrinsic(const llvm::Record &record, llvm::raw_ostream &os) {
   if (requiresAccessGroup)
     operands.push_back("OptionalAttr<SymbolRefArrayAttr>:$access_groups");
   if (requiresAliasAnalysis) {
-    operands.push_back("OptionalAttr<SymbolRefArrayAttr>:$alias_scopes");
-    operands.push_back("OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes");
+    operands.push_back("OptionalAttr<LLVM_AliasScopeArrayAttr>:$alias_scopes");
+    operands.push_back(
+        "OptionalAttr<LLVM_AliasScopeArrayAttr>:$noalias_scopes");
     operands.push_back("OptionalAttr<SymbolRefArrayAttr>:$tbaa");
   }
 


        


More information about the Mlir-commits mailing list