Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/mlir/cxx/mlir/codegen_statements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,21 @@ void Codegen::StatementVisitor::operator()(WhileStatementAST* ast) {

void Codegen::StatementVisitor::operator()(DoStatementAST* ast) {
auto loopBlock = gen.newBlock();
auto conditionBlock = gen.newBlock();
auto endLoopBlock = gen.newBlock();

Loop loop{loopBlock, endLoopBlock};
Loop loop{conditionBlock, endLoopBlock};
std::swap(gen.loop_, loop);

gen.branch(gen.getLocation(ast->statement->firstSourceLocation()), loopBlock);

gen.builder_.setInsertionPointToEnd(loopBlock);
gen.statement(ast->statement);

gen.branch(gen.getLocation(ast->statement->lastSourceLocation()),
conditionBlock);

gen.builder_.setInsertionPointToEnd(conditionBlock);
gen.condition(ast->expression, loopBlock, endLoopBlock);

gen.builder_.setInsertionPointToEnd(endLoopBlock);
Expand Down Expand Up @@ -226,13 +232,14 @@ void Codegen::StatementVisitor::operator()(ForStatementAST* ast) {
Loop loop{stepLoopBlock, endLoopBlock};
std::swap(gen.loop_, loop);

gen.branch(
gen.getLocation(ast->condition ? ast->condition->firstSourceLocation()
: ast->semicolonLoc),
beginLoopBlock);

gen.branch(gen.getLocation(ast->firstSourceLocation()), beginLoopBlock);
gen.builder_.setInsertionPointToEnd(beginLoopBlock);
gen.condition(ast->condition, loopBodyBlock, endLoopBlock);

if (ast->condition) {
gen.condition(ast->condition, loopBodyBlock, endLoopBlock);
} else {
gen.branch(gen.getLocation(ast->semicolonLoc), loopBodyBlock);
}

gen.builder_.setInsertionPointToEnd(loopBodyBlock);
gen.statement(ast->statement);
Expand Down
Loading