-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic clang backend plugin support.
This patch teaches Clad how to attach itself as a plugin to the compiler backend. This allows us to implement our own AD-related backend passes but also to integrate tools such as Enzyme easily.
- Loading branch information
1 parent
fab29b6
commit b5bfdb9
Showing
4 changed files
with
182 additions
and
14 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,30 @@ | ||
//--------------------------------------------------------------------*- C++ -*- | ||
// clad - the C++ Clang-based Automatic Differentiator | ||
// version: $Id$ | ||
// author: Vassil Vassilev <vvasilev-at-cern.ch> | ||
//------------------------------------------------------------------------------ | ||
|
||
#include "clang/Basic/Version.h" // for CLANG_VERSION_MAJOR | ||
|
||
#if CLANG_VERSION_MAJOR > 8 | ||
|
||
#include "ClangBackendPlugin.h" | ||
|
||
#include "llvm/Passes/PassBuilder.h" | ||
|
||
namespace clad { | ||
using namespace llvm; | ||
void ClangBackendPluginPass::registerCallbacks(PassBuilder& PB) { | ||
PB.registerPipelineParsingCallback( | ||
[](StringRef Name, ModulePassManager& PM, | ||
ArrayRef<PassBuilder::PipelineElement> InnerPipeline) { | ||
if (Name == "plugin-pass") { | ||
PM.addPass(ClangBackendPluginPass()); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} | ||
} // namespace clad | ||
|
||
#endif // CLANG_VERSION_MAJOR > 8 |
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,31 @@ | ||
//--------------------------------------------------------------------*- C++ -*- | ||
// clad - the C++ Clang-based Automatic Differentiator | ||
// version: $Id$ | ||
// author: Vassil Vassilev <vvasilev-at-cern.ch> | ||
//------------------------------------------------------------------------------ | ||
|
||
#ifndef CLANG_BACKEND_PLUGIN_H | ||
#define CLANG_BACKEND_PLUGIN_H | ||
|
||
#include "llvm/Config/llvm-config.h" // for CLANG_VERSION_MAJOR | ||
|
||
#if CLANG_VERSION_MAJOR > 8 | ||
|
||
#include "llvm/IR/PassManager.h" | ||
#include "llvm/Passes/PassPlugin.h" | ||
|
||
namespace clad { | ||
|
||
struct ClangBackendPluginPass | ||
: public llvm::PassInfoMixin<ClangBackendPluginPass> { | ||
llvm::PreservedAnalyses run(llvm::Module& M, | ||
llvm::ModuleAnalysisManager& MAM) { | ||
return llvm::PreservedAnalyses::all(); | ||
} | ||
|
||
static void registerCallbacks(llvm::PassBuilder& PB); | ||
}; | ||
} // end namespace clad | ||
|
||
#endif // CLANG_VERSION_MAJOR > 8 | ||
#endif // CLANG_BACKEND_PLUGIN_H |
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