New LLVMBuilder api

I just checked in a new LLVMBuilder class into llvm/Support/LLVMBuilder.h, and switched llvm-gcc over to use it. This class is based on feedback Tom Tromey gave on LLVM way back here: http://lists.cs.uiuc.edu/pipermail/llvmdev/2006-April/005581.html

Basically, when creating a frontend, you end up creating a lot of instructions. This has three suboptimal aspects to it:

1. The constructors for the instructions all must be passed a place to
    insert the instructions into. Because the instructions often take a
    long list of arguments, this is nontrivial can can cause errors (Tom
    hit a problem with Alloca, for example).

2. The instruction ctors all default construct an std::string. In
    practice, this is a very modest overhead, but if it isn't needed, it
    shouldn't happen.

3. Some of the construction APIs are very verbose, my "favorite" being
    BinaryOperator::createAdd and friends.

The new API separates the idea of what to construct from where to insert it. In particular, when you create an LLVMBuilder object, you can tell it where to insert all subsequently created instructions. This means you end up writing code like this:

LLVMBuilder B;
B.SetInsertPoint(<where-ever>);

Value *V1 = B.CreateAdd(a, b, "tmp");
Value *V2 = B.CreateMul(V1, c, "whatever");
Value *V3 = B.CreateCall(FnPtr, V1, V2);
...

The name strings are c strings, are always at the end of the argument list, and are always optional.

This API is simple and consistent, which makes it easy to understand. It would also be really easy to build a C api for it, if someone is interested (hint hint :),

-Chris

I just checked in a new LLVMBuilder class into llvm/Support/LLVMBuilder.h,

It does not seem to be on the LLVM cvsweb, is that still showing 1.9 or 2.0 and not cvs ?

Aaron

It is there:
http://llvm.org/cvsweb/cvsweb.cgi/llvm/include/llvm/Support/LLVMBuilder.h?rev=HEAD&content-type=text/x-cvsweb-markup

-Chris

Ah, right, sorry, not looking properly.

This is a tiny bit like .NET, but that uses emit rather than CreateX.

How did the meeting go, have heard no news on the mailing list.

Aaron

CreateMalloc and CreateAlloca should not the ArraySize be set to (a) 1 as default argument ?

Aaron

Some news here:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-May/009187.html

I imagine that people are traveling back home. The videos turned out great, we should have them online in a week or two worst case.

Other attendees are welcome to contribute their impressions :slight_smile:

-Chris

How did the meeting go, have heard no news on the mailing list.

http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-May/009187.html

-Tanya

Yes, they are.

-Chris