[llvm] [llvm] Fix enum-enum bitwise and arithmetic conversions for C++26 (PR #228945)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 10 19:45:49 PDT 2026
https://github.com/rdong8 updated https://github.com/llvm/llvm-project/pull/228945
>From 6f6aff0c499fd2fae808a1d63e293eefd2aa6fe7 Mon Sep 17 00:00:00 2001
From: Richard Dong <rdong8 at protonmail.com>
Date: Sun, 4 Oct 2026 20:36:39 +0000
Subject: [PATCH 1/5] [llvm] Fix enum-enum bitwise and arithmetic conversions
for C++26
Fix operations involving distinct enum types across LLVM target descriptors,
MC, and CodeGen that are deprecated or rejected under C++26:
- Use llvm::to_underlying for fixup arithmetic and MachO section attributes.
- Use explicit comparison for InlineAsm dialect flags rather than enum arithmetic.
- Define operator& for PPC Predicate and BranchHintBit.
---
llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp | 3 ++-
llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 3 ++-
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 3 ++-
llvm/lib/MC/MCObjectFileInfo.cpp | 4 ++--
llvm/lib/MC/MCParser/DarwinAsmParser.cpp | 8 ++++----
llvm/lib/Target/AMDGPU/SIFrameLowering.cpp | 4 ++--
llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp | 2 +-
.../LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp | 2 +-
.../LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp | 2 +-
.../lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp | 2 +-
llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h | 10 ++++++++++
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 2 +-
.../SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp | 2 +-
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp | 2 +-
14 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
index 19eae930cc26b..01bd7c28595fe 100644
--- a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
@@ -69,7 +69,8 @@ class ExtraFlags {
Flags |= InlineAsm::Extra_MayUnwind;
if (CB.isConvergent())
Flags |= InlineAsm::Extra_IsConvergent;
- Flags |= IA->getDialect() * InlineAsm::Extra_AsmDialect;
+ if (IA->getDialect() == InlineAsm::AD_Intel)
+ Flags |= InlineAsm::Extra_AsmDialect;
}
void update(const TargetLowering::AsmOperandInfo &OpInfo) {
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index 4f39139070508..19f1f328d309b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1171,7 +1171,8 @@ bool FastISel::selectCall(const User *I) {
ExtraInfo |= InlineAsm::Extra_MayUnwind;
if (Call->isConvergent())
ExtraInfo |= InlineAsm::Extra_IsConvergent;
- ExtraInfo |= IA->getDialect() * InlineAsm::Extra_AsmDialect;
+ if (IA->getDialect() == InlineAsm::AD_Intel)
+ ExtraInfo |= InlineAsm::Extra_AsmDialect;
MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(TargetOpcode::INLINEASM));
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index dfbf9a401b53e..3f3a316ba418f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -10396,7 +10396,8 @@ class ExtraFlags {
Flags |= InlineAsm::Extra_MayUnwind;
if (Call.isConvergent())
Flags |= InlineAsm::Extra_IsConvergent;
- Flags |= IA->getDialect() * InlineAsm::Extra_AsmDialect;
+ if (IA->getDialect() == InlineAsm::AD_Intel)
+ Flags |= InlineAsm::Extra_AsmDialect;
}
void update(const TargetLowering::AsmOperandInfo &OpInfo) {
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 41e5adf304d35..86d2388147756 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -66,7 +66,7 @@ static bool useCompactUnwind(const Triple &T) {
void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
EHFrameSection = Ctx->getMachOSection(
"__TEXT", "__eh_frame",
- MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
+ llvm::to_underlying(MachO::S_COALESCED) | MachO::S_ATTR_NO_TOC |
MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
SectionKind::getReadOnly());
@@ -160,7 +160,7 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
TextCoalSection
= Ctx->getMachOSection("__TEXT", "__textcoal_nt",
- MachO::S_COALESCED |
+ llvm::to_underlying(MachO::S_COALESCED) |
MachO::S_ATTR_PURE_INSTRUCTIONS,
SectionKind::getText());
ConstTextCoalSection
diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
index ba6813c142266..25e6cab7d9fee 100644
--- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
@@ -269,7 +269,7 @@ class DarwinAsmParser : public MCAsmParserExtension {
bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) {
return parseSectionSwitch("__TEXT","__symbol_stub",
- MachO::S_SYMBOL_STUBS |
+ llvm::to_underlying(MachO::S_SYMBOL_STUBS) |
MachO::S_ATTR_PURE_INSTRUCTIONS,
// FIXME: Different on PPC and ARM.
0, 16);
@@ -277,7 +277,7 @@ class DarwinAsmParser : public MCAsmParserExtension {
bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) {
return parseSectionSwitch("__TEXT","__picsymbol_stub",
- MachO::S_SYMBOL_STUBS |
+ llvm::to_underlying(MachO::S_SYMBOL_STUBS) |
MachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26);
}
@@ -365,13 +365,13 @@ class DarwinAsmParser : public MCAsmParserExtension {
bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) {
return parseSectionSwitch("__OBJC", "__cls_refs",
MachO::S_ATTR_NO_DEAD_STRIP |
- MachO::S_LITERAL_POINTERS, 4);
+ llvm::to_underlying(MachO::S_LITERAL_POINTERS), 4);
}
bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) {
return parseSectionSwitch("__OBJC", "__message_refs",
MachO::S_ATTR_NO_DEAD_STRIP |
- MachO::S_LITERAL_POINTERS, 4);
+ llvm::to_underlying(MachO::S_LITERAL_POINTERS), 4);
}
bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) {
diff --git a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
index 364d8f07b6df2..eff041737b405 100644
--- a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
@@ -81,7 +81,7 @@ static MCCFIInstruction createScaledCFAInPrivateWave(const GCNSubtarget &ST,
<< uint8_t(dwarf::DW_OP_lit0 + WavefrontSizeLog2)
<< uint8_t(dwarf::DW_OP_shl)
<< uint8_t(dwarf::DW_OP_lit0 +
- dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave)
+ llvm::to_underlying(dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave))
<< uint8_t(dwarf::DW_OP_LLVM_user)
<< uint8_t(dwarf::DW_OP_LLVM_form_aspace_address);
@@ -780,7 +780,7 @@ void SIFrameLowering::emitEntryFunctionPrologue(MachineFunction &MF,
4, // length
static_cast<char>(dwarf::DW_OP_lit0),
static_cast<char>(dwarf::DW_OP_lit0 +
- dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave),
+ llvm::to_underlying(dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave)),
static_cast<char>(dwarf::DW_OP_LLVM_user),
static_cast<char>(dwarf::DW_OP_LLVM_form_aspace_address)};
static StringRef CFAEncodedInstUserOps =
diff --git a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
index 129f3071a3a88..088cebe1d53d5 100644
--- a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
@@ -628,7 +628,7 @@ struct OpRef {
assert(!R.isValue());
return OpRef(R.OpN & (Undef | Index | HiHalf));
}
- static OpRef undef(MVT Ty) { return OpRef(Undef | Ty.SimpleTy); }
+ static OpRef undef(MVT Ty) { return OpRef(Undef | llvm::to_underlying(Ty.SimpleTy)); }
// Direct value.
SDValue OpV = SDValue();
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index 4581da3c7b9c3..1895fa2eb9920 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -252,7 +252,7 @@ bool LoongArchAsmBackend::relaxAlign(MCFragment &F, unsigned &Size) {
Ctx);
}
MCFixup Fixup =
- MCFixup::create(0, Expr, FirstLiteralRelocationKind + ELF::R_LARCH_ALIGN);
+ MCFixup::create(0, Expr, FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_LARCH_ALIGN));
F.setVarFixups({Fixup});
F.setLinkerRelaxable();
return true;
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
index 8146a15eba295..3a77bd154ca2c 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
@@ -166,7 +166,7 @@ LoongArchMCCodeEmitter::getExprOpValue(const MCInst &MI, const MCOperand &MO,
// `la.abs`.
Fixups.push_back(
MCFixup::create(0, MCConstantExpr::create(0, Ctx),
- FirstLiteralRelocationKind + ELF::R_LARCH_MARK_LA));
+ FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_LARCH_MARK_LA)));
[[fallthrough]];
case ELF::R_LARCH_ABS_HI20:
FixupKind = LoongArch::fixup_loongarch_abs_hi20;
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
index 7b2d2be503d72..0a64998a213c7 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
@@ -157,7 +157,7 @@ void PPCELFStreamer::emitGOTToPCRelReloc(const MCInst &Inst) {
MCFragment *F = LabelSym->getFragment();
F->addFixup(
MCFixup::create(LabelSym->getOffset() - 8, SubExpr2,
- FirstLiteralRelocationKind + ELF::R_PPC64_PCREL_OPT));
+ FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_PPC64_PCREL_OPT)));
emitLabel(CurrentLocation, Inst.getLoc());
}
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
index d686a8ea2a228..cd73179274110 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
@@ -13,6 +13,8 @@
#ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H
#define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H
+#include "llvm/ADT/STLForwardCompat.h"
+
// GCC #defines PPC on Linux but we use it as our namespace name
#undef PPC
@@ -66,6 +68,14 @@ namespace PPC {
BR_HINT_MASK = 0X3
};
+ inline unsigned operator&(Predicate P, BranchHintBit B) {
+ return llvm::to_underlying(P) & llvm::to_underlying(B);
+ }
+
+ inline unsigned operator&(BranchHintBit B, Predicate P) {
+ return P & B;
+ }
+
/// Invert the specified predicate. != -> ==, < -> >=.
Predicate InvertPredicate(Predicate Opcode);
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 315d129aeb5fb..9c9fb67968a7d 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -350,7 +350,7 @@ bool RISCVAsmBackend::relaxAlign(MCFragment &F, unsigned &Size) {
Size = F.getAlignment().value() - MinNopLen;
auto *Expr = MCConstantExpr::create(Size, getContext());
MCFixup Fixup =
- MCFixup::create(0, Expr, FirstLiteralRelocationKind + ELF::R_RISCV_ALIGN);
+ MCFixup::create(0, Expr, FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_RISCV_ALIGN));
F.setVarFixups({Fixup});
F.setLinkerRelaxable();
return true;
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp
index 383c96e8cca73..bd0bcabb0e239 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp
@@ -172,7 +172,7 @@ uint64_t SystemZMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNum,
unsigned MIBitSize = MCII.get(MI.getOpcode()).getSize() * 8;
uint32_t RawBitOffset = getOperandBitOffset(MI, OpNum, STI);
unsigned OpBitSize =
- SystemZ::MCFixupKindInfos[Kind - FirstTargetFixupKind].TargetSize;
+ SystemZ::MCFixupKindInfos[llvm::to_underlying(Kind) - FirstTargetFixupKind].TargetSize;
uint32_t BitOffset = MIBitSize - RawBitOffset - OpBitSize;
addFixup(Fixups, BitOffset >> 3, MO.getExpr(), Kind);
return 0;
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
index ab535c81dbf42..8f2374426b806 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
@@ -542,7 +542,7 @@ void X86MCCodeEmitter::emitImmediate(const MCOperand &DispOp, SMLoc Loc,
assert(ImmOffset == 0);
if (Size == 8) {
- FixupKind = FirstLiteralRelocationKind + ELF::R_X86_64_GOTPC64;
+ FixupKind = FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_X86_64_GOTPC64);
} else {
assert(Size == 4);
FixupKind = X86::reloc_global_offset_table;
>From 33bf247cdc7c091c2bd79a5f906ef1cb6405f0de Mon Sep 17 00:00:00 2001
From: Richard Dong <rdong8 at protonmail.com>
Date: Sun, 4 Oct 2026 22:34:20 +0000
Subject: [PATCH 2/5] format code
---
llvm/lib/MC/MCObjectFileInfo.cpp | 6 ++---
llvm/lib/MC/MCParser/DarwinAsmParser.cpp | 25 +++++++++++--------
llvm/lib/Target/AMDGPU/SIFrameLowering.cpp | 10 +++++---
.../Target/Hexagon/HexagonISelDAGToDAGHVX.cpp | 4 ++-
.../MCTargetDesc/LoongArchAsmBackend.cpp | 5 ++--
.../MCTargetDesc/LoongArchMCCodeEmitter.cpp | 3 ++-
.../PowerPC/MCTargetDesc/PPCELFStreamer.cpp | 6 ++---
.../PowerPC/MCTargetDesc/PPCPredicates.h | 4 +--
.../RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 5 ++--
.../MCTargetDesc/SystemZMCCodeEmitter.cpp | 5 ++--
.../X86/MCTargetDesc/X86MCCodeEmitter.cpp | 3 ++-
11 files changed, 44 insertions(+), 32 deletions(-)
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 86d2388147756..546ac7caa26a1 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -158,10 +158,10 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
SectionKind::getReadOnlyWithRel());
if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
- TextCoalSection
- = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
+ TextCoalSection =
+ Ctx->getMachOSection("__TEXT", "__textcoal_nt",
llvm::to_underlying(MachO::S_COALESCED) |
- MachO::S_ATTR_PURE_INSTRUCTIONS,
+ MachO::S_ATTR_PURE_INSTRUCTIONS,
SectionKind::getText());
ConstTextCoalSection
= Ctx->getMachOSection("__TEXT", "__const_coal",
diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
index 25e6cab7d9fee..dd0e4dd68cf64 100644
--- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
@@ -268,17 +268,18 @@ class DarwinAsmParser : public MCAsmParserExtension {
}
bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) {
- return parseSectionSwitch("__TEXT","__symbol_stub",
+ return parseSectionSwitch("__TEXT", "__symbol_stub",
llvm::to_underlying(MachO::S_SYMBOL_STUBS) |
- MachO::S_ATTR_PURE_INSTRUCTIONS,
+ MachO::S_ATTR_PURE_INSTRUCTIONS,
// FIXME: Different on PPC and ARM.
0, 16);
}
bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) {
- return parseSectionSwitch("__TEXT","__picsymbol_stub",
+ return parseSectionSwitch("__TEXT", "__picsymbol_stub",
llvm::to_underlying(MachO::S_SYMBOL_STUBS) |
- MachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26);
+ MachO::S_ATTR_PURE_INSTRUCTIONS,
+ 0, 26);
}
bool parseSectionDirectiveData(StringRef, SMLoc) {
@@ -363,15 +364,19 @@ class DarwinAsmParser : public MCAsmParserExtension {
}
bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) {
- return parseSectionSwitch("__OBJC", "__cls_refs",
- MachO::S_ATTR_NO_DEAD_STRIP |
- llvm::to_underlying(MachO::S_LITERAL_POINTERS), 4);
+ return parseSectionSwitch(
+ "__OBJC", "__cls_refs",
+ MachO::S_ATTR_NO_DEAD_STRIP |
+ llvm::to_underlying(MachO::S_LITERAL_POINTERS),
+ 4);
}
bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) {
- return parseSectionSwitch("__OBJC", "__message_refs",
- MachO::S_ATTR_NO_DEAD_STRIP |
- llvm::to_underlying(MachO::S_LITERAL_POINTERS), 4);
+ return parseSectionSwitch(
+ "__OBJC", "__message_refs",
+ MachO::S_ATTR_NO_DEAD_STRIP |
+ llvm::to_underlying(MachO::S_LITERAL_POINTERS),
+ 4);
}
bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) {
diff --git a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
index eff041737b405..2f1581c9887d9 100644
--- a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
@@ -80,8 +80,9 @@ static MCCFIInstruction createScaledCFAInPrivateWave(const GCNSubtarget &ST,
OSBlock << uint8_t(dwarf::DW_OP_deref_size) << uint8_t(SGPRByteSize)
<< uint8_t(dwarf::DW_OP_lit0 + WavefrontSizeLog2)
<< uint8_t(dwarf::DW_OP_shl)
- << uint8_t(dwarf::DW_OP_lit0 +
- llvm::to_underlying(dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave))
+ << uint8_t(
+ dwarf::DW_OP_lit0 +
+ llvm::to_underlying(dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave))
<< uint8_t(dwarf::DW_OP_LLVM_user)
<< uint8_t(dwarf::DW_OP_LLVM_form_aspace_address);
@@ -779,8 +780,9 @@ void SIFrameLowering::emitEntryFunctionPrologue(MachineFunction &MF,
dwarf::DW_CFA_def_cfa_expression,
4, // length
static_cast<char>(dwarf::DW_OP_lit0),
- static_cast<char>(dwarf::DW_OP_lit0 +
- llvm::to_underlying(dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave)),
+ static_cast<char>(
+ dwarf::DW_OP_lit0 +
+ llvm::to_underlying(dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave)),
static_cast<char>(dwarf::DW_OP_LLVM_user),
static_cast<char>(dwarf::DW_OP_LLVM_form_aspace_address)};
static StringRef CFAEncodedInstUserOps =
diff --git a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
index 088cebe1d53d5..4cc6abb80034e 100644
--- a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
@@ -628,7 +628,9 @@ struct OpRef {
assert(!R.isValue());
return OpRef(R.OpN & (Undef | Index | HiHalf));
}
- static OpRef undef(MVT Ty) { return OpRef(Undef | llvm::to_underlying(Ty.SimpleTy)); }
+ static OpRef undef(MVT Ty) {
+ return OpRef(Undef | llvm::to_underlying(Ty.SimpleTy));
+ }
// Direct value.
SDValue OpV = SDValue();
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index 1895fa2eb9920..633d3b32e3d41 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -251,8 +251,9 @@ bool LoongArchAsmBackend::relaxAlign(MCFragment &F, unsigned &Size) {
Ctx),
Ctx);
}
- MCFixup Fixup =
- MCFixup::create(0, Expr, FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_LARCH_ALIGN));
+ MCFixup Fixup = MCFixup::create(0, Expr,
+ FirstLiteralRelocationKind +
+ llvm::to_underlying(ELF::R_LARCH_ALIGN));
F.setVarFixups({Fixup});
F.setLinkerRelaxable();
return true;
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
index 3a77bd154ca2c..3f66cd062b70f 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
@@ -166,7 +166,8 @@ LoongArchMCCodeEmitter::getExprOpValue(const MCInst &MI, const MCOperand &MO,
// `la.abs`.
Fixups.push_back(
MCFixup::create(0, MCConstantExpr::create(0, Ctx),
- FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_LARCH_MARK_LA)));
+ FirstLiteralRelocationKind +
+ llvm::to_underlying(ELF::R_LARCH_MARK_LA)));
[[fallthrough]];
case ELF::R_LARCH_ABS_HI20:
FixupKind = LoongArch::fixup_loongarch_abs_hi20;
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
index 0a64998a213c7..5a77b57cfa559 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
@@ -155,9 +155,9 @@ void PPCELFStreamer::emitGOTToPCRelReloc(const MCInst &Inst) {
MCBinaryExpr::createSub(CurrentLocationExpr, SubExpr, getContext());
MCFragment *F = LabelSym->getFragment();
- F->addFixup(
- MCFixup::create(LabelSym->getOffset() - 8, SubExpr2,
- FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_PPC64_PCREL_OPT)));
+ F->addFixup(MCFixup::create(LabelSym->getOffset() - 8, SubExpr2,
+ FirstLiteralRelocationKind +
+ llvm::to_underlying(ELF::R_PPC64_PCREL_OPT)));
emitLabel(CurrentLocation, Inst.getLoc());
}
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
index cd73179274110..850eee52f5527 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
@@ -72,9 +72,7 @@ namespace PPC {
return llvm::to_underlying(P) & llvm::to_underlying(B);
}
- inline unsigned operator&(BranchHintBit B, Predicate P) {
- return P & B;
- }
+ inline unsigned operator&(BranchHintBit B, Predicate P) { return P & B; }
/// Invert the specified predicate. != -> ==, < -> >=.
Predicate InvertPredicate(Predicate Opcode);
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 9c9fb67968a7d..820f5886cf2ac 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -349,8 +349,9 @@ bool RISCVAsmBackend::relaxAlign(MCFragment &F, unsigned &Size) {
Size = F.getAlignment().value() - MinNopLen;
auto *Expr = MCConstantExpr::create(Size, getContext());
- MCFixup Fixup =
- MCFixup::create(0, Expr, FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_RISCV_ALIGN));
+ MCFixup Fixup = MCFixup::create(0, Expr,
+ FirstLiteralRelocationKind +
+ llvm::to_underlying(ELF::R_RISCV_ALIGN));
F.setVarFixups({Fixup});
F.setLinkerRelaxable();
return true;
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp
index bd0bcabb0e239..6b87167679ea9 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp
@@ -171,8 +171,9 @@ uint64_t SystemZMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNum,
if (MO.isExpr()) {
unsigned MIBitSize = MCII.get(MI.getOpcode()).getSize() * 8;
uint32_t RawBitOffset = getOperandBitOffset(MI, OpNum, STI);
- unsigned OpBitSize =
- SystemZ::MCFixupKindInfos[llvm::to_underlying(Kind) - FirstTargetFixupKind].TargetSize;
+ unsigned OpBitSize = SystemZ::MCFixupKindInfos[llvm::to_underlying(Kind) -
+ FirstTargetFixupKind]
+ .TargetSize;
uint32_t BitOffset = MIBitSize - RawBitOffset - OpBitSize;
addFixup(Fixups, BitOffset >> 3, MO.getExpr(), Kind);
return 0;
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
index 8f2374426b806..dcf052fa3a199 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
@@ -542,7 +542,8 @@ void X86MCCodeEmitter::emitImmediate(const MCOperand &DispOp, SMLoc Loc,
assert(ImmOffset == 0);
if (Size == 8) {
- FixupKind = FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_X86_64_GOTPC64);
+ FixupKind = FirstLiteralRelocationKind +
+ llvm::to_underlying(ELF::R_X86_64_GOTPC64);
} else {
assert(Size == 4);
FixupKind = X86::reloc_global_offset_table;
>From 60c41693cf4b213bdba4ee364b0a51d672cdd506 Mon Sep 17 00:00:00 2001
From: Richard Dong <rdong8 at protonmail.com>
Date: Mon, 5 Oct 2026 05:47:24 +0000
Subject: [PATCH 3/5] [Hexagon][PowerPC] Use constexpr for bitmasks instead of
enum-enum operations
---
.../Target/Hexagon/HexagonISelDAGToDAGHVX.cpp | 20 ++++++++-----------
.../PowerPC/MCTargetDesc/PPCPredicates.h | 9 +--------
2 files changed, 9 insertions(+), 20 deletions(-)
diff --git a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
index 4cc6abb80034e..bf50136521ec1 100644
--- a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
@@ -628,9 +628,7 @@ struct OpRef {
assert(!R.isValue());
return OpRef(R.OpN & (Undef | Index | HiHalf));
}
- static OpRef undef(MVT Ty) {
- return OpRef(Undef | llvm::to_underlying(Ty.SimpleTy));
- }
+ static OpRef undef(MVT Ty) { return OpRef(Undef | Ty.SimpleTy); }
// Direct value.
SDValue OpV = SDValue();
@@ -642,15 +640,13 @@ struct OpRef {
// If bit 29 is set, it's the low half of the operand.
unsigned OpN = 0;
- enum : unsigned {
- Invalid = 0x10000000,
- LoHalf = 0x20000000,
- HiHalf = 0x40000000,
- Whole = LoHalf | HiHalf,
- Undef = 0x80000000,
- Index = 0x0FFFFFFF, // Mask of the index value.
- IndexBits = 28,
- };
+ static constexpr unsigned Invalid = 0x10000000;
+ static constexpr unsigned LoHalf = 0x20000000;
+ static constexpr unsigned HiHalf = 0x40000000;
+ static constexpr unsigned Whole = LoHalf | HiHalf;
+ static constexpr unsigned Undef = 0x80000000;
+ static constexpr unsigned Index = 0x0FFFFFFF; // Mask of the index value.
+ static constexpr unsigned IndexBits = 28;
LLVM_DUMP_METHOD
void print(raw_ostream &OS, const SelectionDAG &G) const;
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
index 850eee52f5527..df130f6547c45 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h
@@ -13,8 +13,6 @@
#ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H
#define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H
-#include "llvm/ADT/STLForwardCompat.h"
-
// GCC #defines PPC on Linux but we use it as our namespace name
#undef PPC
@@ -65,14 +63,9 @@ namespace PPC {
BR_NO_HINT = 0x0,
BR_NONTAKEN_HINT = 0x2,
BR_TAKEN_HINT = 0x3,
- BR_HINT_MASK = 0X3
};
- inline unsigned operator&(Predicate P, BranchHintBit B) {
- return llvm::to_underlying(P) & llvm::to_underlying(B);
- }
-
- inline unsigned operator&(BranchHintBit B, Predicate P) { return P & B; }
+ constexpr unsigned BR_HINT_MASK = 0x3;
/// Invert the specified predicate. != -> ==, < -> >=.
Predicate InvertPredicate(Predicate Opcode);
>From 08bbe7a36d304c95ad98df446730b7a739c71ae5 Mon Sep 17 00:00:00 2001
From: Richard Dong <rdong8 at protonmail.com>
Date: Sat, 10 Oct 2026 05:00:10 +0000
Subject: [PATCH 4/5] [BinaryFormat][MachO] Use constexpr for rebase, bind, and
export constants
---
llvm/include/llvm/BinaryFormat/MachO.h | 53 +++++++++++---------------
1 file changed, 22 insertions(+), 31 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/MachO.h b/llvm/include/llvm/BinaryFormat/MachO.h
index ecf9f36fdffcf..d0231793f41c6 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -227,13 +227,12 @@ enum DataRegionType {
DICE_KIND_ABS_JUMP_TABLE32 = 5u
};
-enum RebaseType {
- REBASE_TYPE_POINTER = 1u,
- REBASE_TYPE_TEXT_ABSOLUTE32 = 2u,
- REBASE_TYPE_TEXT_PCREL32 = 3u
-};
+constexpr uint8_t REBASE_TYPE_POINTER = 1u;
+constexpr uint8_t REBASE_TYPE_TEXT_ABSOLUTE32 = 2u;
+constexpr uint8_t REBASE_TYPE_TEXT_PCREL32 = 3u;
-enum { REBASE_OPCODE_MASK = 0xF0u, REBASE_IMMEDIATE_MASK = 0x0Fu };
+constexpr uint8_t REBASE_OPCODE_MASK = 0xF0u;
+constexpr uint8_t REBASE_IMMEDIATE_MASK = 0x0Fu;
enum RebaseOpcode {
REBASE_OPCODE_DONE = 0x00u,
@@ -247,11 +246,9 @@ enum RebaseOpcode {
REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80u
};
-enum BindType {
- BIND_TYPE_POINTER = 1u,
- BIND_TYPE_TEXT_ABSOLUTE32 = 2u,
- BIND_TYPE_TEXT_PCREL32 = 3u
-};
+constexpr uint8_t BIND_TYPE_POINTER = 1u;
+constexpr uint8_t BIND_TYPE_TEXT_ABSOLUTE32 = 2u;
+constexpr uint8_t BIND_TYPE_TEXT_PCREL32 = 3u;
enum BindSpecialDylib {
BIND_SPECIAL_DYLIB_SELF = 0,
@@ -260,13 +257,11 @@ enum BindSpecialDylib {
BIND_SPECIAL_DYLIB_WEAK_LOOKUP = -3
};
-enum {
- BIND_SYMBOL_FLAGS_WEAK_IMPORT = 0x1u,
- BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION = 0x8u,
+constexpr uint8_t BIND_SYMBOL_FLAGS_WEAK_IMPORT = 0x1u;
+constexpr uint8_t BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION = 0x8u;
- BIND_OPCODE_MASK = 0xF0u,
- BIND_IMMEDIATE_MASK = 0x0Fu
-};
+constexpr uint8_t BIND_OPCODE_MASK = 0xF0u;
+constexpr uint8_t BIND_IMMEDIATE_MASK = 0x0Fu;
enum BindOpcode {
BIND_OPCODE_DONE = 0x00u,
@@ -284,12 +279,10 @@ enum BindOpcode {
BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0u
};
-enum {
- EXPORT_SYMBOL_FLAGS_KIND_MASK = 0x03u,
- EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION = 0x04u,
- EXPORT_SYMBOL_FLAGS_REEXPORT = 0x08u,
- EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER = 0x10u
-};
+constexpr uint8_t EXPORT_SYMBOL_FLAGS_KIND_MASK = 0x03u;
+constexpr uint8_t EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION = 0x04u;
+constexpr uint8_t EXPORT_SYMBOL_FLAGS_REEXPORT = 0x08u;
+constexpr uint8_t EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER = 0x10u;
enum ExportSymbolKind {
EXPORT_SYMBOL_FLAGS_KIND_REGULAR = 0x00u,
@@ -297,14 +290,12 @@ enum ExportSymbolKind {
EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE = 0x02u
};
-enum {
- // Constant masks for the "n_type" field in llvm::MachO::nlist and
- // llvm::MachO::nlist_64
- N_STAB = 0xe0,
- N_PEXT = 0x10,
- N_TYPE = 0x0e,
- N_EXT = 0x01
-};
+// Constant masks for the "n_type" field in llvm::MachO::nlist and
+// llvm::MachO::nlist_64
+constexpr uint8_t N_STAB = 0xe0;
+constexpr uint8_t N_PEXT = 0x10;
+constexpr uint8_t N_TYPE = 0x0e;
+constexpr uint8_t N_EXT = 0x01;
enum NListType : uint8_t {
// Constants for the "n_type & N_TYPE" llvm::MachO::nlist and
>From 7e043c17bb4791f91021d87e7960fe53513d14e1 Mon Sep 17 00:00:00 2001
From: Richard Dong <rdong8 at protonmail.com>
Date: Sun, 11 Oct 2026 01:38:41 +0000
Subject: [PATCH 5/5] [TargetParser][CSKY] Use constexpr uint64_t for
MultiArchExtKind bitmasks
---
.../llvm/TargetParser/CSKYTargetParser.h | 26 ++++++++++---------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/TargetParser/CSKYTargetParser.h b/llvm/include/llvm/TargetParser/CSKYTargetParser.h
index 8eab03ca01490..625fbe17b4555 100644
--- a/llvm/include/llvm/TargetParser/CSKYTargetParser.h
+++ b/llvm/include/llvm/TargetParser/CSKYTargetParser.h
@@ -81,18 +81,20 @@ enum ArchExtKind : uint64_t {
};
// Arch extension modifiers for CPUs.
-enum MultiArchExtKind : uint64_t {
- MAEK_E1 = CSKY::AEK_E1 | CSKY::AEK_ELRW,
- MAEK_E2 = CSKY::AEK_E2 | CSKY::MAEK_E1,
- MAEK_2E3 = CSKY::AEK_2E3 | CSKY::MAEK_E2,
- MAEK_MP = CSKY::AEK_MP | CSKY::MAEK_2E3,
- MAEK_3E3R1 = CSKY::AEK_3E3R1,
- MAEK_3E3R2 = CSKY::AEK_3E3R1 | CSKY::AEK_3E3R2 | CSKY::AEK_DOLOOP,
- MAEK_3E7 = CSKY::AEK_3E7 | CSKY::MAEK_2E3,
- MAEK_MP1E2 = CSKY::AEK_MP1E2 | CSKY::MAEK_3E7,
- MAEK_7E10 = CSKY::AEK_7E10 | CSKY::MAEK_3E7,
- MAEK_10E60 = CSKY::AEK_10E60 | CSKY::MAEK_7E10,
-};
+namespace MultiArchExtKind {
+inline constexpr uint64_t MAEK_E1 = CSKY::AEK_E1 | CSKY::AEK_ELRW;
+inline constexpr uint64_t MAEK_E2 = CSKY::AEK_E2 | MAEK_E1;
+inline constexpr uint64_t MAEK_2E3 = CSKY::AEK_2E3 | MAEK_E2;
+inline constexpr uint64_t MAEK_MP = CSKY::AEK_MP | MAEK_2E3;
+inline constexpr uint64_t MAEK_3E3R1 = CSKY::AEK_3E3R1;
+inline constexpr uint64_t MAEK_3E3R2 =
+ CSKY::AEK_3E3R1 | CSKY::AEK_3E3R2 | CSKY::AEK_DOLOOP;
+inline constexpr uint64_t MAEK_3E7 = CSKY::AEK_3E7 | MAEK_2E3;
+inline constexpr uint64_t MAEK_MP1E2 = CSKY::AEK_MP1E2 | MAEK_3E7;
+inline constexpr uint64_t MAEK_7E10 = CSKY::AEK_7E10 | MAEK_3E7;
+inline constexpr uint64_t MAEK_10E60 = CSKY::AEK_10E60 | MAEK_7E10;
+} // namespace MultiArchExtKind
+using namespace MultiArchExtKind;
// FPU names.
enum CSKYFPUKind {
#define CSKY_FPU(NAME, KIND, VERSION) KIND,
More information about the llvm-commits
mailing list