X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FDIBuilder.cpp;h=1b2049b1e56dd7e70eb044452e4f529bbb955f3d;hb=56a756821842678a96f2baa8c6a53bd28fc2b69e;hp=b6464e1eb27b70de8b1b1e1d2f97b27ca97b0708;hpb=35fcd6557f53aab69c2990b80fed4653fbaa3473;p=oota-llvm.git diff --git a/lib/Analysis/DIBuilder.cpp b/lib/Analysis/DIBuilder.cpp index b6464e1eb27..1b2049b1e56 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 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 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 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 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 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 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 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 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 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 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 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.