mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
5c619ab063
This commit introduces two new passes: * `GeneratedCodeBasicInfo`: recovers from the IR some basic information like the size of delay slots in the input architecture, the name of the program counter and so on. It can also identify the type of a basic block (e.g., dispatcher, jump target...). * * `FunctionCallIdentification`: identifies function calls and injects a marker before the associated terminator instruction. The idea of these two passes is to try to progressively move information we used to keep in `JumpTargetManager` into the IR, so that it is more easily accessible and passes do not need a reference to `JTM`. In particular by having markers for function calls available during jump target discovery we don't have to have duplicated and suboptimal implementation of `isCall`. This commit also introduce some additional helper functions and an helper class to quickly.
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
#ifndef _FUNCTIONCALLIDENTIFICATION_H
|
|
#define _FUNCTIONCALLIDENTIFICATION_H
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
// LLVM includes
|
|
#include "llvm/Pass.h"
|
|
#include "llvm/IR/BasicBlock.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/Instructions.h"
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
// Local includes
|
|
#include "generatedcodebasicinfo.h"
|
|
#include "ir-helpers.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::FunctionPass {
|
|
public:
|
|
static char ID;
|
|
|
|
public:
|
|
FunctionCallIdentification() : llvm::FunctionPass(ID) { }
|
|
|
|
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
|
|
AU.setPreservesAll();
|
|
AU.addRequired<GeneratedCodeBasicInfo>();
|
|
}
|
|
|
|
bool runOnFunction(llvm::Function &F) override;
|
|
|
|
/// \brief Return true if \p T is a function call in the input assembly
|
|
bool isCall(llvm::TerminatorInst *T) const {
|
|
assert(T != nullptr);
|
|
llvm::Instruction *Previous = getPrevious(T);
|
|
if (Previous == nullptr)
|
|
return false;
|
|
|
|
if (auto *Call = llvm::dyn_cast<llvm::CallInst>(Previous))
|
|
return Call->getCalledFunction() == FunctionCall;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool isCall(llvm::BasicBlock *BB) const {
|
|
return isCall(BB->getTerminator());
|
|
}
|
|
|
|
private:
|
|
llvm::Function *FunctionCall;
|
|
};
|
|
|
|
#endif // _FUNCTIONCALLIDENTIFICATION_H
|