Mei, we investigated your suggestion and here's what we found:

We tried to delete these bb_regionexit nodes after they are used. But
it did not solve the out-of-memory issue.

The optimization flow is like the following:
preopt:
  Build_cfg  --> bb_regionexit added (and never used)
  DCE
    compute_dom_tree --> out of memory because too many bbs
  ...
 mainopt:
  Build_cfg --> bb_regionexit added to mark the end of EH region
  DCE
  CFG_tranformation
  ...

We need to keep bb_regionexit until CFG_transformation (i.e., we
cannot delete them after build_cfg). preopt still has out-of-memory
issue. Thus, not adding bb_regionexits in build_cfg when these bbs are
not used seems to be a reasonable solution. Also Adding bb_regionexit
in the beginning of CFG_transformation is difficult, since we need to
know the scope of a region.

We changed the original patch to add a flag OPT_Enable_EH_CFG_OPT to
control whether the CFG_transformation for EH regions are performed
and bb_regionexits are added. The default is only enabled in mainopt.
We believe it is more understandable this way.


-David Coakley / AMD Open Source Compiler Engineering

On Thu, Jul 7, 2011 at 1:30 PM, Ye, Mei <mei...@amd.com> wrote:
> If EH exit blocks are only used in CFG optimizations, why not inserting these 
> blocks right before the CFG optimization, and delete them right after the CFG 
> optimization.
> This way it is self-contained and won't affect the memory usage of other 
> optimizations.
>
> The "out of memory" problem can happen anywhere besides dead store 
> elimination.
>
>
> -Mei
>
> -----Original Message-----
> From: David Coakley [mailto:dcoak...@gmail.com]
> Sent: Thursday, July 07, 2011 12:54 PM
> To: Ye, Mei
> Cc: Sun Chan; open64-devel
> Subject: Re: [Open64-devel] Code review request: add region exit blocks only 
> when needed [OPT]
>
> Mei, Sun,
>
> Here is some explanation:
>
> The "out-of-memory" issue happens because - in building cfg, our
> previous change allocates extra blocks for EH region exits (these
> could be a lot in the corner case).  Memory for CFG is not freed until
> the later phase in preopt/mainopt.  Thus we got "out-of-memory" inside
> the dead code elimination.
>
> Adding EH exit block is an effecient way to indentify EH regions and
> their levels (indentifying MP regions does the exact same thing).
>
> The argument for the patch is we don't need the extra data structure
> if it is not used.  If control flow optimization happens in preopt, we
> will add this extra data structure.  On the other hand, control flow
> optimization will remove unreachable bbs from the cfg (which is the
> reason why mainopt does not get "out of memory").
>
> On Wed, Jul 6, 2011 at 10:13 PM, Ye, Mei <mei...@amd.com> wrote:
>> My understanding is that the work allocates too many blocks that are not 
>> freed or recycled which causes "out of memory".
>> David, please clarify.
>>
>> -Mei
>>
>> -----Original Message-----
>> From: Sun Chan [mailto:sun.c...@gmail.com]
>> Sent: Wednesday, July 06, 2011 4:34 PM
>> To: Ye, Mei
>> Cc: David Coakley; open64-devel
>> Subject: Re: [Open64-devel] Code review request: add region exit blocks only 
>> when needed [OPT]
>>
>> looking at the diff, I don't fully understand this "outof memory"
>> issue. Can you clarify?
>> Sun
>>
>> On Thu, Jul 7, 2011 at 5:15 AM, Ye, Mei <mei...@amd.com> wrote:
>>> Even if control flow optimization does not happen in preopt now, it can 
>>> happen in the future.
>>> It is likely that the "out of memory" issue is a bug in the design or 
>>> implementation of adding an EH exit block which is not exposed by the 
>>> mainopt.
>>> So I don't quite agree on this fix. Let's hear from other gatekeeper's 
>>> opinion.
>>>
>>> -Mei
>>>
>>> -----Original Message-----
>>> From: David Coakley [mailto:dcoak...@gmail.com]
>>> Sent: Wednesday, July 06, 2011 1:52 PM
>>> To: open64-devel
>>> Subject: [Open64-devel] Code review request: add region exit blocks only 
>>> when needed [OPT]
>>>
>>> Could a gatekeeper review the attached patch to files 
>>> osprey/be/opt/opt_main.cxx and opt_cfg.[cxx,h]?  Here is the
>>> description:
>>>
>>> When we enhanced the control flow optimization to handle the PU with EH 
>>> regions in the previous release, we added a region exit block for each EH 
>>> region during the CFG construction.  These extra blocks are unnecessary 
>>> when CFG is built but no control flow optimization is performed. Indeed, 
>>> control flow optimization only happens in mainopt.
>>> These unnecessary extra blocks may cause "out of memory" issue in preopt. 
>>> Thus, this change is to add these region exit blocks only when CFG control 
>>> flow optimization is performed (i.e. mainopt).
>>>
>>> Thanks,
>>>
>>> -David Coakley / AMD Open Source Compiler Engineering
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> All of the data generated in your IT infrastructure is seriously valuable.
>>> Why? It contains a definitive record of application performance, security
>>> threats, fraudulent activity, and more. Splunk takes this data and makes
>>> sense of it. IT sense. And common sense.
>>> http://p.sf.net/sfu/splunk-d2d-c2
>>> _______________________________________________
>>> Open64-devel mailing list
>>> Open64-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/open64-devel
>>>
>>
>>
>>
>
>
>
Index: osprey/be/opt/opt_cfg_trans.cxx
===================================================================
--- osprey/be/opt/opt_cfg_trans.cxx     (revision 3694)
+++ osprey/be/opt/opt_cfg_trans.cxx     (working copy)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2010 Advanced Micro Devices, Inc.  All Rights Reserved.
+ * Copyright (C) 2008-2011 Advanced Micro Devices, Inc.  All Rights Reserved.
  */
 
 //-*-c++-*-
