[llvm] [polly] Slightly improve the getenv("bar") linking problem (PR #150020)

Luke Drummond via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 22 06:22:11 PDT 2025


================
@@ -35,132 +38,219 @@
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/Support/Valgrind.h"
+#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
+#include "llvm/Transforms/IPO/Attributor.h"
+#include "llvm/Transforms/IPO/FunctionAttrs.h"
 #include "llvm/Transforms/InstCombine/InstCombine.h"
+#include "llvm/Transforms/Instrumentation.h"
+#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/GVN.h"
+#include "llvm/Transforms/Scalar/InstSimplifyPass.h"
 #include "llvm/Transforms/Scalar/Scalarizer.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
-#include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"
+#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
+#include "llvm/Transforms/Vectorize.h"
 #include <cstdlib>
 
 namespace llvm {
-class Triple;
+  inline bool getNonFoldableAlwaysTrue() {
+    // Some parts of the codebase require a "constant true value" used as a
+    // predicate. These cases require that even with LTO and static linking,
+    // it's not possible to for the compiler to fold the value. As compilers
+    // aren't smart enough to know that getenv() never returns -1, this will do
+    // the job.
+    return std::getenv("LLVM_IGNORED_ENV_VAR") != (char *)-1;
+  }
 }
-
 namespace {
-struct ForcePassLinking {
-  ForcePassLinking() {
-    // We must reference the passes in such a way that compilers will not
-    // delete it all as dead code, even with whole program optimization,
-    // yet is effectively a NO-OP. As the compiler isn't smart enough
-    // to know that getenv() never returns -1, this will do the job.
-    // This is so that globals in the translation units where these functions
-    // are defined are forced to be initialized, populating various
-    // registries.
-    if (std::getenv("bar") != (char *)-1)
-      return;
+  struct ForcePassLinking {
----------------
ldrumm wrote:

Not sure what I've done to the formatting here. Will check

https://github.com/llvm/llvm-project/pull/150020


More information about the llvm-commits mailing list