constmrg.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* constmrg.h: Routines to merge constants
  2. Copyright (C) 2004 Kevin Kofler
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. #ifndef CONSTMRG_H
  15. #define CONSTMRG_H
  16. #include "generic.h"
  17. #include "data.h"
  18. // Merge constants (including strings) in sections marked Mergeable to avoid
  19. // duplication. A constant is considered to be an interval enclosed within 2
  20. // label groups, where a label group is the equivalence class formed by the
  21. // symbols at a given offset. A constant is said unaligned if the section
  22. // containing it also has the Unaligned flag set, and aligned otherwise. The
  23. // value of a constant is said to be the contents of the interval defining it.
  24. // The algorithm used is a prefix merge algorithm:
  25. // * If the value of a constant A is a prefix of the value of a constant B, and
  26. // A is unaligned and/or B is aligned, then A is identified with B.
  27. // * If the value of a constant A is a strict prefix of the value of a constant
  28. // B, A is aligned and B is unaligned, then B is split into a new aligned
  29. // section, and A is identified with the so-created B.
  30. // Identification works the following way: The label group defining A is moved
  31. // into the label group defining B. Then, if A was constituting an entire
  32. // section, the section is deleted. Otherwise, A is removed using the
  33. // range-cutting API.
  34. // The linker doesn't look for identical constants in the same section. It is
  35. // the compiler's job to merge constants in this case.
  36. void MergeConstants (PROGRAM *Program);
  37. #endif