[mlir] Add basic block arguments
This patch adds support for basic block arguments including parsing and printing.
In doing so noticed that `ssa-id-and-type` is undefined in the MLIR spec; suggested an implementation in the spec doc.
PiperOrigin-RevId: 205593369
diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp
index c2c865c..1aad430 100644
--- a/lib/IR/BasicBlock.cpp
+++ b/lib/IR/BasicBlock.cpp
@@ -19,12 +19,14 @@
#include "mlir/IR/CFGFunction.h"
using namespace mlir;
-BasicBlock::BasicBlock() {
-}
+BasicBlock::BasicBlock() {}
BasicBlock::~BasicBlock() {
if (terminator)
terminator->eraseFromBlock();
+ for (BBArgument *arg : arguments)
+ delete arg;
+ arguments.clear();
}
/// Unlink this BasicBlock from its CFGFunction and delete it.
@@ -84,3 +86,17 @@
for (; first != last; ++first)
first->function = curParent;
}
+
+BBArgument *BasicBlock::addArgument(Type *type) {
+ arguments.push_back(new BBArgument(type, this));
+ return arguments.back();
+}
+
+llvm::iterator_range<BasicBlock::BBArgListType::iterator>
+BasicBlock::addArguments(ArrayRef<Type *> types) {
+ auto initial_size = arguments.size();
+ for (auto *type : types) {
+ addArgument(type);
+ }
+ return {arguments.data() + initial_size, arguments.data() + arguments.size()};
+}