Rework the cloning infrastructure for statements to be able to take and update
an operand mapping, which simplifies it a bit. Implement cloning for IfStmt,
rename getThenClause() to getThen() which is unambiguous and less repetitive in
use cases.
PiperOrigin-RevId: 207915990
diff --git a/lib/Parser/Parser.cpp b/lib/Parser/Parser.cpp
index 5c34bff..45ac4e6 100644
--- a/lib/Parser/Parser.cpp
+++ b/lib/Parser/Parser.cpp
@@ -2094,7 +2094,7 @@
public:
MLFunctionParser(ParserState &state, MLFunction *function)
: FunctionParser(state, Kind::MLFunc), function(function),
- builder(function) {}
+ builder(function, function->end()) {}
ParseResult parseFunctionBody();
@@ -2191,7 +2191,7 @@
return ParseFailure;
// Reset insertion point to the current block.
- builder.setInsertionPoint(forStmt->getBlock());
+ builder.setInsertionPointToEnd(forStmt->getBlock());
// TODO: remove definition of the induction variable.
@@ -2348,7 +2348,7 @@
return ParseFailure;
IfStmt *ifStmt = builder.createIf(condition);
- IfClause *thenClause = ifStmt->getThenClause();
+ IfClause *thenClause = ifStmt->getThen();
// When parsing of an if statement body fails, the IR contains
// the if statement with the portion of the body that has been
@@ -2357,20 +2357,20 @@
return ParseFailure;
if (consumeIf(Token::kw_else)) {
- auto *elseClause = ifStmt->createElseClause();
+ auto *elseClause = ifStmt->createElse();
if (parseElseClause(elseClause))
return ParseFailure;
}
// Reset insertion point to the current block.
- builder.setInsertionPoint(ifStmt->getBlock());
+ builder.setInsertionPointToEnd(ifStmt->getBlock());
return ParseSuccess;
}
ParseResult MLFunctionParser::parseElseClause(IfClause *elseClause) {
if (getToken().is(Token::kw_if)) {
- builder.setInsertionPoint(elseClause);
+ builder.setInsertionPointToEnd(elseClause);
return parseIfStmt();
}
@@ -2385,7 +2385,7 @@
return builder.createOperation(state);
};
- builder.setInsertionPoint(block);
+ builder.setInsertionPointToEnd(block);
while (getToken().isNot(Token::kw_return, Token::r_brace)) {
switch (getToken().getKind()) {