[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 c185cf099058de712574f09ab813be5163b2fbca..95daa9887de0158ee7c38d086d830ab4556a0a3b 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 782d7dd92b75ef2a9badc07e962d9dce77515e7a..374fdadf4b783d2026f276ac22ae357d30dc5121 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 a53f061ce82bdc8c855ed52486f8e8e2cc733f78..ebcf9f1c6decacd18556e87494a7a937ece85217 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
+  }
+}
+