[LLVMdev] LLVM Newb: Getting started
Chris Lattner
sabre at nondot.org
Mon Nov 27 10:52:40 PST 2006
On Sat, 25 Nov 2006, Wolfgang Draxinger wrote:
> D itself is platform independent, but since D is also aimed at system
> programming it has an inline asembler. However one can supply
> different kinds of assembler through conditional comilation, so the
> following would be completely valid:
>
> void foo(){
> version(x86) {
> asm {
> /* x86 assembler */
> }
> } else version(llvm) {
> asm {
> /* llvm assembler */
> }
> } else {
> /* plain D implementation */
> }
> }
I would eventually like to support "codegen-time comparisons against the
target" in a more formal way. The most straight-forward way to do this is
to compile this into LLVM code like:
if (llvm.target.matches("x86"))
...
else if (llvm.target.matches("ppc"))
...
else
...
The "..." can use the standard LLVM inline asm facility as others have
mentioned and the 'plain D impl' can compile to plain llvm code. In order
to get the dynamic target checks working properly and efficiently, you'd
make an llvm intrinsic (e.g. "llvm.target.matches") and have that
intrinsic lowered to a constant by the code generator. Dead code elim
will delete the unreachable cases, so you'll get the right code for each
target.
-Chris
--
http://nondot.org/sabre/
http://llvm.org/
More information about the llvm-dev
mailing list