Commit dbc7e2a4 authored by Kunshan Wang's avatar Kunshan Wang

Passes OSR, native and "simple" tests.

parent f92fbb2f
......@@ -15,6 +15,8 @@ import uvm.refimpl.nat.NativeCallResult
object InterpreterThread {
val logger = Logger(LoggerFactory.getLogger(getClass.getName))
val BOX_VOID = new BoxVoid()
}
class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator: Mutator)(
......@@ -40,7 +42,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
// Initialisation
rebindPassVoid(initialStack)
rebindPassValue(initialStack, BOX_VOID)
// Public interface
......@@ -48,6 +50,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
def step(): Unit = {
if (!isRunning) throw new UvmRefImplException(ctx + "Attempt to run thread after it has reached exit.")
if (isFutexWaiting) throw new UvmRefImplException(ctx + "Attempt to run thread when it is waiting on a futex.")
topMu.justCreated = false
interpretCurrentInstruction()
}
......@@ -1168,11 +1171,11 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
val norArgs = destClause.args
// Copy to edge-assigned boxes, first.
if(norArgs.length != dest.norParams.length) {
if (norArgs.length != dest.norParams.length) {
throw new UvmRefImplException(ctx + "Wrong number of arguments. Basic block: %s, expected: %d, actual: %d".format(
dest.repr, dest.norParams.length, norArgs.length))
dest.repr, dest.norParams.length, norArgs.length))
}
for ((arg, np) <- norArgs zip dest.norParams) {
val argBox = boxOf(arg)
val npEdgeBox = edgeAssignedBoxOf(np)
......@@ -1353,36 +1356,45 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
stack = None
}
/** Rebind to a stack. */
private def rebind(newStack: InterpreterStack): Unit = {
/**
* Rebind to a stack.
* @return Return the old state.
*
*/
private def rebind(newStack: InterpreterStack): StackState = {
stack = Some(newStack)
val oldState = curStack.state
curStack.rebindToThread()
oldState
}
/** Rebind to a stack and pass a value. */
private def rebindPassValue(newStack: InterpreterStack, value: ValueBox): Unit = {
rebind(newStack)
val oldState = rebind(newStack)
try {
boxOf(curInst).copyFrom(value)
} catch {
case e: Exception => {
throw new UvmRuntimeException(ctx + "Error during rebinding while assigning the value passed to a stack " +
"to the instruction waiting for rebinding. This is usually caused by the mismatching between the type of " +
"READY<T> and the actual value type. The passed value box is a %s.".format(value.getClass.getName), e)
top match {
case mf: MuFrame => {
if (mf.justCreated) {
mf.justCreated = false
} else {
try {
boxOf(curInst).copyFrom(value)
} catch {
case e: Exception => {
throw new UvmRuntimeException(ctx + "Error passing value while rebinding. " +
"The new stack is in state %s, the passed value box is a %s.".format(oldState, value.getClass.getName), e)
}
}
}
}
case nf: NativeFrame => {
???
}
}
finishHalfExecutedInst()
}
/** Rebind to a stack and pass void. */
private def rebindPassVoid(newStack: InterpreterStack): Unit = {
rebind(newStack)
finishHalfExecutedInst()
}
/** Rebind to a stack and throw an exception on that stack. */
private def rebindThrowExc(newStack: InterpreterStack, exc: ValueBox): Unit = {
rebind(newStack)
......@@ -1422,7 +1434,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
}
case TrapRebindPassVoid(newStack) => {
val ns = getStackNotNull(newStack)
rebindPassVoid(ns)
rebindPassValue(ns, BOX_VOID)
}
case TrapRebindThrowExc(newStack, exc) => {
val ns = getStackNotNull(newStack)
......
......@@ -177,6 +177,10 @@ class MuFrame(val funcVer: FuncVer, val cookie: Long, prev: Option[InterpreterFr
/** Current instruction index within the current basic block */
var curInstIndex: Int = 0
/** true if the frame is just created (push_frame or new_stack). Binding a thread to the stack or executing an
* instruction will make it false. */
var justCreated: Boolean = true
/**
* curInstHalfExecuted is true if the current instruction is partially executed and may continue when resumed.
......
......@@ -33,20 +33,20 @@ class UvmOSRTests extends UvmBundleTesterBase {
testFunc(ca, func, Seq(arg0)) { (ca, th, st, wp) =>
nameOf(ca.currentInstruction(st, 0)) match {
case "@intro_rec_v1.trap_rec" => {
case "@intro_rec_v1.zero.trap_rec" => {
val Seq(n0) = ca.dumpKeepalives(st, 0)
ca.toInt(n0) shouldBe 0
for (i <- 1 to 3) {
nameOf(ca.currentInstruction(st, i)) shouldBe "@intro_rec_v1.rv"
nameOf(ca.currentInstruction(st, i)) shouldBe "@intro_rec_v1.nz.rv"
val Seq(ni, nm1i) = ca.dumpKeepalives(st, i)
ca.toInt(ni) shouldBe i
ca.toInt(nm1i) shouldBe (i - 1)
}
nameOf(ca.currentInstruction(st, 4)) shouldBe "@intro_test_base_v1.rv"
nameOf(ca.currentInstruction(st, 4)) shouldBe "@intro_test_base_v1.entry.rv"
TrapRebindPassVoid(st)
TrapRebindPassValue(st, n0)
}
}
}
......@@ -63,7 +63,7 @@ class UvmOSRTests extends UvmBundleTesterBase {
testFunc(ca, func, Seq(arg0)) { (ca, th, st, wp) =>
nameOf(ca.currentInstruction(st, 0)) match {
case "@osr_test_base_v1.trap_base_exit" => {
case "@osr_test_base_v1.entry.trap_base_exit" => {
val Seq(rv) = ca.dumpKeepalives(st, 0)
ca.toInt(rv) shouldBe 6
......@@ -84,7 +84,7 @@ class UvmOSRTests extends UvmBundleTesterBase {
testFunc(ca, func, Seq(arg0)) { (ca, th, st, wp) =>
nameOf(ca.currentInstruction(st, 0)) match {
case "@sum_v1.trap_opt" => {
case "@sum_v1.opt.trap_opt" => {
val Seq(n, i, s) = ca.dumpKeepalives(st, 0)
ca.toInt(s) shouldBe 10
......@@ -108,7 +108,7 @@ class UvmOSRTests extends UvmBundleTesterBase {
// Continue
TrapRebindPassVoid(st)
}
case "@osr_test_base_v1.trap_base_exit" => {
case "@osr_test_base_v1.entry.trap_base_exit" => {
val Seq(rv) = ca.dumpKeepalives(st, 0)
ca.toInt(rv) shouldBe 28
......@@ -121,7 +121,7 @@ class UvmOSRTests extends UvmBundleTesterBase {
// and OSR should be unnecessary.
testFunc(ca, func, Seq(arg0)) { (ca, th, st, wp) =>
nameOf(ca.currentInstruction(st, 0)) match {
case "@osr_test_base_v1.trap_base_exit" => {
case "@osr_test_base_v1.entry.trap_base_exit" => {
val Seq(rv) = ca.dumpKeepalives(st, 0)
ca.toInt(rv) shouldBe 28
......
......@@ -48,7 +48,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
testFunc(ca, muFunc, Seq()) { (ca, th, st, wp) =>
ca.nameOf(ca.currentInstruction(st, 0)) match {
case "@square.v1.trap" => {
case "@square.v1.entry.trap" => {
val Seq(value, cok) = ca.dumpKeepalives(st, 0)
ca.toDouble(value) shouldBe (callbackCalled match {
......@@ -62,14 +62,14 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
TrapRebindPassVoid(st)
}
case "@one_level_test.v1.pretrap" => {
case "@one_level_test.v1.entry.pretrap" => {
val Seq(fp) = ca.dumpKeepalives(st, 0)
ca.toPointer(fp) shouldEqual nativeFuncAddr
TrapRebindPassVoid(st)
}
case "@one_level_test.v1.trap" => {
case "@one_level_test.v1.entry.trap" => {
val Seq(fp, rv) = ca.dumpKeepalives(st, 0)
ca.toPointer(fp) shouldEqual nativeFuncAddr
......@@ -103,7 +103,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
testFunc(ca, muFunc, Seq()) { (ca, th, st, wp) =>
ca.nameOf(ca.currentInstruction(st, 0)) match {
case "@square.v1.trap" => {
case "@square.v1.entry.trap" => {
val Seq(value, cok) = ca.dumpKeepalives(st, 0)
ca.toDouble(value) shouldBe (callbackCalled match {
......@@ -124,7 +124,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
TrapRebindPassVoid(st)
}
case "@one_level_test2.v1.pretrap" => {
case "@one_level_test2.v1.entry.pretrap" => {
val Seq(fp, cb1, cb2) = ca.dumpKeepalives(st, 0)
ca.toPointer(fp) shouldEqual nativeFuncAddr
......@@ -144,7 +144,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
TrapRebindPassVoid(st)
}
case "@one_level_test2.v1.trap" => {
case "@one_level_test2.v1.entry.trap" => {
val Seq(fp, rv1, rv2, cb1, cb2) = ca.dumpKeepalives(st, 0)
ca.toPointer(fp) shouldEqual nativeFuncAddr
......@@ -191,7 +191,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
testFunc(ca, muFunc, Seq(hCB)) { (ca, th, st, wp) =>
ca.nameOf(ca.currentInstruction(st, 0)) match {
case "@square.v1.trap" => {
case "@square.v1.entry.trap" => {
val Seq(value, cok) = ca.dumpKeepalives(st, 0)
ca.toDouble(value) shouldBe (callbackCalled match {
......@@ -205,7 +205,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
TrapRebindPassVoid(st)
}
case "@one_level_test3.v1.pretrap" => {
case "@one_level_test3.v1.entry.pretrap" => {
val Seq(fp, cb) = ca.dumpKeepalives(st, 0)
ca.toPointer(fp) shouldEqual nativeFuncAddr
......@@ -213,7 +213,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
TrapRebindPassVoid(st)
}
case "@one_level_test3.v1.trap" => {
case "@one_level_test3.v1.entry.trap" => {
val Seq(fp, rv) = ca.dumpKeepalives(st, 0)
ca.toPointer(fp) shouldEqual nativeFuncAddr
......@@ -254,7 +254,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
testFunc(ca, hPongTest, Seq(initialV, hPingFP)) { (ca, th, st, wp) =>
ca.nameOf(ca.currentInstruction(st, 0)) match {
case "@pong.v1.entrytrap" => {
case "@pong.v1.entry.entrytrap" => {
val Seq(v, peer) = ca.dumpKeepalives(st, 0)
val vInt = ca.toInt(v).toInt
val peerAddr = ca.toPointer(peer)
......@@ -276,7 +276,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
TrapRebindPassVoid(st)
}
case "@pong.v1.resptrap" => {
case "@pong.v1.not_zero.resptrap" => {
val Seq(v, resp) = ca.dumpKeepalives(st, 0)
val vInt = ca.toInt(v).toInt
val respInt = ca.toInt(resp).toInt
......@@ -291,7 +291,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
TrapRebindPassVoid(st)
}
case "@pong_test.v1.entrytrap" => {
case "@pong_test.v1.entry.entrytrap" => {
val Seq(v, peer) = ca.dumpKeepalives(st, 0)
ca.toInt(v).toInt shouldEqual 10
......@@ -299,7 +299,7 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
TrapRebindPassVoid(st)
}
case "@pong_test.v1.exittrap" => {
case "@pong_test.v1.entry.exittrap" => {
val Seq(rv) = ca.dumpKeepalives(st, 0)
ca.toInt(rv).toInt shouldEqual 3628800
......@@ -337,7 +337,21 @@ class UvmInterpreterNativeCallbackTests extends UvmBundleTesterBase {
testFunc(ca, muFunc, Seq()) { (ca, th, st, wp) =>
ca.nameOf(ca.currentInstruction(st, 0)) match {
case "@native_sched_test.v1.exittrap" => {
case "@native_sched_test.v1.body.inspect" => {
val Seq(rv) = ca.dumpKeepalives(st, 0)
val rvInt = ca.toInt(rv)
printf("@native_sched_test: rv = %d\n", rvInt)
TrapRebindPassVoid(st)
}
case "@take_from_mu.v1.entry.inspect" => {
val Seq(ss) = ca.dumpKeepalives(st, 0)
val rvInt = ca.toInt(ss)
printf("@take_from_mu: ss = %d\n", rvInt)
TrapRebindPassVoid(st)
}
case "@native_sched_test.v1.exit.exittrap" => {
try {
val Seq(rvTaker) = ca.dumpKeepalives(st, 0)
......
......@@ -38,11 +38,11 @@ class UvmInterpreterSimpleSumTest extends UvmBundleTesterBase {
testFunc(ca, func, Seq(hFrom, hTo)) { (ca, th, st, wp) =>
nameOf(ca.currentInstruction(st, 0)) match {
case "@simplesum_v1.starttrap" => {
case "@simplesum_v1.entry.starttrap" => {
t1 = System.currentTimeMillis()
TrapRebindPassVoid(st)
}
case "@simplesum_v1.exittrap" => {
case "@simplesum_v1.exit.exittrap" => {
t2 = System.currentTimeMillis()
val Seq(sum) = ca.dumpKeepalives(st, 0)
......
......@@ -50,7 +50,7 @@ class UvmInterpreterSimpleTests extends UvmBundleTesterBase {
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@fibonacci_mat_v1.watch" => {
case "@fibonacci_mat_v1.head.watch" => {
if (watch) {
val vhs = ca.dumpKeepalives(st, 0)
val vs = vhs.map(_.vb.asInt)
......@@ -58,7 +58,7 @@ class UvmInterpreterSimpleTests extends UvmBundleTesterBase {
}
TrapRebindPassVoid(st)
}
case "@test_fib_v1.checktrap" => {
case "@test_fib_v1.entry.checktrap" => {
val Seq(r1, r2) = ca.dumpKeepalives(st, 0)
r1.vb.asInt shouldEqual 55
......@@ -82,14 +82,14 @@ class UvmInterpreterSimpleTests extends UvmBundleTesterBase {
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@test_coroutine_v1.trap_body" => {
case "@test_coroutine_v1.body.trap_body" => {
val Seq(v) = ca.dumpKeepalives(st, 0)
println(v.vb.asSInt(64))
TrapRebindPassVoid(st)
}
case "@test_coroutine_v1.trap_exit" => {
case "@test_coroutine_v1.exit.trap_exit" => {
val Seq(exc) = ca.dumpKeepalives(st, 0)
val hsi = ca.putGlobal("@StopIteration")
......@@ -115,7 +115,7 @@ class UvmInterpreterSimpleTests extends UvmBundleTesterBase {
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@test_multithreading_v1.trap_result" => {
case "@test_multithreading_v1.getresult.trap_result" => {
val Seq(v) = ca.dumpKeepalives(st, 0)
v.vb.asSInt(64) shouldEqual 4950
......
......@@ -12,10 +12,10 @@
.funcsig @noparamsnoret = @void ()
.typedef @funcdumb = func<@noparamsnoret>
.typedef @funcdumb = funcref<@noparamsnoret>
.typedef @thread = thread
.typedef @stack = stack
.typedef @thread = threadref
.typedef @stack = stackref
.typedef @tagref64 = tagref64
.const @TRUE <@i64> = 1
......@@ -61,14 +61,14 @@
.typedef @4xi32 = vector <@i32 4>
.typedef @2xdouble = vector <@double 2>
.const @4xI32_V1 <@4xi32> = VEC {@I32_0 @I32_1 @I32_2 @I32_3}
.const @4xI32_V2 <@4xi32> = VEC {@I32_4 @I32_5 @I32_6 @I32_7}
.const @4xI32_V1 <@4xi32> = {@I32_0 @I32_1 @I32_2 @I32_3}
.const @4xI32_V2 <@4xi32> = {@I32_4 @I32_5 @I32_6 @I32_7}
.const @4xF_V1 <@4xfloat> = VEC {@F_0 @F_1 @F_2 @F_3}
.const @4xF_V2 <@4xfloat> = VEC {@F_4 @F_5 @F_6 @F_7}
.const @4xF_V1 <@4xfloat> = {@F_0 @F_1 @F_2 @F_3}
.const @4xF_V2 <@4xfloat> = {@F_4 @F_5 @F_6 @F_7}
.const @2xD_V1 <@2xdouble> = VEC {@D_0 @D_1}
.const @2xD_V2 <@2xdouble> = VEC {@D_2 @D_3}
.const @2xD_V1 <@2xdouble> = {@D_0 @D_1}
.const @2xD_V2 <@2xdouble> = {@D_2 @D_3}
.funcsig @i_i = @i64 (@i64)
.funcsig @i_ii = @i64 (@i64 @i64)
......@@ -96,28 +96,28 @@
.const @NULLREF_I64 <@refi64> = NULL
.const @NULLIREF_I64 <@irefi64> = NULL
.typedef @ptrvoid = ptr<@void>
.typedef @ptri8 = ptr<@i8>
.typedef @ptri16 = ptr<@i16>
.typedef @ptri32 = ptr<@i32>
.typedef @ptri64 = ptr<@i64>
.typedef @ptrfloat = ptr<@float>
.typedef @ptrdouble = ptr<@double>
.typedef @ptrptrvoid = ptr<@ptrvoid>
.typedef @ptrfpnoparamsnoret = ptr<@fpnoparamsnoret>
.typedef @ptrfpi_i = ptr<@fpi_i>
.typedef @fpnoparamsnoret = funcptr<@noparamsnoret>
.typedef @fpi_i = funcptr<@i_i>
.typedef @fpi_ii = funcptr<@i_ii>
.typedef @ptrvoid = uptr<@void>
.typedef @ptri8 = uptr<@i8>
.typedef @ptri16 = uptr<@i16>
.typedef @ptri32 = uptr<@i32>
.typedef @ptri64 = uptr<@i64>
.typedef @ptrfloat = uptr<@float>
.typedef @ptrdouble = uptr<@double>
.typedef @ptrptrvoid = uptr<@ptrvoid>
.typedef @ptrfpnoparamsnoret = uptr<@fpnoparamsnoret>
.typedef @ptrfpi_i = uptr<@fpi_i>
.typedef @fpnoparamsnoret = ufuncptr<@noparamsnoret>
.typedef @fpi_i = ufuncptr<@i_i>
.typedef @fpi_ii = ufuncptr<@i_ii>
.funcsig @v_a = @void (@i64)
.funcsig @getpid_sig = @i32 ()
.typedef @getpid_fp = funcptr<@getpid_sig>
.typedef @getpid_fp = ufuncptr<@getpid_sig>
.funcdef @getpidtest VERSION @getpidtest_v1 <@v_a> (%p0) {
%entry:
.funcdef @getpidtest VERSION @getpidtest_v1 <@v_a> {
%entry(<@i64> %p0):
%fp = PTRCAST <@i64 @getpid_fp> %p0
%rv = CCALL #DEFAULT <@getpid_fp @getpid_sig> %fp ()
......@@ -127,7 +127,7 @@
.typedef @size_t = int<64>
.funcsig @write_sig = @size_t (@i32 @ptrvoid @size_t)
.typedef @write_fp = funcptr<@write_sig>
.typedef @write_fp = ufuncptr<@write_sig>
.typedef @CharBuf = hybrid<@i64 @i8>
.const @I8_H <@i8> = 0x48
......@@ -137,8 +137,8 @@
.const @I8_NL <@i8> = 0x0a
.funcsig @writetest_sig = @void (@write_fp)
.funcdef @writetest VERSION @writetest_v1 <@writetest_sig> (%fp) {
%entry:
.funcdef @writetest VERSION @writetest_v1 <@writetest_sig> {
%entry(<@write_fp> %fp):
%buf = NEWHYBRID <@CharBuf @i64> @I64_6
%buf_i = GETIREF <@CharBuf> %buf
%buf_v0 = GETVARPARTIREF <@CharBuf> %buf_i
......@@ -166,12 +166,12 @@
}
.funcsig @memcpy_sig = @ptrvoid (@ptrvoid @ptrvoid @size_t)
.typedef @memcpy_fp = funcptr<@write_sig>
.typedef @memcpy_fp = ufuncptr<@write_sig>
.global @FP_MEMCPY <@memcpy_fp>
.funcdef @memcpytest VERSION @memcpytest_v1 <@noparamsnoret> () {
%entry:
.funcdef @memcpytest VERSION @memcpytest_v1 <@noparamsnoret> {
%entry():
%fp = LOAD <@memcpy_fp> @FP_MEMCPY
%buf = NEWHYBRID <@CharBuf @i64> @I64_6
......@@ -225,14 +225,14 @@
.typedef @struct_baz = struct<@struct_baz1 @double>
.typedef @irefstruct_baz = iref<@struct_baz>
.typedef @ptrstruct_baz = ptr<@struct_baz>
.typedef @ptrstruct_baz = uptr<@struct_baz>
.funcsig @foo_func_sig = @void (@struct_foo @ptri64 @ptri32 @ptri16 @ptri8)
.funcsig @bar_func_sig = @void (@struct_bar @ptrptrvoid @ptrfpnoparamsnoret)
.funcsig @baz_func_sig = @struct_baz (@struct_baz @ptrfloat @ptri32 @ptrdouble @ptrstruct_baz)
.typedef @foo_func_fp = funcptr<@foo_func_sig>
.typedef @bar_func_fp = funcptr<@bar_func_sig>
.typedef @baz_func_fp = funcptr<@baz_func_sig>
.typedef @foo_func_fp = ufuncptr<@foo_func_sig>
.typedef @bar_func_fp = ufuncptr<@bar_func_sig>
.typedef @baz_func_fp = ufuncptr<@baz_func_sig>
.const @I64BIG <@i64> = 0x55aa55aa55aa55aa
.const @I32BIG <@i32> = 0x5a5a5a5a
......@@ -241,8 +241,8 @@
.const @o_foo <@struct_foo> = {@I64BIG @I32BIG @I16BIG @I8BIG}
.funcdef @foo_func_test VERSION @foo_func_test_v1 <@v_a> (%p0) {
%entry:
.funcdef @foo_func_test VERSION @foo_func_test_v1 <@v_a> {
%entry(<@i64> %p0):
%fp = PTRCAST <@i64 @foo_func_fp> %p0
%aa = ALLOCA <@i64>
......@@ -276,8 +276,8 @@
.typedef @irefptrvoid = iref<@ptrvoid>
.typedef @ireffpnoparamsnoret = iref<@fpnoparamsnoret>
.funcdef @bar_func_test VERSION @bar_func_test_v1 <@v_a> (%p0) {
%entry:
.funcdef @bar_func_test VERSION @bar_func_test_v1 <@v_a> {
%entry(<@i64> %p0):
%fp = PTRCAST <@i64 @bar_func_fp> %p0
%aa = ALLOCA <@ptrvoid>
......@@ -300,8 +300,8 @@
.const @o_baz_a <@struct_baz1> = {@F_1 @I32_2}
.const @o_baz <@struct_baz> = {@o_baz_a @D_3}
.funcdef @baz_func_test VERSION @baz_func_test_v1 <@v_a> (%p0) {
%entry:
.funcdef @baz_func_test VERSION @baz_func_test_v1 <@v_a> {
%entry(<@i64> %p0):
%fp = PTRCAST <@i64 @baz_func_fp> %p0
%aa = ALLOCA <@float>
......
// loaded after "osr-tests.uir" when doing OSR
// Calculate the sum of 0..(n-1) by n*(n-1)/2
.funcdef @sum VERSION @sum_v2 <@i_i> (%n) {
%entry:
.funcdef @sum VERSION @sum_v2 <@i_i> {
%entry(<@i64> %n):
%nm1 = SUB <@i64> %n @I64_1
%ntnm1 = MUL <@i64> %n %nm1
%rv = SDIV <@i64> %ntnm1 @I64_2
RET <@i64> %rv
RET %rv
}
.funcsig @sum_osr_oneshot_sig = @i64 (@i64 @i64 @i64)
......@@ -14,14 +14,14 @@
// Calculate the remaining sum.
// Given s, i, n, the result is s + (n-i)*(n+i-1)/2
.funcdef @sum_osr_oneshot VERSION @sum_osr_oneshot_v1
<@sum_osr_oneshot_sig> (%s %i %n) {
%entry:
<@sum_osr_oneshot_sig> {
%entry(<@i64> %s <@i64> %i <@i64> %n):
%nmi = SUB <@i64> %n %i
%npi = ADD <@i64> %n %i
%npim1 = SUB <@i64> %npi @I64_1
%nmitnpim1 = MUL <@i64> %nmi %npim1
%remsum = SDIV <@i64> %nmitnpim1 @I64_2
%rv = ADD <@i64> %s %remsum
RET <@i64> %rv
RET %rv
}
......@@ -2,31 +2,31 @@
.funcsig @v_i = @void (@i64)
.funcdef @intro_test_base VERSION @intro_test_base_v1 <@v_i> (%n) {
%entry:
.funcdef @intro_test_base VERSION @intro_test_base_v1 <@v_i> {
%entry(<@i64> %n):
%rv = CALL <@v_i> @intro_rec (%n)
COMMINST @uvm.thread_exit
}
.funcdef @intro_rec VERSION @intro_rec_v1 <@v_i> (%n) {
%entry:
.funcdef @intro_rec VERSION @intro_rec_v1 <@v_i> {
%entry(<@i64> %n):
%isz = EQ <@i64> %n @I64_0
BRANCH2 %isz %zero %nz
BRANCH2 %isz %zero(%n) %nz(%n)
%zero:
%zero(<@i64> %n):
%trap_rec = TRAP <@i64> KEEPALIVE(%n)
RET <@i64> %trap_rec
RET %trap_rec
%nz:
%nz(<@i64> %n):
%nm1 = SUB <@i64> %n @I64_1
%rv = CALL <@v_i> @intro_rec (%nm1) KEEPALIVE(%n %nm1)
RET <@i64> %rv
RET %rv
}
.funcdef @osr_test_base VERSION @osr_test_base_v1 <@v_i> (%n) {
%entry:
.funcdef @osr_test_base VERSION @osr_test_base_v1 <@v_i> {
%entry(<@i64> %n):
%rv = CALL <@i_i> @sum (%n)
%trap_base_exit = TRAP <@void> KEEPALIVE (%rv)
COMMINST @uvm.thread_exit
......@@ -35,30 +35,27 @@
.const @sum_v1.THRESHOLD <@i64> = 5
// Sum from 0..(n-1), but optimise when adding more than 5 numbers
.funcdef @sum VERSION @sum_v1 <@i_i> (%n) {
%entry:
BRANCH %head
%head:
%i = PHI <@i64> { %entry: @I64_0; %body: %i2; }
%s = PHI <@i64> { %entry: @I64_0; %body: %s2; }
.funcdef @sum VERSION @sum_v1 <@i_i> {
%entry(<@i64> %n):
BRANCH %head(%n @I64_0 @I64_0)
%head(<@i64> %n <@i64> %i <@i64> %s):
%ge_thr = SGE <@i64> %i @sum_v1.THRESHOLD
BRANCH2 %ge_thr %opt %head2
BRANCH2 %ge_thr %opt(%n %i %s) %head2(%n %i %s)
%head2:
%head2(<@i64> %n <@i64> %i <@i64> %s):
%lt_n = SLT <@i64> %i %n
BRANCH2 %lt_n %body %exit
BRANCH2 %lt_n %body(%n %i %s) %exit(%s)
%body:
%body(<@i64> %n <@i64> %i <@i64> %s):
%i2 = ADD <@i64> %i @I64_1
%s2 = ADD <@i64> %s %i
BRANCH %head
BRANCH %head(%n %i2 %s2)
%exit:
RET <@i64> %s
%exit(<@i64> %s):
RET %s
%opt:
%opt(<@i64> %n <@i64> %i <@i64> %s):
%trap_opt = TRAP <@void> KEEPALIVE(%n %i %s)
THROW @NULLREF // unreachable
}
......@@ -22,6 +22,8 @@
.typedef @refvoid = ref<@void>
.const @NULLREF <@refvoid> = NULL
.const @VOID <@void> = NULL
.typedef @refi64 = ref<@i64>
.typedef @irefi64 = iref<@i64>
.typedef @weakrefi64 = weakref<@i64>
......
// require "primitives.uir"
.funcsig @simplesum_sig = @void (@i64 @i64)
.funcdef @simplesum VERSION @simplesum_v1 <@simplesum_sig> (%from %to) {
%entry:
.funcdef @simplesum VERSION @simplesum_v1 <@simplesum_sig> {
%entry (<@i64> %from <@i64> %to):
%starttrap = TRAP <@void>
BRANCH %head
BRANCH %head(@I64_0 %from %to)
%head:
%sum = PHI <@i64> { %entry: @I64_0; %body: %sum2; }
%i = PHI <@i64> { %entry: %from; %body: %i2; }
%head(<@i64> %sum <@i64> %i <@i64> %to):
%le = SLE <@i64> %i %to
BRANCH2 %le %body %exit
BRANCH2 %le %body(%sum %i %to) %exit(%sum)
%body:
%body(<@i64> %sum <@i64> %i <@i64> %to):
%sum2 = ADD <@i64> %sum %i
%i2 = ADD <@i64> %i @I64_1
BRANCH %head
BRANCH %head(%sum2 %i2 %to)
//%montrap = TRAP <@void> %head %head KEEPALIVE (%from %to %sum %i %le %sum2 %i2)
%exit:
%exit(<@i64> %sum):
%exittrap = TRAP <@void> KEEPALIVE (%sum)
COMMINST @uvm.thread_exit
}
This diff is collapsed.
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