Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Porting to other architectures
Porting the Clang/LLVM compiler
We strive to implement Intel® Cilk™ Plus extensions for Clang/LLVM in a portable way. Most of our compiler changes should not depend on the underlining OS or architecture. In the following, we list some expected portablity changes in the compiler.
Save Cilk runtime state
To save Cilk runtime state, setjmp/longjmp are used and this is OS and architecture dependent. On Unix-like operating systems, this is done with __builtin_setjmp/longjmp. Detailed information can be found in the Intel® Cilk™ Plus ABI Specification. In Clang/LLVM, __builtin_setjmp/longjmp should be compatible with gcc's implementation, and so far this support has been implemented for the X86, and PowerPC backends. A similar patch may be needed for other backends.
The floating point state is required to be saved while spawning a function call. If __builtin_setjmp does not save the floating point state into the jump buffer, (registers mxcsr and fpcsr for x86), the compiler needs to save floating point state explicitly prior to the __builtin_setjmp call. In Clang, the following inline assembly is currently inserted, where sf is a pointer to __cilkrts_stack_frame struct:
__asm__ ( "stmxcsr %0\n\t" "fnstcw %1" : : "m" (sf->mxcsr), "m" (sf->fpcsr));
For other architectures, a corresponding inline assembly might be needed in the compiler, together with appropriate changes to the Cilk Plus runtime. For example, adjust the member fields of __cilkrts_stack_frame struct and port the runtime function __cilkrts_resume which restores the float pointing state with a corresponding inline assembly:
__asm__ ( "ldmxcsr %0\n\t" "fnclex\n\t" "fldcw %1" : : "m" (sf->mxcsr), "m" (sf->fpcsr));
This could be improved by introducing LLVM intrinsics to save and restore floating point states.
All Cilk-specific exception handling changes are architecture-neutral in the Clang compiler, which implements the Itanium ABI zero-cost exception handling. Porting work will be mainly inside the Cilk Plus runtime library.
Porting the Cilk Plus runtime library
A complete porting guide of the runtime is not available yet. The following is a brief summary from cilkplus.org.
While there is very little architecture-specific code, be aware that access to shared variables currently assumes sequential consistency. Architectures using a different memory model may require the insertion of additional memory barriers.
The runtime function __cilkrts_fence is a typical example to be ported.
The Cilk Plus runtime library shipped in compiler-rt only supports the Itanium C++ ABI, and porting to Windows OS would require additional effort. The exception handling is implemented in files runtime/except-gcc.h and runtime/except-gcc.cpp needs to be ported for other architectures.
Intel and Cilk are trademarks of Intel Corporation in the U.S. and/or other countries.