comparison python/mem2reg.py @ 261:444b9df2ed99

try to split up code generation
author Windel Bouwman
date Fri, 09 Aug 2013 09:05:13 +0200
parents 74c6a20302d5
children 534b94b40aa8
comparison
equal deleted inserted replaced
260:b2f94b4951f1 261:444b9df2ed99
3 from ir import * 3 from ir import *
4 4
5 def isAllocPromotable(allocinst): 5 def isAllocPromotable(allocinst):
6 # Check if alloc value is only used by load and store operations. 6 # Check if alloc value is only used by load and store operations.
7 assert type(allocinst) is Alloc 7 assert type(allocinst) is Alloc
8 return all(type(use) in [Load,Store] for use in allocinst.value.used_by) 8 return all(type(use) in [Load, Store] for use in allocinst.value.used_by)
9 9
10 class Mem2RegPromotor(FunctionPass): 10 class Mem2RegPromotor(FunctionPass):
11 def promoteSingleBlock(self, ai): 11 def promoteSingleBlock(self, ai):
12 v = ai.value 12 v = ai.value
13 bb = ai.Block 13 bb = ai.Block
22 idx = load.Position 22 idx = load.Position
23 # Search upwards: 23 # Search upwards:
24 for store in stores: 24 for store in stores:
25 if store.Position < load.Position: 25 if store.Position < load.Position:
26 break 26 break
27 for use_ins in load.value.used_by: 27 load.value.replaceby(store.value)
28 use_ins.replaceValue(load.value, store.value)
29 assert not load.value.Used
30 logging.debug('replaced {} with {}'.format(load, store.value)) 28 logging.debug('replaced {} with {}'.format(load, store.value))
31 bb.removeInstruction(load) 29 bb.removeInstruction(load)
32 30
33 # Remove store instructions: 31 # Remove store instructions:
34 for store in stores: 32 for store in stores: