leveraging back-end C compiler features in the gcc-based front-end

View: New views
6 Messages — Rating Filter:   Alert me  

leveraging back-end C compiler features in the gcc-based front-end

by Bob Frankel :: Rate this Message:

| View Threaded | Show Only this Message

i'm looking into using llvm with TI's MSP430, for which a C compiler from TI already exists; the idea here is to use llc -march=c and then pass the generated C code on to the TI compiler.  as it turns out, the TI C compiler supports a number of (processor-specific) intrinsics that expose much of the underlying CPU architecture directly to the C programmer -- registers, pseudo-functions for enabling/disabling interrupts and reading/writing status bits, etc.

is there a way to leverage these (non-gcc) intrinsics in the llvm gcc-based frontend -- perhaps flagging their use in such a way that they effectively "pass through" the optimizer and are emitted "as is" in the generated C code?   in some respects, you can think of this usage as not unlike dropping inline asm code into the C sources.

bob frankel


_______________________________________________
LLVM Developers mailing list
LLVMdev@...         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Re: leveraging back-end C compiler features in the gcc-based front-end

by Eli Friedman-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Sun, May 3, 2009 at 6:19 PM, Bob Frankel <bios.bob.frankel@...> wrote:
> i'm looking into using llvm with TI's MSP430

Ah, you're in luck then: an MSP430 backend was checked in to SVN today
:)  I don't think it's mature enough for general use yet, though.

> is there a way to leverage these (non-gcc) intrinsics in the llvm gcc-based
> frontend -- perhaps flagging their use in such a way that they effectively
> "pass through" the optimizer and are emitted "as is" in the generated C
> code?   in some respects, you can think of this usage as not unlike dropping
> inline asm code into the C sources.

You could try just generating calls to the builtins in question; if
you're lucky, it'll just work... if not, you can always use sed (or
equivalent) to manipulate the C output into the correct form.

-Eli

_______________________________________________
LLVM Developers mailing list
LLVMdev@...         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Re: leveraging back-end C compiler features in the gcc-based front-end

by Bob Frankel :: Rate this Message:

| View Threaded | Show Only this Message

wow!!!  i would be interested in trying this....  any helpful instructions (for a novice like me) to get started using the msp430 backend would be helpful....

as for your suggestion, it does work -- i can (say) place a call to __get_SR_register() in my front-end source, and it simply shows up in the back-end .c file; other "extensions" to compilers (such as 'interrupt' keyword to generate different prologue/epilogue code) would be a little trickier (though there are presumably already gcc mechansims for flagging interrupt routines??)



Eli Friedman wrote:
On Sun, May 3, 2009 at 6:19 PM, Bob Frankel bios.bob.frankel@... wrote:
  
i'm looking into using llvm with TI's MSP430
    

Ah, you're in luck then: an MSP430 backend was checked in to SVN today
:)  I don't think it's mature enough for general use yet, though.

  
is there a way to leverage these (non-gcc) intrinsics in the llvm gcc-based
frontend -- perhaps flagging their use in such a way that they effectively
"pass through" the optimizer and are emitted "as is" in the generated C
code?   in some respects, you can think of this usage as not unlike dropping
inline asm code into the C sources.
    

You could try just generating calls to the builtins in question; if
you're lucky, it'll just work... if not, you can always use sed (or
equivalent) to manipulate the C output into the correct form.

-Eli

_______________________________________________
LLVM Developers mailing list
LLVMdev@...         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
  

_______________________________________________
LLVM Developers mailing list
LLVMdev@...         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Re: leveraging back-end C compiler features in the gcc-based front-end

by Eli Friedman-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Sun, May 3, 2009 at 7:12 PM, Bob Frankel <bios.bob.frankel@...> wrote:
> wow!!!  i would be interested in trying this....  any helpful instructions
> (for a novice like me) to get started using the msp430 backend would be
> helpful....

If you've built clang (http://clang.llvm.org/), you can use a command
like "clang -ccc-host-triple msp430-generic-generic -ccc-clang-archs
msp430 -x c - -o - -S -O" and type in some C code, and it'll spit out
msp430 assembly.  (The -ccc-host-triple and -cc-clang-archs arguments
are magic; besides that, clang takes the same arguments as gcc.)

-Eli

_______________________________________________
LLVM Developers mailing list
LLVMdev@...         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Re: leveraging back-end C compiler features in the gcc-based front-end

by Anton Korobeynikov-2 :: Rate this Message:

| View Threaded | Show Only this Message

Hello, Bob

> supports a number of (processor-specific) intrinsics that expose much of the
> underlying CPU architecture directly to the C programmer -- registers,
> pseudo-functions for enabling/disabling interrupts and reading/writing
> status bits, etc.
Nothing special here. All this can be implemented either via inline
assembler and/or via register-tied variables. I have no idea whether
mspgcc supports this, but this certainly possible.

--
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University
_______________________________________________
LLVM Developers mailing list
LLVMdev@...         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Re: leveraging back-end C compiler features in the gcc-based front-end

by Anton Korobeynikov-2 :: Rate this Message:

| View Threaded | Show Only this Message

Hello, Bob

> wow!!!  i would be interested in trying this....  any helpful instructions
> (for a novice like me) to get started using the msp430 backend would be
> helpful....
It depends what you want to do with it. It's definitely not mature
enough, so... "patches are welcome" :) Please read readme.txt in the
backend dir for some information & possible tasks if you're interested
in it.

--
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University

_______________________________________________
LLVM Developers mailing list
LLVMdev@...         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev