Newbie question for registering new target with LLVM

Hi all, llvm newbie here.

I'm trying to learn porting with llvm for study purpose. This is my first query
on llvm mailing list.I have some idea about GCC. I choose 'rx' as a target to
port as it is also available in GCC. I have done some initial changes with llvm
source code to register target with llvm. I need to verify these changes. Can
anyone please take a chance to verify it.

Build Command(s):

Hi,

1.1) Please verify all above change(s) are OK? or I have modify some code?

Parts will almost certainly have to change in future, but if it builds
that's an excellent first step.

1.2) In LLVM, can we proceed our development like as GCC i.e. incremental
      approach? In case of yes, please provide me any reference.

Incremental is definitely possible. I started out with the most
trivial of functions:

define void @foo() {
    ret void
}

and worked on from there in roughly this order:

+ Global variables (gives you guaranteed non-dead values to test
everything with and is likely simpler than getting procedure call ABIs
correct).
+ Simple arithmetic to make sure I'm not being completely insane in my
design decisions and get an idea of how the XXXInstrInfo.td will work
+ Stack spills and function prologue/epilogue.
+ Function calls and arguments.

After about the second stage I was implementing wide swathes of the
processor's instruction space, to give me the instructions needed to
support the more complicated details.

1.3) Please help me from anyone of llvm lovers :slight_smile: to proceed further. What
      modifications required to generate rx assembly of hello word program.

As far as a backends go "Hello World" is not a small goal, though it
could be reached reasonably quickly if you're willing to put in hacks
that'll have to change later.

It's probably best to start trying to compile simple functions and
keep adding bits until that works. Anything you're not sure of but
that needs to be present for compilation, put an
llvm_unreachable("What's going on here?") so that you get to see
what's actually happening when it reaches that code and don't have to
guess what's needed.

Even compiling the simplest "define void @foo() { ret void }" is
likely to require quite a bit more infrastructure. Most of the files
in the existing backends are needed (possibly in a much simplified
form) for that function. I think the most important things you'll need
start in just two places and gradually depend on all the real
features:
  + RxTargetMachine.cpp is small, but central. It's where you register
the passes that actually do the work. If you can get things to compile
with these functions doing their job you should have stubs for most of
the necessary components.
   + InstPrinter/XXXInstPrinter.cpp: This is the main entry for the
so-called MC instruction printing, which is the good way to do things.
It's theoretically possible to get your instructions printing without
creating this, but you'd be Doing It Wrong.

But most importantly, have fun and don't be afraid to ask more
detailed questions on the lists when you hit problems!

Tim.

Hi Tim, Thank you so much for your detailed
guidance e-mail. I am following your points and llvm artifacts. Soon I
need further guidance for next step.
  Regards, Sandeep

Hi Tim,

Have you considered taking your knowledge about writing backends and
improve the current documentation? I have made a document which should
allow you to get up and running writing documentation extremely
quickly and easily; you can find it at
<http://llvm.org/docs/SphinxQuickstartTemplate.html&gt;\.

Any help is greatly appreciated. Even just a slightly more expository
coverage of the material in your email would be a great addition to
the docs, and could serve as a seed for others to improve. This email
reply you just gave seems like it would fit really well into a new
document "How To dive into developing an LLVM backend"; you appear to
have a good recollection of how you "dove in" :slight_smile:

Thanks,

-- Sean Silva

Have you considered taking your knowledge about writing backends and
improve the current documentation? I have made a document which should
allow you to get up and running writing documentation extremely
quickly and easily; you can find it at
<http://llvm.org/docs/SphinxQuickstartTemplate.html&gt;\.

Could be a good idea. I'll see what I can do this weekend.

Tim.

Have you considered taking your knowledge about writing backends and
improve the current documentation? I have made a document which should
allow you to get up and running writing documentation extremely
quickly and easily; you can find it at
<http://llvm.org/docs/SphinxQuickstartTemplate.html&gt;\.

Could be a good idea. I'll see what I can do this weekend.

Thanks!

-- Sean Silva

Hey, I’m developing a new backend right now and I feel like I miss some steps and I was looking for a small backend to take as an example (in particular for the .cpp files). In the end have you done something about the “How To dive into developing an LLVM backend” document?
Thanks

There are some docs here (which you may have already found), and there’s also an LLVM Dev talk by @asb that might help. If you run into any specific issues or have any follow-up questions, feel free to post in the Beginners category.