llvm.org GIT mirror llvm / d8ff3ca
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 Chris Lattner 12 years ago
3 changed file(s) with 24 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
219219 static StructType *get(const std::vector &Params,
220220 bool isPacked=false);
221221
222 /// StructType::get - This static method is a convenience method for
223 /// creating structure types by specifying the elements as arguments. Note
224 /// that this method always returns a non-packed struct.
225 static StructType *get(const Type *type, ...) END_WITH_NULL;
226
222227 // Iterator access to the elements
223228 typedef Type::subtype_iterator element_iterator;
224229 element_iterator element_begin() const { return ContainedTys; }
225225 GetElementPtrInst *CreateGEP(Value *Ptr, Value *Idx, const char *Name = "") {
226226 return Insert(new GetElementPtrInst(Ptr, Idx, Name));
227227 }
228 GetElementPtrInst *CreateStructGEP(Value *Ptr, unsigned Idx,
229 const char *Name = "") {
230 llvm::Value *Idxs[] = {
231 ConstantInt::get(llvm::Type::Int32Ty, 0),
232 ConstantInt::get(llvm::Type::Int32Ty, Idx)
233 };
234 return Insert(new GetElementPtrInst(Ptr, Idxs, Idxs+2, Name));
235 }
228236
229237 //===--------------------------------------------------------------------===//
230238 // Instruction creation methods: Cast/Conversion Operators
2121 #include "llvm/Support/ManagedStatic.h"
2222 #include "llvm/Support/Debug.h"
2323 #include
24 #include
2425 using namespace llvm;
2526
2627 // DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are
12461247 return ST;
12471248 }
12481249
1250 StructType *StructType::get(const Type *type, ...) {
1251 va_list ap;
1252 std::vector StructFields;
1253 va_start(ap, type);
1254 do {
1255 StructFields.push_back(type);
1256 } while ((type = va_arg(ap, llvm::Type*)));
1257 return llvm::StructType::get(StructFields);
1258 }
1259
12491260
12501261
12511262 //===----------------------------------------------------------------------===//