[llvm-commits] [llvm] r48531 - in /llvm/trunk: include/llvm/DerivedTypes.h include/llvm/Support/LLVMBuilder.h lib/VMCore/Type.cpp
Chris Lattner
sabre at nondot.org
Tue Mar 18 22:06:05 PDT 2008
Author: lattner
Date: Wed Mar 19 00:06:05 2008
New Revision: 48531
URL: http://llvm.org/viewvc/llvm-project?rev=48531&view=rev
Log:
add some convenience methods for creating GEP instructions and
struct types. Patch by David Chisnall, with some tweaks.
Modified:
llvm/trunk/include/llvm/DerivedTypes.h
llvm/trunk/include/llvm/Support/LLVMBuilder.h
llvm/trunk/lib/VMCore/Type.cpp
Modified: llvm/trunk/include/llvm/DerivedTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DerivedTypes.h?rev=48531&r1=48530&r2=48531&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DerivedTypes.h (original)
+++ llvm/trunk/include/llvm/DerivedTypes.h Wed Mar 19 00:06:05 2008
@@ -220,6 +220,11 @@
static StructType *get(const std::vector<const Type*> &Params,
bool isPacked=false);
+ /// StructType::get - This static method is a convenience method for
+ /// creating structure types by specifying the elements as arguments. Note
+ /// that this method always returns a non-packed struct.
+ static StructType *get(const Type *type, ...) END_WITH_NULL;
+
// Iterator access to the elements
typedef Type::subtype_iterator element_iterator;
element_iterator element_begin() const { return ContainedTys; }
Modified: llvm/trunk/include/llvm/Support/LLVMBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/LLVMBuilder.h?rev=48531&r1=48530&r2=48531&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/LLVMBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/LLVMBuilder.h Wed Mar 19 00:06:05 2008
@@ -226,6 +226,14 @@
GetElementPtrInst *CreateGEP(Value *Ptr, Value *Idx, const char *Name = "") {
return Insert(new GetElementPtrInst(Ptr, Idx, Name));
}
+ 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(new GetElementPtrInst(Ptr, Idxs, Idxs+2, Name));
+ }
//===--------------------------------------------------------------------===//
// Instruction creation methods: Cast/Conversion Operators
Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=48531&r1=48530&r2=48531&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Wed Mar 19 00:06:05 2008
@@ -22,6 +22,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Debug.h"
#include <algorithm>
+#include <cstdarg>
using namespace llvm;
// DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are
@@ -1247,6 +1248,16 @@
return ST;
}
+StructType *StructType::get(const Type *type, ...) {
+ va_list ap;
+ std::vector<const llvm::Type*> StructFields;
+ va_start(ap, type);
+ do {
+ StructFields.push_back(type);
+ } while ((type = va_arg(ap, llvm::Type*)));
+ return llvm::StructType::get(StructFields);
+}
+
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list