Duan Bing via llvm-dev
2019-Apr-01 15:16 UTC
[llvm-dev] Instruction Execution With Hard Limitation at Runtime
I am trying to give a quota of how many instructions can be run to a program. So create a simple function as below: define void @add_gas(i64 %gasCost) { __virtual_entry: %0 = load i64, i64* @__WAVM__XX__gGasUsed ### I am sure it exists, same as the __WAVM__XX__gGasLimit %addtmp = add i64 %0, %gasCost %1 = load i64, i64* @__WAVM__XX__gGasLimit %cmptmp = icmp sgt i64 %addtmp, %1 br i1 %cmptmp, label %then, label %ifcont then: ; preds = %__virtual_entry call void @exit(i32 1024) ret void ifcont: ; preds = %__virtual_entry store i64 %addtmp, i64* @__WAVM__XX__gGasUsed ret void } ; Function Attrs: noreturn nounwind declare void @exit(i32) #2 Then, I insert this function into the beginning of each basic block the way as below: ... ifElse55: ; preds = %ifElseEnd53 call void @add_gas(i64 1) br label %ifElseEnd56 ifElseEnd56: ; preds = %ifElse55, %ifThen54 call void @add_gas(i64 2) %378 = load i32, i32* %11 br label %ifElseEnd41 ifElse40: ; preds = %blockEnd23 call void @add_gas(i64 2) %379 = load i32, i32* %11 br label %ifElseEnd41 ifElseEnd41: ; preds = %ifElse40, %ifElseEnd56 call void @add_gas(i64 2) %380 = phi i32 [ %378, %ifElseEnd56 ], [ %379, %ifElse40 ] br label %ifElseEnd3 ifElseEnd3: ; preds = %ifElseEnd41, %ifThen1 ... but, when I run my program by RuntimeDyld, I got an error: While deleting: i32 % Use still stuck around after Def is destroyed: %380 = phi i32 [ %40, %ifThen1 ], [ <badref>, %ifElseEnd41 ], !dbg !27 Assertion failed: (use_empty() && "Uses remain when a value is destroyed!"), function ~Value, file /Users/duanbing/Project/llvm/llvm/lib/IR/Value.cpp, line 90. Can you give me some tips about what's happened or how to debug this? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190401/73ac9225/attachment.html>
Tim Northover via llvm-dev
2019-Apr-01 16:27 UTC
[llvm-dev] Instruction Execution With Hard Limitation at Runtime
Hi Duan, On Mon, 1 Apr 2019 at 16:16, Duan Bing via llvm-dev <llvm-dev at lists.llvm.org> wrote:> ifElseEnd41: ; preds = %ifElse40, %ifElseEnd56 > call void @add_gas(i64 2) > %380 = phi i32 [ %378, %ifElseEnd56 ], [ %379, %ifElse40 ] > br label %ifElseEnd3 > > > Use still stuck around after Def is destroyed: %380 = phi i32 [ %40, %ifThen1 ], [ <badref>, %ifElseEnd41 ], !dbg !27 > Assertion failed: (use_empty() && "Uses remain when a value is destroyed!"), function ~Value, file /Users/duanbing/Project/llvm/llvm/lib/IR/Value.cpp, line 90. > > Can you give me some tips about what's happened or how to debug this?The issue is that phi instructions must always be at the start of their basic block (see https://llvm.org/docs/LangRef.html#i-phi). You can use BasicBlock::getFirstNonPHI to get the correct insertion point for your call. Cheers. Tim.
Duan Bing via llvm-dev
2019-Apr-02 00:40 UTC
[llvm-dev] Instruction Execution With Hard Limitation at Runtime
Got it, thanks! Tim Northover <t.p.northover at gmail.com> 于2019年4月2日周二 上午12:27写道:> Hi Duan, > > On Mon, 1 Apr 2019 at 16:16, Duan Bing via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > ifElseEnd41: ; preds = %ifElse40, > %ifElseEnd56 > > call void @add_gas(i64 2) > > %380 = phi i32 [ %378, %ifElseEnd56 ], [ %379, %ifElse40 ] > > br label %ifElseEnd3 > > > > > > Use still stuck around after Def is destroyed: %380 = phi i32 [ %40, > %ifThen1 ], [ <badref>, %ifElseEnd41 ], !dbg !27 > > Assertion failed: (use_empty() && "Uses remain when a value is > destroyed!"), function ~Value, file > /Users/duanbing/Project/llvm/llvm/lib/IR/Value.cpp, line 90. > > > > Can you give me some tips about what's happened or how to debug this? > > The issue is that phi instructions must always be at the start of > their basic block (see https://llvm.org/docs/LangRef.html#i-phi). You > can use BasicBlock::getFirstNonPHI to get the correct insertion point > for your call. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190402/680ecbd1/attachment.html>