Hope d has great development in Raspberry Pi

Joakim via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Mon Feb 1 23:44:11 PST 2016


On Sunday, 31 January 2016 at 22:17:43 UTC, Dan Olson wrote:
> Dan Olson <gorox at comcast.net> writes:
>> Ironically, Fibers do work with optimize compile.  Something 
>> does wrong with -O0, some bad codegen in spots.
>>
>> Simple phobos hello world works, just make sure you give -O to 
>> enable optimizer.
>
> Picking away at LDC on arm-linux.
>
> I am assuming that very few folks are trying LDC with target 
> arm-unknown-linux-gnueabihf because LLVM really has a problem 
> with simple global variables (__gshared).  It is not LDC, but 
> LLVM.  The codegen to load a simple global variable is all 
> wrong with optimizer disabled (-O0).
>
> // load x into a register
>
> 	ldr	r0, .LCPI0_0
> 	ldr	r0, [r0]
> 	ldr	r0, [r0]        // what?! an extra load? SEGV!
>
> // elsewhere, x is defined as
> x:
> 	.long	0
> .LCPI0_0:
> 	.long	x
>
>
> Clang is ok at -O0.  But if I take clang IR output (-emit-llvm) 
> and generate code with llc -O0, it too has extra ldr 
> instruction.  Clang must be adding some optimization passes at 
> -O0 that are different than llc -O0.  I think LDC uses same 
> passes as llc, so there is the problem.

I tried it out a couple summers ago, following in your footsteps 
with iOS, and Kai and I ran into the same issue, though we didn't 
look into the codegen like you have:

http://forum.dlang.org/post/rdrhocrqfldcanrqxlgz@forum.dlang.org

I chipped away at it a little, but left it there as I wasn't 
particularly instructed in linux/ARM, only the much more popular 
Android/ARM.

> Next, see if LLVM has a bug filed for this and find that extra 
> optimization pass for LDC.

Llvm has a debug option for optimization passes that will dump 
all the info you could want about which passes are invoked and 
whether they actually modified the IR:

https://github.com/llvm-mirror/llvm/blob/55307987a11d765a4741d319f3ea19b6433263fd/lib/IR/LegacyPassManager.cpp#L51

I've found it invaluable when debugging how optimizations are 
messing up the ldc-generated IR, by passing 
--debug-pass=Executions to ldc (should work with clang too) and 
dumping the extensive output to a log file.  There are 2-3 places 
where optimization passes are called, which are demarcated in the 
log.  That helps separate passes invoked by the frontend from 
architecture-specific codegen passes.


More information about the digitalmars-d-ldc mailing list