Skip to content

Commit 6ee1aba

Browse files
committed
[mlir][bytecode] Fix lazy loading of non-isolated regions
The bytecode reader currently assumes all regions can be lazy loaded, which breaks reading any non-isolated region. This patch fixes that by properly handling nested non-lazy regions, and only considers isolated regions as lazy. Differential Revision: https://reviews.llvm.org/D153795
1 parent a182664 commit 6ee1aba

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,11 +1317,11 @@ class mlir::BytecodeReader::Impl {
13171317
regionStack.push_back(std::move(it->getSecond()->second));
13181318
lazyLoadableOps.erase(it->getSecond());
13191319
lazyLoadableOpsMap.erase(it);
1320-
auto result = parseRegions(regionStack, regionStack.back());
1321-
assert((regionStack.empty() || failed(result)) &&
1322-
"broken invariant: regionStack should be empty when parseRegions "
1323-
"succeeds");
1324-
return result;
1320+
1321+
while (!regionStack.empty())
1322+
if (failed(parseRegions(regionStack, regionStack.back())))
1323+
return failure();
1324+
return success();
13251325
}
13261326

13271327
/// Return the context for this config.
@@ -2094,14 +2094,11 @@ BytecodeReader::Impl::parseRegions(std::vector<RegionReadState> &regionStack,
20942094
childState.owningReader =
20952095
std::make_unique<EncodingReader>(sectionData, fileLoc);
20962096
childState.reader = childState.owningReader.get();
2097-
}
20982097

2099-
if (lazyLoading) {
2100-
// If the user has a callback set, they have the opportunity
2101-
// to control lazyloading as we go.
2102-
if (!lazyOpsCallback || !lazyOpsCallback(*op)) {
2103-
lazyLoadableOps.push_back(
2104-
std::make_pair(*op, std::move(childState)));
2098+
// If the user has a callback set, they have the opportunity to
2099+
// control lazyloading as we go.
2100+
if (lazyLoading && (!lazyOpsCallback || !lazyOpsCallback(*op))) {
2101+
lazyLoadableOps.emplace_back(*op, std::move(childState));
21052102
lazyLoadableOpsMap.try_emplace(*op,
21062103
std::prev(lazyLoadableOps.end()));
21072104
continue;

mlir/test/Bytecode/bytecode-lazy-loading.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
func.func @op_with_passthrough_region_args() {
6+
// Ensure we can handle nested non-isolated/non-lazy regions.
7+
"test.one_region_op"() ({}) : () -> ()
8+
69
%0 = arith.constant 10 : index
710
test.isolated_region %0 {
811
"test.consumer"(%0) : (index) -> ()
@@ -36,6 +39,7 @@ func.func @op_with_passthrough_region_args() {
3639
// CHECK-NOT: arith
3740
// CHECK: Materializing...
3841
// CHECK: "func.func"() <{function_type = () -> (), sym_name = "op_with_passthrough_region_args"}> ({
42+
// CHECK: one_region_op
3943
// CHECK: arith
4044
// CHECK: isolated_region
4145
// CHECK-NOT: test.consumer

0 commit comments

Comments
 (0)