Skip to content

Commit 9abb574

Browse files
committed
[MC] Make MCCFIInstruction smaller
by placing `Operation` next to a 4-byte member. Refactor the union representation so that it is easy to add a pointer member for .cfi_label support without increasing the total size. There are two primary forms (RI and RR) and RIA for AMDGPU-specific .cfi_llvm_def_aspace_cfa.
1 parent 5028dea commit 9abb574

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

llvm/include/llvm/MC/MCDwarf.h

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class MCGenDwarfLabelEntry {
483483

484484
class MCCFIInstruction {
485485
public:
486-
enum OpType {
486+
enum OpType : uint8_t {
487487
OpSameValue,
488488
OpRememberState,
489489
OpRestoreState,
@@ -504,35 +504,44 @@ class MCCFIInstruction {
504504
};
505505

506506
private:
507-
OpType Operation;
508507
MCSymbol *Label;
509-
unsigned Register;
510508
union {
511-
int Offset;
512-
unsigned Register2;
513-
};
514-
unsigned AddressSpace = ~0u;
509+
struct {
510+
unsigned Register;
511+
int Offset;
512+
} RI;
513+
struct {
514+
unsigned Register;
515+
int Offset;
516+
unsigned AddressSpace;
517+
} RIA;
518+
struct {
519+
unsigned Register;
520+
unsigned Register2;
521+
} RR;
522+
} U;
523+
OpType Operation;
515524
SMLoc Loc;
516525
std::vector<char> Values;
517526
std::string Comment;
518527

519528
MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int O, SMLoc Loc,
520529
StringRef V = "", StringRef Comment = "")
521-
: Operation(Op), Label(L), Register(R), Offset(O), Loc(Loc),
522-
Values(V.begin(), V.end()), Comment(Comment) {
530+
: Label(L), Operation(Op), Loc(Loc), Values(V.begin(), V.end()),
531+
Comment(Comment) {
523532
assert(Op != OpRegister && Op != OpLLVMDefAspaceCfa);
533+
U.RI = {R, O};
524534
}
525-
526535
MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R1, unsigned R2, SMLoc Loc)
527-
: Operation(Op), Label(L), Register(R1), Register2(R2), Loc(Loc) {
536+
: Label(L), Operation(Op), Loc(Loc) {
528537
assert(Op == OpRegister);
538+
U.RR = {R1, R2};
529539
}
530-
531540
MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int O, unsigned AS,
532541
SMLoc Loc)
533-
: Operation(Op), Label(L), Register(R), Offset(O), AddressSpace(AS),
534-
Loc(Loc) {
542+
: Label(L), Operation(Op), Loc(Loc) {
535543
assert(Op == OpLLVMDefAspaceCfa);
544+
U.RIA = {R, O, AS};
536545
}
537546

538547
public:
@@ -659,30 +668,34 @@ class MCCFIInstruction {
659668
MCSymbol *getLabel() const { return Label; }
660669

661670
unsigned getRegister() const {
671+
if (Operation == OpRegister)
672+
return U.RR.Register;
673+
if (Operation == OpLLVMDefAspaceCfa)
674+
return U.RIA.Register;
662675
assert(Operation == OpDefCfa || Operation == OpOffset ||
663676
Operation == OpRestore || Operation == OpUndefined ||
664677
Operation == OpSameValue || Operation == OpDefCfaRegister ||
665-
Operation == OpRelOffset || Operation == OpRegister ||
666-
Operation == OpLLVMDefAspaceCfa);
667-
return Register;
678+
Operation == OpRelOffset);
679+
return U.RI.Register;
668680
}
669681

670682
unsigned getRegister2() const {
671683
assert(Operation == OpRegister);
672-
return Register2;
684+
return U.RR.Register2;
673685
}
674686

675687
unsigned getAddressSpace() const {
676688
assert(Operation == OpLLVMDefAspaceCfa);
677-
return AddressSpace;
689+
return U.RIA.AddressSpace;
678690
}
679691

680692
int getOffset() const {
693+
if (Operation == OpLLVMDefAspaceCfa)
694+
return U.RIA.Offset;
681695
assert(Operation == OpDefCfa || Operation == OpOffset ||
682696
Operation == OpRelOffset || Operation == OpDefCfaOffset ||
683-
Operation == OpAdjustCfaOffset || Operation == OpGnuArgsSize ||
684-
Operation == OpLLVMDefAspaceCfa);
685-
return Offset;
697+
Operation == OpAdjustCfaOffset || Operation == OpGnuArgsSize);
698+
return U.RI.Offset;
686699
}
687700

688701
StringRef getValues() const {

0 commit comments

Comments
 (0)