From fb330cddea6d780b50d0af02db92d88e45e0a137 Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Sat, 18 May 2024 19:33:57 +0200 Subject: [PATCH] llvm passes act --- gen_input/templates/llvm/CORENAME.cpp.gtl | 35 +- src/vm/llvm/vm_tgc5c.cpp | 744 +++++++++++++--------- 2 files changed, 479 insertions(+), 300 deletions(-) diff --git a/gen_input/templates/llvm/CORENAME.cpp.gtl b/gen_input/templates/llvm/CORENAME.cpp.gtl index b6bef39..1b13101 100644 --- a/gen_input/templates/llvm/CORENAME.cpp.gtl +++ b/gen_input/templates/llvm/CORENAME.cpp.gtl @@ -99,16 +99,11 @@ protected: std::tuple gen_single_inst_behavior(virt_addr_t &, unsigned int &, BasicBlock *) override; void gen_leave_behavior(BasicBlock *leave_blk) override; - void gen_raise_trap(uint16_t trap_id, uint16_t cause); - void gen_leave_trap(unsigned lvl); - void gen_wait(unsigned type); - void gen_trap_behavior(BasicBlock *) override; - - void gen_trap_check(BasicBlock *bb); + void gen_instr_epilogue(BasicBlock *bb); inline Value *gen_reg_load(unsigned i, unsigned level = 0) { return this->builder.CreateLoad(this->get_typeptr(i), get_reg_ptr(i), false); @@ -162,20 +157,22 @@ private: /* instruction definitions */<%instructions.eachWithIndex{instr, idx -> %> /* instruction ${idx}: ${instr.name} */ std::tuple __${generator.functionName(instr.name)}(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("${instr.name}_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,${idx}); uint64_t PC = pc.val; <%instr.fields.eachLine{%>${it} <%}%>if(this->disass_enabled){ /* generate console output when executing the command */<%instr.disass.eachLine{%> ${it}<%}%> } + bb->setName(fmt::format("${instr.name}_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,${idx}); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ ${instr.length/8}; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ <%instr.behavior.eachLine{%>${it} <%}%> - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, ${idx}); this->builder.CreateBr(bb); return returnValue; @@ -195,7 +192,7 @@ private: pc = pc + ((instr & 3) == 3 ? 4 : 2); this->gen_raise_trap(0, 2); // illegal instruction trap this->gen_sync(iss::POST_SYNC, instr_descr.size()); - this->gen_trap_check(this->leave_blk); + this->gen_instr_epilogue(this->leave_blk); return std::make_tuple(BRANCH, nullptr); } //decoding functionality @@ -301,18 +298,21 @@ vm_impl::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt, return (this->*f)(pc, instr, this_block); } -template void vm_impl::gen_leave_behavior(BasicBlock *leave_blk) { +template +void vm_impl::gen_leave_behavior(BasicBlock *leave_blk) { this->builder.SetInsertPoint(leave_blk); this->builder.CreateRet(this->builder.CreateLoad(this->get_typeptr(traits::NEXT_PC),get_reg_ptr(traits::NEXT_PC), false)); } -template void vm_impl::gen_raise_trap(uint16_t trap_id, uint16_t cause) { +template +void vm_impl::gen_raise_trap(uint16_t trap_id, uint16_t cause) { auto *TRAP_val = this->gen_const(32, 0x80 << 24 | (cause << 16) | trap_id); this->builder.CreateStore(TRAP_val, get_reg_ptr(traits::TRAP_STATE), true); this->builder.CreateStore(this->gen_const(32U, std::numeric_limits::max()), get_reg_ptr(traits::LAST_BRANCH), false); } -template void vm_impl::gen_leave_trap(unsigned lvl) { +template +void vm_impl::gen_leave_trap(unsigned lvl) { std::vector args{ this->core_ptr, ConstantInt::get(getContext(), APInt(64, lvl)) }; this->builder.CreateCall(this->mod->getFunction("leave_trap"), args); auto *PC_val = this->gen_read_mem(traits::CSR, (lvl << 8) + 0x41, traits::XLEN / 8); @@ -320,12 +320,14 @@ template void vm_impl::gen_leave_trap(unsigned lvl) { this->builder.CreateStore(this->gen_const(32U, std::numeric_limits::max()), get_reg_ptr(traits::LAST_BRANCH), false); } -template void vm_impl::gen_wait(unsigned type) { +template +void vm_impl::gen_wait(unsigned type) { std::vector args{ this->core_ptr, ConstantInt::get(getContext(), APInt(64, type)) }; this->builder.CreateCall(this->mod->getFunction("wait"), args); } -template void vm_impl::gen_trap_behavior(BasicBlock *trap_blk) { +template +void vm_impl::gen_trap_behavior(BasicBlock *trap_blk) { this->builder.SetInsertPoint(trap_blk); this->gen_sync(POST_SYNC, -1); //TODO get right InstrId auto *trap_state_val = this->builder.CreateLoad(this->get_typeptr(traits::TRAP_STATE), get_reg_ptr(traits::TRAP_STATE), true); @@ -338,7 +340,8 @@ template void vm_impl::gen_trap_behavior(BasicBlock *trap_ this->builder.CreateRet(trap_addr_val); } -template inline void vm_impl::gen_trap_check(BasicBlock *bb) { +template +void vm_impl::gen_instr_epilogue(BasicBlock *bb) { auto* target_bb = BasicBlock::Create(this->mod->getContext(), "", this->func, bb); auto *v = this->builder.CreateLoad(this->get_typeptr(traits::TRAP_STATE), get_reg_ptr(traits::TRAP_STATE), true); this->gen_cond_branch(this->builder.CreateICmp( diff --git a/src/vm/llvm/vm_tgc5c.cpp b/src/vm/llvm/vm_tgc5c.cpp index fe03630..58e3c2c 100644 --- a/src/vm/llvm/vm_tgc5c.cpp +++ b/src/vm/llvm/vm_tgc5c.cpp @@ -99,16 +99,11 @@ protected: std::tuple gen_single_inst_behavior(virt_addr_t &, unsigned int &, BasicBlock *) override; void gen_leave_behavior(BasicBlock *leave_blk) override; - void gen_raise_trap(uint16_t trap_id, uint16_t cause); - void gen_leave_trap(unsigned lvl); - void gen_wait(unsigned type); - void gen_trap_behavior(BasicBlock *) override; - - void gen_trap_check(BasicBlock *bb); + void gen_instr_epilogue(BasicBlock *bb); inline Value *gen_reg_load(unsigned i, unsigned level = 0) { return this->builder.CreateLoad(this->get_typeptr(i), get_reg_ptr(i), false); @@ -334,8 +329,6 @@ private: /* instruction definitions */ /* instruction 0: LUI */ std::tuple __lui(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("LUI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,0); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint32_t imm = ((bit_sub<12,20>(instr) << 12)); @@ -351,9 +344,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("LUI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,0); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -367,7 +364,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 0); this->builder.CreateBr(bb); return returnValue; @@ -375,8 +372,6 @@ private: /* instruction 1: AUIPC */ std::tuple __auipc(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("AUIPC_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,1); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint32_t imm = ((bit_sub<12,20>(instr) << 12)); @@ -392,9 +387,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("AUIPC_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,1); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -408,7 +407,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 1); this->builder.CreateBr(bb); return returnValue; @@ -416,8 +415,6 @@ private: /* instruction 2: JAL */ std::tuple __jal(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("JAL_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,2); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint32_t imm = ((bit_sub<12,8>(instr) << 12) | (bit_sub<20,1>(instr) << 11) | (bit_sub<21,10>(instr) << 1) | (bit_sub<31,1>(instr) << 20)); @@ -433,9 +430,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("JAL_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,2); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -456,7 +457,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 2); this->builder.CreateBr(bb); return returnValue; @@ -464,8 +465,6 @@ private: /* instruction 3: JALR */ std::tuple __jalr(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("JALR_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,3); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -482,9 +481,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("JALR_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,3); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -528,7 +531,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 3); this->builder.CreateBr(bb); return returnValue; @@ -536,8 +539,6 @@ private: /* instruction 4: BEQ */ std::tuple __beq(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("BEQ_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,4); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -554,9 +555,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("BEQ_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,4); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -583,7 +588,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 4); this->builder.CreateBr(bb); return returnValue; @@ -591,8 +596,6 @@ private: /* instruction 5: BNE */ std::tuple __bne(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("BNE_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,5); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -609,9 +612,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("BNE_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,5); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -638,7 +645,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 5); this->builder.CreateBr(bb); return returnValue; @@ -646,8 +653,6 @@ private: /* instruction 6: BLT */ std::tuple __blt(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("BLT_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,6); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -664,9 +669,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("BLT_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,6); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -697,7 +706,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 6); this->builder.CreateBr(bb); return returnValue; @@ -705,8 +714,6 @@ private: /* instruction 7: BGE */ std::tuple __bge(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("BGE_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,7); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -723,9 +730,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("BGE_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,7); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -756,7 +767,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 7); this->builder.CreateBr(bb); return returnValue; @@ -764,8 +775,6 @@ private: /* instruction 8: BLTU */ std::tuple __bltu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("BLTU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,8); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -782,9 +791,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("BLTU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,8); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -811,7 +824,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 8); this->builder.CreateBr(bb); return returnValue; @@ -819,8 +832,6 @@ private: /* instruction 9: BGEU */ std::tuple __bgeu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("BGEU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,9); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -837,9 +848,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("BGEU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,9); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -866,7 +881,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 9); this->builder.CreateBr(bb); return returnValue; @@ -874,8 +889,6 @@ private: /* instruction 10: LB */ std::tuple __lb(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("LB_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,10); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -892,9 +905,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("LB_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,10); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -919,7 +936,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 10); this->builder.CreateBr(bb); return returnValue; @@ -927,8 +944,6 @@ private: /* instruction 11: LH */ std::tuple __lh(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("LH_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,11); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -945,9 +960,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("LH_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,11); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -972,7 +991,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 11); this->builder.CreateBr(bb); return returnValue; @@ -980,8 +999,6 @@ private: /* instruction 12: LW */ std::tuple __lw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("LW_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,12); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -998,9 +1015,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("LW_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,12); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1025,7 +1046,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 12); this->builder.CreateBr(bb); return returnValue; @@ -1033,8 +1054,6 @@ private: /* instruction 13: LBU */ std::tuple __lbu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("LBU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,13); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1051,9 +1070,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("LBU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,13); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1076,7 +1099,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 13); this->builder.CreateBr(bb); return returnValue; @@ -1084,8 +1107,6 @@ private: /* instruction 14: LHU */ std::tuple __lhu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("LHU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,14); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1102,9 +1123,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("LHU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,14); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1127,7 +1152,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 14); this->builder.CreateBr(bb); return returnValue; @@ -1135,8 +1160,6 @@ private: /* instruction 15: SB */ std::tuple __sb(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SB_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,15); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1153,9 +1176,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SB_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,15); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1175,7 +1202,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 15); this->builder.CreateBr(bb); return returnValue; @@ -1183,8 +1210,6 @@ private: /* instruction 16: SH */ std::tuple __sh(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SH_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,16); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1201,9 +1226,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SH_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,16); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1223,7 +1252,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 16); this->builder.CreateBr(bb); return returnValue; @@ -1231,8 +1260,6 @@ private: /* instruction 17: SW */ std::tuple __sw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SW_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,17); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5)); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1249,9 +1276,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SW_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,17); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1271,7 +1302,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 17); this->builder.CreateBr(bb); return returnValue; @@ -1279,8 +1310,6 @@ private: /* instruction 18: ADDI */ std::tuple __addi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("ADDI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,18); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1297,9 +1326,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("ADDI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,18); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1318,7 +1351,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 18); this->builder.CreateBr(bb); return returnValue; @@ -1326,8 +1359,6 @@ private: /* instruction 19: SLTI */ std::tuple __slti(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SLTI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,19); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1344,9 +1375,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SLTI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,19); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1367,7 +1402,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 19); this->builder.CreateBr(bb); return returnValue; @@ -1375,8 +1410,6 @@ private: /* instruction 20: SLTIU */ std::tuple __sltiu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SLTIU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,20); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1393,9 +1426,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SLTIU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,20); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1415,7 +1452,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 20); this->builder.CreateBr(bb); return returnValue; @@ -1423,8 +1460,6 @@ private: /* instruction 21: XORI */ std::tuple __xori(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("XORI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,21); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1441,9 +1476,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("XORI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,21); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1460,7 +1499,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 21); this->builder.CreateBr(bb); return returnValue; @@ -1468,8 +1507,6 @@ private: /* instruction 22: ORI */ std::tuple __ori(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("ORI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,22); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1486,9 +1523,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("ORI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,22); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1505,7 +1546,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 22); this->builder.CreateBr(bb); return returnValue; @@ -1513,8 +1554,6 @@ private: /* instruction 23: ANDI */ std::tuple __andi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("ANDI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,23); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1531,9 +1570,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("ANDI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,23); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1550,7 +1593,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 23); this->builder.CreateBr(bb); return returnValue; @@ -1558,8 +1601,6 @@ private: /* instruction 24: SLLI */ std::tuple __slli(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SLLI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,24); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1576,9 +1617,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SLLI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,24); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1595,7 +1640,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 24); this->builder.CreateBr(bb); return returnValue; @@ -1603,8 +1648,6 @@ private: /* instruction 25: SRLI */ std::tuple __srli(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SRLI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,25); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1621,9 +1664,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SRLI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,25); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1640,7 +1687,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 25); this->builder.CreateBr(bb); return returnValue; @@ -1648,8 +1695,6 @@ private: /* instruction 26: SRAI */ std::tuple __srai(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SRAI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,26); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1666,9 +1711,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SRAI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,26); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1688,7 +1737,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 26); this->builder.CreateBr(bb); return returnValue; @@ -1696,8 +1745,6 @@ private: /* instruction 27: ADD */ std::tuple __add(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("ADD_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,27); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1714,9 +1761,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("ADD_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,27); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1735,7 +1786,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 27); this->builder.CreateBr(bb); return returnValue; @@ -1743,8 +1794,6 @@ private: /* instruction 28: SUB */ std::tuple __sub(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SUB_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,28); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1761,9 +1810,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SUB_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,28); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1782,7 +1835,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 28); this->builder.CreateBr(bb); return returnValue; @@ -1790,8 +1843,6 @@ private: /* instruction 29: SLL */ std::tuple __sll(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SLL_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,29); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1808,9 +1859,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SLL_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,29); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1830,7 +1885,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 29); this->builder.CreateBr(bb); return returnValue; @@ -1838,8 +1893,6 @@ private: /* instruction 30: SLT */ std::tuple __slt(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SLT_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,30); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1856,9 +1909,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SLT_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,30); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1880,7 +1937,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 30); this->builder.CreateBr(bb); return returnValue; @@ -1888,8 +1945,6 @@ private: /* instruction 31: SLTU */ std::tuple __sltu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SLTU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,31); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1906,9 +1961,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SLTU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,31); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1928,7 +1987,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 31); this->builder.CreateBr(bb); return returnValue; @@ -1936,8 +1995,6 @@ private: /* instruction 32: XOR */ std::tuple __xor(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("XOR_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,32); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1954,9 +2011,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("XOR_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,32); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -1973,7 +2034,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 32); this->builder.CreateBr(bb); return returnValue; @@ -1981,8 +2042,6 @@ private: /* instruction 33: SRL */ std::tuple __srl(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SRL_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,33); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -1999,9 +2058,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SRL_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,33); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2021,7 +2084,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 33); this->builder.CreateBr(bb); return returnValue; @@ -2029,8 +2092,6 @@ private: /* instruction 34: SRA */ std::tuple __sra(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("SRA_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,34); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2047,9 +2108,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("SRA_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,34); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2072,7 +2137,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 34); this->builder.CreateBr(bb); return returnValue; @@ -2080,8 +2145,6 @@ private: /* instruction 35: OR */ std::tuple __or(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("OR_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,35); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2098,9 +2161,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("OR_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,35); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2117,7 +2184,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 35); this->builder.CreateBr(bb); return returnValue; @@ -2125,8 +2192,6 @@ private: /* instruction 36: AND */ std::tuple __and(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("AND_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,36); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2143,9 +2208,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("AND_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,36); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2162,7 +2231,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 36); this->builder.CreateBr(bb); return returnValue; @@ -2170,8 +2239,6 @@ private: /* instruction 37: FENCE */ std::tuple __fence(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("FENCE_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,37); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2190,16 +2257,20 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("FENCE_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,37); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_write_mem(traits::FENCE, static_cast(traits::fence), this->gen_const(8,(uint8_t)pred<< 4|succ)); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 37); this->builder.CreateBr(bb); return returnValue; @@ -2207,21 +2278,23 @@ private: /* instruction 38: ECALL */ std::tuple __ecall(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("ECALL_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,38); uint64_t PC = pc.val; if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("ECALL_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,38); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_raise_trap(0, 11); bb = this->leave_blk; auto returnValue = std::make_tuple(TRAP,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 38); this->builder.CreateBr(bb); return returnValue; @@ -2229,21 +2302,23 @@ private: /* instruction 39: EBREAK */ std::tuple __ebreak(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("EBREAK_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,39); uint64_t PC = pc.val; if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("EBREAK_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,39); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_raise_trap(0, 3); bb = this->leave_blk; auto returnValue = std::make_tuple(TRAP,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 39); this->builder.CreateBr(bb); return returnValue; @@ -2251,21 +2326,23 @@ private: /* instruction 40: MRET */ std::tuple __mret(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("MRET_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,40); uint64_t PC = pc.val; if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("MRET_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,40); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_leave_trap(3); bb = this->leave_blk; auto returnValue = std::make_tuple(TRAP,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 40); this->builder.CreateBr(bb); return returnValue; @@ -2273,21 +2350,23 @@ private: /* instruction 41: WFI */ std::tuple __wfi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("WFI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,41); uint64_t PC = pc.val; if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("WFI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,41); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_wait(1); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 41); this->builder.CreateBr(bb); return returnValue; @@ -2295,8 +2374,6 @@ private: /* instruction 42: CSRRW */ std::tuple __csrrw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("CSRRW_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,42); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2313,9 +2390,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("CSRRW_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,42); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2338,7 +2419,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 42); this->builder.CreateBr(bb); return returnValue; @@ -2346,8 +2427,6 @@ private: /* instruction 43: CSRRS */ std::tuple __csrrs(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("CSRRS_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,43); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2364,9 +2443,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("CSRRS_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,43); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2390,7 +2473,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 43); this->builder.CreateBr(bb); return returnValue; @@ -2398,8 +2481,6 @@ private: /* instruction 44: CSRRC */ std::tuple __csrrc(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("CSRRC_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,44); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2416,9 +2497,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("CSRRC_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,44); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2442,7 +2527,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 44); this->builder.CreateBr(bb); return returnValue; @@ -2450,8 +2535,6 @@ private: /* instruction 45: CSRRWI */ std::tuple __csrrwi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("CSRRWI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,45); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t zimm = ((bit_sub<15,5>(instr))); @@ -2468,9 +2551,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("CSRRWI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,45); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2488,7 +2575,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 45); this->builder.CreateBr(bb); return returnValue; @@ -2496,8 +2583,6 @@ private: /* instruction 46: CSRRSI */ std::tuple __csrrsi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("CSRRSI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,46); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t zimm = ((bit_sub<15,5>(instr))); @@ -2514,9 +2599,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("CSRRSI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,46); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2539,7 +2628,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 46); this->builder.CreateBr(bb); return returnValue; @@ -2547,8 +2636,6 @@ private: /* instruction 47: CSRRCI */ std::tuple __csrrci(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("CSRRCI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,47); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t zimm = ((bit_sub<15,5>(instr))); @@ -2565,9 +2652,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("CSRRCI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,47); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2590,7 +2681,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 47); this->builder.CreateBr(bb); return returnValue; @@ -2598,8 +2689,6 @@ private: /* instruction 48: FENCE_I */ std::tuple __fence_i(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("FENCE_I_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,48); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2616,16 +2705,20 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("FENCE_I_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,48); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_write_mem(traits::FENCE, static_cast(traits::fencei), this->gen_const(16,imm)); - bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); - auto returnValue = std::make_tuple(CONT,bb); + bb = this->leave_blk; + auto returnValue = std::make_tuple(FLUSH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 48); this->builder.CreateBr(bb); return returnValue; @@ -2633,8 +2726,6 @@ private: /* instruction 49: MUL */ std::tuple __mul(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("MUL_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,49); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2651,9 +2742,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("MUL_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,49); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2681,7 +2776,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 49); this->builder.CreateBr(bb); return returnValue; @@ -2689,8 +2784,6 @@ private: /* instruction 50: MULH */ std::tuple __mulh(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("MULH_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,50); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2707,9 +2800,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("MULH_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,50); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2740,7 +2837,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 50); this->builder.CreateBr(bb); return returnValue; @@ -2748,8 +2845,6 @@ private: /* instruction 51: MULHSU */ std::tuple __mulhsu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("MULHSU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,51); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2766,9 +2861,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("MULHSU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,51); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2798,7 +2897,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 51); this->builder.CreateBr(bb); return returnValue; @@ -2806,8 +2905,6 @@ private: /* instruction 52: MULHU */ std::tuple __mulhu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("MULHU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,52); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2824,9 +2921,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("MULHU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,52); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2855,7 +2956,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 52); this->builder.CreateBr(bb); return returnValue; @@ -2863,8 +2964,6 @@ private: /* instruction 53: DIV */ std::tuple __div(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("DIV_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,53); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2881,9 +2980,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("DIV_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,53); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -2952,7 +3055,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 53); this->builder.CreateBr(bb); return returnValue; @@ -2960,8 +3063,6 @@ private: /* instruction 54: DIVU */ std::tuple __divu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("DIVU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,54); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -2978,9 +3079,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("DIVU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,54); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -3020,7 +3125,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 54); this->builder.CreateBr(bb); return returnValue; @@ -3028,8 +3133,6 @@ private: /* instruction 55: REM */ std::tuple __rem(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("REM_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,55); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -3046,9 +3149,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("REM_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,55); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -3122,7 +3229,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 55); this->builder.CreateBr(bb); return returnValue; @@ -3130,8 +3237,6 @@ private: /* instruction 56: REMU */ std::tuple __remu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("REMU_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,56); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rs1 = ((bit_sub<15,5>(instr))); @@ -3148,9 +3253,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("REMU_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,56); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 4; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rs1>=static_cast(traits::RFS)||rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -3188,7 +3297,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 56); this->builder.CreateBr(bb); return returnValue; @@ -3196,8 +3305,6 @@ private: /* instruction 57: C__ADDI4SPN */ std::tuple __c__addi4spn(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__ADDI4SPN_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,57); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<2,3>(instr))); uint16_t imm = ((bit_sub<5,1>(instr) << 3) | (bit_sub<6,1>(instr) << 2) | (bit_sub<7,4>(instr) << 6) | (bit_sub<11,2>(instr) << 4)); @@ -3213,9 +3320,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__ADDI4SPN_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,57); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(imm) { this->builder.CreateStore( this->gen_ext( @@ -3232,7 +3343,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 57); this->builder.CreateBr(bb); return returnValue; @@ -3240,8 +3351,6 @@ private: /* instruction 58: C__LW */ std::tuple __c__lw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__LW_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,58); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<2,3>(instr))); uint8_t uimm = ((bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 2) | (bit_sub<10,3>(instr) << 3)); @@ -3258,9 +3367,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__LW_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,58); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ auto offs =this->gen_ext( (this->builder.CreateAdd( this->gen_ext(this->gen_reg_load(rs1+ 8+ traits::X0, 0), 64,false), @@ -3277,7 +3390,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 58); this->builder.CreateBr(bb); return returnValue; @@ -3285,8 +3398,6 @@ private: /* instruction 59: C__SW */ std::tuple __c__sw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__SW_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,59); uint64_t PC = pc.val; uint8_t rs2 = ((bit_sub<2,3>(instr))); uint8_t uimm = ((bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 2) | (bit_sub<10,3>(instr) << 3)); @@ -3303,9 +3414,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__SW_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,59); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ auto offs =this->gen_ext( (this->builder.CreateAdd( this->gen_ext(this->gen_reg_load(rs1+ 8+ traits::X0, 0), 64,false), @@ -3320,7 +3435,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 59); this->builder.CreateBr(bb); return returnValue; @@ -3328,8 +3443,6 @@ private: /* instruction 60: C__ADDI */ std::tuple __c__addi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__ADDI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,60); uint64_t PC = pc.val; uint8_t imm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5)); uint8_t rs1 = ((bit_sub<7,5>(instr))); @@ -3345,9 +3458,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__ADDI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,60); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -3366,7 +3483,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 60); this->builder.CreateBr(bb); return returnValue; @@ -3374,21 +3491,23 @@ private: /* instruction 61: C__NOP */ std::tuple __c__nop(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__NOP_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,61); uint64_t PC = pc.val; uint8_t nzimm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5)); if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("C__NOP_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,61); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 61); this->builder.CreateBr(bb); return returnValue; @@ -3396,8 +3515,6 @@ private: /* instruction 62: C__JAL */ std::tuple __c__jal(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__JAL_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,62); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,3>(instr) << 1) | (bit_sub<6,1>(instr) << 7) | (bit_sub<7,1>(instr) << 6) | (bit_sub<8,1>(instr) << 10) | (bit_sub<9,2>(instr) << 8) | (bit_sub<11,1>(instr) << 4) | (bit_sub<12,1>(instr) << 11)); if(this->disass_enabled){ @@ -3412,9 +3529,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__JAL_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,62); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->builder.CreateStore( this->gen_const(32,(uint32_t)(PC+ 2)), get_reg_ptr(1 + traits::X0), false); @@ -3424,7 +3545,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 62); this->builder.CreateBr(bb); return returnValue; @@ -3432,8 +3553,6 @@ private: /* instruction 63: C__LI */ std::tuple __c__li(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__LI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,63); uint64_t PC = pc.val; uint8_t imm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5)); uint8_t rd = ((bit_sub<7,5>(instr))); @@ -3449,9 +3568,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__LI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,63); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -3465,7 +3588,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 63); this->builder.CreateBr(bb); return returnValue; @@ -3473,8 +3596,6 @@ private: /* instruction 64: C__LUI */ std::tuple __c__lui(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__LUI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,64); uint64_t PC = pc.val; uint32_t imm = ((bit_sub<2,5>(instr) << 12) | (bit_sub<12,1>(instr) << 17)); uint8_t rd = ((bit_sub<7,5>(instr))); @@ -3490,9 +3611,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__LUI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,64); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(imm== 0||rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -3504,7 +3629,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 64); this->builder.CreateBr(bb); return returnValue; @@ -3512,8 +3637,6 @@ private: /* instruction 65: C__ADDI16SP */ std::tuple __c__addi16sp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__ADDI16SP_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,65); uint64_t PC = pc.val; uint16_t nzimm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 7) | (bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 4) | (bit_sub<12,1>(instr) << 9)); if(this->disass_enabled){ @@ -3528,9 +3651,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__ADDI16SP_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,65); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(nzimm) { this->builder.CreateStore( this->gen_ext( @@ -3547,7 +3674,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 65); this->builder.CreateBr(bb); return returnValue; @@ -3555,22 +3682,24 @@ private: /* instruction 66: __reserved_clui */ std::tuple ____reserved_clui(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("__reserved_clui_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,66); uint64_t PC = pc.val; uint8_t rd = ((bit_sub<7,5>(instr))); if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("__reserved_clui_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,66); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_raise_trap(0, 2); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 66); this->builder.CreateBr(bb); return returnValue; @@ -3578,8 +3707,6 @@ private: /* instruction 67: C__SRLI */ std::tuple __c__srli(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__SRLI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,67); uint64_t PC = pc.val; uint8_t shamt = ((bit_sub<2,5>(instr))); uint8_t rs1 = ((bit_sub<7,3>(instr))); @@ -3595,9 +3722,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__SRLI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,67); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->builder.CreateStore( this->builder.CreateLShr( this->gen_reg_load(rs1+ 8+ traits::X0, 0), @@ -3607,7 +3738,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 67); this->builder.CreateBr(bb); return returnValue; @@ -3615,8 +3746,6 @@ private: /* instruction 68: C__SRAI */ std::tuple __c__srai(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__SRAI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,68); uint64_t PC = pc.val; uint8_t shamt = ((bit_sub<2,5>(instr))); uint8_t rs1 = ((bit_sub<7,3>(instr))); @@ -3632,9 +3761,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__SRAI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,68); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(shamt){ this->builder.CreateStore( this->gen_ext( (this->builder.CreateAShr( @@ -3662,7 +3795,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 68); this->builder.CreateBr(bb); return returnValue; @@ -3670,8 +3803,6 @@ private: /* instruction 69: C__ANDI */ std::tuple __c__andi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__ANDI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,69); uint64_t PC = pc.val; uint8_t imm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5)); uint8_t rs1 = ((bit_sub<7,3>(instr))); @@ -3687,9 +3818,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__ANDI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,69); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->builder.CreateStore( this->gen_ext( (this->builder.CreateAnd( @@ -3701,7 +3836,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 69); this->builder.CreateBr(bb); return returnValue; @@ -3709,8 +3844,6 @@ private: /* instruction 70: C__SUB */ std::tuple __c__sub(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__SUB_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,70); uint64_t PC = pc.val; uint8_t rs2 = ((bit_sub<2,3>(instr))); uint8_t rd = ((bit_sub<7,3>(instr))); @@ -3726,9 +3859,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__SUB_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,70); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->builder.CreateStore( this->gen_ext( (this->builder.CreateSub( @@ -3740,7 +3877,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 70); this->builder.CreateBr(bb); return returnValue; @@ -3748,8 +3885,6 @@ private: /* instruction 71: C__XOR */ std::tuple __c__xor(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__XOR_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,71); uint64_t PC = pc.val; uint8_t rs2 = ((bit_sub<2,3>(instr))); uint8_t rd = ((bit_sub<7,3>(instr))); @@ -3765,9 +3900,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__XOR_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,71); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->builder.CreateStore( this->builder.CreateXor( this->gen_reg_load(rd+ 8+ traits::X0, 0), @@ -3777,7 +3916,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 71); this->builder.CreateBr(bb); return returnValue; @@ -3785,8 +3924,6 @@ private: /* instruction 72: C__OR */ std::tuple __c__or(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__OR_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,72); uint64_t PC = pc.val; uint8_t rs2 = ((bit_sub<2,3>(instr))); uint8_t rd = ((bit_sub<7,3>(instr))); @@ -3802,9 +3939,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__OR_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,72); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->builder.CreateStore( this->builder.CreateOr( this->gen_reg_load(rd+ 8+ traits::X0, 0), @@ -3814,7 +3955,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 72); this->builder.CreateBr(bb); return returnValue; @@ -3822,8 +3963,6 @@ private: /* instruction 73: C__AND */ std::tuple __c__and(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__AND_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,73); uint64_t PC = pc.val; uint8_t rs2 = ((bit_sub<2,3>(instr))); uint8_t rd = ((bit_sub<7,3>(instr))); @@ -3839,9 +3978,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__AND_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,73); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->builder.CreateStore( this->builder.CreateAnd( this->gen_reg_load(rd+ 8+ traits::X0, 0), @@ -3851,7 +3994,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 73); this->builder.CreateBr(bb); return returnValue; @@ -3859,8 +4002,6 @@ private: /* instruction 74: C__J */ std::tuple __c__j(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__J_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,74); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,3>(instr) << 1) | (bit_sub<6,1>(instr) << 7) | (bit_sub<7,1>(instr) << 6) | (bit_sub<8,1>(instr) << 10) | (bit_sub<9,2>(instr) << 8) | (bit_sub<11,1>(instr) << 4) | (bit_sub<12,1>(instr) << 11)); if(this->disass_enabled){ @@ -3875,16 +4016,20 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__J_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,74); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ auto PC_val_v = (uint32_t)(PC+(int16_t)sext<12>(imm)); this->builder.CreateStore(this->gen_const(32,PC_val_v), get_reg_ptr(traits::NEXT_PC), false); this->builder.CreateStore(this->gen_const(32,2U), get_reg_ptr(traits::LAST_BRANCH), false); bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 74); this->builder.CreateBr(bb); return returnValue; @@ -3892,8 +4037,6 @@ private: /* instruction 75: C__BEQZ */ std::tuple __c__beqz(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__BEQZ_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,75); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 1) | (bit_sub<5,2>(instr) << 6) | (bit_sub<10,2>(instr) << 3) | (bit_sub<12,1>(instr) << 8)); uint8_t rs1 = ((bit_sub<7,3>(instr))); @@ -3909,9 +4052,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__BEQZ_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,75); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ 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_ext(this->builder.CreateICmp(ICmpInst::ICMP_EQ, @@ -3929,7 +4076,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 75); this->builder.CreateBr(bb); return returnValue; @@ -3937,8 +4084,6 @@ private: /* instruction 76: C__BNEZ */ std::tuple __c__bnez(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__BNEZ_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,76); uint64_t PC = pc.val; uint16_t imm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 1) | (bit_sub<5,2>(instr) << 6) | (bit_sub<10,2>(instr) << 3) | (bit_sub<12,1>(instr) << 8)); uint8_t rs1 = ((bit_sub<7,3>(instr))); @@ -3954,9 +4099,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__BNEZ_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,76); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ 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_ext(this->builder.CreateICmp(ICmpInst::ICMP_NE, @@ -3974,7 +4123,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 76); this->builder.CreateBr(bb); return returnValue; @@ -3982,8 +4131,6 @@ private: /* instruction 77: C__SLLI */ std::tuple __c__slli(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__SLLI_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,77); uint64_t PC = pc.val; uint8_t nzuimm = ((bit_sub<2,5>(instr))); uint8_t rs1 = ((bit_sub<7,5>(instr))); @@ -3999,9 +4146,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__SLLI_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,77); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -4018,7 +4169,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 77); this->builder.CreateBr(bb); return returnValue; @@ -4026,8 +4177,6 @@ private: /* instruction 78: C__LWSP */ std::tuple __c__lwsp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__LWSP_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,78); uint64_t PC = pc.val; uint8_t uimm = ((bit_sub<2,2>(instr) << 6) | (bit_sub<4,3>(instr) << 2) | (bit_sub<12,1>(instr) << 5)); uint8_t rd = ((bit_sub<7,5>(instr))); @@ -4043,9 +4192,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__LWSP_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,78); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)||rd== 0) { this->gen_raise_trap(0, 2); } @@ -4067,7 +4220,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 78); this->builder.CreateBr(bb); return returnValue; @@ -4075,8 +4228,6 @@ private: /* instruction 79: C__MV */ std::tuple __c__mv(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__MV_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,79); uint64_t PC = pc.val; uint8_t rs2 = ((bit_sub<2,5>(instr))); uint8_t rd = ((bit_sub<7,5>(instr))); @@ -4092,9 +4243,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__MV_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,79); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -4108,7 +4263,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 79); this->builder.CreateBr(bb); return returnValue; @@ -4116,8 +4271,6 @@ private: /* instruction 80: C__JR */ std::tuple __c__jr(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__JR_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,80); uint64_t PC = pc.val; uint8_t rs1 = ((bit_sub<7,5>(instr))); if(this->disass_enabled){ @@ -4132,16 +4285,20 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__JR_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,80); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); - if(rs1&&rs1(traits::RFS)) { - auto PC_val_v = this->builder.CreateAnd( - this->gen_reg_load(rs1%static_cast(traits::RFS)+ traits::X0, 0), - this->gen_ext(this->gen_const(8,~ 0x1), 32,false)) - ; - this->builder.CreateStore(PC_val_v, get_reg_ptr(traits::NEXT_PC), false); - this->builder.CreateStore(this->gen_const(32,2U), get_reg_ptr(traits::LAST_BRANCH), false); + + /*generate behavior*/ + if(rs1&&rs1(traits::RFS)){ auto addr_mask =this->gen_const(32,(uint32_t)- 2); + auto PC_val_v = this->builder.CreateAnd( + this->gen_reg_load(rs1%static_cast(traits::RFS)+ traits::X0, 0), + addr_mask) + ; + this->builder.CreateStore(PC_val_v, get_reg_ptr(traits::NEXT_PC), false); + this->builder.CreateStore(this->gen_const(32,2U), get_reg_ptr(traits::LAST_BRANCH), false); } else{ this->gen_raise_trap(0, 2); @@ -4149,7 +4306,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 80); this->builder.CreateBr(bb); return returnValue; @@ -4157,21 +4314,23 @@ private: /* instruction 81: __reserved_cmv */ std::tuple ____reserved_cmv(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("__reserved_cmv_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,81); uint64_t PC = pc.val; if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("__reserved_cmv_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,81); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_raise_trap(0, 2); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 81); this->builder.CreateBr(bb); return returnValue; @@ -4179,8 +4338,6 @@ private: /* instruction 82: C__ADD */ std::tuple __c__add(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__ADD_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,82); uint64_t PC = pc.val; uint8_t rs2 = ((bit_sub<2,5>(instr))); uint8_t rd = ((bit_sub<7,5>(instr))); @@ -4196,9 +4353,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__ADD_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,82); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rd>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -4217,7 +4378,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 82); this->builder.CreateBr(bb); return returnValue; @@ -4225,8 +4386,6 @@ private: /* instruction 83: C__JALR */ std::tuple __c__jalr(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__JALR_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,83); uint64_t PC = pc.val; uint8_t rs1 = ((bit_sub<7,5>(instr))); if(this->disass_enabled){ @@ -4241,20 +4400,25 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__JALR_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,83); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs1>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } else{ + auto addr_mask =this->gen_const(32,(uint32_t)- 2); auto new_pc =this->gen_reg_load(rs1+ traits::X0, 0); this->builder.CreateStore( this->gen_const(32,(uint32_t)(PC+ 2)), get_reg_ptr(1 + traits::X0), false); auto PC_val_v = this->builder.CreateAnd( new_pc, - this->gen_ext(this->gen_const(8,~ 0x1), 32,false)) + addr_mask) ; this->builder.CreateStore(PC_val_v, get_reg_ptr(traits::NEXT_PC), false); this->builder.CreateStore(this->gen_const(32,2U), get_reg_ptr(traits::LAST_BRANCH), false); @@ -4262,7 +4426,7 @@ private: bb = this->leave_blk; auto returnValue = std::make_tuple(BRANCH,nullptr); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 83); this->builder.CreateBr(bb); return returnValue; @@ -4270,21 +4434,23 @@ private: /* instruction 84: C__EBREAK */ std::tuple __c__ebreak(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__EBREAK_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,84); uint64_t PC = pc.val; if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("C__EBREAK_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,84); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_raise_trap(0, 3); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 84); this->builder.CreateBr(bb); return returnValue; @@ -4292,8 +4458,6 @@ private: /* instruction 85: C__SWSP */ std::tuple __c__swsp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("C__SWSP_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,85); uint64_t PC = pc.val; uint8_t rs2 = ((bit_sub<2,5>(instr))); uint8_t uimm = ((bit_sub<7,2>(instr) << 6) | (bit_sub<9,4>(instr) << 2)); @@ -4309,9 +4473,13 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } + bb->setName(fmt::format("C__SWSP_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,85); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ if(rs2>=static_cast(traits::RFS)) { this->gen_raise_trap(0, 2); } @@ -4331,7 +4499,7 @@ private: bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 85); this->builder.CreateBr(bb); return returnValue; @@ -4339,21 +4507,23 @@ private: /* instruction 86: DII */ std::tuple __dii(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){ - bb->setName(fmt::format("DII_0x{:X}",pc.val)); - this->gen_sync(PRE_SYNC,86); uint64_t PC = pc.val; if(this->disass_enabled){ /* generate console output when executing the command */ //This disass is not yet implemented } + bb->setName(fmt::format("DII_0x{:X}",pc.val)); + this->gen_sync(PRE_SYNC,86); auto cur_pc_val = this->gen_const(32,pc.val); pc=pc+ 2; this->gen_set_pc(pc, traits::NEXT_PC); + + /*generate behavior*/ this->gen_raise_trap(0, 2); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); - this->gen_trap_check(bb); + this->gen_instr_epilogue(bb); this->gen_sync(POST_SYNC, 86); this->builder.CreateBr(bb); return returnValue; @@ -4373,7 +4543,7 @@ private: pc = pc + ((instr & 3) == 3 ? 4 : 2); this->gen_raise_trap(0, 2); // illegal instruction trap this->gen_sync(iss::POST_SYNC, instr_descr.size()); - this->gen_trap_check(this->leave_blk); + this->gen_instr_epilogue(this->leave_blk); return std::make_tuple(BRANCH, nullptr); } //decoding functionality @@ -4479,18 +4649,21 @@ vm_impl::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt, return (this->*f)(pc, instr, this_block); } -template void vm_impl::gen_leave_behavior(BasicBlock *leave_blk) { +template +void vm_impl::gen_leave_behavior(BasicBlock *leave_blk) { this->builder.SetInsertPoint(leave_blk); this->builder.CreateRet(this->builder.CreateLoad(this->get_typeptr(traits::NEXT_PC),get_reg_ptr(traits::NEXT_PC), false)); } -template void vm_impl::gen_raise_trap(uint16_t trap_id, uint16_t cause) { +template +void vm_impl::gen_raise_trap(uint16_t trap_id, uint16_t cause) { auto *TRAP_val = this->gen_const(32, 0x80 << 24 | (cause << 16) | trap_id); this->builder.CreateStore(TRAP_val, get_reg_ptr(traits::TRAP_STATE), true); this->builder.CreateStore(this->gen_const(32U, std::numeric_limits::max()), get_reg_ptr(traits::LAST_BRANCH), false); } -template void vm_impl::gen_leave_trap(unsigned lvl) { +template +void vm_impl::gen_leave_trap(unsigned lvl) { std::vector args{ this->core_ptr, ConstantInt::get(getContext(), APInt(64, lvl)) }; this->builder.CreateCall(this->mod->getFunction("leave_trap"), args); auto *PC_val = this->gen_read_mem(traits::CSR, (lvl << 8) + 0x41, traits::XLEN / 8); @@ -4498,12 +4671,14 @@ template void vm_impl::gen_leave_trap(unsigned lvl) { this->builder.CreateStore(this->gen_const(32U, std::numeric_limits::max()), get_reg_ptr(traits::LAST_BRANCH), false); } -template void vm_impl::gen_wait(unsigned type) { +template +void vm_impl::gen_wait(unsigned type) { std::vector args{ this->core_ptr, ConstantInt::get(getContext(), APInt(64, type)) }; this->builder.CreateCall(this->mod->getFunction("wait"), args); } -template void vm_impl::gen_trap_behavior(BasicBlock *trap_blk) { +template +void vm_impl::gen_trap_behavior(BasicBlock *trap_blk) { this->builder.SetInsertPoint(trap_blk); this->gen_sync(POST_SYNC, -1); //TODO get right InstrId auto *trap_state_val = this->builder.CreateLoad(this->get_typeptr(traits::TRAP_STATE), get_reg_ptr(traits::TRAP_STATE), true); @@ -4516,7 +4691,8 @@ template void vm_impl::gen_trap_behavior(BasicBlock *trap_ this->builder.CreateRet(trap_addr_val); } -template inline void vm_impl::gen_trap_check(BasicBlock *bb) { +template +void vm_impl::gen_instr_epilogue(BasicBlock *bb) { auto* target_bb = BasicBlock::Create(this->mod->getContext(), "", this->func, bb); auto *v = this->builder.CreateLoad(this->get_typeptr(traits::TRAP_STATE), get_reg_ptr(traits::TRAP_STATE), true); this->gen_cond_branch(this->builder.CreateICmp(