@@ -1429,9 +1429,10 @@
                                  insert_iterator<vector<vertex_id> >
                                  (entry, entry.begin()));
 
-  if (ok == CFG_other_regions) {
+  if (ok == CFG_other_regions ||
+      (ok == CFG_EH_regions && !OPT_Enable_EH_CFG_OPT)) {
     if (trace)
-      fprintf(TFile, ("skip CFG transformation because of non-EH REGION."));
+      fprintf(TFile, ("skip CFG transformation."));
     return;
   }
 
@@ -1449,7 +1450,7 @@
   generate_zones(cu, g, zones, do_butterfly, trace, display);
   clone_zones(g, entry, zones.begin(), zones.end(), cfg, trace, display);
 
-  reconstruct_CFG(g, cfg, trace, ok == CFG_EH_regions);
+  reconstruct_CFG(g, cfg, trace, (ok == CFG_EH_regions && 
OPT_Enable_EH_CFG_OPT));
 
   cfg->Invalidate_loops();
   cfg->Analyze_loops();
Index: osprey/be/opt/opt_main.cxx
===================================================================
--- osprey/be/opt/opt_main.cxx  (revision 3694)
+++ osprey/be/opt/opt_main.cxx  (working copy)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2010 Advanced Micro Devices, Inc.  All Rights Reserved.
+ * Copyright (C) 2008-2011 Advanced Micro Devices, Inc.  All Rights Reserved.
  */
 
 //-*-c++-*-
@@ -546,6 +546,7 @@
   BOOL _no_return;
   BOOL _nothrow;
   BOOL _simp_if_conv;
+  BOOL _eh_cfg_opt;
 
   WOPT_SWITCHES(const WOPT_SWITCHES&);
   WOPT_SWITCHES& operator = (const WOPT_SWITCHES&);
@@ -672,6 +673,8 @@
           OPT_Enable_WHIRL_SSA)
        WOPT_Enable_Zero_Version = FALSE;
 
+      if (!OPT_Enable_EH_CFG_OPT_Set)
+        OPT_Enable_EH_CFG_OPT = TRUE;
       break; // end MAINOPT_PHASE
 
 #ifdef TARG_NVISA
