Move newline printed with op to function/basic block printer.
Allows printing the instruction to string without trailing newline. Making it easier to reuse print to annotate instructions during lowering. And removes need for newline in the print functions of ops.
PiperOrigin-RevId: 204630791
diff --git a/lib/IR/AsmPrinter.cpp b/lib/IR/AsmPrinter.cpp
index 0103e6a..2dd2a3b 100644
--- a/lib/IR/AsmPrinter.cpp
+++ b/lib/IR/AsmPrinter.cpp
@@ -117,8 +117,6 @@
[&]() { os << ", "; });
os << '}';
}
-
- os << '\n';
}
//===----------------------------------------------------------------------===//
@@ -174,10 +172,13 @@
os << "bb" << getBBID(block) << ":\n";
// TODO Print arguments.
- for (auto &inst : block->getOperations())
+ for (auto &inst : block->getOperations()) {
print(&inst);
+ os << "\n";
+ }
print(block->getTerminator());
+ os << "\n";
}
void CFGFunctionState::print(const Instruction *inst) {
@@ -196,10 +197,10 @@
}
void CFGFunctionState::print(const BranchInst *inst) {
- os << " br bb" << getBBID(inst->getDest()) << "\n";
+ os << " br bb" << getBBID(inst->getDest());
}
void CFGFunctionState::print(const ReturnInst *inst) {
- os << " return\n";
+ os << " return";
}
//===----------------------------------------------------------------------===//
@@ -248,8 +249,10 @@
void MLFunctionState::print(const StmtBlock *block) {
numSpaces += indentWidth;
- for (auto &stmt : block->getStatements())
+ for (auto &stmt : block->getStatements()) {
print(&stmt);
+ os << "\n";
+ }
numSpaces -= indentWidth;
}
@@ -297,6 +300,7 @@
void Instruction::dump() const {
print(llvm::errs());
+ llvm::errs() << "\n";
}
void AffineMap::dump() const { print(llvm::errs()); }
@@ -417,6 +421,7 @@
void Statement::dump() const {
print(llvm::errs());
}
+
void Function::print(raw_ostream &os) const {
switch (getKind()) {
case Kind::ExtFunc: return cast<ExtFunction>(this)->print(os);
diff --git a/lib/IR/StandardOps.cpp b/lib/IR/StandardOps.cpp
index 01d91bb..d1ddf65 100644
--- a/lib/IR/StandardOps.cpp
+++ b/lib/IR/StandardOps.cpp
@@ -21,7 +21,7 @@
using namespace mlir;
void AddFOp::print(raw_ostream &os) const {
- os << "addf xx, yy : sometype\n";
+ os << "addf xx, yy : sometype";
}
// Return an error message on failure.
@@ -33,7 +33,7 @@
}
void DimOp::print(raw_ostream &os) const {
- os << "dim xxx, " << getIndex() << " : sometype\n";
+ os << "dim xxx, " << getIndex() << " : sometype";
}
const char *DimOp::verify() const {