Is it easy to achieve high level of optimization with LLVM?
To give a concrete example let’s assume that I have a simple lanuage that I want to write a compiler for.
- simple functions
- simple structs
- tables
- pointers (with arithmetic)
- control structures
- etc.
I can quite easily create compilation-to-C backend and rely on clang -O3.
Is it as easy to use LLVM API for that purpose?
Except perhaps for a few high-level (as in, aware of high-level language features or details that aren’t encoded in LLVM IR) optimizations, Clang’s backend does little more than generate straightforward IR and run some set of LLVM optimization passes on it. All of these (or at least most) should be available trough the
optcommand and also as API calls when using the C++ libraries that all LLVM tools are built on. See the tutorial for a simple example. I see several advantages:#defines, obscure pragmas, instrincts or command line options) to provide them. I’m talking about like vectors, guaranteed (well, more than in C anyway – AFAIK, some code generators ignore them) tail calls, pure/readonly functions, more control over memory layout and type conversions (for instance zero extending vs. sign extending). Granted, you may not need most of them.