Skip to content

[CMake/Bazel] Support usage of opt driver as a library #79205

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

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions llvm/tools/opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@ set(LLVM_LINK_COMPONENTS
Passes
)

add_llvm_tool(opt
# We don't want to link this into libLLVM
add_llvm_library(LLVMOptDriver
STATIC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual llvlm style is to have one target per directory. If this is now a lib, could you move this into llvm/tools/opt/lib? Then you don't need the PARTIAL_SOURCES_INTENDED below.

NewPMDriver.cpp
opt.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)
9 changes: 7 additions & 2 deletions llvm/tools/opt/NewPMDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ bool llvm::runPassPipeline(
StringRef Arg0, Module &M, TargetMachine *TM, TargetLibraryInfoImpl *TLII,
ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut,
ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
ArrayRef<PassPlugin> PassPlugins, OutputKind OK, VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
ArrayRef<PassPlugin> PassPlugins,
ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks,
OutputKind OK, VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve,
bool UnifiedLTO) {
Expand Down Expand Up @@ -428,6 +429,10 @@ bool llvm::runPassPipeline(
for (auto &PassPlugin : PassPlugins)
PassPlugin.registerPassBuilderCallbacks(PB);

// Load any explicitly specified plugins.
for (auto &PassCallback : PassBuilderCallbacks)
PassCallback(PB);

#define HANDLE_EXTENSION(Ext) \
get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
#include "llvm/Support/Extension.def"
Expand Down
22 changes: 12 additions & 10 deletions llvm/tools/opt/NewPMDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/Support/CommandLine.h"

namespace llvm {
class PassBuilder;
class StringRef;
class Module;
class PassPlugin;
Expand Down Expand Up @@ -64,16 +65,17 @@ void printPasses(raw_ostream &OS);
///
/// ThinLTOLinkOut is only used when OK is OK_OutputThinLTOBitcode, and can be
/// nullptr.
bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
TargetLibraryInfoImpl *TLII, ToolOutputFile *Out,
ToolOutputFile *ThinLinkOut, ToolOutputFile *OptRemarkFile,
StringRef PassPipeline, ArrayRef<PassPlugin> PassPlugins,
opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder,
bool EmitSummaryIndex, bool EmitModuleHash,
bool EnableDebugify, bool VerifyDIPreserve,
bool UnifiedLTO = false);
bool runPassPipeline(
StringRef Arg0, Module &M, TargetMachine *TM, TargetLibraryInfoImpl *TLII,
ToolOutputFile *Out, ToolOutputFile *ThinLinkOut,
ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
ArrayRef<PassPlugin> PassPlugins,
ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks,
opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve,
bool UnifiedLTO = false);
} // namespace llvm

#endif
Loading