forked from OSchip/llvm-project
[mlir:Parser] Always splice parsed operations to the end of the parsed block
The current splicing behavior dates back to when all blocks had terminators, so we would "helpfully" splice before the terminator. This doesn't make sense anymore, and leads to somewhat unexpected results when parsing multiple pieces of IR into the same block. Differential Revision: https://reviews.llvm.org/D135096
This commit is contained in:
parent
5301826fa8
commit
54cdc03dfa
|
@ -2593,8 +2593,8 @@ ParseResult TopLevelOperationParser::parse(Block *topLevelBlock,
|
|||
// top-level block.
|
||||
auto &parsedOps = topLevelOp->getBody()->getOperations();
|
||||
auto &destOps = topLevelBlock->getOperations();
|
||||
destOps.splice(destOps.empty() ? destOps.end() : std::prev(destOps.end()),
|
||||
parsedOps, parsedOps.begin(), parsedOps.end());
|
||||
destOps.splice(destOps.end(), parsedOps, parsedOps.begin(),
|
||||
parsedOps.end());
|
||||
return success();
|
||||
}
|
||||
|
||||
|
|
|
@ -1414,8 +1414,7 @@ LogicalResult BytecodeReader::parseIRSection(ArrayRef<uint8_t> sectionData,
|
|||
// Splice the parsed operations over to the provided top-level block.
|
||||
auto &parsedOps = moduleOp->getBody()->getOperations();
|
||||
auto &destOps = block->getOperations();
|
||||
destOps.splice(destOps.empty() ? destOps.end() : std::prev(destOps.end()),
|
||||
parsedOps, parsedOps.begin(), parsedOps.end());
|
||||
destOps.splice(destOps.end(), parsedOps, parsedOps.begin(), parsedOps.end());
|
||||
return success();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,4 +28,31 @@ TEST(MLIRParser, ParseInvalidIR) {
|
|||
ASSERT_TRUE(module);
|
||||
ASSERT_TRUE(failed(verify(*module)));
|
||||
}
|
||||
|
||||
TEST(MLIRParser, ParseAtEnd) {
|
||||
std::string firstModuleStr = R"mlir(
|
||||
"test.first"() : () -> ()
|
||||
)mlir";
|
||||
std::string secondModuleStr = R"mlir(
|
||||
"test.second"() : () -> ()
|
||||
)mlir";
|
||||
|
||||
MLIRContext context;
|
||||
context.allowUnregisteredDialects();
|
||||
Block block;
|
||||
|
||||
// Parse the first module string.
|
||||
LogicalResult firstParse =
|
||||
parseSourceString(firstModuleStr, &block, &context);
|
||||
EXPECT_TRUE(succeeded(firstParse));
|
||||
|
||||
// Parse the second module string.
|
||||
LogicalResult secondParse =
|
||||
parseSourceString(secondModuleStr, &block, &context);
|
||||
EXPECT_TRUE(succeeded(secondParse));
|
||||
|
||||
// Check the we parse at the end.
|
||||
EXPECT_EQ(block.front().getName().getStringRef(), "test.first");
|
||||
EXPECT_EQ(block.back().getName().getStringRef(), "test.second");
|
||||
}
|
||||
} // namespace
|
||||
|
|
Loading…
Reference in New Issue