Skip to content

Instantly share code, notes, and snippets.

@jpienaar
Last active January 8, 2024 05:37
Show Gist options
  • Save jpienaar/9598339b504157b189c3a3c38314a703 to your computer and use it in GitHub Desktop.
Save jpienaar/9598339b504157b189c3a3c38314a703 to your computer and use it in GitHub Desktop.
Checking ranges
int i = 0;
for (auto it : asmState.getOpDefs()) {
const char *startOp = it.scopeLoc.Start.getPointer();
const char *endOp = it.scopeLoc.End.getPointer();
for (auto res : it.resultGroups) {
SMRange range = res.definition.loc;
startOp = std::min(startOp, range.Start.getPointer());
}
rewriteBuffer.InsertText(startOp - start, ("🌜<" + Twine(i) + ">").str());
rewriteBuffer.InsertText(endOp - start, ("<" + Twine(i) + ">πŸŒ›").str());
++i;
}
// Two dynamic shapes: one of direct shape.shape_of(arg) and the other.
🌜<15>func.func @two_dynamic_one_direct_shape(%arg0: tensor<?x4x?xf32>, %arg1: tensor<2x4x?xf32>) -> tensor<?x4x?xf32> {
// SHAPE-DAG: Shape for {{.*}} = "test.abs"({{.*}}> :: @shape_cal_0(<block argument> of type 'tensor<?x4x?xf32>' at index: 0)
// SHAPE-DAG: Shape for {{.*}} = "test.concat"({{.*}}> :: @shape_cal_1(<block argument> of type 'tensor<?x4x?xf32>' at index: 0)
🌜<0>%c2 = arith.constant 2 : index
<0>πŸŒ›πŸŒœ<1>%c0 = arith.constant 0 : index
// Bar
<1>πŸŒ›πŸŒœ<2>%c4 = arith.constant 4 : index
// Foo
<2>πŸŒ›πŸŒœ<3>%0 = shape.shape_of %arg0 : tensor<?x4x?xf32> -> tensor<3xindex>
<3>πŸŒ›πŸŒœ<4>%1 = shape.get_extent %0, %c2 : tensor<3xindex>, index -> index
<4>πŸŒ›πŸŒœ<5>%2 = "test.abs"(%arg0) : (tensor<?x4x?xf32>) -> tensor<?x4x?xf32>
<5>πŸŒ›πŸŒœ<6>%3 = shape.with_shape %2, %0 : tensor<?x4x?xf32>, tensor<3xindex>
<6>πŸŒ›πŸŒœ<7>%4 = shape.value_of %3 : tensor<?x4x?xf32>
<7>πŸŒ›πŸŒœ<8>%5 = "test.concat"(%4, %arg1) {axis = 0 : i64} : (tensor<?x4x?xf32>, tensor<2x4x?xf32>) -> tensor<?x4x?xf32>
<8>πŸŒ›πŸŒœ<9>%6 = shape.get_extent %0, %c0 : tensor<3xindex>, index -> index
<9>πŸŒ›πŸŒœ<10>%7 = arith.addi %6, %c2 : index
<10>πŸŒ›πŸŒœ<11>%8 = shape.from_extents %7, %c4, %1 : index, index, index
<11>πŸŒ›πŸŒœ<12>%9 = shape.with_shape %5, %8 : tensor<?x4x?xf32>, !shape.shape
<12>πŸŒ›πŸŒœ<13>%10 = shape.value_of %9 : tensor<?x4x?xf32>
<13>πŸŒ›πŸŒœ<14>return %10 : tensor<?x4x?xf32>
<14>πŸŒ›}
<15>πŸŒ›
// Two dynamic shapes: one of direct shape.shape_of(arg) and the other.
🌜<15>func.func @two_dynamic_one_direct_shape(%arg0: tensor<?x4x?xf32>, %arg1: tensor<2x4x?xf32>) -> tensor<?x4x?xf32> {
// SHAPE-DAG: Shape for {{.*}} = "test.abs"({{.*}}> :: @shape_cal_0(<block argument> of type 'tensor<?x4x?xf32>' at index: 0)
// SHAPE-DAG: Shape for {{.*}} = "test.concat"({{.*}}> :: @shape_cal_1(<block argument> of type 'tensor<?x4x?xf32>' at index: 0)
🌜<0>%c2 = arith.constant 2 : index<0>πŸŒ›
🌜<1>%c0 = arith.constant 0 : index<1>πŸŒ›
// Bar
🌜<2>%c4 = arith.constant 4 : index<2>πŸŒ›
// Foo
🌜<3>%0 = shape.shape_of %arg0 : tensor<?x4x?xf32> -> tensor<3xindex><3>πŸŒ›
🌜<4>%1 = shape.get_extent %0, %c2 : tensor<3xindex>, index -> index<4>πŸŒ›
🌜<5>%2 = "test.abs"(%arg0) : (tensor<?x4x?xf32>) -> tensor<?x4x?xf32><5>πŸŒ›
🌜<6>%3 = shape.with_shape %2, %0 : tensor<?x4x?xf32>, tensor<3xindex><6>πŸŒ›
🌜<7>%4 = shape.value_of %3 : tensor<?x4x?xf32><7>πŸŒ›
🌜<8>%5 = "test.concat"(%4, %arg1) {axis = 0 : i64} : (tensor<?x4x?xf32>, tensor<2x4x?xf32>) -> tensor<?x4x?xf32><8>πŸŒ›
🌜<9>%6 = shape.get_extent %0, %c0 : tensor<3xindex>, index -> index<9>πŸŒ›
🌜<10>%7 = arith.addi %6, %c2 : index<10>πŸŒ›
🌜<11>%8 = shape.from_extents %7, %c4, %1 : index, index, index<11>πŸŒ›
🌜<12>%9 = shape.with_shape %5, %8 : tensor<?x4x?xf32>, !shape.shape
🌜<13>%10<12>πŸŒ› = shape.value_of %9 : tensor<?x4x?xf32><13>πŸŒ›
🌜<14>return %10 : tensor<?x4x?xf32><14>πŸŒ›
}<15>πŸŒ›
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment