remove empty global init blocks
MODIFY
ir/function.cpp
ir/function.cpp
@@ -88,6 +88,17 @@ const BasicBlock& Function::getBB(string_view name) const {
return BBs.at(string(name));
}
+void Function::removeBB(BasicBlock &BB) {
+ BBs.erase(BB.getName());
+
+ for (auto I = BB_order.begin(), E = BB_order.end(); I != E; ++I) {
+ if (*I == &BB) {
+ BB_order.erase(I);
+ break;
+ }
+ }
+}
+
void Function::addConstant(unique_ptr<Value> &&c) {
constants.emplace_back(move(c));
}

MODIFY
ir/function.h
ir/function.h
@@ -80,6 +80,7 @@ public:
const BasicBlock& getFirstBB() const { return *BB_order[0]; }
BasicBlock& getBB(std::string_view name, bool push_front = false);
const BasicBlock& getBB(std::string_view name) const;
+ void removeBB(BasicBlock &BB);
void addConstant(std::unique_ptr<Value> &&c);
util::const_strip_unique_ptr<decltype(constants)> getConstants() const {

MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -730,6 +730,10 @@ public:
for (auto &itm : stores)
// Insert stores in lexicographical order of global var's names
InitBB.addInstr(move(itm.second));
+
+ if (InitBB.empty())
+ Fn.removeBB(InitBB);
+ else
InitBB.addInstr(make_unique<Branch>(Fn.getBB(entryName)));
return move(Fn);

remove empty global init blocks