Add the unconditional branch instruction, improve diagnostics for block
references.
PiperOrigin-RevId: 201872745
diff --git a/lib/IR/AsmPrinter.cpp b/lib/IR/AsmPrinter.cpp
index f857963..08fe838 100644
--- a/lib/IR/AsmPrinter.cpp
+++ b/lib/IR/AsmPrinter.cpp
@@ -120,6 +120,9 @@
void CFGFunctionState::print(const TerminatorInst *inst) {
switch (inst->getKind()) {
+ case TerminatorInst::Kind::Branch:
+ os << " br bb" << getBBID(cast<BranchInst>(inst)->getDest()) << "\n";
+ break;
case TerminatorInst::Kind::Return:
os << " return\n";
break;
diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp
index ad8f71e..4cfe162 100644
--- a/lib/IR/BasicBlock.cpp
+++ b/lib/IR/BasicBlock.cpp
@@ -16,7 +16,9 @@
// =============================================================================
#include "mlir/IR/BasicBlock.h"
+#include "mlir/IR/CFGFunction.h"
using namespace mlir;
BasicBlock::BasicBlock(CFGFunction *function) : function(function) {
+ function->blockList.push_back(this);
}
diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp
index c123b86..c32e878 100644
--- a/lib/IR/Instructions.cpp
+++ b/lib/IR/Instructions.cpp
@@ -23,6 +23,10 @@
return getBlock()->getFunction();
}
-ReturnInst::ReturnInst(BasicBlock *block) : TerminatorInst(Kind::Return, block){
+ReturnInst::ReturnInst(BasicBlock *parent)
+ : TerminatorInst(Kind::Return, parent) {
}
+BranchInst::BranchInst(BasicBlock *dest, BasicBlock *parent)
+ : TerminatorInst(Kind::Branch, parent), dest(dest) {
+}