OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
WhirlParentize.cxx
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/lib/support/WhirlParentize.cxx,v 1.3 2004/04/14 21:25:21 eraxxon Exp $
3 
4 
6 #include "WhirlParentize.h"
7 
8 
9 namespace fortTkSupport {
10 
11  WN*
12  FindParentWNBlock(const WN* wn_tree, const WN* wn)
13  {
14  if (!wn_tree || !wn) { return NULL; }
15 
16  OPERATOR opr = WN_operator(wn_tree);
17  if (!OPERATOR_is_scf(opr)) {
18  // 'wn_tree' is not structured control flow and cannot contain blocks
19  return NULL;
20  } else {
21 
22  WN* blkWN = NULL;
23  if (opr == OPR_BLOCK) {
24 
25  // Test to see if 'wn' is a child of 'wn_tree'
26  WN *kid = WN_first(wn_tree);
27  while (kid) {
28 
29  // Test this child
30  if (kid == wn) {
31  return const_cast<WN*>(wn_tree); // we found the parent block|
32  }
33 
34  // Recursively test
35  if ( (blkWN = FindParentWNBlock(kid, wn)) ) {
36  return blkWN;
37  }
38 
39  kid = WN_next(kid);
40  }
41  } else {
42 
43  // Recur on for non-block structured control flow
44  for (INT kidno = 0; kidno < WN_kid_count(wn_tree); kidno++) {
45  WN* kid = WN_kid(wn_tree, kidno);
46  if ( (blkWN = FindParentWNBlock(kid, wn)) ) {
47  return blkWN;
48  }
49  }
50 
51  }
52 
53  return NULL; // not found
54  }
55  }
56 
57  //***************************************************************************
58  // WhirlParentMap
59  //***************************************************************************
60 
61  // Note: whirl2f implementation of parentizing for each PU
62  // W2F_Push_PU
63  // MEM_POOL_Push(&W2F_Parent_Pool);
64  // W2CF_Parent_Map = WN_MAP_Create(&W2F_Parent_Pool);
65  // W2CF_Parentize(pu);
66  // W2F_Pop_PU
67  // WN_MAP_Delete(W2CF_Parent_Map);
68  // W2CF_Parent_Map = WN_MAP_UNDEFINED;
69  // MEM_POOL_Pop(&W2F_Parent_Pool);
70 
72  {
73  Ctor();
74  }
75 
77  {
78  Ctor();
79  Create(wn);
80  }
81 
82  void
84  {
85  // Create a pool to hold the parent map for every PU, one at a time.
86  MEM_POOL_Initialize(&memPool, "WhirlParentMap_Pool", FALSE);
89  }
90 
92  {
95  }
96 
97  void
99  {
100  if (parentMap != WN_MAP_UNDEFINED) {
101  Clear();
102  }
103 
105  Parentize(wn);
106  }
107 
108  void
110  {
113  }
114 
115  WN*
117  {
118  WN* curWN = const_cast<WN*>(wn);
119  while ( (curWN = Find(curWN)) ) {
120  if (WN_operator(curWN) == OPR_BLOCK) {
121  return curWN;
122  }
123  }
124  return NULL;
125  }
126 
127  // Parentize: Given a tree, initialize its parent pointers, overriding
128  // anything that may have been in the map. Does not update parent
129  // pointer of the root node 'wn'.
130  void
132  {
133  OPERATOR opr = WN_operator(wn);
134 
135  if (!OPERATOR_is_leaf(opr)) {
136  if (opr == OPR_BLOCK) { // WN_opcode(wn) == OPC_BLOCK
137  WN *kid = WN_first(wn);
138  while (kid) {
139  Insert(kid, wn);
140  Parentize(kid);
141  kid = WN_next(kid);
142  }
143  } else {
144  for (INT kidno = 0; kidno < WN_kid_count(wn); kidno++) {
145  WN* kid = WN_kid(wn, kidno);
146  if (kid) {
147  Insert(kid, wn);
148  Parentize(kid);
149  }
150  }
151  }
152  }
153  }
154 
155 }