Commit eac74cd8 authored by Kunshan Wang's avatar Kunshan Wang

Fixed bundle building with excClause

The normal destination may use the results of the instruction. So the
excClause needs to be created after the instruction is created and the
results are created.
parent 5eb904bb
......@@ -322,7 +322,7 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
val muInst: Instruction = irInst match {
case NodeBinOp(id, resultID, optr, ty, opnd1, opnd2, excClause) =>
InstBinOp(optr, ty, opnd1, opnd2, excClause) --> resultID
InstBinOp(optr, ty, opnd1, opnd2, null) --> resultID EXC excClause
case NodeCmp(id, resultID, optr, ty, opnd1, opnd2) =>
InstCmp(optr, ty, opnd1, opnd2) --> resultID
case NodeConv(id, resultID, optr, fromTy, toTy, opnd) =>
......@@ -340,7 +340,7 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
InstSwitch(opndTy, opnd, defaultDest, ArrayBuffer(caseDests: _*))
}
case NodeCall(id, resultIDs, sig, callee, args, excClause, keepaliveClause) =>
InstCall(sig, callee, args, excClause, keepaliveClause) --> resultIDs
InstCall(sig, callee, args, null, keepaliveClause) --> resultIDs EXC excClause
case NodeTailCall(id, sig, callee, args) =>
InstTailCall(sig, callee, args)
case NodeRet(id, rvs) =>
......@@ -358,13 +358,13 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
case NodeShuffleVector(id, resultID, vecty, maskty, vec1, vec2, mask) =>
InstShuffleVector(needVector(vecty), needVector(maskty), vec1, vec2, mask) --> resultID
case NodeNew(id, resultID, allocty, excClause) =>
InstNew(allocty, excClause) --> resultID
InstNew(allocty, null) --> resultID EXC excClause
case NodeNewHybrid(id, resultID, allocty, lenty, length, excClause) =>
InstNewHybrid(needHybrid(allocty), needInt(lenty), length, excClause) --> resultID
InstNewHybrid(needHybrid(allocty), needInt(lenty), length, null) --> resultID EXC excClause
case NodeAlloca(id, resultID, allocty, excClause) =>
InstAlloca(allocty, excClause) --> resultID
InstAlloca(allocty, null) --> resultID EXC excClause
case NodeAllocaHybrid(id, resultID, allocty, lenty, length, excClause) =>
InstAllocaHybrid(needHybrid(allocty), needInt(lenty), length, excClause) --> resultID
InstAllocaHybrid(needHybrid(allocty), needInt(lenty), length, null) --> resultID EXC excClause
case NodeGetIRef(id, resultID, refty, opnd) =>
InstGetIRef(refty, opnd) --> resultID
case NodeGetFieldIRef(id, resultID, isPtr, refty, index, opnd) =>
......@@ -376,29 +376,29 @@ class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNod
case NodeGetVarPartIRef(id, resultID, isPtr, refty, opnd) =>
InstGetVarPartIRef(isPtr, needHybrid(refty), opnd) --> resultID
case NodeLoad(id, resultID, isPtr, ord, refty, loc, excClause) =>
InstLoad(isPtr, ord, refty, loc, excClause) --> resultID
InstLoad(isPtr, ord, refty, loc, null) --> resultID EXC excClause
case NodeStore(id, isPtr, ord, refty, loc, newval, excClause) =>
InstStore(isPtr, ord, refty, loc, newval, excClause)
InstStore(isPtr, ord, refty, loc, newval, null) EXC excClause
case NodeCmpXchg(id, valueResultID, succResultID, isPtr, isWeak, ordSucc, ordFail, refty, loc, expected, desired, excClause) =>
InstCmpXchg(isPtr, isWeak, ordSucc, ordFail, refty, loc, expected, desired, excClause) --> (valueResultID, succResultID)
InstCmpXchg(isPtr, isWeak, ordSucc, ordFail, refty, loc, expected, desired, null) --> (valueResultID, succResultID) EXC excClause
case NodeAtomicRMW(id, resultID, isPtr, ord, optr, refTy, loc, opnd, excClause) =>
InstAtomicRMW(isPtr, ord, optr, refTy, loc, opnd, excClause) --> resultID
InstAtomicRMW(isPtr, ord, optr, refTy, loc, opnd, null) --> resultID EXC excClause
case NodeFence(id, ord) =>
InstFence(ord)
case NodeTrap(id, resultIDs, rettys, excClause, keepaliveClause) =>
InstTrap(rettys, excClause, keepaliveClause) --> resultIDs
InstTrap(rettys, null, keepaliveClause) --> resultIDs EXC excClause
case NodeWatchPoint(id, wpid, resultIDs, rettys, dis, ena, exc, keepaliveClause) =>
InstWatchPoint(wpid, rettys, dis, ena, exc.map(resDestClause), keepaliveClause) --> resultIDs
case NodeWPBranch(id, wpid, dis, ena) =>
InstWPBranch(wpid, dis, ena)
case NodeCCall(id, resultIDs, callconv, calleeTy, sig, callee, args, excClause, keepaliveClause) =>
InstCCall(callconv, calleeTy, sig, callee, args, excClause, keepaliveClause) --> resultIDs
InstCCall(callconv, calleeTy, sig, callee, args, null, keepaliveClause) --> resultIDs EXC excClause
case NodeNewThread(id, resultID, stack, threadlocal, newStackClause, excClause) =>
InstNewThread(stack, threadlocal.map(resVar), newStackClause, excClause) --> resultID
InstNewThread(stack, threadlocal.map(resVar), newStackClause, null) --> resultID EXC excClause
case NodeSwapStack(id, resultIDs, swappee, curStackClause, newStackClause, excClause, keepaliveClause) =>
InstSwapStack(swappee, curStackClause, newStackClause, excClause, keepaliveClause) --> resultIDs
InstSwapStack(swappee, curStackClause, newStackClause, null, keepaliveClause) --> resultIDs EXC excClause
case NodeCommInst(id, resultIDs, opcode, flags, tys, sigs, args, excClause, keepaliveClause) =>
InstCommInst(opcode, flags, tys, sigs.map(resSig), args, excClause, keepaliveClause) --> resultIDs
InstCommInst(opcode, flags, tys, sigs.map(resSig), args, null, keepaliveClause) --> resultIDs EXC excClause
}
muInst.bb = muBB
muInst
......@@ -430,5 +430,11 @@ private object BundleConstructorImplicitMagics {
inst
}
}
implicit class AddExcClause[T <: HasExcClause](val inst: T) extends AnyVal {
@inline
def EXC(excClause: Option[MuID])(implicit resExcClause: Option[MuID] => Option[ExcClause]): T = {
inst.excClause = resExcClause(excClause)
inst
}
}
}
......@@ -513,4 +513,35 @@ class MuCtxIRBuilderTest extends UvmBundleTesterBase with ExtraMatchers {
ctx.closeContext()
}
it should "create instructions with ExcClause" in {
val ctx = microVM.newContext()
val b = ctx.newIRBuilder()
val ns = new ConvenientNs(b, "createexcclause")
implicit def _lookup = ns.symLookup _
b.newTypeInt('i32, 32)
b.newFuncSig('main_sig, Seq('i32, 'i32), Seq())
b.newFunc('main, 'main_sig)
b.newFuncVer('main_v1, 'main, Seq('entry, 'bb1, 'bb2))
b.newBB('entry, Seq('x, 'y), Seq('i32, 'i32), None, Seq('div))
b.newBinOp('div, 'z, BinOptr.SDIV, 'i32, 'x, 'y, Some('excClause))
b.newExcClause('excClause, 'norDest, 'excDest)
b.newDestClause('norDest, 'bb1, Seq('x, 'y, 'z))
b.newDestClause('excDest, 'bb2, Seq())
b.newBB('bb1, Seq('x1, 'y1, 'z1), Seq('i32, 'i32, 'i32), None, Seq('threadexit1))
b.newCommInst('threadexit1, Seq(), CommInsts("@uvm.thread_exit"), Seq(), Seq(), Seq(), Seq(), None, None)
b.newBB('bb2, Seq(), Seq(), None, Seq('threadexit2))
b.newCommInst('threadexit2, Seq(), CommInsts("@uvm.thread_exit"), Seq(), Seq(), Seq(), Seq(), None, None)
b.load()
ctx.close()
}
}
\ No newline at end of file
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