[llvm-commits] [llvm] r66295 - /llvm/trunk/include/llvm/Support/IRBuilder.h
Daniel Dunbar
daniel at zuster.org
Fri Mar 6 14:26:07 PST 2009
Author: ddunbar
Date: Fri Mar 6 16:26:07 2009
New Revision: 66295
URL: http://llvm.org/viewvc/llvm-project?rev=66295&view=rev
Log:
Add IRBuilder::CreateConstGEP{1, 2}_{32, 64}.
- Names are lame, but it seems better to be explicit.
Modified:
llvm/trunk/include/llvm/Support/IRBuilder.h
Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=66295&r1=66294&r2=66295&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Fri Mar 6 16:26:07 2009
@@ -318,16 +318,48 @@
return Folder.CreateGetElementPtr(PC, &IC, 1);
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
}
- Value *CreateStructGEP(Value *Ptr, unsigned Idx, const char *Name = "") {
+ Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") {
+ llvm::Value *Idx = ConstantInt::get(llvm::Type::Int32Ty, Idx0);
+
+ if (Constant *PC = dyn_cast<Constant>(Ptr))
+ return Folder.CreateGetElementPtr(PC, &Idx, 1);
+
+ return Insert(GetElementPtrInst::Create(Ptr, &Idx, &Idx+1), Name);
+ }
+ Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
+ const char *Name = "") {
+ llvm::Value *Idxs[] = {
+ ConstantInt::get(llvm::Type::Int32Ty, Idx0),
+ ConstantInt::get(llvm::Type::Int32Ty, Idx1)
+ };
+
+ if (Constant *PC = dyn_cast<Constant>(Ptr))
+ return Folder.CreateGetElementPtr(PC, Idxs, 2);
+
+ return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
+ }
+ Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") {
+ llvm::Value *Idx = ConstantInt::get(llvm::Type::Int64Ty, Idx0);
+
+ if (Constant *PC = dyn_cast<Constant>(Ptr))
+ return Folder.CreateGetElementPtr(PC, &Idx, 1);
+
+ return Insert(GetElementPtrInst::Create(Ptr, &Idx, &Idx+1), Name);
+ }
+ Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
+ const char *Name = "") {
llvm::Value *Idxs[] = {
- ConstantInt::get(llvm::Type::Int32Ty, 0),
- ConstantInt::get(llvm::Type::Int32Ty, Idx)
+ ConstantInt::get(llvm::Type::Int64Ty, Idx0),
+ ConstantInt::get(llvm::Type::Int64Ty, Idx1)
};
if (Constant *PC = dyn_cast<Constant>(Ptr))
return Folder.CreateGetElementPtr(PC, Idxs, 2);
- return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
+ return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
+ }
+ Value *CreateStructGEP(Value *Ptr, unsigned Idx, const char *Name = "") {
+ return CreateConstGEP2_32(Ptr, 0, Idx, Name);
}
Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
Constant *StrConstant = ConstantArray::get(Str, true);
More information about the llvm-commits
mailing list