[llvm] Remove unneeded global inits (PR #129245)
JP Hafer via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 28 05:48:17 PST 2025
https://github.com/jph-13 created https://github.com/llvm/llvm-project/pull/129245
Theses consts in ASMTargetParser were causing unnecessary global initialization fuctions.
_GLOBAL__sub_I_ARMTargetParser.cpp
_GLOBAL__sub_I_Triple.cpp
Both functions init the same consts.
>From d13791bdc01b2f2a870a8196e6b5c6b5788157c6 Mon Sep 17 00:00:00 2001
From: Jason Hafer <jhafer at mathworks.com>
Date: Mon, 24 Feb 2025 12:57:04 -0500
Subject: [PATCH 1/2] Remove redundant assert from AsmWriter
---
llvm/lib/IR/AsmWriter.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 57e9cccdc0fb6..233b16f7f6856 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2109,7 +2109,6 @@ static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N,
};
auto GetConstant = [&](Metadata *Bound) -> int64_t {
- assert(IsConstant(Bound) && "Expected constant");
auto *BE = dyn_cast_or_null<DIExpression>(Bound);
return static_cast<int64_t>(BE->getElement(1));
};
>From 57deb17930749b934ebc0341aed02b9a043d481f Mon Sep 17 00:00:00 2001
From: Jason Hafer <jhafer at mathworks.com>
Date: Fri, 28 Feb 2025 08:43:12 -0500
Subject: [PATCH 2/2] Update Const to Avoid Un-needed Global Inits
---
llvm/include/llvm/TargetParser/ARMTargetParser.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.h b/llvm/include/llvm/TargetParser/ARMTargetParser.h
index 2b0ef76a6b51f..5dbcfd3d2d693 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.h
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.h
@@ -77,7 +77,7 @@ struct ExtName {
StringRef NegFeature;
};
-const ExtName ARCHExtNames[] = {
+constexpr ExtName ARCHExtNames[] = {
#define ARM_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
{NAME, ID, FEATURE, NEGFEATURE},
#include "ARMTargetParser.def"
@@ -85,7 +85,7 @@ const ExtName ARCHExtNames[] = {
// List of HWDiv names (use getHWDivSynonym) and which architectural
// features they correspond to (use getHWDivFeatures).
-const struct {
+constexpr struct {
StringRef Name;
uint64_t ID;
} HWDivNames[] = {
@@ -112,7 +112,7 @@ struct CpuNames {
uint64_t DefaultExtensions;
};
-const CpuNames CPUNames[] = {
+constexpr CpuNames CPUNames[] = {
#define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
{NAME, ARM::ArchKind::ID, IS_DEFAULT, DEFAULT_EXT},
#include "ARMTargetParser.def"
@@ -173,7 +173,7 @@ struct FPUName {
FPURestriction Restriction;
};
-static const FPUName FPUNames[] = {
+static constexpr FPUName FPUNames[] = {
#define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) \
{NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION},
#include "llvm/TargetParser/ARMTargetParser.def"
@@ -199,7 +199,7 @@ struct ArchNames {
StringRef getSubArch() const { return ArchFeature.substr(1); }
};
-static const ArchNames ARMArchNames[] = {
+static constexpr ArchNames ARMArchNames[] = {
#define ARM_ARCH(NAME, ID, CPU_ATTR, ARCH_FEATURE, ARCH_ATTR, ARCH_FPU, \
ARCH_BASE_EXT) \
{NAME, CPU_ATTR, ARCH_FEATURE, ARCH_FPU, \
More information about the llvm-commits
mailing list