Index: bindings/go/llvm/DIBuilderBindings.h =================================================================== --- bindings/go/llvm/DIBuilderBindings.h +++ bindings/go/llvm/DIBuilderBindings.h @@ -76,6 +76,7 @@ LLVMMetadataRef PointeeType, uint64_t SizeInBits, uint32_t AlignInBits, + unsigned AddressSpace, const char *Name); LLVMMetadataRef Index: bindings/go/llvm/DIBuilderBindings.cpp =================================================================== --- bindings/go/llvm/DIBuilderBindings.cpp +++ bindings/go/llvm/DIBuilderBindings.cpp @@ -116,10 +116,11 @@ LLVMMetadataRef PointeeType, uint64_t SizeInBits, uint32_t AlignInBits, + unsigned AddressSpace, const char *Name) { DIBuilder *D = unwrap(Dref); return wrap(D->createPointerType(unwrap(PointeeType), SizeInBits, - AlignInBits, Name)); + AlignInBits, AddressSpace, Name)); } LLVMMetadataRef Index: bindings/go/llvm/dibuilder.go =================================================================== --- bindings/go/llvm/dibuilder.go +++ bindings/go/llvm/dibuilder.go @@ -297,10 +297,11 @@ // DIPointerType holds the values for creating pointer type debug metadata. type DIPointerType struct { - Pointee Metadata - SizeInBits uint64 - AlignInBits uint32 // optional - Name string // optional + Pointee Metadata + SizeInBits uint64 + AlignInBits uint32 // optional + AddressSpace int // optional + Name string // optional } // CreateBasicType creates basic type debug metadata. @@ -312,6 +313,7 @@ t.Pointee.C, C.uint64_t(t.SizeInBits), C.uint32_t(t.AlignInBits), + C.unsigned(t.AddressSpace), name, ) return Metadata{C: result} Index: include/llvm/IR/DIBuilder.h =================================================================== --- include/llvm/IR/DIBuilder.h +++ include/llvm/IR/DIBuilder.h @@ -168,12 +168,14 @@ DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy); /// Create debugging information entry for a pointer. - /// \param PointeeTy Type pointed by this pointer. - /// \param SizeInBits Size. - /// \param AlignInBits Alignment. (optional) - /// \param Name Pointer type name. (optional) + /// \param PointeeTy Type pointed by this pointer. + /// \param SizeInBits Size. + /// \param AlignInBits Alignment. (optional) + /// \param AddressSpace Address space. (optional) + /// \param Name Pointer type name. (optional) DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits = 0, + unsigned AddressSpace = 0, StringRef Name = ""); /// Create debugging information entry for a pointer to member. @@ -190,7 +192,8 @@ /// style reference or rvalue reference type. DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits = 0, - uint32_t AlignInBits = 0); + uint32_t AlignInBits = 0, + unsigned AddressSpace = 0); /// Create debugging information entry for a typedef. /// \param Ty Original type. Index: include/llvm/IR/DebugInfoMetadata.h =================================================================== --- include/llvm/IR/DebugInfoMetadata.h +++ include/llvm/IR/DebugInfoMetadata.h @@ -710,37 +710,43 @@ friend class LLVMContextImpl; friend class MDNode; + /// \brief The address space of the memory pointed to or referenced by a + /// pointer or reference type respectively. + unsigned AddressSpace; + DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag, unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, - uint64_t OffsetInBits, DIFlags Flags, ArrayRef Ops) + uint64_t OffsetInBits, unsigned AddressSpace, DIFlags Flags, + ArrayRef Ops) : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits, - AlignInBits, OffsetInBits, Flags, Ops) {} + AlignInBits, OffsetInBits, Flags, Ops), + AddressSpace(AddressSpace) {} ~DIDerivedType() = default; static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File, unsigned Line, DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits, uint32_t AlignInBits, - uint64_t OffsetInBits, DIFlags Flags, - Metadata *ExtraData, StorageType Storage, - bool ShouldCreate = true) { + uint64_t OffsetInBits, unsigned AddressSpace, + DIFlags Flags, Metadata *ExtraData, + StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, - Flags, ExtraData, Storage, ShouldCreate); + AddressSpace, Flags, ExtraData, Storage, ShouldCreate); } static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, - uint64_t OffsetInBits, DIFlags Flags, - Metadata *ExtraData, StorageType Storage, - bool ShouldCreate = true); + uint64_t OffsetInBits, unsigned AddressSpace, + DIFlags Flags, Metadata *ExtraData, + StorageType Storage, bool ShouldCreate = true); TempDIDerivedType cloneImpl() const { return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(), getScope(), getBaseType(), getSizeInBits(), - getAlignInBits(), getOffsetInBits(), getFlags(), - getExtraData()); + getAlignInBits(), getOffsetInBits(), getAddressSpace(), + getFlags(), getExtraData()); } public: @@ -748,24 +754,29 @@ (unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, - uint64_t OffsetInBits, DIFlags Flags, - Metadata *ExtraData = nullptr), + uint64_t OffsetInBits, unsigned AddressSpace, + DIFlags Flags, Metadata *ExtraData = nullptr), (Tag, Name, File, Line, Scope, BaseType, SizeInBits, - AlignInBits, OffsetInBits, Flags, ExtraData)) + AlignInBits, OffsetInBits, AddressSpace, Flags, ExtraData)) DEFINE_MDNODE_GET(DIDerivedType, (unsigned Tag, StringRef Name, DIFile *File, unsigned Line, DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, - DIFlags Flags, Metadata *ExtraData = nullptr), + unsigned AddressSpace, DIFlags Flags, + Metadata *ExtraData = nullptr), (Tag, Name, File, Line, Scope, BaseType, SizeInBits, - AlignInBits, OffsetInBits, Flags, ExtraData)) + AlignInBits, OffsetInBits, AddressSpace, Flags, ExtraData)) TempDIDerivedType clone() const { return cloneImpl(); } - //// Get the base type this is derived from. + /// Get the base type this is derived from. DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); } Metadata *getRawBaseType() const { return getOperand(3); } + /// \returns The address space of the memory pointed to or referenced by a + /// pointer or reference type respectively. + unsigned getAddressSpace() const { return AddressSpace; } + /// Get extra data associated with this derived type. /// /// Class type for pointer-to-members, objective-c property node for ivars, Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -248,7 +248,10 @@ /// Branch relaxation, which must happen after block placement, can /// on some targets (e.g. SystemZ) expose additional post-RA /// scheduling opportunities. - virtual bool targetSchedulesPostRAScheduling() const { return false; }; + virtual bool targetSchedulesPostRAScheduling() const { return false; } + + /// True if subtarget supports more than one address space. + virtual bool targetSupportsMultipleAddressSpaces() const { return false; } void getNameWithPrefix(SmallVectorImpl &Name, const GlobalValue *GV, Mangler &Mang, bool MayAlwaysUsePrivate = false) const; Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -3908,7 +3908,8 @@ /// ParseDIDerivedType: /// ::= !DIDerivedType(tag: DW_TAG_pointer_type, name: "int", file: !0, /// line: 7, scope: !1, baseType: !2, size: 32, -/// align: 32, offset: 0, flags: 0, extraData: !3) +/// align: 32, offset: 0, addressSpace: 1, flags: 0, +/// extraData: !3) bool LLParser::ParseDIDerivedType(MDNode *&Result, bool IsDistinct) { #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ REQUIRED(tag, DwarfTagField, ); \ @@ -3920,6 +3921,7 @@ OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \ OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \ + OPTIONAL(addressSpace, MDUnsignedField, (0, UINT32_MAX)); \ OPTIONAL(flags, DIFlagField, ); \ OPTIONAL(extraData, MDField, ); PARSE_MD_FIELDS(); @@ -3928,7 +3930,8 @@ Result = GET_OR_DISTINCT(DIDerivedType, (Context, tag.Val, name.Val, file.Val, line.Val, scope.Val, baseType.Val, size.Val, align.Val, - offset.Val, flags.Val, extraData.Val)); + offset.Val, addressSpace.Val, flags.Val, + extraData.Val)); return false; } Index: lib/Bitcode/Reader/MetadataLoader.cpp =================================================================== --- lib/Bitcode/Reader/MetadataLoader.cpp +++ lib/Bitcode/Reader/MetadataLoader.cpp @@ -1070,10 +1070,18 @@ break; } case bitc::METADATA_DERIVED_TYPE: { - if (Record.size() != 12) + if (Record.size() < 12 || Record.size() > 13) return error("Invalid record"); IsDistinct = Record[0]; + + unsigned AddressSpace = 0; + if (Record.size() > 12) { + if (Record[12] > (uint64_t)std::numeric_limits::max()) + return error("Address space value is too large"); + AddressSpace = Record[12]; + } + DINode::DIFlags Flags = static_cast(Record[10]); MetadataList.assignValue( GET_OR_DISTINCT(DIDerivedType, @@ -1081,7 +1089,8 @@ getMDOrNull(Record[3]), Record[4], getDITypeRefOrNull(Record[5]), getDITypeRefOrNull(Record[6]), Record[7], Record[8], - Record[9], Flags, getDITypeRefOrNull(Record[11]))), + Record[9], AddressSpace, Flags, + getDITypeRefOrNull(Record[11]))), NextMetadataNo); NextMetadataNo++; break; Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1472,6 +1472,7 @@ Record.push_back(N->getOffsetInBits()); Record.push_back(N->getFlags()); Record.push_back(VE.getMetadataOrNullID(N->getExtraData())); + Record.push_back(N->getAddressSpace()); Stream.EmitRecord(bitc::METADATA_DERIVED_TYPE, Record, Abbrev); Record.clear(); Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -841,6 +841,14 @@ // Add source line info if available and TyDesc is not a forward declaration. if (!DTy->isForwardDecl()) addSourceLine(Buffer, DTy); + + // If target supports more than one address space, then add + // DW_AT_address_class for pointer and reference types. + if (Asm->TM.targetSupportsMultipleAddressSpaces() && + (Tag == dwarf::DW_TAG_pointer_type || + Tag == dwarf::DW_TAG_reference_type)) + addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4, + DTy->getAddressSpace()); } void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args) { Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -1612,6 +1612,7 @@ Printer.printInt("size", N->getSizeInBits()); Printer.printInt("align", N->getAlignInBits()); Printer.printInt("offset", N->getOffsetInBits()); + Printer.printInt("addressSpace", N->getAddressSpace()); Printer.printDIFlags("flags", N->getFlags()); Printer.printMetadata("extraData", N->getRawExtraData()); Out << ")"; Index: lib/IR/DIBuilder.cpp =================================================================== --- lib/IR/DIBuilder.cpp +++ lib/IR/DIBuilder.cpp @@ -241,17 +241,18 @@ DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0, - 0, 0, DINode::FlagZero); + 0, 0, 0, DINode::FlagZero); } DIDerivedType *DIBuilder::createPointerType(DIType *PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits, + unsigned AddressSpace, StringRef Name) { // FIXME: Why is there a name here? return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name, nullptr, 0, nullptr, PointeeTy, SizeInBits, - AlignInBits, 0, DINode::FlagZero); + AlignInBits, 0, AddressSpace, DINode::FlagZero); } DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, @@ -261,15 +262,17 @@ DINode::DIFlags Flags) { return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "", nullptr, 0, nullptr, PointeeTy, SizeInBits, - AlignInBits, 0, Flags, Base); + AlignInBits, 0, 0, Flags, Base); } DIDerivedType *DIBuilder::createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits, - uint32_t AlignInBits) { + uint32_t AlignInBits, + unsigned AddressSpace) { assert(RTy && "Unable to create reference type"); return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy, - SizeInBits, AlignInBits, 0, DINode::FlagZero); + SizeInBits, AlignInBits, 0, AddressSpace, + DINode::FlagZero); } DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name, @@ -277,14 +280,14 @@ DIScope *Context) { return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File, LineNo, getNonCompileUnitScope(Context), Ty, 0, 0, - 0, DINode::FlagZero); + 0, 0, DINode::FlagZero); } DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) { assert(Ty && "Invalid type!"); assert(FriendTy && "Invalid friend type!"); return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty, - FriendTy, 0, 0, 0, DINode::FlagZero); + FriendTy, 0, 0, 0, 0, DINode::FlagZero); } DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, @@ -292,7 +295,7 @@ DINode::DIFlags Flags) { assert(Ty && "Unable to create inheritance"); return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, - 0, Ty, BaseTy, 0, 0, BaseOffset, Flags); + 0, Ty, BaseTy, 0, 0, BaseOffset, 0, Flags); } DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, @@ -303,7 +306,7 @@ DINode::DIFlags Flags, DIType *Ty) { return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, getNonCompileUnitScope(Scope), Ty, - SizeInBits, AlignInBits, OffsetInBits, Flags); + SizeInBits, AlignInBits, OffsetInBits, 0, Flags); } static ConstantAsMetadata *getConstantOrNull(Constant *C) { @@ -320,7 +323,7 @@ return DIDerivedType::get( VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0, - OffsetInBits, Flags, + OffsetInBits, 0, Flags, ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64), StorageOffsetInBits))); } @@ -333,7 +336,7 @@ Flags |= DINode::FlagStaticMember; return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, getNonCompileUnitScope(Scope), Ty, 0, - AlignInBits, 0, Flags, getConstantOrNull(Val)); + AlignInBits, 0, 0, Flags, getConstantOrNull(Val)); } DIDerivedType * @@ -343,7 +346,7 @@ DIType *Ty, MDNode *PropertyNode) { return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, getNonCompileUnitScope(File), Ty, - SizeInBits, AlignInBits, OffsetInBits, Flags, + SizeInBits, AlignInBits, OffsetInBits, 0, Flags, PropertyNode); } Index: lib/IR/DebugInfoMetadata.cpp =================================================================== --- lib/IR/DebugInfoMetadata.cpp +++ lib/IR/DebugInfoMetadata.cpp @@ -245,16 +245,18 @@ DIDerivedType *DIDerivedType::getImpl( LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, - uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, - Metadata *ExtraData, StorageType Storage, bool ShouldCreate) { + uint32_t AlignInBits, uint64_t OffsetInBits, unsigned AddressSpace, + DIFlags Flags, Metadata *ExtraData, StorageType Storage, + bool ShouldCreate) { assert(isCanonical(Name) && "Expected canonical MDString"); DEFINE_GETIMPL_LOOKUP(DIDerivedType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits, - AlignInBits, OffsetInBits, Flags, ExtraData)); + AlignInBits, OffsetInBits, AddressSpace, Flags, + ExtraData)); Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData}; DEFINE_GETIMPL_STORE( - DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags), - Ops); + DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, + AddressSpace, Flags), Ops); } DICompositeType *DICompositeType::getImpl( Index: lib/IR/LLVMContextImpl.h =================================================================== --- lib/IR/LLVMContextImpl.h +++ lib/IR/LLVMContextImpl.h @@ -352,22 +352,25 @@ uint64_t SizeInBits; uint64_t OffsetInBits; uint32_t AlignInBits; + unsigned AddressSpace; unsigned Flags; Metadata *ExtraData; MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, - uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, - Metadata *ExtraData) + uint32_t AlignInBits, uint64_t OffsetInBits, + unsigned AddressSpace, unsigned Flags, Metadata *ExtraData) : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope), BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits), - AlignInBits(AlignInBits), Flags(Flags), ExtraData(ExtraData) {} + AlignInBits(AlignInBits), AddressSpace(AddressSpace), Flags(Flags), + ExtraData(ExtraData) {} MDNodeKeyImpl(const DIDerivedType *N) : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), Scope(N->getRawScope()), BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()), - Flags(N->getFlags()), ExtraData(N->getRawExtraData()) {} + AddressSpace(N->getAddressSpace()), Flags(N->getFlags()), + ExtraData(N->getRawExtraData()) {} bool isKeyOf(const DIDerivedType *RHS) const { return Tag == RHS->getTag() && Name == RHS->getRawName() && @@ -375,7 +378,8 @@ Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() && SizeInBits == RHS->getSizeInBits() && AlignInBits == RHS->getAlignInBits() && - OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() && + OffsetInBits == RHS->getOffsetInBits() && + AddressSpace == RHS->getAddressSpace() && Flags == RHS->getFlags() && ExtraData == RHS->getRawExtraData(); } unsigned getHashValue() const { Index: lib/Target/AMDGPU/AMDGPUTargetMachine.h =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetMachine.h +++ lib/Target/AMDGPU/AMDGPUTargetMachine.h @@ -109,6 +109,8 @@ TargetPassConfig *createPassConfig(PassManagerBase &PM) override; const SISubtarget *getSubtargetImpl(const Function &) const override; + + bool targetSupportsMultipleAddressSpaces() const override { return true; } }; } // end namespace llvm Index: test/Assembler/debug-info.ll =================================================================== --- test/Assembler/debug-info.ll +++ test/Assembler/debug-info.ll @@ -37,8 +37,8 @@ !13 = distinct !{} !14 = !DIFile(filename: "", directory: "") -; CHECK-NEXT: !13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 32, align: 32) -!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 32, align: 32) +; CHECK-NEXT: !13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 32, align: 32, addressSpace: 1) +!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 32, align: 32, addressSpace: 1) ; CHECK-NEXT: !14 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyType", file: !10, line: 2, size: 32, align: 32, identifier: "MangledMyType") ; CHECK-NEXT: !15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Base", scope: !14, file: !10, line: 3, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !16, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !15, templateParams: !18, identifier: "MangledBase") @@ -84,4 +84,4 @@ ; CHECK-NEXT: !33 = !DIFile(filename: "file", directory: "dir") !35 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_MD5, checksum: "000102030405060708090a0b0c0d0e0f") !36 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_None) -!37 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_None, checksum: "") \ No newline at end of file +!37 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_None, checksum: "") Index: test/CodeGen/AMDGPU/debugger-pointer-address-class.ll =================================================================== --- /dev/null +++ test/CodeGen/AMDGPU/debugger-pointer-address-class.ll @@ -0,0 +1,135 @@ +; RUN: llc -O0 -mtriple=amdgcn--amdhsa -mcpu=fiji -verify-machineinstrs < %s | FileCheck %s +declare void @llvm.dbg.declare(metadata, metadata, metadata) + +@test.Var4 = internal addrspace(3) global i32 addrspace(1)* undef, align 4, !dbg !0 +@test.Var5 = internal addrspace(3) global i32 addrspace(2)* undef, align 4, !dbg !13 +@test.Var6 = internal addrspace(3) global i32 addrspace(3)* undef, align 4, !dbg !15 +@test.Var7 = internal addrspace(3) global i32* undef, align 4, !dbg !17 + +; CHECK-DAG: .long 0 ; DW_AT_address_class +; CHECK-DAG: .long 1 ; DW_AT_address_class +; CHECK-DAG: .long 2 ; DW_AT_address_class +; CHECK-DAG: .long 3 ; DW_AT_address_class + +define amdgpu_kernel void @test( + i32 addrspace(1)* %Arg0, + i32 addrspace(2)* %Arg1, + i32 addrspace(3)* %Arg2) !dbg !2 { +entry: + %Arg0.addr = alloca i32 addrspace(1)*, align 4 + %Arg1.addr = alloca i32 addrspace(2)*, align 4 + %Arg2.addr = alloca i32 addrspace(3)*, align 4 + %Tmp = alloca i32*, align 4 + %Var0 = alloca i32 addrspace(1)*, align 4 + %Var1 = alloca i32 addrspace(2)*, align 4 + %Var2 = alloca i32 addrspace(3)*, align 4 + %Var3 = alloca i32*, align 4 + %Var8 = alloca i32 addrspace(1)*, align 4 + %Var9 = alloca i32 addrspace(2)*, align 4 + %Var10 = alloca i32 addrspace(3)*, align 4 + %Var11 = alloca i32*, align 4 + store i32 addrspace(1)* %Arg0, i32 addrspace(1)** %Arg0.addr, align 4 + call void @llvm.dbg.declare(metadata i32 addrspace(1)** %Arg0.addr, metadata !28, metadata !29), !dbg !30 + store i32 addrspace(2)* %Arg1, i32 addrspace(2)** %Arg1.addr, align 4 + call void @llvm.dbg.declare(metadata i32 addrspace(2)** %Arg1.addr, metadata !31, metadata !29), !dbg !32 + store i32 addrspace(3)* %Arg2, i32 addrspace(3)** %Arg2.addr, align 4 + call void @llvm.dbg.declare(metadata i32 addrspace(3)** %Arg2.addr, metadata !33, metadata !29), !dbg !34 + call void @llvm.dbg.declare(metadata i32** %Tmp, metadata !35, metadata !29), !dbg !36 + call void @llvm.dbg.declare(metadata i32 addrspace(1)** %Var0, metadata !37, metadata !29), !dbg !38 + %0 = load i32 addrspace(1)*, i32 addrspace(1)** %Arg0.addr, align 4, !dbg !39 + store i32 addrspace(1)* %0, i32 addrspace(1)** %Var0, align 4, !dbg !38 + call void @llvm.dbg.declare(metadata i32 addrspace(2)** %Var1, metadata !40, metadata !29), !dbg !41 + %1 = load i32 addrspace(2)*, i32 addrspace(2)** %Arg1.addr, align 4, !dbg !42 + store i32 addrspace(2)* %1, i32 addrspace(2)** %Var1, align 4, !dbg !41 + call void @llvm.dbg.declare(metadata i32 addrspace(3)** %Var2, metadata !43, metadata !29), !dbg !44 + %2 = load i32 addrspace(3)*, i32 addrspace(3)** %Arg2.addr, align 4, !dbg !45 + store i32 addrspace(3)* %2, i32 addrspace(3)** %Var2, align 4, !dbg !44 + call void @llvm.dbg.declare(metadata i32** %Var3, metadata !46, metadata !29), !dbg !47 + %3 = load i32*, i32** %Tmp, align 4, !dbg !48 + store i32* %3, i32** %Var3, align 4, !dbg !47 + %4 = load i32 addrspace(1)*, i32 addrspace(1)** %Arg0.addr, align 4, !dbg !49 + store i32 addrspace(1)* %4, i32 addrspace(1)* addrspace(3)* @test.Var4, align 4, !dbg !50 + %5 = load i32 addrspace(2)*, i32 addrspace(2)** %Arg1.addr, align 4, !dbg !51 + store i32 addrspace(2)* %5, i32 addrspace(2)* addrspace(3)* @test.Var5, align 4, !dbg !52 + %6 = load i32 addrspace(3)*, i32 addrspace(3)** %Arg2.addr, align 4, !dbg !53 + store i32 addrspace(3)* %6, i32 addrspace(3)* addrspace(3)* @test.Var6, align 4, !dbg !54 + %7 = load i32*, i32** %Tmp, align 4, !dbg !55 + store i32* %7, i32* addrspace(3)* @test.Var7, align 4, !dbg !56 + call void @llvm.dbg.declare(metadata i32 addrspace(1)** %Var8, metadata !57, metadata !29), !dbg !58 + call void @llvm.dbg.declare(metadata i32 addrspace(2)** %Var9, metadata !59, metadata !29), !dbg !60 + call void @llvm.dbg.declare(metadata i32 addrspace(3)** %Var10, metadata !61, metadata !29), !dbg !62 + call void @llvm.dbg.declare(metadata i32** %Var11, metadata !63, metadata !29), !dbg !64 + ret void, !dbg !65 +} + +!llvm.dbg.cu = !{!10} +!opencl.ocl.version = !{!20} +!llvm.module.flags = !{!21, !22} +!llvm.ident = !{!23} + +!0 = !DIGlobalVariableExpression(var: !1) +!1 = distinct !DIGlobalVariable(name: "Var4", scope: !2, file: !3, line: 9, type: !6, isLocal: true, isDefinition: true) +!2 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 1, type: !4, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !10, variables: !11) +!3 = !DIFile(filename: "test.cl", directory: "/home/kzhuravl/Compute/test") +!4 = !DISubroutineType(types: !5) +!5 = !{null, !6, !8, !9} +!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, addressSpace: 1) +!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, addressSpace: 2) +!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 32, addressSpace: 3) +!10 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !11, globals: !12) +!11 = !{} +!12 = !{!0, !13, !15, !17} +!13 = !DIGlobalVariableExpression(var: !14) +!14 = distinct !DIGlobalVariable(name: "Var5", scope: !2, file: !3, line: 10, type: !8, isLocal: true, isDefinition: true) +!15 = !DIGlobalVariableExpression(var: !16) +!16 = distinct !DIGlobalVariable(name: "Var6", scope: !2, file: !3, line: 11, type: !9, isLocal: true, isDefinition: true) +!17 = !DIGlobalVariableExpression(var: !18) +!18 = distinct !DIGlobalVariable(name: "Var7", scope: !2, file: !3, line: 12, type: !19, isLocal: true, isDefinition: true) +!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 32) +!20 = !{i32 2, i32 0} +!21 = !{i32 2, !"Dwarf Version", i32 2} +!22 = !{i32 2, !"Debug Info Version", i32 3} +!23 = !{!""} +!24 = !{i32 1, i32 2, i32 3} +!25 = !{!"none", !"none", !"none"} +!26 = !{!"int*", !"int*", !"int*"} +!27 = !{!"", !"const", !""} +!28 = !DILocalVariable(name: "Arg0", arg: 1, scope: !2, file: !3, line: 1, type: !6) +!29 = !DIExpression() +!30 = !DILocation(line: 1, column: 30, scope: !2) +!31 = !DILocalVariable(name: "Arg1", arg: 2, scope: !2, file: !3, line: 1, type: !8) +!32 = !DILocation(line: 1, column: 50, scope: !2) +!33 = !DILocalVariable(name: "Arg2", arg: 3, scope: !2, file: !3, line: 1, type: !9) +!34 = !DILocation(line: 1, column: 67, scope: !2) +!35 = !DILocalVariable(name: "Tmp", scope: !2, file: !3, line: 2, type: !19) +!36 = !DILocation(line: 2, column: 16, scope: !2) +!37 = !DILocalVariable(name: "Var0", scope: !2, file: !3, line: 4, type: !6) +!38 = !DILocation(line: 4, column: 24, scope: !2) +!39 = !DILocation(line: 4, column: 31, scope: !2) +!40 = !DILocalVariable(name: "Var1", scope: !2, file: !3, line: 5, type: !8) +!41 = !DILocation(line: 5, column: 26, scope: !2) +!42 = !DILocation(line: 5, column: 33, scope: !2) +!43 = !DILocalVariable(name: "Var2", scope: !2, file: !3, line: 6, type: !9) +!44 = !DILocation(line: 6, column: 23, scope: !2) +!45 = !DILocation(line: 6, column: 30, scope: !2) +!46 = !DILocalVariable(name: "Var3", scope: !2, file: !3, line: 7, type: !19) +!47 = !DILocation(line: 7, column: 25, scope: !2) +!48 = !DILocation(line: 7, column: 32, scope: !2) +!49 = !DILocation(line: 9, column: 34, scope: !2) +!50 = !DILocation(line: 9, column: 32, scope: !2) +!51 = !DILocation(line: 10, column: 36, scope: !2) +!52 = !DILocation(line: 10, column: 34, scope: !2) +!53 = !DILocation(line: 11, column: 33, scope: !2) +!54 = !DILocation(line: 11, column: 31, scope: !2) +!55 = !DILocation(line: 12, column: 35, scope: !2) +!56 = !DILocation(line: 12, column: 33, scope: !2) +!57 = !DILocalVariable(name: "Var8", scope: !2, file: !3, line: 14, type: !6) +!58 = !DILocation(line: 14, column: 23, scope: !2) +!59 = !DILocalVariable(name: "Var9", scope: !2, file: !3, line: 15, type: !8) +!60 = !DILocation(line: 15, column: 25, scope: !2) +!61 = !DILocalVariable(name: "Var10", scope: !2, file: !3, line: 16, type: !9) +!62 = !DILocation(line: 16, column: 22, scope: !2) +!63 = !DILocalVariable(name: "Var11", scope: !2, file: !3, line: 17, type: !19) +!64 = !DILocation(line: 17, column: 24, scope: !2) +!65 = !DILocation(line: 18, column: 1, scope: !2) Index: unittests/IR/MetadataTest.cpp =================================================================== --- unittests/IR/MetadataTest.cpp +++ unittests/IR/MetadataTest.cpp @@ -103,7 +103,7 @@ DIType *getDerivedType() { return DIDerivedType::getDistinct( Context, dwarf::DW_TAG_pointer_type, "", nullptr, 0, nullptr, - getBasicType("basictype"), 1, 2, 0, DINode::FlagZero); + getBasicType("basictype"), 1, 2, 0, 0, DINode::FlagZero); } Constant *getConstant() { return ConstantInt::get(Type::getInt32Ty(Context), Counter++); @@ -1053,12 +1053,14 @@ DIScope *Scope = getSubprogram(); DIType *BaseType = getBasicType("basic"); MDTuple *ExtraData = getTuple(); + unsigned AddressSpace = 8; DINode::DIFlags Flags5 = static_cast(5); DINode::DIFlags Flags4 = static_cast(4); auto *N = DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, - 1, Scope, BaseType, 2, 3, 4, Flags5, ExtraData); + 1, Scope, BaseType, 2, 3, 4, AddressSpace, Flags5, + ExtraData); EXPECT_EQ(dwarf::DW_TAG_pointer_type, N->getTag()); EXPECT_EQ("something", N->getName()); EXPECT_EQ(File, N->getFile()); @@ -1068,45 +1070,51 @@ EXPECT_EQ(2u, N->getSizeInBits()); EXPECT_EQ(3u, N->getAlignInBits()); EXPECT_EQ(4u, N->getOffsetInBits()); + EXPECT_EQ(AddressSpace, N->getAddressSpace()); EXPECT_EQ(5u, N->getFlags()); EXPECT_EQ(ExtraData, N->getExtraData()); EXPECT_EQ(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, 1, Scope, BaseType, 2, 3, - 4, Flags5, ExtraData)); + 4, AddressSpace, Flags5, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_reference_type, "something", File, 1, Scope, BaseType, 2, 3, - 4, Flags5, ExtraData)); + 4, AddressSpace, Flags5, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "else", - File, 1, Scope, BaseType, 2, 3, 4, Flags5, - ExtraData)); + File, 1, Scope, BaseType, 2, 3, 4, + AddressSpace, Flags5, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", getFile(), 1, Scope, BaseType, 2, - 3, 4, Flags5, ExtraData)); + 3, 4, AddressSpace, Flags5, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, 2, Scope, BaseType, 2, 3, - 4, Flags5, ExtraData)); + 4, AddressSpace, Flags5, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, 1, getSubprogram(), - BaseType, 2, 3, 4, Flags5, ExtraData)); + BaseType, 2, 3, 4, AddressSpace, Flags5, + ExtraData)); EXPECT_NE(N, DIDerivedType::get( Context, dwarf::DW_TAG_pointer_type, "something", File, 1, - Scope, getBasicType("basic2"), 2, 3, 4, Flags5, ExtraData)); + Scope, getBasicType("basic2"), 2, 3, 4, AddressSpace, Flags5, + ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, 1, Scope, BaseType, 3, 3, - 4, Flags5, ExtraData)); + 4, AddressSpace, Flags5, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, 1, Scope, BaseType, 2, 2, - 4, Flags5, ExtraData)); + 4, AddressSpace, Flags5, ExtraData)); + EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, + "something", File, 1, Scope, BaseType, 2, 3, + 5, AddressSpace, Flags5, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, 1, Scope, BaseType, 2, 3, - 5, Flags5, ExtraData)); + 4, AddressSpace + 1, Flags5, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, 1, Scope, BaseType, 2, 3, - 4, Flags4, ExtraData)); + 4, AddressSpace, Flags4, ExtraData)); EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, 1, Scope, BaseType, 2, 3, - 4, Flags5, getTuple())); + 4, AddressSpace, Flags5, getTuple())); TempDIDerivedType Temp = N->clone(); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); @@ -1121,10 +1129,12 @@ auto *N = DIDerivedType::get( Context, dwarf::DW_TAG_pointer_type, "something", File, 1, Scope, - BaseType, UINT64_MAX, UINT32_MAX - 1, UINT64_MAX - 2, Flags, ExtraData); + BaseType, UINT64_MAX, UINT32_MAX - 1, UINT64_MAX - 2, UINT32_MAX - 3, + Flags, ExtraData); EXPECT_EQ(UINT64_MAX, N->getSizeInBits()); EXPECT_EQ(UINT32_MAX - 1, N->getAlignInBits()); EXPECT_EQ(UINT64_MAX - 2, N->getOffsetInBits()); + EXPECT_EQ(UINT32_MAX - 3, N->getAddressSpace()); } typedef MetadataTest DICompositeTypeTest;