[llvm] 9abb574 - [MC] Make MCCFIInstruction smaller
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 6 14:24:05 PDT 2024
Author: Fangrui Song
Date: 2024-07-06T14:24:01-07:00
New Revision: 9abb574f9a68b1c0c32f49745f9dad8e1a7db1f9
URL: https://github.com/llvm/llvm-project/commit/9abb574f9a68b1c0c32f49745f9dad8e1a7db1f9
DIFF: https://github.com/llvm/llvm-project/commit/9abb574f9a68b1c0c32f49745f9dad8e1a7db1f9.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/MC/MCDwarf.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCDwarf.h b/llvm/include/llvm/MC/MCDwarf.h
index 18056c5fdf816..5052c6756c32b 100644
--- a/llvm/include/llvm/MC/MCDwarf.h
+++ b/llvm/include/llvm/MC/MCDwarf.h
@@ -483,7 +483,7 @@ class MCGenDwarfLabelEntry {
class MCCFIInstruction {
public:
- enum OpType {
+ enum OpType : uint8_t {
OpSameValue,
OpRememberState,
OpRestoreState,
@@ -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:
@@ -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 {
More information about the llvm-commits
mailing list