Skip to content

Commit 57a3d08

Browse files
committed
Make static variables const if possible. Makes them go into a read-only section.
Or fold them into a initializer list which has the same effect. NFC. llvm-svn: 231598
1 parent 28b45ce commit 57a3d08

File tree

7 files changed

+35
-50
lines changed

7 files changed

+35
-50
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TargetLibraryInfoImpl {
4040

4141
unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
4242
llvm::DenseMap<unsigned, std::string> CustomNames;
43-
static const char* StandardNames[LibFunc::NumLibFuncs];
43+
static const char *const StandardNames[LibFunc::NumLibFuncs];
4444

4545
enum AvailabilityState {
4646
StandardName = 3, // (memset to all ones)

llvm/lib/Analysis/Lint.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ using namespace llvm;
5959

6060
namespace {
6161
namespace MemRef {
62-
static unsigned Read = 1;
63-
static unsigned Write = 2;
64-
static unsigned Callee = 4;
65-
static unsigned Branchee = 8;
62+
static const unsigned Read = 1;
63+
static const unsigned Write = 2;
64+
static const unsigned Callee = 4;
65+
static const unsigned Branchee = 8;
6666
}
6767

6868
class Lint : public FunctionPass, public InstVisitor<Lint> {

llvm/lib/Analysis/TargetLibraryInfo.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
#include "llvm/ADT/Triple.h"
1616
using namespace llvm;
1717

18-
const char* TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
19-
{
18+
const char *const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
2019
#define TLI_DEFINE_STRING
2120
#include "llvm/Analysis/TargetLibraryInfo.def"
22-
};
21+
};
2322

2423
static bool hasSinCosPiStret(const Triple &T) {
2524
// Only Darwin variants have _stret versions of combined trig functions.
@@ -43,7 +42,7 @@ static bool hasSinCosPiStret(const Triple &T) {
4342
/// specified target triple. This should be carefully written so that a missing
4443
/// target triple gets a sane set of defaults.
4544
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
46-
const char **StandardNames) {
45+
const char *const *StandardNames) {
4746
#ifndef NDEBUG
4847
// Verify that the StandardNames array is in alphabetical order.
4948
for (unsigned F = 1; F < LibFunc::NumLibFuncs; ++F) {
@@ -401,14 +400,14 @@ static StringRef sanitizeFunctionName(StringRef funcName) {
401400

402401
bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
403402
LibFunc::Func &F) const {
404-
const char **Start = &StandardNames[0];
405-
const char **End = &StandardNames[LibFunc::NumLibFuncs];
403+
const char *const *Start = &StandardNames[0];
404+
const char *const *End = &StandardNames[LibFunc::NumLibFuncs];
406405

407406
funcName = sanitizeFunctionName(funcName);
408407
if (funcName.empty())
409408
return false;
410409

411-
const char **I = std::lower_bound(
410+
const char *const *I = std::lower_bound(
412411
Start, End, funcName, [](const char *LHS, StringRef RHS) {
413412
return std::strncmp(LHS, RHS.data(), RHS.size()) < 0;
414413
});

llvm/lib/CodeGen/InterferenceCache.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ using namespace llvm;
2121
#define DEBUG_TYPE "regalloc"
2222

2323
// Static member used for null interference cursors.
24-
InterferenceCache::BlockInterference InterferenceCache::Cursor::NoInterference;
24+
const InterferenceCache::BlockInterference
25+
InterferenceCache::Cursor::NoInterference;
2526

2627
// Initializes PhysRegEntries (instead of a SmallVector, PhysRegEntries is a
2728
// buffer of size NumPhysRegs to speed up alloc/clear for targets with large

llvm/lib/CodeGen/InterferenceCache.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class InterferenceCache {
170170
/// Cursor - The primary query interface for the block interference cache.
171171
class Cursor {
172172
Entry *CacheEntry;
173-
BlockInterference *Current;
174-
static BlockInterference NoInterference;
173+
const BlockInterference *Current;
174+
static const BlockInterference NoInterference;
175175

176176
void setEntry(Entry *E) {
177177
Current = nullptr;

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,7 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
370370
setOperationAction(ISD::FLOG10, MVT::v8f16, Expand);
371371

372372
// AArch64 has implementations of a lot of rounding-like FP operations.
373-
static MVT RoundingTypes[] = { MVT::f32, MVT::f64};
374-
for (unsigned I = 0; I < array_lengthof(RoundingTypes); ++I) {
375-
MVT Ty = RoundingTypes[I];
373+
for (MVT Ty : {MVT::f32, MVT::f64}) {
376374
setOperationAction(ISD::FFLOOR, Ty, Legal);
377375
setOperationAction(ISD::FNEARBYINT, Ty, Legal);
378376
setOperationAction(ISD::FCEIL, Ty, Legal);
@@ -569,9 +567,7 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
569567
}
570568

571569
// AArch64 has implementations of a lot of rounding-like FP operations.
572-
static MVT RoundingVecTypes[] = {MVT::v2f32, MVT::v4f32, MVT::v2f64 };
573-
for (unsigned I = 0; I < array_lengthof(RoundingVecTypes); ++I) {
574-
MVT Ty = RoundingVecTypes[I];
570+
for (MVT Ty : {MVT::v2f32, MVT::v4f32, MVT::v2f64}) {
575571
setOperationAction(ISD::FFLOOR, Ty, Legal);
576572
setOperationAction(ISD::FNEARBYINT, Ty, Legal);
577573
setOperationAction(ISD::FCEIL, Ty, Legal);

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

+18-29
Original file line numberDiff line numberDiff line change
@@ -752,58 +752,47 @@ class AArch64Operand : public MCParsedAsmOperand {
752752
}
753753

754754
bool isMovZSymbolG3() const {
755-
static AArch64MCExpr::VariantKind Variants[] = { AArch64MCExpr::VK_ABS_G3 };
756-
return isMovWSymbol(Variants);
755+
return isMovWSymbol(AArch64MCExpr::VK_ABS_G3);
757756
}
758757

759758
bool isMovZSymbolG2() const {
760-
static AArch64MCExpr::VariantKind Variants[] = {
761-
AArch64MCExpr::VK_ABS_G2, AArch64MCExpr::VK_ABS_G2_S,
762-
AArch64MCExpr::VK_TPREL_G2, AArch64MCExpr::VK_DTPREL_G2};
763-
return isMovWSymbol(Variants);
759+
return isMovWSymbol({AArch64MCExpr::VK_ABS_G2, AArch64MCExpr::VK_ABS_G2_S,
760+
AArch64MCExpr::VK_TPREL_G2,
761+
AArch64MCExpr::VK_DTPREL_G2});
764762
}
765763

766764
bool isMovZSymbolG1() const {
767-
static AArch64MCExpr::VariantKind Variants[] = {
768-
AArch64MCExpr::VK_ABS_G1, AArch64MCExpr::VK_ABS_G1_S,
765+
return isMovWSymbol({
766+
AArch64MCExpr::VK_ABS_G1, AArch64MCExpr::VK_ABS_G1_S,
769767
AArch64MCExpr::VK_GOTTPREL_G1, AArch64MCExpr::VK_TPREL_G1,
770768
AArch64MCExpr::VK_DTPREL_G1,
771-
};
772-
return isMovWSymbol(Variants);
769+
});
773770
}
774771

775772
bool isMovZSymbolG0() const {
776-
static AArch64MCExpr::VariantKind Variants[] = {
777-
AArch64MCExpr::VK_ABS_G0, AArch64MCExpr::VK_ABS_G0_S,
778-
AArch64MCExpr::VK_TPREL_G0, AArch64MCExpr::VK_DTPREL_G0};
779-
return isMovWSymbol(Variants);
773+
return isMovWSymbol({AArch64MCExpr::VK_ABS_G0, AArch64MCExpr::VK_ABS_G0_S,
774+
AArch64MCExpr::VK_TPREL_G0,
775+
AArch64MCExpr::VK_DTPREL_G0});
780776
}
781777

782778
bool isMovKSymbolG3() const {
783-
static AArch64MCExpr::VariantKind Variants[] = { AArch64MCExpr::VK_ABS_G3 };
784-
return isMovWSymbol(Variants);
779+
return isMovWSymbol(AArch64MCExpr::VK_ABS_G3);
785780
}
786781

787782
bool isMovKSymbolG2() const {
788-
static AArch64MCExpr::VariantKind Variants[] = {
789-
AArch64MCExpr::VK_ABS_G2_NC};
790-
return isMovWSymbol(Variants);
783+
return isMovWSymbol(AArch64MCExpr::VK_ABS_G2_NC);
791784
}
792785

793786
bool isMovKSymbolG1() const {
794-
static AArch64MCExpr::VariantKind Variants[] = {
795-
AArch64MCExpr::VK_ABS_G1_NC, AArch64MCExpr::VK_TPREL_G1_NC,
796-
AArch64MCExpr::VK_DTPREL_G1_NC
797-
};
798-
return isMovWSymbol(Variants);
787+
return isMovWSymbol({AArch64MCExpr::VK_ABS_G1_NC,
788+
AArch64MCExpr::VK_TPREL_G1_NC,
789+
AArch64MCExpr::VK_DTPREL_G1_NC});
799790
}
800791

801792
bool isMovKSymbolG0() const {
802-
static AArch64MCExpr::VariantKind Variants[] = {
803-
AArch64MCExpr::VK_ABS_G0_NC, AArch64MCExpr::VK_GOTTPREL_G0_NC,
804-
AArch64MCExpr::VK_TPREL_G0_NC, AArch64MCExpr::VK_DTPREL_G0_NC
805-
};
806-
return isMovWSymbol(Variants);
793+
return isMovWSymbol(
794+
{AArch64MCExpr::VK_ABS_G0_NC, AArch64MCExpr::VK_GOTTPREL_G0_NC,
795+
AArch64MCExpr::VK_TPREL_G0_NC, AArch64MCExpr::VK_DTPREL_G0_NC});
807796
}
808797

809798
template<int RegWidth, int Shift>

0 commit comments

Comments
 (0)