finish live analysis
This commit is contained in:
@ -365,9 +365,7 @@ class SelectItem : public ActionItem {
|
||||
}
|
||||
};
|
||||
class FunctionDefItem : public LLVMIRItemBase {
|
||||
friend class IRBuilder;
|
||||
friend void GenerateNaiveASM(std::ostream &os, std::shared_ptr<ModuleItem> prog);
|
||||
friend class CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func);
|
||||
public:
|
||||
LLVMType return_type;
|
||||
std::string func_name_raw;
|
||||
std::vector<LLVMType> args;
|
||||
@ -375,7 +373,6 @@ class FunctionDefItem : public LLVMIRItemBase {
|
||||
std::shared_ptr<BlockItem> init_block;
|
||||
std::vector<std::shared_ptr<BlockItem>> basic_blocks;
|
||||
|
||||
public:
|
||||
FunctionDefItem() = default;
|
||||
void RecursivePrint(std::ostream &os) const {
|
||||
os << "define ";
|
||||
|
@ -17,6 +17,11 @@ class CFGNodeType {
|
||||
CFGNodeType *idom;
|
||||
std::vector<CFGNodeType *> successors_in_dom_tree;
|
||||
CFGNodeCollection dom_frontier;
|
||||
|
||||
std::vector<size_t> in_active_vars;
|
||||
std::vector<size_t> out_active_vars;
|
||||
std::vector<size_t> use_vars;
|
||||
std::vector<size_t> def_vars;
|
||||
};
|
||||
|
||||
class CFGType {
|
||||
@ -27,9 +32,100 @@ class CFGType {
|
||||
std::unordered_map<std::string, BlockItem *> label_to_block;
|
||||
};
|
||||
|
||||
CFGNodeCollection GetCFGNodeCollectionsIntersection(const CFGNodeCollection &a, const CFGNodeCollection &b);
|
||||
CFGNodeCollection GetCFGNodeCollectionsUnion(const CFGNodeCollection &a, const CFGNodeCollection &b);
|
||||
CFGNodeCollection GetCFGNodeCollectionsDifference(const CFGNodeCollection &a, const CFGNodeCollection &b);
|
||||
bool CFGNodeCollectionIsSame(const CFGNodeCollection &a, const CFGNodeCollection &b);
|
||||
template <typename Container, typename Compare = std::less<typename Container::value_type>>
|
||||
Container GetCollectionsIntersection(const Container &a, const Container &b, Compare comp = Compare()) {
|
||||
Container result;
|
||||
auto ita = a.begin();
|
||||
auto itb = b.begin();
|
||||
|
||||
while (ita != a.end() && itb != b.end()) {
|
||||
if (comp(*ita, *itb)) {
|
||||
++ita;
|
||||
} else if (comp(*itb, *ita)) {
|
||||
++itb;
|
||||
} else {
|
||||
result.push_back(*ita);
|
||||
++ita;
|
||||
++itb;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Container, typename Compare = std::less<typename Container::value_type>>
|
||||
Container GetCollectionsUnion(const Container &a, const Container &b, Compare comp = Compare()) {
|
||||
Container result;
|
||||
auto ita = a.begin();
|
||||
auto itb = b.begin();
|
||||
|
||||
while (ita != a.end() && itb != b.end()) {
|
||||
if (comp(*ita, *itb)) {
|
||||
result.push_back(*ita);
|
||||
++ita;
|
||||
} else if (comp(*itb, *ita)) {
|
||||
result.push_back(*itb);
|
||||
++itb;
|
||||
} else {
|
||||
result.push_back(*ita);
|
||||
++ita;
|
||||
++itb;
|
||||
}
|
||||
}
|
||||
|
||||
while (ita != a.end()) {
|
||||
result.push_back(*ita);
|
||||
++ita;
|
||||
}
|
||||
|
||||
while (itb != b.end()) {
|
||||
result.push_back(*itb);
|
||||
++itb;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Container, typename Compare = std::less<typename Container::value_type>>
|
||||
Container GetCollectionsDifference(const Container &a, const Container &b, Compare comp = Compare()) {
|
||||
Container result;
|
||||
auto ita = a.begin();
|
||||
auto itb = b.begin();
|
||||
|
||||
while (ita != a.end() && itb != b.end()) {
|
||||
if (comp(*ita, *itb)) {
|
||||
result.push_back(*ita);
|
||||
++ita;
|
||||
} else if (comp(*itb, *ita)) {
|
||||
++itb;
|
||||
} else {
|
||||
++ita;
|
||||
++itb;
|
||||
}
|
||||
}
|
||||
|
||||
while (ita != a.end()) {
|
||||
result.push_back(*ita);
|
||||
++ita;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Container, typename Compare = std::less<typename Container::value_type>>
|
||||
bool GetCollectionsIsSame(const Container &a, const Container &b, Compare comp = Compare()) {
|
||||
auto ita = a.begin();
|
||||
auto itb = b.begin();
|
||||
|
||||
while (ita != a.end() && itb != b.end()) {
|
||||
if (comp(*ita, *itb) || comp(*itb, *ita)) {
|
||||
return false;
|
||||
}
|
||||
++ita;
|
||||
++itb;
|
||||
}
|
||||
|
||||
return ita == a.end() && itb == b.end();
|
||||
}
|
||||
|
||||
CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func);
|
4
include/opt/liveanalysis.h
Normal file
4
include/opt/liveanalysis.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "cfg.h"
|
||||
|
||||
void LiveAnalysis(CFGType &cfg);
|
@ -8,11 +8,10 @@ class MoveInstruct : public ActionItem {
|
||||
std::string src_full;
|
||||
std::string dest_full;
|
||||
MoveInstruct() = default;
|
||||
void RecursivePrint(std::ostream &os) const {
|
||||
void RecursivePrint([[maybe_unused]] std::ostream &os) const {
|
||||
throw std::runtime_error("Move instruction is not an actual LLVM IR instruction");
|
||||
}
|
||||
};
|
||||
} // namespace opt
|
||||
|
||||
|
||||
std::shared_ptr<ModuleItem> PhiEliminate(std::shared_ptr<ModuleItem> src);
|
@ -1,2 +1,5 @@
|
||||
#pragma once
|
||||
#include "phieliminate.h"
|
||||
#include "liveanalysis.h"
|
||||
#include "phieliminate.h"
|
||||
|
||||
std::shared_ptr<ModuleItem> RegAlloc(std::shared_ptr<ModuleItem> src);
|
Reference in New Issue
Block a user