like this form better

This commit is contained in:
Simone
2023-12-27 14:50:34 +01:00
parent 9d8ecdc953
commit 52914d9b78
2 changed files with 20 additions and 11 deletions

View File

@@ -1,5 +1,7 @@
#include <IR.hpp> #include <IR.hpp>
#include <fmt/format.h> #include <fmt/format.h>
#include <set>
#include <algorithm>
namespace n64 { namespace n64 {
template <> struct fmt::formatter<Entry> : formatter<string_view> { template <> struct fmt::formatter<Entry> : formatter<string_view> {
@@ -177,8 +179,15 @@ void IR::push(const Entry& e) {
code.push_back(e); code.push_back(e);
} }
void IR::dead_code_elimination(std::vector<Entry>& code_) { std::vector<Entry> IR::constant_propagation(std::vector<Entry>& code_) {
for(const auto& i : code) { std::vector<Entry> optimized{};
return optimized;
}
std::vector<Entry> IR::dead_code_elimination(std::vector<Entry>& code_) {
std::vector<Entry> optimized{};
for(const auto& i : code_) {
bool isOp1Reg = i.op1.isReg(); bool isOp1Reg = i.op1.isReg();
bool isOp2Reg = i.op2.isReg(); bool isOp2Reg = i.op2.isReg();
bool isDstReg = i.dst.isReg(); bool isDstReg = i.dst.isReg();
@@ -200,21 +209,20 @@ void IR::dead_code_elimination(std::vector<Entry>& code_) {
} }
} }
code_.push_back(i); optimized.push_back(i);
} }
return optimized;
} }
void IR::optimize() { void IR::optimize() {
std::vector<Entry> optimized{}; std::vector<Entry> optimized{};
dead_code_elimination(optimized); while (optimized.size() < code.size()) {
optimized = dead_code_elimination(code);
if(optimized.size() == code.size()) { //optimized = constant_propagation(optimized);
return;
}
code = optimized; code = optimized;
optimize(); }
} }
void IR::print() { void IR::print() {

View File

@@ -90,7 +90,8 @@ struct IR {
void print(); void print();
void optimize(); void optimize();
private: private:
void dead_code_elimination(std::vector<Entry>&); std::vector<Entry> constant_propagation(std::vector<Entry>&);
std::vector<Entry> dead_code_elimination(std::vector<Entry>&);
std::vector<Entry> code{}; std::vector<Entry> code{};
}; };
} }