Commit 52ed1a5f authored by Kunshan Wang's avatar Kunshan Wang

Implemented `xxx_by_id` COMMINSTs

parent ba938c48
......@@ -12,3 +12,4 @@ hs_err_pid*.log
/bin/
*.py[co]
classpath.txt
project/build.properties
......@@ -798,6 +798,10 @@ struct MuIRBuilder {
#define MU_CI_UVM_META_ENABLE_WATCHPOINT ((MuCommInst)0x25e) /// MUAPIPARSER muname:@uvm.meta.enable_watchpoint
#define MU_CI_UVM_META_DISABLE_WATCHPOINT ((MuCommInst)0x25f) /// MUAPIPARSER muname:@uvm.meta.disable_watchpoint
#define MU_CI_UVM_META_SET_TRAP_HANDLER ((MuCommInst)0x260) /// MUAPIPARSER muname:@uvm.meta.set_trap_handler
#define MU_CI_UVM_META_CONSTANT_BY_ID ((MuCommInst)0x268) /// MUAPIPARSER muname:@uvm.meta.constant_by_id
#define MU_CI_UVM_META_GLOBAL_BY_ID ((MuCommInst)0x269) /// MUAPIPARSER muname:@uvm.meta.global_by_id
#define MU_CI_UVM_META_FUNC_BY_ID ((MuCommInst)0x26a) /// MUAPIPARSER muname:@uvm.meta.func_by_id
#define MU_CI_UVM_META_EXPFUNC_BY_ID ((MuCommInst)0x26b) /// MUAPIPARSER muname:@uvm.meta.expfunc_by_id
#define MU_CI_UVM_IRBUILDER_NEW_IR_BUILDER ((MuCommInst)0x270) /// MUAPIPARSER muname:@uvm.irbuilder.new_ir_builder
#define MU_CI_UVM_IRBUILDER_LOAD ((MuCommInst)0x300) /// MUAPIPARSER muname:@uvm.irbuilder.load
#define MU_CI_UVM_IRBUILDER_ABORT ((MuCommInst)0x301) /// MUAPIPARSER muname:@uvm.irbuilder.abort
......
......@@ -385,6 +385,10 @@ common_instruction_opcodes = {
'@uvm.meta.enable_watchpoint': 0x25e,
'@uvm.meta.disable_watchpoint': 0x25f,
'@uvm.meta.set_trap_handler': 0x260,
'@uvm.meta.constant_by_id': 0x268,
'@uvm.meta.global_by_id': 0x269,
'@uvm.meta.func_by_id': 0x26a,
'@uvm.meta.expfunc_by_id': 0x26b,
'@uvm.irbuilder.new_ir_builder': 0x270,
'@uvm.irbuilder.load': 0x300,
'@uvm.irbuilder.abort': 0x301,
......@@ -466,6 +470,8 @@ common_instruction_opcodes = {
'@uvm.irbuilder.new_newthread': 0x34d,
'@uvm.irbuilder.new_swapstack': 0x34e,
'@uvm.irbuilder.new_comminst': 0x34f,
'@uvm.ext.print_stats': 0xc001,
'@uvm.ext.clear_stats': 0xc002,
}
## GEN:END:CENUMS
......
......@@ -65,6 +65,11 @@ object CommInsts extends SimpleNamespace[CommInst] {
commInst(0x260, "@uvm.meta.set_trap_handler")
commInst(0x268, "@uvm.meta.constant_by_id")
commInst(0x269, "@uvm.meta.global_by_id")
commInst(0x26a, "@uvm.meta.func_by_id")
commInst(0x26b, "@uvm.meta.expfunc_by_id")
commInst(0x270, "@uvm.irbuilder.new_ir_builder")
// Proprietary extensions specific to this refimpl
......
......@@ -197,6 +197,11 @@ object TypeInferer {
case "@uvm.meta.set_trap_handler" => Seq()
case "@uvm.meta.constant_by_id" => Seq(i.typeList(0))
case "@uvm.meta.global_by_id" => Seq(i.typeList(0))
case "@uvm.meta.func_by_id" => Seq(i.typeList(0))
case "@uvm.meta.expfunc_by_id" => Seq(i.typeList(0))
case "@uvm.irbuilder.new_ir_builder" => Seq(IRBUILDERREF)
/// GEN:BEGIN:IRBUILDER_RETVALS
......
......@@ -363,6 +363,46 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner with IRBuild
case "@uvm.meta.disable_watchPoint" => ???
case "@uvm.meta.set_trap_handler" => ???
case "@uvm.meta.constant_by_id" => {
val Seq(idBox) = argList
val id = idBox.asInt32.toInt
val gvBox = globalVarBoxByID(id)
results(0).copyFrom(gvBox)
continueNormally()
}
case "@uvm.meta.global_by_id" => {
val Seq(idBox) = argList
val id = idBox.asInt32.toInt
val gvBox = globalVarBoxByID(id)
results(0).copyFrom(gvBox)
continueNormally()
}
case "@uvm.meta.func_by_id" => {
val Seq(idBox) = argList
val id = idBox.asInt32.toInt
val gvBox = globalVarBoxByID(id)
results(0).copyFrom(gvBox)
continueNormally()
}
case "@uvm.meta.expfunc_by_id" => {
val Seq(idBox) = argList
val id = idBox.asInt32.toInt
val gvBox = globalVarBoxByID(id)
results(0).copyFrom(gvBox)
continueNormally()
}
case "@uvm.ext.print_stats" => {
val Seq(vUserNum) = argList
......@@ -388,4 +428,10 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner with IRBuild
}
}
private def globalVarBoxByID(id: MuID): ValueBox = {
val gv = microVM.globalBundle.globalVarNs(id)
val gvBox = microVM.constantPool.getGlobalVarBox(gv)
gvBox
}
}
\ No newline at end of file
......@@ -1911,7 +1911,7 @@ val _raw_result_id = _jffiBuffer.getInt(2)
val _raw_is_ptr = _jffiBuffer.getInt(3)
val _raw_ord = _jffiBuffer.getInt(4)
val _raw_optr = _jffiBuffer.getInt(5)
val _raw_refTy = _jffiBuffer.getInt(6)
val _raw_ref_ty = _jffiBuffer.getInt(6)
val _raw_loc = _jffiBuffer.getInt(7)
val _raw_opnd = _jffiBuffer.getInt(8)
val _raw_exc_clause = _jffiBuffer.getInt(9)
......@@ -1921,11 +1921,11 @@ val result_id = _raw_result_id
val is_ptr = intToBoolean(_raw_is_ptr)
val ord = toMemoryOrder(_raw_ord)
val optr = toAtomicRMWOptr(_raw_optr)
val refTy = _raw_refTy
val ref_ty = _raw_ref_ty
val loc = _raw_loc
val opnd = _raw_opnd
val exc_clause = readMuIDOptional(_raw_exc_clause)
val _RV = b.newAtomicRMW(id, result_id, is_ptr, ord, optr, refTy, loc, opnd, exc_clause)
val _RV = b.newAtomicRMW(id, result_id, is_ptr, ord, optr, ref_ty, loc, opnd, exc_clause)
}
val MUIRBUILDER__NEW_FENCE = exposedMethod("MuIRBuilder.new_fence", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.UINT32)) { _jffiBuffer =>
val _raw_b = _jffiBuffer.getAddress(0)
......@@ -2284,6 +2284,10 @@ val MU_CI_UVM_META_PUSH_FRAME = 0x25d
val MU_CI_UVM_META_ENABLE_WATCHPOINT = 0x25e
val MU_CI_UVM_META_DISABLE_WATCHPOINT = 0x25f
val MU_CI_UVM_META_SET_TRAP_HANDLER = 0x260
val MU_CI_UVM_META_CONSTANT_BY_ID = 0x268
val MU_CI_UVM_META_GLOBAL_BY_ID = 0x269
val MU_CI_UVM_META_FUNC_BY_ID = 0x26a
val MU_CI_UVM_META_EXPFUNC_BY_ID = 0x26b
val MU_CI_UVM_IRBUILDER_NEW_IR_BUILDER = 0x270
val MU_CI_UVM_IRBUILDER_LOAD = 0x300
val MU_CI_UVM_IRBUILDER_ABORT = 0x301
......@@ -2365,6 +2369,8 @@ val MU_CI_UVM_IRBUILDER_NEW_CCALL = 0x34c
val MU_CI_UVM_IRBUILDER_NEW_NEWTHREAD = 0x34d
val MU_CI_UVM_IRBUILDER_NEW_SWAPSTACK = 0x34e
val MU_CI_UVM_IRBUILDER_NEW_COMMINST = 0x34f
val MU_CI_UVM_EXT_PRINT_STATS = 0xc001
val MU_CI_UVM_EXT_CLEAR_STATS = 0xc002
def toBinOptr(cval: MuBinOptr): BinOptr.Value = cval match {
case 0x01 => BinOptr.ADD
case 0x02 => BinOptr.SUB
......
......@@ -25,6 +25,9 @@ class UvmInterpreterIRBuilderTests extends UvmBundleTesterBase with ExtraMatcher
preloadBundles("tests/uvm-refimpl-test/primitives.uir",
"tests/uvm-refimpl-test/irbuilder-tests.uir")
// Dump bundles to see run-time-loaded bundles
override def makeMicroVM = MicroVM(new VMConf(dumpBundle=true))
"The new_ir_builder COMMINST" should "create an IR builder" in {
val ctx = microVM.newContext()
......@@ -42,6 +45,13 @@ class UvmInterpreterIRBuilderTests extends UvmBundleTesterBase with ExtraMatcher
returnFromTrap(st)
}
case "@irbuilder_test.v1.entry.trap2" => {
val Seq(mySecondConstByID: MuIntValue) = ctx.dumpKeepalives(st, 0)
mySecondConstByID.asInt32 shouldBe 50
returnFromTrap(st)
}
case _ => fail("Should not hit " + trapName)
}
}
......
.const @NULLIREFI8 <@irefi8> = NULL
.const @MYFIRSTCONST <@i64> = 49
.const @I32_64 <@i32> = 64
.funcdef @irbuilder_test VERSION %v1 <@v_v> {
%entry():
%irb = COMMINST @uvm.irbuilder.new_ir_builder
%id1 = COMMINST @uvm.irbuilder.gen_sym (%irb @NULLIREFI8)
%id2 = COMMINST @uvm.irbuilder.gen_sym (%irb @NULLIREFI8)
COMMINST @uvm.irbuilder.new_type_int(%irb %id1 @I32_64)
%my_second_const = ADD <@i64> @MYFIRSTCONST @I64_1
COMMINST @uvm.irbuilder.new_const_int(%irb %id2 %id1 %my_second_const)
[%trap] TRAP <> KEEPALIVE (%irb %id1)
COMMINST @uvm.irbuilder.load(%irb)
%my_second_const_byid = COMMINST @uvm.meta.constant_by_id <@i32> (%id2)
[%trap2] TRAP <> KEEPALIVE (%my_second_const_byid)
COMMINST @uvm.thread_exit
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment