Ejemplo n.º 1
0
 def opt_backward_copy_propagation(self):
     for i, st in enumerate(self.statements):
         if isinstance(st, Equal):
             lhs, rhs = st.children
             lhs = lhs.children
             if len(lhs) == 1 and isinstance(lhs[0],
                                             Symbol) and rhs.isTemporary():
                 killed = []
                 for oth_st in self.statements[i - 1::-1]:
                     if not isinstance(oth_st, Equal):
                         break  # declare, part, repart, ... no more assignments towards the beginning of the block
                     oth_lhs, oth_rhs = oth_st.lhs(), oth_st.rhs()
                     if contains(oth_lhs, rhs):
                         if len(oth_lhs.children) > 1:
                             break
                         if any([contains(oth_rhs, k) for k in killed]):
                             break
                         #if isinstance( oth_rhs, Predicate ) and pm.DB[oth_rhs.name].overwrite:
                         #print( "Overwrites" )
                         #break
                         if contains(oth_rhs, oth_lhs.children[0]):
                             break
                         st.children[1] = oth_rhs
                         break
                     killed.extend(oth_lhs.children)
                     killed.extend(
                         [ch.st_info[1] for ch in oth_lhs.children])
Ejemplo n.º 2
0
 def analysis_next_use_var(self, var):
     if self.visited:
         return
     self.visited = True
     #
     dead = False
     for i, st in enumerate(self.statements):
         if isinstance(st, lpla.declare):
             continue
         if isinstance(st.rhs(), BaseExpression):
             #rhs_symbols = [n for n in st.rhs().iterate_preorder() if isinstance(n, Symbol)]
             #if any([ var.st_info[1] == n.st_info[1] for n in rhs_symbols ]):
             if contains(st.rhs(), var):
                 yield (self, i)
         else:
             if var in st.rhs():
                 yield (self, i)
         #[FIXME] For now, one single output
         if isinstance(st.lhs(), BaseExpression):
             if contains(st.lhs(), var):
                 dead = True
                 #yield None
                 return
         else:
             for l in st.lhs():
                 if var == l:
                     dead = True
                     #yield None
                     return
     if not dead:
         for n in self.successors:
             for occurrence in n.analysis_next_use_var(var):
                 yield occurrence
Ejemplo n.º 3
0
def compress_tiles(tiled_subpme):
    compressed = []
    for tiles in tiled_subpme:
        compressed.append([])
        i = 0
        while i < len(tiles):
            #for i, tile in enumerate( tiles ):
            tile = tiles[i]
            lhs, rhs = tile.get_children()
            if isinstance(rhs, Predicate):
                compressed[-1].append(copy.deepcopy(tile))
                i += 1
                continue
            replaced = False
            for j, other_tile in enumerate(tiles[i + 1:], start=i + 1):
                olhs, orhs = other_tile.get_children()
                lhs_ch = lhs.get_children()[0]
                if contains(orhs, lhs_ch):
                    new_other = copy.deepcopy(other_tile)
                    #new_other = replace( new_other, [RewriteRule(lhs_ch, Replacement(rhs))] )
                    new_other.children[1] = replace(
                        new_other.rhs(),
                        [RewriteRule(lhs_ch, Replacement(rhs))])
                    tiles[j] = new_other
                    replaced = True
                # if tile lhs = f(rhs) and other_tile overwrites lhs (lhs = f(lhs))
                # stop replacing with "old" lhs
                if lhs_ch in olhs.children:
                    break
            if not replaced:
                compressed[-1].append(copy.deepcopy(tile))
            i += 1
    return compressed
Ejemplo n.º 4
0
    def analysis_next_use(self):
        self.next_use = []
        for i, cur_st in enumerate(self.statements):
            self.next_use.append([])
            if isinstance(cur_st, lpla.declare):
                continue
            dead = False
            for j, oth_st in enumerate(self.statements[i + 1:], start=i + 1):
                if isinstance(oth_st, lpla.declare):
                    continue
                for op in cur_st.lhs():
                    if isinstance(oth_st.rhs(), BaseExpression):
                        if contains(oth_st.rhs(), op):
                            self.next_use[-1].append((self, j))
                            break
                    else:
                        #if op in oth_st.rhs():
                        try:
                            _ = op.st_info
                            if any([
                                    op.st_info[1] == other
                                    for other in oth_st.rhs()
                            ]):
                                self.next_use[-1].append((self, j))
                                break
                        except AttributeError:
                            if op in oth_st.rhs():
                                self.next_use[-1].append((self, j))
                                break

                #[FIXME] For now, one single output
                for op in cur_st.lhs():
                    if op in oth_st.lhs():
                        dead = True
                        break
                if dead:
                    break
            if not dead and self.successors:
                for op in cur_st.lhs():
                    self.graph.clear_visited()
                    for n in self.successors:
                        for occurrence in n.analysis_next_use_var(op):
                            self.next_use[-1].append(occurrence)
Ejemplo n.º 5
0
 def opt_copy_propagation(self):
     for i, st in enumerate(self.statements):
         if isinstance(st, Equal):
             lhs, rhs = st.children
             lhs = lhs.children
             if len(lhs) == 1 and lhs[0].isTemporary() and isinstance(
                     st.rhs(), Symbol):
                 for oth_st in self.statements[i + 1:]:
                     if not isinstance(
                             oth_st, Equal
                     ):  #[CHECK] Careful. Not the case, but generally speaking could be some part/repart
                         continue
                     oth_lhs, oth_rhs = oth_st.lhs(), oth_st.rhs()
                     if contains(oth_rhs, lhs[0]):
                         #\ and not (isinstance( oth_rhs, Predicate ) and pm.DB[oth_rhs.name].overwrite): #[FIXME] Can be less restrictive
                         new_rhs = replace(
                             oth_rhs,
                             [RewriteRule(lhs[0], Replacement(rhs))])
                         oth_st.children[1] = new_rhs
                     if oth_lhs.children[0] == lhs[0] or oth_lhs == rhs:
                         break