// Prevent recursion.
WillMaterializeAllForwardRefs = true;
- while (!BasicBlockFwdRefs.empty()) {
- Function *F = BasicBlockFwdRefs.begin()->first;
+ while (!BasicBlockFwdRefQueue.empty()) {
+ Function *F = BasicBlockFwdRefQueue.front();
+ BasicBlockFwdRefQueue.pop_front();
assert(F && "Expected valid function");
+ if (!BasicBlockFwdRefs.count(F))
+ // Already materialized.
+ continue;
+
// Check for a function that isn't materializable to prevent an infinite
// loop. When parsing a blockaddress stored in a global variable, there
// isn't a trivial way to check if a function will have a body without a
if (std::error_code EC = Materialize(F))
return EC;
}
+ assert(BasicBlockFwdRefs.empty() && "Function missing from queue");
// Reset state.
WillMaterializeAllForwardRefs = false;
MDKindMap.clear();
assert(BasicBlockFwdRefs.empty() && "Unresolved blockaddress fwd references");
+ BasicBlockFwdRefQueue.clear();
}
//===----------------------------------------------------------------------===//
// Otherwise insert a placeholder and remember it so it can be inserted
// when the function is parsed.
BB = BasicBlock::Create(Context);
- BasicBlockFwdRefs[Fn].emplace_back(BBID, BB);
+ auto &FwdBBs = BasicBlockFwdRefs[Fn];
+ if (FwdBBs.empty())
+ BasicBlockFwdRefQueue.push_back(Fn);
+ FwdBBs.emplace_back(BBID, BB);
}
V = BlockAddress::get(Fn, BB);
break;
#include "llvm/IR/OperandTraits.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/ValueHandle.h"
+#include <deque>
#include <system_error>
#include <vector>
/// inserted lazily into functions when they're loaded.
typedef std::pair<unsigned, BasicBlock *> BasicBlockRefTy;
DenseMap<Function *, std::vector<BasicBlockRefTy>> BasicBlockFwdRefs;
+ std::deque<Function *> BasicBlockFwdRefQueue;
/// UseRelativeIDs - Indicates that we are using a new encoding for
/// instruction operands where most operands in the current