-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir][transform] Make variable names in interpreter consistent. (NFC) #67800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][transform] Make variable names in interpreter consistent. (NFC) #67800
Conversation
This commit renames the arguments of several static implementation functions of the transform interpreter base class to match the names of the corresponding member variables in order to clarify their intent. Similarly, it renames some local variables to reflect their relationship with corresponding member variables. Finally, this commit also asserts in `interpreterBaseRunOnOperationImpl` that at most one of shared and library module are set (which the initialization function guarantees) and simplifies some related `if` conditions.
@llvm/pr-subscribers-mlir ChangesThis commit renames the arguments of several static implementation functions of the transform interpreter base class to match the names of the corresponding member variables in order to clarify their intent. Similarly, it renames some local variables to reflect their relationship with corresponding member variables. Finally, this commit also asserts in I factored out this commit from #67686, which I am thinking to abandon/put on hold. Full diff: https://github.com/llvm/llvm-project/pull/67800.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp b/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp
index d5c65b23e3a2134..47fa5cde1190704 100644
--- a/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp
+++ b/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp
@@ -379,7 +379,7 @@ static LogicalResult defineDeclaredSymbols(Block &block, ModuleOp definitions) {
LogicalResult transform::detail::interpreterBaseRunOnOperationImpl(
Operation *target, StringRef passName,
const std::shared_ptr<OwningOpRef<ModuleOp>> &sharedTransformModule,
- const std::shared_ptr<OwningOpRef<ModuleOp>> &libraryModule,
+ const std::shared_ptr<OwningOpRef<ModuleOp>> &transformLibraryModule,
const RaggedArray<MappedValue> &extraMappings,
const TransformOptions &options,
const Pass::Option<std::string> &transformFileName,
@@ -387,6 +387,12 @@ LogicalResult transform::detail::interpreterBaseRunOnOperationImpl(
const Pass::Option<std::string> &debugPayloadRootTag,
const Pass::Option<std::string> &debugTransformRootTag,
StringRef binaryName) {
+ bool hasSharedTransformModule =
+ sharedTransformModule && *sharedTransformModule;
+ bool hasTransformLibraryModule =
+ transformLibraryModule && *transformLibraryModule;
+ assert((!hasSharedTransformModule || !hasTransformLibraryModule) &&
+ "at most one of shared or library transform module can be set");
// Step 1
// ------
@@ -407,9 +413,8 @@ LogicalResult transform::detail::interpreterBaseRunOnOperationImpl(
// transform is embedded in the payload IR. If debugTransformRootTag was
// passed, then we are in user-specified selection of the transforming IR.
// This corresponds to REPL debug mode.
- bool sharedTransform = (sharedTransformModule && *sharedTransformModule);
Operation *transformContainer =
- sharedTransform ? sharedTransformModule->get() : target;
+ hasSharedTransformModule ? sharedTransformModule->get() : target;
Operation *transformRoot =
debugTransformRootTag.empty()
? findTopLevelTransform(transformContainer,
@@ -430,7 +435,7 @@ LogicalResult transform::detail::interpreterBaseRunOnOperationImpl(
// Copy external defintions for symbols if provided. Be aware of potential
// concurrent execution (normally, the error shouldn't be triggered unless the
// transform IR modifies itself in a pass, which is also forbidden elsewhere).
- if (!sharedTransform && libraryModule && *libraryModule) {
+ if (hasTransformLibraryModule) {
if (!target->isProperAncestor(transformRoot)) {
InFlightDiagnostic diag =
transformRoot->emitError()
@@ -439,7 +444,7 @@ LogicalResult transform::detail::interpreterBaseRunOnOperationImpl(
return diag;
}
if (failed(defineDeclaredSymbols(*transformRoot->getBlock(),
- libraryModule->get())))
+ transformLibraryModule->get())))
return failure();
}
@@ -461,25 +466,27 @@ LogicalResult transform::detail::interpreterBaseRunOnOperationImpl(
LogicalResult transform::detail::interpreterBaseInitializeImpl(
MLIRContext *context, StringRef transformFileName,
StringRef transformLibraryFileName,
- std::shared_ptr<OwningOpRef<ModuleOp>> &module,
- std::shared_ptr<OwningOpRef<ModuleOp>> &libraryModule,
+ std::shared_ptr<OwningOpRef<ModuleOp>> &sharedTransformModule,
+ std::shared_ptr<OwningOpRef<ModuleOp>> &transformLibraryModule,
function_ref<std::optional<LogicalResult>(OpBuilder &, Location)>
moduleBuilder) {
- OwningOpRef<ModuleOp> parsed;
- if (failed(parseTransformModuleFromFile(context, transformFileName, parsed)))
+ OwningOpRef<ModuleOp> parsedTransformModule;
+ if (failed(parseTransformModuleFromFile(context, transformFileName,
+ parsedTransformModule)))
return failure();
- if (parsed && failed(mlir::verify(*parsed)))
+ if (parsedTransformModule && failed(mlir::verify(*parsedTransformModule)))
return failure();
- OwningOpRef<ModuleOp> parsedLibrary;
+ OwningOpRef<ModuleOp> parsedLibraryModule;
if (failed(parseTransformModuleFromFile(context, transformLibraryFileName,
- parsedLibrary)))
+ parsedLibraryModule)))
return failure();
- if (parsedLibrary && failed(mlir::verify(*parsedLibrary)))
+ if (parsedLibraryModule && failed(mlir::verify(*parsedLibraryModule)))
return failure();
- if (parsed) {
- module = std::make_shared<OwningOpRef<ModuleOp>>(std::move(parsed));
+ if (parsedTransformModule) {
+ sharedTransformModule = std::make_shared<OwningOpRef<ModuleOp>>(
+ std::move(parsedTransformModule));
} else if (moduleBuilder) {
// TODO: better location story.
auto location = UnknownLoc::get(context);
@@ -491,20 +498,20 @@ LogicalResult transform::detail::interpreterBaseInitializeImpl(
if (std::optional<LogicalResult> result = moduleBuilder(b, location)) {
if (failed(*result))
return failure();
- module = std::move(localModule);
+ sharedTransformModule = std::move(localModule);
}
}
- if (!parsedLibrary || !*parsedLibrary)
+ if (!parsedLibraryModule || !*parsedLibraryModule)
return success();
- if (module && *module) {
- if (failed(defineDeclaredSymbols(*module->get().getBody(),
- parsedLibrary.get())))
+ if (sharedTransformModule && *sharedTransformModule) {
+ if (failed(defineDeclaredSymbols(*sharedTransformModule->get().getBody(),
+ parsedLibraryModule.get())))
return failure();
} else {
- libraryModule =
- std::make_shared<OwningOpRef<ModuleOp>>(std::move(parsedLibrary));
+ transformLibraryModule =
+ std::make_shared<OwningOpRef<ModuleOp>>(std::move(parsedLibraryModule));
}
return success();
}
|
This commit renames the arguments of several static implementation functions of the transform interpreter base class to match the names of the corresponding member variables in order to clarify their intent. Similarly, it renames some local variables to reflect their relationship with corresponding member variables. Finally, this commit also asserts in
interpreterBaseRunOnOperationImpl
that at most one of shared and library module are set (which the initialization function guarantees) and simplifies some relatedif
conditions.I factored out this commit from #67686, which I am thinking to abandon/put on hold.