Use arrays instead of constant-sized SmallVectors.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118257 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2010-11-04 18:45:27 +00:00
parent 7387345016
commit 42c9b25554

View File

@ -16,6 +16,7 @@
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/IntrinsicInst.h" #include "llvm/IntrinsicInst.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Dwarf.h" #include "llvm/Support/Dwarf.h"
using namespace llvm; using namespace llvm;
@ -35,41 +36,43 @@ void DIBuilder::CreateCompileUnit(unsigned Lang, StringRef Filename,
StringRef Directory, StringRef Producer, StringRef Directory, StringRef Producer,
bool isOptimized, StringRef Flags, bool isOptimized, StringRef Flags,
unsigned RunTimeVer) { unsigned RunTimeVer) {
SmallVector<Value *, 16> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit)); GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext))); llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), Lang)); ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
Elts.push_back(MDString::get(VMContext, Filename)); MDString::get(VMContext, Filename),
Elts.push_back(MDString::get(VMContext, Directory)); MDString::get(VMContext, Directory),
Elts.push_back(MDString::get(VMContext, Producer)); MDString::get(VMContext, Producer),
// Deprecate isMain field. // Deprecate isMain field.
Elts.push_back(ConstantInt::get(Type::getInt1Ty(VMContext), true)); // isMain ConstantInt::get(Type::getInt1Ty(VMContext), true), // isMain
Elts.push_back(ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized)); ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Elts.push_back(MDString::get(VMContext, Flags)); MDString::get(VMContext, Flags),
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)); ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
};
TheCU = DICompileUnit(MDNode::get(VMContext, Elts.data(), Elts.size())); TheCU = DICompileUnit(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateFile - Create a file descriptor to hold debugging information /// CreateFile - Create a file descriptor to hold debugging information
/// for a file. /// for a file.
DIFile DIBuilder::CreateFile(StringRef Filename, StringRef Directory) { DIFile DIBuilder::CreateFile(StringRef Filename, StringRef Directory) {
assert (TheCU && "Unable to create DW_TAG_file_type without CompileUnit"); assert(TheCU && "Unable to create DW_TAG_file_type without CompileUnit");
SmallVector<Value *, 4> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_file_type)); GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
Elts.push_back(MDString::get(VMContext, Filename)); MDString::get(VMContext, Filename),
Elts.push_back(MDString::get(VMContext, Directory)); MDString::get(VMContext, Directory),
Elts.push_back(TheCU); TheCU
return DIFile(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIFile(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateEnumerator - Create a single enumerator value. /// CreateEnumerator - Create a single enumerator value.
DIEnumerator DIBuilder::CreateEnumerator(StringRef Name, uint64_t Val) { DIEnumerator DIBuilder::CreateEnumerator(StringRef Name, uint64_t Val) {
SmallVector<Value *, 4> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_enumerator)); GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
Elts.push_back(MDString::get(VMContext, Name)); MDString::get(VMContext, Name),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), Val)); ConstantInt::get(Type::getInt64Ty(VMContext), Val)
return DIEnumerator(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIEnumerator(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateBasicType - Create debugging information entry for a basic /// CreateBasicType - Create debugging information entry for a basic
@ -79,128 +82,135 @@ DIType DIBuilder::CreateBasicType(StringRef Name, uint64_t SizeInBits,
unsigned Encoding) { unsigned Encoding) {
// Basic types are encoded in DIBasicType format. Line number, filename, // Basic types are encoded in DIBasicType format. Line number, filename,
// offset and flags are always empty here. // offset and flags are always empty here.
SmallVector<Value *, 12> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_base_type)); GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
Elts.push_back(TheCU); TheCU,
Elts.push_back(MDString::get(VMContext, Name)); MDString::get(VMContext, Name),
Elts.push_back(NULL); // Filename NULL, // Filename
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits)); ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits)); ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags; ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)); ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateQaulifiedType - Create debugging information entry for a qualified /// CreateQaulifiedType - Create debugging information entry for a qualified
/// type, e.g. 'const int'. /// type, e.g. 'const int'.
DIType DIBuilder::CreateQualifiedType(unsigned Tag, DIType FromTy) { DIType DIBuilder::CreateQualifiedType(unsigned Tag, DIType FromTy) {
/// Qualified types are encoded in DIDerivedType format. // Qualified types are encoded in DIDerivedType format.
SmallVector<Value *, 12> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, Tag)); GetTagConstant(VMContext, Tag),
Elts.push_back(TheCU); TheCU,
Elts.push_back(MDString::get(VMContext, StringRef())); // Empty name. MDString::get(VMContext, StringRef()), // Empty name.
Elts.push_back(NULL); // Filename NULL, // Filename
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Elts.push_back(FromTy); FromTy
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreatePointerType - Create debugging information entry for a pointer. /// CreatePointerType - Create debugging information entry for a pointer.
DIType DIBuilder::CreatePointerType(DIType PointeeTy, uint64_t SizeInBits, DIType DIBuilder::CreatePointerType(DIType PointeeTy, uint64_t SizeInBits,
uint64_t AlignInBits, StringRef Name) { uint64_t AlignInBits, StringRef Name) {
/// pointer types are encoded in DIDerivedType format. // Pointer types are encoded in DIDerivedType format.
SmallVector<Value *, 12> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type)); GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
Elts.push_back(TheCU); TheCU,
Elts.push_back(MDString::get(VMContext, Name)); MDString::get(VMContext, Name),
Elts.push_back(NULL); // Filename NULL, // Filename
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits)); ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits)); ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Elts.push_back(PointeeTy); PointeeTy
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateReferenceType - Create debugging information entry for a reference. /// CreateReferenceType - Create debugging information entry for a reference.
DIType DIBuilder::CreateReferenceType(DIType RTy) { DIType DIBuilder::CreateReferenceType(DIType RTy) {
/// references are encoded in DIDerivedType format. // References are encoded in DIDerivedType format.
SmallVector<Value *, 12> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_reference_type)); GetTagConstant(VMContext, dwarf::DW_TAG_reference_type),
Elts.push_back(TheCU); TheCU,
Elts.push_back(NULL); // Name NULL, // Name
Elts.push_back(NULL); // Filename NULL, // Filename
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Elts.push_back(RTy); RTy
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateTypedef - Create debugging information entry for a typedef. /// CreateTypedef - Create debugging information entry for a typedef.
DIType DIBuilder::CreateTypedef(DIType Ty, StringRef Name, DIFile File, DIType DIBuilder::CreateTypedef(DIType Ty, StringRef Name, DIFile File,
unsigned LineNo) { unsigned LineNo) {
/// typedefs are encoded in DIDerivedType format. // typedefs are encoded in DIDerivedType format.
assert (Ty.Verify() && "Invalid typedef type!"); assert(Ty.Verify() && "Invalid typedef type!");
SmallVector<Value *, 12> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_typedef)); GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
Elts.push_back(Ty.getContext()); Ty.getContext(),
Elts.push_back(MDString::get(VMContext, Name)); MDString::get(VMContext, Name),
Elts.push_back(File); File,
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)); ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Elts.push_back(Ty); Ty
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateFriend - Create debugging information entry for a 'friend'. /// CreateFriend - Create debugging information entry for a 'friend'.
DIType DIBuilder::CreateFriend(DIType Ty, DIType FriendTy) { DIType DIBuilder::CreateFriend(DIType Ty, DIType FriendTy) {
/// typedefs are encoded in DIDerivedType format. // typedefs are encoded in DIDerivedType format.
assert (Ty.Verify() && "Invalid type!"); assert(Ty.Verify() && "Invalid type!");
assert (FriendTy.Verify() && "Invalid friend type!"); assert(FriendTy.Verify() && "Invalid friend type!");
SmallVector<Value *, 12> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_friend)); GetTagConstant(VMContext, dwarf::DW_TAG_friend),
Elts.push_back(Ty); Ty,
Elts.push_back(NULL); // Name NULL, // Name
Elts.push_back(Ty.getFile()); Ty.getFile(),
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Offset ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Flags ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Elts.push_back(FriendTy); FriendTy
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateInheritance - Create debugging information entry to establish /// CreateInheritance - Create debugging information entry to establish
/// inheritnace relationship between two types. /// inheritnace relationship between two types.
DIType DIBuilder::CreateInheritance(DIType Ty, DIType BaseTy, DIType DIBuilder::CreateInheritance(DIType Ty, DIType BaseTy,
uint64_t BaseOffset, unsigned Flags) { uint64_t BaseOffset, unsigned Flags) {
/// TAG_inheritance is encoded in DIDerivedType format. // TAG_inheritance is encoded in DIDerivedType format.
SmallVector<Value *, 12> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_inheritance)); GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
Elts.push_back(Ty); Ty,
Elts.push_back(NULL); // Name NULL, // Name
Elts.push_back(NULL); // File NULL, // File
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), 0)); // Line ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Size ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), 0)); // Align ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset)); ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), Flags)); ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Elts.push_back(BaseTy); BaseTy
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateMemberType - Create debugging information entry for a member. /// 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 SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags, uint64_t OffsetInBits, unsigned Flags,
DIType Ty) { DIType Ty) {
/// TAG_member is encoded in DIDerivedType format. // TAG_member is encoded in DIDerivedType format.
SmallVector<Value *, 12> Elts; Value *Elts[] = {
Elts.push_back(GetTagConstant(VMContext, dwarf::DW_TAG_member)); GetTagConstant(VMContext, dwarf::DW_TAG_member),
Elts.push_back(Context); Context,
Elts.push_back(MDString::get(VMContext, Name)); MDString::get(VMContext, Name),
Elts.push_back(F); F,
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber)); ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits)); ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits)); ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Elts.push_back(ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits)); ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), Flags)); ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Elts.push_back(Ty); Ty
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size())); };
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
} }
/// CreateArtificialType - Create a new DIType with "artificial" flag set. /// CreateArtificialType - Create a new DIType with "artificial" flag set.