DataFlow improvements #22

Merged
Alexander_KS merged 2 commits from dead_code_removing into master 2024-01-13 12:19:22 +00:00
6 changed files with 21 additions and 21 deletions

View File

@@ -9,8 +9,8 @@
#include "../CFGraph.h" #include "../CFGraph.h"
#include "../IR.h" #include "../IR.h"
template <class DataType, class NodeType> template <class NodeType>
class BackwardDataFlowAnalysis : public DataFlowAnalysis<DataType, NodeType> { class BackwardDataFlowAnalysis : public DataFlowAnalysis<NodeType> {
std::vector<SAPFOR::BasicBlock*> reorderSequence(const std::vector<SAPFOR::BasicBlock*>& blocks, std::vector<SAPFOR::BasicBlock*> reorderSequence(const std::vector<SAPFOR::BasicBlock*>& blocks,
const std::set<SAPFOR::BasicBlock*> back_edge_sources); const std::set<SAPFOR::BasicBlock*> back_edge_sources);
public: public:

View File

@@ -13,9 +13,9 @@
/* Note: this file should be included in backward_data_flow.h to provide template definitions */ /* Note: this file should be included in backward_data_flow.h to provide template definitions */
// minimizes the number of blocks beween the ends of back edges // minimizes the number of blocks beween the ends of back edges
template <class DataType, class NodeType> template <class NodeType>
std::vector<SAPFOR::BasicBlock*> std::vector<SAPFOR::BasicBlock*>
BackwardDataFlowAnalysis<DataType, NodeType>::reorderSequence(const std::vector<SAPFOR::BasicBlock*>& blocks, BackwardDataFlowAnalysis<NodeType>::reorderSequence(const std::vector<SAPFOR::BasicBlock*>& blocks,
const std::set<SAPFOR::BasicBlock*> back_edge_sources) const std::set<SAPFOR::BasicBlock*> back_edge_sources)
{ {
std::vector<SAPFOR::BasicBlock*> res = { }; std::vector<SAPFOR::BasicBlock*> res = { };
@@ -40,8 +40,8 @@ BackwardDataFlowAnalysis<DataType, NodeType>::reorderSequence(const std::vector<
return res; return res;
} }
template <class DataType, class NodeType> template <class NodeType>
void BackwardDataFlowAnalysis<DataType, NodeType>::fit(const std::vector<SAPFOR::BasicBlock*>& blocks) void BackwardDataFlowAnalysis<NodeType>::fit(const std::vector<SAPFOR::BasicBlock*>& blocks)
{ {
std::set<std::pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>> back_edges = {}; std::set<std::pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>> back_edges = {};
@@ -65,21 +65,21 @@ void BackwardDataFlowAnalysis<DataType, NodeType>::fit(const std::vector<SAPFOR:
std::reverse(blocks_sorted.begin(), blocks_sorted.end()); std::reverse(blocks_sorted.begin(), blocks_sorted.end());
nodes.clear(); this->nodes.clear();
std::map<SAPFOR::BasicBlock*, NodeType*> node_by_block; std::map<SAPFOR::BasicBlock*, NodeType*> node_by_block;
for (auto block : blocks_sorted) for (auto block : blocks_sorted)
{ {
NodeType* node = createNode(block); NodeType* node = this->createNode(block);
nodes.push_back(node); this->nodes.push_back(node);
node_by_block[block] = node; node_by_block[block] = node;
} }
int nodes_size = nodes.size(); int nodes_size = this->nodes.size();
for (int i = 0; i < nodes_size; i++) for (int i = 0; i < nodes_size; i++)
{ {
NodeType* node = nodes[i]; NodeType* node = this->nodes[i];
auto back_edges_by_src_it = back_edges_by_src.find(node->getBlock()); auto back_edges_by_src_it = back_edges_by_src.find(node->getBlock());
if (back_edges_by_src_it != back_edges_by_src.end()) if (back_edges_by_src_it != back_edges_by_src.end())

View File

@@ -49,7 +49,7 @@ public:
void setBlock(SAPFOR::BasicBlock* b) { bb = b; } void setBlock(SAPFOR::BasicBlock* b) { bb = b; }
}; };
template <class DataType, class NodeType> template <class NodeType>
class DataFlowAnalysis { class DataFlowAnalysis {
protected: protected:
std::vector<NodeType*> nodes; std::vector<NodeType*> nodes;

View File

@@ -67,8 +67,8 @@ void DataFlowAnalysisNode<DataType>::doStep()
/* definitions for DataFlowAnalysis class */ /* definitions for DataFlowAnalysis class */
template <class DataType, class NodeType> template <class NodeType>
void DataFlowAnalysis<DataType, NodeType>::analyze() { void DataFlowAnalysis<NodeType>::analyze() {
auto curr = 0; auto curr = 0;
auto stop = nodes.size(); auto stop = nodes.size();
@@ -103,10 +103,10 @@ void DataFlowAnalysis<DataType, NodeType>::analyze() {
} }
} }
template <class DataType, class NodeType> template <class NodeType>
DataFlowAnalysis<DataType, NodeType>::~DataFlowAnalysis() DataFlowAnalysis<NodeType>::~DataFlowAnalysis()
{ {
for (DataFlowAnalysisNode<DataType>* node : nodes) for (NodeType* node : nodes)
delete node; delete node;
nodes.clear(); nodes.clear();

View File

@@ -271,7 +271,7 @@ public:
} }
}; };
class LiveVarAnalysis : public BackwardDataFlowAnalysis<map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>, LiveVarAnalysisNode> { class LiveVarAnalysis : public BackwardDataFlowAnalysis<LiveVarAnalysisNode> {
protected: protected:
vector<SAPFOR::Argument*>& formal_parameters; vector<SAPFOR::Argument*>& formal_parameters;
vector<LiveDeadVarsForCall>& fcalls; vector<LiveDeadVarsForCall>& fcalls;

View File

@@ -298,7 +298,7 @@ public:
const vector<bool>& getResult() { return useful; }; const vector<bool>& getResult() { return useful; };
}; };
class DeadCodeAnalysis : public BackwardDataFlowAnalysis<map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>, DeadCodeAnalysisNode> { class DeadCodeAnalysis : public BackwardDataFlowAnalysis<DeadCodeAnalysisNode> {
protected: protected:
vector<SAPFOR::Argument*>& formal_parameters; vector<SAPFOR::Argument*>& formal_parameters;