Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
llvm-epi
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roger Ferrer
llvm-epi
Commits
3444996b
Commit
3444996b
authored
3 years ago
by
Alexander Belyaev
Browse files
Options
Downloads
Patches
Plain Diff
[mlir] Add a pattern to bufferize std.index_cast.
Differential Revision:
https://reviews.llvm.org/D102088
parent
a3f22d02
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mlir/lib/Dialect/StandardOps/Transforms/Bufferize.cpp
+21
-7
21 additions, 7 deletions
mlir/lib/Dialect/StandardOps/Transforms/Bufferize.cpp
mlir/test/Dialect/Standard/bufferize.mlir
+13
-0
13 additions, 0 deletions
mlir/test/Dialect/Standard/bufferize.mlir
with
34 additions
and
7 deletions
mlir/lib/Dialect/StandardOps/Transforms/Bufferize.cpp
+
21
−
7
View file @
3444996b
...
@@ -34,9 +34,22 @@ public:
...
@@ -34,9 +34,22 @@ public:
return
success
();
return
success
();
}
}
};
};
}
// namespace
namespace
{
class
BufferizeIndexCastOp
:
public
OpConversionPattern
<
IndexCastOp
>
{
public:
using
OpConversionPattern
::
OpConversionPattern
;
LogicalResult
matchAndRewrite
(
IndexCastOp
op
,
ArrayRef
<
Value
>
operands
,
ConversionPatternRewriter
&
rewriter
)
const
override
{
IndexCastOp
::
Adaptor
adaptor
(
operands
);
auto
tensorType
=
op
.
getType
().
cast
<
RankedTensorType
>
();
rewriter
.
replaceOpWithNewOp
<
IndexCastOp
>
(
op
,
adaptor
.
in
(),
MemRefType
::
get
(
tensorType
.
getShape
(),
tensorType
.
getElementType
()));
return
success
();
}
};
class
BufferizeSelectOp
:
public
OpConversionPattern
<
SelectOp
>
{
class
BufferizeSelectOp
:
public
OpConversionPattern
<
SelectOp
>
{
public:
public:
using
OpConversionPattern
::
OpConversionPattern
;
using
OpConversionPattern
::
OpConversionPattern
;
...
@@ -56,8 +69,8 @@ public:
...
@@ -56,8 +69,8 @@ public:
void
mlir
::
populateStdBufferizePatterns
(
BufferizeTypeConverter
&
typeConverter
,
void
mlir
::
populateStdBufferizePatterns
(
BufferizeTypeConverter
&
typeConverter
,
RewritePatternSet
&
patterns
)
{
RewritePatternSet
&
patterns
)
{
patterns
.
add
<
BufferizeDimOp
,
BufferizeSelectOp
>
(
typeConverter
,
patterns
.
add
<
BufferizeDimOp
,
BufferizeSelectOp
,
BufferizeIndexCastOp
>
(
patterns
.
getContext
());
typeConverter
,
patterns
.
getContext
());
}
}
namespace
{
namespace
{
...
@@ -68,14 +81,15 @@ struct StdBufferizePass : public StdBufferizeBase<StdBufferizePass> {
...
@@ -68,14 +81,15 @@ struct StdBufferizePass : public StdBufferizeBase<StdBufferizePass> {
RewritePatternSet
patterns
(
context
);
RewritePatternSet
patterns
(
context
);
ConversionTarget
target
(
*
context
);
ConversionTarget
target
(
*
context
);
target
.
addLegalDialect
<
memref
::
MemRefDialect
>
();
target
.
addLegalDialect
<
scf
::
SCFDialect
,
StandardOpsDialect
,
target
.
addLegalDialect
<
StandardOpsDialect
>
();
memref
::
MemRefDialect
>
();
target
.
addLegalDialect
<
scf
::
SCFDialect
>
();
populateStdBufferizePatterns
(
typeConverter
,
patterns
);
populateStdBufferizePatterns
(
typeConverter
,
patterns
);
// We only bufferize the case of tensor selected type and scalar condition,
// We only bufferize the case of tensor selected type and scalar condition,
// as that boils down to a select over memref descriptors (don't need to
// as that boils down to a select over memref descriptors (don't need to
// touch the data).
// touch the data).
target
.
addDynamicallyLegalOp
<
IndexCastOp
>
(
[
&
](
IndexCastOp
op
)
{
return
typeConverter
.
isLegal
(
op
.
getType
());
});
target
.
addDynamicallyLegalOp
<
SelectOp
>
([
&
](
SelectOp
op
)
{
target
.
addDynamicallyLegalOp
<
SelectOp
>
([
&
](
SelectOp
op
)
{
return
typeConverter
.
isLegal
(
op
.
getType
())
||
return
typeConverter
.
isLegal
(
op
.
getType
())
||
!
op
.
condition
().
getType
().
isa
<
IntegerType
>
();
!
op
.
condition
().
getType
().
isa
<
IntegerType
>
();
...
...
This diff is collapsed.
Click to expand it.
mlir/test/Dialect/Standard/bufferize.mlir
+
13
−
0
View file @
3444996b
...
@@ -24,3 +24,16 @@ func @select(%arg0: i1, %arg1: tensor<f32>, %arg2: tensor<f32>) -> tensor<f32> {
...
@@ -24,3 +24,16 @@ func @select(%arg0: i1, %arg1: tensor<f32>, %arg2: tensor<f32>) -> tensor<f32> {
%0 = select %arg0, %arg1, %arg2 : tensor<f32>
%0 = select %arg0, %arg1, %arg2 : tensor<f32>
return %0 : tensor<f32>
return %0 : tensor<f32>
}
}
// CHECK-LABEL: func @index_cast(
// CHECK-SAME: %[[TENSOR:.*]]: tensor<i32>, %[[SCALAR:.*]]: i32
func @index_cast(%tensor: tensor<i32>, %scalar: i32) -> (tensor<index>, index) {
%index_tensor = index_cast %tensor : tensor<i32> to tensor<index>
%index_scalar = index_cast %scalar : i32 to index
return %index_tensor, %index_scalar : tensor<index>, index
}
// CHECK: %[[MEMREF:.*]] = memref.buffer_cast %[[TENSOR]] : memref<i32>
// CHECK-NEXT: %[[INDEX_MEMREF:.*]] = index_cast %[[MEMREF]]
// CHECK-SAME: memref<i32> to memref<index>
// CHECK-NEXT: %[[INDEX_TENSOR:.*]] = memref.tensor_load %[[INDEX_MEMREF]]
// CHECK: return %[[INDEX_TENSOR]]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment