mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
c7f8f3302d
This commit introduces `BasicBlockID` as the unique identifier for a `efa::BasicBlock` into the CFG. A `BasicBlockID` is defined by a `MetaAddress` plus an incremental integer. This enables us to have multiple instances of the same block in a single function, which is particularly useful when inlining multiple times the same function. Apart from this, the commit also does the following: * It drops representing `MetaAddress`es a `structs` in the IR. This created several issues related to ABI. We now represent them as strings. * It defines more functions in `support.h`, instead of defining prototypes by hand in `CodeGenerator.cpp` and the like. Specifically, `unknownPC` and `raise_exception_helper`. We also introduce a C "constructor" for `PlainMetaAddress`. * It significantly reduces the API of `GeneratedCodeBasicInfo`, which was supposed to be put on a diet since a long time. Specifically, many jump target related methods have been moved to free functions in `IRHelpers.h`. Also `GCBI::getSuccessors` has been pushed into its only user, `PruneRetSuccessors`, to prevent further usage of a deprecated API. In the future, it would be nice to drop it entirely. * It introduces `efa::BasicBlock::InlinedFrom`. * Introduce an enum to represent named argument indices for `newpc`. This enables us to more effectively manipulate its argument list. * It improves the verification and error reporting for `efa::FunctionMetadata`. * Update tests. This commit is preliminary to another piece of work to improve the generality of inlining beyond the simple "fake function" scenario, for which the feature was originally conceived.
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/Instructions.h"
|
|
#include "llvm/Pass.h"
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "revng/BasicAnalyses/CustomCFG.h"
|
|
#include "revng/BasicAnalyses/GeneratedCodeBasicInfo.h"
|
|
#include "revng/Support/IRHelpers.h"
|
|
|
|
/// \brief Identify function call instructions
|
|
///
|
|
/// This pass parses the generated IR looking for terminator instructions which
|
|
/// look like function calls, i.e., they store the next program counter (the
|
|
/// return address) to a CSV (the link register) or in memory (the stack).
|
|
///
|
|
/// The pass also injects a call to the "funcion_call" function before
|
|
/// terminator instructions identified. The first argument represents the callee
|
|
/// basic block, the second the return basic block and the third the return
|
|
/// address.
|
|
class FunctionCallIdentification : public llvm::ModulePass {
|
|
public:
|
|
static char ID;
|
|
|
|
public:
|
|
FunctionCallIdentification() : llvm::ModulePass(ID) {}
|
|
|
|
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
|
|
AU.setPreservesAll();
|
|
AU.addRequired<GeneratedCodeBasicInfoWrapperPass>();
|
|
}
|
|
|
|
bool runOnModule(llvm::Module &M) override;
|
|
|
|
bool isFallthrough(MetaAddress Address) const {
|
|
return FallthroughAddresses.count(Address) != 0;
|
|
}
|
|
|
|
bool isFallthrough(llvm::BasicBlock *BB) const {
|
|
return isFallthrough(getBasicBlockID(BB).start());
|
|
}
|
|
|
|
bool isFallthrough(llvm::Instruction *I) const {
|
|
revng_assert(I->isTerminator());
|
|
return isFallthrough(I->getParent());
|
|
}
|
|
|
|
private:
|
|
void buildFilteredCFG(llvm::Function &F);
|
|
|
|
private:
|
|
llvm::Function *FunctionCall;
|
|
std::set<MetaAddress> FallthroughAddresses;
|
|
CustomCFG FilteredCFG;
|
|
};
|