[MLIR][SPIRV] Use getAsmResultName(...) hook for AddressOfOp.
authorKareemErgawy <kareem.ergawy@tomtom.com>
Mon, 7 Jun 2021 11:19:39 +0000 (13:19 +0200)
committerKareemErgawy <kareem.ergawy@tomtom.com>
Mon, 7 Jun 2021 11:58:26 +0000 (13:58 +0200)
Implements better naming for results of spv.mlir.addressof ops by making it
inherit from OpAsmOpInterface and implementing the associated
getAsmResultName(...) hook.

Reviewed By: antiagainst

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

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
mlir/test/Dialect/SPIRV/IR/asm-op-interface.mlir

index c185cf0..95daa98 100644 (file)
@@ -23,7 +23,8 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
 
 // -----
 
-def SPV_AddressOfOp : SPV_Op<"mlir.addressof", [InFunctionScope, NoSideEffect]> {
+def SPV_AddressOfOp : SPV_Op<"mlir.addressof",
+    [DeclareOpInterfaceMethods<OpAsmOpInterface>, InFunctionScope, NoSideEffect]> {
   let summary = "Get the address of a global variable.";
 
   let description = [{
index 782d7dd..374fdad 100644 (file)
@@ -1690,6 +1690,14 @@ void mlir::spirv::ConstantOp::getAsmResultNames(
   setNameFn(getResult(), specialName.str());
 }
 
+void mlir::spirv::AddressOfOp::getAsmResultNames(
+    llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
+  SmallString<32> specialNameBuffer;
+  llvm::raw_svector_ostream specialName(specialNameBuffer);
+  specialName << variable() << "_addr";
+  setNameFn(getResult(), specialName.str());
+}
+
 //===----------------------------------------------------------------------===//
 // spv.EntryPoint
 //===----------------------------------------------------------------------===//
index a53f061..ebcf9f1 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s | FileCheck %s
+// RUN: mlir-opt %s -split-input-file | FileCheck %s
 
 func @const() -> () {
   // CHECK: %true
@@ -26,3 +26,16 @@ func @const() -> () {
 
   return
 }
+
+// -----
+
+spv.module Logical GLSL450 {
+  spv.GlobalVariable @global_var : !spv.ptr<f32, Input>
+
+  spv.func @addressof() -> () "None" {
+    // CHECK: %global_var_addr = spv.mlir.addressof 
+    %0 = spv.mlir.addressof @global_var : !spv.ptr<f32, Input>
+    spv.Return
+  }
+}
+