updates template with fcsr check, adds extra braces on If Statements

This commit is contained in:
Eyck-Alexander Jentzsch 2024-08-14 14:32:58 +02:00
parent 4a19e27926
commit efc11d87a5
2 changed files with 42 additions and 6 deletions

View File

@ -37,7 +37,9 @@
#include <iss/llvm/vm_base.h> #include <iss/llvm/vm_base.h>
#include <util/logging.h> #include <util/logging.h>
#include <iss/instruction_decoder.h> #include <iss/instruction_decoder.h>
<%def fcsr = registers.find {it.name=='FCSR'}
if(fcsr != null) {%>
#include <vm/fp_functions.h><%}%>
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
@ -83,7 +85,9 @@ protected:
using vm_base<ARCH>::get_reg_ptr; using vm_base<ARCH>::get_reg_ptr;
inline const char *name(size_t index){return traits::reg_aliases.at(index);} 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 <typename T> inline ConstantInt *size(T type) { template <typename T> inline ConstantInt *size(T type) {
return ConstantInt::get(getContext(), APInt(32, type->getType()->getScalarSizeInBits())); return ConstantInt::get(getContext(), APInt(32, type->getType()->getScalarSizeInBits()));
} }
@ -131,7 +135,9 @@ protected:
auto sign_mask = 1ULL<<(W-1); auto sign_mask = 1ULL<<(W-1);
return (from & mask) | ((from & sign_mask) ? ~mask : 0); return (from & mask) | ((from & sign_mask) ? ~mask : 0);
} }
<%functions.each{ it.eachLine { %>
${it}<%}%>
<%}%>
private: private:
/**************************************************************************** /****************************************************************************
* start opcode definitions * start opcode definitions

View File

@ -516,6 +516,7 @@ private:
this->gen_ext(this->gen_const(32,addr_mask), 64,false)) this->gen_ext(this->gen_const(32,addr_mask), 64,false))
), ),
32, true); 32, true);
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_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); 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.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -585,6 +587,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_EQ, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_EQ,
@ -605,6 +608,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -648,6 +652,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE,
@ -668,6 +673,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -711,6 +717,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_SLT, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_SLT,
@ -735,6 +742,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -778,6 +786,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_SGE, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_SGE,
@ -802,6 +811,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -845,6 +855,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_ULT, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_ULT,
@ -865,6 +876,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -908,6 +920,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_UGE, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_UGE,
@ -928,6 +941,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -3184,7 +3198,8 @@ private:
this->gen_reg_load(traits::X0+ rs1), 32,true); this->gen_reg_load(traits::X0+ rs1), 32,true);
auto divisor =this->gen_ext( auto divisor =this->gen_ext(
this->gen_reg_load(traits::X0+ rs2), 32,true); 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_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); 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, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE,
@ -3194,6 +3209,7 @@ private:
this->builder.SetInsertPoint(bb_then); this->builder.SetInsertPoint(bb_then);
{ {
auto MMIN =((uint32_t)1)<<(static_cast<uint32_t>(traits::XLEN)-1); auto MMIN =((uint32_t)1)<<(static_cast<uint32_t>(traits::XLEN)-1);
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_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); 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.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_else); this->builder.SetInsertPoint(bb_else);
@ -3238,6 +3255,7 @@ private:
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
} }
}
} }
bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk);
auto returnValue = std::make_tuple(CONT,bb); auto returnValue = std::make_tuple(CONT,bb);
@ -3280,6 +3298,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_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); 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.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk);
auto returnValue = std::make_tuple(CONT,bb); auto returnValue = std::make_tuple(CONT,bb);
@ -3351,6 +3371,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_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); auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge);
@ -3361,6 +3382,7 @@ private:
this->builder.SetInsertPoint(bb_then); this->builder.SetInsertPoint(bb_then);
{ {
auto MMIN =(uint32_t)1<<(static_cast<uint32_t>(traits::XLEN)-1); auto MMIN =(uint32_t)1<<(static_cast<uint32_t>(traits::XLEN)-1);
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_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); 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.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_else); this->builder.SetInsertPoint(bb_else);
@ -3413,6 +3436,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk);
auto returnValue = std::make_tuple(CONT,bb); auto returnValue = std::make_tuple(CONT,bb);
@ -3455,6 +3479,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk); 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_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); 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.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
} }
bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk);
auto returnValue = std::make_tuple(CONT,bb); auto returnValue = std::make_tuple(CONT,bb);
@ -4324,6 +4350,7 @@ private:
this->gen_instr_prologue(); this->gen_instr_prologue();
/*generate behavior*/ /*generate behavior*/
this->builder.CreateStore(this->gen_const(32U, static_cast<int>(NO_JUMP)), get_reg_ptr(traits::LAST_BRANCH), false); this->builder.CreateStore(this->gen_const(32U, static_cast<int>(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_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_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_EQ, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_EQ,
@ -4338,6 +4365,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -4375,6 +4403,7 @@ private:
this->gen_instr_prologue(); this->gen_instr_prologue();
/*generate behavior*/ /*generate behavior*/
this->builder.CreateStore(this->gen_const(32U, static_cast<int>(NO_JUMP)), get_reg_ptr(traits::LAST_BRANCH), false); this->builder.CreateStore(this->gen_const(32U, static_cast<int>(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_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_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE, this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE,
@ -4389,6 +4418,7 @@ private:
} }
this->builder.CreateBr(bb_merge); this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge); this->builder.SetInsertPoint(bb_merge);
}
bb = this->leave_blk; bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr); auto returnValue = std::make_tuple(BRANCH,nullptr);