start work on handling savedpc - experimental

pull/81/head
Dibyendu Majumdar 9 years ago
parent 564f64ea7a
commit d98520f2b2

@ -213,7 +213,7 @@ typedef void (*lua_Hook)(struct lua_State *L, struct lua_Debug *ar);
struct CallInfoL { /* only for Lua functions */
struct TValue *base; /* base for this function */
const unsigned int *savedpc;
unsigned int *savedpc;
ptrdiff_t dummy;
};

@ -4,7 +4,7 @@ extern int printf(const char *, ...);
void testfunc(struct GCObject *obj) { printf("value = %d\n", obj->tt); }
extern int luaD_poscall(struct lua_State *L, struct TValue *ra, int n);
extern void luaF_close(struct lua_State *L, struct TValue *base);
extern void test1(struct lua_State *L, int b);
extern void test1(struct lua_State *L, int b, unsigned int x);
/*
The following represents a C version of the Lua function:
@ -28,7 +28,7 @@ extern void test1(struct lua_State *L, int b);
upvalues (0) for 00000033C3366630:
*/
void test1(struct lua_State *L, int b) {
void test1(struct lua_State *L, int b, unsigned int x) {
/* This is the function prologue */
struct CallInfoLua *ci;
@ -39,6 +39,8 @@ void test1(struct lua_State *L, int b) {
ci = L->ci;
base = ci->l.base;
ci->l.savedpc = &x;
#if 0
cl = (struct LClosure *)(ci->func->value_.gc);
k = cl->p->k;
@ -62,4 +64,5 @@ void test1(struct lua_State *L, int b) {
b = luaD_poscall(L, ra3, n);
if (b)
L->top = ci->top;
#endif
}

@ -42,23 +42,19 @@ entry:
declare i32 @printf(i8*, ...) #1
; Function Attrs: nounwind
define void @test1(%struct.lua_State* %L, i32 %b) #0 {
define void @test1(%struct.lua_State* %L, i32 %b, i32 %x) #0 {
entry:
%L.addr = alloca %struct.lua_State*, align 4
%b.addr = alloca i32, align 4
%x.addr = alloca i32, align 4
%ci = alloca %struct.CallInfoLua*, align 4
%cl = alloca %struct.LClosure*, align 4
%k = alloca %struct.TValue*, align 4
%base = alloca %struct.TValue*, align 4
%cil = alloca %struct.CallInfoL*, align 4
%ra = alloca %struct.TValue*, align 4
%rb = alloca %struct.TValue*, align 4
%ra2 = alloca %struct.TValue*, align 4
%rb2 = alloca %struct.TValue*, align 4
%ra3 = alloca %struct.TValue*, align 4
%n = alloca i32, align 4
store %struct.lua_State* %L, %struct.lua_State** %L.addr, align 4, !tbaa !1
store i32 %b, i32* %b.addr, align 4, !tbaa !7
store i32 %x, i32* %x.addr, align 4, !tbaa !7
%0 = bitcast %struct.CallInfoLua** %ci to i8*
call void @llvm.lifetime.start(i64 4, i8* %0) #2
%1 = bitcast %struct.LClosure** %cl to i8*
@ -79,148 +75,25 @@ entry:
%8 = load %struct.TValue*, %struct.TValue** %base2, align 4, !tbaa !14
store %struct.TValue* %8, %struct.TValue** %base, align 4, !tbaa !1
%9 = load %struct.CallInfoLua*, %struct.CallInfoLua** %ci, align 4, !tbaa !1
%func = getelementptr inbounds %struct.CallInfoLua, %struct.CallInfoLua* %9, i32 0, i32 0
%10 = load %struct.TValue*, %struct.TValue** %func, align 4, !tbaa !17
%value_ = getelementptr inbounds %struct.TValue, %struct.TValue* %10, i32 0, i32 0
%gc = bitcast %union.Value* %value_ to %struct.GCObject**
%11 = load %struct.GCObject*, %struct.GCObject** %gc, align 4, !tbaa !1
%12 = bitcast %struct.GCObject* %11 to %struct.LClosure*
store %struct.LClosure* %12, %struct.LClosure** %cl, align 4, !tbaa !1
%13 = load %struct.LClosure*, %struct.LClosure** %cl, align 4, !tbaa !1
%p = getelementptr inbounds %struct.LClosure, %struct.LClosure* %13, i32 0, i32 5
%14 = load %struct.Proto*, %struct.Proto** %p, align 4, !tbaa !18
%k3 = getelementptr inbounds %struct.Proto, %struct.Proto* %14, i32 0, i32 14
%15 = load %struct.TValue*, %struct.TValue** %k3, align 4, !tbaa !20
store %struct.TValue* %15, %struct.TValue** %k, align 4, !tbaa !1
%16 = bitcast %struct.TValue** %ra to i8*
call void @llvm.lifetime.start(i64 4, i8* %16) #2
%17 = load %struct.TValue*, %struct.TValue** %base, align 4, !tbaa !1
%add.ptr = getelementptr inbounds %struct.TValue, %struct.TValue* %17, i32 0
store %struct.TValue* %add.ptr, %struct.TValue** %ra, align 4, !tbaa !1
%18 = bitcast %struct.TValue** %rb to i8*
call void @llvm.lifetime.start(i64 4, i8* %18) #2
%19 = load %struct.TValue*, %struct.TValue** %k, align 4, !tbaa !1
%add.ptr4 = getelementptr inbounds %struct.TValue, %struct.TValue* %19, i32 0
store %struct.TValue* %add.ptr4, %struct.TValue** %rb, align 4, !tbaa !1
%20 = load %struct.TValue*, %struct.TValue** %ra, align 4, !tbaa !1
%21 = load %struct.TValue*, %struct.TValue** %rb, align 4, !tbaa !1
%22 = bitcast %struct.TValue* %20 to i8*
%23 = bitcast %struct.TValue* %21 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %22, i8* %23, i32 16, i32 8, i1 false), !tbaa.struct !23
%24 = bitcast %struct.TValue** %ra2 to i8*
call void @llvm.lifetime.start(i64 4, i8* %24) #2
%25 = load %struct.TValue*, %struct.TValue** %base, align 4, !tbaa !1
%add.ptr5 = getelementptr inbounds %struct.TValue, %struct.TValue* %25, i32 1
store %struct.TValue* %add.ptr5, %struct.TValue** %ra2, align 4, !tbaa !1
%26 = bitcast %struct.TValue** %rb2 to i8*
call void @llvm.lifetime.start(i64 4, i8* %26) #2
%27 = load %struct.TValue*, %struct.TValue** %k, align 4, !tbaa !1
%add.ptr6 = getelementptr inbounds %struct.TValue, %struct.TValue* %27, i32 1
store %struct.TValue* %add.ptr6, %struct.TValue** %rb2, align 4, !tbaa !1
%28 = load %struct.TValue*, %struct.TValue** %ra2, align 4, !tbaa !1
%29 = load %struct.TValue*, %struct.TValue** %rb2, align 4, !tbaa !1
%30 = bitcast %struct.TValue* %28 to i8*
%31 = bitcast %struct.TValue* %29 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %30, i8* %31, i32 16, i32 8, i1 false), !tbaa.struct !23
%32 = bitcast %struct.TValue** %ra3 to i8*
call void @llvm.lifetime.start(i64 4, i8* %32) #2
%33 = load %struct.TValue*, %struct.TValue** %base, align 4, !tbaa !1
%add.ptr7 = getelementptr inbounds %struct.TValue, %struct.TValue* %33, i32 0
store %struct.TValue* %add.ptr7, %struct.TValue** %ra3, align 4, !tbaa !1
%34 = load %struct.LClosure*, %struct.LClosure** %cl, align 4, !tbaa !1
%p8 = getelementptr inbounds %struct.LClosure, %struct.LClosure* %34, i32 0, i32 5
%35 = load %struct.Proto*, %struct.Proto** %p8, align 4, !tbaa !18
%sizep = getelementptr inbounds %struct.Proto, %struct.Proto* %35, i32 0, i32 10
%36 = load i32, i32* %sizep, align 4, !tbaa !27
%cmp = icmp sgt i32 %36, 0
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
%37 = load %struct.lua_State*, %struct.lua_State** %L.addr, align 4, !tbaa !1
%38 = load %struct.TValue*, %struct.TValue** %base, align 4, !tbaa !1
call void @luaF_close(%struct.lua_State* %37, %struct.TValue* %38)
br label %if.end
if.end: ; preds = %if.then, %entry
%39 = bitcast i32* %n to i8*
call void @llvm.lifetime.start(i64 4, i8* %39) #2
%40 = load i32, i32* %b.addr, align 4, !tbaa !7
%cmp9 = icmp ne i32 %40, 0
br i1 %cmp9, label %cond.true, label %cond.false
cond.true: ; preds = %if.end
%41 = load i32, i32* %b.addr, align 4, !tbaa !7
%sub = sub nsw i32 %41, 1
br label %cond.end
cond.false: ; preds = %if.end
%42 = load %struct.lua_State*, %struct.lua_State** %L.addr, align 4, !tbaa !1
%top = getelementptr inbounds %struct.lua_State, %struct.lua_State* %42, i32 0, i32 4
%43 = load %struct.TValue*, %struct.TValue** %top, align 4, !tbaa !28
%44 = load %struct.TValue*, %struct.TValue** %ra, align 4, !tbaa !1
%sub.ptr.lhs.cast = ptrtoint %struct.TValue* %43 to i32
%sub.ptr.rhs.cast = ptrtoint %struct.TValue* %44 to i32
%sub.ptr.sub = sub i32 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
%sub.ptr.div = sdiv exact i32 %sub.ptr.sub, 16
br label %cond.end
cond.end: ; preds = %cond.false, %cond.true
%cond = phi i32 [ %sub, %cond.true ], [ %sub.ptr.div, %cond.false ]
store i32 %cond, i32* %n, align 4, !tbaa !7
%45 = load %struct.lua_State*, %struct.lua_State** %L.addr, align 4, !tbaa !1
%46 = load %struct.TValue*, %struct.TValue** %ra3, align 4, !tbaa !1
%47 = load i32, i32* %n, align 4, !tbaa !7
%call = call i32 @luaD_poscall(%struct.lua_State* %45, %struct.TValue* %46, i32 %47)
store i32 %call, i32* %b.addr, align 4, !tbaa !7
%48 = load i32, i32* %b.addr, align 4, !tbaa !7
%tobool = icmp ne i32 %48, 0
br i1 %tobool, label %if.then10, label %if.end13
if.then10: ; preds = %cond.end
%49 = load %struct.CallInfoLua*, %struct.CallInfoLua** %ci, align 4, !tbaa !1
%top11 = getelementptr inbounds %struct.CallInfoLua, %struct.CallInfoLua* %49, i32 0, i32 1
%50 = load %struct.TValue*, %struct.TValue** %top11, align 4, !tbaa !29
%51 = load %struct.lua_State*, %struct.lua_State** %L.addr, align 4, !tbaa !1
%top12 = getelementptr inbounds %struct.lua_State, %struct.lua_State* %51, i32 0, i32 4
store %struct.TValue* %50, %struct.TValue** %top12, align 4, !tbaa !28
br label %if.end13
if.end13: ; preds = %if.then10, %cond.end
%52 = bitcast i32* %n to i8*
call void @llvm.lifetime.end(i64 4, i8* %52) #2
%53 = bitcast %struct.TValue** %ra3 to i8*
call void @llvm.lifetime.end(i64 4, i8* %53) #2
%54 = bitcast %struct.TValue** %rb2 to i8*
call void @llvm.lifetime.end(i64 4, i8* %54) #2
%55 = bitcast %struct.TValue** %ra2 to i8*
call void @llvm.lifetime.end(i64 4, i8* %55) #2
%56 = bitcast %struct.TValue** %rb to i8*
call void @llvm.lifetime.end(i64 4, i8* %56) #2
%57 = bitcast %struct.TValue** %ra to i8*
call void @llvm.lifetime.end(i64 4, i8* %57) #2
%58 = bitcast %struct.CallInfoL** %cil to i8*
call void @llvm.lifetime.end(i64 4, i8* %58) #2
%59 = bitcast %struct.TValue** %base to i8*
call void @llvm.lifetime.end(i64 4, i8* %59) #2
%60 = bitcast %struct.TValue** %k to i8*
call void @llvm.lifetime.end(i64 4, i8* %60) #2
%61 = bitcast %struct.LClosure** %cl to i8*
call void @llvm.lifetime.end(i64 4, i8* %61) #2
%62 = bitcast %struct.CallInfoLua** %ci to i8*
call void @llvm.lifetime.end(i64 4, i8* %62) #2
%l3 = getelementptr inbounds %struct.CallInfoLua, %struct.CallInfoLua* %9, i32 0, i32 4
%savedpc = getelementptr inbounds %struct.CallInfoL, %struct.CallInfoL* %l3, i32 0, i32 1
store i32* %x.addr, i32** %savedpc, align 4, !tbaa !17
%10 = bitcast %struct.CallInfoL** %cil to i8*
call void @llvm.lifetime.end(i64 4, i8* %10) #2
%11 = bitcast %struct.TValue** %base to i8*
call void @llvm.lifetime.end(i64 4, i8* %11) #2
%12 = bitcast %struct.TValue** %k to i8*
call void @llvm.lifetime.end(i64 4, i8* %12) #2
%13 = bitcast %struct.LClosure** %cl to i8*
call void @llvm.lifetime.end(i64 4, i8* %13) #2
%14 = bitcast %struct.CallInfoLua** %ci to i8*
call void @llvm.lifetime.end(i64 4, i8* %14) #2
ret void
}
; Function Attrs: nounwind
declare void @llvm.lifetime.start(i64, i8* nocapture) #2
; Function Attrs: nounwind
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i32, i1) #2
declare void @luaF_close(%struct.lua_State*, %struct.TValue*) #1
declare i32 @luaD_poscall(%struct.lua_State*, %struct.TValue*, i32) #1
; Function Attrs: nounwind
declare void @llvm.lifetime.end(i64, i8* nocapture) #2
@ -247,16 +120,4 @@ attributes #2 = { nounwind }
!14 = !{!15, !2, i64 16}
!15 = !{!"CallInfoLua", !2, i64 0, !2, i64 4, !2, i64 8, !2, i64 12, !16, i64 16, !12, i64 32, !13, i64 40, !3, i64 42, !3, i64 43}
!16 = !{!"CallInfoL", !2, i64 0, !2, i64 4, !12, i64 8}
!17 = !{!15, !2, i64 0}
!18 = !{!19, !2, i64 12}
!19 = !{!"LClosure", !2, i64 0, !3, i64 4, !3, i64 5, !3, i64 6, !2, i64 8, !2, i64 12, !3, i64 16}
!20 = !{!21, !2, i64 44}
!21 = !{!"Proto", !2, i64 0, !3, i64 4, !3, i64 5, !3, i64 6, !3, i64 7, !3, i64 8, !8, i64 12, !8, i64 16, !8, i64 20, !8, i64 24, !8, i64 28, !8, i64 32, !8, i64 36, !8, i64 40, !2, i64 44, !2, i64 48, !2, i64 52, !2, i64 56, !2, i64 60, !2, i64 64, !2, i64 68, !2, i64 72, !2, i64 76, !22, i64 80}
!22 = !{!"RaviJITProto", !3, i64 0, !2, i64 4, !2, i64 8}
!23 = !{i64 0, i64 4, !1, i64 0, i64 4, !1, i64 0, i64 4, !7, i64 0, i64 4, !1, i64 0, i64 8, !24, i64 0, i64 8, !25, i64 8, i64 4, !7}
!24 = !{!12, !12, i64 0}
!25 = !{!26, !26, i64 0}
!26 = !{!"double", !3, i64 0}
!27 = !{!21, !8, i64 28}
!28 = !{!10, !2, i64 8}
!29 = !{!15, !2, i64 4}
!17 = !{!15, !2, i64 20}

