fixed code style, moved dom tree building to IR
This commit is contained in:
@@ -1149,6 +1149,16 @@ map<FuncInfo*, vector<BBlock*>> buildCFG(const map<string, CommonBlock*>& common
|
||||
if (settings.withRD)
|
||||
buildReachingDefs(result, settings);
|
||||
|
||||
if (settings.withDominators)
|
||||
{
|
||||
auto t = high_resolution_clock::now();
|
||||
for (auto& [func, bblocks] : result)
|
||||
SAPFOR::buildDominatorTree(bblocks);
|
||||
|
||||
auto msec = duration_cast<milliseconds>(high_resolution_clock::now() - t).count();
|
||||
__spf_print(1, "dominator build time is %.3f sec\n", msec / 1000.);
|
||||
}
|
||||
|
||||
if (SgFile::switchToFile(oldFile) == -1)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "IR.h"
|
||||
#include "IR_domTree.h"
|
||||
|
||||
namespace SAPFOR
|
||||
{
|
||||
@@ -24,7 +25,7 @@ namespace SAPFOR
|
||||
|
||||
std::vector<BasicBlock*> next;
|
||||
std::vector<BasicBlock*> prev;
|
||||
BasicBlock* idom{};
|
||||
BasicBlock* directDominator = NULL;
|
||||
//reaching definition
|
||||
std::map<SAPFOR::Argument*, std::set<int>> RD_in, RD_out;
|
||||
|
||||
@@ -34,6 +35,7 @@ namespace SAPFOR
|
||||
bool addLive(const std::map<SAPFOR::Argument*, std::vector<SAPFOR::BasicBlock*>>& to_add, bool in);
|
||||
std::map<SAPFOR::Argument*, std::vector<SAPFOR::BasicBlock*>> getLive(bool in) const;
|
||||
bool removeLive(SAPFOR::Argument* to_remove, bool in);
|
||||
|
||||
public:
|
||||
BasicBlock() { num = lastNumBlock++; }
|
||||
BasicBlock(IR_Block* item);
|
||||
@@ -42,7 +44,7 @@ namespace SAPFOR
|
||||
void addInstruction(IR_Block* item);
|
||||
void addPrev(BasicBlock* prev_) { prev.push_back(prev_); }
|
||||
void addNext(BasicBlock* next_) { next.push_back(next_); }
|
||||
void setIdom(BasicBlock* idom_) { idom = idom_; }
|
||||
void setDom(BasicBlock* dom) { directDominator = dom; }
|
||||
|
||||
int removePrev(BasicBlock* removed);
|
||||
int removeNext(BasicBlock* removed);
|
||||
@@ -70,7 +72,16 @@ namespace SAPFOR
|
||||
const std::vector<IR_Block*>& getInstructions() const { return instructions; }
|
||||
const std::vector<BasicBlock*>& getNext() const { return next; }
|
||||
const std::vector<BasicBlock*>& getPrev() const { return prev; }
|
||||
BasicBlock* getIdom() const { return idom; }
|
||||
BasicBlock* getDom() const
|
||||
{
|
||||
if (!directDominator)
|
||||
{
|
||||
__spf_print(1, "%s\n", "the dominator tree was built with an error or was not built at all");
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
|
||||
return directDominator;
|
||||
}
|
||||
|
||||
/*
|
||||
* FOR LIVE ANALYSIS
|
||||
@@ -107,13 +118,15 @@ namespace SAPFOR
|
||||
bool withDVM = false;
|
||||
bool withCallsInBlocks = false; // separate each F_CALL to own BasicBlock
|
||||
bool withCallFrom = true;
|
||||
bool withDominators = true;
|
||||
|
||||
explicit CFG_Settings(int) { }
|
||||
|
||||
explicit CFG_Settings(bool atLeastOneIterInLoop = false, bool withRD = true, bool withRegisters = false,
|
||||
bool withDVM = false, bool withSPF = false, bool withCallsInBlocks = false, bool withCallFrom = true) :
|
||||
bool withDVM = false, bool withSPF = false, bool withCallsInBlocks = false,
|
||||
bool withCallFrom = true, bool withDominators = true) :
|
||||
atLeastOneIterInLoop(atLeastOneIterInLoop), withRD(withRD), withRegisters(withRegisters), withDVM(withDVM), withSPF(withSPF),
|
||||
withCallsInBlocks(withCallsInBlocks), withCallFrom(withCallFrom)
|
||||
withCallsInBlocks(withCallsInBlocks), withCallFrom(withCallFrom), withDominators(withDominators)
|
||||
{ }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "CFGraph.h"
|
||||
#include "../Utils/CommonBlock.h"
|
||||
#include "../GraphCall/graph_calls.h"
|
||||
|
||||
namespace SAPFOR
|
||||
{
|
||||
|
||||
35
src/CFGraph/IR_domTree.h
Normal file
35
src/CFGraph/IR_domTree.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "CFGraph.h"
|
||||
|
||||
// Lengauer, Thomas. A fast algorithm for finding dominators in a flowgraph / Thomas Lengauer, Robert Endre Tarjan
|
||||
// ACM Transactions on Programming Languages and Systems (TOPLAS). <20> 1979. <20> Vol. 1, no. 1. <20> Pp. 121<32>141.
|
||||
|
||||
namespace SAPFOR {
|
||||
|
||||
class BasicBlock;
|
||||
|
||||
class DominatorFinder {
|
||||
private:
|
||||
BasicBlock* entry;
|
||||
std::vector<BasicBlock*> vertices;
|
||||
std::unordered_map<BasicBlock*, int> dfs_num;
|
||||
std::vector<int> parent, semi, vertex, ancestor, label;
|
||||
std::vector<std::vector<int>> bucket;
|
||||
int n;
|
||||
|
||||
void DFS(BasicBlock* v, int parent_num);
|
||||
void Compress(int v);
|
||||
int Eval(int v);
|
||||
void Link(int v, int w);
|
||||
|
||||
public:
|
||||
DominatorFinder(std::vector<BasicBlock*>& blocks);
|
||||
};
|
||||
|
||||
void buildDominatorTree(std::vector<BasicBlock*>& blocks);
|
||||
}
|
||||
Reference in New Issue
Block a user