Skip to content

Commit

Permalink
[Codegen] Clean up MaterializeUserConfigs. NFC. (#19207)
Browse files Browse the repository at this point in the history
Just some minor cleanup before doing any changes to the pass logic:
* Drop unused includes
* Fix comment formatting
* Hoist constants to the namespace scope
* Simplify control flow to follow the llvm coding style

Signed-off-by: Jakub Kuderski <[email protected]>
  • Loading branch information
kuhar authored Nov 19, 2024
1 parent 23c32c6 commit 4396bf1
Showing 1 changed file with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <iterator>

#include "iree/compiler/Codegen/Common/Passes.h"
#include "iree/compiler/Codegen/Common/UserConfig.h"
#include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenAttrs.h"
#include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenDialect.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/iterator_range.h"
#include "mlir/Dialect/Linalg/Transforms/Transforms.h"
#include "mlir/Dialect/Transform/IR/TransformDialect.h"
#include "mlir/Dialect/Transform/IR/TransformOps.h"
#include "mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"

#define DEBUG_TYPE "iree-codegen-materialize-user-configs"
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
Expand All @@ -40,7 +31,8 @@ llvm::cl::opt<std::string> clCodegenTransformDialectLibraryFileName(

namespace {

static const char kTranslationInfoAttrName[] = "translation_info";
constexpr StringLiteral kTranslationInfoAttrName = "translation_info";
constexpr StringLiteral kDefaultTransformSequenceName = "__kernel_config";

enum StrategyRunResult {
Success = 0,
Expand Down Expand Up @@ -87,10 +79,11 @@ struct MaterializeUserConfigsPass final
// or any other IREE codegen pipeline.
//
// 2. Use the configuration strategy to do codegen directly. At the end
// of
// the strategy, the variant needs to be annotated with
// "translation_info" = #iree_codegen.translation_info<pipeline =
// None>
// of the strategy, the variant needs to be annotated with:
// ```mlir
// "translation_info" =
// #iree_codegen.translation_info<pipeline = None>
// ```
SmallVector<StringRef, 2> parts;
llvm::SplitString(
llvm::StringRef(clCodegenTransformDialectLibraryFileName), parts,
Expand All @@ -112,16 +105,14 @@ struct MaterializeUserConfigsPass final
libraryFileName = parts[0];
}

std::string entrySequenceName;
StringRef entrySequenceName = kDefaultTransformSequenceName;
// Check if the user specified a custom entry point name.
if (parts.size() == 2) {
if (parts[1].empty()) {
funcOp.emitError() << "Cannot specify an empty sequence name";
return signalPassFailure();
}
entrySequenceName = parts[1];
} else {
entrySequenceName = "__kernel_config";
}

LDBG("MaterializeUserConfigsPass on function: " << funcOp);
Expand All @@ -145,7 +136,8 @@ struct MaterializeUserConfigsPass final
funcOp.emitError() << "transform kernel config strategy `"
<< entrySequenceName << " not found";
return signalPassFailure();
} else if (runResult == StrategyRunResult::Failed) {
}
if (runResult == StrategyRunResult::Failed) {
funcOp.emitError() << "transform kernel config strategy `"
<< entrySequenceName << "` failed to apply";
return signalPassFailure();
Expand Down

0 comments on commit 4396bf1

Please sign in to comment.