From ef2d8241f610fcf4d247c05e6ae062c87e4d004a Mon Sep 17 00:00:00 2001 From: Alessandro Di Federico Date: Tue, 12 Jan 2016 18:20:07 +0100 Subject: [PATCH] Rework the `root` function header * Don't start exploration from `VirtualAddress` but just add it as a block to explore. Then start the translation with `JumpTargetManager::peek` as usual. * Remove the unreachable instruction we were using as a delimiter to create new local variables, since it make the module invalid. Use the fake branch to the dispatcher instead. --- codegenerator.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/codegenerator.cpp b/codegenerator.cpp index 720e6faf0..ab8670c2d 100644 --- a/codegenerator.cpp +++ b/codegenerator.cpp @@ -526,7 +526,6 @@ void CodeGenerator::translate(uint64_t VirtualAddress, "entrypoint", MainFunction); Builder.SetInsertPoint(Entry); - Instruction *Delimiter = Builder.CreateUnreachable(); // Instantiate helpers VariableManager Variables(*TheModule, @@ -539,13 +538,14 @@ void CodeGenerator::translate(uint64_t VirtualAddress, MainFunction, ExecutableRanges); - // 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()); + JumpTargets.getBlockAt(VirtualAddress); + std::tie(VirtualAddress, Entry) = JumpTargets.peek(); + + // Fake jump to the dispatcher. This way all the blocks are always reachable. + // Also, use this branch as the delimiter to create local variables. + auto *Delimiter = Builder.CreateCondBr(Builder.getTrue(), + Entry, + JumpTargets.dispatcher()); std::map LabeledBasicBlocks; @@ -741,9 +741,6 @@ void CodeGenerator::translate(uint64_t VirtualAddress, PM.add(createDeadCodeEliminationPass()); PM.run(*TheModule); - // TODO: we have around all the usages of the PC, shall we drop them? - Delimiter->eraseFromParent(); - JumpTargets.translateIndirectJumps(); Translator.removeNewPCMarkers();