Sorry about the bad title, but I hope you will get my idea. I
think that in many LLVM programs that create/modify the LLVM
IR (like say a language frontend/profiler etc), and in other
cases too, some of the code is just "mechanical", for example
creating function types takes like 4-5 lines of code, but
nothing interesting goes on there. I think we can get rid of
such code by providing an LLVM assembly language parsing
library. For example, a type parser may look something like:
TypeParser p("uint x uinx -> void");
Type* FuncType = p.getType();
The same thing can be extended to an LLVM snippet parser,
which will parse LLVM instruction. We can use $1, $2 etc as
paramaters, so that snippets can be instantiated with
specific arguments.
Do others think this functionality will be useful?
Oops .. pardon my last incomplete posting, pushed Ctrl-Enter by
accident! As I was saying ..
Rahul's idea is interesting and would make some aspects of LLVM
programming easier, but I wouldn't use it in my source language for the
following reasons:
1. Of necessity the "snippet parser" would need to be based on the same
language/grammar as AsmParser. Allowing parsing and correct error
handling of snippets could obfuscate the grammar and make
maintenance of it harder.
2. The overhead in the compiler for parsing snippets would be too high
for my compiler. Compilers are already memory and CPU intensive
applications, adding any additional CPU burden for convenience is a
high price to pay.
3. There are alternative mechanisms that can achieve the same thing. I
would much rather use a set of C++ templates, CPP macros, or plain
functions to achieve the same end. This essentially raises the
level of abstraction for programming the IR.
What would be quite useful is to have a *standard* set of IR utility
functions/macros/templates that would achieve the same end. Programming
to the LLVM IR is already quite simple but an even higher level
interface would provide support for the many idioms that occur
frequently.
What would be quite useful is to have a *standard* set of IR utility
functions/macros/templates that would achieve the same end. Programming
to the LLVM IR is already quite simple but an even higher level
interface would provide support for the many idioms that occur
frequently.
I agree with Reid in this case. Having a snippet parser would be cool,
but I don't think it would be very heavily used, and very hard to get
right. I would rather invest effort in making the LLVM IR easier to use.
For example, would it help if I added a FunctionType::get method that took
a null terminated list of arguments?
In general, if you think the LLVM IR interface is clunky or doesn't
support a common usage case, please let me know so I can fix it!