Skip to content

Commit 5f782d2

Browse files
dominikgrewejoker-eph
authored andcommitted
Preserve argument locations when cloning a region.
Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D117403
1 parent 0d7fbb0 commit 5f782d2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

mlir/lib/IR/Region.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void Region::cloneInto(Region *dest, Region::iterator destPos,
9292
// argument to the cloned block.
9393
for (auto arg : block.getArguments())
9494
if (!mapper.contains(arg))
95-
mapper.map(arg, newBlock->addArgument(arg.getType()));
95+
mapper.map(arg, newBlock->addArgument(arg.getType(), arg.getLoc()));
9696

9797
// Clone and remap the operations within this block.
9898
for (auto &op : block)

mlir/test/Transforms/inlining.mlir

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,26 @@ func @inline_gpu_ops() -> memref<1024xf32> {
202202
%m = call @gpu_alloc() : () -> memref<1024xf32>
203203
return %m : memref<1024xf32>
204204
}
205+
206+
// Test block arguments location propagation.
207+
// Use two call-sites to force cloning.
208+
func @func_with_block_args_location(%arg0 : i32) {
209+
br ^bb1(%arg0 : i32)
210+
^bb1(%x : i32 loc("foo")):
211+
"test.foo" (%x) : (i32) -> () loc("bar")
212+
return
213+
}
214+
215+
// INLINE-LOC-LABEL: func @func_with_block_args_location_callee1
216+
// INLINE-LOC: br
217+
// INLINE-LOC: ^bb{{[0-9]+}}(%{{.*}}: i32 loc("foo")
218+
func @func_with_block_args_location_callee1(%arg0 : i32) {
219+
call @func_with_block_args_location(%arg0) : (i32) -> ()
220+
return
221+
}
222+
223+
// CHECK-LABEL: func @func_with_block_args_location_callee2
224+
func @func_with_block_args_location_callee2(%arg0 : i32) {
225+
call @func_with_block_args_location(%arg0) : (i32) -> ()
226+
return
227+
}

0 commit comments

Comments
 (0)