[llvm] [opt] Use static arrays instead of std::vector to store legacy pass names. NFC (PR #83634)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 15:42:45 PST 2024


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/83634

A std::vector causes a heap allocation and a memcpy of static initialization data from the rodata section.

Use a static array instead so we can use the static data directly.

>From 1251c7fa9f3d0beb60ea0a619591746530965aac Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Fri, 1 Mar 2024 15:37:37 -0800
Subject: [PATCH] [opt] Use static arrays instead of std::vector to store
 legacy pass names.

A std::vector causes a heap allocation and a memcpy of static
initialization data from the rodata section.

Use a static array instead so we can use the static data directly.
---
 llvm/tools/opt/optdriver.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp
index 7d05cb412b3d5a..948148bb80498c 100644
--- a/llvm/tools/opt/optdriver.cpp
+++ b/llvm/tools/opt/optdriver.cpp
@@ -317,7 +317,7 @@ struct TimeTracerRAII {
 // TODO: use a codegen version of PassRegistry.def/PassBuilder::is*Pass() once
 // it exists.
 static bool shouldPinPassToLegacyPM(StringRef Pass) {
-  std::vector<StringRef> PassNameExactToIgnore = {
+  static constexpr StringLiteral PassNameExactToIgnore[] = {
       "nvvm-reflect",
       "nvvm-intr-range",
       "amdgpu-simplifylib",
@@ -334,13 +334,13 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) {
   if (llvm::is_contained(PassNameExactToIgnore, Pass))
     return false;
 
-  std::vector<StringRef> PassNamePrefix = {
+  static constexpr StringLiteral PassNamePrefix[] = {
       "x86-",    "xcore-", "wasm-",  "systemz-", "ppc-",    "nvvm-",
       "nvptx-",  "mips-",  "lanai-", "hexagon-", "bpf-",    "avr-",
       "thumb2-", "arm-",   "si-",    "gcn-",     "amdgpu-", "aarch64-",
       "amdgcn-", "polly-", "riscv-", "dxil-"};
-  std::vector<StringRef> PassNameContain = {"-eh-prepare"};
-  std::vector<StringRef> PassNameExact = {
+  static constexpr StringLiteral PassNameContain[] = {"-eh-prepare"};
+  static constexpr StringLiteral PassNameExact[] = {
       "safe-stack",
       "cost-model",
       "codegenprepare",



More information about the llvm-commits mailing list