a better trial
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/IR)
|
||||
file(GLOB IR_SOURCES "*.cpp")
|
||||
|
||||
add_library(IR STATIC ${IR_SOURCES})
|
||||
add_library(IR SHARED ${IR_SOURCES})
|
||||
target_link_libraries(IR PUBLIC ast)
|
@ -1180,6 +1180,7 @@ void IRBuilder::ActuralVisit(ThisExpr_ASTNode *node) {
|
||||
}
|
||||
|
||||
void IRBuilder::ActuralVisit(ParenExpr_ASTNode *node) {
|
||||
node->expr->is_requiring_lvalue = node->is_requiring_lvalue;
|
||||
node->expr->accept(this); // just visit it
|
||||
node->IR_result_full = node->expr->IR_result_full;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/ast)
|
||||
file(GLOB AST_SOURCES "*.cpp")
|
||||
add_library(ast STATIC ${AST_SOURCES})
|
||||
add_library(ast SHARED ${AST_SOURCES})
|
||||
target_include_directories(ast PUBLIC /usr/include/antlr4-runtime/)
|
||||
target_include_directories(ast PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../semantic/antlr-generated)
|
||||
target_link_libraries(ast PUBLIC antlr4-runtime)
|
@ -45,11 +45,13 @@ int main(int argc, char **argv) {
|
||||
if (!optimize_all) {
|
||||
GenerateNaiveASM(fout, IR);
|
||||
} else {
|
||||
// IR->RecursivePrint(std::cerr);
|
||||
auto IR_with_out_allocas = Mem2Reg(IR);
|
||||
// IR_with_out_allocas->RecursivePrint(fout);
|
||||
// IR_with_out_allocas->RecursivePrint(std::cerr);
|
||||
auto IR_with_out_phis = PhiEliminate(IR_with_out_allocas);
|
||||
// IR_with_out_phis->RecursivePrint(fout);
|
||||
// IR_with_out_phis->RecursivePrint(std::cerr);
|
||||
auto alloced_code = RegAlloc(IR_with_out_phis);
|
||||
// alloced_code->RecursivePrint(std::cerr);
|
||||
OptBackend::GenerateOptASM(fout, alloced_code);
|
||||
}
|
||||
} catch (const SemanticError &err) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/naivebackend)
|
||||
|
||||
file(GLOB NAIVE_BACKEND_SOURCES "*.cpp")
|
||||
add_library(naivebackend STATIC ${NAIVE_BACKEND_SOURCES})
|
||||
add_library(naivebackend SHARED ${NAIVE_BACKEND_SOURCES})
|
||||
target_link_libraries(naivebackend PUBLIC ast)
|
@ -1,5 +1,5 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/opt)
|
||||
|
||||
file(GLOB NAIVE_BACKEND_SOURCES "*.cpp")
|
||||
add_library(opt STATIC ${NAIVE_BACKEND_SOURCES})
|
||||
add_library(opt SHARED ${NAIVE_BACKEND_SOURCES})
|
||||
target_link_libraries(opt PUBLIC ast)
|
@ -1,7 +1,8 @@
|
||||
#include "cfg.h"
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
||||
CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func) {
|
||||
CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func, bool remove_poison_entry) {
|
||||
CFGType res;
|
||||
if (func->init_block) {
|
||||
res.label_to_block[func->init_block->label_full] = func->init_block.get();
|
||||
@ -39,5 +40,35 @@ CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func) {
|
||||
}
|
||||
}
|
||||
res.corresponding_func = func.get();
|
||||
bool need_rebuild = false;
|
||||
if (remove_poison_entry) {
|
||||
auto tmp = func->basic_blocks;
|
||||
func->basic_blocks.clear();
|
||||
std::queue<CFGNodeType *> Q;
|
||||
std::unordered_set<CFGNodeType *> visited;
|
||||
Q.push(res.entry);
|
||||
visited.insert(res.entry);
|
||||
while (Q.size() > 0) {
|
||||
auto cur = Q.front();
|
||||
Q.pop();
|
||||
for (auto succ : cur->successors) {
|
||||
if (visited.find(succ) == visited.end()) {
|
||||
visited.insert(succ);
|
||||
Q.push(succ);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto block : tmp) {
|
||||
auto node = res.block_to_node[block.get()];
|
||||
if (visited.find(node) == visited.end()) {
|
||||
need_rebuild = true;
|
||||
continue;
|
||||
}
|
||||
func->basic_blocks.push_back(block);
|
||||
}
|
||||
}
|
||||
if (need_rebuild) {
|
||||
res = BuildCFGForFunction(func, false);
|
||||
}
|
||||
return res;
|
||||
}
|
@ -57,6 +57,8 @@ ConfGraph BuildConfGraph(CFGType &cfg) {
|
||||
if (auto move_act = std::dynamic_pointer_cast<opt::MoveInstruct>(act)) {
|
||||
if (!VRegCheck(move_act->src_full)) continue;
|
||||
if (cfg.var_to_id.find(move_act->src_full) == cfg.var_to_id.end()) {
|
||||
move_act->src_full = "0";
|
||||
continue;
|
||||
move_act->RecursivePrint(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
throw std::runtime_error("move_act->src_full not found in var_to_id");
|
||||
@ -457,7 +459,8 @@ bool ConductColoring(std::shared_ptr<FunctionDefItem> src, CFGType &cfg, ConfGra
|
||||
size_t round_counter = 0;
|
||||
do {
|
||||
// std::cerr << std::endl << "\n\na new round begins " << ++round_counter << std::endl;
|
||||
// std::cerr << "confgraph.low_degree_and_not_move_related.size()=" << confgraph.low_degree_and_not_move_related.size()
|
||||
// std::cerr << "confgraph.low_degree_and_not_move_related.size()=" <<
|
||||
// confgraph.low_degree_and_not_move_related.size()
|
||||
// << std::endl;
|
||||
// std::cerr << "confgraph.pending_moves.size()=" << confgraph.pending_moves.size() << std::endl;
|
||||
// std::cerr << "confgraph.low_degree_and_move_related.size()=" << confgraph.low_degree_and_move_related.size()
|
||||
|
@ -290,7 +290,7 @@ std::shared_ptr<ModuleItem> Mem2Reg(std::shared_ptr<ModuleItem> src) {
|
||||
auto res = src;
|
||||
for (auto &func : res->function_defs) {
|
||||
// func = std::make_shared<FunctionDefItem>(*func);
|
||||
auto cfg = BuildCFGForFunction(func);
|
||||
auto cfg = BuildCFGForFunction(func, true);
|
||||
ConductMem2RegForFunction(func, cfg);
|
||||
}
|
||||
return res;
|
||||
|
@ -368,7 +368,7 @@ void ConductRegAllocForFunction(std::shared_ptr<FunctionDefItem> func) {
|
||||
} while (ConductColoring(func, cfg, confgraph));
|
||||
TranslateColorResult(func, cfg, confgraph);
|
||||
RemoveCallingConventionKeeper(func, cfg, confgraph);
|
||||
func->RecursivePrint(std::cerr);
|
||||
// func->RecursivePrint(std::cerr);
|
||||
}
|
||||
|
||||
std::shared_ptr<ModuleItem> RegAlloc(std::shared_ptr<ModuleItem> src) {
|
||||
|
@ -2,8 +2,8 @@ include_directories(/usr/include/antlr4-runtime/)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/semantic)
|
||||
file(GLOB ANLTR_SOURCES "antlr-generated/*.cpp")
|
||||
file(GLOB SEMANTIC_SOURCES "*.cpp")
|
||||
add_library(mx-antlr STATIC ${ANLTR_SOURCES})
|
||||
add_library(semantic STATIC ${SEMANTIC_SOURCES})
|
||||
add_library(mx-antlr SHARED ${ANLTR_SOURCES})
|
||||
add_library(semantic SHARED ${SEMANTIC_SOURCES})
|
||||
target_include_directories(semantic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/antlr-generated)
|
||||
target_include_directories(semantic PUBLIC /usr/include/antlr4-runtime/)
|
||||
target_link_libraries(mx-antlr PUBLIC antlr4-runtime)
|
||||
|
Reference in New Issue
Block a user