To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 86d89634 authored by John Zhang's avatar John Zhang
Browse files

annotator and rtyper hack for ir_inst

parent c91a4314
"""
Meta-circular bundle building interface
"""
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.annotator.bookkeeper import analyzer_for
from rpython.rtyper.rbuiltin import parse_kwds, typer_for
from rpython.annotator import model as annmodel
from rpython.flowspace.model import Constant, Variable
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rlib.objectmodel import specialize, always_inline, ExtRegistryEntry
from rpython.translator.mu import mutype
import os
IRBuilderRef = lltype.Ptr(lltype.GcOpaqueType('irbuilderref', hints={'mu_render_ptr_as': mutype.MUTA_IRBUILDER_REF}))
MuID = rffi.UINT # MU_INT32
MuStr = lltype.Ptr(lltype.GcOpaqueType('MuStr', hints={'mu_render_ptr_as': mutype.META_CSTR}))
class MuCommInst:
IRBUILDER_NEW_IR_BUILDER = "MU_CI_UVM_IRBUILDER_NEW_IR_BUILDER"
IRBUILDER_LOAD = "MU_CI_UVM_IRBUILDER_LOAD"
IRBUILDER_ABORT = "MU_CI_UVM_IRBUILDER_ABORT"
IRBUILDER_GEN_SYM = "MU_CI_UVM_IRBUILDER_GEN_SYM"
IRBUILDER_NEW_TYPE_INT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_INT"
IRBUILDER_NEW_TYPE_FLOAT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FLOAT"
IRBUILDER_NEW_TYPE_DOUBLE = "MU_CI_UVM_IRBUILDER_NEW_TYPE_DOUBLE"
IRBUILDER_NEW_TYPE_UPTR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_UPTR"
IRBUILDER_NEW_TYPE_UFUNCPTR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_UFUNCPTR"
IRBUILDER_NEW_TYPE_STRUCT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_STRUCT"
IRBUILDER_NEW_TYPE_HYBRID = "MU_CI_UVM_IRBUILDER_NEW_TYPE_HYBRID"
IRBUILDER_NEW_TYPE_ARRAY = "MU_CI_UVM_IRBUILDER_NEW_TYPE_ARRAY"
IRBUILDER_NEW_TYPE_VECTOR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_VECTOR"
IRBUILDER_NEW_TYPE_VOID = "MU_CI_UVM_IRBUILDER_NEW_TYPE_VOID"
IRBUILDER_NEW_TYPE_REF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_REF"
IRBUILDER_NEW_TYPE_IREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_IREF"
IRBUILDER_NEW_TYPE_WEAKREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_WEAKREF"
IRBUILDER_NEW_TYPE_FUNCREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FUNCREF"
IRBUILDER_NEW_TYPE_TAGREF64 = "MU_CI_UVM_IRBUILDER_NEW_TYPE_TAGREF64"
IRBUILDER_NEW_TYPE_THREADREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_THREADREF"
IRBUILDER_NEW_TYPE_STACKREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_STACKREF"
IRBUILDER_NEW_TYPE_FRAMECURSORREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FRAMECURSORREF"
IRBUILDER_NEW_TYPE_IRBUILDERREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_IRBUILDERREF"
IRBUILDER_NEW_FUNCSIG = "MU_CI_UVM_IRBUILDER_NEW_FUNCSIG"
IRBUILDER_NEW_CONST_INT = "MU_CI_UVM_IRBUILDER_NEW_CONST_INT"
IRBUILDER_NEW_CONST_INT_EX = "MU_CI_UVM_IRBUILDER_NEW_CONST_INT_EX"
IRBUILDER_NEW_CONST_FLOAT = "MU_CI_UVM_IRBUILDER_NEW_CONST_FLOAT"
IRBUILDER_NEW_CONST_DOUBLE = "MU_CI_UVM_IRBUILDER_NEW_CONST_DOUBLE"
IRBUILDER_NEW_CONST_NULL = "MU_CI_UVM_IRBUILDER_NEW_CONST_NULL"
IRBUILDER_NEW_CONST_SEQ = "MU_CI_UVM_IRBUILDER_NEW_CONST_SEQ"
IRBUILDER_NEW_CONST_EXTERN = "MU_CI_UVM_IRBUILDER_NEW_CONST_EXTERN"
IRBUILDER_NEW_GLOBAL_CELL = "MU_CI_UVM_IRBUILDER_NEW_GLOBAL_CELL"
IRBUILDER_NEW_FUNC = "MU_CI_UVM_IRBUILDER_NEW_FUNC"
IRBUILDER_NEW_EXP_FUNC = "MU_CI_UVM_IRBUILDER_NEW_EXP_FUNC"
IRBUILDER_NEW_FUNC_VER = "MU_CI_UVM_IRBUILDER_NEW_FUNC_VER"
IRBUILDER_NEW_BB = "MU_CI_UVM_IRBUILDER_NEW_BB"
IRBUILDER_NEW_DEST_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_DEST_CLAUSE"
IRBUILDER_NEW_EXC_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_EXC_CLAUSE"
IRBUILDER_NEW_KEEPALIVE_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_KEEPALIVE_CLAUSE"
IRBUILDER_NEW_CSC_RET_WITH = "MU_CI_UVM_IRBUILDER_NEW_CSC_RET_WITH"
IRBUILDER_NEW_CSC_KILL_OLD = "MU_CI_UVM_IRBUILDER_NEW_CSC_KILL_OLD"
IRBUILDER_NEW_NSC_PASS_VALUES = "MU_CI_UVM_IRBUILDER_NEW_NSC_PASS_VALUES"
IRBUILDER_NEW_NSC_THROW_EXC = "MU_CI_UVM_IRBUILDER_NEW_NSC_THROW_EXC"
IRBUILDER_NEW_BINOP = "MU_CI_UVM_IRBUILDER_NEW_BINOP"
IRBUILDER_NEW_BINOP_WITH_STATUS = "MU_CI_UVM_IRBUILDER_NEW_BINOP_WITH_STATUS"
IRBUILDER_NEW_CMP = "MU_CI_UVM_IRBUILDER_NEW_CMP"
IRBUILDER_NEW_CONV = "MU_CI_UVM_IRBUILDER_NEW_CONV"
IRBUILDER_NEW_SELECT = "MU_CI_UVM_IRBUILDER_NEW_SELECT"
IRBUILDER_NEW_BRANCH = "MU_CI_UVM_IRBUILDER_NEW_BRANCH"
IRBUILDER_NEW_BRANCH2 = "MU_CI_UVM_IRBUILDER_NEW_BRANCH2"
IRBUILDER_NEW_SWITCH = "MU_CI_UVM_IRBUILDER_NEW_SWITCH"
IRBUILDER_NEW_CALL = "MU_CI_UVM_IRBUILDER_NEW_CALL"
IRBUILDER_NEW_TAILCALL = "MU_CI_UVM_IRBUILDER_NEW_TAILCALL"
IRBUILDER_NEW_RET = "MU_CI_UVM_IRBUILDER_NEW_RET"
IRBUILDER_NEW_THROW = "MU_CI_UVM_IRBUILDER_NEW_THROW"
IRBUILDER_NEW_EXTRACTVALUE = "MU_CI_UVM_IRBUILDER_NEW_EXTRACTVALUE"
IRBUILDER_NEW_INSERTVALUE = "MU_CI_UVM_IRBUILDER_NEW_INSERTVALUE"
IRBUILDER_NEW_EXTRACTELEMENT = "MU_CI_UVM_IRBUILDER_NEW_EXTRACTELEMENT"
IRBUILDER_NEW_INSERTELEMENT = "MU_CI_UVM_IRBUILDER_NEW_INSERTELEMENT"
IRBUILDER_NEW_SHUFFLEVECTOR = "MU_CI_UVM_IRBUILDER_NEW_SHUFFLEVECTOR"
IRBUILDER_NEW_NEW = "MU_CI_UVM_IRBUILDER_NEW_NEW"
IRBUILDER_NEW_NEWHYBRID = "MU_CI_UVM_IRBUILDER_NEW_NEWHYBRID"
IRBUILDER_NEW_ALLOCA = "MU_CI_UVM_IRBUILDER_NEW_ALLOCA"
IRBUILDER_NEW_ALLOCAHYBRID = "MU_CI_UVM_IRBUILDER_NEW_ALLOCAHYBRID"
IRBUILDER_NEW_GETIREF = "MU_CI_UVM_IRBUILDER_NEW_GETIREF"
IRBUILDER_NEW_GETFIELDIREF = "MU_CI_UVM_IRBUILDER_NEW_GETFIELDIREF"
IRBUILDER_NEW_GETELEMIREF = "MU_CI_UVM_IRBUILDER_NEW_GETELEMIREF"
IRBUILDER_NEW_SHIFTIREF = "MU_CI_UVM_IRBUILDER_NEW_SHIFTIREF"
IRBUILDER_NEW_GETVARPARTIREF = "MU_CI_UVM_IRBUILDER_NEW_GETVARPARTIREF"
IRBUILDER_NEW_LOAD = "MU_CI_UVM_IRBUILDER_NEW_LOAD"
IRBUILDER_NEW_STORE = "MU_CI_UVM_IRBUILDER_NEW_STORE"
IRBUILDER_NEW_CMPXCHG = "MU_CI_UVM_IRBUILDER_NEW_CMPXCHG"
IRBUILDER_NEW_ATOMICRMW = "MU_CI_UVM_IRBUILDER_NEW_ATOMICRMW"
IRBUILDER_NEW_FENCE = "MU_CI_UVM_IRBUILDER_NEW_FENCE"
IRBUILDER_NEW_TRAP = "MU_CI_UVM_IRBUILDER_NEW_TRAP"
IRBUILDER_NEW_WATCHPOINT = "MU_CI_UVM_IRBUILDER_NEW_WATCHPOINT"
IRBUILDER_NEW_WPBRANCH = "MU_CI_UVM_IRBUILDER_NEW_WPBRANCH"
IRBUILDER_NEW_CCALL = "MU_CI_UVM_IRBUILDER_NEW_CCALL"
IRBUILDER_NEW_NEWTHREAD = "MU_CI_UVM_IRBUILDER_NEW_NEWTHREAD"
IRBUILDER_NEW_SWAPSTACK = "MU_CI_UVM_IRBUILDER_NEW_SWAPSTACK"
IRBUILDER_NEW_COMMINST = "MU_CI_UVM_IRBUILDER_NEW_COMMINST"
@always_inline
def ir_inst(inst, *args, **kwargs):
pass
class Entry(ExtRegistryEntry):
_about_ = ir_inst
def compute_result_annotation(self, s_inst, *s_args, **s_kwds):
s_restype = s_kwds.get('s_restype', None)
if s_restype:
assert s_restype.is_constant()
LLT = s_restype.const
if isinstance(LLT, lltype.Ptr):
return lltype.SomePtr(s_restype.const)
else:
assert LLT == MuID, "Unanticipated result type: %(LLT)s" % locals()
return lltype.SomeInteger(knowntype=LLT._type)
return None
def specialize_call(self, hop, **i_kwds):
hop.exception_cannot_occur()
inst = hop.args_v[0].value
idx_kwds_start = min(min(i_kwds.values()), len(hop.args_v))
i_args = range(1, idx_kwds_start)
args = [hop.inputconst(lltype.Void, inst)]
for idx in i_args:
args.append(hop.inputarg(hop.args_r[idx], idx))
i_restype = i_kwds.get('i_restype', None)
restype = hop.args_v[i_restype].value if i_restype else lltype.Void
metainfo = {}
args.append(hop.inputconst(lltype.Void, metainfo))
return hop.genop('mu_comminst', args, resulttype=restype)
class MuIRBuilder:
def __init__(self):
self._bldr = ir_inst(MuCommInst.IRBUILDER_NEW_IR_BUILDER, restype=IRBuilderRef)
from rpython.rlib.rmu import holstein_meta as rmu
from rpython.translator.interactive import Translation
def test_type_translation():
def main(argv):
bldr = rmu.MuIRBuilder()
# i8 = bldr.gen_sym("@i8")
# bldr.new_type_int(i8, 8)
# stt = bldr.gen_sym("@stt")
# bldr.new_type_struct(stt, [i8], 1)
return 0
t = Translation(main, None, backend='mu')
t.annotate()
# t.view()
t.rtype()
t.view()
# t.mutype()
# t.view()
def test_compile_calls():
from rpython.translator.mu.tool.textgraph import save_graphs
from rpython.rlib.jit import hint
def main(argv):
"""
Builds the following test bundle.
.typedef @i8 = int<8>
.const @0xff_i8 <@i8> = 0xff
.const @0x0a_i8 <@i8> = 0x0a
.funcsig @sig__i8 = () -> (@i8)
.funcdecl @test_fnc <@fnrsig__i8>
.funcdef @test_fnc VERSION @test_fnc_v1 <@sig__i8> {
@test_fnc_v1.blk0():
@test_fnc_v1.blk0.res = ADD <@i8> @0xff_i8 @0x0a_i8
RET @test_fnc_v1.blk0.res
}
"""
hint(0, rmu_meta=True)
mu = rmu.MuVM()
ctx = mu.new_context()
bldr = ctx.new_ir_builder()
i8 = bldr.gen_sym("@i8")
bldr.new_type_int(i8, 8)
c_0xff_i8 = bldr.gen_sym("@0xff_i8")
bldr.new_const_int(c_0xff_i8, i8, 0xff)
c_0x0a_i8 = bldr.gen_sym("@0x0a_i8")
bldr.new_const_int(c_0x0a_i8, i8, 0x0a)
sig__i8 = bldr.gen_sym("@sig__i8")
bldr.new_funcsig(sig__i8, [], [i8])
test_fnc = bldr.gen_sym("@test_fnc")
bldr.new_func(test_fnc, sig__i8)
# function body
v1 = bldr.gen_sym("@test_fnc_v1")
blk0 = bldr.gen_sym("@test_fnc_v1.blk0")
res = bldr.gen_sym("@test_fnc_v1.blk0.res")
op_binop = bldr.gen_sym()
bldr.new_binop(op_binop, res, rmu.MuBinOptr.ADD, i8, c_0xff_i8, c_0x0a_i8)
op_ret = bldr.gen_sym()
bldr.new_ret(op_ret, [res])
bldr.new_bb(blk0, [], [], rmu.MU_NO_ID, [op_binop, op_ret])
bldr.new_func_ver(v1, test_fnc, [blk0])
bldr.load()
hint(0, rmu_meta=False)
return 0
t = Translation(main, None, backend='mu')
t.backendopt(mallocs=True)
save_graphs(t.context.graphs)
......@@ -1259,6 +1259,8 @@ META_REFS_REF = MuRef(META_REFS)
META_MUID = MU_INT32
META_CSTR = MuIRef(MU_INT8)
MUTA_IRBUILDER_REF = MuOpaqueRef('irbuilder')
MU_PREDEF_TYPES = { # predefined types in Mu
META_BYTES: ('@uvm.meta.bytes', mu_int32(0x260)),
META_BYTES_REF: ('@uvm.meta.bytes.r', mu_int32(0x261)),
......
......@@ -324,12 +324,10 @@ def prepare(graphs, entry_graph):
_OPS_KEEP_ALL_ARGS = ('setfield', 'setinteriorfield')
# Returns True if the argument/parameter is to be kept
if 'malloc' in opname:
return True
if 'setfield' in opname:
return True
if arg.concretetype != lltype.Void:
if (opname == 'mu_comminst') or ('malloc' in opname) or \
('setfield' in opname) or (arg.concretetype != lltype.Void):
return True
if isinstance(arg, Constant):
if isinstance(arg.value, (str, list)):
return True
......
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