[Mlir-commits] [mlir] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Dec 15 13:50:42 PST 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 62b21c6ced918c7fec97b557e3087e3ffdf71494 fd8c637f2b146ffce657307841f84a4123e351af -- mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 66f1d6b2e1..5343a12132 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -1162,8 +1162,8 @@ LogicalResult spirv::GlobalVariableOp::verify() {
// TODO: Currently only variable initialization with specialization
// constants and other variables is supported. They could be normal
// constants in the module scope as well.
- if (!initOp ||
- !isa<spirv::GlobalVariableOp, spirv::SpecConstantOp, spirv::SpecConstantCompositeOp>(initOp)) {
+ if (!initOp || !isa<spirv::GlobalVariableOp, spirv::SpecConstantOp,
+ spirv::SpecConstantCompositeOp>(initOp)) {
return emitOpError("initializer must be result of a "
"spirv.SpecConstant or spirv.GlobalVariable or "
"spirv.SpecConstantCompositeOp op");
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index ccea690a7c..0e1e294b02 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -637,19 +637,21 @@ spirv::Deserializer::processGlobalVariable(ArrayRef<uint32_t> operands) {
// Initializer.
FlatSymbolRefAttr initializer = nullptr;
-
+
if (wordIndex < operands.size()) {
Operation *op = nullptr;
- if((op = getGlobalVariable(operands[wordIndex])))
- initializer = SymbolRefAttr::get((dyn_cast<spirv::GlobalVariableOp>(op)).getOperation());
- else if ((op = getSpecConstant(operands[wordIndex])))
- initializer = SymbolRefAttr::get((dyn_cast<spirv::SpecConstantOp>(op)).getOperation());
- else if((op = getSpecConstantComposite(operands[wordIndex])))
- initializer = SymbolRefAttr::get((dyn_cast<spirv::SpecConstantCompositeOp>(op)).getOperation());
+ if ((op = getGlobalVariable(operands[wordIndex])))
+ initializer = SymbolRefAttr::get(
+ (dyn_cast<spirv::GlobalVariableOp>(op)).getOperation());
+ else if ((op = getSpecConstant(operands[wordIndex])))
+ initializer = SymbolRefAttr::get(
+ (dyn_cast<spirv::SpecConstantOp>(op)).getOperation());
+ else if ((op = getSpecConstantComposite(operands[wordIndex])))
+ initializer = SymbolRefAttr::get(
+ (dyn_cast<spirv::SpecConstantCompositeOp>(op)).getOperation());
else
- return emitError(unknownLoc,
- "Unknown op used as initializer");
+ return emitError(unknownLoc, "Unknown op used as initializer");
wordIndex++;
}
diff --git a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
index bd1fc7a84f..cbede7d8a3 100644
--- a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
+++ b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
@@ -387,18 +387,20 @@ Serializer::processGlobalVariableOp(spirv::GlobalVariableOp varOp) {
uint32_t initializerID = 0;
auto init = varOp->getAttrOfType<FlatSymbolRefAttr>("initializer");
- Operation *initOp = SymbolTable::lookupNearestSymbolFrom(varOp->getParentOp(), init.getAttr());
+ Operation *initOp = SymbolTable::lookupNearestSymbolFrom(
+ varOp->getParentOp(), init.getAttr());
- // Check if initializer is GlobalVariable or SpecConstant/SpecConstantComposite
- if(isa<spirv::GlobalVariableOp>(initOp))
+ // Check if initializer is GlobalVariable or
+ // SpecConstant/SpecConstantComposite
+ if (isa<spirv::GlobalVariableOp>(initOp))
initializerID = getVariableID(*initializerName);
else
initializerID = getSpecConstID(*initializerName);
if (!initializerID)
- return emitError(varOp.getLoc(),
- "invalid usage of undefined variable as initializer");
-
+ return emitError(varOp.getLoc(),
+ "invalid usage of undefined variable as initializer");
+
operands.push_back(initializerID);
elidedAttrs.push_back("initializer");
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/75660
More information about the Mlir-commits
mailing list