From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15896 invoked by alias); 20 May 2011 09:48:18 -0000 Received: (qmail 15885 invoked by uid 22791); 20 May 2011 09:48:17 -0000 X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,BAYES_20,RCVD_IN_DNSWL_NONE,RCVD_IN_RP_RNBL,TW_GB X-Spam-Check-By: sourceware.org Received: from 63.mail-out.ovh.net (HELO 63.mail-out.ovh.net) (91.121.185.56) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Fri, 20 May 2011 09:48:00 +0000 Received: (qmail 32684 invoked by uid 503); 20 May 2011 10:42:12 -0000 Received: from b9.ovh.net (HELO mail176.ha.ovh.net) (213.186.33.59) by 63.mail-out.ovh.net with SMTP; 20 May 2011 10:42:12 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 20 May 2011 11:47:58 +0200 Received: from 85-170-204-97.rev.numericable.fr (HELO ?85.170.204.97?) (piervit@pvittet.com@85.170.204.97) by ns0.ovh.net with SMTP; 20 May 2011 11:47:56 +0200 Message-ID: <4DD638CD.5020106@pvittet.com> Date: Fri, 20 May 2011 11:47:00 -0000 From: Pierre Vittet User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100515 Lightning/1.0b1 Icedove/3.0.4 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org CC: Basile Starynkevitch Subject: Re: [PATCH, MELT] add dominance functions References: <4DD41847.1040801@pvittet.com> <20110519073238.35a156ca.basile@starynkevitch.net> In-Reply-To: <20110519073238.35a156ca.basile@starynkevitch.net> Content-Type: multipart/mixed; boundary="------------010407000704020303060107" X-Ovh-Tracer-Id: 4092646161508335774 X-Ovh-Remote: 85.170.204.97 (85-170-204-97.rev.numericable.fr) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg01439.txt.bz2 This is a multi-part message in MIME format. --------------010407000704020303060107 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 4030 I have corrected my patch with your remarks. Especially about the debug functions, it takes the debug melt flag into account. Moreover, I have allowed the user to give a message when calling this function, as usual in MELT debug functions. Giving this message was a bit difficult (This is the only argument of the function, so this must be a MELT value, and that uneasy to convert the value into :cstring). I have used debugeprintf macro into a code_chunk to give the MELT file + line numbers, followed by a outstr_err, which displays the user message. I think the only disavantage is that it puts an end of lines between the two informations. If you think there is a best way to do this, I am ok to try it. The new changelog: 2011-05-20 Pierre Vittet * melt/xtramelt-ana-base.melt (is_dominance_info_available, is_post_dominance_info_available, calculate_dominance_info_unsafe, calculate_post_dominance_info_unsafe, free_dominance_info, free_post_dominance_info, calculate_dominance_info, calculate_post_dominance_info, debug_dominance_info, debug_post_dominance_info, get_immediate_dominator_unsafe, get_immediate_dominator, get_immediate_post_dominator_unsafe, get_immediate_post_dominator, dominated_by_other_unsafe, dominated_by_other, post_dominated_by_other_unsafe, post_dominated_by_other, foreach_dominated_unsafe, dominated_by_bb_iterator): Add primitives, functions, iterators for using dominance info. On 19/05/2011 07:32, Basile Starynkevitch wrote: > On Wed, 18 May 2011 21:04:39 +0200 > Pierre Vittet wrote: > > >> Hello, >> >> I have written a patch to allow the use of the GCC dominance functions >> into MELT. >> > [...] > > >> Changelog: >> 2011-05-17 Pierre Vittet >> >> * melt/xtramelt-ana-base.melt >> (is_dominance_info_available, is_post_dominance_info_available, >> calculate_dominance_info_unsafe, >> calculate_post_dominance_info_unsafe, >> free_dominance_info, free_post_dominance_info, >> calculate_dominance_info, >> calculate_post_dominance_info, debug_dominance_info, >> debug_post_dominance_info, get_immediate_dominator_unsafe, >> get_immediate_dominator, get_immediate_post_dominator_unsafe, >> get_immediate_post_dominator, dominated_by_other_unsafe, >> dominated_by_other, post_dominated_by_other_unsafe, >> post_dominated_by_other, foreach_dominated_unsafe, >> dominated_by_bb_iterator): Add primitives, functions, iterators for >> using dominance info. >> >> >> > Thanks for the patch. Some minor tweaks: > > First, put a space between formal arguments list& function name. > So > > +(defprimitive calculate_dominance_info_unsafe() :void > should be > +(defprimitive calculate_dominance_info_unsafe () :void > > Then, please put the defined name on the same line that defprimitive or > defun or def... When consecutive MELT formals have the same ctype, you > don't need to repeat it > > So > > +(defprimitive > + dominated_by_other_unsafe(:basic_block bbA :basic_block bbB) :long > > should be > > +(defprimitive dominated_by_other_unsafe (:basic_block bbA bbB) :long > > In :doc strings, document when something is a boxed value > (distinction between values& stuffs is crucial), so write instead > [I added the boxed word, it is important] > > +(defun get_immediate_dominator (bb) > + :doc#{Return the next immediate dominator of the boxed basic_block > $BB as a MELT +value.}# > > At last, all debug* operations should only output debug to stderr only > when flag_melt_debug is set and give the MELT source position (because > we don't want any debug printing in the usual case when -fmelt-debug is > not given to our cc1) Look at debugloop in xtramelt-ana-base.melt for > an example (notice that debugeprintfnonl is a C macro printing the MELT > source position. > > > So please resubmit a slightly improved patch. > > Regards. > --------------010407000704020303060107 Content-Type: text/plain; name="add_dominance_functions-173936.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="add_dominance_functions-173936.diff" Content-length: 9775 Index: gcc/melt/xtramelt-ana-base.melt =================================================================== --- gcc/melt/xtramelt-ana-base.melt (revision 173936) +++ gcc/melt/xtramelt-ana-base.melt (working copy) @@ -1871,7 +1871,6 @@ (defprimitive make_basicblock (discr :basic_block bb) :value #{/*make_basicblock*/(meltgc_new_basicblock((meltobject_ptr_t)($discr),($bb)))}# ) - (defprimitive basicblock_content (v) :basic_block #{(melt_basicblock_content((melt_ptr_t)($v)))}# ) @@ -1910,6 +1909,243 @@ (defprimitive basicblock_nth_succ_edge (:basic_block bb :long ix) :edge #{(($bb && $ix>=0 && $ixsuccs))?EDGE_SUCC($bb,$ix):NULL)}#) +;; Primitives concerning dominance in basic_blocks +;; those functions mainly come from gcc/dominance.c + +(defprimitive is_dominance_info_available () :long + :doc #{Check if dominance info are already calculated. + User normally doesn't have to call this primitive, as MELT functions + check if there is a need to use this.}# + #{dom_info_available_p(CDI_DOMINATORS)}# +) + +(defprimitive is_post_dominance_info_available () :long + :doc #{Check if post dominance info are already calculated. + User normally doesn't have to call this primitive, as MELT functions + check if there is a need to use this.}# + #{dom_info_available_p(CDI_POST_DOMINATORS)}# +) + +(defprimitive calculate_dominance_info_unsafe () :void + :doc #{This primitive is internaly called, user doesn't need it. + Build the struct containing dominance info. + This struct is necessary to use others dominance related function. + This function is unsafe because it does not register any future call to + free_dominance_info.}# + #{calculate_dominance_info(CDI_DOMINATORS)}# +) + +(defprimitive calculate_post_dominance_info_unsafe () :void + :doc #{This primitive is internaly called, user doesn't need it. + Build the struct containing post dominance info. + This struct is necessary to use other dominance related function. + This function is unsafe because it does not register any future call to + free_dominance_info.}# + #{calculate_dominance_info(CDI_POST_DOMINATORS)}# +) + +(defprimitive free_dominance_info () :void + :doc #{This primitive is internaly called, user doesn't need it. + Clear dominance info if they have been allocated.}# + #{free_dominance_info(CDI_DOMINATORS)}# +) + +(defprimitive free_post_dominance_info () :void + :doc #{This primitive is internaly called, user doesn't need it. + Clear post dominance info if they have been allocated.}# + #{free_dominance_info(CDI_POST_DOMINATORS)}# +) + +(defun calculate_dominance_info () + :doc #{This primitive is internaly called, user doesn't need it. + Build the struct containing dominance info. + This struct is necessary to use other dominance related info. + It place a call to free dominance info when pass is finished if it is + necessary.}# + (if (is_dominance_info_available) + () ;; do nothing + (progn ;; else calculate dom and ask to free them at end of pass + (calculate_dominance_info_unsafe) + (at_end_melt_pass_first free_dominance_info) + )) +) + +(defun calculate_post_dominance_info () + :doc #{This primitive is internaly called, user doesn't need it + Build the struct containing post dominance info. + This struct is necessary to use other post dominance related info. + It place a call to free dominance info when pass is finished if it is + necessary.}# + (if (is_post_dominance_info_available) + () ;; do nothing + (progn ;; else calculate dom and ask to free them at end of pass + (calculate_post_dominance_info_unsafe) + (at_end_melt_pass_first free_post_dominance_info) + )) +) + +(defun debug_dominance_info (msg) + :doc#{Print to stderr all dominance relation, in the format "bb1->bb2".}# + (calculate_dominance_info) + (code_chunk debugdomchunk #{ + /*$DEBUGDOMCHUNK*/ + debugeprintf("debugdominanceinfo: ");}#) + (outstr_err msg) + (each_bb_current_fun () (:basic_block curbb) + (let ((:basic_block dombb (basicblock_content (get_immediate_dominator + (make_basicblock discr_basic_block curbb))))) + (if dombb + (code_chunk debugbbdomchunk + #{ + if (flag_melt_debug) + fprintf (stderr, "%i dominated by %i\n", $CURBB->index, + $DOMBB->index); + }# + )) + ) + ) +) + +(defun debug_post_dominance_info (msg) + :doc#{Print to stderr all post dominance relation, in the format + "bb1 dominated_by bb2".}# + (calculate_post_dominance_info) + (outstr_dbg msg) + (code_chunk debugpostdomchunk #{ + /*$DEBUGPOSTDOMCHUNK*/ + debugeprintf("debugpostdominanceinfo: ");}#) + (outstr_err msg) + (each_bb_current_fun () (:basic_block curbb) + (let ( (:basic_block dombb (basicblock_content + (get_immediate_post_dominator (make_basicblock discr_basic_block + curbb))))) + (if dombb + (code_chunk debugbbpostdomchunk + #{ + if(flag_melt_debug) + fprintf (stderr, "%i post-dominated by %i\n", $CURBB->index, + $DOMBB->index); + }# + )) + ) + ) +) + +(defprimitive get_immediate_dominator_unsafe (:basic_block bb) :basic_block + :doc#{It doesn't check that dominance info are build, use + get_immediate_dominator instead.}# + #{($bb) ? get_immediate_dominator (CDI_DOMINATORS, $bb) : NULL}# +) + +(defun get_immediate_dominator (bb) + :doc#{Return the next immediate dominator of the boxed basic_block $BB as a + MELT value.}# + (if (is_basicblock bb) + (progn + (calculate_dominance_info) + (return (make_basicblock discr_basic_block + (get_immediate_dominator_unsafe (basicblock_content bb)))))) +) + +(defprimitive get_immediate_post_dominator_unsafe (:basic_block bb) :basic_block + :doc#{It doesn't check that post_dominance info are build, use + get_immediate_post_dominator instead.}# + #{($bb) ? get_immediate_dominator (CDI_POST_DOMINATORS, $bb) : NULL}# +) + +(defun get_immediate_post_dominator (bb) + :doc#{Return the next immediate post dominator of the boxed basic_block $BB as + a MELT value.}# + (if (is_basicblock bb) + (progn + (calculate_post_dominance_info) + (return (make_basicblock discr_basic_block + (get_immediate_post_dominator_unsafe (basicblock_content bb)))))) +) + +(defprimitive dominated_by_other_unsafe (:basic_block bbA bbB) :long + :doc#{It doesn't check that dominance info are build, use + dominated_by_other instead.}# + #{ (($bbA) && ($bbB)) ? + dominated_by_p (CDI_DOMINATORS, $bbA, $bbB) + : 0 + }# +) + +(defun dominated_by_other (bbA bbB) + :doc#{true if boxed basic_block $BBA is dominated by boxed basic_block $BBB.}# + (if (and (is_basicblock bbA) (is_basicblock bbB)) + (progn + (calculate_dominance_info) + (if (dominated_by_other_unsafe (basicblock_content bbA) + (basicblock_content bbB)) + (return :true) + ))) +) + +(defprimitive post_dominated_by_other_unsafe (:basic_block bbA bbB) :long + :doc#{It doesn't check that post_dominance info are build, use + post_dominated_by_other instead.}# + #{ (($bbA) && ($bbB)) ? + dominated_by_p (CDI_POST_DOMINATORS, $bbA, $bbB) + : 0 + }# +) + +(defun post_dominated_by_other (bbA bbB) + :doc#{true if boxed basic_block $BBA is post dominated by boxed basic_block + $BBB.}# + (if (and (is_basicblock bbA) (is_basicblock bbB)) + (progn + (calculate_post_dominance_info) + (if (post_dominated_by_other_unsafe (basicblock_content bbA) + (basicblock_content bbB)) + (return :true) + ))) +) + +(defciterator foreach_dominated_unsafe + (:basic_block dominator_bb) + ebbdomd + (:basic_block dominated_bb) + #{ + /* $EBBDOMD before+ */ + + VEC (basic_block, heap)* $EBBDOMD#_bbvec = 0; + unsigned int $EBBDOMD#_ix = 0; + basic_block $EBBDOMD#_bb = 0; + + if($DOMINATOR_BB){ + $EBBDOMD#_bbvec = get_dominated_by(CDI_DOMINATORS, $DOMINATOR_BB); + if($EBBDOMD#_bbvec){ + FOR_EACH_VEC_ELT (basic_block, $EBBDOMD#_bbvec, + $EBBDOMD#_ix, $EBBDOMD#_bb){ + if (!$EBBDOMD#_ix) + continue; + $DOMINATED_BB = $EBBDOMD#_bb; + /*$EBBDOMD before- */}# + ;; after expansion + #{/*$EBBDOMD after+ */ + } + }} + VEC_free (basic_block, heap, $EBBDOMD#_bbvec); + $EBBDOMD#_bbvec = 0; + $EBBDOMD#_bb = 0; + /* $EBBDOMD after- */}# +) + +(defun dominated_by_bb_iterator (f data bb) + :doc #{run function $F on every basicblocks dominated by boxed basic_block + $BB with $DATA as first parameters and ending with the dominated + basicblock as last parameters.}# + (calculate_dominance_info) + (foreach_dominated_unsafe + ((basicblock_content bb)) + (:basic_block dominated_bb) + (f data dominated_bb) + ) +) + ;;;; (defprimitive null_gimpleseq () :gimple_seq #{((gimple_seq)0)}#) ;;;;;;;;;;;;;;;; @@ -2931,6 +3167,17 @@ and discriminant $DIS, usually $DISCR_MIXED_LOCATI basicblock_nb_succ basicblock_phinodes basicblock_single_succ + debug_dominance_info + debug_post_dominance_info + get_immediate_dominator + get_immediate_post_dominator + dominated_by_other + post_dominated_by_other + dominated_by_bb_iterator + get_immediate_dominator + get_immediate_post_dominator + dominated_by_other + post_dominated_by_other cfun_decl cfun_gimple_body cfun_has_cfg --------------010407000704020303060107--