February 10, 2014
"Kai Nacke" <kai@redstar.de> writes:

> Hi Dan!
>
> On Wednesday, 5 February 2014 at 07:32:05 UTC, Dan Olson wrote:
>>
>> The todo list will look something like:

>> - figure out ldc codegen assertion errors for armv7/thumbv7 so can
>> ditch
>>    the ldc/llc 2-phase approach.
>>
>
> And if you still encounter ldc crashes, please report them. Even if I can't help on iOS right know I still can make sure that you have a stable environment.

I discovered the ldc (llvm codegen assertion failures) happen when float abi is soft for triples armv7-apple-darwin or thumbv7-apple-darwin.

Thumb defaults to soft, and iOS likes thumb, so by overriding with -float-abi=softfp, I am avoiding the ldc -> IR -> llc -> obj 2-phase approach and using ldc all the way to build phobos.

Works
../buildldc/bin/ldc2 -c ../ldc-git/runtime/druntime/src/core/demangle.d -mtriple=thumbv7-apple-darwin -float-abi=softfp -O

Fails
../buildldc/bin/ldc2 -c ../ldc-git/runtime/druntime/src/core/demangle.d -mtriple=thumbv7-apple-darwin -O

Assertion failed: ((TLI.getTypeAction(*DAG.getContext(), Node->getOperand(i).getValueType()) == TargetLowering::TypeLegal || Node->getOperand(i).getOpcode() == ISD::TargetConstant) && "Unexpected illegal type!"), function LegalizeOp, file /Users/dan/projects/ldc/llvm-svn/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp, line 1165.

These fail in same way:
-mtriple=armv7-apple-darwin -float-abi=soft
-mtriple=armv7-unknown-linux-gnueabi -float-abi=soft
-mtriple=thumbv7-unknown-linux-gnueabi

It has something to do with TargetOptions UseSoftFloat = 1.

I can file an issue if you like.  Perhaps it is an llvm bug though.
-- 
Dan
February 10, 2014
On 5 Feb 2014, at 8:32, Dan Olson wrote:
> Success building phobos this way and was able to writeln() to the Xcode
> console from iPhone 4.  Again, druntime rt_init() and D functions are
> called by the iOS app's C main (not using dmain2 main).

Coming back after a while and reading about that kind of progress while going through the mail inbox backlog is awesome!

Regarding the assertion failures when emitting object code from within LDC, I'd use a debug build and GDB to figure out to try and figure out what could be the cause of the problem, and then compare the pass list (-debug-pass=…) and TargetOptions between llc and LDC (assuming that you already checked the obvious things, such as the target CPUs selected being the same, …).

David
February 12, 2014
On Mon, Feb 10, 2014 at 5:39 PM, Dan Olson <zans.is.for.cans@yahoo.com> wrote> Works
> ../buildldc/bin/ldc2 -c ../ldc-git/runtime/druntime/src/core/demangle.d -mtriple=thumbv7-apple-darwin -float-abi=softfp -O
>
> Fails
> ../buildldc/bin/ldc2 -c ../ldc-git/runtime/druntime/src/core/demangle.d -mtriple=thumbv7-apple-darwin -O
>
> […]
>
> It has something to do with TargetOptions UseSoftFloat = 1.
>
> I can file an issue if you like.  Perhaps it is an llvm bug though.

Ah, yes, that's not really surprising. Unimplemented floating point lowerings tend to be responsible for a good share of strange error messages when targeting non-x86 platforms with LLVM, in my experience.

The decision whether to use "soft", "softfp" or "hard" by default is
(unfortunately) made in the LDC driver code, based on the target
triple: https://github.com/ldc-developers/ldc/blob/master/driver/targetmachine.cpp.
The logic is supposed to mirror what Clang does, but maybe I missed
something. I'd definitely double-check the behavior against Clang,
although this should really be moved into an LLVM support library –
every flexible ARM compiler is going to need something similar.

Another potential cause is that "thumbv7-apple-darwin" might not be the right target triple for iOS (thus leading to hardware floating point support being incorrectly disabled), but I'd have to reboot into OS X to check right now.

Best,
David

February 12, 2014
David Nadlinger <code@klickverbot.at> writes:

> On Mon, Feb 10, 2014 at 5:39 PM, Dan Olson <zans.is.for.cans@yahoo.com> wrote> Works
>> ../buildldc/bin/ldc2 -c ../ldc-git/runtime/druntime/src/core/demangle.d -mtriple=thumbv7-apple-darwin -float-abi=softfp -O
>>
>> Fails
>> ../buildldc/bin/ldc2 -c ../ldc-git/runtime/druntime/src/core/demangle.d -mtriple=thumbv7-apple-darwin -O
>>
>> […]
>>
>> It has something to do with TargetOptions UseSoftFloat = 1.
>>
>> I can file an issue if you like.  Perhaps it is an llvm bug though.
>
> Ah, yes, that's not really surprising. Unimplemented floating point lowerings tend to be responsible for a good share of strange error messages when targeting non-x86 platforms with LLVM, in my experience.
>
> The decision whether to use "soft", "softfp" or "hard" by default is
> (unfortunately) made in the LDC driver code, based on the target
> triple: https://github.com/ldc-developers/ldc/blob/master/driver/targetmachine.cpp.
> The logic is supposed to mirror what Clang does, but maybe I missed
> something. I'd definitely double-check the behavior against Clang,
> although this should really be moved into an LLVM support library –
> every flexible ARM compiler is going to need something similar.
>
> Another potential cause is that "thumbv7-apple-darwin" might not be the right target triple for iOS (thus leading to hardware floating point support being incorrectly disabled), but I'd have to reboot into OS X to check right now.

Hi David,

Clang does a bunch of munging of the -target it is handed.  It seems very extensive for darwin targets with many special cases.  I discovered a couple weeks ago that clang converts -target armv7-apple-darwin into -triple thumbv7-apple-ios5.0.0.  I later found in an article that iOS prefers thumb2 to minimize code size.  So that is why I suppose armv7 is converted to thumbv7.  Anyway, I was curious just now so looked through clang/lib/Driver/ToolChains.pp and found Darwin::ComputeEffectiveClangTriple() is where the conversion is.

and

ToolChain::ComputeLLVMTriple()
    ...
    // Thumb2 is the default for V7 on Darwin.

elsewhere

tools::arm::getARMFloatABI()
   ...
      // Darwin defaults to "softfp" for v6 and v7.

For now I am just fine with having to tell ldc2 to use

-mtriple=thumbv7-apple-ios5.0.0 -float-abi=softfp

It works.

I am hoping to get changes up to an ldc github fork soon along with build instructions and some sample apps.  Being new to git/github, there is a bit for me to learn about best practices for forks and submodules. For example, my instinct would be to put any example apps, scripts, and notes in the forked repo, but looking at others forked repos, it seems like they don't do that.

P.S. I did have to add llvm::Triple::IOS to ldc main.cpp in the switch that sets D versions.  So far very few changes to ldc to get D breathing on iOS.
-- 
Dan
1 2 3 4 5 6 7
Next ›   Last »