[LLVMdev] LLVMBuilder vs LLVMFoldingBuilder
Dominic Hamon
dom.hamon at gmail.com
Sat Apr 12 00:10:50 PDT 2008
Duncan Sands wrote:
> + GetElementPtrInst *CreateStructGEP(Value *Ptr, unsigned Idx,
> + const char *Name = "") {
> + llvm::Value *Idxs[] = {
> + ConstantInt::get(llvm::Type::Int32Ty, 0),
> + ConstantInt::get(llvm::Type::Int32Ty, Idx)
> + };
> + return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2, Name));
> + }
>
> This should constant fold if Ptr is a constant.
>
>
While looking at this, I noticed that GetElementPtrInst::Create and
ConstantExpr::getGetElementPtr have a different interface when taking a
list of indices. The first takes the start and end pointers to the list,
while the second takes the first pointer and the length of the list. I
feel like these interfaces should be consistent. Maybe my next patch.
> Index: Xcode/LLVM.xcodeproj/project.pbxproj
>
> I don't know what this Xcode stuff is, so I've no idea if it is correct
> or whether you should be committing it.
>
I've added some missing files, removed LLVMBuilder.h and added
IRBuilder.h and added the BrainF example (as I had to make changes to it
for the patch).
The only changes that I'm not 100% happy with are the
ShadowStackCollector changes. The code will currently assert if the
BasePtr passed in to the ShadowStackCollector is a constant as the GEP
will be a constant. If we want to make the ShadowStackCollector support
constant folding, more changes are required. None of the tests in the
DejaGNU test suite or the full llvm test-suite have asserted, so I have
to believe this is safe. If someone with a greater understanding of how
the ShadowStackCollector works could give input on this, I'd be grateful.
Please find _attached_ the update patches with all requested changes.
Thanks
Dominic
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: llvm-gcc42.IRBuilder.patch
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080412/8317f8be/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: llvm.IRBuilder.patch
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080412/8317f8be/attachment-0001.ksh>
More information about the llvm-dev
mailing list