1 /* Adjust alignment for local variable.
2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 Contributed by Kito Cheng <kito.cheng@sifive.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "tree-pass.h"
33 const pass_data pass_data_adjust_alignment
=
35 GIMPLE_PASS
, /* type */
36 "adjust_alignment", /* name */
37 OPTGROUP_NONE
, /* optinfo_flags */
39 0, /* properties_required */
40 0, /* properties_provided */
41 0, /* properties_destroyed */
42 0, /* todo_flags_start */
43 0, /* todo_flags_finish */
46 class pass_adjust_alignment
: public gimple_opt_pass
49 pass_adjust_alignment (gcc::context
*ctxt
)
50 : gimple_opt_pass (pass_data_adjust_alignment
, ctxt
)
53 unsigned int execute (function
*) final override
;
54 }; // class pass_adjust_alignment
58 /* Entry point to adjust_alignment pass. */
60 pass_adjust_alignment::execute (function
*fun
)
65 FOR_EACH_LOCAL_DECL (fun
, i
, var
)
67 /* Don't adjust aligment for static local var and hard register var. */
68 if (is_global_var (var
) || DECL_HARD_REGISTER (var
))
71 unsigned align
= LOCAL_DECL_ALIGNMENT (var
);
73 /* Make sure alignment only increase. */
74 gcc_assert (align
>= DECL_ALIGN (var
));
76 SET_DECL_ALIGN (var
, align
);
82 make_pass_adjust_alignment (gcc::context
*ctxt
)
84 return new pass_adjust_alignment (ctxt
);