Skip to content

Commit 362500d

Browse files
authored
Replace (unsafe_)delete! with remove!/erase!, closer to upstream. (#467)
These functions also don't have to take a `parent` argument, as `Base.delete!` does, making them more general (e.g., to erase unlinked instructions or blocks).
1 parent 2be779e commit 362500d

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

src/core/basicblock.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export BasicBlock, unsafe_delete!,
1+
export BasicBlock, remove!, erase!,
22
terminator, name,
33
move_before, move_after
44

@@ -20,9 +20,8 @@ BasicBlock(f::Function, name::String;) =
2020
BasicBlock(bb::BasicBlock, name::String) =
2121
BasicBlock(API.LLVMInsertBasicBlockInContext(context(bb), bb, name))
2222

23-
unsafe_delete!(::Function, bb::BasicBlock) = API.LLVMDeleteBasicBlock(bb)
24-
Base.delete!(::Function, bb::BasicBlock) =
25-
API.LLVMRemoveBasicBlockFromParent(bb)
23+
remove!(bb::BasicBlock) = API.LLVMRemoveBasicBlockFromParent(bb)
24+
erase!(bb::BasicBlock) = API.LLVMDeleteBasicBlock(bb)
2625

2726
function parent(bb::BasicBlock)
2827
ref = API.LLVMGetBasicBlockParent(bb)

src/core/function.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export unsafe_delete!,
1+
export erase!,
22
personality, personality!,
33
callconv, callconv!,
44
gc, gc!,
@@ -14,7 +14,7 @@ function_type(Fn::Function) = FunctionType(API.LLVMGetFunctionType(Fn))
1414

1515
Base.empty!(f::Function) = API.LLVMFunctionDeleteBody(f)
1616

17-
unsafe_delete!(::Module, f::Function) = API.LLVMDeleteFunction(f)
17+
erase!(f::Function) = API.LLVMDeleteFunction(f)
1818

1919
function personality(f::Function)
2020
has_personality = API.LLVMHasPersonalityFn(f) |> Bool

src/core/instructions.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export Instruction, unsafe_delete!,
1+
export Instruction, remove!, erase!, parent,
22
opcode,
33
predicate_int, predicate_real
44

@@ -35,10 +35,8 @@ end
3535

3636
Base.copy(inst::Instruction) = Instruction(API.LLVMInstructionClone(inst))
3737

38-
unsafe_delete!(::BasicBlock, inst::Instruction) =
39-
API.LLVMInstructionEraseFromParent(inst)
40-
Base.delete!(::BasicBlock, inst::Instruction) =
41-
API.LLVMInstructionRemoveFromParent(inst)
38+
remove!(inst::Instruction) = API.LLVMInstructionRemoveFromParent(inst)
39+
erase!(inst::Instruction) = API.LLVMInstructionEraseFromParent(inst)
4240

4341
parent(inst::Instruction) =
4442
BasicBlock(API.LLVMGetInstructionParent(inst))

src/core/value/constant.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ alignment!(val::AlignedValue, bytes::Integer) = API.LLVMSetAlignment(val, bytes)
635635

636636
abstract type GlobalObject <: GlobalValue end
637637

638-
export GlobalVariable, unsafe_delete!,
638+
export GlobalVariable, erase!,
639639
initializer, initializer!,
640640
isthreadlocal, threadlocal!,
641641
threadlocalmode, threadlocalmode!,
@@ -654,7 +654,7 @@ GlobalVariable(mod::Module, typ::LLVMType, name::String, addrspace::Integer) =
654654
GlobalVariable(API.LLVMAddGlobalInAddressSpace(mod, typ,
655655
name, addrspace))
656656

657-
unsafe_delete!(::Module, gv::GlobalVariable) = API.LLVMDeleteGlobal(gv)
657+
erase!(gv::GlobalVariable) = API.LLVMDeleteGlobal(gv)
658658

659659
function initializer(gv::GlobalVariable)
660660
init = API.LLVMGetInitializer(gv)

src/deprecated.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ Base.@deprecate_binding ValueMetadataDict LLVM.InstructionMetadataDict
2828

2929
@deprecate Module(mod::Module) copy(mod) false
3030
@deprecate Instruction(inst::Instruction) copy(inst) false
31+
32+
@deprecate unsafe_delete!(::Module, gv::GlobalVariable) erase!(gv)
33+
@deprecate unsafe_delete!(::Module, f::Function) erase!(f)
34+
@deprecate unsafe_delete!(::Function, bb::BasicBlock) erase!(bb)
35+
@deprecate unsafe_delete!(::BasicBlock, inst::Instruction) erase!(inst)

test/core_tests.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -831,16 +831,16 @@ end
831831
@test !haskey(globals(mod), "llvm.used")
832832
set_used!(mod, gv)
833833
@test haskey(globals(mod), "llvm.used")
834-
unsafe_delete!(mod, globals(mod)["llvm.used"])
834+
erase!(globals(mod)["llvm.used"])
835835

836836
@test !haskey(globals(mod), "llvm.compiler.used")
837837
set_compiler_used!(mod, gv)
838838
@test haskey(globals(mod), "llvm.compiler.used")
839-
unsafe_delete!(mod, globals(mod)["llvm.compiler.used"])
839+
erase!(globals(mod)["llvm.compiler.used"])
840840

841841
let gvars = globals(mod)
842842
@test gv in gvars
843-
unsafe_delete!(mod, gv)
843+
erase!(gv)
844844
@test isempty(gvars)
845845
end
846846
end
@@ -1181,7 +1181,7 @@ end
11811181
@test personality(fn) == pers_fn
11821182
personality!(fn, nothing)
11831183
@test personality(fn) === nothing
1184-
unsafe_delete!(mod, pers_fn)
1184+
erase!(pers_fn)
11851185

11861186
@test !isintrinsic(fn)
11871187

@@ -1195,7 +1195,7 @@ end
11951195

11961196
let fns = functions(mod)
11971197
@test fn in fns
1198-
unsafe_delete!(mod, fn)
1198+
erase!(fn)
11991199
@test isempty(fns)
12001200
end
12011201
end
@@ -1417,7 +1417,7 @@ end
14171417
@test collect(insts) == [brinst]
14181418
end
14191419

1420-
unsafe_delete!(bb1, brinst) # we'll be deleting bb2, so remove uses of it
1420+
erase!(brinst) # we'll be deleting bb2, so remove uses of it
14211421

14221422
# basic block iteration
14231423
let bbs = blocks(fn)
@@ -1434,8 +1434,8 @@ end
14341434

14351435
@test bb1 in bbs
14361436
@test bb2 in bbs
1437-
delete!(fn, bb1)
1438-
unsafe_delete!(fn, bb2)
1437+
remove!(bb1)
1438+
erase!(bb2)
14391439
@test isempty(bbs)
14401440
end
14411441
end
@@ -1539,12 +1539,12 @@ end
15391539
end
15401540

15411541
@test retinst in instructions(bb3)
1542-
delete!(bb3, retinst)
1542+
remove!(retinst)
15431543
@test !(retinst in instructions(bb3))
15441544
@test opcode(retinst) == LLVM.API.LLVMRet # make sure retinst is still alive
15451545

15461546
@test brinst in instructions(bb1)
1547-
unsafe_delete!(bb1, brinst)
1547+
erase!(brinst)
15481548
@test !(brinst in instructions(bb1))
15491549
end
15501550

0 commit comments

Comments
 (0)