Clean up and extend MLFuncBuilder to allow creating statements in the middle of a statement block. Rename Statement::getFunction() and StmtBlock()::getFunction() to findFunction() to make it clear that this is not a constant time getter.
Fix b/112039912 - we were recording 'i' instead of '%i' for loop induction variables causing "use of undefined SSA value" error.
PiperOrigin-RevId: 206884644
diff --git a/lib/Transforms/LoopUnroll.cpp b/lib/Transforms/LoopUnroll.cpp
index 489a98f..160a463 100644
--- a/lib/Transforms/LoopUnroll.cpp
+++ b/lib/Transforms/LoopUnroll.cpp
@@ -101,9 +101,7 @@
auto trip_count = (ub - lb + 1) / step;
auto *block = forStmt->getBlock();
-
- MLFuncBuilder builder(forStmt->Statement::getFunction());
- builder.setInsertionPoint(block);
+ MLFuncBuilder builder(block);
for (int i = 0; i < trip_count; i++) {
for (auto &stmt : forStmt->getStatements()) {