Exemple #1
0
    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
Exemple #2
0
	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
Exemple #3
0
	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
Exemple #4
0
    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
Exemple #5
0
	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 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)
Exemple #7
0
	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
Exemple #8
0
    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
Exemple #9
0
    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