-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Opt] Enable support for statically linked plugins
- Loading branch information
Showing
4 changed files
with
116 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; REQUIRES: x86-registered-target | ||
; RUN: opt-printplugin %s -load-pass-plugin="PrintPlugin" -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 | ||
} | ||
|
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,63 @@ | ||
//===- LLVMPrintFunctionNames.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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Example opt plugin which simply prints the names of all the functions | ||
// within the generated LLVM code. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#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" | ||
|
||
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; } | ||
}; | ||
|
||
} // namespace | ||
|
||
llvm::PassPluginLibraryInfo getPrintPluginInfo() { | ||
return {LLVM_PLUGIN_API_VERSION, "PrintPlugin", LLVM_VERSION_STRING, | ||
[](PassBuilder &PB) { | ||
PB.registerPipelineParsingCallback( | ||
[](StringRef Name, llvm::ModulePassManager &PM, | ||
ArrayRef<llvm::PassBuilder::PipelineElement>) { | ||
if (Name == "printpass") { | ||
PM.addPass(PrintPass()); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
}}; | ||
} | ||
|
||
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo | ||
llvmGetPassPluginInfoPrintPlugin() { | ||
return getPrintPluginInfo(); | ||
} |