Skip to content

Commit e9d303b

Browse files
authored
Remove julia level type rules (#2130)
1 parent 45f01bd commit e9d303b

File tree

5 files changed

+16
-264
lines changed

5 files changed

+16
-264
lines changed

src/api.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ function CreateTypeAnalysis(logic, rulenames, rules)
441441
EnzymeTypeAnalysisRef,
442442
(EnzymeLogicRef, Ptr{Cstring}, Ptr{CustomRuleType}, Csize_t),
443443
logic,
444-
rulenames,
445-
rules,
446-
length(rules),
444+
rulenames isa Tuple{} ? C_NULL : rulenames,
445+
rules isa Tuple{} ? C_NULL : rules,
446+
rulenames isa Tuple{} ? 0 : length(rules),
447447
)
448448
end
449449

src/compiler.jl

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3940,7 +3940,6 @@ function enzyme_extract_parm_type(fn::LLVM.Function, idx::Int, error::Bool = tru
39403940
return ty, byref
39413941
end
39423942

3943-
include("rules/typerules.jl")
39443943
include("rules/activityrules.jl")
39453944

39463945
@inline Base.convert(::Type{API.CDIFFE_TYPE}, ::Type{A}) where {A<:Const} = API.DFT_CONSTANT
@@ -4073,107 +4072,8 @@ function enzyme!(
40734072
convert(API.CDIFFE_TYPE, rt)
40744073
end
40754074

4076-
rules = Dict{String,API.CustomRuleType}(
4077-
"jl_array_copy" => @cfunction(
4078-
inout_rule,
4079-
UInt8,
4080-
(
4081-
Cint,
4082-
API.CTypeTreeRef,
4083-
Ptr{API.CTypeTreeRef},
4084-
Ptr{API.IntList},
4085-
Csize_t,
4086-
LLVM.API.LLVMValueRef,
4087-
)
4088-
),
4089-
"ijl_array_copy" => @cfunction(
4090-
inout_rule,
4091-
UInt8,
4092-
(
4093-
Cint,
4094-
API.CTypeTreeRef,
4095-
Ptr{API.CTypeTreeRef},
4096-
Ptr{API.IntList},
4097-
Csize_t,
4098-
LLVM.API.LLVMValueRef,
4099-
)
4100-
),
4101-
"jl_genericmemory_copy_slice" => @cfunction(
4102-
inoutcopyslice_rule,
4103-
UInt8,
4104-
(
4105-
Cint,
4106-
API.CTypeTreeRef,
4107-
Ptr{API.CTypeTreeRef},
4108-
Ptr{API.IntList},
4109-
Csize_t,
4110-
LLVM.API.LLVMValueRef,
4111-
)
4112-
),
4113-
"ijl_genericmemory_copy_slice" => @cfunction(
4114-
inoutcopyslice_rule,
4115-
UInt8,
4116-
(
4117-
Cint,
4118-
API.CTypeTreeRef,
4119-
Ptr{API.CTypeTreeRef},
4120-
Ptr{API.IntList},
4121-
Csize_t,
4122-
LLVM.API.LLVMValueRef,
4123-
)
4124-
),
4125-
"jl_inactive_inout" => @cfunction(
4126-
inout_rule,
4127-
UInt8,
4128-
(
4129-
Cint,
4130-
API.CTypeTreeRef,
4131-
Ptr{API.CTypeTreeRef},
4132-
Ptr{API.IntList},
4133-
Csize_t,
4134-
LLVM.API.LLVMValueRef,
4135-
)
4136-
),
4137-
"jl_excstack_state" => @cfunction(
4138-
int_return_rule,
4139-
UInt8,
4140-
(
4141-
Cint,
4142-
API.CTypeTreeRef,
4143-
Ptr{API.CTypeTreeRef},
4144-
Ptr{API.IntList},
4145-
Csize_t,
4146-
LLVM.API.LLVMValueRef,
4147-
)
4148-
),
4149-
"ijl_excstack_state" => @cfunction(
4150-
int_return_rule,
4151-
UInt8,
4152-
(
4153-
Cint,
4154-
API.CTypeTreeRef,
4155-
Ptr{API.CTypeTreeRef},
4156-
Ptr{API.IntList},
4157-
Csize_t,
4158-
LLVM.API.LLVMValueRef,
4159-
)
4160-
),
4161-
"julia.except_enter" => @cfunction(
4162-
int_return_rule,
4163-
UInt8,
4164-
(
4165-
Cint,
4166-
API.CTypeTreeRef,
4167-
Ptr{API.CTypeTreeRef},
4168-
Ptr{API.IntList},
4169-
Csize_t,
4170-
LLVM.API.LLVMValueRef,
4171-
)
4172-
),
4173-
)
4174-
41754075
logic = Logic()
4176-
TA = TypeAnalysis(logic, rules)
4076+
TA = TypeAnalysis(logic)
41774077

41784078
retTT = if !isa(actualRetType, Union) &&
41794079
actualRetType <: Tuple &&

src/rules/allocrules.jl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,6 @@ function array_shadow_handler(
8686
return ref
8787
end
8888

89-
function null_free_handler(
90-
B::LLVM.API.LLVMBuilderRef,
91-
ToFree::LLVM.API.LLVMValueRef,
92-
Fn::LLVM.API.LLVMValueRef,
93-
)::LLVM.API.LLVMValueRef
94-
return C_NULL
95-
end
96-
9789
function register_alloc_handler!(variants, alloc_handler, free_handler)
9890
for variant in variants
9991
API.EnzymeRegisterAllocationHandler(variant, alloc_handler, free_handler)
@@ -120,10 +112,6 @@ end
120112
API.EnzymeGradientUtilsRef,
121113
)
122114
),
123-
@cfunction(
124-
null_free_handler,
125-
LLVM.API.LLVMValueRef,
126-
(LLVM.API.LLVMBuilderRef, LLVM.API.LLVMValueRef, LLVM.API.LLVMValueRef)
127-
)
115+
C_NULL
128116
)
129117
end

src/rules/typerules.jl

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/typeanalysis.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ LLVM.dispose(ta::TypeAnalysis) = API.FreeTypeAnalysis(ta)
99

1010
function TypeAnalysis(
1111
logic,
12-
typerules::Dict{String,CustomRuleType} = Dict{String,CustomRuleType}(),
12+
typerules::Union{Dict{String,CustomRuleType}, Nothing} = nothing,
1313
)
14-
rulenames = String[]
15-
rules = CustomRuleType[]
16-
for (rulename, rule) in typerules
17-
push!(rulenames, rulename)
18-
push!(rules, rule)
14+
if typerules isa Nothing
15+
ref = API.CreateTypeAnalysis(logic, (), ())
16+
else
17+
rulenames = String[]
18+
rules = CustomRuleType[]
19+
for (rulename, rule) in typerules
20+
push!(rulenames, rulename)
21+
push!(rules, rule)
22+
end
23+
ref = API.CreateTypeAnalysis(logic, rulenames, rules)
1924
end
20-
ref = API.CreateTypeAnalysis(logic, rulenames, rules)
2125
TypeAnalysis(ref)
2226
end
2327

0 commit comments

Comments
 (0)