Commit ae62feee authored by Julian Kranz's avatar Julian Kranz
Browse files

Liveness

parent 926c3265
......@@ -13,6 +13,8 @@ export =
# lvstate-pretty
# lv-sweep-and-collect-upto-native-flow
val print o = update@{nothing=(println o)}
val lv-kill kills stmt =
let
val visit-semvar kills sz x = fmap-add-range kills x.id sz x.offset
......@@ -223,7 +225,7 @@ val lv-analyze initial-live stack =
val sweep stack state =
case stack of
SEM_NIL: return state
| SEM_CONS x:
| SEM_CONS x: do print x.hd;
case x.hd of
# SEM_LABEL y:
# do lv-update-state y.label state;
......@@ -307,8 +309,12 @@ val lv-analyze initial-live stack =
lv-push-maybelive ite-conservative;
lv-push-live-only ite-greedy;
print "peter";
state-new <- return (lvstate-union then-state else-state);
print "hallo";
#sweep x.tl state-new
sweep x.tl (lv-eval-simple state-new x.hd)
end
......@@ -349,7 +355,7 @@ val lv-analyze initial-live stack =
in
cont (lv-kill1 x.hd) (lvstate-eval state x.hd)
end
end
end end
end
in do
# lv-sweep-and-collect-upto-native-flow;
......
......@@ -79,7 +79,7 @@ char elf_section_boundary_get(char *path, size_t *offset, size_t *size) {
}
int main(int argc, char** argv) {
const rlim_t kStackSize = 1024L * 1024L * 1024L;
const rlim_t kStackSize = 4096L * 1024L * 1024L;
struct rlimit rl;
int result;
......@@ -134,55 +134,72 @@ int main(int argc, char** argv) {
fclose(f);
if(buffer_length > size_max)
buffer_length = size_max;
__obj state = __createState(buffer, buffer_length, 0, 0);
__obj rreil_instructions = __runMonadicNoArg(__translateBlock__, &state);
if(!__isNil(rreil_instructions)) {
__fatal("TranslateBlock failed");
goto end;
if(buffer_length == buffer_size) {
buffer_size++;
buffer = (unsigned char*)realloc(buffer, buffer_size);
}
buffer[buffer_length++] = 0xc3; //Last instruction should be a jump (ret) ;-).
__obj greedy_state = __runMonadicOneArg(__liveness__, &state,
rreil_instructions);
if(!__isNil(greedy_state)) {
__fatal("Liveness failed");
goto end;
}
if(buffer_length > size_max)
buffer_length = size_max;
__obj rreil_instructions_greedy = __RECORD_SELECT(state, ___live);
if(!__isNil(rreil_instructions_greedy)) {
__fatal("Liveness failed (no greedy instructions)");
goto end;
}
printf("Liveness greedy state:\n");
__pretty(__lv_pretty__, greedy_state, fmt, size);
puts(fmt);
printf("\n");
size_t lines = 0;
size_t lines_greedy = 0;
printf("Initial RREIL instructions:\n");
__pretty(__rreil_pretty__, rreil_instructions, fmt, size);
puts(fmt);
printf("\n");
uint64_t consumed = 0;
while(consumed < buffer_length) {
__obj state = __createState(buffer + consumed, buffer_length - consumed, 0, 0);
size_t lines = 0;
for(size_t i = 0; fmt[i]; i++)
if(fmt[i] == '\n')
lines++;
__obj rreil_instructions = __runMonadicNoArg(__translateBlock__, &state);
if(!__isNil(rreil_instructions)) {
__fatal("TranslateBlock failed");
goto end;
}
printf("RREIL instructions after LV (greedy):\n");
__pretty(__rreil_pretty__, rreil_instructions_greedy, fmt, size);
puts(fmt);
printf("\n");
printf("%x\n", buffer[consumed]);
printf("Initial RREIL instructions:\n");
__pretty(__rreil_pretty__, rreil_instructions, fmt, size);
puts(fmt);
printf("\n");
__obj greedy_state = __runMonadicOneArg(__liveness__, &state,
rreil_instructions);
if(!__isNil(greedy_state)) {
__fatal("Liveness failed");
goto end;
}
size_t lines_greedy = 0;
for(size_t i = 0; fmt[i]; i++)
if(fmt[i] == '\n')
lines_greedy++;
__obj rreil_instructions_greedy = __RECORD_SELECT(state, ___live);
if(!__isNil(rreil_instructions_greedy)) {
__fatal("Liveness failed (no greedy instructions)");
goto end;
}
printf("Liveness greedy state:\n");
__pretty(__lv_pretty__, greedy_state, fmt, size);
puts(fmt);
printf("\n");
for(size_t i = 0; fmt[i]; i++)
if(fmt[i] == '\n')
lines++;
printf("RREIL instructions after LV (greedy):\n");
__pretty(__rreil_pretty__, rreil_instructions_greedy, fmt, size);
puts(fmt);
printf("\n");
for(size_t i = 0; fmt[i]; i++)
if(fmt[i] == '\n')
lines_greedy++;
consumed += __getBlobIndex(state);
printf("consumed: %lu\n", consumed);
}
printf("Statistics:\n");
printf("Number of lines without LV analysis: %zu\n", lines);
......@@ -192,7 +209,8 @@ int main(int argc, char** argv) {
printf("Reduction: %lf%%\n", 100 * reduction);
end: free(buffer);
end:
free(buffer);
free(fmt);
return (1);
......
......@@ -2096,7 +2096,7 @@ val sem-rep-insn x sem =
else
sem x
val sem-ret x =
val sem-ret x = do
case x of
VA0 x:
do
......@@ -2109,9 +2109,11 @@ val sem-ret x =
release-from-stack x;
ret address
end
end
end;
update @{foundJump='1'}
end
val sem-ret-far x =
val sem-ret-far x = do
case x of
VA0 x:
do
......@@ -2124,7 +2126,9 @@ val sem-ret-far x =
release-from-stack x;
ret address
end
end
end;
update @{foundJump='1'}
end
val pop-ip opnd-sz = do
ip-sz <-
......
......@@ -2200,7 +2200,8 @@ val transBlock = do
transInstr;
jmp <- query $foundJump;
ic <- query $ins_count;
if jmp or ic>1000 then query $stack else transBlock
#if jmp or ic>1000 then query $stack else transBlock
if jmp then query $stack else transBlock
end
val translateBlock = do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment