11load ("@bazel_skylib//rules:expand_template.bzl" , "expand_template" )
2+
3+ # generate compilation commands for enzymemlir - opt
4+ load ("@hedron_compile_commands//:refresh_compile_commands.bzl" , "refresh_compile_commands" )
25load ("@llvm-project//mlir:tblgen.bzl" , "gentbl_cc_library" , "td_library" )
36
47licenses (["notice" ])
@@ -135,22 +138,25 @@ cc_library(
135138 name = "EnzymeCacheUtility" ,
136139 srcs = [
137140 "Enzyme/CacheUtility.cpp" ,
138- "Enzyme/MustExitScalarEvolution.cpp"
141+ "Enzyme/MustExitScalarEvolution.cpp" ,
139142 ],
140- hdrs = glob ([
141- "Enzyme/*.h" ,
142- "Enzyme/TypeAnalysis/*.h" ,
143- ]),
143+ hdrs = glob (
144+ [
145+ "Enzyme/*.h" ,
146+ "Enzyme/TypeAnalysis/*.h" ,
147+ ],
148+ exclude = ["Enzyme/AdjointGenerator.h" ],
149+ ),
144150 copts = [
145151 "-Wno-unused-variable" ,
146152 "-Wno-return-type" ,
147153 ],
148154 visibility = ["//visibility:public" ],
149155 deps = [
150- "@llvm-project//llvm:Passes" ,
151156 "@llvm-project//llvm:Analysis" ,
152157 "@llvm-project//llvm:CodeGen" ,
153158 "@llvm-project//llvm:Core" ,
159+ "@llvm-project//llvm:Passes" ,
154160 "@llvm-project//llvm:Support" ,
155161 "@llvm-project//llvm:Target" ,
156162 "@llvm-project//llvm:TransformUtils" ,
@@ -161,26 +167,29 @@ cc_library(
161167cc_library (
162168 name = "EnzymeTypeAnalysis" ,
163169 srcs = [
170+ "Enzyme/TypeAnalysis/RustDebugInfo.cpp" ,
164171 "Enzyme/TypeAnalysis/TypeAnalysis.cpp" ,
165172 "Enzyme/TypeAnalysis/TypeTree.cpp" ,
166- "Enzyme/TypeAnalysis/RustDebugInfo.cpp"
167173 ],
168- hdrs = glob ([
169- "Enzyme/*.h" ,
170- "Enzyme/TypeAnalysis/*.h" ,
171- ]),
174+ hdrs = glob (
175+ [
176+ "Enzyme/*.h" ,
177+ "Enzyme/TypeAnalysis/*.h" ,
178+ ],
179+ exclude = ["Enzyme/AdjointGenerator.h" ],
180+ ),
172181 copts = [
173182 "-Wno-unused-variable" ,
174183 "-Wno-return-type" ,
175184 ],
176185 visibility = ["//visibility:public" ],
177186 deps = [
178187 ":blas-typeanalysis" ,
179- "@llvm-project//llvm:Passes" ,
180188 "@llvm-project//llvm:Analysis" ,
181189 "@llvm-project//llvm:CodeGen" ,
182190 "@llvm-project//llvm:Core" ,
183191 "@llvm-project//llvm:Demangle" ,
192+ "@llvm-project//llvm:Passes" ,
184193 "@llvm-project//llvm:Support" ,
185194 "@llvm-project//llvm:Target" ,
186195 "@llvm-project//llvm:TransformUtils" ,
@@ -191,23 +200,26 @@ cc_library(
191200cc_library (
192201 name = "EnzymePreserveNVVM" ,
193202 srcs = [
194- "Enzyme/PreserveNVVM.cpp"
203+ "Enzyme/PreserveNVVM.cpp" ,
195204 ],
196- hdrs = glob ([
197- "Enzyme/*.h" ,
198- "Enzyme/TypeAnalysis/*.h" ,
199- ]),
205+ hdrs = glob (
206+ [
207+ "Enzyme/*.h" ,
208+ "Enzyme/TypeAnalysis/*.h" ,
209+ ],
210+ exclude = ["Enzyme/AdjointGenerator.h" ],
211+ ),
200212 copts = [
201213 "-Wno-unused-variable" ,
202214 "-Wno-return-type" ,
203- "-DENZYME_ENABLE_NVVM_ATTRIBUTION=0"
215+ "-DENZYME_ENABLE_NVVM_ATTRIBUTION=0" ,
204216 ],
205217 visibility = ["//visibility:public" ],
206218 deps = [
207- "@llvm-project//llvm:Passes" ,
208219 "@llvm-project//llvm:Analysis" ,
209220 "@llvm-project//llvm:CodeGen" ,
210221 "@llvm-project//llvm:Core" ,
222+ "@llvm-project//llvm:Passes" ,
211223 "@llvm-project//llvm:Support" ,
212224 "@llvm-project//llvm:Target" ,
213225 "@llvm-project//llvm:TransformUtils" ,
@@ -219,17 +231,17 @@ cc_library(
219231 name = "EnzymeDiffCore" ,
220232 srcs = [
221233 "Enzyme/ActivityAnalysis.cpp" ,
234+ "Enzyme/CallDerivatives.cpp" ,
235+ "Enzyme/DiffeGradientUtils.cpp" ,
236+ "Enzyme/DifferentialUseAnalysis.cpp" ,
222237 "Enzyme/EnzymeLogic.cpp" ,
223- "Enzyme/Utils.cpp" ,
224238 "Enzyme/FunctionUtils.cpp" ,
225239 "Enzyme/GradientUtils.cpp" ,
226- "Enzyme/DiffeGradientUtils.cpp" ,
227- "Enzyme/DifferentialUseAnalysis.cpp" ,
228240 "Enzyme/InstructionBatcher.cpp" ,
229241 "Enzyme/TraceGenerator.cpp" ,
230- "Enzyme/TraceUtils.cpp" ,
231242 "Enzyme/TraceInterface.cpp" ,
232- "Enzyme/CallDerivatives.cpp" ,
243+ "Enzyme/TraceUtils.cpp" ,
244+ "Enzyme/Utils.cpp" ,
233245 ],
234246 hdrs = glob ([
235247 "Enzyme/*.h" ,
@@ -241,20 +253,24 @@ cc_library(
241253 ],
242254 visibility = ["//visibility:public" ],
243255 deps = [
244- ":inst-derivatives" ,
245256 ":binop-derivatives" ,
246- ":intr-derivatives" ,
247257 ":blas-attributor" ,
248- ":blas-diffuseanalysis" ,
249258 ":blas-derivatives" ,
259+ ":blas-diffuseanalysis" ,
250260 ":call-derivatives" ,
251- "@llvm-project//llvm:Passes" ,
261+ ":inst-derivatives" ,
262+ ":intr-derivatives" ,
252263 "@llvm-project//llvm:Analysis" ,
253264 "@llvm-project//llvm:CodeGen" ,
254265 "@llvm-project//llvm:Core" ,
255266 "@llvm-project//llvm:Demangle" ,
267+ "@llvm-project//llvm:IPO" ,
268+ "@llvm-project//llvm:InstCombine" ,
269+ "@llvm-project//llvm:Passes" ,
270+ "@llvm-project//llvm:Scalar" ,
256271 "@llvm-project//llvm:Support" ,
257272 "@llvm-project//llvm:Target" ,
273+ "@llvm-project//llvm:TargetParser" ,
258274 "@llvm-project//llvm:TransformUtils" ,
259275 "@llvm-project//llvm:config" ,
260276 ],
@@ -289,10 +305,13 @@ cc_library(
289305 "Enzyme/CallDerivatives.cpp" ,
290306 ],
291307 ),
292- hdrs = glob ([
293- "Enzyme/*.h" ,
294- "Enzyme/TypeAnalysis/*.h" ,
295- ]) + ["Enzyme/Clang/bundled_includes.h" ],
308+ hdrs = glob (
309+ [
310+ "Enzyme/*.h" ,
311+ "Enzyme/TypeAnalysis/*.h" ,
312+ ],
313+ exclude = ["Enzyme/AdjointGenerator.h" ],
314+ ) + ["Enzyme/Clang/bundled_includes.h" ],
296315 copts = [
297316 "-DENZYME_RUNPASS=1" ,
298317 "-DENZYME_VERSION_MAJOR=0" ,
@@ -306,10 +325,10 @@ cc_library(
306325 "Enzyme/Clang" , # for bundled_includes.h
307326 ],
308327 visibility = ["//visibility:public" ],
309- deps = [
310- ":EnzymeTypeAnalysis" ,
328+ deps = [
311329 ":EnzymeCacheUtility" ,
312330 ":EnzymeDiffCore" ,
331+ ":EnzymeTypeAnalysis" ,
313332 ":bundled-includes" ,
314333 "@llvm-project//clang:ast" ,
315334 "@llvm-project//clang:basic" ,
@@ -328,6 +347,7 @@ cc_library(
328347 "@llvm-project//llvm:IRReader" ,
329348 "@llvm-project//llvm:InstCombine" ,
330349 "@llvm-project//llvm:Passes" ,
350+ "@llvm-project//llvm:Plugins" ,
331351 "@llvm-project//llvm:Scalar" ,
332352 "@llvm-project//llvm:Support" ,
333353 "@llvm-project//llvm:Target" ,
@@ -338,13 +358,15 @@ cc_library(
338358 alwayslink = 1 ,
339359)
340360
341-
342361# Modified from llvm_driver_cc_binary since that can't be used
343362# outside of llvm tree
344363expand_template (
345364 name = "_gen_enzyme-clang" ,
346365 out = "enzyme-clang-driver.cpp" ,
347- substitutions = { "@TOOL_NAME@" : "clang" , "@INITLLVM_ARGS@" : ", /*InstallPipeSignalExitHandler=*/true, /*NeedsPOSIXUtilitySignalHandling=*/true" },
366+ substitutions = {
367+ "@TOOL_NAME@" : "clang" ,
368+ "@INITLLVM_ARGS@" : ", /*InstallPipeSignalExitHandler=*/true, /*NeedsPOSIXUtilitySignalHandling=*/true" ,
369+ },
348370 template = "@llvm-project//llvm:cmake/modules/llvm-driver-template.cpp.in" ,
349371)
350372
@@ -397,7 +419,7 @@ td_library(
397419 includes = ["." ],
398420 deps = [
399421 "@llvm-project//mlir:OpBaseTdFiles" ,
400- ]
422+ ],
401423)
402424
403425td_library (
@@ -408,27 +430,27 @@ td_library(
408430 ],
409431 includes = ["." ],
410432 deps = [
433+ "@llvm-project//mlir:ArithOpsTdFiles" ,
411434 "@llvm-project//mlir:ControlFlowInterfacesTdFiles" ,
412435 "@llvm-project//mlir:FunctionInterfacesTdFiles" ,
413436 "@llvm-project//mlir:LoopLikeInterfaceTdFiles" ,
414437 "@llvm-project//mlir:MemorySlotInterfacesTdFiles" ,
415438 "@llvm-project//mlir:OpBaseTdFiles" ,
416439 "@llvm-project//mlir:SideEffectInterfacesTdFiles" ,
417440 "@llvm-project//mlir:ViewLikeInterfaceTdFiles" ,
418- "@llvm-project//mlir:ArithOpsTdFiles" ,
419441 ],
420442)
421443
422444cc_library (
423445 name = "LLVMExtDialect" ,
424- strip_include_prefix = "Enzyme/MLIR" ,
425446 srcs = [
426447 "Enzyme/MLIR/Dialect/LLVMExt/LLVMExtDialect.cpp" ,
427448 "Enzyme/MLIR/Dialect/LLVMExt/LLVMExtOps.cpp" ,
428449 ],
429450 hdrs = [
430451 "Enzyme/MLIR/Dialect/LLVMExt/LLVMExt.h" ,
431452 ],
453+ strip_include_prefix = "Enzyme/MLIR" ,
432454 visibility = ["//visibility:public" ],
433455 deps = [
434456 ":LLVMExtIncGen" ,
@@ -580,13 +602,17 @@ gentbl_cc_library(
580602 strip_include_prefix = "Enzyme/MLIR" ,
581603 tbl_outs = [
582604 (
583- ["-gen-attrdef-decls" ,
584- "-attrdefs-dialect=enzyme" ],
605+ [
606+ "-gen-attrdef-decls" ,
607+ "-attrdefs-dialect=enzyme" ,
608+ ],
585609 "Enzyme/MLIR/Dialect/EnzymeAttributes.h.inc" ,
586610 ),
587611 (
588- ["-gen-attrdef-defs" ,
589- "-attrdefs-dialect=enzyme" ],
612+ [
613+ "-gen-attrdef-defs" ,
614+ "-attrdefs-dialect=enzyme" ,
615+ ],
590616 "Enzyme/MLIR/Dialect/EnzymeAttributes.cpp.inc" ,
591617 ),
592618 ],
@@ -818,28 +844,28 @@ cc_library(
818844 ],
819845 visibility = ["//visibility:public" ],
820846 deps = [
821- ":EnzymeAttributesIncGen" ,
822847 ":EnzymeAttributeInterfacesIncGen" ,
848+ ":EnzymeAttributesIncGen" ,
823849 ":EnzymeEnumsIncGen" ,
824850 ":EnzymeOpInterfacesIncGen" ,
825851 ":EnzymeOpsIncGen" ,
826- ":LLVMExtDialect" ,
827852 ":EnzymePassesIncGen" ,
828853 ":EnzymeTypeInterfacesIncGen" ,
829854 ":EnzymeTypesIncGen" ,
855+ ":LLVMExtDialect" ,
830856 ":affine-derivatives" ,
831- ":linalg-derivatives" ,
832857 ":arith-derivatives" ,
833858 ":cf-derivatives" ,
834859 ":complex-derivatives" ,
860+ ":enzyme-derivatives" ,
835861 ":func-derivatives" ,
862+ ":linalg-derivatives" ,
836863 ":llvm-derivatives" ,
837864 ":llvm-ext-derivatives" ,
838865 ":math-derivatives" ,
839866 ":memref-derivatives" ,
840867 ":nvvm-derivatives" ,
841868 ":scf-derivatives" ,
842- ":enzyme-derivatives" ,
843869 "@llvm-project//llvm:Analysis" ,
844870 "@llvm-project//llvm:Core" ,
845871 "@llvm-project//llvm:Demangle" ,
@@ -863,8 +889,8 @@ cc_library(
863889 "@llvm-project//mlir:FuncExtensions" ,
864890 "@llvm-project//mlir:FunctionInterfaces" ,
865891 "@llvm-project//mlir:GPUDialect" ,
866- "@llvm-project//mlir:InliningUtils" ,
867892 "@llvm-project//mlir:IR" ,
893+ "@llvm-project//mlir:InliningUtils" ,
868894 "@llvm-project//mlir:LLVMCommonConversion" ,
869895 "@llvm-project//mlir:LLVMDialect" ,
870896 "@llvm-project//mlir:LinalgDialect" ,
@@ -944,8 +970,6 @@ cc_binary(
944970
945971exports_files (["run_lit.sh" ])
946972
947- # generate compilation commands for enzymemlir-opt
948- load ("@hedron_compile_commands//:refresh_compile_commands.bzl" , "refresh_compile_commands" )
949973refresh_compile_commands (
950974 name = "refresh_compile_commands" ,
951975 targets = [":enzymemlir-opt" ],
0 commit comments