GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit ba938c48 authored by Kunshan Wang's avatar Kunshan Wang

Fixed IRBuilder COMMINST bugs

- Implemented @uvm.irbuilder.new_ir_builder

- Fixed @uvm.irbuilder.gen_sym where the %name parameter should be optional
parent d8d384ea
......@@ -326,8 +326,14 @@ def gen_comminst_impl(comminst):
lines.append(' val {} = {} != 0'.format(bool_name, cname))
ir_builder_args.append(bool_name)
elif cty in ["MuName", "MuCString"]:
if cname in comminst.optionals:
str_name = "_maybestr_" + cname
lines.append(' val {} = loadMaybeCString({})'.format(str_name, cname))
else:
str_name = "_str_" + cname
lines.append(' val {} = loadCString({})'.format(str_name, cname))
ir_builder_args.append(str_name)
else:
ir_builder_args.append(cname)
......
......@@ -65,6 +65,8 @@ object CommInsts extends SimpleNamespace[CommInst] {
commInst(0x260, "@uvm.meta.set_trap_handler")
commInst(0x270, "@uvm.irbuilder.new_ir_builder")
// Proprietary extensions specific to this refimpl
commInst(0xc001, "@uvm.ext.print_stats")
commInst(0xc002, "@uvm.ext.clear_stats")
......
......@@ -197,6 +197,8 @@ object TypeInferer {
case "@uvm.meta.set_trap_handler" => Seq()
case "@uvm.irbuilder.new_ir_builder" => Seq(IRBUILDERREF)
/// GEN:BEGIN:IRBUILDER_RETVALS
case "@uvm.irbuilder.load" => Seq()
case "@uvm.irbuilder.abort" => Seq()
......
......@@ -43,29 +43,39 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
implicit protected def memorySupport: MemorySupport
protected def loadInt64Array(ir: (Word, Word), sz: Word): IndexedSeq[Long] = {
val (obj,off) = ir
val (obj, off) = ir
val loc = obj + off
MemoryOperations.loadInt64Array(loc, sz)
}
protected def loadInt32Array(ir: (Word, Word), sz: Word): IndexedSeq[Int] = {
val (obj,off) = ir
val (obj, off) = ir
val loc = obj + off
MemoryOperations.loadInt32Array(loc, sz)
}
protected def loadFlagArray(ir: (Word, Word), sz: Word): IndexedSeq[Flag] = {
val (obj,off) = ir
val (obj, off) = ir
val loc = obj + off
MemoryOperations.loadInt32Array(loc, sz).map(toFlag)
}
protected def loadCString(ir: (Word, Word)): String = {
val (obj,off) = ir
val (obj, off) = ir
val loc = obj + off
MemoryOperations.bytesToStr(loc)
}
protected def loadMaybeCString(ir: (Word, Word)): Option[String] = {
val (obj, off) = ir
val loc = obj + off
loc match {
case 0L => None
case _ => Some(MemoryOperations.bytesToStr(loc))
}
}
private type TB = TrantientBundle
def interpretCurrentIRBuilderCommonInstruction(): Unit = {
......@@ -75,6 +85,13 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
assert(ci.name.get.startsWith("@uvm.irbuilder"))
ci.name.get match {
case "@uvm.irbuilder.new_ir_builder" => {
val irBuilder = microVM.newIRBuilder()
results(0).asIRBuilder = Some(irBuilder)
continueNormally()
}
/// The auto-generated implementations work just fine.
//case "@uvm.irbuilder.load" => {
// val _param0 = argList(0).asIRBuilder.get
......@@ -102,8 +119,8 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
case "@uvm.irbuilder.gen_sym" => {
val b = argList(0).asIRBuilder.getOrElse(throw new UvmNullGenRefException("CommInst arg %b must not be null"))
val name = argList(1).asIRef
val _str_name = loadCString(name)
val _rv = b.genSym(_str_name)
val _maybestr_name = loadMaybeCString(name)
val _rv = b.genSym(_maybestr_name)
results(0).asInt32 = _rv
continueNormally()
}
......@@ -750,12 +767,12 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
val is_ptr = argList(3).asInt32.toInt
val ord = argList(4).asInt32.toInt
val optr = argList(5).asInt32.toInt
val refTy = argList(6).asInt32.toInt
val ref_ty = argList(6).asInt32.toInt
val loc = argList(7).asInt32.toInt
val opnd = argList(8).asInt32.toInt
val exc_clause = argList(9).asInt32.toInt.asOptionalID
val _bool_is_ptr = is_ptr != 0
val _rv = b.newAtomicRMW(id, result_id, _bool_is_ptr, ord, optr, refTy, loc, opnd, exc_clause)
val _rv = b.newAtomicRMW(id, result_id, _bool_is_ptr, ord, optr, ref_ty, loc, opnd, exc_clause)
continueNormally()
}
case "@uvm.irbuilder.new_fence" => {
......
package uvm.refimpl.itpr
import org.scalatest._
import java.io.FileReader
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.refimpl._
import uvm.refimpl.itpr._
import MemoryOrder._
import AtomicRMWOptr._
import uvm.refimpl.Word
import ch.qos.logback.classic.Level._
import uvm.refimpl.UvmBundleTesterBase
import uvm.refimpl.TrapHandlerResult.{ ThreadExit, Rebind }
import uvm.refimpl.HowToResume.{ PassValues, ThrowExc }
import uvm.ir.irbuilder.IRBuilder
import uvm.ir.textinput.ExtraMatchers
class UvmInterpreterIRBuilderTests extends UvmBundleTesterBase with ExtraMatchers {
setLogLevels(
ROOT_LOGGER_NAME -> INFO,
"uvm.refimpl.itpr" -> DEBUG)
preloadBundles("tests/uvm-refimpl-test/primitives.uir",
"tests/uvm-refimpl-test/irbuilder-tests.uir")
"The new_ir_builder COMMINST" should "create an IR builder" in {
val ctx = microVM.newContext()
val func = ctx.handleFromFunc("@irbuilder_test")
testFunc(ctx, func, Seq()) { (ctx, th, st, wp) =>
val trapName = nameOf(ctx.curInst(st, 0))
trapName match {
case "@irbuilder_test.v1.entry.trap" => {
val Seq(irb: MuOpaqueRefValue[IRBuilder], id1: MuIntValue) = ctx.dumpKeepalives(st, 0)
irb.vb.obj.get shouldBeA[IRBuilder] thatsIt
(id1.asInt32 >= 65536) shouldBe true
returnFromTrap(st)
}
case _ => fail("Should not hit " + trapName)
}
}
ctx.closeContext()
}
}
\ No newline at end of file
.const @NULLIREFI8 <@irefi8> = NULL
.funcdef @irbuilder_test VERSION %v1 <@v_v> {
%entry():
%irb = COMMINST @uvm.irbuilder.new_ir_builder
%id1 = COMMINST @uvm.irbuilder.gen_sym (%irb @NULLIREFI8)
[%trap] TRAP <> KEEPALIVE (%irb %id1)
COMMINST @uvm.irbuilder.load(%irb)
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