2024-01-09 18:13:56 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-09-14 19:43:13 +03:00
|
|
|
#include "../Utils/SgUtils.h"
|
|
|
|
|
#include "CFGraph.h"
|
|
|
|
|
|
2024-01-09 18:13:56 +03:00
|
|
|
namespace LIVE_VARIABLES
|
|
|
|
|
{
|
2024-01-12 16:11:21 +03:00
|
|
|
/* Store information about live and dead variables after call operator */
|
|
|
|
|
/* (needed for interprocedural part of live variable analysis) */
|
|
|
|
|
class LiveDeadVarsForCall
|
2024-01-09 18:13:56 +03:00
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
bool tryInsert(std::set<SAPFOR::BasicBlock*>& dest, SAPFOR::BasicBlock* b);
|
|
|
|
|
public:
|
|
|
|
|
FuncInfo* func;
|
|
|
|
|
|
|
|
|
|
std::map<int, std::set<SAPFOR::BasicBlock*>> live_after;
|
|
|
|
|
std::set<int> dead_after;
|
|
|
|
|
|
|
|
|
|
std::map<SAPFOR::Argument*, std::set<SAPFOR::BasicBlock*>> commons_live_after;
|
|
|
|
|
std::set<SAPFOR::Argument*> commons_dead_after;
|
|
|
|
|
|
|
|
|
|
std::vector<SAPFOR::Argument*> params;
|
|
|
|
|
SAPFOR::BasicBlock* block;
|
|
|
|
|
|
2024-01-12 16:11:21 +03:00
|
|
|
LiveDeadVarsForCall(FuncInfo* f, SAPFOR::BasicBlock* b, const std::vector<SAPFOR::Argument*>& p);
|
2024-01-09 18:13:56 +03:00
|
|
|
|
|
|
|
|
void make_live(SAPFOR::Argument* arg, SAPFOR::BasicBlock* b);
|
|
|
|
|
void make_dead(SAPFOR::Argument* arg);
|
|
|
|
|
|
|
|
|
|
void updateFromOut();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 19:43:13 +03:00
|
|
|
template <class IT, class DEST>
|
|
|
|
|
void insertIfVar(IT begin, IT end, DEST& to) {
|
|
|
|
|
for (auto it = begin; it != end; it++)
|
|
|
|
|
if (*it && (*it)->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
|
|
|
|
|
to.insert(*it);
|
2024-01-14 13:26:21 +03:00
|
|
|
}
|
2023-09-14 19:43:13 +03:00
|
|
|
|
2024-01-09 18:13:56 +03:00
|
|
|
void getUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr,
|
|
|
|
|
std::set<SAPFOR::Argument*>& use, std::set<SAPFOR::Argument*>& def,
|
2024-01-12 16:11:21 +03:00
|
|
|
std::vector<SAPFOR::Argument*>& formal_parameters, std::vector<LIVE_VARIABLES::LiveDeadVarsForCall>& fcalls,
|
2024-04-10 22:03:27 +03:00
|
|
|
std::vector<SAPFOR::Argument*>& arg_stack, int& arg_stack_index, int& arg_stack_size,
|
|
|
|
|
bool& last_stack_op,
|
2024-01-09 18:13:56 +03:00
|
|
|
std::string& fName, const std::map<std::string, FuncInfo*>& funcByName, bool interprocedural);
|
|
|
|
|
|
2023-09-14 19:43:13 +03:00
|
|
|
void runLiveVariableAnalysis(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph_for_project);
|
|
|
|
|
|
|
|
|
|
void doDumpLive(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph_for_project);
|
|
|
|
|
|
|
|
|
|
bool joinGlobalsWithParameters(const std::vector<SAPFOR::Argument*>& params,
|
|
|
|
|
const std::map<std::string, std::pair<std::set<int>, std::set<SAPFOR::Argument*>>>& params_and_globals,
|
|
|
|
|
const std::string& func_name, std::set<SAPFOR::Argument*>& result);
|