*** empty log message ***
[deliverable/binutils-gdb.git] / gold / icf.h
1 // icf.h -- Identical Code Folding
2
3 // Copyright 2009 Free Software Foundation, Inc.
4 // Written by Sriraman Tallam <tmsriram@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #ifndef GOLD_ICF_H
24 #define GOLD_ICF_H
25
26 #include <vector>
27
28 #include "elfcpp.h"
29 #include "symtab.h"
30
31 namespace gold
32 {
33
34 class Object;
35 class Input_objects;
36 class Symbol_table;
37
38 typedef std::pair<Object*, unsigned int> Section_id;
39
40 class Icf
41 {
42 public:
43 struct Section_id_hash
44 {
45 size_t operator()(const Section_id& loc) const
46 { return reinterpret_cast<uintptr_t>(loc.first) ^ loc.second; }
47 };
48
49 typedef std::vector<Section_id> Sections_reachable_list;
50 typedef std::vector<Symbol*> Symbol_info;
51 typedef std::vector<std::pair<long long, long long> > Addend_info;
52 typedef Unordered_map<Section_id,
53 Sections_reachable_list,
54 Section_id_hash> Section_list;
55 typedef Unordered_map<Section_id, Symbol_info, Section_id_hash> Symbol_list;
56 typedef Unordered_map<Section_id, Addend_info, Section_id_hash> Addend_list;
57 typedef Unordered_map<Section_id,
58 unsigned int,
59 Section_id_hash> Uniq_secn_id_map;
60
61 Icf()
62 : id_section_(), section_id_(), kept_section_id_(),
63 num_tracked_relocs(NULL), icf_ready_(false),
64 section_reloc_list_(), symbol_reloc_list_(),
65 addend_reloc_list_()
66 { }
67
68 // Returns the kept folded identical section corresponding to
69 // dup_obj and dup_shndx.
70 Section_id
71 get_folded_section(Object* dup_obj, unsigned int dup_shndx);
72
73 // Forms groups of identical sections where the first member
74 // of each group is the kept section during folding.
75 void
76 find_identical_sections(const Input_objects* input_objects,
77 Symbol_table* symtab);
78
79 // This is set when ICF has been run and the groups of
80 // identical sections have been formed.
81 void
82 icf_ready()
83 { this->icf_ready_ = true; }
84
85 // Returns true if ICF has been run.
86 bool
87 is_icf_ready()
88 { return this->icf_ready_; }
89
90 // Returns the kept section corresponding to the
91 // given section.
92 bool
93 is_section_folded(Object* obj, unsigned int shndx);
94
95 // Returns a map of a section to a list of all sections referenced
96 // by its relocations.
97 Section_list&
98 section_reloc_list()
99 { return this->section_reloc_list_; }
100
101 // Returns a map of a section to a list of all symbols referenced
102 // by its relocations.
103 Symbol_list&
104 symbol_reloc_list()
105 { return this->symbol_reloc_list_; }
106
107 // Returns a maps of a section to a list of symbol values and addends
108 // of its relocations.
109 Addend_list&
110 addend_reloc_list()
111 { return this->addend_reloc_list_; }
112
113 // Returns a mapping of each section to a unique integer.
114 Uniq_secn_id_map&
115 section_to_int_map()
116 { return this->section_id_; }
117
118 private:
119
120 // Maps integers to sections.
121 std::vector<Section_id> id_section_;
122 // Does the reverse.
123 Uniq_secn_id_map section_id_;
124 // Given a section id, this maps it to the id of the kept
125 // section. If the id's are the same then this section is
126 // not folded.
127 std::vector<unsigned int> kept_section_id_;
128 unsigned int* num_tracked_relocs;
129 // Flag to indicate if ICF has been run.
130 bool icf_ready_;
131
132 // These lists are populated by gc_process_relocs in gc.h.
133 Section_list section_reloc_list_;
134 Symbol_list symbol_reloc_list_;
135 Addend_list addend_reloc_list_;
136 };
137
138 } // End of namespace gold.
139
140 #endif
This page took 0.034619 seconds and 4 git commands to generate.