@@ -819,6 +822,7 @@
       WOPT_Enable_Generate_Trip_Count = _trip;
       WOPT_Enable_LNO_Copy_Propagate  = _lno_copy;
       WOPT_Enable_Zero_Version   = _zero_version;
+      OPT_Enable_EH_CFG_OPT = _eh_cfg_opt;
       break;
 #ifdef TARG_NVISA
     case PREOPT_CMC_PHASE:
@@ -959,6 +963,7 @@
     _no_return = WOPT_Enable_Noreturn_Attr_Opt;
     _nothrow = WOPT_Enable_Nothrow_Opt;
     _simp_if_conv = WOPT_Enable_Simple_If_Conv;
+    _eh_cfg_opt = OPT_Enable_EH_CFG_OPT;
 
     Adjust_Optimization();
   }
Index: osprey/be/opt/opt_cfg.cxx
===================================================================
--- osprey/be/opt/opt_cfg.cxx   (revision 3694)
+++ osprey/be/opt/opt_cfg.cxx   (working copy)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2010 Advanced Micro Devices, Inc.  All Rights Reserved.
+ * Copyright (C) 2008-2011 Advanced Micro Devices, Inc.  All Rights Reserved.
  */
 
 /*
@@ -2698,7 +2698,7 @@
   }
 #endif
 
-  if (REGION_is_EH(wn)) 
+  if (OPT_Enable_EH_CFG_OPT && REGION_is_EH(wn)) 
   {
     if (_current_bb->Succ() ||
         _current_bb->Kind() == BB_EXIT)
@@ -3914,7 +3914,8 @@
     opt_tail.Mutate();
   }
 
-  Ident_eh_regions();
+  if (OPT_Enable_EH_CFG_OPT)
+    Ident_eh_regions();
  
   Process_multi_entryexit( TRUE/*is_whirl*/ );
 
Index: osprey/common/com/config_opt.h
===================================================================
--- osprey/common/com/config_opt.h      (revision 3694)
+++ osprey/common/com/config_opt.h      (working copy)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2009 Advanced Micro Devices, Inc.  All Rights Reserved.
+ * Copyright (C) 2008-2011 Advanced Micro Devices, Inc.  All Rights Reserved.
  */
 
 /*
@@ -213,6 +213,8 @@
 extern UINT32 AA_force_tag_alias_before_dim1;
 extern UINT32 AA_force_tag_alias_before_dim2;
 
+extern BOOL OPT_Enable_EH_CFG_OPT;
+extern BOOL OPT_Enable_EH_CFG_OPT_Set;
 #endif
 #ifdef __cplusplus
 }
Index: osprey/common/com/config_opt.cxx
===================================================================
--- osprey/common/com/config_opt.cxx    (revision 3694)
+++ osprey/common/com/config_opt.cxx    (working copy)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2010 Advanced Micro Devices, Inc.  All Rights Reserved.
+ * Copyright (C) 2008-2011 Advanced Micro Devices, Inc.  All Rights Reserved.
  */
 
 /*
@@ -347,6 +347,11 @@
 UINT32 AA_force_tag_alias_before_dim1 = 0;
 UINT32 AA_force_tag_alias_before_dim2 = UINT32_MAX;
 
+// enable control flow optimization for the program with EH regions
+// by default it is only enabled in mainopt
+BOOL  OPT_Enable_EH_CFG_OPT = FALSE;
+BOOL  OPT_Enable_EH_CFG_OPT_Set = FALSE;
+
 /***** Obsolete options *****/
 static BOOL Fprop_Limit_Set = FALSE;
 
@@ -913,6 +918,10 @@
     0, 0, UINT32_MAX,  &AA_force_tag_alias_before_dim2, NULL,
     "Triage option for alias analyzer" },
 
+  { OVK_BOOL,   OV_INTERNAL,     TRUE, "eh_cfg_opt",        "",
+    0, 0, 0,    &OPT_Enable_EH_CFG_OPT, &OPT_Enable_EH_CFG_OPT_Set, 
+    "Enable CFO for EH regions"},
+
   /* Obsolete options: */
 
   { OVK_OBSOLETE,      OV_INTERNAL,    FALSE, "global_limit",          NULL,
------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to