[PATCH] D75869: [mlir][spirv] Use larger range for target environment lookup function

Lei Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 14:03:41 PDT 2020


antiagainst created this revision.
antiagainst added a reviewer: denis13.
Herald added subscribers: llvm-commits, bader, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, nicolasvasilache, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a reviewer: mravishankar.
Herald added a project: LLVM.
antiagainst added a child revision: D75870: [mlir][spirv] Add a pass to deduce version/extension/capability.

Previously we only look at the directly passed-in op for a potential
spv.target_env attribute. This commit switches to use a larger range
and recursively check enclosing symbol tables.

Depends On D75868 <https://reviews.llvm.org/D75868>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75869

Files:
  mlir/docs/Dialects/SPIR-V.md
  mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
  mlir/lib/Dialect/SPIRV/TargetAndABI.cpp


Index: mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
===================================================================
--- mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
+++ mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
@@ -11,6 +11,7 @@
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/FunctionSupport.h"
 #include "mlir/IR/Operation.h"
+#include "mlir/IR/SymbolTable.h"
 
 using namespace mlir;
 
@@ -294,8 +295,15 @@
 }
 
 spirv::TargetEnvAttr spirv::lookupTargetEnvOrDefault(Operation *op) {
-  if (auto attr = op->getAttrOfType<spirv::TargetEnvAttr>(
-          spirv::getTargetEnvAttrName()))
-    return attr;
+  for (Operation *symTable = op; symTable; symTable = symTable->getParentOp()) {
+    symTable = SymbolTable::getNearestSymbolTable(symTable);
+    if (!symTable)
+      break;
+
+    if (auto attr = symTable->getAttrOfType<spirv::TargetEnvAttr>(
+            spirv::getTargetEnvAttrName()))
+      return attr;
+  }
+
   return getDefaultTargetEnv(op->getContext());
 }
Index: mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
===================================================================
--- mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
+++ mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
@@ -174,9 +174,9 @@
 /// and no extra extensions.
 TargetEnvAttr getDefaultTargetEnv(MLIRContext *context);
 
-/// Queries the target environment from the given `op` or returns the default
-/// target environment (SPIR-V 1.0 with Shader capability and no extra
-/// extensions) if not provided.
+/// Queries the target environment recursively from enclosing symbol table ops
+/// containing the given `op` or returns the default target environment as
+/// returned by getDefaultTargetEnv() if not provided.
 TargetEnvAttr lookupTargetEnvOrDefault(Operation *op);
 
 } // namespace spirv
Index: mlir/docs/Dialects/SPIR-V.md
===================================================================
--- mlir/docs/Dialects/SPIR-V.md
+++ mlir/docs/Dialects/SPIR-V.md
@@ -792,9 +792,11 @@
 } { ... }
 ```
 
-Dialect conversion framework will utilize the information in `spv.target_env`
-to properly filter out patterns and ops not available in the target execution
-environment.
+Dialect conversion framework will utilize the information in `spv.target_env` to
+properly filter out patterns and ops not available in the target execution
+environment. When targeting SPIR-V, one needs to create a
+[`SPIRVConversionTarget`](#spirvconversiontarget) by providing such an
+attribute.
 
 ## Shader interface (ABI)
 
@@ -931,6 +933,10 @@
 proper hooks to check the dynamic legality of SPIR-V ops. Users can further
 register other legality constraints into the returned `SPIRVConversionTarget`.
 
+`spirv::lookupTargetEnvOrDefault()` is a hany utility function to query an
+`spv.target_env` attached in the input IR or use the feault to construct a
+`SPIRVConversionTarget`.
+
 ### `SPIRVTypeConverter`
 
 The `mlir::SPIRVTypeConverter` derives from `mlir::TypeConverter` and provides


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75869.249209.patch
Type: text/x-patch
Size: 2965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200309/5ffe9884/attachment-0001.bin>


More information about the llvm-commits mailing list