Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 015ed51

Browse files
committed
switch over to std::map
1 parent 4c78b6e commit 015ed51

File tree

1 file changed

+59
-56
lines changed

1 file changed

+59
-56
lines changed

gcc/config/riscv/riscv-gen-pack.c

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
3636
#include "insn-attr.h"
3737

3838
#include <vector>
39+
#include <map>
3940

4041
namespace {
4142

@@ -85,14 +86,12 @@ class pass_gen_pack : public rtl_opt_pass
8586
reg_bits_low,
8687
reg_bits_high
8788
} reg_bits_low_high;
88-
typedef int_hash <HOST_WIDE_INT, 0> wideint_hash;
89-
typedef nofree_ptr_hash <rtx_insn> rtxinsn_hash;
90-
typedef hash_map <wideint_hash, reg_bits_prop> inum_bits_map;
91-
typedef hash_map <wideint_hash, rtx_insn*> inum_def_map;
92-
typedef hash_map <wideint_hash, std::vector<HOST_WIDE_INT> > regno_inum_map;
93-
typedef hash_map <wideint_hash, HOST_WIDE_INT> inum_regno_map;
94-
typedef hash_map <wideint_hash, rtx> inum_source_map;
95-
typedef hash_map <rtxinsn_hash, HOST_WIDE_INT> insn_inum_map;
89+
typedef std::map<HOST_WIDE_INT, reg_bits_prop> inum_bits_map;
90+
typedef std::map<HOST_WIDE_INT, rtx_insn*> inum_def_map;
91+
typedef std::map<HOST_WIDE_INT, std::vector<HOST_WIDE_INT> > regno_inum_map;
92+
typedef std::map<HOST_WIDE_INT, HOST_WIDE_INT> inum_regno_map;
93+
typedef std::map<HOST_WIDE_INT, rtx> inum_source_map;
94+
typedef std::map<rtx_insn*, HOST_WIDE_INT> insn_inum_map;
9695
struct gen_pack_maps_t {
9796
HOST_WIDE_INT cinum;
9897
inum_bits_map* ibm;
@@ -102,17 +101,44 @@ class pass_gen_pack : public rtl_opt_pass
102101
inum_source_map* ishm;
103102
inum_source_map* islm;
104103
insn_inum_map* iim;
104+
void alloc(void) {
105+
ibm = new inum_bits_map;
106+
idm = new inum_def_map;
107+
rim = new regno_inum_map;
108+
irm = new inum_regno_map;
109+
ishm = new inum_source_map;
110+
islm = new inum_source_map;
111+
iim = new insn_inum_map;
112+
}
113+
void free() {
114+
delete ibm;
115+
delete idm;
116+
delete rim;
117+
delete irm;
118+
delete ishm;
119+
delete islm;
120+
delete iim;
121+
}
122+
void reset(void) {
123+
cinum = 0;
124+
ibm->clear();
125+
idm->clear();
126+
rim->clear();
127+
irm->clear();
128+
ishm->clear();
129+
islm->clear();
130+
iim->clear();
131+
}
105132
HOST_WIDE_INT get_num(rtx_insn* insn) {
106133
if (insn == NULL)
107134
return -1;
108-
HOST_WIDE_INT* inumptr = iim->get(insn);
109-
if (inumptr != NULL)
110-
return *inumptr;
111-
return -1;
135+
if (iim->find(insn) == iim->end())
136+
return -1;
137+
return (*iim)[insn];
112138
}
113139
HOST_WIDE_INT get_inum(const HOST_WIDE_INT regno, rtx_insn* before) {
114140
HOST_WIDE_INT binum = get_num(before);;
115-
std::vector<HOST_WIDE_INT>& inums = rim->get_or_insert(regno);
141+
std::vector<HOST_WIDE_INT>& inums = (*rim)[regno];
116142
if (inums.size() < 1) {
117143
return -1;
118144
}
@@ -129,46 +155,42 @@ class pass_gen_pack : public rtl_opt_pass
129155
HOST_WIDE_INT inum = get_inum(regno, before);
130156
if (inum == -1)
131157
return REG_UNKNOWN;
132-
reg_bits_prop *rbp = ibm->get(inum);
133-
if (rbp == NULL)
158+
if (ibm->find(inum) == ibm->end())
134159
return REG_UNKNOWN;
135-
return *rbp;
160+
return (*ibm)[inum];
136161
}
137162
rtx_insn* get_def_insn(const HOST_WIDE_INT regno, rtx_insn* before = NULL) {
138163
HOST_WIDE_INT inum = get_inum(regno, before);
139164
if (inum == -1)
140165
return NULL;
141-
rtx_insn **insn = idm->get(inum);
142-
if (insn == NULL)
166+
if (idm->find(inum) == idm->end())
143167
return NULL;
144-
return *insn;
168+
return (*idm)[inum];
145169
}
146170
rtx get_source_low(const HOST_WIDE_INT regno, rtx_insn* before = NULL) {
147171
HOST_WIDE_INT inum = get_inum(regno, before);
148172
if (inum == -1)
149173
return NULL;
150-
rtx *s = islm->get(inum);
151-
if (s == NULL)
174+
if (islm->find(inum) == islm->end())
152175
return NULL;
153-
return *s;
176+
return (*islm)[inum];
154177
}
155178
rtx get_source_high(const HOST_WIDE_INT regno, rtx_insn* before = NULL) {
156179
HOST_WIDE_INT inum = get_inum(regno, before);
157180
if (inum == -1)
158181
return NULL;
159-
rtx *s = ishm->get(regno);
160-
if (s == NULL)
182+
if (ishm->find(inum) == ishm->end())
161183
return NULL;
162-
return *s;
184+
return (*ishm)[inum];
163185
}
164186
void fill(HOST_WIDE_INT regno, reg_bits_prop rbp, rtx_insn* def, rtx source_low, rtx source_high) {
165-
ibm->put(cinum, rbp);
166-
idm->put(cinum, def);
167-
irm->put(cinum, regno);
168-
rim->get_or_insert(regno).push_back(cinum);
169-
islm->put(cinum, source_low);
170-
ishm->put(cinum, source_high);
171-
iim->put(def, cinum);
187+
(*ibm)[cinum] = rbp;
188+
(*idm)[cinum] = def;
189+
(*irm)[cinum] = regno;
190+
(*rim)[regno].push_back(cinum);
191+
(*islm)[cinum] = source_low;
192+
(*ishm)[cinum] = source_high;
193+
(*iim)[def] = cinum;
172194
cinum++;
173195
}
174196
};
@@ -1218,27 +1240,14 @@ pass_gen_pack::execute (function *fn)
12181240
unsigned int c_packhu = 0;
12191241
unsigned int c_pack = 0;
12201242
unsigned int c_packu = 0;
1243+
struct gen_pack_maps_t gen_pack_maps;
1244+
gen_pack_maps.alloc();
12211245

12221246
FOR_ALL_BB_FN (bb, fn)
12231247
{
1224-
struct gen_pack_maps_t gen_pack_maps;
1225-
gen_pack_maps.ibm = hash_map<wideint_hash, reg_bits_prop>::create_ggc (10);
1226-
gen_pack_maps.idm = hash_map<wideint_hash, rtx_insn *>::create_ggc (10);
1227-
gen_pack_maps.rim = hash_map<wideint_hash, std::vector<HOST_WIDE_INT> >::create_ggc (10);
1228-
gen_pack_maps.irm = hash_map<wideint_hash, HOST_WIDE_INT>::create_ggc (10);
1229-
gen_pack_maps.ishm = hash_map<wideint_hash, rtx>::create_ggc (10);
1230-
gen_pack_maps.islm = hash_map<wideint_hash, rtx>::create_ggc (10);
1231-
gen_pack_maps.iim = hash_map<rtxinsn_hash, HOST_WIDE_INT>::create_ggc (10);
12321248
start_or:
12331249
{
1234-
gen_pack_maps.cinum = 0;
1235-
gen_pack_maps.ibm->empty();
1236-
gen_pack_maps.idm->empty();
1237-
gen_pack_maps.rim->empty();
1238-
gen_pack_maps.irm->empty();
1239-
gen_pack_maps.ishm->empty();
1240-
gen_pack_maps.islm->empty();
1241-
gen_pack_maps.iim->empty();
1250+
gen_pack_maps.reset();
12421251
FOR_BB_INSNS (bb, insn)
12431252
{
12441253
if (analyze (insn, &gen_pack_maps)) {
@@ -1251,14 +1260,7 @@ pass_gen_pack::execute (function *fn)
12511260
}
12521261
start_pack:
12531262
{
1254-
gen_pack_maps.cinum = 0;
1255-
gen_pack_maps.ibm->empty();
1256-
gen_pack_maps.idm->empty();
1257-
gen_pack_maps.rim->empty();
1258-
gen_pack_maps.irm->empty();
1259-
gen_pack_maps.ishm->empty();
1260-
gen_pack_maps.islm->empty();
1261-
gen_pack_maps.iim->empty();
1263+
gen_pack_maps.reset();
12621264
FOR_BB_INSNS (bb, insn)
12631265
{
12641266
if (analyze (insn, &gen_pack_maps)) {
@@ -1286,6 +1288,7 @@ pass_gen_pack::execute (function *fn)
12861288
}
12871289
}
12881290
}
1291+
gen_pack_maps.free();
12891292
if ((c_packh | c_packhm | c_packhu | c_pack | c_packu | c_treeor) == 0) {
12901293
//printf("%s:%d: generated no pack* for '%s'\n", __PRETTY_FUNCTION__, __LINE__, function_name(fn));
12911294
} else {

0 commit comments

Comments
 (0)