mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
06733a9f3a
Split the `InlineHelpers` pass into the three phases: - `link-helpers-to-inline` links the missing `revng_inline` helper bodies from the `libtcg-helpers-to-inline-arch` module. - `inline-helpers` inlines, in every function except those tagged `Root` or `Helper`, the calls to `revng_inline` helpers whose critical arguments on the call site are constant. - `delete-helper-bodies` drops from the module the body of every `revng_inline` function, leaving only the declaration. The three passes live in a dedicated `revngInlineHelpers` library (`lib/InlineHelpers/` + `include/revng/InlineHelpers/`), so that libraries which do not depend on `revngFunctionIsolation` can use them without creating cyclic dependencies.
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "revng/InlineHelpers/DeleteHelperBodies.h"
|
|
#include "revng/Support/IRHelpers.h"
|
|
|
|
#include "PostInlineHelpersVerifyPass.h"
|
|
|
|
using namespace llvm;
|
|
|
|
// Drop the body of every `revng_inline`-tagged function in `M`, turning each
|
|
// one back into a declaration.
|
|
static void deleteHelperBodies(llvm::Module &M) {
|
|
for (llvm::Function &F : M) {
|
|
if (F.getSection() == InlineHelpersSection)
|
|
deleteOnlyBody(F);
|
|
}
|
|
}
|
|
|
|
char DeleteHelperBodiesPass::ID = 0;
|
|
|
|
using Register = RegisterPass<DeleteHelperBodiesPass>;
|
|
static Register
|
|
X("delete-helper-bodies", "Delete Helper Bodies Pass", true, true);
|
|
|
|
bool DeleteHelperBodiesPass::runOnModule(llvm::Module &M) {
|
|
deleteHelperBodies(M);
|
|
|
|
// Verify that no `getelementptr` instruction was dragged into an Isolated
|
|
// function by the inlining performed by the upstream `-inline-helpers`
|
|
// pass. The downstream pipeline relies on this invariant.
|
|
// TODO: convert this from a pass to a free-standing function
|
|
PostInlineHelpersVerifyPass{}.runOnModule(M);
|
|
|
|
return true;
|
|
}
|