コード例 #1
0
	def processCode(self, code, simplify):
		signatures = self.generateSignatures(code)
		replace = self.generateReplacements(signatures)

		if simplify:
			rewrite.rewriteAndSimplify(self.compiler, self.prgm, code, replace)
		else:
			rewrite.rewrite(self.compiler, code, replace)

		return self.eliminated
コード例 #2
0
    def processCode(self, code, simplify):
        signatures = self.generateSignatures(code)
        replace = self.generateReplacements(signatures)

        if simplify:
            rewrite.rewriteAndSimplify(self.compiler, self.prgm, code, replace)
        else:
            rewrite.rewrite(self.compiler, code, replace)

        return self.eliminated
コード例 #3
0
def evaluate(compiler, prgm, simplify=False):
    with compiler.console.scope('dead store elimination'):
        live = set()
        stores = collections.defaultdict(list)

        # Analysis pass
        for code in prgm.liveCode:
            live.update(code.annotation.codeReads[0])

            for op in codeOps(code):
                live.update(op.annotation.reads[0])
                if isinstance(op, ast.Store):
                    stores[code].append(op)

        # Transform pass
        totalEliminated = 0

        for code in prgm.liveCode:
            if not code.isStandardCode() or code.annotation.descriptive:
                continue

            replace = {}
            eliminated = 0

            # Look for dead stores
            for store in stores[code]:
                for modify in store.annotation.modifies[0]:
                    if modify in live: break
                    if modify.object.leaks: break
                else:
                    replace[store] = []
                    eliminated += 1

            # Rewrite the code without the dead stores
            if replace:
                compiler.console.output('%r %d' % (code, eliminated))

                if simplify:
                    rewrite.rewriteAndSimplify(compiler, prgm, code, replace)
                else:
                    rewrite.rewrite(compiler, code, replace)

            totalEliminated += eliminated

        return totalEliminated > 0
コード例 #4
0
def evaluate(compiler, prgm, simplify=False):
	with compiler.console.scope('dead store elimination'):
		live = set()
		stores = collections.defaultdict(list)

		# Analysis pass
		for code in prgm.liveCode:
			live.update(code.annotation.codeReads[0])

			for op in codeOps(code):
				live.update(op.annotation.reads[0])
				if isinstance(op, ast.Store):
					stores[code].append(op)

		# Transform pass
		totalEliminated = 0

		for code in prgm.liveCode:
			if not code.isStandardCode() or code.annotation.descriptive: continue

			replace = {}
			eliminated = 0

			# Look for dead stores
			for store in stores[code]:
				for modify in store.annotation.modifies[0]:
					if modify in live: break
					if modify.object.leaks: break
				else:
					replace[store] = []
					eliminated += 1

			# Rewrite the code without the dead stores
			if replace:
				compiler.console.output('%r %d' % (code, eliminated))

				if simplify:
					rewrite.rewriteAndSimplify(compiler, prgm, code, replace)
				else:
					rewrite.rewrite(compiler, code, replace)

			totalEliminated += eliminated

		return totalEliminated > 0