Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ enzyme/benchmarks/ReverseMode/*/results.json
.cache
CMakeUserPresets.json
/out
bazel-*
*.pyc
compile_commands.json
.vscode/
18 changes: 9 additions & 9 deletions enzyme/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,18 @@ cc_library(
":bundled-includes",
"@llvm-project//clang:ast",
"@llvm-project//clang:basic",
"@llvm-project//clang:driver",
"@llvm-project//clang:frontend",
"@llvm-project//clang:frontend_tool",
"@llvm-project//clang:lex",
"@llvm-project//clang:sema",
"@llvm-project//clang:serialization",
"@llvm-project//llvm:AggressiveInstCombine",
"@llvm-project//llvm:Analysis",
"@llvm-project//llvm:CodeGen",
"@llvm-project//llvm:Core",
"@llvm-project//llvm:Demangle",
"@llvm-project//llvm:IPO",
"@llvm-project//llvm:IRReader",
"@llvm-project//llvm:InstCombine",
"@llvm-project//llvm:Passes",
"@llvm-project//llvm:Scalar",
"@llvm-project//llvm:Support",
"@llvm-project//llvm:Target",
"@llvm-project//llvm:TargetParser",
"@llvm-project//llvm:TransformUtils",
"@llvm-project//llvm:config",
],
alwayslink = 1,
)
Expand All @@ -88,8 +79,17 @@ cc_binary(
],
deps = [
":ReactantStatic",
"@llvm-project//clang:driver",
"@llvm-project//clang:clang-driver",
"@llvm-project//clang:frontend_tool",
"@llvm-project//clang:serialization",
"@llvm-project//llvm:AggressiveInstCombine",
"@llvm-project//llvm:Support",
"@llvm-project//llvm:CodeGen",
"@llvm-project//llvm:Demangle",
"@llvm-project//llvm:Target",
"@llvm-project//llvm:TargetParser",
"@llvm-project//llvm:config",
],
)

Expand Down
49 changes: 47 additions & 2 deletions enzyme/Enzyme/Clang/EnzymeClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"

#include "llvm/ADT/StringRef.h"

#include "Enzyme/Utils.h"

#include "bundled_includes.h"
Expand All @@ -48,6 +50,8 @@ constexpr auto StructKind = clang::TagTypeKind::TTK_Struct;
#endif

extern llvm::cl::opt<std::string> ReactantBackend;
extern llvm::cl::opt<std::string> Passes;
extern llvm::cl::opt<std::string> DeviceLibraries;

template <typename ConsumerType>
class EnzymeAction final : public clang::PluginASTAction {
Expand All @@ -64,9 +68,50 @@ llvm::errs() << " out file: " << CI.getFrontendOpts().OutputFile << "\n";
bool ParseArgs(const clang::CompilerInstance &CI,
const std::vector<std::string> &args) override {
llvm::errs() << " parse args action\n";
llvm::errs() << " pa: " << CI.getFrontendOpts().ProgramAction << "\n";
llvm::errs() << " pa: " << CI.getFrontendOpts().ProgramAction << "\n";
llvm::errs() << " args:\n";
for (auto a : args) llvm::errs() << "+ arg: " << a<<"\n";
static constexpr llvm::StringLiteral RaisePathPrefix = "raising-plugin-path=";
static constexpr llvm::StringLiteral BackendPrefix = "reactant-backend=";
static constexpr llvm::StringLiteral DeviceLibPrefix = "reactant-device-lib=";

for (const auto &arg : args) {
llvm::errs() << "+ arg: " << arg << "\n";
llvm::StringRef value(arg);

if (value.consume_front(RaisePathPrefix)) {
if (value.empty()) {
llvm::errs() << " warning: ignoring malformed plugin arg '" << arg
<< "' (missing value)\n";
continue;
}
Passes = value.str();
continue;
}

if (value.consume_front(BackendPrefix)) {
if (value.empty()) {
llvm::errs() << " warning: ignoring malformed plugin arg '" << arg
<< "' (missing value)\n";
continue;
}
ReactantBackend = value.str();
continue;
}

if (value.consume_front(DeviceLibPrefix)) {
if (value.empty()) {
llvm::errs() << " warning: ignoring malformed plugin arg '" << arg
<< "' (missing value)\n";
continue;
}
DeviceLibraries = value.str();
continue;
}

llvm::errs() << " warning: ignoring unknown plugin arg '" << arg
<< "'\n";
}

return true;
}

Expand Down
Loading