00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "c_breeze.h"
00039 #include <algorithm>
00040 #include "mergepoints.h"
00041
00042
00043
00044
00045
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
00056
00057 while ( cur && ! found ) {
00058
00059
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
00070
00071
00072 basicblock_set_map & df = (*p).second;
00073
00074 if ( ! df.empty()) {
00075
00076 found = true;
00077
00078
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
00101
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
00109
00110 mergepoint_map_p existing = find(merge_location);
00111 if (existing == end()) {
00112
00113
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
00122
00123
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
00135
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
00163
00164 void mergePoints::stats()
00165 {
00166 cout << "CLASS: mergePoints" << endl;
00167 cout << " Total number of merge points: " << size() << endl;
00168 }
00169