From efc11d87a57fb973f5f7e9cefe6d92ec84a22442 Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Wed, 14 Aug 2024 14:32:58 +0200 Subject: [PATCH] updates template with fcsr check, adds extra braces on If Statements --- gen_input/templates/llvm/CORENAME.cpp.gtl | 14 +++++++--- src/vm/llvm/vm_tgc5c.cpp | 34 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/gen_input/templates/llvm/CORENAME.cpp.gtl b/gen_input/templates/llvm/CORENAME.cpp.gtl index 9c90f61..f362493 100644 --- a/gen_input/templates/llvm/CORENAME.cpp.gtl +++ b/gen_input/templates/llvm/CORENAME.cpp.gtl @@ -37,7 +37,9 @@ #include #include #include - +<%def fcsr = registers.find {it.name=='FCSR'} +if(fcsr != null) {%> +#include <%}%> #ifndef FMT_HEADER_ONLY #define FMT_HEADER_ONLY #endif @@ -83,7 +85,9 @@ protected: using vm_base::get_reg_ptr; inline const char *name(size_t index){return traits::reg_aliases.at(index);} - +<%if(fcsr != null) {%> + inline const char *fname(size_t index){return index < 32?name(index+traits::F0):"illegal";} +<%}%> template inline ConstantInt *size(T type) { return ConstantInt::get(getContext(), APInt(32, type->getType()->getScalarSizeInBits())); } @@ -130,8 +134,10 @@ protected: auto mask = (1ULL< + ${it}<%}%> +<%}%> private: /**************************************************************************** * start opcode definitions diff --git a/src/vm/llvm/vm_tgc5c.cpp b/src/vm/llvm/vm_tgc5c.cpp index 4c8b91b..b928011 100644 --- a/src/vm/llvm/vm_tgc5c.cpp +++ b/src/vm/llvm/vm_tgc5c.cpp @@ -130,7 +130,7 @@ protected: auto mask = (1ULL<gen_ext(this->gen_const(32,addr_mask), 64,false)) ), 32, true); + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge); @@ -542,6 +543,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); @@ -585,6 +587,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_EQ, @@ -605,6 +608,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); @@ -648,6 +652,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE, @@ -668,6 +673,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); @@ -711,6 +717,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_SLT, @@ -735,6 +742,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); @@ -778,6 +786,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_SGE, @@ -802,6 +811,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); @@ -845,6 +855,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_ULT, @@ -865,6 +876,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); @@ -908,6 +920,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_UGE, @@ -928,6 +941,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); @@ -3184,7 +3198,8 @@ private: this->gen_reg_load(traits::X0+ rs1), 32,true); auto divisor =this->gen_ext( this->gen_reg_load(traits::X0+ rs2), 32,true); - if(rd!=0){ auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); + if(rd!=0){ { + auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE, @@ -3194,6 +3209,7 @@ private: this->builder.SetInsertPoint(bb_then); { auto MMIN =((uint32_t)1)<<(static_cast(traits::XLEN)-1); + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge); @@ -3227,6 +3243,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_else); @@ -3238,6 +3255,7 @@ private: this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); } + } } bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); @@ -3280,6 +3298,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge); @@ -3309,6 +3328,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); @@ -3351,6 +3371,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge); @@ -3361,6 +3382,7 @@ private: this->builder.SetInsertPoint(bb_then); { auto MMIN =(uint32_t)1<<(static_cast(traits::XLEN)-1); + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge); @@ -3401,6 +3423,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_else); @@ -3413,6 +3436,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); @@ -3455,6 +3479,7 @@ private: this->gen_raise_trap(0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge); @@ -3484,6 +3509,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } } bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); @@ -4324,6 +4350,7 @@ private: this->gen_instr_prologue(); /*generate behavior*/ this->builder.CreateStore(this->gen_const(32U, static_cast(NO_JUMP)), get_reg_ptr(traits::LAST_BRANCH), false); + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_EQ, @@ -4338,6 +4365,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); @@ -4375,6 +4403,7 @@ private: this->gen_instr_prologue(); /*generate behavior*/ this->builder.CreateStore(this->gen_const(32U, static_cast(NO_JUMP)), get_reg_ptr(traits::LAST_BRANCH), false); + { auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge); this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE, @@ -4389,6 +4418,7 @@ private: } this->builder.CreateBr(bb_merge); this->builder.SetInsertPoint(bb_merge); + } bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr);