-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[Opt] Enable statically-linked plugin support #79227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,7 @@ set(LLVM_TEST_DEPENDS | |
not | ||
obj2yaml | ||
opt | ||
opt-printplugin | ||
sancov | ||
sanstats | ||
split-file | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; REQUIRES: x86-registered-target | ||
; RUN: opt-printplugin %s -passes="printpass" -disable-output 2>&1 | FileCheck %s | ||
|
||
; REQUIRES: plugins | ||
|
||
; CHECK: [PrintPass] Found function: somefunk | ||
|
||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
@junk = global i32 0 | ||
|
||
define ptr @somefunk() { | ||
ret ptr @junk | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,24 +29,6 @@ set(LLVM_LINK_COMPONENTS | |
Passes | ||
) | ||
|
||
# We don't want to link this into libLLVM | ||
add_llvm_library(LLVMOptDriver | ||
STATIC | ||
NewPMDriver.cpp | ||
optdriver.cpp | ||
PARTIAL_SOURCES_INTENDED | ||
DEPENDS | ||
intrinsics_gen | ||
) | ||
|
||
add_llvm_tool(opt | ||
PARTIAL_SOURCES_INTENDED | ||
opt.cpp | ||
DEPENDS | ||
intrinsics_gen | ||
SUPPORT_PLUGINS | ||
|
||
) | ||
target_link_libraries(opt PRIVATE LLVMOptDriver) | ||
|
||
export_executable_symbols_for_plugins(opt) | ||
add_subdirectory(lib) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (can't comment above due to github limitations) should |
||
add_subdirectory(driver) | ||
add_subdirectory(test) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
add_llvm_tool(opt | ||
opt.cpp | ||
DEPENDS | ||
intrinsics_gen | ||
SUPPORT_PLUGINS | ||
) | ||
target_link_libraries(opt PRIVATE LLVMOptDriver) | ||
export_executable_symbols_for_plugins(opt) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# We don't want to link this into libLLVM | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my understanding, how do we tell the build system not to link this into libLLVM? |
||
add_llvm_library(LLVMOptDriver | ||
STATIC | ||
NewPMDriver.cpp | ||
optdriver.cpp | ||
PARTIAL_SOURCES_INTENDED | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need |
||
DEPENDS | ||
intrinsics_gen | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,12 +57,12 @@ cl::opt<bool> VerifyEachDebugInfoPreserve( | |
cl::desc("Start each pass with collecting and end it with checking of " | ||
"debug info preservation.")); | ||
|
||
cl::opt<std::string> | ||
VerifyDIPreserveExport("verify-di-preserve-export", | ||
cl::desc("Export debug info preservation failures into " | ||
"specified (JSON) file (should be abs path as we use" | ||
" append mode to insert new JSON objects)"), | ||
cl::value_desc("filename"), cl::init("")); | ||
cl::opt<std::string> VerifyDIPreserveExport( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you commit the formatting changes ahead of time |
||
"verify-di-preserve-export", | ||
cl::desc("Export debug info preservation failures into " | ||
"specified (JSON) file (should be abs path as we use" | ||
" append mode to insert new JSON objects)"), | ||
cl::value_desc("filename"), cl::init("")); | ||
|
||
} // namespace llvm | ||
|
||
|
@@ -163,7 +163,6 @@ static cl::opt<bool> DisablePipelineVerification( | |
"-print-pipeline-passes can be used to create a pipeline."), | ||
cl::Hidden); | ||
|
||
|
||
static cl::opt<PGOKind> | ||
PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden, | ||
cl::desc("The kind of profile guided optimization"), | ||
|
@@ -174,8 +173,8 @@ static cl::opt<PGOKind> | |
"Use instrumented profile to guide PGO."), | ||
clEnumValN(SampleUse, "pgo-sample-use-pipeline", | ||
"Use sampled profile to guide PGO."))); | ||
static cl::opt<std::string> ProfileFile("profile-file", | ||
cl::desc("Path to the profile."), cl::Hidden); | ||
static cl::opt<std::string> | ||
ProfileFile("profile-file", cl::desc("Path to the profile."), cl::Hidden); | ||
static cl::opt<std::string> | ||
MemoryProfileFile("memory-profile-file", | ||
cl::desc("Path to the memory profile."), cl::Hidden); | ||
|
@@ -411,8 +410,7 @@ bool llvm::runPassPipeline( | |
} else if (VerifyEachDebugInfoPreserve) { | ||
Debugify.setDebugInfoBeforePass(DebugInfoBeforePass); | ||
Debugify.setDebugifyMode(DebugifyMode::OriginalDebugInfo); | ||
Debugify.setOrigDIVerifyBugsReportFilePath( | ||
VerifyDIPreserveExport); | ||
Debugify.setOrigDIVerifyBugsReportFilePath(VerifyDIPreserveExport); | ||
Debugify.registerCallbacks(PIC, MAM); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
add_llvm_tool(opt-printplugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this |
||
opt-printplugin.cpp | ||
DEPENDS | ||
intrinsics_gen | ||
SUPPORT_PLUGINS | ||
) | ||
target_link_libraries(opt-printplugin PRIVATE LLVMOptDriver) | ||
export_executable_symbols_for_plugins(opt-printplugin) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this for an example/test binary? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//===- opt-printplugin.cpp - The LLVM Modular Optimizer | ||
//-------------------------------===// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting |
||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Example static opt plugin which simply prints the names of all the functions | ||
// within the generated LLVM code. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/IR/PassManager.h" | ||
#include "llvm/Passes/OptimizationLevel.h" | ||
#include "llvm/Passes/PassBuilder.h" | ||
#include "llvm/Passes/PassPlugin.h" | ||
#include "llvm/Support/Registry.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
#include <functional> | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
|
||
class PrintPass final : public llvm::AnalysisInfoMixin<PrintPass> { | ||
friend struct llvm::AnalysisInfoMixin<PrintPass>; | ||
|
||
private: | ||
static llvm::AnalysisKey key; | ||
|
||
public: | ||
using Result = llvm::PreservedAnalyses; | ||
|
||
Result run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM) { | ||
for (auto &F : M) | ||
llvm::outs() << "[PrintPass] Found function: " << F.getName() << "\n"; | ||
return llvm::PreservedAnalyses::all(); | ||
} | ||
static bool isRequired() { return true; } | ||
}; | ||
|
||
void registerPlugin(PassBuilder &PB) { | ||
PB.registerPipelineParsingCallback( | ||
[](StringRef Name, llvm::ModulePassManager &PM, | ||
ArrayRef<llvm::PassBuilder::PipelineElement>) { | ||
if (Name == "printpass") { | ||
PM.addPass(PrintPass()); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
} // namespace | ||
|
||
extern "C" int optMain(int argc, char **argv, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
llvm::ArrayRef<std::function<void(llvm::PassBuilder &)>> | ||
PassBuilderCallbacks); | ||
|
||
int main(int argc, char **argv) { | ||
std::function<void(llvm::PassBuilder &)> plugins[] = {registerPlugin}; | ||
return optMain(argc, argv, plugins); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this actually requires plugins, that's only necessary for shared library plugins IIUC