February 01, 2016
On Sunday, 31 January 2016 at 22:17:43 UTC, Dan Olson wrote:
>
> Next, see if LLVM has a bug filed for this and find that extra optimization pass for LDC.

If there is no bug report then it is easy to file one with the given information!

Regards,
Kai
February 02, 2016
On Sunday, 31 January 2016 at 22:17:43 UTC, Dan Olson wrote:
> Dan Olson <gorox@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.
February 02, 2016
On Thursday, 28 January 2016 at 16:15:59 UTC, Dan Olson wrote:
> Do you know how long does it take for Debian packages to be available for Raspbian?  The existing package has a useless ldc.
>
> Here is the current state of things.  I updated my Pi to Jessie, did apt-get ldc which gives:
>
> LDC - the LLVM D compiler (0.14.0):
>   based on DMD v2.065 and LLVM 3.5.0
>
> A simple hello world program ends in:
>
> _Unwind_RaiseException failed with reason code: -1090604416 Aborted
>
> Not too suprising with version 0.14.0.  There have been much exception handling improvements since then.

GDC is ok.

Frank
February 02, 2016
Joakim <dlang@joakim.fea.st> writes:
> 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 didn't realize the history.  That's a long time ago.  I never ran into this specific problem because it seems to be unique to gnueabi targets, and only -relocation-model=dynamic-no-pic (the default for arm-linux-gnueabih).

The problem is still in LLVM 3.8.

I also found using triple thumb-linux-gnueabihf sidesteps this problem. Trying thumb on Pi (armv6) was good because I discovered that druntime is missing thumb support (original, not thumb-2) and am preparing a PR.

I still think immediate solution for LDC is to see what clang is doing. We may have some wrong target options.
-- 
Dan
February 02, 2016
FrankLike <1150015857@qq.com> writes:
> GDC is ok.
>
> Frank

Yeah GDC is pretty solid with ARM targets and all sorts of others.  Time for LDC to catchup, at least for ARM!
February 04, 2016
On Tuesday, 2 February 2016 at 17:58:16 UTC, Dan Olson wrote:
> FrankLike <1150015857@qq.com> writes:
>> GDC is ok.
>>
>> Frank
>
> Yeah GDC is pretty solid with ARM targets and all sorts of others.  Time for LDC to catchup, at least for ARM!

http://gdcproject.org/downloads/binaries/5.2.0/arm-linux-gnueabihf/gdc-5.2.0+2.066.1.tar.xz

You can use it on Raspbian ,build your d codes ,it's ok.

Frank
February 04, 2016
On Thursday, 4 February 2016 at 14:14:05 UTC, FrankLike wrote:
> On Tuesday, 2 February 2016 at 17:58:16 UTC, Dan Olson wrote:
>> FrankLike <1150015857@qq.com> writes:
>>> GDC is ok.
>>>
>>> Frank
>>
>> Yeah GDC is pretty solid with ARM targets and all sorts of others.  Time for LDC to catchup, at least for ARM!
>
> http://gdcproject.org/downloads/binaries/5.2.0/arm-linux-gnueabihf/gdc-5.2.0+2.066.1.tar.xz
>
> You can use it on Raspbian ,build your d codes ,it's ok.

I doubt he has much D code, he just likes getting new targets up and running, :) like Kai.
February 05, 2016
Dan Olson <gorox@comcast.net> writes:

> Joakim <dlang@joakim.fea.st> writes:
>> 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 didn't realize the history.  That's a long time ago.  I never ran into this specific problem because it seems to be unique to gnueabi targets, and only -relocation-model=dynamic-no-pic (the default for arm-linux-gnueabih).
>
> The problem is still in LLVM 3.8.
>
> I also found using triple thumb-linux-gnueabihf sidesteps this problem. Trying thumb on Pi (armv6) was good because I discovered that druntime is missing thumb support (original, not thumb-2) and am preparing a PR.
>
> I still think immediate solution for LDC is to see what clang is doing. We may have some wrong target options.

Follow up: -relocation-model=dynamic-no-pic is all wrong.  Clang even emits an error if you try to use it on any other OS than darwin.

$ clang++ -target arm-linux-gnueabihf -S -c fun.cpp -O0 -mdynamic-no-pic
clang: error: unsupported option '-mdynamic-no-pic' for target 'arm--linux-gnueabihf'

The source is tools/clang/lib/Driver/Tools.cpp function ParsePICArgs():

  if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
    // This is a very special mode. It trumps the other modes, almost no one
    // uses it, and it isn't even valid on any OS but Darwin.
    if (!ToolChain.getTriple().isOSDarwin())
      ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
          << A->getSpelling() << ToolChain.getTriple().str();

There is a disconnect because llvm chooses dynamic-no-pic as default for all except darwin in lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp. That is really backwards.  At least there is an explanation and now a fix.
-- 
Dan
February 06, 2016
On 6 Feb 2016, at 8:01, Dan Olson via digitalmars-d-ldc wrote:
> There is a disconnect because llvm chooses dynamic-no-pic as default for
> all except darwin in lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp.
> That is really backwards.  At least there is an explanation and now a
> fix.

Ah, so that finally makes sense now (well, except that it doesn't). Thanks for the detective work!

 — David
March 11, 2016
On Friday, 22 January 2016 at 13:53:09 UTC, FrankLike wrote:
> D is very good,I like LDC,but it's not use on Raspberry Pi,I hope D will have a great development in Raspberry Pi.
> Now,I only work on GDC for  Raspberry Pi.
> Will you don't like LDC work on  Raspberry Pi?
>
> Thank you.

LDC build from ltsmaster branch can be used for development on Raspberry Pi boards. E.g. I currently develop a vibe.d application on an ARM based board with LDC.

Regards,
Kai