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
// -----
-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 = [{
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
//===----------------------------------------------------------------------===//
-// RUN: mlir-opt %s | FileCheck %s
+// RUN: mlir-opt %s -split-input-file | FileCheck %s
func @const() -> () {
// CHECK: %true
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
+ }
+}
+