C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

mergepoints.cc

Go to the documentation of this file.
00001 // $Id: mergepoints.cc,v 1.9 2003/08/07 23:14:26 pnav Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2000 University of Texas at Austin
00008 // 
00009 //  Samuel Z. Guyer
00010 //  Daniel A. Jimenez
00011 //  Calvin Lin
00012 // 
00013 //  Permission is hereby granted, free of charge, to any person
00014 //  obtaining a copy of this software and associated documentation
00015 //  files (the "Software"), to deal in the Software without
00016 //  restriction, including without limitation the rights to use, copy,
00017 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00018 //  of the Software, and to permit persons to whom the Software is
00019 //  furnished to do so, subject to the following conditions:
00020 //  
00021 //  The above copyright notice and this permission notice shall be
00022 //  included in all copies or substantial portions of the Software.
00023 //  
00024 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00028 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00029 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00030 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00031 //  THE SOFTWARE.
00032 //
00033 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00034 //  Computer Science for inspiring parts of the C-Breeze design.
00035 //
00036 // ----------------------------------------------------------------------
00037 
00038 #include "c_breeze.h"
00039 #include <algorithm>
00040 #include "mergepoints.h"
00041 
00042 // --- find_merge_points : Essentially, perform an interprocedural
00043 // version of dominance frontiers. Look for a dominance frontier in
00044 // the current procedure; if there is none, move up to the calling
00045 // procedure.
00046 
00047 void mergePoints::find_merge_points(basicblockLocation * where,
00048                                     mergepoint_list & merge_points)
00049 {
00050   basicblockLocation * cur = where;
00051   procLocation * proc_loc;
00052   procNode * cur_proc;
00053   bool found = false;
00054 
00055   // --- Move up the call stack until we find a dominance frontier
00056 
00057   while ( cur && ! found ) {
00058 
00059     // --- Check to see if the given proc has a dominance frontier entry.
00060 
00061     proc_loc = cur->proc_location();
00062     cur_proc = proc_loc->proc();
00063     procedureInfo * info = Procedures->lookup(cur_proc);
00064     DFPreds * dfs = info->dominance_frontiers();
00065 
00066     basicblock_set_map_map_p p = dfs->find(cur->block());
00067     if (p != dfs->end()) {
00068 
00069       // --- Found one: get the list of DF blocks and make sure it's
00070       // not empty.
00071 
00072       basicblock_set_map & df = (*p).second;
00073 
00074       if ( ! df.empty()) {
00075 
00076         found = true;
00077 
00078         // --- Put each entry on the list
00079 
00080         for (basicblock_set_map_p q = df.begin();
00081              q != df.end();
00082              ++q)
00083           {
00084             basicblockNode * bb = (*q).first;
00085             basicblock_set & preds = (*q).second;
00086             basicblockLocation * bblock = proc_loc->lookup_block(bb);
00087 
00088             merge_points.push_back(mergepoint_pair(bblock, preds));
00089           }
00090       }
00091     }
00092 
00093     if (proc_loc->stmt_location())
00094       cur = proc_loc->stmt_location()->block_location();
00095     else
00096       cur = 0;
00097   }
00098 }
00099 
00100 // --- Add a block to the list of blocks that need to be merged at
00101 // the given merge point.
00102 
00103 void mergePoints::add_block_to_merge_point(mergepoint_pair & merge_point,
00104                                            memoryBlock * block)
00105 {
00106   basicblockLocation * merge_location = merge_point.first;
00107 
00108   // --- Look up the merge point
00109 
00110   mergepoint_map_p existing = find(merge_location);
00111   if (existing == end()) {
00112 
00113     // --- Not there; start a new entry
00114 
00115     memoryblock_set empty;
00116     pair< basicblockLocation *, memoryblock_set > new_entry(merge_location, empty);
00117     pair< mergepoint_map_p, bool > result = insert(new_entry);
00118     existing = result.first;
00119   }
00120 
00121   // --- Add the object to the list, skipping over it if it is not in
00122   // the scope of the given merge point (i.e., don't create a merge
00123   // point for a local variable outside it's potential scope).
00124 
00125   memoryblock_set & objects = (*existing).second;
00126 
00127   if (block->in_scope(merge_location))
00128     objects.insert(block);
00129       
00130   if (pointerOptions::Verbose)
00131     cout << "    - Merge " << block->name() << " at " << * merge_location << endl;
00132 }
00133 
00134 // --- Find the set of objects to be merged at a particular basic
00135 // block entry point.
00136 
00137 memoryblock_set * mergePoints::lookup_merge_point(basicblockLocation * merge_location)
00138 {
00139   if (pointerOptions::Verbose) {
00140     cout << "  Lookup merge: " << *merge_location << endl;
00141   }
00142 
00143   mergepoint_map_p p = find(merge_location);
00144   if (p == end()) {
00145     if (pointerOptions::Verbose)
00146       cout << "    None found." << endl;
00147     return 0;
00148   }
00149   else {
00150       if (pointerOptions::Verbose) {
00151         memoryblock_set & objects = (*p).second;
00152         for (memoryblock_set_cp q = objects.begin();
00153              q != objects.end();
00154              ++q)
00155           cout << "      Merge: " << (*q)->name() << endl;
00156       }
00157 
00158     return &((*p).second);
00159   }
00160 }
00161 
00162 // --- Print some statistics
00163 
00164 void mergePoints::stats()
00165 {
00166   cout << "CLASS: mergePoints" << endl;
00167   cout << "  Total number of merge points: " << size() << endl;
00168 }
00169 

Generated on August 27, 2003
Back to the C-Breeze home page