mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
371dc7ea97
We now craft a new decompilation pipeline. We remove the exceptions introduced as fallbacks to preserve the semantics, and we perform passes of `dce` and `simplifycfg` to remove all the superfluos basic block remaining after this change. To do this, we need an additional pass that removes also the calls to the `llvm.assume` intrinsic, and another pass of `dce` to remove all the dead uses. In addition, we also remove dead stores to the `cpu_loop_exiting` global variable in order to improve the decompiled code. As a byproduct of this, we remove also the dependency from the `-remove-pc-stores` pass, since its jobs is included by the changes mentioned above.
54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
// LLVM includes
|
|
#include <llvm/ADT/SmallVector.h>
|
|
#include <llvm/IR/Function.h>
|
|
#include <llvm/IR/Module.h>
|
|
|
|
// revng includes
|
|
#include <revng/Support/IRHelpers.h>
|
|
|
|
// Local libraries includes
|
|
#include "revng-c/RemoveCpuLoopStore/RemoveCpuLoopStorePass.h"
|
|
|
|
using namespace llvm;
|
|
|
|
char RemoveCpuLoopStorePass::ID = 0;
|
|
using Reg = RegisterPass<RemoveCpuLoopStorePass>;
|
|
static Reg X("remove-cpu-loop-store", "Removes store to cpu_loop", true, true);
|
|
|
|
bool RemoveCpuLoopStorePass::runOnFunction(Function &F) {
|
|
if (not F.hasMetadata("revng.func.entry"))
|
|
return false;
|
|
|
|
// Retrieve the global variable `cpu_loop_exiting`
|
|
Module *M = F.getParent();
|
|
GlobalVariable *CpuLoop = M->getGlobalVariable("cpu_loop_exiting");
|
|
|
|
// Remove in bulk all the users of the global variable. We directly cast
|
|
// the user to a `llvm::StoreInst` by design (if we have another kind of user
|
|
// our assumptions does not hold.
|
|
SmallVector<Instruction *, 8> ToErase;
|
|
|
|
for (User *U : CpuLoop->users()) {
|
|
Instruction *I = cast<Instruction>(U);
|
|
|
|
// Check only translated functions.
|
|
if (I->getParent()->getParent() != &F)
|
|
continue;
|
|
|
|
StoreInst *Store = cast<StoreInst>(U);
|
|
ToErase.push_back(Store);
|
|
}
|
|
|
|
// Remove in bulk all the store found before.
|
|
bool Changed = not ToErase.empty();
|
|
for (Instruction *I : ToErase) {
|
|
I->eraseFromParent();
|
|
}
|
|
|
|
return Changed;
|
|
}
|