Added
Link Here
|
1 |
commit d15d49b09dc7aef9edcc4cf6a0cb2b77a0db203f |
2 |
Author: Nico Weber <thakis@chromium.org> |
3 |
Date: 2022-07-29 20:07:40 -0400 |
4 |
|
5 |
Make bitfields only as wide as necessary for enums |
6 |
|
7 |
clang now complains when a BitField for an enum is too wide. |
8 |
We could suppress this, but it seems kind of useful from an |
9 |
uninformed distance, so I made a few bitfields smaller instead. |
10 |
|
11 |
(For AddressingMode, since its size is target-dependent, I added |
12 |
an explicit underlying type to the enum instead, which suppresses |
13 |
the diag on a per-enum basis.) |
14 |
|
15 |
This is without any understanding of the code I'm touching. |
16 |
Especially the change in v8-internal.h feels a bit risky to me. |
17 |
|
18 |
Bug: chromium:1348574 |
19 |
Change-Id: I73395de593045036b72dadf4e3147b5f7e13c958 |
20 |
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3794708 |
21 |
Commit-Queue: Nico Weber <thakis@chromium.org> |
22 |
Reviewed-by: Leszek Swirski <leszeks@chromium.org> |
23 |
Reviewed-by: Hannes Payer <hpayer@chromium.org> |
24 |
Auto-Submit: Nico Weber <thakis@chromium.org> |
25 |
Cr-Commit-Position: refs/heads/main@{#82109} |
26 |
|
27 |
--- deps/v8/include/v8-internal.h.orig 2023-03-28 21:14:19 UTC |
28 |
+++ deps/v8/include/v8-internal.h |
29 |
@@ -253,7 +253,7 @@ class Internals { |
30 |
|
31 |
static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize; |
32 |
static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3; |
33 |
- static const int kNodeStateMask = 0x7; |
34 |
+ static const int kNodeStateMask = 0x3; |
35 |
static const int kNodeStateIsWeakValue = 2; |
36 |
static const int kNodeStateIsPendingValue = 3; |
37 |
|
38 |
--- deps/v8/src/ast/ast.h.orig 2023-03-28 21:14:19 UTC |
39 |
+++ deps/v8/src/ast/ast.h |
40 |
@@ -998,7 +998,7 @@ class Literal final : public Expression { |
41 |
friend class AstNodeFactory; |
42 |
friend Zone; |
43 |
|
44 |
- using TypeField = Expression::NextBitField<Type, 4>; |
45 |
+ using TypeField = Expression::NextBitField<Type, 3>; |
46 |
|
47 |
Literal(int smi, int position) : Expression(position, kLiteral), smi_(smi) { |
48 |
bit_field_ = TypeField::update(bit_field_, kSmi); |
49 |
--- deps/v8/src/base/bit-field.h.orig 2023-03-28 21:14:19 UTC |
50 |
+++ deps/v8/src/base/bit-field.h |
51 |
@@ -40,6 +40,11 @@ class BitField final { |
52 |
static constexpr U kNumValues = U{1} << kSize; |
53 |
|
54 |
// Value for the field with all bits set. |
55 |
+ // If clang complains |
56 |
+ // "constexpr variable 'kMax' must be initialized by a constant expression" |
57 |
+ // on this line, then you're creating a BitField for an enum with more bits |
58 |
+ // than needed for the enum values. Either reduce the BitField size, |
59 |
+ // or give the enum an explicit underlying type. |
60 |
static constexpr T kMax = static_cast<T>(kNumValues - 1); |
61 |
|
62 |
template <class T2, int size2> |
63 |
--- deps/v8/src/compiler/backend/instruction-codes.h.orig 2023-03-28 21:14:19 UTC |
64 |
+++ deps/v8/src/compiler/backend/instruction-codes.h |
65 |
@@ -191,7 +191,7 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostrea |
66 |
V(None) \ |
67 |
TARGET_ADDRESSING_MODE_LIST(V) |
68 |
|
69 |
-enum AddressingMode { |
70 |
+enum AddressingMode : uint8_t { |
71 |
#define DECLARE_ADDRESSING_MODE(Name) kMode_##Name, |
72 |
ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE) |
73 |
#undef DECLARE_ADDRESSING_MODE |
74 |
@@ -282,7 +282,7 @@ using LaneSizeField = base::BitField<int, 22, 8>; |
75 |
// LaneSizeField and AccessModeField are helper types to encode/decode a lane |
76 |
// size, an access mode, or both inside the overlapping MiscField. |
77 |
using LaneSizeField = base::BitField<int, 22, 8>; |
78 |
-using AccessModeField = base::BitField<MemoryAccessMode, 30, 2>; |
79 |
+using AccessModeField = base::BitField<MemoryAccessMode, 30, 1>; |
80 |
using MiscField = base::BitField<int, 22, 10>; |
81 |
|
82 |
} // namespace compiler |
83 |
--- deps/v8/src/compiler/backend/instruction.h.orig 2023-03-28 21:14:19 UTC |
84 |
+++ deps/v8/src/compiler/backend/instruction.h |
85 |
@@ -584,8 +584,8 @@ class LocationOperand : public InstructionOperand { |
86 |
} |
87 |
|
88 |
STATIC_ASSERT(KindField::kSize == 3); |
89 |
- using LocationKindField = base::BitField64<LocationKind, 3, 2>; |
90 |
- using RepresentationField = base::BitField64<MachineRepresentation, 5, 8>; |
91 |
+ using LocationKindField = base::BitField64<LocationKind, 3, 1>; |
92 |
+ using RepresentationField = LocationKindField::Next<MachineRepresentation, 8>; |
93 |
using IndexField = base::BitField64<int32_t, 35, 29>; |
94 |
}; |
95 |
|
96 |
--- deps/v8/src/handles/global-handles.cc.orig 2023-03-28 21:14:19 UTC |
97 |
+++ deps/v8/src/handles/global-handles.cc |
98 |
@@ -618,7 +618,7 @@ class GlobalHandles::Node final : public NodeBase<Glob |
99 |
|
100 |
// This stores three flags (independent, partially_dependent and |
101 |
// in_young_list) and a State. |
102 |
- using NodeState = base::BitField8<State, 0, 3>; |
103 |
+ using NodeState = base::BitField8<State, 0, 2>; |
104 |
using IsInYoungList = NodeState::Next<bool, 1>; |
105 |
using NodeWeaknessType = IsInYoungList::Next<WeaknessType, 2>; |
106 |
|
107 |
--- deps/v8/src/profiler/profile-generator.h.orig 2023-03-28 23:14:19 UTC |
108 |
+++ deps/v8/src/profiler/profile-generator.h |
109 |
@@ -224,7 +224,7 @@ class CodeEntry { |
110 |
return ref_count_; |
111 |
} |
112 |
|
113 |
- using TagField = base::BitField<CodeEventListener::LogEventsAndTags, 0, 8>; |
114 |
+ using TagField = base::BitField<CodeEventListener::LogEventsAndTags, 0, 5>; |
115 |
using BuiltinField = base::BitField<Builtin, 8, 20>; |
116 |
static_assert(Builtins::kBuiltinCount <= BuiltinField::kNumValues, |
117 |
"builtin_count exceeds size of bitfield"); |
118 |
--- deps/v8/src/wasm/wasm-code-manager.h.orig 2023-03-28 21:14:19 UTC |
119 |
+++ deps/v8/src/wasm/wasm-code-manager.h |
120 |
@@ -440,7 +440,7 @@ class V8_EXPORT_PRIVATE WasmCode final { |
121 |
int trap_handler_index_ = -1; |
122 |
|
123 |
// Bits encoded in {flags_}: |
124 |
- using KindField = base::BitField8<Kind, 0, 3>; |
125 |
+ using KindField = base::BitField8<Kind, 0, 2>; |
126 |
using ExecutionTierField = KindField::Next<ExecutionTier, 2>; |
127 |
using ForDebuggingField = ExecutionTierField::Next<ForDebugging, 2>; |
128 |
|