Switch to incremental creation of the dispatcher

Before this patch the dispatcher area was created all at once at a final
stage, however it's useful also while translating, since it keeps all the
code reachable, which is particularly important to be able to build a
exhaustive dominator tree.

* Create the dispatcher area when a new instance of `JumpTargetManager`
  is created.
* Create a fake conditional branch to the dispatcher at the beginning of
  the `root` function.
* Incrementally build the dispatcher's switch case in
  `JumpTargetManager::getBlockAt`.
This commit is contained in:
Alessandro Di Federico
2016-01-09 11:15:29 +01:00
parent 5882aaff95
commit 186435d456
3 changed files with 34 additions and 28 deletions
+10
View File
@@ -515,6 +515,16 @@ void CodeGenerator::translate(size_t LoadAddress,
GlobalVariable *PCReg = Variables.getByEnvOffset(ptc.pc, "pc");
JumpTargetManager JumpTargets(*TheModule, PCReg, MainFunction);
// Create a new block where the translation will start and emit a tautological
// branch to it, with false part being the dispatcher, which is always
// reachable
Entry = BasicBlock::Create(Context,
"translation-start",
MainFunction);
Builder.CreateCondBr(Builder.getTrue(), Entry, JumpTargets.dispatcher());
std::map<std::string, BasicBlock *> LabeledBasicBlocks;
std::vector<BasicBlock *> Blocks;