forked from OSchip/llvm-project
[MLIR] NFC. gpu.launch op argument const folder cleanup
NFC updates to gpu.launch op argument const folder. Differential Revision: https://reviews.llvm.org/D110136
This commit is contained in:
parent
7e7484a816
commit
5c77ed0330
|
@ -532,23 +532,19 @@ static ParseResult parseLaunchOp(OpAsmParser &parser, OperationState &result) {
|
|||
parser.parseOptionalAttrDict(result.attributes));
|
||||
}
|
||||
|
||||
/// Simplify the gpu.launch when the range of the thread and block IDs is
|
||||
/// Simplify the gpu.launch when the range of a thread or block ID is
|
||||
/// trivially known to be one.
|
||||
struct FoldLaunchArguments : public OpRewritePattern<LaunchOp> {
|
||||
using OpRewritePattern<LaunchOp>::OpRewritePattern;
|
||||
LogicalResult matchAndRewrite(LaunchOp op,
|
||||
PatternRewriter &rewriter) const override {
|
||||
auto isTriviallyOne = [](Value size) {
|
||||
IntegerAttr cst;
|
||||
return matchPattern(size, m_Constant(&cst)) && cst.getInt() == 1;
|
||||
};
|
||||
|
||||
// If the range implies a single value for `id`, replace `id`'s uses by
|
||||
// zero.
|
||||
Value zero;
|
||||
bool simplified = false;
|
||||
auto constPropIdUses = [&](Value id, Value size) {
|
||||
if (!isTriviallyOne(size))
|
||||
// Check if size is trivially one.
|
||||
if (!matchPattern(size, m_One()))
|
||||
return;
|
||||
if (!simplified) {
|
||||
// Create a zero value the first time.
|
||||
|
|
Loading…
Reference in New Issue