Changeset 2690 for proto/Compiler


Ignore:
Timestamp:
Nov 25, 2012, 7:59:49 AM (6 years ago)
Author:
cameron
Message:

Restructure CarryInfoSetVisitor?, add block child info.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r2689 r2690  
    7979#
    8080class CarryInfoSetVisitor(ast.NodeVisitor):
    81   def __init__(self):
    82     self.operation_no = 0
     81  def __init__(self, streamFunctionNode):
     82    (self.operation_count, self.block_count) = (0, 0)
     83    (self.block_first_op, self.block_op_count, self.advance_amount) = ({}, {}, {})
     84    self.init_one_list = []
     85    (self.parent_block, self.children) = ({}, {})
     86    (self.carry_count, self.adv_n_count, self.adv_1_count) = (0, 0, 0)
     87    (self.total_advance, self.max_advance) = (0, 0)
     88
     89    # Initialize for the main block
    8390    self.block_no = 0
    84     self.next_block_no = 1
    85    
    86     self.parent_block = {}
    87     self.block_first_op = {}
    88     self.block_op_count = {}
    89     self.advance_amount = {}
    90     self.init_one_list = []
    91     self.carry_count = 0
    92     self.adv_n_count = 0
    93     self.adv_1_count = 0
    94     self.total_advance = 0
    95     self.max_advance = 0
     91    self.block_count += 1
     92    self.children[0] = []
     93    self.block_first_op[0] = 0
     94    # Recursively process all blocks
     95    self.generic_visit(streamFunctionNode)
     96    self.block_op_count[0] = self.operation_count
    9697
    9798  def visit_Call(self, callnode):
     
    100101    if builtin == None: return
    101102    if isCarryGenerating(builtin):
    102       if usesCarryInit1(builtin): self.init_one_list.append(self.operation_no)
    103       self.operation_no += 1
     103      if usesCarryInit1(builtin): self.init_one_list.append(self.operation_count)
     104      self.operation_count += 1
    104105      self.carry_count += 1
    105106    elif isAdvance(builtin):
     
    110111        adv_amount = 1
    111112        self.adv_1_count += 1
    112       self.advance_amount[self.operation_no] = adv_amount
     113      self.advance_amount[self.operation_count] = adv_amount
    113114      self.total_advance += adv_amount
    114115      if adv_amount > self.max_advance: self.max_advance = adv_amount
    115       self.operation_no += 1
     116      self.operation_count += 1
    116117    else: return
    117118
    118   def visit_If(self, ifNode):
    119     this_block_no = self.next_block_no
    120     self.next_block_no += 1
    121     self.parent_block[this_block_no] = self.block_no
     119  def block_visit(self, blkNode):
     120    prnt = self.block_no
     121    this_block_no = self.block_count
     122    self.block_count += 1
     123    self.parent_block[this_block_no] = prnt
     124    self.children[prnt].append(this_block_no)
    122125    self.block_no = this_block_no
    123     self.block_first_op[this_block_no] = self.operation_no
    124     self.generic_visit(ifNode)
    125     self.block_op_count[this_block_no] = self.operation_no - self.block_first_op[this_block_no]
     126    self.block_first_op[this_block_no] = self.operation_count
     127    self.children[this_block_no] = []
     128    self.generic_visit(blkNode)
     129    self.block_op_count[this_block_no] = self.operation_count - self.block_first_op[this_block_no]
    126130    # reset for processing remainder of parent
    127131    self.block_no = self.parent_block[this_block_no]
     132
     133
     134  def visit_If(self, ifNode): 
     135    self.block_visit(ifNode)
    128136 
    129   def visit_While(self, whileNode):
    130     this_block_no = self.next_block_no
    131     self.next_block_no += 1
    132     self.parent_block[this_block_no] = self.block_no
    133     self.block_no = this_block_no
    134     self.block_first_op[this_block_no] = self.operation_no
    135     self.generic_visit(whileNode)
    136     self.block_op_count[this_block_no] = self.operation_no - self.block_first_op[this_block_no]
    137     # reset
    138     self.block_no = self.parent_block[this_block_no]
    139    
    140   def getInfoSet(self, nodeToVisit):
    141     self.operation_no = 0
    142     self.block_no = 0
    143     self.next_block_no = 1
    144    
    145     self.parent_block = {}
    146     self.block_first_op = {}
    147     self.block_op_count = {}
    148     self.advance_amount = {}
    149     self.init_one_list = []
    150    
    151     self.generic_visit(nodeToVisit)
    152     self.block_first_op[0] = 0
    153     self.block_op_count[0] = self.operation_no
    154     self.carry_count = 0
    155     self.adv_n_count = 0
    156     self.adv_1_count = 0
    157     self.total_advance = 0
    158     self.max_advance = 0
    159     return self
     137  def visit_While(self, whileNode):   
     138    self.block_visit(whileNode)
    160139
    161140  def countBlockCarrysWithAdv1(self, blk):
     
    526505        self.operation_offset = 0
    527506        carry_counter = 0
    528         for op_no in range(carryInfoSet.operation_no):
     507        for op_no in range(carryInfoSet.operation_count):
    529508          self.carryIndex[op_no] = carry_counter
    530509          if not op_no in carryInfoSet.advance_amount.keys(): carry_counter += 1
    531510          elif carryInfoSet.advance_amount[op_no] == 1: carry_counter += 1
    532511        # Add a dummy entry for any possible final block that is empty.
    533         self.carryIndex[carryInfoSet.operation_no] = carry_counter
     512        self.carryIndex[carryInfoSet.operation_count] = carry_counter
    534513    # Helper
    535514    def CarryGroupAtt(self, attname, CarryGroupVarName=""):
     
    610589  def xfrm_fndef(self, fndef):
    611590    self.block_no = 0
    612     self.operation_no = 0
     591    self.operation_count = 0
    613592    self.current_carry = 0
    614593    self.current_adv_n = 0
     
    618597  def xfrm_fndef_final(self, fndef):
    619598    self.block_no = 0
    620     self.operation_no = 0
     599    self.operation_count = 0
    621600    self.carryout = ""
    622601    self.current_carry = 0
     
    630609  def generic_xfrm(self, node):
    631610    self.block_no = 0
    632     self.operation_no = 0
     611    self.operation_count = 0
    633612    self.current_carry = 0
    634613    self.current_adv_n = 0
     
    642621   
    643622  def local_while_xfrm(self, local_carryvar, whileNode):
    644     saved_state = (self.block_no, self.operation_no, self.carryvar, self.carryin, self.carryout, self.current_carry, self.current_adv_n)
     623    saved_state = (self.block_no, self.operation_count, self.carryvar, self.carryin, self.carryout, self.current_carry, self.current_adv_n)
    645624    (self.carryvar, self.carryin, self.current_carry, self.current_adv_n) = (local_carryvar, '', 0, 0)
    646     self.ccgo.EnterLocalWhileBlock(self.operation_no);
     625    self.ccgo.EnterLocalWhileBlock(self.operation_count);
    647626    inner_while = self.generic_visit(whileNode)
    648627    self.ccgo.ExitLocalWhileBlock();
    649     (self.block_no, self.operation_no, self.carryvar, self.carryin, self.carryout, self.current_carry, self.current_adv_n) = saved_state
     628    (self.block_no, self.operation_count, self.carryvar, self.carryin, self.carryout, self.current_carry, self.current_adv_n) = saved_state
    650629    return inner_while
    651630   
     
    790769    #elif f == 'ScanThru':
    791770            if self.carryin == "_ci":
    792                 carry_in_expr = self.ccgo.GenerateCarryInAccess(self.operation_no)
     771                carry_in_expr = self.ccgo.GenerateCarryInAccess(self.operation_count)
    793772            else:
    794773                carry_in_expr = mkCall('simd<1>::constant<0>', [])
     
    803782               pablo_routine_call = mkCall('pablo_blk_' + f, assigNode.value.args + [carry_in_expr, assigNode.targets[0]])
    804783            self.last_stmt = pablo_routine_call
    805             compiled = self.ccgo.GenerateCarryOutStore(self.operation_no, pablo_routine_call)
    806             self.operation_no += 1
     784            compiled = self.ccgo.GenerateCarryOutStore(self.operation_count, pablo_routine_call)
     785            self.operation_count += 1
    807786            self.current_carry += 1
    808787            return compiled
     
    810789            self.generic_visit(assigNode)
    811790            self.last_stmt = assigNode
    812             self.operation_no += 1
     791            self.operation_count += 1
    813792            return assigNode
    814793           
     
    12701249    self.main_carry_count = CarryCounter().count(self.main_node)
    12711250    self.main_adv_n_count = adv_nCounter().count(self.main_node)
    1272     self.main_carry_info_set = CarryInfoSetVisitor().getInfoSet(self.main_node)
     1251    self.main_carry_info_set = CarryInfoSetVisitor(self.main_node)
    12731252    self.main_ccgo = Strategic_CCGO_Factory(self.main_carry_info_set)
    12741253    assert self.main_adv_n_count == 0, "Advance32() in main not supported.\n"
     
    12811260                stream_function.init_to_one_list = CarryInitToOneList().count(node)
    12821261                stream_function.adv_n_count = adv_nCounter().count(node)
    1283                 carry_info_set = CarryInfoSetVisitor().getInfoSet(node)
     1262                carry_info_set = CarryInfoSetVisitor(node)
    12841263                stream_function.ccgo = Strategic_CCGO_Factory(carry_info_set)
    12851264                stream_function.type_name = node.name[0].upper() + node.name[1:]
     
    13861365    Bitwise_to_SIMD().xfrm(self.main_node)
    13871366    final_block_main = copy.deepcopy(self.main_node)
    1388     carry_info_set = CarryInfoSetVisitor().getInfoSet(self.main_node)
     1367    carry_info_set = CarryInfoSetVisitor(self.main_node)
    13891368    ccgo = Strategic_CCGO_Factory(carry_info_set)
    13901369    CarryIntroVisitor = CarryIntro(ccgo)
Note: See TracChangeset for help on using the changeset viewer.