[llvm-dev] Instruction Execution With Hard Limitation at Runtime
Duan Bing via llvm-dev
llvm-dev at lists.llvm.org
Mon Apr 1 08:16:38 PDT 2019
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>
More information about the llvm-dev
mailing list