[Mlir-commits] [mlir] 41bc54c - [mlir][spirv] NFC: Replace OwningSPIRVModuleRef with OwningOpRef
Lei Zhang
llvmlistbot at llvm.org
Thu May 6 14:20:13 PDT 2021
Author: Lei Zhang
Date: 2021-05-06T17:17:44-04:00
New Revision: 41bc54cc56fd9e9cdaaeb9ca630f0c690e1a28e4
URL: https://github.com/llvm/llvm-project/commit/41bc54cc56fd9e9cdaaeb9ca630f0c690e1a28e4
DIFF: https://github.com/llvm/llvm-project/commit/41bc54cc56fd9e9cdaaeb9ca630f0c690e1a28e4.diff
LOG: [mlir][spirv] NFC: Replace OwningSPIRVModuleRef with OwningOpRef
Reviewed By: rriddle
Differential Revision: https://reviews.llvm.org/D102009
Added:
Modified:
mlir/include/mlir/Dialect/SPIRV/Linking/ModuleCombiner.h
mlir/include/mlir/Target/SPIRV/Deserialization.h
mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
mlir/lib/Target/SPIRV/Deserialization/Deserialization.cpp
mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
mlir/lib/Target/SPIRV/TranslateRegistration.cpp
mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp
mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp
mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp
mlir/unittests/Dialect/SPIRV/SerializationTest.cpp
Removed:
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVModule.h
################################################################################
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVModule.h b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVModule.h
deleted file mode 100644
index f64a5029bbf2..000000000000
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVModule.h
+++ /dev/null
@@ -1,30 +0,0 @@
-//===- SPIRVModule.h - SPIR-V Module Utilities ------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_DIALECT_SPIRV_IR_SPIRVMODULE_H
-#define MLIR_DIALECT_SPIRV_IR_SPIRVMODULE_H
-
-#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
-#include "mlir/IR/OwningOpRef.h"
-
-namespace mlir {
-namespace spirv {
-
-/// This class acts as an owning reference to a SPIR-V module, and will
-/// automatically destroy the held module on destruction if the held module
-/// is valid.
-// TODO: Remove this class in favor of using OwningOpRef directly.
-class OwningSPIRVModuleRef : public OwningOpRef<spirv::ModuleOp> {
-public:
- using OwningOpRef<spirv::ModuleOp>::OwningOpRef;
-};
-
-} // end namespace spirv
-} // end namespace mlir
-
-#endif // MLIR_DIALECT_SPIRV_IR_SPIRVMODULE_H
diff --git a/mlir/include/mlir/Dialect/SPIRV/Linking/ModuleCombiner.h b/mlir/include/mlir/Dialect/SPIRV/Linking/ModuleCombiner.h
index 692c905454b3..c2eaef037d10 100644
--- a/mlir/include/mlir/Dialect/SPIRV/Linking/ModuleCombiner.h
+++ b/mlir/include/mlir/Dialect/SPIRV/Linking/ModuleCombiner.h
@@ -13,9 +13,8 @@
#ifndef MLIR_DIALECT_SPIRV_LINKING_MODULECOMBINER_H_
#define MLIR_DIALECT_SPIRV_LINKING_MODULECOMBINER_H_
-#include "mlir/Dialect/SPIRV/IR/SPIRVModule.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallVector.h"
+#include "mlir/IR/OwningOpRef.h"
+#include "mlir/Support/LLVM.h"
namespace mlir {
class OpBuilder;
@@ -67,11 +66,9 @@ class ModuleOp;
/// function call.
///
/// \return the combined module.
-OwningSPIRVModuleRef
-combine(llvm::MutableArrayRef<ModuleOp> modules,
- OpBuilder &combinedModuleBuilder,
- llvm::function_ref<void(ModuleOp, StringRef, StringRef)>
- symbRenameListener);
+OwningOpRef<spirv::ModuleOp>
+combine(MutableArrayRef<ModuleOp> modules, OpBuilder &combinedModuleBuilder,
+ function_ref<void(ModuleOp, StringRef, StringRef)> symbRenameListener);
} // namespace spirv
} // namespace mlir
diff --git a/mlir/include/mlir/Target/SPIRV/Deserialization.h b/mlir/include/mlir/Target/SPIRV/Deserialization.h
index 207f506b17ad..ab7cce673d6d 100644
--- a/mlir/include/mlir/Target/SPIRV/Deserialization.h
+++ b/mlir/include/mlir/Target/SPIRV/Deserialization.h
@@ -13,21 +13,21 @@
#ifndef MLIR_TARGET_SPIRV_DESERIALIZATION_H
#define MLIR_TARGET_SPIRV_DESERIALIZATION_H
+#include "mlir/IR/OwningOpRef.h"
#include "mlir/Support/LLVM.h"
namespace mlir {
-struct LogicalResult;
class MLIRContext;
namespace spirv {
-class OwningSPIRVModuleRef;
+class ModuleOp;
/// Deserializes the given SPIR-V `binary` module and creates a MLIR ModuleOp
/// in the given `context`. Returns the ModuleOp on success; otherwise, reports
/// errors to the error handler registered with `context` and returns a null
/// module.
-OwningSPIRVModuleRef deserialize(ArrayRef<uint32_t> binary,
- MLIRContext *context);
+OwningOpRef<spirv::ModuleOp> deserialize(ArrayRef<uint32_t> binary,
+ MLIRContext *context);
} // end namespace spirv
} // end namespace mlir
diff --git a/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp b/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
index b91d7438e7c0..61494866850c 100644
--- a/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
+++ b/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
@@ -119,7 +119,7 @@ namespace spirv {
// TODO Properly test symbol rename listener mechanism.
-OwningSPIRVModuleRef
+OwningOpRef<spirv::ModuleOp>
combine(llvm::MutableArrayRef<spirv::ModuleOp> modules,
OpBuilder &combinedModuleBuilder,
llvm::function_ref<void(ModuleOp, StringRef, StringRef)>
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserialization.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserialization.cpp
index 2eb08669f658..7bb876266059 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserialization.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserialization.cpp
@@ -10,9 +10,10 @@
#include "Deserializer.h"
-namespace mlir {
-spirv::OwningSPIRVModuleRef spirv::deserialize(ArrayRef<uint32_t> binary,
- MLIRContext *context) {
+using namespace mlir;
+
+OwningOpRef<spirv::ModuleOp> spirv::deserialize(ArrayRef<uint32_t> binary,
+ MLIRContext *context) {
Deserializer deserializer(binary, context);
if (failed(deserializer.deserialize()))
@@ -20,4 +21,3 @@ spirv::OwningSPIRVModuleRef spirv::deserialize(ArrayRef<uint32_t> binary,
return deserializer.collect();
}
-} // namespace mlir
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 9a91428ba0db..d48349630b5b 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -14,7 +14,6 @@
#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h"
-#include "mlir/Dialect/SPIRV/IR/SPIRVModule.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
#include "mlir/IR/BlockAndValueMapping.h"
@@ -88,7 +87,7 @@ LogicalResult spirv::Deserializer::deserialize() {
return success();
}
-spirv::OwningSPIRVModuleRef spirv::Deserializer::collect() {
+OwningOpRef<spirv::ModuleOp> spirv::Deserializer::collect() {
return std::move(module);
}
@@ -96,7 +95,7 @@ spirv::OwningSPIRVModuleRef spirv::Deserializer::collect() {
// Module structure
//===----------------------------------------------------------------------===//
-spirv::OwningSPIRVModuleRef spirv::Deserializer::createModuleOp() {
+OwningOpRef<spirv::ModuleOp> spirv::Deserializer::createModuleOp() {
OpBuilder builder(context);
OperationState state(unknownLoc, spirv::ModuleOp::getOperationName());
spirv::ModuleOp::build(builder, state);
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
index 895b66a33509..ac4846d63cad 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
@@ -14,7 +14,6 @@
#define MLIR_TARGET_SPIRV_DESERIALIZER_H
#include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h"
-#include "mlir/Dialect/SPIRV/IR/SPIRVModule.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/IR/Builders.h"
#include "llvm/ADT/ArrayRef.h"
@@ -142,7 +141,7 @@ class Deserializer {
LogicalResult deserialize();
/// Collects the final SPIR-V ModuleOp.
- spirv::OwningSPIRVModuleRef collect();
+ OwningOpRef<spirv::ModuleOp> collect();
private:
//===--------------------------------------------------------------------===//
@@ -150,7 +149,7 @@ class Deserializer {
//===--------------------------------------------------------------------===//
/// Initializes the `module` ModuleOp in this deserializer instance.
- spirv::OwningSPIRVModuleRef createModuleOp();
+ OwningOpRef<spirv::ModuleOp> createModuleOp();
/// Processes SPIR-V module header in `binary`.
LogicalResult processHeader();
@@ -507,7 +506,7 @@ class Deserializer {
Location unknownLoc;
/// The SPIR-V ModuleOp.
- spirv::OwningSPIRVModuleRef module;
+ OwningOpRef<spirv::ModuleOp> module;
/// The current function under construction.
Optional<spirv::FuncOp> curFunction;
diff --git a/mlir/lib/Target/SPIRV/TranslateRegistration.cpp b/mlir/lib/Target/SPIRV/TranslateRegistration.cpp
index 852fe4b573c8..989de4142d76 100644
--- a/mlir/lib/Target/SPIRV/TranslateRegistration.cpp
+++ b/mlir/lib/Target/SPIRV/TranslateRegistration.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
-#include "mlir/Dialect/SPIRV/IR/SPIRVModule.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
@@ -52,7 +51,8 @@ static OwningModuleRef deserializeModule(const llvm::MemoryBuffer *input,
auto binary = llvm::makeArrayRef(reinterpret_cast<const uint32_t *>(start),
size / sizeof(uint32_t));
- spirv::OwningSPIRVModuleRef spirvModule = spirv::deserialize(binary, context);
+ OwningOpRef<spirv::ModuleOp> spirvModule =
+ spirv::deserialize(binary, context);
if (!spirvModule)
return {};
@@ -140,7 +140,7 @@ static LogicalResult roundTripModule(ModuleOp srcModule, bool emitDebugInfo,
// TODO: we should only load the required dialects instead of all dialects.
deserializationContext.loadAllAvailableDialects();
// Then deserialize to get back a SPIR-V module.
- spirv::OwningSPIRVModuleRef spirvModule =
+ OwningOpRef<spirv::ModuleOp> spirvModule =
spirv::deserialize(binary, &deserializationContext);
if (!spirvModule)
return failure();
diff --git a/mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp b/mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp
index ba6c94bc46db..8222be5f02f9 100644
--- a/mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp
+++ b/mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/SPIRV/IR/SPIRVGLSLCanonicalization.h"
-#include "mlir/Dialect/SPIRV/IR/SPIRVModule.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
diff --git a/mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp b/mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp
index 29a057041b55..cac6880c80d2 100644
--- a/mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp
+++ b/mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp
@@ -25,7 +25,7 @@ class TestModuleCombinerPass
void runOnOperation() override;
private:
- mlir::spirv::OwningSPIRVModuleRef combinedModule;
+ OwningOpRef<spirv::ModuleOp> combinedModule;
};
} // namespace
diff --git a/mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp b/mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp
index e3802807ed87..4f2c5d554cc2 100644
--- a/mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp
+++ b/mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp
@@ -14,7 +14,6 @@
#include "mlir/Target/SPIRV/Deserialization.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
-#include "mlir/Dialect/SPIRV/IR/SPIRVModule.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/MLIRContext.h"
@@ -45,7 +44,7 @@ class DeserializationTest : public ::testing::Test {
}
/// Performs deserialization and returns the constructed spv.module op.
- spirv::OwningSPIRVModuleRef deserialize() {
+ OwningOpRef<spirv::ModuleOp> deserialize() {
return spirv::deserialize(binary, &context);
}
diff --git a/mlir/unittests/Dialect/SPIRV/SerializationTest.cpp b/mlir/unittests/Dialect/SPIRV/SerializationTest.cpp
index 2a05edb8d42a..d92c52438e8c 100644
--- a/mlir/unittests/Dialect/SPIRV/SerializationTest.cpp
+++ b/mlir/unittests/Dialect/SPIRV/SerializationTest.cpp
@@ -14,7 +14,6 @@
#include "mlir/Target/SPIRV/Serialization.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
-#include "mlir/Dialect/SPIRV/IR/SPIRVModule.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
#include "mlir/IR/Builders.h"
@@ -102,7 +101,7 @@ class SerializationTest : public ::testing::Test {
protected:
MLIRContext context;
- spirv::OwningSPIRVModuleRef module;
+ OwningOpRef<spirv::ModuleOp> module;
SmallVector<uint32_t, 0> binary;
};
More information about the Mlir-commits
mailing list