-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Driver][Frontend] Introduce
load-pass-plugin
option
Allow dynamic loading of LLVM passes via `load-pass-plugin` option passed to the Swift compiler driver.
- Loading branch information
1 parent
3a511e0
commit 7055ddf
Showing
10 changed files
with
120 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//===---------------------- TestPlugin.cpp ----------------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2023 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Used by -load-pass-plugin | ||
|
||
#include "llvm/Pass.h" | ||
#include "llvm/Passes/PassBuilder.h" | ||
#include "llvm/Passes/PassPlugin.h" | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
|
||
void runTestPlugin(Function &F) { | ||
errs() << "TestPlugin: "; | ||
errs().write_escaped(F.getName()) << '\n'; | ||
} | ||
|
||
struct TestPluginPass : PassInfoMixin<TestPluginPass> { | ||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) { | ||
runTestPlugin(F); | ||
return PreservedAnalyses::all(); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
PassPluginLibraryInfo getTestPluginInfo() { | ||
return {LLVM_PLUGIN_API_VERSION, "TestPlugin", LLVM_VERSION_STRING, | ||
[](PassBuilder &PB) { | ||
PB.registerVectorizerStartEPCallback( | ||
[](llvm::FunctionPassManager &PM, OptimizationLevel Level) { | ||
PM.addPass(TestPluginPass()); | ||
}); | ||
}}; | ||
} | ||
|
||
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo | ||
llvmGetPassPluginInfo() { | ||
return getTestPluginInfo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// REQUIRES: OS=macosx | ||
|
||
// RUN: %target-swift-frontend -load-pass-plugin=nonexistent.dylib %s -emit-ir -o /dev/null 2>&1 | %FileCheck -check-prefix=CHECK-UNABLE-LOAD %s | ||
// CHECK-UNABLE-LOAD: error: unable to load plugin 'nonexistent.dylib': 'Could not load library{{.*}}' | ||
|
||
// RUN: %target-clangxx %S/Inputs/TestPlugin.cpp -std=c++17 -stdlib=libc++ \ | ||
// RUN: -isysroot %sdk -I %llvm_src_root/include -I %llvm_obj_root/include -L %llvm_obj_root/lib -lLLVMSupport \ | ||
// RUN: -Wl,-undefined -Wl,suppress -Wl,-flat_namespace \ | ||
// RUN: -dynamiclib -o %t/libTestPlugin.dylib | ||
|
||
// RUN: %target-swift-frontend -load-pass-plugin=%t/libTestPlugin.dylib %s -emit-ir -o /dev/null 2>&1 | swift-demangle | %FileCheck %s | ||
// CHECK: TestPlugin: main | ||
// CHECK: TestPlugin: null.empty() -> () | ||
|
||
func empty() {} |