Commit 73e6de36 authored by Kunshan Wang's avatar Kunshan Wang

Reimpl IRBuilder, support get_inst_res

Fixes issue #59
parent 93de3cde
This diff is collapsed.
......@@ -14,61 +14,99 @@ begin = "SCRIPT: BEGIN HERE"
end = "SCRIPT: END HERE"
replaces = [(re.compile(x), y) for (x,y) in [
(r'BN', 'MuBundleNode'),
(r'(CN|ChildNode)\[(_\s*<:\s*)?Identified\]', 'MuChildNode'),
(r'(CN|ChildNode)\[(_\s*<:\s*)?IdentifiedSettable\]', 'MuChildNode'),
(r'(CN|ChildNode)\[Type\w*\]', 'MuTypeNode'),
(r'(CN|ChildNode)\[Abstract\w+Type\]', 'MuTypeNode'),
(r'(CN|ChildNode)\[FuncSig\]', 'MuFuncSigNode'),
(r'(CN|ChildNode)\[Const\w+\]', 'MuConstNode'),
(r'(CN|ChildNode)\[GlobalCell\]', 'MuGlobalNode'),
(r'(CN|ChildNode)\[Function\]', 'MuFuncNode'),
(r'(CN|ChildNode)\[ExposedFunc\]', 'MuExpFuncNode'),
(r'(CN|ChildNode)\[FuncVer\]', 'MuFuncVerNode'),
(r'(CN|ChildNode)\[BasicBlock\]', 'MuBBNode'),
(r'(CN|ChildNode)\[BB\]', 'MuBBNode'),
(r'(CN|ChildNode)\[SSAVariable\]', 'MuVarNode'),
(r'(CN|ChildNode)\[Var\]', 'MuVarNode'),
(r'(CN|ChildNode)\[LocalVariable\]', 'MuLocalVarNode'),
(r'(CN|ChildNode)\[NorParam\]', 'MuNorParamNode'),
(r'(CN|ChildNode)\[ExcParam\]', 'MuExcParamNode'),
(r'(CN|ChildNode)\[InstResult\]', 'MuInstResNode'),
(r'(CN|ChildNode)\[Inst\w+\]', 'MuInstNode'),
(r'(CN|ChildNode)\[HasKeepaliveClause\]', 'MuInstNode'),
(r'TrantientBundle', 'MuBundleNode'),
(r'TB', 'MuBundleNode'),
(r'Bundle', 'MuBundleNode'),
(r'TopLevel', 'MuChildNode'),
(r'ChildNode', 'MuChildNode'),
(r'Type\w*', 'MuTypeNode'),
(r'Abstract\w+Type', 'MuTypeNode'),
(r'FuncSig', 'MuFuncSigNode'),
(r'Const\w+', 'MuConstNode'),
(r'GlobalCell', 'MuGlobalNode'),
(r'Function', 'MuFuncNode'),
(r'ExposedFunc', 'MuExpFuncNode'),
(r'FuncVer', 'MuFuncVerNode'),
(r'BasicBlock', 'MuBBNode'),
(r'BB', 'MuBBNode'),
(r'SSAVariable', 'MuVarNode'),
(r'Var', 'MuVarNode'),
(r'LocalVariable', 'MuLocalVarNode'),
(r'NorParam', 'MuNorParamNode'),
(r'ExcParam', 'MuExcParamNode'),
(r'InstResult', 'MuInstResNode'),
(r'Inst\w+', 'MuInstNode'),
(r'HasKeepaliveClause', 'MuInstNode'),
]]
sig = re.compile(r'^( def\s+(\w+)\s*\(([^)]*)\):\s+\w+\s+=)', re.MULTILINE)
arg = re.compile(r'(\w*):\s+([a-zA-Z0-9\[\]]+)')
sig = re.compile(r'^( def\s+(\w+)\s*\(([^)]*)\):\s+(\w+)\s+=)', re.MULTILINE)
arg = re.compile(r'(\w*):\s*([a-zA-Z0-9\[\].]+)')
node_like = re.compile(r'Mu\w+Node')
node_seq_like = re.compile(r'Seq\[Mu\w+Node\]')
node_seq_like = re.compile(r'Seq\[(Mu\w+Node)\]')
_my_dir = os.path.dirname(__file__)
_refimpl2_root = os.path.join(_my_dir, "..")
irbuilder_path = os.path.join(_refimpl2_root, "src/main/scala/uvm/ir/irbuilder/IRBuilder.scala")
## No longer replace names, but just use MuIRNode[...]
#def rewrite_type(ty):
# for p, t in replaces:
# oldty = ty
# ty = p.sub(t, ty)
# if oldty != ty:
# break
# return ty
container_ty_r = re.compile(r'(Seq|Option)\[(.+)\]')
def rewrite_type(ty):
m = container_ty_r.match(ty)
if m is not None:
t1, t2 = m.groups()
return "{}[{}]".format(t1, rewrite_type(t2))
for p, t in replaces:
if p.match(ty) is not None:
return "MuIRNode[{}]".format(ty)
return ty
def main():
with open(irbuilder_path) as f:
lines = f.read()
text = injecttools.extract_lines(lines, begin, end)
for p, t in replaces:
text = p.sub(t, text)
#for p, t in replaces:
#text = p.sub(t, text)
output = io.StringIO()
for whole, name, arglist in sig.findall(text):
print(whole, "{", file=output)
for whole, name, arglist, retty in sig.findall(text):
argnames = []
argtypes_muctx = []
sanitisers = []
retty = rewrite_type(retty)
for an,at in arg.findall(arglist):
rwt = rewrite_type(at)
print(an, at, rwt)
argnames.append(an)
#print(an, at)
if node_seq_like.match(at) is not None:
print(' for((n,i) <- {}.zipWithIndex) require(!n.isNull, "{}[%d] must not be NULL".format(i))'.format(an, an), file=output)
elif node_like.match(at) is not None:
print(' require(!{}.isNull, "{} must not be NULL")'.format(an, an), file=output)
if name.startswith("new"):
print(' addHandle(irBuilder.{}({}))'.format(name, ", ".join(argnames)), file=output)
argtypes_muctx.append(rwt)
m = node_seq_like.match(rwt)
if m is not None:
sanitisers.append(' for((n,i) <- {}.zipWithIndex) require(!n.isNull, "{}[%d] must not be NULL".format(i))'.format(an, an))
elif node_like.match(rwt) is not None:
sanitisers.append(' require(!{}.isNull, "{} must not be NULL")'.format(an, an))
new_arglist = ", ".join("{}: {}".format(n,t) for n,t in zip(argnames, argtypes_muctx))
print(" def {}({}): {} = {{".format(name, new_arglist, retty), file=output)
for s in sanitisers:
print(s, file=output)
if name.startswith("new") or name in["getNode", "getInstRes"]:
print(' nodeToHandle(irBuilder.{}({}))'.format(name, ", ".join(argnames)), file=output)
else:
print(' irBuilder.{}({})'.format(name, ", ".join(argnames)), file=output)
print(" }", file=output)
......@@ -78,6 +116,10 @@ def main():
#args = arg_name.findall(a)
#print(" addHandle(irBuilder.{}({}))".format(n, ", ".join(args)))
#print(output.getvalue())
#return
injectable_files["MuCtxIRBuilderPart.scala"].inject_many({
"METHODS": output.getvalue(),
})
......
......@@ -164,13 +164,17 @@ def mu_ty_to_internal(mty):
raise Exception("I don't know how to convert to internal: {}".format(mty))
def gen_comminsts_retvals(comminsts):
lines = []
lines_retvals = []
lines_nretvals = []
for comminst in comminsts:
lines.append(' case "{}" => Seq({})'.format(
lines_retvals.append(' case "{}" => Seq({})'.format(
comminst.muname, mu_ty_to_internal(comminst.muretty)))
lines_nretvals.append(' case "{}" => {}'.format(
comminst.muname, 0 if comminst.muretty == "" else 1))
return "\n".join(lines)
return ("\n".join(lines_retvals), "\n".join(lines_nretvals))
_get_arg_meths = {
"int<64>": "asInt64.toLong",
......@@ -189,12 +193,12 @@ def get_arg_meth(mty, cty, cname):
def get_arg(ind, mty, cty, cname, is_optional):
if cty == "MuBundleNode":
meth = 'asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %{} must not be null")).asInstanceOf[BundleNode]'.format(cname)
meth = 'asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %{} must not be null")).asInstanceOf[TB]'.format(cname)
elif mty == "irnoderef":
if is_optional:
meth = 'asIRNode'
meth = 'asIRNodeWeak'
else:
meth = 'asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %{} must not be null"))'.format(cname)
meth = 'asIRNodeWeak.getOrElse(throw new UvmNullGenRefException("CommInst arg %{} must not be null"))'.format(cname)
else:
meth = get_arg_meth(mty, cty, cname)
return " val {} = argList({}).{}".format(cname, ind, meth)
......@@ -213,7 +217,7 @@ def set_arg_meth(mty, cty):
def set_ret(ind, mty, cty, value):
if mty == "irnoderef":
meth = 'asIRNode'
meth = 'asIRNodeWeak'
return " results({}).{} = Some({})".format(ind, meth, value)
else:
meth = set_arg_meth(mty, cty)
......@@ -359,7 +363,7 @@ def main():
comminsts = get_comminsts(ast)
comminsts_defs = gen_comminsts_defs(comminsts)
comminsts_retvals = gen_comminsts_retvals(comminsts)
comminsts_retvals, comminsts_nretvals = gen_comminsts_retvals(comminsts)
comminsts_impls = gen_comminsts_impls(comminsts)
#print(comminsts_defs)
......@@ -371,6 +375,9 @@ def main():
"internals.scala": {
"IRBUILDER_RETVALS": comminsts_retvals,
},
"InstructionResultInferer.scala": {
"IRBUILDER_RETVAL_NUMS": comminsts_nretvals,
},
"ir-ci-exec": {
"IRBUILDER_IMPL": comminsts_impls,
},
......
......@@ -19,6 +19,8 @@ injectable_files = injecttools.make_injectable_file_set(_refimpl2_root, [
["IRBUILDER_COMMINSTS"]),
("internals.scala", "src/main/scala/uvm/refimpl/internals.scala",
["IRBUILDER_RETVALS"]),
("InstructionResultInferer.scala", "src/main/scala/uvm/staticanalysis/InstructionResultInferer.scala",
["IRBUILDER_RETVAL_NUMS"]),
("ir-ci-exec", "src/main/scala/uvm/refimpl/itpr/IRBuilderCommInstExecutor.scala",
["IRBUILDER_IMPL"]),
("MuCtxIRBuilderPart.scala", "src/main/scala/uvm/refimpl/MuCtxIRBuilderPart.scala",
......
python3 irbuildertomuctx.py
python3 muapitocstubs.py
python3 muapitoirbuildercomminstsimpl.py
python3 muapitolibmupy.py
......@@ -433,57 +433,59 @@ common_instruction_opcodes = {
'@uvm.irbuilder.new_const_double': 0x323,
'@uvm.irbuilder.new_const_null': 0x324,
'@uvm.irbuilder.new_const_seq': 0x325,
'@uvm.irbuilder.new_global_cell': 0x326,
'@uvm.irbuilder.new_func': 0x327,
'@uvm.irbuilder.new_func_ver': 0x328,
'@uvm.irbuilder.new_exp_func': 0x329,
'@uvm.irbuilder.new_bb': 0x32a,
'@uvm.irbuilder.new_nor_param': 0x32b,
'@uvm.irbuilder.new_exc_param': 0x32c,
'@uvm.irbuilder.new_inst_res': 0x32d,
'@uvm.irbuilder.add_dest': 0x32e,
'@uvm.irbuilder.add_keepalives': 0x32f,
'@uvm.irbuilder.new_binop': 0x330,
'@uvm.irbuilder.new_cmp': 0x331,
'@uvm.irbuilder.new_conv': 0x332,
'@uvm.irbuilder.new_select': 0x333,
'@uvm.irbuilder.new_branch': 0x334,
'@uvm.irbuilder.new_branch2': 0x335,
'@uvm.irbuilder.new_switch': 0x336,
'@uvm.irbuilder.add_switch_dest': 0x337,
'@uvm.irbuilder.new_call': 0x338,
'@uvm.irbuilder.new_tailcall': 0x339,
'@uvm.irbuilder.new_ret': 0x33a,
'@uvm.irbuilder.new_throw': 0x33b,
'@uvm.irbuilder.new_extractvalue': 0x33c,
'@uvm.irbuilder.new_insertvalue': 0x33d,
'@uvm.irbuilder.new_extractelement': 0x33e,
'@uvm.irbuilder.new_insertelement': 0x33f,
'@uvm.irbuilder.new_shufflevector': 0x340,
'@uvm.irbuilder.new_new': 0x341,
'@uvm.irbuilder.new_newhybrid': 0x342,
'@uvm.irbuilder.new_alloca': 0x343,
'@uvm.irbuilder.new_allocahybrid': 0x344,
'@uvm.irbuilder.new_getiref': 0x345,
'@uvm.irbuilder.new_getfieldiref': 0x346,
'@uvm.irbuilder.new_getelemiref': 0x347,
'@uvm.irbuilder.new_shiftiref': 0x348,
'@uvm.irbuilder.new_getvarpartiref': 0x349,
'@uvm.irbuilder.new_load': 0x34a,
'@uvm.irbuilder.new_store': 0x34b,
'@uvm.irbuilder.new_cmpxchg': 0x34c,
'@uvm.irbuilder.new_atomicrmw': 0x34d,
'@uvm.irbuilder.new_fence': 0x34e,
'@uvm.irbuilder.new_trap': 0x34f,
'@uvm.irbuilder.new_watchpoint': 0x350,
'@uvm.irbuilder.new_wpbranch': 0x351,
'@uvm.irbuilder.new_ccall': 0x352,
'@uvm.irbuilder.new_newthread': 0x353,
'@uvm.irbuilder.new_swapstack_ret': 0x354,
'@uvm.irbuilder.new_swapstack_kill': 0x355,
'@uvm.irbuilder.set_newstack_pass_values': 0x356,
'@uvm.irbuilder.set_newstack_throw_exc': 0x357,
'@uvm.irbuilder.new_comminst': 0x358,
'@uvm.irbuilder.new_const_extern': 0x326,
'@uvm.irbuilder.new_global_cell': 0x327,
'@uvm.irbuilder.new_func': 0x328,
'@uvm.irbuilder.new_func_ver': 0x329,
'@uvm.irbuilder.new_exp_func': 0x32a,
'@uvm.irbuilder.new_bb': 0x32b,
'@uvm.irbuilder.new_nor_param': 0x32c,
'@uvm.irbuilder.new_exc_param': 0x32d,
'@uvm.irbuilder.get_inst_res': 0x32e,
'@uvm.irbuilder.get_num_inst_res': 0x32f,
'@uvm.irbuilder.add_dest': 0x330,
'@uvm.irbuilder.add_keepalives': 0x331,
'@uvm.irbuilder.new_binop': 0x332,
'@uvm.irbuilder.new_cmp': 0x333,
'@uvm.irbuilder.new_conv': 0x334,
'@uvm.irbuilder.new_select': 0x335,
'@uvm.irbuilder.new_branch': 0x336,
'@uvm.irbuilder.new_branch2': 0x337,
'@uvm.irbuilder.new_switch': 0x338,
'@uvm.irbuilder.add_switch_dest': 0x339,
'@uvm.irbuilder.new_call': 0x33a,
'@uvm.irbuilder.new_tailcall': 0x33b,
'@uvm.irbuilder.new_ret': 0x33c,
'@uvm.irbuilder.new_throw': 0x33d,
'@uvm.irbuilder.new_extractvalue': 0x33e,
'@uvm.irbuilder.new_insertvalue': 0x33f,
'@uvm.irbuilder.new_extractelement': 0x340,
'@uvm.irbuilder.new_insertelement': 0x341,
'@uvm.irbuilder.new_shufflevector': 0x342,
'@uvm.irbuilder.new_new': 0x343,
'@uvm.irbuilder.new_newhybrid': 0x344,
'@uvm.irbuilder.new_alloca': 0x345,
'@uvm.irbuilder.new_allocahybrid': 0x346,
'@uvm.irbuilder.new_getiref': 0x347,
'@uvm.irbuilder.new_getfieldiref': 0x348,
'@uvm.irbuilder.new_getelemiref': 0x349,
'@uvm.irbuilder.new_shiftiref': 0x34a,
'@uvm.irbuilder.new_getvarpartiref': 0x34b,
'@uvm.irbuilder.new_load': 0x34c,
'@uvm.irbuilder.new_store': 0x34d,
'@uvm.irbuilder.new_cmpxchg': 0x34e,
'@uvm.irbuilder.new_atomicrmw': 0x34f,
'@uvm.irbuilder.new_fence': 0x350,
'@uvm.irbuilder.new_trap': 0x351,
'@uvm.irbuilder.new_watchpoint': 0x352,
'@uvm.irbuilder.new_wpbranch': 0x353,
'@uvm.irbuilder.new_ccall': 0x354,
'@uvm.irbuilder.new_newthread': 0x355,
'@uvm.irbuilder.new_swapstack_ret': 0x356,
'@uvm.irbuilder.new_swapstack_kill': 0x357,
'@uvm.irbuilder.set_newstack_pass_values': 0x358,
'@uvm.irbuilder.set_newstack_throw_exc': 0x359,
'@uvm.irbuilder.new_comminst': 0x35a,
}
## GEN:END:CENUMS
......@@ -1370,7 +1372,8 @@ _initialize_methods(MuCtx, [
('new_bb', MuBBNode, [MuFuncVerNode]),
('new_nor_param', MuNorParamNode, [MuBBNode, MuTypeNode]),
('new_exc_param', MuExcParamNode, [MuBBNode]),
('new_inst_res', MuInstResNode, [MuInstNode]),
('get_inst_res', MuInstResNode, [MuInstNode, ctypes.c_int]),
('get_num_inst_res', ctypes.c_int, [MuInstNode]),
('add_dest', None, [MuInstNode, CMuDestKind, MuBBNode, ctypes.c_void_p, CMuArraySize]),
('add_keepalives', None, [MuInstNode, ctypes.c_void_p, CMuArraySize]),
('new_binop', MuInstNode, [MuBBNode, CMuBinOptr, MuTypeNode, MuVarNode, MuVarNode]),
......
......@@ -5,25 +5,36 @@ import uvm.ssavariables._
import scala.collection.mutable.HashMap
import scala.collection.mutable.ArrayBuffer
/**
* The top-level type for all Mu IR AST nodes. Convenient for the IRBuilder API.
*/
trait IRNode
/**
* All nodes that are not Bundle.
*/
trait ChildNode extends IRNode with IdentifiedSettable
/**
* Abstract type for all top-level definitions. Unlike the text form, FuncVer is not considered as top-level, but a sub-
* node of Function.
*/
trait TopLevel extends Identified
trait TopLevel extends ChildNode
abstract class Bundle {
abstract class Bundle extends IRNode {
/*
* There is a hierarchy of namespaces. A subnode is a subset of the parent.
*
* + allNs // All globally Identified entities
* + typeNs // All types
* + funcSigNs // All function signatures
* + topLevelNs // All globally Identified entities
* + typeNs // All types
* + funcSigNs // All function signatures
* + globalVarNs // Global variables
* + constantNs // Constants
* + globalCellNs // Global cells
* + funcNs // Functions
* + expFuncNs // Exposed functions
* + funcVerNs // All function versions
* + globalVarNs // Global variables
* + constantNs // Constants
* + globalCellNs // Global cells
* + funcNs // Functions
* + expFuncNs // Exposed functions
* + bbNs // Basic blocks (per function version)
* + instNs // All instructions
* + localInstNs // Instructions in a basic block (per basic block)
......@@ -33,28 +44,26 @@ abstract class Bundle {
val allNs = new NestedNamespace[Identified](None, "Mu entity")
val typeNs = allNs.makeSubSpace[Type]("type")
val funcSigNs = allNs.makeSubSpace[FuncSig]("function signature")
val funcVerNs = allNs.makeSubSpace[FuncVer]("function version")
val topLevelNs = allNs.makeSubSpace[TopLevel]("top-level definition")
val typeNs = topLevelNs.makeSubSpace[Type]("type")
val funcSigNs = topLevelNs.makeSubSpace[FuncSig]("function signature")
val globalVarNs = allNs.makeSubSpace[GlobalVariable]("global variable")
val globalVarNs = topLevelNs.makeSubSpace[GlobalVariable]("global variable")
val constantNs = globalVarNs.makeSubSpace[Constant]("constant")
val globalCellNs = globalVarNs.makeSubSpace[GlobalCell]("global cell")
val funcNs = globalVarNs.makeSubSpace[Function]("function")
val expFuncNs = globalVarNs.makeSubSpace[ExposedFunc]("exposed function")
val funcVerNs = allNs.makeSubSpace[FuncVer]("function version")
val instNs = allNs.makeSubSpace[Instruction]("instruction")
val sourceInfoRepo = new SourceInfoRepo()
def allTopLevels(): Seq[TopLevel] = {
val buf = new ArrayBuffer[TopLevel]()
buf ++= typeNs.all
buf ++= funcSigNs.all
buf ++= constantNs.all
buf ++= globalCellNs.all
buf ++= funcNs.all
buf ++= expFuncNs.all
buf ++= topLevelNs.all
buf
}
}
......@@ -147,11 +156,11 @@ class GlobalBundle extends Bundle {
// Only merge leaves
simpleMerge(typeNs, newBundle.typeNs, newBundle.sourceInfoRepo)
simpleMerge(funcSigNs, newBundle.funcSigNs, newBundle.sourceInfoRepo)
simpleMerge(funcVerNs, newBundle.funcVerNs, newBundle.sourceInfoRepo)
simpleMerge(constantNs, newBundle.constantNs, newBundle.sourceInfoRepo)
simpleMerge(globalCellNs, newBundle.globalCellNs, newBundle.sourceInfoRepo)
simpleMerge(funcNs, newBundle.funcNs, newBundle.sourceInfoRepo)
simpleMerge(expFuncNs, newBundle.expFuncNs, newBundle.sourceInfoRepo)
simpleMerge(funcVerNs, newBundle.funcVerNs, newBundle.sourceInfoRepo)
simpleMerge(instNs, newBundle.instNs, newBundle.sourceInfoRepo)
declareFunctions(newBundle.funcNs)
......
......@@ -113,49 +113,50 @@ object CommInsts extends SimpleNamespace[CommInst] {
commInst(0x32b, "@uvm.irbuilder.new_bb")
commInst(0x32c, "@uvm.irbuilder.new_nor_param")
commInst(0x32d, "@uvm.irbuilder.new_exc_param")
commInst(0x32e, "@uvm.irbuilder.new_inst_res")
commInst(0x32f, "@uvm.irbuilder.add_dest")
commInst(0x330, "@uvm.irbuilder.add_keepalives")
commInst(0x331, "@uvm.irbuilder.new_binop")
commInst(0x332, "@uvm.irbuilder.new_cmp")
commInst(0x333, "@uvm.irbuilder.new_conv")
commInst(0x334, "@uvm.irbuilder.new_select")
commInst(0x335, "@uvm.irbuilder.new_branch")
commInst(0x336, "@uvm.irbuilder.new_branch2")
commInst(0x337, "@uvm.irbuilder.new_switch")
commInst(0x338, "@uvm.irbuilder.add_switch_dest")
commInst(0x339, "@uvm.irbuilder.new_call")
commInst(0x33a, "@uvm.irbuilder.new_tailcall")
commInst(0x33b, "@uvm.irbuilder.new_ret")
commInst(0x33c, "@uvm.irbuilder.new_throw")
commInst(0x33d, "@uvm.irbuilder.new_extractvalue")
commInst(0x33e, "@uvm.irbuilder.new_insertvalue")
commInst(0x33f, "@uvm.irbuilder.new_extractelement")
commInst(0x340, "@uvm.irbuilder.new_insertelement")
commInst(0x341, "@uvm.irbuilder.new_shufflevector")
commInst(0x342, "@uvm.irbuilder.new_new")
commInst(0x343, "@uvm.irbuilder.new_newhybrid")
commInst(0x344, "@uvm.irbuilder.new_alloca")
commInst(0x345, "@uvm.irbuilder.new_allocahybrid")
commInst(0x346, "@uvm.irbuilder.new_getiref")
commInst(0x347, "@uvm.irbuilder.new_getfieldiref")
commInst(0x348, "@uvm.irbuilder.new_getelemiref")
commInst(0x349, "@uvm.irbuilder.new_shiftiref")
commInst(0x34a, "@uvm.irbuilder.new_getvarpartiref")
commInst(0x34b, "@uvm.irbuilder.new_load")
commInst(0x34c, "@uvm.irbuilder.new_store")
commInst(0x34d, "@uvm.irbuilder.new_cmpxchg")
commInst(0x34e, "@uvm.irbuilder.new_atomicrmw")
commInst(0x34f, "@uvm.irbuilder.new_fence")
commInst(0x350, "@uvm.irbuilder.new_trap")
commInst(0x351, "@uvm.irbuilder.new_watchpoint")
commInst(0x352, "@uvm.irbuilder.new_wpbranch")
commInst(0x353, "@uvm.irbuilder.new_ccall")
commInst(0x354, "@uvm.irbuilder.new_newthread")
commInst(0x355, "@uvm.irbuilder.new_swapstack_ret")
commInst(0x356, "@uvm.irbuilder.new_swapstack_kill")
commInst(0x357, "@uvm.irbuilder.set_newstack_pass_values")
commInst(0x358, "@uvm.irbuilder.set_newstack_throw_exc")
commInst(0x359, "@uvm.irbuilder.new_comminst")
commInst(0x32e, "@uvm.irbuilder.get_inst_res")
commInst(0x32f, "@uvm.irbuilder.get_num_inst_res")
commInst(0x330, "@uvm.irbuilder.add_dest")
commInst(0x331, "@uvm.irbuilder.add_keepalives")
commInst(0x332, "@uvm.irbuilder.new_binop")
commInst(0x333, "@uvm.irbuilder.new_cmp")
commInst(0x334, "@uvm.irbuilder.new_conv")
commInst(0x335, "@uvm.irbuilder.new_select")
commInst(0x336, "@uvm.irbuilder.new_branch")
commInst(0x337, "@uvm.irbuilder.new_branch2")
commInst(0x338, "@uvm.irbuilder.new_switch")
commInst(0x339, "@uvm.irbuilder.add_switch_dest")
commInst(0x33a, "@uvm.irbuilder.new_call")
commInst(0x33b, "@uvm.irbuilder.new_tailcall")
commInst(0x33c, "@uvm.irbuilder.new_ret")
commInst(0x33d, "@uvm.irbuilder.new_throw")
commInst(0x33e, "@uvm.irbuilder.new_extractvalue")
commInst(0x33f, "@uvm.irbuilder.new_insertvalue")
commInst(0x340, "@uvm.irbuilder.new_extractelement")
commInst(0x341, "@uvm.irbuilder.new_insertelement")
commInst(0x342, "@uvm.irbuilder.new_shufflevector")
commInst(0x343, "@uvm.irbuilder.new_new")
commInst(0x344, "@uvm.irbuilder.new_newhybrid")
commInst(0x345, "@uvm.irbuilder.new_alloca")
commInst(0x346, "@uvm.irbuilder.new_allocahybrid")
commInst(0x347, "@uvm.irbuilder.new_getiref")
commInst(0x348, "@uvm.irbuilder.new_getfieldiref")
commInst(0x349, "@uvm.irbuilder.new_getelemiref")
commInst(0x34a, "@uvm.irbuilder.new_shiftiref")
commInst(0x34b, "@uvm.irbuilder.new_getvarpartiref")
commInst(0x34c, "@uvm.irbuilder.new_load")
commInst(0x34d, "@uvm.irbuilder.new_store")
commInst(0x34e, "@uvm.irbuilder.new_cmpxchg")
commInst(0x34f, "@uvm.irbuilder.new_atomicrmw")
commInst(0x350, "@uvm.irbuilder.new_fence")
commInst(0x351, "@uvm.irbuilder.new_trap")
commInst(0x352, "@uvm.irbuilder.new_watchpoint")
commInst(0x353, "@uvm.irbuilder.new_wpbranch")
commInst(0x354, "@uvm.irbuilder.new_ccall")
commInst(0x355, "@uvm.irbuilder.new_newthread")
commInst(0x356, "@uvm.irbuilder.new_swapstack_ret")
commInst(0x357, "@uvm.irbuilder.new_swapstack_kill")
commInst(0x358, "@uvm.irbuilder.set_newstack_pass_values")
commInst(0x359, "@uvm.irbuilder.set_newstack_throw_exc")
commInst(0x35a, "@uvm.irbuilder.new_comminst")
/// GEN:END:IRBUILDER_COMMINSTS
}
......@@ -5,7 +5,7 @@ import scala.collection.mutable.ArrayBuffer
import uvm.types._
import uvm.ssavariables._
case class FuncSig(var paramTys: Seq[Type], var retTys: Seq[Type]) extends IdentifiedSettable with TopLevel {
case class FuncSig(var paramTys: Seq[Type], var retTys: Seq[Type]) extends TopLevel {
override final def toString: String = FuncSig.prettyPrint(this)
}
......@@ -23,7 +23,7 @@ class Function extends GlobalVariable {
/**
* A version of a function. Also known as a "control flow graph".
*/
class FuncVer(val func: Function) extends IdentifiedSettable {
class FuncVer(val func: Function) extends ChildNode {
var bbs: ArrayBuffer[BasicBlock] = null
def entry: BasicBlock = bbs.head
......@@ -32,7 +32,7 @@ class FuncVer(val func: Function) extends IdentifiedSettable {
var bbNs: NestedNamespace[BasicBlock] = null // sub-namespace of allNs
}
class BasicBlock(val funcVer: FuncVer) extends IdentifiedSettable {
class BasicBlock(val funcVer: FuncVer) extends ChildNode {
var norParams: ArrayBuffer[NorParam] = null
var excParam: Option[ExcParam] = null
var insts: ArrayBuffer[Instruction] = null
......
package uvm.ir.irbuilder
import uvm._
import uvm.types._
import uvm.ssavariables._
import scala.collection.mutable.ArrayBuffer
/**
* Abstract class for all nodes.
* @param obj The contained object.
*/
abstract class IRNode
/**
* Node for the newly-built bundle.
* @param bundle The bundle
*/
class BundleNode(val bundle: TrantientBundle) extends IRNode {
/**
* Nodes not in this bundle, but is referred to, such as types defined in previously loaded bundles.
* In a non-garbage-collected implementation, these nodes need to be explicitly freed when the bundle node is loaded
* or aborted.
*/
val externalNodes = new ArrayBuffer[IRNode]()
}
/**
* Any children of BundleNode.
* @param obj the underlying object
*/
class ChildNode[+T <: Identified](val obj: T) extends IRNode
......@@ -8,7 +8,6 @@ import scala.collection.mutable.HashSet
import uvm._
import uvm.ir.irbuilder.IRBuilder
import uvm.ir.irbuilder.IRNode
import uvm.ir.textinput.UIRTextReader
import uvm.ir.textoutput.BundleSerializer
import uvm.refimpl.bootimg.BootImageBuilder
......
......@@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
import uvm._
import uvm.ir.irbuilder.IRNode
import uvm.ir.textoutput.BundleSerializer
import uvm.ir.textoutput.EntityUtils
import uvm.refimpl._
......
......@@ -18,7 +18,6 @@ import uvm.refimpl.mem.scanning.MemoryDataScanner
import uvm.ssavariables._
import uvm.types._
import uvm.refimpl.mem.scanning.MemoryFieldHandler
import uvm.ir.irbuilder.IRNode
object TransitiveClosure {
def apply[T](initialElems: T*) = new TransitiveClosure(initialElems)
......
......@@ -8,9 +8,6 @@ import uvm.ssavariables._
import uvm.ssavariables.AtomicRMWOptr._
import uvm.ssavariables.MemoryOrder._
import uvm.types._
import uvm.ir.irbuilder.IRNode
import uvm.ir.irbuilder.ChildNode
import uvm.ir.irbuilder.BundleNode
object MuValue {
def apply(ty: Type, vb: ValueBox): MuValue = (ty, vb) match {
......@@ -56,7 +53,7 @@ abstract class MuGenRefValue extends MuValue {
def isNull: Boolean
}
abstract class MuSpecialEntityRefValue extends MuGenRefValue {
abstract class MuSpecialEntityRefValue[+T] extends MuGenRefValue {
def vb: ObjectBox[_]
def isNull: Boolean = vb.obj.isEmpty
}
......@@ -73,46 +70,42 @@ case class MuIRefValue(ty: TypeIRef, vb: BoxIRef) extends MuGenRefValue {
case class MuStructValue(ty: TypeStruct, vb: BoxSeq) extends MuValue
case class MuArrayValue(ty: TypeArray, vb: BoxSeq) extends MuSeqValue
case class MuVectorValue(ty: TypeVector, vb: BoxSeq) extends MuSeqValue
case class MuFuncRefValue(ty: TypeFuncRef, vb: BoxFunc) extends MuSpecialEntityRefValue
case class MuThreadRefValue(ty: TypeThreadRef, vb: BoxThread) extends MuSpecialEntityRefValue
case class MuStackRefValue(ty: TypeStackRef, vb: BoxStack) extends MuSpecialEntityRefValue
case class MuFuncRefValue(ty: TypeFuncRef, vb: BoxFunc) extends MuSpecialEntityRefValue[Function]
case class MuThreadRefValue(ty: TypeThreadRef, vb: BoxThread) extends MuSpecialEntityRefValue[InterpreterThread]
case class MuStackRefValue(ty: TypeStackRef, vb: BoxStack) extends MuSpecialEntityRefValue[InterpreterStack]
case class MuTagRef64Value(ty: TypeTagRef64, vb: BoxTagRef64) extends MuValue
case class MuUPtrValue(ty: TypeUPtr, vb: BoxPointer) extends MuValue
case class MuUFPValue(ty: TypeUFuncPtr, vb: BoxPointer) extends MuValue
case class MuFCRefValue(ty: TypeFrameCursorRef, vb: BoxFrameCursor) extends MuSpecialEntityRefValue
case class MuFCRefValue(ty: TypeFrameCursorRef, vb: BoxFrameCursor) extends MuSpecialEntityRefValue[FrameCursor]
abstract class MuIRNode extends MuSpecialEntityRefValue {
def ty: TypeIRNodeRef
def vb: BoxIRNode
def node: IRNode = vb.node.get
case class MuIRNode[+T <: IRNode](ty: TypeIRNodeRef, vb: BoxIRNode) extends MuSpecialEntityRefValue[T] {
// The underlying BoxIRNode is weakly typed. Conversion needed
def maybeNode: Option[T] = vb.obj.asInstanceOf[Option[T]]
def node: T = vb.obj.get.asInstanceOf[T]
}
case class MuBundleNode(ty: TypeIRNodeRef, vb: BoxIRNode) extends MuIRNode {
def bundle: TrantientBundle = node.asInstanceOf[BundleNode].bundle
object MuIRNodeAliases {
type MuBundleNode = MuIRNode[TrantientBundle]
type MuChildNode = MuIRNode[ChildNode]
type MuVarNode = MuIRNode[SSAVariable]
type MuGlobalVarNode = MuIRNode[GlobalVariable]
type MuLocalVarNode = MuIRNode[LocalVariable]
type MuTypeNode = MuIRNode[Type]
type MuFuncSigNode = MuIRNode[FuncSig]
type MuConstNode = MuIRNode[Constant]
type MuGlobalNode = MuIRNode [GlobalCell]
type MuFuncNode = MuIRNode[Function]