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
59 changes: 59 additions & 0 deletions patches/llvm_flang_features.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -278,6 +278,20 @@
auto uint64Ty = mlir::IntegerType::get(context, 64);
auto funcTy = mlir::FunctionType::get(
context, {voidPtrTy, voidPtrTy, uint64Ty}, {voidPtrTy});
+ return fir::LLVMPointerType::get(context, funcTy);
+ };
+}
+#else
+template <>
+constexpr TypeBuilderFunc
+getModel<void *(*)(void *, const void *, unsigned long long)>() {
+ return [](mlir::MLIRContext *context) -> mlir::Type {
+ auto voidPtrTy =
+ fir::LLVMPointerType::get(context, mlir::IntegerType::get(context, 8));
+ auto unsignedLongLongTy =
+ mlir::IntegerType::get(context, 8 * sizeof(unsigned long long));
+ auto funcTy = mlir::FunctionType::get(
+ context, {voidPtrTy, voidPtrTy, unsignedLongLongTy}, {voidPtrTy});
return fir::LLVMPointerType::get(context, funcTy);
};
}
diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
--- a/flang/include/flang/Support/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -11,7 +11,10 @@

#include "Fortran.h"
#include "flang/Common/enum-set.h"
+#include <array>
+#include <string>
#include <string_view>
+#include <unordered_map>
#include <vector>

namespace Fortran::common {
diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -498,7 +498,7 @@
#endif // __GLIBC__ && (HAS_FLOAT80 || HAS_LDBL128)
#endif // _POSIX_VERSION >= 200112L || _XOPEN_VERSION >= 600

-#ifdef _WIN32
+#if defined(_MSC_VER)
template <> struct HostRuntimeLibrary<double, LibraryVersion::LibmExtensions> {
using F = FuncPointer<double, double>;
using FN = FuncPointer<double, int, double>;
@@ -513,7 +513,7 @@
static constexpr HostRuntimeMap map{table};
static_assert(map.Verify(), "map must be sorted");
};
-#endif // _WIN32
+#endif // _MSC_VER

#if HAS_QUADMATHLIB
template <> struct HostRuntimeLibrary<__float128, LibraryVersion::Libm> {
53 changes: 53 additions & 0 deletions src/enzyme_ad/jax/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,57 @@ cc_library(
alwayslink = True,
)

genrule(
name = "flang_rt_archive_inc",
srcs = ["@llvm-project//flang-rt:runtime"],
outs = ["flang_rt_archive.inc"],
cmd = """python3 -c '
import sys
archive_path = next(p for p in sys.argv[1:-1] if p.endswith(".a"))
data = open(archive_path, "rb").read()
with open(sys.argv[-1], "w") as out:
out.write("alignas(8) static const unsigned char kFlangRuntimeArchive[] = {\\n")
for i in range(0, len(data), 16):
chunk = data[i : i + 16]
out.write(" " + ", ".join(f"0x{b:02x}" for b in chunk) + ",\\n")
out.write("};\\n")
' $(SRCS) $@""",
)

cc_library(
name = "flang_compile",
srcs = ["flang_compile.cc"],
hdrs = ["flang_compile.h"],
copts = [
"-Wno-implicit-fallthrough",
"-Wno-non-virtual-dtor",
"-Wno-pessimizing-move",
"-Wno-unused-result",
"-Wno-unused-variable",
],
deps = [
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@llvm-project//clang:basic",
"@llvm-project//flang:CommonHeaders",
"@llvm-project//flang:FrontendHeaders",
"@llvm-project//flang:ParserHeaders",
"@llvm-project//flang:RuntimeHeaders",
"@llvm-project//flang/include/flang/Optimizer/Dialect:DialectHeaders",
"@llvm-project//flang/include/flang/Optimizer/Support:FIRSupportHeaders",
"@llvm-project//flang/lib/Frontend:flangFrontend",
"@llvm-project//flang/lib/Optimizer/Dialect:FIRDialect",
"@llvm-project//flang/lib/Optimizer/Support:FIRSupport",
"@llvm-project//llvm:Core",
"@llvm-project//llvm:Support",
"@llvm-project//llvm:Target",
"@llvm-project//llvm:TargetParser",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Support",
],
)

cc_library(
name = "clang_compile",
srcs = ["clang_compile.cc"],
Expand All @@ -183,6 +234,7 @@ cc_library(
],
deps = [
":compile_with_xla",
":flang_compile",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@enzyme//:EnzymeStatic",
Expand Down Expand Up @@ -1894,6 +1946,7 @@ pybind_extension(
name = "enzyme_call",
srcs = [
"enzyme_call.cc",
"flang_rt_archive.inc",
],
copts = [
"-Wno-implicit-fallthrough",
Expand Down
1 change: 1 addition & 0 deletions src/enzyme_ad/jax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enzyme_ad.jax.primitives import (
cpp_call,
ffi_call,
fortran_call,
hlo_call,
enzyme_jax_ir,
XLAPipeline,
Expand Down
Loading
Loading