Skip to content

Commit e557a6a

Browse files
committed
Add a wrapper for llvm::Function's deleteBody.
1 parent c9492da commit e557a6a

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

deps/LLVMExtra/include/LLVMExtra.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,7 @@ void LLVMCloneFunctionInto(LLVMValueRef NewFunc, LLVMValueRef OldFunc,
131131
LLVMValueRef (*Materializer)(LLVMValueRef, void *),
132132
void *MaterializerData);
133133

134+
void LLVMFunctionDeleteBody(LLVMValueRef Func);
135+
134136
LLVM_C_EXTERN_C_END
135137
#endif

deps/LLVMExtra/lib/llvm-api.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,7 @@ void LLVMCloneFunctionInto(LLVMValueRef NewFunc, LLVMValueRef OldFunc,
414414
TypeMapper ? &TheTypeRemapper : nullptr,
415415
Materializer ? &TheMaterializer : nullptr);
416416
}
417+
418+
void LLVMFunctionDeleteBody(LLVMValueRef Func) {
419+
unwrap<Function>(Func)->deleteBody();
420+
}

lib/libLLVM_extra.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,7 @@ end
334334
function LLVMCloneFunctionInto(NewFunc, OldFunc, ValueMap, ValueMapElements, Changes, NameSuffix, TypeMapper, TypeMapperData, Materializer, MaterializerData)
335335
ccall((:LLVMCloneFunctionInto, libLLVMExtra), Cvoid, (LLVMValueRef, LLVMValueRef, Ptr{LLVMValueRef}, Cuint, LLVMCloneFunctionChangeType, Cstring, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), NewFunc, OldFunc, ValueMap, ValueMapElements, Changes, NameSuffix, TypeMapper, TypeMapperData, Materializer, MaterializerData)
336336
end
337+
338+
function LLVMFunctionDeleteBody(Func)
339+
ccall((:LLVMFunctionDeleteBody, libLLVMExtra), Cvoid, (LLVMValueRef,), Func)
340+
end

src/core/function.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ identify(::Type{Value}, ::Val{API.LLVMFunctionValueKind}) = Function
1010
Function(mod::Module, name::String, ft::FunctionType) =
1111
Function(API.LLVMAddFunction(mod, name, ft))
1212

13+
Base.empty!(f::Function) = API.LLVMFunctionDeleteBody(f)
14+
1315
unsafe_delete!(::Module, f::Function) = API.LLVMDeleteFunction(f)
1416

1517
function personality(f::Function)

test/core.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,9 @@ LLVM.Module("SomeModule"; ctx) do mod
10181018

10191019
@test collect(bbs) == [entrybb]
10201020
end
1021+
1022+
empty!(fn)
1023+
@test isempty(blocks(fn))
10211024
end
10221025
end
10231026

0 commit comments

Comments
 (0)