[llvm] d575f80 - MCFixup: Make MCFixupKind a type alias

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 5 14:19:45 PDT 2025


Author: Fangrui Song
Date: 2025-07-05T14:19:40-07:00
New Revision: d575f802104f8fc28a42268608881cc1ce96033e

URL: https://github.com/llvm/llvm-project/commit/d575f802104f8fc28a42268608881cc1ce96033e
DIFF: https://github.com/llvm/llvm-project/commit/d575f802104f8fc28a42268608881cc1ce96033e.diff

LOG: MCFixup: Make MCFixupKind a type alias

The unscoped enumeration contains a fix generic kinds (e.g. FK_Data_).
However, most fixup kinds are target-specific (including relocation
code) and lead to a lot of casts. Make MCFixupKind a type alias instead.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCFixup.h
    llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCFixup.h b/llvm/include/llvm/MC/MCFixup.h
index 0a138aede40c0..c1fbe70284919 100644
--- a/llvm/include/llvm/MC/MCFixup.h
+++ b/llvm/include/llvm/MC/MCFixup.h
@@ -18,7 +18,8 @@ namespace llvm {
 class MCExpr;
 
 /// Extensible enumeration to represent the type of a fixup.
-enum MCFixupKind : uint16_t {
+using MCFixupKind = uint16_t;
+enum {
   // [0, FirstLiteralRelocationKind) encodes raw relocation types.
 
   // [FirstLiteralRelocationKind, FK_NONE) encodes raw relocation types coming
@@ -67,7 +68,7 @@ class MCFixup {
 
   /// The target dependent kind of fixup item this is. The kind is used to
   /// determine how the operand value should be encoded into the instruction.
-  uint16_t Kind = FK_NONE;
+  MCFixupKind Kind = FK_NONE;
 
   /// True if this is a PC-relative fixup. The relocatable expression is
   /// typically resolved When SymB is nullptr and SymA is a local symbol defined
@@ -81,7 +82,7 @@ class MCFixup {
   /// Consider bit fields if we need more flags.
 
 public:
-  static MCFixup create(uint32_t Offset, const MCExpr *Value, uint16_t Kind,
+  static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind,
                         bool PCRel = false) {
     MCFixup FI;
     FI.Value = Value;
@@ -90,13 +91,8 @@ class MCFixup {
     FI.PCRel = PCRel;
     return FI;
   }
-  static MCFixup create(uint32_t Offset, const MCExpr *Value,
-                        MCFixupKind Kind) {
-    return create(Offset, Value, unsigned(Kind));
-  }
-
-  MCFixupKind getKind() const { return MCFixupKind(Kind); }
 
+  MCFixupKind getKind() const { return Kind; }
   unsigned getTargetKind() const { return Kind; }
 
   uint32_t getOffset() const { return Offset; }

diff  --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp
index 2fc5b42e73d4b..3c171b59c035d 100644
--- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp
+++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp
@@ -135,7 +135,7 @@ static unsigned getSize(unsigned Kind) {
   switch (Kind) {
   default:
     return 3;
-  case MCFixupKind::FK_Data_4:
+  case FK_Data_4:
     return 4;
   case Xtensa::fixup_xtensa_branch_6:
     return 2;


        


More information about the llvm-commits mailing list