@ -289,12 +289,14 @@ struct LuaLLVMTypes {
llvm::MDNode *tbaa_CallInfo_topT;
llvm::MDNode *tbaa_CallInfo_jitstatusT;
llvm::MDNode *tbaa_CallInfo_callstatusT;
llvm::MDNode *tbaa_CallInfo_savedpcT;
llvm::MDNode *tbaa_LClosureT;
llvm::MDNode *tbaa_LClosure_pT;
llvm::MDNode *tbaa_LClosure_upvalsT;
llvm::MDNode *tbaa_ProtoT;
llvm::MDNode *tbaa_Proto_kT;
llvm::MDNode *tbaa_Proto_sizepT;
llvm::MDNode *tbaa_Proto_codeT;
llvm::MDNode *tbaa_TValueT;
llvm::MDNode *tbaa_TValue_nT;
llvm::MDNode *tbaa_TValue_hT;
@ -446,9 +448,7 @@ public:
min_exec_count_ = value > 0 ? value : min_exec_count_;
}
int get_gcstep() const { return gc_step_; }
void set_gcstep(int value) {
gc_step_ = value > 0 ? value : gc_step_;
}
void set_gcstep(int value) { gc_step_ = value > 0 ? value : gc_step_; }
};
// To optimise fornum loops

@ -1029,6 +1029,8 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
mdbuilder.createTBAAStructTagNode(tbaa_pointerT, tbaa_pointerT, 0);
tbaa_CallInfo_topT =
mdbuilder.createTBAAStructTagNode(tbaa_CallInfoT, tbaa_pointerT, 4);
tbaa_CallInfo_savedpcT =
mdbuilder.createTBAAStructTagNode(tbaa_CallInfoT, tbaa_pointerT, 20);
tbaa_CallInfo_callstatusT =
mdbuilder.createTBAAStructTagNode(tbaa_CallInfoT, tbaa_charT, 42);
tbaa_CallInfo_jitstatusT =
@ -1118,6 +1120,8 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
mdbuilder.createTBAAStructTagNode(tbaa_ProtoT, tbaa_pointerT, 44);
tbaa_Proto_sizepT =
mdbuilder.createTBAAStructTagNode(tbaa_ProtoT, tbaa_intT, 28);
tbaa_Proto_codeT =
mdbuilder.createTBAAStructTagNode(tbaa_ProtoT, tbaa_pointerT, 48);
nodes.clear();
nodes.push_back(std::pair<llvm::MDNode *, uint64_t>(tbaa_longlongT, 0));

Loading…
Cancel
Save