[clang] [lld] [llvm] [RFC] Initial reference pass-plugin in LLVM (PR #171111)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 10 04:01:42 PST 2025
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/171111 at github.com>
================
@@ -0,0 +1,464 @@
+//===- tools/plugins-shlib/pypass.cpp -------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/ScopeExit.h"
+#include "llvm/Passes/PassBuilder.h"
+#include "llvm/Passes/PassPlugin.h"
+#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <algorithm>
+#include <cstdlib>
+#include <filesystem>
+#include <memory>
+#include <optional>
+#include <string>
+
+using namespace llvm;
+
+static cl::opt<std::string>
+ DylibPath("pypass-dylib", cl::desc("Path to the Python shared library"),
+ cl::init(""));
+
+static cl::opt<std::string>
+ ScriptPath("pypass-script", cl::desc("Path to the Python script to run"),
+ cl::init(""));
+
+static std::string findPython() {
+ if (!DylibPath.empty())
+ return DylibPath;
+ if (const char *Path = std::getenv("LLVM_PYPASS_DYLIB"))
+ return std::string(Path);
+ // TODO: Run Python from PATH and use a script to query the shared lib
+ return std::string{};
+}
+
+static std::string findScript() {
+ if (!ScriptPath.empty())
+ return ScriptPath;
+ if (const char *Path = std::getenv("LLVM_PYPASS_SCRIPT"))
+ return std::string(Path);
+ return std::string{};
+}
+
+struct PythonAPI {
----------------
serge-sans-paille wrote:
I forgot to mention, but I think that this + the stable API is the most portable approach, I'm glad you chose this path.
https://github.com/llvm/llvm-project/pull/171111
More information about the llvm-commits
mailing list