Skip to content

Commit 76ba29b

Browse files
authored
[NFC] Address bit-field storage sizes to ensure ideal packing (#139825)
The MS bit-field packing ABI depends on the storage size of the type of being placed in the bit-field. This PR addresses a number of cases in llvm where the storage type has lead to suboptimal packing.
1 parent c41812e commit 76ba29b

File tree

19 files changed

+69
-38
lines changed

19 files changed

+69
-38
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
18581858
/// This needs to be cached as deduction is performed during declaration,
18591859
/// and we need the information to be preserved so that it is consistent
18601860
/// during instantiation.
1861-
bool StrictPackMatch : 1;
1861+
LLVM_PREFERRED_TYPE(bool)
1862+
unsigned StrictPackMatch : 1;
18621863

18631864
protected:
18641865
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,

clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "llvm/ADT/ArrayRef.h"
5353
#include "llvm/ADT/StringRef.h"
5454
#include "llvm/Support/Casting.h"
55+
#include "llvm/Support/Compiler.h"
5556
#include "llvm/Support/raw_ostream.h"
5657
#include <algorithm>
5758
#include <cassert>
@@ -1664,7 +1665,8 @@ class BasicBlock : public SExpr {
16641665
unsigned BlockID : 31;
16651666

16661667
// Bit to determine if a block has been visited during a traversal.
1667-
bool Visited : 1;
1668+
LLVM_PREFERRED_TYPE(bool)
1669+
unsigned Visited : 1;
16681670

16691671
// Predecessor blocks in the CFG.
16701672
BlockArray Predecessors;

clang/include/clang/Basic/DiagnosticCategories.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace clang {
1313
namespace diag {
14-
enum {
14+
enum DiagCategory {
1515
#define GET_CATEGORY_TABLE
1616
#define CATEGORY(X, ENUM) ENUM,
1717
#include "clang/Basic/DiagnosticGroups.inc"

clang/include/clang/Sema/Overload.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,8 @@ class Sema;
986986
/// Have we matched any packs on the parameter side, versus any non-packs on
987987
/// the argument side, in a context where the opposite matching is also
988988
/// allowed?
989-
bool StrictPackMatch : 1;
989+
LLVM_PREFERRED_TYPE(bool)
990+
unsigned StrictPackMatch : 1;
990991

991992
/// True if the candidate was found using ADL.
992993
LLVM_PREFERRED_TYPE(CallExpr::ADLCallKind)
@@ -1002,7 +1003,8 @@ class Sema;
10021003

10031004
/// FailureKind - The reason why this candidate is not viable.
10041005
/// Actually an OverloadFailureKind.
1005-
unsigned char FailureKind;
1006+
LLVM_PREFERRED_TYPE(OverloadFailureKind)
1007+
unsigned FailureKind : 8;
10061008

10071009
/// The number of call arguments that were explicitly provided,
10081010
/// to be used while performing partial ordering of function templates.

clang/include/clang/Sema/ScopeInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ enum class FirstCoroutineStmtKind { CoReturn, CoAwait, CoYield };
103103
/// currently being parsed.
104104
class FunctionScopeInfo {
105105
protected:
106-
enum ScopeKind {
106+
enum ScopeKind : uint8_t {
107107
SK_Function,
108108
SK_Block,
109109
SK_Lambda,

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2020
#include "llvm/ADT/StringMap.h"
2121
#include "llvm/ADT/StringRef.h"
22+
#include "llvm/Support/Compiler.h"
2223
#include <string>
2324
#include <utility>
2425
#include <vector>
@@ -269,7 +270,8 @@ class AnalyzerOptions {
269270
unsigned NoRetryExhausted : 1;
270271

271272
/// Emit analyzer warnings as errors.
272-
bool AnalyzerWerror : 1;
273+
LLVM_PREFERRED_TYPE(bool)
274+
unsigned AnalyzerWerror : 1;
273275

274276
/// The inlining stack depth limit.
275277
unsigned InlineMaxStackDepth;
@@ -410,7 +412,7 @@ class AnalyzerOptions {
410412
// an alias to the new verbose filename option because this
411413
// closely mimics the behavior under the old option.
412414
ShouldWriteStableReportFilename || ShouldWriteVerboseReportFilename,
413-
AnalyzerWerror,
415+
static_cast<bool>(AnalyzerWerror),
414416
ShouldApplyFixIts,
415417
ShouldDisplayCheckerNameForText};
416418
}

clang/lib/Basic/DiagnosticIDs.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/ADT/SmallVector.h"
2020
#include "llvm/ADT/StringTable.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/ErrorHandling.h"
2223
#include "llvm/Support/Path.h"
2324
#include <map>
@@ -74,19 +75,21 @@ enum DiagnosticClass {
7475
struct StaticDiagInfoRec {
7576
uint16_t DiagID;
7677
LLVM_PREFERRED_TYPE(diag::Severity)
77-
uint8_t DefaultSeverity : 3;
78+
uint16_t DefaultSeverity : 3;
7879
LLVM_PREFERRED_TYPE(DiagnosticClass)
79-
uint8_t Class : 3;
80+
uint16_t Class : 3;
8081
LLVM_PREFERRED_TYPE(DiagnosticIDs::SFINAEResponse)
81-
uint8_t SFINAE : 2;
82-
uint8_t Category : 6;
82+
uint16_t SFINAE : 2;
83+
LLVM_PREFERRED_TYPE(diag::DiagCategory)
84+
uint16_t Category : 6;
8385
LLVM_PREFERRED_TYPE(bool)
84-
uint8_t WarnNoWerror : 1;
86+
uint16_t WarnNoWerror : 1;
8587
LLVM_PREFERRED_TYPE(bool)
86-
uint8_t WarnShowInSystemHeader : 1;
88+
uint16_t WarnShowInSystemHeader : 1;
8789
LLVM_PREFERRED_TYPE(bool)
88-
uint8_t WarnShowInSystemMacro : 1;
90+
uint16_t WarnShowInSystemMacro : 1;
8991

92+
LLVM_PREFERRED_TYPE(diag::Group)
9093
uint16_t OptionGroupIndex : 15;
9194
LLVM_PREFERRED_TYPE(bool)
9295
uint16_t Deferrable : 1;

llvm/include/llvm/ADT/ImmutableSet.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/iterator.h"
2222
#include "llvm/Support/Allocator.h"
23+
#include "llvm/Support/Compiler.h"
2324
#include "llvm/Support/ErrorHandling.h"
2425
#include <cassert>
2526
#include <cstdint>
@@ -213,9 +214,12 @@ class ImutAVLTree {
213214
ImutAVLTree *next = nullptr;
214215

215216
unsigned height : 28;
216-
bool IsMutable : 1;
217-
bool IsDigestCached : 1;
218-
bool IsCanonicalized : 1;
217+
LLVM_PREFERRED_TYPE(bool)
218+
unsigned IsMutable : 1;
219+
LLVM_PREFERRED_TYPE(bool)
220+
unsigned IsDigestCached : 1;
221+
LLVM_PREFERRED_TYPE(bool)
222+
unsigned IsCanonicalized : 1;
219223

220224
value_type value;
221225
uint32_t digest = 0;

llvm/include/llvm/Bitstream/BitCodes.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/StringExtras.h"
2222
#include "llvm/Bitstream/BitCodeEnums.h"
23+
#include "llvm/Support/Compiler.h"
2324
#include "llvm/Support/DataTypes.h"
2425
#include "llvm/Support/ErrorHandling.h"
2526
#include <cassert>
@@ -31,9 +32,6 @@ namespace llvm {
3132
/// 2. It could be an encoding specification ("this operand encoded like so").
3233
///
3334
class BitCodeAbbrevOp {
34-
uint64_t Val; // A literal value or data for an encoding.
35-
bool IsLiteral : 1; // Indicate whether this is a literal value or not.
36-
unsigned Enc : 3; // The encoding to use.
3735
public:
3836
enum Encoding {
3937
Fixed = 1, // A fixed width field, Val specifies number of bits.
@@ -43,6 +41,14 @@ class BitCodeAbbrevOp {
4341
Blob = 5 // 32-bit aligned array of 8-bit characters.
4442
};
4543

44+
protected:
45+
uint64_t Val; // A literal value or data for an encoding.
46+
LLVM_PREFERRED_TYPE(bool)
47+
uint64_t IsLiteral : 1; // Indicate whether this is a literal value or not.
48+
LLVM_PREFERRED_TYPE(Encoding)
49+
uint64_t Enc : 3; // The encoding to use.
50+
51+
public:
4652
static bool isValidEncoding(uint64_t E) {
4753
return E >= 1 && E <= 5;
4854
}

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class MachineInstr
149149
/// Various bits of information used by the AsmPrinter to emit helpful
150150
/// comments. This is *not* semantic information. Do not use this for
151151
/// anything other than to convey comment information to AsmPrinter.
152-
uint8_t AsmPrinterFlags : LLVM_MI_ASMPRINTERFLAGS_BITS;
152+
uint32_t AsmPrinterFlags : LLVM_MI_ASMPRINTERFLAGS_BITS;
153153

154154
/// Internal implementation detail class that provides out-of-line storage for
155155
/// extra info used by the machine instruction when this info cannot be stored

llvm/include/llvm/Demangle/ItaniumDemangle.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "DemangleConfig.h"
2020
#include "StringViewExtras.h"
2121
#include "Utility.h"
22+
#include "llvm/Support/Compiler.h"
2223
#include <algorithm>
2324
#include <cctype>
2425
#include <cstdio>
@@ -164,18 +165,18 @@ class NodeArray;
164165
// traversed by the printLeft/Right functions to produce a demangled string.
165166
class Node {
166167
public:
167-
enum Kind : unsigned char {
168+
enum Kind : uint8_t {
168169
#define NODE(NodeKind) K##NodeKind,
169170
#include "ItaniumNodes.def"
170171
};
171172

172173
/// Three-way bool to track a cached value. Unknown is possible if this node
173174
/// has an unexpanded parameter pack below it that may affect this cache.
174-
enum class Cache : unsigned char { Yes, No, Unknown, };
175+
enum class Cache : uint8_t { Yes, No, Unknown, };
175176

176177
/// Operator precedence for expression nodes. Used to determine required
177178
/// parens in expression emission.
178-
enum class Prec {
179+
enum class Prec : uint8_t {
179180
Primary,
180181
Postfix,
181182
Unary,

llvm/include/llvm/IR/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,8 @@ class MDNode : public Metadata {
10761076
/// Explicity set alignment because bitfields by default have an
10771077
/// alignment of 1 on z/OS.
10781078
struct alignas(alignof(size_t)) Header {
1079-
bool IsResizable : 1;
1080-
bool IsLarge : 1;
1079+
size_t IsResizable : 1;
1080+
size_t IsLarge : 1;
10811081
size_t SmallSize : 4;
10821082
size_t SmallNumOps : 4;
10831083
size_t : sizeof(size_t) * CHAR_BIT - 10;

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/IR/GlobalValue.h"
2929
#include "llvm/IR/Module.h"
3030
#include "llvm/Support/Allocator.h"
31+
#include "llvm/Support/Compiler.h"
3132
#include "llvm/Support/InterleavedRange.h"
3233
#include "llvm/Support/MathExtras.h"
3334
#include "llvm/Support/ScaledNumber.h"
@@ -72,7 +73,8 @@ struct CalleeInfo {
7273
uint32_t Hotness : 3;
7374

7475
// True if at least one of the calls to the callee is a tail call.
75-
bool HasTailCall : 1;
76+
LLVM_PREFERRED_TYPE(bool)
77+
uint32_t HasTailCall : 1;
7678

7779
/// The value stored in RelBlockFreq has to be interpreted as the digits of
7880
/// a scaled number with a scale of \p -ScaleShift.

llvm/include/llvm/IR/User.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ class User : public Value {
7979
struct AllocInfo {
8080
public:
8181
const unsigned NumOps : NumUserOperandsBits;
82-
const bool HasHungOffUses : 1;
83-
const bool HasDescriptor : 1;
82+
LLVM_PREFERRED_TYPE(bool)
83+
const unsigned HasHungOffUses : 1;
84+
LLVM_PREFERRED_TYPE(bool)
85+
const unsigned HasDescriptor : 1;
8486

8587
AllocInfo() = delete;
8688

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
6363
int DataOffset : 31;
6464

6565
/// Non-zero if this is a piece of an aggregate.
66-
uint16_t IsSubfield : 1;
66+
uint32_t IsSubfield : 1;
6767

6868
/// Offset into aggregate.
69-
uint16_t StructOffset : 15;
69+
uint32_t StructOffset : 15;
7070

7171
/// Register containing the data or the register base of the memory
7272
/// location containing the data.

llvm/lib/Target/AArch64/AArch64CollectLOH.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,12 @@ static int mapRegToGPRIndex(MCRegister Reg) {
272272
/// datastructure for each tracked general purpose register.
273273
struct LOHInfo {
274274
MCLOHType Type : 8; ///< "Best" type of LOH possible.
275-
bool IsCandidate : 1; ///< Possible LOH candidate.
276-
bool OneUser : 1; ///< Found exactly one user (yet).
277-
bool MultiUsers : 1; ///< Found multiple users.
275+
LLVM_PREFERRED_TYPE(bool)
276+
unsigned IsCandidate : 1; ///< Possible LOH candidate.
277+
LLVM_PREFERRED_TYPE(bool)
278+
unsigned OneUser : 1; ///< Found exactly one user (yet).
279+
LLVM_PREFERRED_TYPE(bool)
280+
unsigned MultiUsers : 1; ///< Found multiple users.
278281
const MachineInstr *MI0; ///< First instruction involved in the LOH.
279282
const MachineInstr *MI1; ///< Second instruction involved in the LOH
280283
/// (if any).

llvm/lib/Target/ARM/ARMConstantIslandPass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ namespace {
193193
struct ImmBranch {
194194
MachineInstr *MI;
195195
unsigned MaxDisp : 31;
196-
bool isCond : 1;
196+
LLVM_PREFERRED_TYPE(bool)
197+
unsigned isCond : 1;
197198
unsigned UncondBr;
198199

199200
ImmBranch(MachineInstr *mi, unsigned maxdisp, bool cond, unsigned ubr)

llvm/lib/Target/CSKY/CSKYConstantIslandPass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ class CSKYConstantIslands : public MachineFunctionPass {
184184
struct ImmBranch {
185185
MachineInstr *MI;
186186
unsigned MaxDisp : 31;
187-
bool IsCond : 1;
187+
LLVM_PREFERRED_TYPE(bool)
188+
unsigned IsCond : 1;
188189
int UncondBr;
189190

190191
ImmBranch(MachineInstr *Mi, unsigned Maxdisp, bool Cond, int Ubr)

llvm/lib/Target/Mips/MipsConstantIslandPass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ namespace {
321321
struct ImmBranch {
322322
MachineInstr *MI;
323323
unsigned MaxDisp : 31;
324-
bool isCond : 1;
324+
LLVM_PREFERRED_TYPE(bool)
325+
unsigned isCond : 1;
325326
int UncondBr;
326327

327328
ImmBranch(MachineInstr *mi, unsigned maxdisp, bool cond, int ubr)

0 commit comments

Comments
 (0)