Home | History | Annotate | Line # | Download | only in gcc
align.h revision 1.1
      1  1.1  mrg /* Alignment-related classes.
      2  1.1  mrg    Copyright (C) 2018-2019 Free Software Foundation, Inc.
      3  1.1  mrg 
      4  1.1  mrg This file is part of GCC.
      5  1.1  mrg 
      6  1.1  mrg GCC is free software; you can redistribute it and/or modify it under
      7  1.1  mrg the terms of the GNU General Public License as published by the Free
      8  1.1  mrg Software Foundation; either version 3, or (at your option) any later
      9  1.1  mrg version.
     10  1.1  mrg 
     11  1.1  mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     12  1.1  mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  1.1  mrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  1.1  mrg for more details.
     15  1.1  mrg 
     16  1.1  mrg You should have received a copy of the GNU General Public License
     17  1.1  mrg along with GCC; see the file COPYING3.  If not see
     18  1.1  mrg <http://www.gnu.org/licenses/>.  */
     19  1.1  mrg 
     20  1.1  mrg /* Align flags tuple with alignment in log form and with a maximum skip.  */
     21  1.1  mrg 
     22  1.1  mrg struct align_flags_tuple
     23  1.1  mrg {
     24  1.1  mrg   /* Values of the -falign-* flags: how much to align labels in code.
     25  1.1  mrg      log is "align to 2^log" (so 0 means no alignment).
     26  1.1  mrg      maxskip is the maximum allowed amount of padding to insert.  */
     27  1.1  mrg   int log;
     28  1.1  mrg   int maxskip;
     29  1.1  mrg 
     30  1.1  mrg   /* Normalize filled values so that maxskip is not bigger than 1 << log.  */
     31  1.1  mrg   void normalize ()
     32  1.1  mrg   {
     33  1.1  mrg     int n = (1 << log);
     34  1.1  mrg     if (maxskip > n)
     35  1.1  mrg       maxskip = n - 1;
     36  1.1  mrg   }
     37  1.1  mrg 
     38  1.1  mrg   /* Return original value of an alignment flag.  */
     39  1.1  mrg   int get_value ()
     40  1.1  mrg   {
     41  1.1  mrg     return maxskip + 1;
     42  1.1  mrg   }
     43  1.1  mrg };
     44  1.1  mrg 
     45  1.1  mrg /* Alignment flags is structure used as value of -align-* options.
     46  1.1  mrg    It's used in target-dependant code.  */
     47  1.1  mrg 
     48  1.1  mrg struct align_flags
     49  1.1  mrg {
     50  1.1  mrg   /* Default constructor.  */
     51  1.1  mrg   align_flags (int log0 = 0, int maxskip0 = 0, int log1 = 0, int maxskip1 = 0)
     52  1.1  mrg   {
     53  1.1  mrg     levels[0].log = log0;
     54  1.1  mrg     levels[0].maxskip = maxskip0;
     55  1.1  mrg     levels[1].log = log1;
     56  1.1  mrg     levels[1].maxskip = maxskip1;
     57  1.1  mrg     normalize ();
     58  1.1  mrg   }
     59  1.1  mrg 
     60  1.1  mrg   /* Normalize both components of align_flags.  */
     61  1.1  mrg   void normalize ()
     62  1.1  mrg   {
     63  1.1  mrg     for (unsigned i = 0; i < 2; i++)
     64  1.1  mrg       levels[i].normalize ();
     65  1.1  mrg   }
     66  1.1  mrg 
     67  1.1  mrg   /* Get alignment that is common bigger alignment of alignments F0 and F1.  */
     68  1.1  mrg   static align_flags max (const align_flags f0, const align_flags f1)
     69  1.1  mrg     {
     70  1.1  mrg       int log0 = MAX (f0.levels[0].log, f1.levels[0].log);
     71  1.1  mrg       int maxskip0 = MAX (f0.levels[0].maxskip, f1.levels[0].maxskip);
     72  1.1  mrg       int log1 = MAX (f0.levels[1].log, f1.levels[1].log);
     73  1.1  mrg       int maxskip1 = MAX (f0.levels[1].maxskip, f1.levels[1].maxskip);
     74  1.1  mrg       return align_flags (log0, maxskip0, log1, maxskip1);
     75  1.1  mrg     }
     76  1.1  mrg 
     77  1.1  mrg   align_flags_tuple levels[2];
     78  1.1  mrg };
     79  1.1  mrg 
     80  1.1  mrg /* Define maximum supported code alignment.  */
     81  1.1  mrg #define MAX_CODE_ALIGN 16
     82  1.1  mrg #define MAX_CODE_ALIGN_VALUE (1 << MAX_CODE_ALIGN)
     83