-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ValueBoundsOpInterface on HAL ID/count ops, util.assume.int
Add a model of ValueBoundsOpInterface (the one used for reasoning about affine maps and loops) to the HAL ID ops and util.assume.int to improve both loop invariant code motion and, in the future, single-iteration loop removal.
- Loading branch information
Showing
7 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
compiler/src/iree/compiler/ExternalInterfaces/HALExternalModels.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2025 The IREE Authors | ||
// | ||
// Licensed 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 | ||
|
||
#include "iree/compiler/ExternalInterfaces/HALExternalModels.h" | ||
|
||
#include "iree/compiler/Dialect/HAL/IR/HALDialect.h" | ||
#include "iree/compiler/Dialect/HAL/IR/HALOps.h" | ||
#include "mlir/Interfaces/ValueBoundsOpInterface.h" | ||
|
||
namespace mlir::iree_compiler { | ||
|
||
namespace { | ||
|
||
//===----------------------------------------------------------------------===// | ||
// ValueBoundsOpInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
template <typename IDOp> | ||
struct IDOpValueBoundsInterface : public ValueBoundsOpInterface::ExternalModel< | ||
IDOpValueBoundsInterface<IDOp>, IDOp> { | ||
void populateBoundsForIndexValue(Operation *op, Value value, | ||
ValueBoundsConstraintSet &cstr) const { | ||
auto boundOp = cast<IDOp>(op); | ||
assert(value == boundOp.getResult() && "value must be op result"); | ||
cstr.bound(value) >= 0; | ||
if (boundOp.getUpperBound()) { | ||
cstr.bound(value) < boundOp.getUpperBound()->getSExtValue(); | ||
} | ||
} | ||
}; | ||
|
||
template <typename CountOp> | ||
struct CountOpValueBoundsInterface | ||
: public ValueBoundsOpInterface::ExternalModel< | ||
CountOpValueBoundsInterface<CountOp>, CountOp> { | ||
void populateBoundsForIndexValue(Operation *op, Value value, | ||
ValueBoundsConstraintSet &cstr) const { | ||
auto boundOp = cast<CountOp>(op); | ||
assert(value == boundOp.getResult() && "value must be op result"); | ||
cstr.bound(value) >= 1; | ||
if (boundOp.getUpperBound()) { | ||
cstr.bound(value) <= boundOp.getUpperBound()->getSExtValue(); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
void registerHALExternalModels(DialectRegistry ®istry) { | ||
registry.addExtension(+[](MLIRContext *context, | ||
IREE::HAL::HALDialect *dialect) { | ||
IREE::HAL::InterfaceWorkgroupIDOp::attachInterface< | ||
IDOpValueBoundsInterface<IREE::HAL::InterfaceWorkgroupIDOp>>(*context); | ||
|
||
IREE::HAL::InterfaceWorkgroupSizeOp::attachInterface< | ||
CountOpValueBoundsInterface<IREE::HAL::InterfaceWorkgroupSizeOp>>( | ||
*context); | ||
IREE::HAL::InterfaceWorkgroupCountOp::attachInterface< | ||
CountOpValueBoundsInterface<IREE::HAL::InterfaceWorkgroupCountOp>>( | ||
*context); | ||
}); | ||
} | ||
} // namespace mlir::iree_compiler |
20 changes: 20 additions & 0 deletions
20
compiler/src/iree/compiler/ExternalInterfaces/HALExternalModels.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2025 The IREE Authors | ||
// | ||
// Licensed 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 IREE_COMPILER_EXTERNALINTERFACES_HALEXTERNALMODELS_H_ | ||
#define IREE_COMPILER_EXTERNALINTERFACES_HALEXTERNALMODELS_H_ | ||
|
||
namespace mlir { | ||
class DialectRegistry; | ||
} // namespace mlir | ||
|
||
namespace mlir::iree_compiler { | ||
|
||
void registerHALExternalModels(DialectRegistry ®istry); | ||
|
||
} // namespace mlir::iree_compiler | ||
|
||
#endif // IREE_COMPILER_EXTERNALINTERFACES_HALEXTERNALMODELS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters