def helper(self, target, id): syms = st.gatherSymbols(target) newtarget = du.genDPatTuple([dha.PatVar(s, dha.P_UNKNOWN) for s in syms]) # Generate wildcard comprehension. elt = du.genDTuple([dha.Name(s) for s in syms]) enumtarget = dka.copy(target) st.cleanPatterns(enumtarget) WildcardFiller().run(enumtarget) enum = dha.RelEnum(enumtarget, id) comp = dha.RelSetComp(elt, [enum], [], dka.Symtab()) num = next(wildcard_uid) repldict = {s: dha.VSymbol(s.name + '_W' + num) for s in syms} st.replaceSymbols(comp, repldict) newid = dha.VSymbol(id.name + '_W' + num) invdef = dha.InvDef(newid, comp) ### Need a more robust way to do this part. oldccb = self.code_callback newccb = \ (lambda ccb: oldccb(ccb) + [invdef] if ccb is self.CCB_NORMAL or ccb is self.CCB_LOOP_ENTRY else []) return newtarget, newid, newccb
def run(self, node): self.bounds = [] self.unbounds = [] mask = super().run(node) bounds = du.genDTuple(self.bounds) unbounds = du.genDPatTuple(self.unbounds) return mask, bounds, unbounds
def visit_PatMatchName(self, node): self.generic_visit(node) id = node.iter info = id.info params = info.enumparams if len(params) > 0: paramtup = du.genDPatTuple([dha.genBoundVar(sym) for sym in params]) newtarget = dha.PatTuple([paramtup, dka.copy(node.target)]) node.target = newtarget else: pass
def visit_RelEnum(self, node): self.generic_visit(node) id = node.iter if not id.hasflag(dha.FLAG_INV): return info = id.info params = info.enumparams if len(params) > 0: paramtup = du.genDPatTuple([dha.genBoundVar(sym) for sym in params]) newtarget = dha.PatTuple([paramtup, dka.copy(node.target)]) node.target = newtarget else: pass
def genHandler(self, setparam, isaddition): compnode = self.compnode code = [] # Compute differential assignment set. for i, enum in enumerate(compnode.enums): if enum.iter is setparam: code.extend(self.genDSetBlock(i)) # Compute change to result set. vartup = du.genDPatTuple([s for s in enumvars]) match = dha.PatMatchName(vartup, self.diffsym) resexpr = dka.copy(compnode.elt) # update = dha.SetUpdate(self.resmapsym, dha.UpAddNS(), resexpr) update = dha.SetUpdate(self.resmapsym, dha.UpAdd(), resexpr) loop = dha.For(match, dha.Block([update])) code.extend([loop])
def genTagInfo(comp): info = comp.info compnode = comp.getCompNode() uset = info.uset if uset is None: return enums = compnode.enums assert(enums[0].iter is uset) rootsyms = set(st.gatherSymbols(enums[0].target)) unconsparams = info.unconsparams assert(rootsyms == set(unconsparams)) taginfo = TagInfo() info.taginfo = taginfo taginfo.compinfo = info pairenums = enums[1:] taginfo.As = As = [] taginfo.Bs = Bs = [] taginfo.Rs = Rs = [] taginfo.DRs = DRs = [] for i, enum in enumerate(pairenums): dka.assertnodetype(enum.target, dha.PatTuple) elts = enum.target.elts assert(len(elts) == 2) dka.assertnodetype(elts[0], dha.PatVar) dka.assertnodetype(elts[1], dha.PatVar) cont, elem = elts[0].id, elts[1].id rel = enum.iter As.append(cont) Bs.append(elem) Rs.append(rel) demrel = TagSym('Dm_' + info.compsym.id + '_' + str(i+1)) DRs.append(demrel) taginfo.tagcomps = tagcomps = [] # Generate auxiliary demand comprehensions. for i, (a, b, r, dr) in enumerate(zip(As, Bs, Rs, DRs)): tagenums = [] # Add U pred. if a in unconsparams: k = unconsparams.index(a) ig1 = [dha.PatIgnore() for z in range(0, i)] ig2 = [dha.PatIgnore() for z in range(i+1, len(unconsparams))] tup = du.genDPatTuple(ig1 + [dha.genUnboundVar(a)] + ig2) e = dha.Enum(tup, uset) tagenums.append(e) # Add other preds. for a2, b2, r2, dr2 in list(zip(As, Bs, Rs, DRs))[:i]: if b2 is a: tup = dha.PatTuple([dha.PatIgnore(), dha.genUnboundVar(b2)]) e = dha.Enum(tup, dr2) tagenums.append(e) # Add orig relation. assert(len(tagenums) > 0) tup = dha.PatTuple([dha.genUnboundVar(a), dha.genUnboundVar(b)]) e = dha.Enum(tup, r) tagenums.append(e) comp = dha.SetComp(dha.Tuple([dha.Name(a), dha.Name(b)]), tagenums, None, dka.Symtab()) instmapping = {s: dha.VSymbol(s.name + '_t' + str(i)) for s in set(As) | set(Bs)} st.replaceSymbols(comp, instmapping) compdef = dha.SetCompDef(dr, comp) tagcomps.append(compdef) return taginfo