Implement support for branch instruction operands.
PiperOrigin-RevId: 205666777
diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp
index 1aad430..7cb6440 100644
--- a/lib/IR/BasicBlock.cpp
+++ b/lib/IR/BasicBlock.cpp
@@ -35,6 +35,31 @@
getFunction()->getBlocks().erase(this);
}
+//===----------------------------------------------------------------------===//
+// Argument list management.
+//===----------------------------------------------------------------------===//
+
+BBArgument *BasicBlock::addArgument(Type *type) {
+ auto *arg = new BBArgument(type, this);
+ arguments.push_back(arg);
+ return arg;
+}
+
+/// Add one argument to the argument list for each type specified in the list.
+auto BasicBlock::addArguments(ArrayRef<Type *> types)
+ -> llvm::iterator_range<args_iterator> {
+ arguments.reserve(arguments.size() + types.size());
+ auto initialSize = arguments.size();
+ for (auto *type : types) {
+ addArgument(type);
+ }
+ return {arguments.data() + initialSize, arguments.data() + arguments.size()};
+}
+
+//===----------------------------------------------------------------------===//
+// Terminator management
+//===----------------------------------------------------------------------===//
+
void BasicBlock::setTerminator(TerminatorInst *inst) {
// If we already had a terminator, abandon it.
if (terminator)
@@ -46,6 +71,10 @@
inst->block = this;
}
+//===----------------------------------------------------------------------===//
+// ilist_traits for BasicBlock
+//===----------------------------------------------------------------------===//
+
mlir::CFGFunction *
llvm::ilist_traits<::mlir::BasicBlock>::getContainingFunction() {
size_t Offset(
@@ -86,17 +115,3 @@
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()};
-}