Target Environment - Cross-compilation

David Clarke dawclarke at
Thu Jan 19 23:55:40 UTC 2017

Good People,

I am researching using Graal to host code that optimises the implementation of memory fences.

On x86 architectures, the CompareAndSet functionality is implemented with lock:xchg.  Because of the way x86 works, the lock prefix is compulsory for shared variables so weakCompareAndSet has to be over-approximated by using lock:xchg.  On ARM, the LL/SC combination is a weakCompareAndSet so a CompareAndSet must be implemented with weakCompareAndSet followed by a fullFence.

So on x86 we want to optimise away a full fence that immediately follows a weakCompareAndSet and on ARM, we don’t.  This could be delayed until the code generation phase, but I would like to keep the optimisations at the IR or LIR level so that we retain the greatest generality for as long as possible and avoid repeating similar code in several distinct code generation phases.

So my questions are “How can the code within a Node find out the target environment?" and “Can we fiddle this so that the target environment is different from the actual host environment?”  I am interested in the prospect of cross-compilation so that I can defer the need to perform experimentation on multiple different platforms.

Can anyone point me to the relevant code/documentation/examples ?

Thank you for your indulgent assistance.

David (Knobby) CLARKE
6 Coptfold Court
Glen Waverley
VIC 3150
+61 408 793 793
dawclarke at

More information about the graal-dev mailing list