def collectRMA(self, code, contexts, op): creads = [ annotations.annotationSet(self.opReads[(code, op, context)]) for context in contexts ] reads = annotations.makeContextualAnnotation(creads) cmodifies = [ annotations.annotationSet(self.opModifies[(code, op, context)]) for context in contexts ] modifies = annotations.makeContextualAnnotation(cmodifies) callocates = [ annotations.annotationSet(self.opAllocates[(code, op, context)]) for context in contexts ] allocates = annotations.makeContextualAnnotation(callocates) reads = self.annotationCache.setdefault(reads, reads) modifies = self.annotationCache.setdefault(modifies, modifies) allocates = self.annotationCache.setdefault(allocates, allocates) self.annotationCount += 3 return reads, modifies, allocates
def collectRMA(self, code, contexts, op): creads = [annotations.annotationSet(self.opReads[(code, op, context)]) for context in contexts] reads = annotations.makeContextualAnnotation(creads) cmodifies = [annotations.annotationSet(self.opModifies[(code, op, context)]) for context in contexts] modifies = annotations.makeContextualAnnotation(cmodifies) callocates = [annotations.annotationSet(self.opAllocates[(code, op, context)]) for context in contexts] allocates = annotations.makeContextualAnnotation(callocates) reads = self.annotationCache.setdefault(reads, reads) modifies = self.annotationCache.setdefault(modifies, modifies) allocates = self.annotationCache.setdefault(allocates, allocates) self.annotationCount += 3 return reads, modifies, allocates
def collectContexts(self, lut, contexts): cdata = [annotations.annotationSet(lut[context]) for context in contexts] data = annotations.makeContextualAnnotation(cdata) data = self.annotationCache.setdefault(data, data) self.annotationCount += 1 return data
def collectContexts(self, lut, contexts): cdata = [ annotations.annotationSet(lut[context]) for context in contexts ] data = annotations.makeContextualAnnotation(cdata) data = self.annotationCache.setdefault(data, data) self.annotationCount += 1 return data
def transferReferences(self, src, field, dst): refs = src.annotation.references cout = [] for cindex, context in enumerate(self.code.annotation.contexts): values = set() for ref in refs[1][cindex]: values.update(ref.knownField(field)) cout.append(annotations.annotationSet(values)) refs = annotations.makeContextualAnnotation(cout) dst.rewriteAnnotation(references=refs)
def transferOpInfo(self, node, rewrite): invokes = node.annotation.invokes if invokes is not None: cinvokesNew = [] for cinvokes in invokes[1]: cinvokesM = set() for f, c in cinvokes: newinv = self.pattern.invokeLUT[(f, c)] cinvokesM.update(newinv) cinvokesNew.append(annotations.annotationSet(cinvokesM)) invokes = annotations.makeContextualAnnotation(cinvokesNew) rewrite.annotation = node.annotation.rewrite(invokes=invokes) else: rewrite.annotation = node.annotation
def buildInvokeLUT(self): self.invokeLUT = {} for code, context in self.mcallsC: cindex = code.annotation.contexts.index(context) op = opThatInvokes(code) targets = op.annotation.invokes[1][cindex] self.invokeLUT[(code, context)] = targets for code, context in self.icallsC: cindex = code.annotation.contexts.index(context) op = opThatInvokes(code) targets = op.annotation.invokes[1][cindex] reach = set() for target in targets: reach.update(self.invokeLUT[target]) self.invokeLUT[(code, context)] = annotations.annotationSet(reach)
def createDB(self, compiler, prgm): self.annotationCount = 0 self.annotationCache = {} readDB = self.rm.opReadDB modifyDB = self.rm.opModifyDB self.allocations = self.rm.allocations for code in prgm.liveCode: # Annotate the code live = [] killed = [] for cindex, context in enumerate(code.annotation.contexts): key = (code, context) live.append(annotations.annotationSet(self.live[key])) killed.append(annotations.annotationSet(self.contextKilled[key])) code.rewriteAnnotation( live=annotations.makeContextualAnnotation(live), killed=annotations.makeContextualAnnotation(killed) ) # Annotate the ops ops, lcls = getOps(code) for op in ops: # TODO is this a good HACK? # if not op.annotation.invokes[0]: continue reads = readDB[code][op] modifies = modifyDB[code][op] rout = [] mout = [] aout = [] for cindex, context in enumerate(code.annotation.contexts): # HACK if an operation directly reads a field, but it is never modified # it still must appear in the reads annotation so cloning behaves correctly! reads.merge(context, op.annotation.opReads[1][cindex]) creads = reads[context] creads = annotations.annotationSet(creads) if creads else () rout.append(creads) cmod = modifies[context] cmod = annotations.annotationSet(cmod) if cmod else () mout.append(cmod) kills = self.killed[(code, op, context)] calloc = set() for dstCode, dstContext in op.annotation.invokes[1][cindex]: live = self.live[(dstCode, dstContext)] killed = kills[(dstCode, dstContext)] calloc.update(live - killed) calloc.update(op.annotation.opAllocates[1][cindex]) aout.append(annotations.annotationSet(calloc)) opReads = annotations.makeContextualAnnotation(rout) opModifies = annotations.makeContextualAnnotation(mout) opAllocates = annotations.makeContextualAnnotation(aout) opReads = self.annotationCache.setdefault(opReads, opReads) opModifies = self.annotationCache.setdefault(opModifies, opModifies) opAllocates = self.annotationCache.setdefault(opAllocates, opAllocates) self.annotationCount += 3 op.rewriteAnnotation(reads=opReads, modifies=opModifies, allocates=opAllocates) compiler.console.output( "Annotation compression %f - %d" % (float(len(self.annotationCache)) / max(self.annotationCount, 1), self.annotationCount) ) del self.annotationCache del self.annotationCount
def createDB(self, compiler, prgm): self.annotationCount = 0 self.annotationCache = {} readDB = self.rm.opReadDB modifyDB = self.rm.opModifyDB self.allocations = self.rm.allocations for code in prgm.liveCode: # Annotate the code live = [] killed = [] for cindex, context in enumerate(code.annotation.contexts): key = (code, context) live.append(annotations.annotationSet(self.live[key])) killed.append( annotations.annotationSet(self.contextKilled[key])) code.rewriteAnnotation( live=annotations.makeContextualAnnotation(live), killed=annotations.makeContextualAnnotation(killed)) # Annotate the ops ops, lcls = getOps(code) for op in ops: # TODO is this a good HACK? # if not op.annotation.invokes[0]: continue reads = readDB[code][op] modifies = modifyDB[code][op] rout = [] mout = [] aout = [] for cindex, context in enumerate(code.annotation.contexts): # HACK if an operation directly reads a field, but it is never modified # it still must appear in the reads annotation so cloning behaves correctly! reads.merge(context, op.annotation.opReads[1][cindex]) creads = reads[context] creads = annotations.annotationSet(creads) if creads else ( ) rout.append(creads) cmod = modifies[context] cmod = annotations.annotationSet(cmod) if cmod else () mout.append(cmod) kills = self.killed[(code, op, context)] calloc = set() for dstCode, dstContext in op.annotation.invokes[1][ cindex]: live = self.live[(dstCode, dstContext)] killed = kills[(dstCode, dstContext)] calloc.update(live - killed) calloc.update(op.annotation.opAllocates[1][cindex]) aout.append(annotations.annotationSet(calloc)) opReads = annotations.makeContextualAnnotation(rout) opModifies = annotations.makeContextualAnnotation(mout) opAllocates = annotations.makeContextualAnnotation(aout) opReads = self.annotationCache.setdefault(opReads, opReads) opModifies = self.annotationCache.setdefault( opModifies, opModifies) opAllocates = self.annotationCache.setdefault( opAllocates, opAllocates) self.annotationCount += 3 op.rewriteAnnotation(reads=opReads, modifies=opModifies, allocates=opAllocates) compiler.console.output( "Annotation compression %f - %d" % (float(len(self.annotationCache)) / max(self.annotationCount, 1), self.annotationCount)) del self.annotationCache del self.annotationCount