def processTypeSwitch(self, node): g = graph.GenericOp(self.hyperblock(), node) g.setPredicate(self.pred()) self.localRead(g, node.conditional) for i in range(len(node.cases)): p = graph.PredicateNode(self.hyperblock(), i) g.predicates.append(p.addDefn(g)) branches = self.branch(g.predicates) exits = [] for case, branch in zip(node.cases, branches): self.setState(branch) if case.expr: target = self.localTarget(case.expr) self.set(case.expr, target) else: target = None g.addLocalModify(case.expr, target) self(case.body) exits.append(self.popState()) self.mergeStates(exits)
def processAllocate(self, node): g = graph.GenericOp(self.hyperblock(), node) g.setPredicate(self.pred()) self.localRead(g, node.expr) self.handleMemory(node, g) return g
def makeStoreOp(dataflow, hyperblock, predicate, exprNode, field, valueNode): name = ast.Existing(field.name) op = ast.Store(exprNode.names[0], field.type, name, valueNode.names[0]) g = graph.GenericOp(hyperblock, op) g.setPredicate(predicate) g.addLocalRead(exprNode.names[0], exprNode) g.addLocalRead(name, dataflow.getExisting(name)) g.addLocalRead(valueNode.names[0], valueNode) return g
def processDirectCall(self, node): g = graph.GenericOp(self.hyperblock(), node) g.setPredicate(self.pred()) self.localRead(g, node.selfarg) for arg in node.args: self.localRead(g, arg) self.localRead(g, node.vargs) self.localRead(g, node.kargs) self.handleMemory(node, g) return g
def makeLoadOp(dataflow, hyperblock, predicate, root, field): if isinstance(root, graph.LocalNode): expr = root.names[0] else: assert isinstance(root, graph.ExistingNode) expr = root.name # Create the dataflow load name = ast.Existing(field.name) nameref = field.name # HACK incorrect op = ast.Load(expr, field.type, name) g = graph.GenericOp(hyperblock, op) g.setPredicate(predicate) g.addLocalRead(expr, root) g.addLocalRead(name, dataflow.getExisting(name, nameref)) return g
def allocateObj(dioa, dataflow, subtree, slot, obj): hyperblock = dataflow.entry.hyperblock predicate = dataflow.entryPredicate objs = slot.annotation.values.flat # Allocate assert len(objs) == 1 obj = tuple(objs)[0] cls = ast.Existing(obj.xtype.obj.type) allocate = ast.Allocate(cls) g = graph.GenericOp(hyperblock, allocate) g.setPredicate(predicate) g.addLocalRead(cls, dataflow.getExisting(cls, obj)) # TODO mask? setOpAnnotation(dioa, g, allocate=dioa.set.leaf((obj, ))) return addOutput(g, subtree, slot)
def processGenericOp(self, g): result = graph.GenericOp(g.hyperblock, g.op) pred = self(g.predicate, 0) result.setPredicate(pred) trace = False if trace: print "!!!!", g.op for p in g.predicates: newp = self(p, 0) result.predicates.append(newp.addDefn(result)) for name, node in g.localReads.iteritems(): result.addLocalRead(name, self(node, 0)) for node in g.localModifies: result.addLocalModify(None, self(node, 0)) reads = self.dioa.set.flatten(self.dioa.opReads[g]) modifies = self.dioa.set.flatten(self.dioa.opModifies[g]) if trace: print "READ ", reads print "MODIFY", modifies for name, node in g.heapReads.iteritems(): node = node.canonical() for index in self.iterFieldIndexes(name): if (node, index) in reads: newname, newnode = self(node, index, name) result.addRead(newname, newnode) else: if trace: print "kill read", node, index for name, node in g.heapPsedoReads.iteritems(): node = node.canonical() modnode = g.heapModifies[name].canonical() for index in self.iterFieldIndexes(name): if (modnode, index) in modifies: newname, newnode = self(node, index, name) # HACK a pseudo read for field on a unique, allocated object can be eliminated if it resolves to the entry. if newnode.isEntryNode(): obj = node.name.object unique = self.dioa.isUniqueObject(obj, index) allocated = not self.dioa.objectIsPreexisting(obj, index) if unique and allocated: newnode = self.dout.null result.addPsedoRead(newname, newnode) else: self.connect(name, node, modnode, index) if trace: print "bypass", node, index for name, node in g.heapModifies.iteritems(): node = node.canonical() for index in self.iterFieldIndexes(name): if (node, index) in modifies: newname, newnode = self(node, index, name) result.addModify(newname, newnode) else: if trace: print "kill mod", node, index if trace: print self.translateOpAnnotations(g, result)