[cfe-dev] feasibility of C++ to inline-assembly using clang

David Tweed david.tweed at gmail.com
Sun Mar 14 20:57:02 PDT 2010


Hi, I'm trying to get a rough opinion of the difficulty of the
following task from knowledgeable people. (I'm a scientific programmer
who knows about SIMD instructions but none of the other vagaries of
x86 or compiler construction.)

For a complete (C-style) C++ function (which doesn't call any other
"not mandatory inline" functions, so this function is pure
preallocated memory access and computation) that takes just scalars
and pointers as arguments, I'd like to modify clang++ to compile the
function (in the context of approprate headers) to full machine code
and then output a gcc-style inline assembly snippet that can be pasted
in to replace the body of the function in the source. (I do mean
assembly because I want to keep the scheduling and register
allocation.) Presumably the main body of the actual code is not going
to be a problem (although I'm unclear about potential label uniqueness
issues), but presumably there's going to be a trick to figuring out
which clang function setup and clearup instructions are needed in the
new context. As a quick opinion, do experts think this is a relatively
small task for a compiler novice?

In case anyone asks "why do I want to do this strange thing?", I'm
looking at the feasibility of writing compute heavy code web-apps
using Google's NativeClient technology (in C++). This requires that
the final binary be compiled from source by the latest version of the
native client C++ compiler, which is a patched version of some
uncontrollable version of g++ (unless I want to try and manually port
the particular patches to a different g++ version). Unfortunately the
g++ optimizers/schedulers are oscillate from release to release for
very performance sensitive inner loops. Given that I'd still very much
prefer to write C++ rather than raw assembly for the "inner loop-y"
functions I'm looking at ways to separate the generation and
optimisation of this code from the need to be via the latest native
client compiler. (Clang/llvm seem to have a much better separation of
concerns than gcc, so I'd think it'd be easier for me to modify it to
output appropriate asm constructs than g++. )

Many thanks for any insight

-- 
cheers, dave tweed__________________________



More information about the cfe-dev mailing list