WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.6% of users enabled 2FA.

Commit b39d6f9e authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Testing IR builder...

parent d7a76d9e
......@@ -13,6 +13,13 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
val idNodeMap = nodeList.map(n => (n.id, n)).toMap
def findNode[T <: IRBuilderNode](id: MuID): T = {
idNodeMap.getOrElse(id, {
val maybeName = idNameMap.get(id)
throw new NodeIDNotFoundException(id, maybeName)
}).asInstanceOf[T]
}
val bundle = new TrantientBundle()
def setIDAndMaybeName[T <: IdentifiedSettable](obj: T, id: MuID): T = {
......@@ -24,7 +31,8 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
def cascadeLookup[T <: Identified](id: MuID, ns1: Namespace[T], ns2: Namespace[T]): T = {
ns1.get(id).getOrElse {
ns2.get(id).getOrElse {
throw new UnknownIDException(id)
val maybeName = idNameMap.get(id)
throw new UnknownIDException(id, maybeName)
}
}
}
......@@ -51,7 +59,7 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
val t = resTy(id)
if (!(expectedType.isAssignableFrom(t.getClass))) {
throw new IRBuilderException("Type id:%d name:%s does not match expected type. Expected %s, actually %s.".format(
id, idNameMap.getOrElse(id, "(no name)"), n, t))
id, idNameMap.getOrElse(id, "(no name)"), n, t))
}
t.asInstanceOf[E]
}
......@@ -203,8 +211,10 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
}
def defineFunction(irNode: NodeFuncVer, muFuncVer: FuncVer): Unit = {
muFuncVer.bbs = new ArrayBuffer()
muFuncVer.bbNs = bundle.allNs.makeSubSpace("basic block")
val irBBmuBBs = irNode.bbs.map { bbID =>
val irBB = idNodeMap(bbID).asInstanceOf[NodeBB]
val irBB = findNode[NodeBB](bbID)
val muBB = new BasicBlock(muFuncVer)
setIDAndMaybeName(muBB, bbID)
muFuncVer.bbs += muBB
......@@ -213,6 +223,11 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
}
for ((irBB, muBB) <- irBBmuBBs) {
muBB.norParams = new ArrayBuffer()
muBB.excParam = None
muBB.insts = new ArrayBuffer()
muBB.localVarNs = bundle.allNs.makeSubSpace("local variable")
muBB.localInstNs = bundle.allNs.makeSubSpace("instruction")
for ((norParamID, norParamTyID) <- irBB.norParamIDs zip irBB.norParamTys) {
val muType = resTy(norParamTyID)
val muNorParam = NorParam(muType)
......@@ -229,7 +244,7 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
}
for (instID <- irBB.insts) {
val irInst = idNodeMap(instID).asInstanceOf[IRInstNode]
val irInst = findNode[IRInstNode](instID)
val muInst = defineInst(muFuncVer, muBB, irInst)
setIDAndMaybeName(muInst, instID)
muBB.insts += muInst
......@@ -250,7 +265,7 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
cascadeLookup(id, bundle.globalVarNs, globalBundle.globalVarNs)
}
}
implicit def resVars(ids: Seq[MuVarNode]): Seq[SSAVariable] = {
ids.map(resVar)
}
......@@ -258,8 +273,9 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
// used by keepalives
def resLocalVar(id: MuVarNode): LocalVariable = {
localVarNs.get(id).getOrElse {
throw new IRBuilderException("Local variable id:%d name:%s not found".format(id,
idNameMap.getOrElse(id, "(no name)")))
val vars = localVarNs.all.map(" " + _.repr).mkString("\n")
throw new IRBuilderException("Local variable id:%d name:%s not found.\nFYI: Current local variables are:\n%s".format(
id, idNameMap.getOrElse(id, "(no name)"), vars))
}
}
......@@ -270,37 +286,37 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
@inline
implicit def resDestClause(id: MuDestClause): DestClause = {
val NodeDestClause(_, dest, vars) = idNodeMap(id).asInstanceOf[NodeDestClause]
val NodeDestClause(_, dest, vars) = findNode[NodeDestClause](id)
DestClause(dest, vars.map(resVar))
}
@inline
implicit def resExcClause(maybeID: Option[MuExcClause]): Option[ExcClause] = maybeID map { id =>
val irExcClause = idNodeMap(id).asInstanceOf[NodeExcClause]
val irExcClause = findNode[NodeExcClause](id)
ExcClause(irExcClause.nor, irExcClause.exc)
}
@inline
implicit def resKeepalives(maybeID: Option[MuKeepaliveClause]): Seq[LocalVariable] = maybeID map { id =>
val irKeepaliveClause = idNodeMap(id).asInstanceOf[NodeKeepaliveClause]
val irKeepaliveClause = findNode[NodeKeepaliveClause](id)
irKeepaliveClause.vars.map(resLocalVar)
} getOrElse(Seq())
} getOrElse (Seq())
@inline
implicit def resCurStackClause(id: MuCurStackClause): CurStackAction = {
val irCurStackClause = idNodeMap(id).asInstanceOf[IRCurStackClauseNode]
val irCurStackClause = findNode[IRCurStackClauseNode](id)
irCurStackClause match {
case NodeCscRetWith(_, tys) => RetWith(tys)
case NodeCscKillOld(_) => KillOld()
case NodeCscKillOld(_) => KillOld()
}
}
@inline
implicit def resNewStackClause(id: MuNewStackClause): NewStackAction = {
val irNewStackClause = idNodeMap(id).asInstanceOf[IRNewStackClauseNode]
val irNewStackClause = findNode[IRNewStackClauseNode](id)
irNewStackClause match {
case NodeNscPassValues(_, tys, vars) => PassValues(tys, vars)
case NodeNscThrowExc(_, exc) => ThrowExc(exc)
case NodeNscThrowExc(_, exc) => ThrowExc(exc)
}
}
......@@ -321,7 +337,7 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
val caseDests = for ((c, d) <- cases zip dests) yield {
(resConst(c), resDestClause(d))
}
InstSwitch(opndTy, opnd, defaultDest, ArrayBuffer(caseDests:_*))
InstSwitch(opndTy, opnd, defaultDest, ArrayBuffer(caseDests: _*))
}
case NodeCall(id, resultIDs, sig, callee, args, excClause, keepaliveClause) =>
InstCall(sig, callee, args, excClause, keepaliveClause) --> resultIDs
......@@ -384,11 +400,12 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
case NodeCommInst(id, resultIDs, opcode, flags, tys, sigs, args, excClause, keepaliveClause) =>
InstCommInst(opcode, flags, tys, sigs.map(resSig), args, excClause, keepaliveClause) --> resultIDs
}
muInst.bb = muBB
muInst
} catch {
case e: Exception => {
throw new IRBuilderException("Exception thrown when building instruction. Func: %s, ver: %s, bb: %s, inst: %d:%s".format(
muFuncVer.func.repr, muFuncVer.repr, muBB.repr, irInst.id, idNameMap.getOrElse(irInst.id, "(no name)")), e)
muFuncVer.func.repr, muFuncVer.repr, muBB.repr, irInst.id, idNameMap.getOrElse(irInst.id, "(no name)")), e)
}
}
}
......@@ -397,7 +414,7 @@ private object BundleConstructorImplicitMagics {
implicit class AddResultsSeq[T <: Instruction](val inst: T) extends AnyVal {
@inline
def -->(resultIDs: Seq[MuID])(implicit self: BundleConstructor, localVarNs: Namespace[LocalVariable]): T = {
inst-->(resultIDs:_*)
inst --> (resultIDs: _*)
}
}
implicit class AddResultsVarArg[T <: Instruction](val inst: T) extends AnyVal {
......
......@@ -96,6 +96,10 @@ class IRBuilder(val id: MuInternalID,
id
}
// Convenient functions for Scala
def genSym(): MuID = genSym(None)
def genSym(name: String): MuID = genSym(Some(name))
// The following functions are generated from irBuilderNodes.scala by /migrate_scripts/irbuildernodestoirbuildermethods.py
// GEN:BEGIN:IRBUILDERNODE_CONSTRUCTORS
......
......@@ -2,6 +2,7 @@ package uvm.ir.irbuilder
import uvm.UvmException
import uvm.MuID
import uvm.MuName
/** Base class for exceptions thrown by the IR builder. */
class IRBuilderException(message: String = null, cause: Throwable = null) extends UvmException(message, cause)
......@@ -17,9 +18,20 @@ class IllegalNameException(message: String = null, cause: Throwable = null) exte
class IllegalSymbolException(message: String = null, cause: Throwable = null) extends IRBuilderException(message, cause)
/**
* Thrown if an ID cannot be resolved
* Thrown if an ID does not correspond to any IR nodes
*/
class UnknownIDException(id: MuID, cause: Throwable = null) extends {
private val msg = "ID %d not found".format(id)
class NodeIDNotFoundException(id: MuID, name: Option[MuName], cause: Throwable = null) extends {
private val msg = ("Node id:%d, name:%s not found. " +
"Chance is that you created this ID using gen_sym, but did not define the actual node.").format(
id, name.getOrElse("(no name)"))
} with IRBuilderException(msg, cause)
/**
* Thrown if a MuID cannot be resolved
*/
class UnknownIDException(id: MuID, name: Option[MuName], cause: Throwable = null) extends {
private val msg = ("MuID %d (name: %s) is not defined" +
"If your Mu IR bundle refers to previously loaded entities, make sure the IDs are correct. " +
"If it refers to entities in the current bundle, make sure they have the appropriate types.").format(
id, name.getOrElse("(no name)"))
} with IRBuilderException(msg, cause)
......@@ -50,7 +50,7 @@ case class InstResult(inst: Instruction, index: Int) extends LocalVariable
abstract class Instruction extends ChildNode {
var bb: BasicBlock = null
var results: IndexedSeq[InstResult] = null
var results: IndexedSeq[InstResult] = IndexedSeq()
override def toString = "[(%s) = %s %s]".format(this.results.map(_.repr).mkString(" "), this.repr, this.getClass.getSimpleName)
}
......
......@@ -16,18 +16,6 @@ import uvm.ssavariables.MemoryOrder._
import uvm.types._
object MuCtxIRBuilderTest {
// FIXME: implement the bundle builder
/*
import MuIRNodeAliases._
implicit class MagicalHandle[T <: Instruction](val handle: MuIRNode[T]) extends AnyVal {
def R(implicit ctx: MuCtx): MuInstResNode = ctx.getInstRes(handle, 0)
def R2(implicit ctx: MuCtx): (MuInstResNode, MuInstResNode) = {
val h0 = ctx.getInstRes(handle, 0)
val h1 = ctx.getInstRes(handle, 1)
(h0, h1)
}
}
}
class MuCtxIRBuilderTest extends UvmBundleTesterBase with ExtraMatchers {
......@@ -42,9 +30,9 @@ class MuCtxIRBuilderTest extends UvmBundleTesterBase with ExtraMatchers {
it should "create an empty bundle" in {
val ctx = microVM.newContext()
val b = ctx.newBundle()
ctx.loadBundleFromNode(b)
val b = ctx.newIRBuilder()
b.load()
ctx.closeContext()
}
......@@ -52,64 +40,76 @@ class MuCtxIRBuilderTest extends UvmBundleTesterBase with ExtraMatchers {
it should "create a bundle that contains types and sigs" in {
val ctx = microVM.newContext()
val b = ctx.newBundle()
val hi1 = ctx.newTypeInt(b, 1)
val hi8 = ctx.newTypeInt(b, 8)
val hi8_id = ctx.getID(b, hi8)
val hi16 = ctx.newTypeInt(b, 16)
val hi16_id = ctx.getID(b, hi16)
val hi32 = ctx.newTypeInt(b, 32)
val hi32_id = ctx.getID(b, hi32)
val hi64 = ctx.newTypeInt(b, 64)
val hi64_id = ctx.getID(b, hi64)
ctx.setName(b, hi64, "@i64")
val hf = ctx.newTypeFloat(b)
val hd = ctx.newTypeDouble(b)
val hs = ctx.newTypeStruct(b, Seq(hi8, hi16, hi32, hi64))
val hh = ctx.newTypeHybrid(b, Seq(hf, hd), hi8)
val ha = ctx.newTypeArray(b, hi8, 100)
val hv = ctx.newTypeVector(b, hf, 4)
val hsig = ctx.newFuncSig(b, Seq(hi8, hi16), Seq(hi32))
val hsig_id = ctx.getID(b, hsig)
val htr64 = ctx.newTypeTagRef64(b)
val hsr = ctx.newTypeStackRef(b)
val htr = ctx.newTypeThreadRef(b)
val hfcr = ctx.newTypeFrameCursorRef(b)
val hinr = ctx.newTypeIRNodeRef(b)
val hp = ctx.newTypeUPtr(b)
val hfp = ctx.newTypeUFuncPtr(b)
val hr = ctx.newTypeRef(b)
val hir = ctx.newTypeIRef(b)
val hwr = ctx.newTypeWeakRef(b)
val hfr = ctx.newTypeFuncRef(b)
ctx.setTypeUPtr(hp, hi64)
ctx.setTypeUFuncPtr(hfp, hsig)
ctx.setTypeRef(hr, hi64)
ctx.setTypeIRef(hir, hi64)
ctx.setTypeWeakRef(hwr, hi64)
ctx.setTypeFuncRef(hfr, hsig)
val hr1 = ctx.newTypeRef(b)
val hs1 = ctx.newTypeStruct(b, Seq(hi64, hr1))
ctx.setTypeRef(hr1, hs1)
val hr1_id = ctx.getID(b, hr1)
val hs1_id = ctx.getID(b, hs1)
ctx.loadBundleFromNode(b)
val b = ctx.newIRBuilder()
val i1 = b.genSym()
val i8 = b.genSym(None)
val i16 = b.genSym()
val i32 = b.genSym("@b1.i32")
val i64 = b.genSym(Some("@b1.i64"))
val f = b.genSym()
val d = b.genSym()
val s = b.genSym("@b1.s")
val h = b.genSym("@b1.h")
val a = b.genSym("@b1.a")
val v = b.genSym("@b1.v")
val sig = b.genSym("@b1.sig")
val tr = b.genSym("@b1.tr64")
val st = b.genSym("@b1.stack")
val th = b.genSym("@b1.thread")
val fc = b.genSym("@b1.framecursor")
val ib = b.genSym("@b1.irbuilder")
b.newTypeInt(i8, 8)
b.newTypeInt(i16, 16)
b.newTypeInt(i32, 32)
b.newTypeInt(i64, 64)
b.newTypeFloat(f)
b.newTypeDouble(d)
b.newTypeStruct(s, Seq(i8, i16, i32, i64))
b.newTypeHybrid(h, Seq(f, d), i8)
b.newTypeArray(a, i8, 100)
b.newTypeVector(v, f, 4)
b.newFuncSig(sig, Seq(i8, i16), Seq(i32))
b.newTypeTagRef64(tr)
b.newTypeStackRef(st)
b.newTypeThreadRef(th)
b.newTypeFrameCursorRef(fc)
b.newTypeIRBuilderRef(ib)
val p = b.genSym("@p")
val fp = b.genSym("@fp")
val r = b.genSym()
val ir = b.genSym()
val wr = b.genSym()
val fr = b.genSym()
b.newTypeUPtr(p, i64)
b.newTypeUFuncPtr(fp, sig)
b.newTypeRef(r, i64)
b.newTypeIRef(ir, i64)
b.newTypeWeakRef(wr, i64)
b.newTypeFuncRef(fr, sig)
val r1 = b.genSym()
val s1 = b.genSym()
b.newTypeRef(r1, s1)
b.newTypeStruct(s1, Seq(i64, r1))
b.load()
val gb = microVM.globalBundle
gb.typeNs(hi64_id) shouldBeA[TypeInt] { its => its.length shouldBe 64 }
gb.typeNs("@i64") shouldBe gb.typeNs(hi64_id)
gb.typeNs(hr1_id) shouldBeA[TypeRef] { its => its.ty shouldBe gb.typeNs(hs1_id) }
gb.typeNs(hs1_id) shouldBeA[TypeStruct] { its => its.fieldTys shouldBe Seq(gb.typeNs(hi64_id), gb.typeNs(hr1_id)) }
gb.funcSigNs(hsig_id) shouldBeA[FuncSig] { its =>
its.paramTys shouldBe Seq(gb.typeNs(hi8_id), gb.typeNs(hi16_id))
its.retTys shouldBe Seq(gb.typeNs(hi32_id))
gb.typeNs(i64) shouldBeA[TypeInt] { its => its.length shouldBe 64 }
gb.typeNs("@b1.i64") shouldBe gb.typeNs(i64)
gb.typeNs(r1) shouldBeA[TypeRef] { its => its.ty shouldBe gb.typeNs(s1) }
gb.typeNs(s1) shouldBeA[TypeStruct] { its => its.fieldTys shouldBe Seq(gb.typeNs(i64), gb.typeNs(r1)) }
gb.funcSigNs(sig) shouldBeA[FuncSig] { its =>
its.paramTys shouldBe Seq(gb.typeNs(i8), gb.typeNs(i16))
its.retTys shouldBe Seq(gb.typeNs(i32))
}
ctx.closeContext()
......@@ -118,50 +118,57 @@ class MuCtxIRBuilderTest extends UvmBundleTesterBase with ExtraMatchers {
it should "create a bundle with constants and global cells" in {
val ctx = microVM.newContext()
val b = ctx.newBundle()
val hi64 = ctx.newTypeInt(b, 64)
val hf = ctx.newTypeFloat(b)
val hd = ctx.newTypeDouble(b)
val hs = ctx.newTypeStruct(b, Seq(hi64, hi64))
val hr = ctx.newTypeRef(b)
ctx.setTypeRef(hr, hi64)
val hc1 = ctx.newConstInt(b, hi64, 0x123456789abcdef0L)
val hc2 = ctx.newConstInt(b, hi64, 0xfedcba9876543210L)
val hc3 = ctx.newConstSeq(b, hs, Seq(hc1, hc2))
val hc4 = ctx.newConstFloat(b, hf, 3.14F)
val hc5 = ctx.newConstDouble(b, hd, 3.14)
val hc6 = ctx.newConstNull(b, hr)
val hc1_id = ctx.getID(b, hc1)
val hc2_id = ctx.getID(b, hc2)
val hc3_id = ctx.getID(b, hc3)
val hc4_id = ctx.getID(b, hc4)
val hc5_id = ctx.getID(b, hc5)
val hc6_id = ctx.getID(b, hc6)
val hg = ctx.newGlobalCell(b, hi64)
val hg_id = ctx.getID(b, hg)
val b = ctx.newIRBuilder()
val i64 = b.genSym()
val f = b.genSym()
val d = b.genSym()
val s = b.genSym()
val r = b.genSym()
b.newTypeInt(i64, 64)
b.newTypeFloat(f)
b.newTypeDouble(d)
b.newTypeStruct(s, Seq(i64, i64))
b.newTypeRef(r, i64)
val c1 = b.genSym()
val c2 = b.genSym()
val c3 = b.genSym()
val c4 = b.genSym()
val c5 = b.genSym()
val c6 = b.genSym()
b.newConstInt(c1, i64, 0x123456789abcdef0L)
b.newConstInt(c2, i64, 0xfedcba9876543210L)
b.newConstSeq(c3, s, Seq(c1, c2))
b.newConstFloat(c4, f, 3.14F)
b.newConstDouble(c5, d, 3.14)
b.newConstNull(c6, r)
val g = b.genSym()
b.newGlobalCell(g, i64)
ctx.loadBundleFromNode(b)
b.load()
val gb = microVM.globalBundle
gb.constantNs(hc1_id) shouldBeA[ConstInt] { its => its.num shouldBe 0x123456789abcdef0L }
gb.constantNs(hc2_id) shouldBeA[ConstInt] { its => its.num shouldBe 0xfedcba9876543210L }
gb.constantNs(hc3_id) shouldBeA[ConstSeq] { its =>
gb.constantNs(c1) shouldBeA[ConstInt] { its => its.num shouldBe 0x123456789abcdef0L }
gb.constantNs(c2) shouldBeA[ConstInt] { its => its.num shouldBe 0xfedcba9876543210L }
gb.constantNs(c3) shouldBeA[ConstSeq] { its =>
its.elems.map(_.asInstanceOf[ConstInt].num) shouldBe Seq(0x123456789abcdef0L, 0xfedcba9876543210L)
}
gb.constantNs(hc4_id) shouldBeA[ConstFloat] { its => its.num shouldBe 3.14f }
gb.constantNs(hc5_id) shouldBeA[ConstDouble] { its => its.num shouldBe 3.14 }
gb.constantNs(hc6_id) shouldBeA[ConstNull] thatsIt
gb.constantNs(c4) shouldBeA[ConstFloat] { its => its.num shouldBe 3.14f }
gb.constantNs(c5) shouldBeA[ConstDouble] { its => its.num shouldBe 3.14 }
gb.constantNs(c6) shouldBeA[ConstNull] thatsIt
gb.globalCellNs(hg_id) shouldBeA[GlobalCell] { its => its.cellTy shouldBeA[TypeInt] { itss => itss.length shouldBe 64 }}
gb.globalCellNs(g) shouldBeA[GlobalCell] { its => its.cellTy shouldBeA[TypeInt] { itss => itss.length shouldBe 64 }}
val hc1v = ctx.handleFromConst(hc1_id).asInstanceOf[MuIntValue]
val hc1v = ctx.handleFromConst(c1).asInstanceOf[MuIntValue]
val hc1vv = ctx.handleToSInt(hc1v)
hc1vv shouldBe 0x123456789abcdef0L
val hirg = ctx.handleFromGlobal(hg_id)
val hirg = ctx.handleFromGlobal(g)
val hirg_v0 = ctx.load(NOT_ATOMIC, hirg).asInstanceOf[MuIntValue]
val hirg_v0v = ctx.handleToSInt(hirg_v0)
hirg_v0v shouldBe 0
......@@ -178,67 +185,105 @@ class MuCtxIRBuilderTest extends UvmBundleTesterBase with ExtraMatchers {
it should "create a bundle with functions and can execute the function" in {
val ctx = microVM.newContext()
val b = ctx.newBundle()
val hi1 = ctx.newTypeInt(b, 1)
val hi8 = ctx.newTypeInt(b, 8)
val hi8_id = ctx.getID(b, hi8)
val hi16 = ctx.newTypeInt(b, 16)
val hi16_id = ctx.getID(b, hi16)
val hi32 = ctx.newTypeInt(b, 32)
val hi32_id = ctx.getID(b, hi32)
val hi64 = ctx.newTypeInt(b, 64)
val hi64_id = ctx.getID(b, hi64)
val hf = ctx.newTypeFloat(b)
val hd = ctx.newTypeDouble(b)
val hs = ctx.newTypeStruct(b, Seq(hi8, hi16, hi32, hi64))
val hh = ctx.newTypeHybrid(b, Seq(hf, hd), hi8)
val ha = ctx.newTypeArray(b, hi8, 100)
val hv = ctx.newTypeVector(b, hf, 4)
val hr = ctx.newTypeRef(b)
ctx.setTypeRef(hr, hi64)
val hsig = ctx.newFuncSig(b, Seq(hi64, hi64, hd, hd), Seq())
val hfunc = ctx.newFunc(b, hsig)
val hfunc_id = ctx.getID(b, hfunc)
val hfv = ctx.newFuncVer(b, hfunc)
val hfv_id = ctx.getID(b,hfv)
val hentry = ctx.newBB(hfv)
val hp0 = ctx.newNorParam(hentry, hi64)
val hp1 = ctx.newNorParam(hentry, hi64)
val hp2 = ctx.newNorParam(hentry, hd)
val hp3 = ctx.newNorParam(hentry, hd)
val hadd = ctx.newBinOp(hentry, BinOptr.ADD, hi64, hp0, hp1)
val hadd_r = ctx.getInstRes(hadd, 0)
val hfadd = ctx.newBinOp(hentry, BinOptr.FADD, hd, hp2, hp3)
val hfadd_r = ctx.getInstRes(hfadd, 0)
val hslt = ctx.newCmp(hentry, CmpOptr.SLT, hi64, hp0, hp1)
val hslt_r = ctx.getInstRes(hslt, 0)
val hbb1 = ctx.newBB(hfv)
val hbb1p0 = ctx.newNorParam(hbb1, hi64)
val hbb1p1 = ctx.newNorParam(hbb1, hd)
val hbb2 = ctx.newBB(hfv)
val hbr2 = ctx.newBranch2(hentry, hslt_r)
ctx.addDest(hbr2, DestKind.TRUE, hbb1, Seq(hadd_r, hfadd_r))
ctx.addDest(hbr2, DestKind.FALSE, hbb2, Seq())
val htrap1 = ctx.newTrap(hbb1, Seq())
val htrap1_id = ctx.getID(b, htrap1)
ctx.addKeepalives(htrap1, Seq(hbb1p0, hbb1p1))
val hthreadexit1 = ctx.newCommInst(hbb1, CommInsts("@uvm.thread_exit").id, Seq(), Seq(), Seq(), Seq())
val htrap2 = ctx.newTrap(hbb2, Seq())
val htrap2_id = ctx.getID(b, htrap2)
val hthreadexit2 = ctx.newCommInst(hbb2, CommInsts("@uvm.thread_exit").id, Seq(), Seq(), Seq(), Seq())
ctx.loadBundleFromNode(b)
val func = ctx.handleFromFunc(hfunc_id)
val b = ctx.newIRBuilder()
val i1 = b.genSym()
val i8 = b.genSym(None)
val i16 = b.genSym()
val i32 = b.genSym("@b2.i32")
val i64 = b.genSym(Some("@b2.i64"))
val f = b.genSym()
val d = b.genSym()
val s = b.genSym("@b2.s")
val h = b.genSym("@b2.h")
val a = b.genSym("@b2.a")
val v = b.genSym("@b2.v")
val tr = b.genSym("@b2.tr64")
val st = b.genSym("@b2.stack")
val th = b.genSym("@b2.thread")
val fc = b.genSym("@b2.framecursor")
val r = b.genSym("@b2.r")
b.newTypeInt(i8, 8)
b.newTypeInt(i16, 16)
b.newTypeInt(i32, 32)
b.newTypeInt(i64, 64)
b.newTypeFloat(f)
b.newTypeDouble(d)
b.newTypeStruct(s, Seq(i8, i16, i32, i64))
b.newTypeHybrid(h, Seq(f, d), i8)
b.newTypeArray(a, i8, 100)
b.newTypeVector(v, f, 4)
b.newTypeTagRef64(tr)
b.newTypeStackRef(st)
b.newTypeThreadRef(th)
b.newTypeFrameCursorRef(fc)
b.newTypeRef(r, i64)
val sig = b.genSym("@b2.sig")
val func = b.genSym("@b2.func")
val fv = b.genSym("@fv")
val entry = b.genSym("@entry")
val bb1 = b.genSym("@bb1")
val bb2 = b.genSym("@bb2")
b.newFuncSig(sig, Seq(i64, i64, d, d), Seq())
b.newFunc(func, sig)
b.newFuncVer(fv, func, Seq(entry, bb1, bb2))
val p0 = b.genSym("@p0")
val p1 = b.genSym("@p1")
val p2 = b.genSym("@p2")
val p3 = b.genSym("@p3")