Skip to content

Commit

Permalink
[MC] Make MCCFIInstruction smaller
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MaskRay committed Jul 6, 2024
1 parent 5028dea commit 9abb574
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions llvm/include/llvm/MC/MCDwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class MCGenDwarfLabelEntry {

class MCCFIInstruction {
public:
enum OpType {
enum OpType : uint8_t {
OpSameValue,
OpRememberState,
OpRestoreState,
Expand All @@ -504,35 +504,44 @@ class MCCFIInstruction {
};

private:
OpType Operation;
MCSymbol *Label;
unsigned Register;
union {
int Offset;
unsigned Register2;
};
unsigned AddressSpace = ~0u;
struct {
unsigned Register;
int Offset;
} RI;
struct {
unsigned Register;
int Offset;
unsigned AddressSpace;
} RIA;
struct {
unsigned Register;
unsigned Register2;
} RR;
} U;
OpType Operation;
SMLoc Loc;
std::vector<char> Values;
std::string Comment;

MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int O, SMLoc Loc,
StringRef V = "", StringRef Comment = "")
: Operation(Op), Label(L), Register(R), Offset(O), Loc(Loc),
Values(V.begin(), V.end()), Comment(Comment) {
: Label(L), Operation(Op), Loc(Loc), Values(V.begin(), V.end()),
Comment(Comment) {
assert(Op != OpRegister && Op != OpLLVMDefAspaceCfa);
U.RI = {R, O};
}

MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R1, unsigned R2, SMLoc Loc)
: Operation(Op), Label(L), Register(R1), Register2(R2), Loc(Loc) {
: Label(L), Operation(Op), Loc(Loc) {
assert(Op == OpRegister);
U.RR = {R1, R2};
}

MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int O, unsigned AS,
SMLoc Loc)
: Operation(Op), Label(L), Register(R), Offset(O), AddressSpace(AS),
Loc(Loc) {
: Label(L), Operation(Op), Loc(Loc) {
assert(Op == OpLLVMDefAspaceCfa);
U.RIA = {R, O, AS};
}

public:
Expand Down Expand Up @@ -659,30 +668,34 @@ class MCCFIInstruction {
MCSymbol *getLabel() const { return Label; }

unsigned getRegister() const {
if (Operation == OpRegister)
return U.RR.Register;
if (Operation == OpLLVMDefAspaceCfa)
return U.RIA.Register;
assert(Operation == OpDefCfa || Operation == OpOffset ||
Operation == OpRestore || Operation == OpUndefined ||
Operation == OpSameValue || Operation == OpDefCfaRegister ||
Operation == OpRelOffset || Operation == OpRegister ||
Operation == OpLLVMDefAspaceCfa);
return Register;
Operation == OpRelOffset);
return U.RI.Register;
}

unsigned getRegister2() const {
assert(Operation == OpRegister);
return Register2;
return U.RR.Register2;
}

unsigned getAddressSpace() const {
assert(Operation == OpLLVMDefAspaceCfa);
return AddressSpace;
return U.RIA.AddressSpace;
}

int getOffset() const {
if (Operation == OpLLVMDefAspaceCfa)
return U.RIA.Offset;
assert(Operation == OpDefCfa || Operation == OpOffset ||
Operation == OpRelOffset || Operation == OpDefCfaOffset ||
Operation == OpAdjustCfaOffset || Operation == OpGnuArgsSize ||
Operation == OpLLVMDefAspaceCfa);
return Offset;
Operation == OpAdjustCfaOffset || Operation == OpGnuArgsSize);
return U.RI.Offset;
}

StringRef getValues() const {
Expand Down

0 comments on commit 9abb574

Please sign in to comment.