diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-11-04 18:45:27 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-11-04 18:45:27 +0000 |
commit | 42c9b2555407a8aae2d81bf820dc95d16f4993c5 (patch) | |
tree | 276a69473955c6825d324957b43e140dd5d15c7b | |
parent | 738734501635a15d8ed2d1c8d52962ed5f319bd3 (diff) | |
download | external_llvm-42c9b2555407a8aae2d81bf820dc95d16f4993c5.zip external_llvm-42c9b2555407a8aae2d81bf820dc95d16f4993c5.tar.gz external_llvm-42c9b2555407a8aae2d81bf820dc95d16f4993c5.tar.bz2 |
Use arrays instead of constant-sized SmallVectors.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118257 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/DIBuilder.cpp | 275 |
1 files changed, 143 insertions, 132 deletions
diff --git a/lib/Analysis/DIBuilder.cpp b/lib/Analysis/DIBuilder.cpp index b6464e1..1b2049b 100644 --- a/lib/Analysis/DIBuilder.cpp +++ b/lib/Analysis/DIBuilder.cpp @@ -16,6 +16,7 @@ #include "llvm/Constants.h" #include "llvm/IntrinsicInst.h" #include "llvm/Module.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/Dwarf.h" using namespace llvm; @@ -35,41 +36,43 @@ void DIBuilder::CreateCompileUnit(unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer, bool isOptimized, StringRef Flags, unsigned RunTimeVer) { - SmallVector<Value *, 16> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit)); - Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext))); - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), Lang)); - Elts.push_back(MDString::get(VMContext, Filename)); - Elts.push_back(MDString::get(VMContext, Directory)); - Elts.push_back(MDString::get(VMContext, Producer)); - // Deprecate isMain field. - Elts.push_back(ConstantInt::get(Type::getInt1Ty(VMContext), true)); // isMain - Elts.push_back(ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized)); - Elts.push_back(MDString::get(VMContext, Flags)); - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)); - - TheCU = DICompileUnit(MDNode::get(VMContext, Elts.data(), Elts.size())); + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit), + llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), + ConstantInt::get(Type::getInt32Ty(VMContext), Lang), + MDString::get(VMContext, Filename), + MDString::get(VMContext, Directory), + MDString::get(VMContext, Producer), + // Deprecate isMain field. + ConstantInt::get(Type::getInt1Ty(VMContext), true), // isMain + ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized), + MDString::get(VMContext, Flags), + ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer) + }; + TheCU = DICompileUnit(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateFile - Create a file descriptor to hold debugging information /// for a file. DIFile DIBuilder::CreateFile(StringRef Filename, StringRef Directory) { - assert (TheCU && "Unable to create DW_TAG_file_type without CompileUnit"); - SmallVector<Value *, 4> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_file_type)); - Elts.push_back(MDString::get(VMContext, Filename)); - Elts.push_back(MDString::get(VMContext, Directory)); - Elts.push_back(TheCU); - return DIFile(MDNode::get(VMContext, Elts.data(), Elts.size())); + assert(TheCU && "Unable to create DW_TAG_file_type without CompileUnit"); + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_file_type), + MDString::get(VMContext, Filename), + MDString::get(VMContext, Directory), + TheCU + }; + return DIFile(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateEnumerator - Create a single enumerator value. DIEnumerator DIBuilder::CreateEnumerator(StringRef Name, uint64_t Val) { - SmallVector<Value *, 4> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_enumerator)); - Elts.push_back(MDString::get(VMContext, Name)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), Val)); - return DIEnumerator(MDNode::get(VMContext, Elts.data(), Elts.size())); + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_enumerator), + MDString::get(VMContext, Name), + ConstantInt::get(Type::getInt64Ty(VMContext), Val) + }; + return DIEnumerator(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateBasicType - Create debugging information entry for a basic @@ -79,128 +82,135 @@ DIType DIBuilder::CreateBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding) { // Basic types are encoded in DIBasicType format. Line number, filename, // offset and flags are always empty here. - SmallVector<Value *, 12> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_base_type)); - Elts.push_back(TheCU); - Elts.push_back(MDString::get(VMContext, Name)); - Elts.push_back(NULL); // Filename - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags; - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)); - return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_base_type), + TheCU, + MDString::get(VMContext, Name), + NULL, // Filename + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line + ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags; + ConstantInt::get(Type::getInt32Ty(VMContext), Encoding) + }; + return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateQaulifiedType - Create debugging information entry for a qualified /// type, e.g. 'const int'. DIType DIBuilder::CreateQualifiedType(unsigned Tag, DIType FromTy) { - /// Qualified types are encoded in DIDerivedType format. - SmallVector<Value *, 12> Elts; - Elts.push_back(GetTagConstant(VMContext, Tag)); - Elts.push_back(TheCU); - Elts.push_back(MDString::get(VMContext, StringRef())); // Empty name. - Elts.push_back(NULL); // Filename - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags - Elts.push_back(FromTy); - return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); + // Qualified types are encoded in DIDerivedType format. + Value *Elts[] = { + GetTagConstant(VMContext, Tag), + TheCU, + MDString::get(VMContext, StringRef()), // Empty name. + NULL, // Filename + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags + FromTy + }; + return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreatePointerType - Create debugging information entry for a pointer. DIType DIBuilder::CreatePointerType(DIType PointeeTy, uint64_t SizeInBits, uint64_t AlignInBits, StringRef Name) { - /// pointer types are encoded in DIDerivedType format. - SmallVector<Value *, 12> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type)); - Elts.push_back(TheCU); - Elts.push_back(MDString::get(VMContext, Name)); - Elts.push_back(NULL); // Filename - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags - Elts.push_back(PointeeTy); - return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); + // Pointer types are encoded in DIDerivedType format. + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type), + TheCU, + MDString::get(VMContext, Name), + NULL, // Filename + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line + ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags + PointeeTy + }; + return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateReferenceType - Create debugging information entry for a reference. DIType DIBuilder::CreateReferenceType(DIType RTy) { - /// references are encoded in DIDerivedType format. - SmallVector<Value *, 12> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_reference_type)); - Elts.push_back(TheCU); - Elts.push_back(NULL); // Name - Elts.push_back(NULL); // Filename - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags - Elts.push_back(RTy); - return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); + // References are encoded in DIDerivedType format. + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_reference_type), + TheCU, + NULL, // Name + NULL, // Filename + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags + RTy + }; + return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateTypedef - Create debugging information entry for a typedef. DIType DIBuilder::CreateTypedef(DIType Ty, StringRef Name, DIFile File, unsigned LineNo) { - /// typedefs are encoded in DIDerivedType format. - assert (Ty.Verify() && "Invalid typedef type!"); - SmallVector<Value *, 12> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_typedef)); - Elts.push_back(Ty.getContext()); - Elts.push_back(MDString::get(VMContext, Name)); - Elts.push_back(File); - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags - Elts.push_back(Ty); - return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); + // typedefs are encoded in DIDerivedType format. + assert(Ty.Verify() && "Invalid typedef type!"); + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_typedef), + Ty.getContext(), + MDString::get(VMContext, Name), + File, + ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags + Ty + }; + return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateFriend - Create debugging information entry for a 'friend'. DIType DIBuilder::CreateFriend(DIType Ty, DIType FriendTy) { - /// typedefs are encoded in DIDerivedType format. - assert (Ty.Verify() && "Invalid type!"); - assert (FriendTy.Verify() && "Invalid friend type!"); - SmallVector<Value *, 12> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_friend)); - Elts.push_back(Ty); - Elts.push_back(NULL); // Name - Elts.push_back(Ty.getFile()); - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags - Elts.push_back(FriendTy); - return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); + // typedefs are encoded in DIDerivedType format. + assert(Ty.Verify() && "Invalid type!"); + assert(FriendTy.Verify() && "Invalid friend type!"); + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_friend), + Ty, + NULL, // Name + Ty.getFile(), + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags + FriendTy + }; + return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateInheritance - Create debugging information entry to establish /// inheritnace relationship between two types. DIType DIBuilder::CreateInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset, unsigned Flags) { - /// TAG_inheritance is encoded in DIDerivedType format. - SmallVector<Value *, 12> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_inheritance)); - Elts.push_back(Ty); - Elts.push_back(NULL); // Name - Elts.push_back(NULL); // File - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset)); - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), Flags)); - Elts.push_back(BaseTy); - return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); + // TAG_inheritance is encoded in DIDerivedType format. + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_inheritance), + Ty, + NULL, // Name + NULL, // File + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size + ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align + ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset), + ConstantInt::get(Type::getInt32Ty(VMContext), Flags), + BaseTy + }; + return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateMemberType - Create debugging information entry for a member. @@ -209,19 +219,20 @@ DIType DIBuilder::CreateMemberType(DIDescriptor Context, StringRef Name, uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, DIType Ty) { - /// TAG_member is encoded in DIDerivedType format. - SmallVector<Value *, 12> Elts; - Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_member)); - Elts.push_back(Context); - Elts.push_back(MDString::get(VMContext, Name)); - Elts.push_back(F); - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits)); - Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits)); - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), Flags)); - Elts.push_back(Ty); - return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); + // TAG_member is encoded in DIDerivedType format. + Value *Elts[] = { + GetTagConstant(VMContext, dwarf::DW_TAG_member), + Context, + MDString::get(VMContext, Name), + F, + ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), + ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), + ConstantInt::get(Type::getInt32Ty(VMContext), Flags), + Ty + }; + return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts))); } /// CreateArtificialType - Create a new DIType with "artificial" flag set. |