On Friday 30 January 2015 19:25:09 misu kun wrote:
> if you add inline to test function , fpc 3.1.1 will produce ~ the same
> assember
>
The difference is that LLVM knows that the procedure has no sideffects and 
that it is called with constant arguments -> it produces a constant result 
and can be replaced by a constant assignment. Another example:
"
program test1;
var
 gi1: int32;
 
function test(p1: int32): int32;
var
 i1: int32;
 pi1: ^int32;
begin
 pi1:= @i1;
 pi1^:= p1;
 result:= pi1^;
 exitcode:= result+2+gi1;
end;
 
begin
 gi1:= 123;
 gi1:= test(gi1);
 exitcode:= gi1;
end.
"

MSElang-LLVM:
"
   .file   "test-opt.ll"
   .text
   .globl   main
   .align   16, 0x90
   .type   main,@function
main:                                   # @main
# BB#0:
   movl   $123, __unnamed_1
   movl   $123, %eax
   ret
.Ltmp0:
   .size   main, .Ltmp0-main
 
   .type   __unnamed_1,@object     # @0
   .local   __unnamed_1
   .comm   __unnamed_1,4,4
 
   .section   ".note.GNU-stack","",@progbits
"

FPC:
"
[...]
.section .text
   .balign 16,0x90
.globl   P$TEST1_TEST$LONGINT$$LONGINT
   .type   P$TEST1_TEST$LONGINT$$LONGINT,@function
P$TEST1_TEST$LONGINT$$LONGINT:
# Temps allocated between esp+4 and esp+4
# [test1.pas]
# [9] begin
   subl   $4,%esp
# Var p1 located in register eax
# Var $result located in register eax
# Var pi1 located in register edx
# Var i1 located at esp+0
# [10] pi1:= @i1;
   movl   %esp,%edx
# [11] pi1^:= p1;
   movl   %eax,(%edx)
# [13] exitcode:= result+2+gi1;
   movl   %eax,%edx
   addl   $2,%edx
   movl   U_P$TEST1_GI1,%ecx
   addl   %ecx,%edx
   movl   %edx,operatingsystem_result
# [14] end;
   addl   $4,%esp
   ret
[...]
main:
# Temps allocated between esp+0 and esp+0
# [16] begin
   call   FPC_INITIALIZEUNITS
# [17] gi1:= 123;
   movl   $123,%eax
# [18] gi1:= test(gi1);
   movl   %eax,U_P$TEST1_GI1
   call   P$TEST1_TEST$LONGINT$$LONGINT
   movl   %eax,U_P$TEST1_GI1
# [19] exitcode:= gi1;
   movl   %eax,operatingsystem_result
# [20] end.
   call   FPC_DO_EXIT
   ret
[...]
"

Martin

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk

Reply via email to