Skip to content

Commit b0865b2

Browse files
alexmalyshevfacebook-github-bot
authored andcommitted
Shrink the size of PhyLocation
Summary: It's currently an `int` and a `size_t`. With padding that sums to 16 bytes. There's no need to use a `size_t` to represent the bit size of the location, it maxes out at 128. Use a `uint32_t` which drops the struct's size down to 8 bytes. This also drops the size of Operand from 48 to 40 bytes. Reviewed By: martindemello Differential Revision: D81930040 fbshipit-source-id: 3facb4560b4ae02960707db8c4abb0faaeb51447
1 parent d31fb65 commit b0865b2

2 files changed

Lines changed: 27 additions & 39 deletions

File tree

cinderx/Jit/codegen/x86_64.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,9 @@
22

33
#include "cinderx/Jit/codegen/x86_64.h"
44

5-
#include <utility>
6-
75
namespace jit::codegen {
86

9-
std::ostream& operator<<(std::ostream& os, const PhyLocation& loc) {
10-
return os << loc.toString();
11-
}
12-
13-
std::string PhyLocation::toString() const {
14-
if (is_memory()) {
15-
return fmt::format("[RBP({})]", loc);
16-
} else if (bitSize == 32) {
17-
return std::string{name32(static_cast<RegId>(loc))};
18-
} else if (bitSize == 16) {
19-
return std::string{name16(static_cast<RegId>(loc))};
20-
} else if (bitSize == 8) {
21-
return std::string{name8(static_cast<RegId>(loc))};
22-
}
23-
return std::string{name(static_cast<RegId>(loc))};
24-
}
25-
26-
// Parse the string given in name to the physical location. Currently only
27-
// parsing physical register names is supported.
28-
PhyLocation PhyLocation::parse(const std::string& name) {
7+
PhyLocation PhyLocation::parse(std::string_view name) {
298
#define FIND_GP_REG(V64, V32, V16, V8) \
309
if (name == #V64) { \
3110
return PhyLocation{RegId::V64, 64}; \
@@ -52,4 +31,21 @@ PhyLocation PhyLocation::parse(const std::string& name) {
5231
JIT_ABORT("Unrecognized register {}", name);
5332
}
5433

34+
std::string PhyLocation::toString() const {
35+
if (is_memory()) {
36+
return fmt::format("[RBP({})]", loc);
37+
} else if (bitSize == 32) {
38+
return std::string{name32(static_cast<RegId>(loc))};
39+
} else if (bitSize == 16) {
40+
return std::string{name16(static_cast<RegId>(loc))};
41+
} else if (bitSize == 8) {
42+
return std::string{name8(static_cast<RegId>(loc))};
43+
}
44+
return std::string{name(static_cast<RegId>(loc))};
45+
}
46+
47+
std::ostream& operator<<(std::ostream& os, const PhyLocation& loc) {
48+
return os << loc.toString();
49+
}
50+
5551
} // namespace jit::codegen

cinderx/Jit/codegen/x86_64.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ struct PhyLocation {
131131
FOREACH_XMM(DEFINE_REG)
132132
#undef DEFINE_REG
133133

134+
// Parse a register name and return the corresponding physical register.
135+
// Return REG_INVALID if the name is not a valid register name. Does not
136+
// support parsing stack slots.
137+
static PhyLocation parse(std::string_view name);
138+
139+
int32_t loc{REG_INVALID};
140+
uint32_t bitSize{64};
141+
134142
PhyLocation() = default;
135143

136144
/* implicit */ constexpr PhyLocation(RegId reg, size_t size = 64)
@@ -140,7 +148,7 @@ struct PhyLocation {
140148
: PhyLocation{static_cast<int>(reg), static_cast<size_t>(size)} {}
141149

142150
/* implicit */ constexpr PhyLocation(int loc, size_t size = 64)
143-
: loc{loc}, bitSize{size} {}
151+
: loc{loc}, bitSize{static_cast<uint32_t>(size)} {}
144152

145153
/* implicit */ constexpr PhyLocation(int loc, int size)
146154
: PhyLocation{loc, static_cast<size_t>(size)} {}
@@ -161,9 +169,6 @@ struct PhyLocation {
161169
return is_register() && loc >= XMM_REG_BASE;
162170
}
163171

164-
int loc{REG_INVALID};
165-
size_t bitSize{64};
166-
167172
std::string toString() const;
168173

169174
// Comparisons are based only on the register ID.
@@ -175,22 +180,9 @@ struct PhyLocation {
175180
return loc == rhs.loc;
176181
}
177182

178-
bool operator==(int rhs) const {
179-
return loc == rhs;
180-
}
181-
182183
bool operator!=(const PhyLocation& rhs) const {
183184
return loc != rhs.loc;
184185
}
185-
186-
bool operator!=(int rhs) const {
187-
return loc != rhs;
188-
}
189-
190-
// Parses the register name in string and returns the corresponding
191-
// physical register.
192-
// Returns REG_INVALID if name is not a valid register name.
193-
static PhyLocation parse(const std::string& name);
194186
};
195187

196188
// Define global definitions like `RAX` and `XMM0`.

0 commit comments

Comments
 (0)