aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-03-19 05:06:05 +0000
committerChris Lattner <sabre@nondot.org>2008-03-19 05:06:05 +0000
commitd8ff3caaa0d5dd4a7cbbe25c42d70af2e3caca7f (patch)
tree7e8f784c5119056872ea90cde770a291d4b58184
parent7f40dea2f1bcb54121f84a479756fb319427e059 (diff)
downloadexternal_llvm-d8ff3caaa0d5dd4a7cbbe25c42d70af2e3caca7f.zip
external_llvm-d8ff3caaa0d5dd4a7cbbe25c42d70af2e3caca7f.tar.gz
external_llvm-d8ff3caaa0d5dd4a7cbbe25c42d70af2e3caca7f.tar.bz2
add some convenience methods for creating GEP instructions and
struct types. Patch by David Chisnall, with some tweaks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48531 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/DerivedTypes.h5
-rw-r--r--include/llvm/Support/LLVMBuilder.h8
-rw-r--r--lib/VMCore/Type.cpp11
3 files changed, 24 insertions, 0 deletions
diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h
index 457d37d..7fc7ed6 100644
--- a/include/llvm/DerivedTypes.h
+++ b/include/llvm/DerivedTypes.h
@@ -220,6 +220,11 @@ public:
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; }
diff --git a/include/llvm/Support/LLVMBuilder.h b/include/llvm/Support/LLVMBuilder.h
index 1757404..ef1817d 100644
--- a/include/llvm/Support/LLVMBuilder.h
+++ b/include/llvm/Support/LLVMBuilder.h
@@ -226,6 +226,14 @@ public:
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
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index 6b88444..4554826 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -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 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
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);
+}
+
//===----------------------------------------------------------------------===//