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/IR/AsmPrinter.cpp b/lib/IR/AsmPrinter.cpp
index 99fb1df..275f8ba 100644
--- a/lib/IR/AsmPrinter.cpp
+++ b/lib/IR/AsmPrinter.cpp
@@ -1065,9 +1065,10 @@
void BasicBlock::dump() const { print(llvm::errs()); }
void Statement::print(raw_ostream &os) const {
- ModuleState state(getFunction()->getContext());
+ MLFunction *function = findFunction();
+ ModuleState state(function->getContext());
ModulePrinter modulePrinter(os, state);
- MLFunctionPrinter(getFunction(), modulePrinter).print(this);
+ MLFunctionPrinter(function, modulePrinter).print(this);
}
void Statement::dump() const { print(llvm::errs()); }