Skip to content

Commit

Permalink
[CPU][NFC] Collapsing methods that query a config is enabled. (#18686)
Browse files Browse the repository at this point in the history
It just looks if the UnitAttr is set in the dictionary or not.

The `translationInfo` check is moved above LLVMCPUPipelineOptions setup
because some configs are set to `translationInfo`. We can bail out
earlier when it does not exist.

It is a follow-up for
903ab0a

Signed-off-by: hanhanW <hanhan0912@gmail.com>
  • Loading branch information
hanhanW authored Oct 4, 2024
1 parent 4710c98 commit 126e334
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ adjustTileSizesForUnPackOp(mlir::FunctionOpInterface entryPointFn,
auto tInfo = getTranslationInfo(entryPointFn);
auto pipeline = tInfo.getPassPipeline().getValue();
auto pipelineConfig = tInfo.getConfiguration();
if (isLoopPeelingEnabled(entryPointFn)) {
if (isOptEnabled(entryPointFn, getEnableLoopPeelingStr())) {
// See #16406
LLVM_DEBUG(KD_DBGS() << "unpack fusion does not work with peeling, falling "
"back to non-peeling path");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,25 @@ void LLVMCPULowerExecutableTargetPass::runOnOperation() {
return;
}

IREE::Codegen::TranslationInfoAttr translationInfo =
getTranslationInfo(funcOp);
if (!translationInfo)
return;

LLVMCPUPipelineOptions pipelineOpts;
if (isX86(target) || isRISCV(target)) {
pipelineOpts.useConfiguredVectorSizes = false;
}
pipelineOpts.decomposePackUnPackOps = isDecompositionEnabled(funcOp);
pipelineOpts.decomposePackUnPackOps =
isOptEnabled(funcOp, getEnableDecompositionStr());
pipelineOpts.lowerToAVX2 = hasAVX2Feature(target);
pipelineOpts.enableVectorMasking =
isX86(target) || isRISCV(target) ||
(isAArch64(target) && hasAnySVEFeature(target));
pipelineOpts.enableAArch64SME =
isAArch64(target) && hasAnySVEFeature(target) && hasSMEFeature(target);
pipelineOpts.enableAArch64I8mm = isAArch64(target) && hasI8mmFeature(target);
pipelineOpts.enablePeeling = isLoopPeelingEnabled(funcOp);

IREE::Codegen::TranslationInfoAttr translationInfo =
getTranslationInfo(funcOp);
if (!translationInfo)
return;
pipelineOpts.enablePeeling = isOptEnabled(funcOp, getEnableLoopPeelingStr());

OpPassManager pipeline(func::FuncOp::getOperationName());
switch (translationInfo.getDispatchLoweringPassPipeline()) {
Expand Down
18 changes: 6 additions & 12 deletions compiler/src/iree/compiler/Codegen/Utils/CPUUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

namespace mlir::iree_compiler {

static const char kLoopPeelingAttrName[] = "enable_loop_peeling";
static const char kDecompositionAttrName[] = "enable_decomposition";

FailureOr<Operation *> getRootOperation(ArrayRef<Operation *> computeOps) {
Operation *rootOperation = nullptr;
for (auto op : llvm::reverse(computeOps)) {
Expand Down Expand Up @@ -67,24 +64,21 @@ FailureOr<Operation *> getRootOperation(ArrayRef<Operation *> computeOps) {
return rootOperation;
}

static const char kDecompositionAttrName[] = "enable_decomposition";
StringAttr getEnableDecompositionAttrName(MLIRContext *ctx) {
return StringAttr::get(ctx, kDecompositionAttrName);
}
std::string getEnableDecompositionStr() { return kDecompositionAttrName; }

bool isDecompositionEnabled(FunctionOpInterface funcOp) {
DictionaryAttr config = getTranslationInfo(funcOp).getConfiguration();

return config && config.contains(kDecompositionAttrName);
}

static const char kLoopPeelingAttrName[] = "enable_loop_peeling";
StringAttr getEnableLoopPeelingAttrName(MLIRContext *ctx) {
return StringAttr::get(ctx, kLoopPeelingAttrName);
}
std::string getEnableLoopPeelingStr() { return kLoopPeelingAttrName; }

bool isLoopPeelingEnabled(FunctionOpInterface funcOp) {
bool isOptEnabled(FunctionOpInterface funcOp, StringRef label) {
DictionaryAttr config = getTranslationInfo(funcOp).getConfiguration();

return config && config.contains(kLoopPeelingAttrName);
return config && config.contains(label);
}

} // namespace mlir::iree_compiler
15 changes: 6 additions & 9 deletions compiler/src/iree/compiler/Codegen/Utils/CPUUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ FailureOr<Operation *> getRootOperation(ArrayRef<Operation *> computeOps);
/// Creates a string attribute containing the name of the attribute that is
/// used to enable decomposition.
StringAttr getEnableDecompositionAttrName(MLIRContext *ctx);

/// Checks whether loop peeling has been enabled for the input function. This
/// is infered from the config dict. attribute that's part of to the
/// translation info corresponding to this funciton.
bool isDecompositionEnabled(FunctionOpInterface funcOp);
std::string getEnableDecompositionStr();

/// Creates a string attribute containing the name of the attribute that is
/// used to enable loop peeling.
StringAttr getEnableLoopPeelingAttrName(MLIRContext *ctx);
std::string getEnableLoopPeelingStr();

/// Checks whether loop peeling has been enabled for the input function. This
/// is infered from the config dictt. attribute that's part of to the
/// translation info corresponding to this funciton.
bool isLoopPeelingEnabled(FunctionOpInterface funcOp);
/// Returns true if the UnitAttr of the `label` is enabled for the input
/// function. This is is infered from the config dictionary. attribute that's
/// part of to the translation info corresponding to this funciton.
bool isOptEnabled(FunctionOpInterface funcOp, StringRef label);

} // namespace mlir::iree_compiler

Expand Down

0 comments on commit 126e334

Please sign in to comment.