Ops[FileIdx] = BM->getString(FileName)->getId();
DIFile *F = DIEntry ? DIEntry->getFile() : nullptr;
- if (F && F->getRawChecksum() && !isNonSemanticDebugInfo()) {
+ if (F && F->getRawChecksum()) {
auto CheckSum = F->getChecksum().getValue();
- Ops.push_back(BM->getString("//__" + CheckSum.getKindAsString().str() +
- ":" + CheckSum.Value.str())
- ->getId());
+
+ if (!isNonSemanticDebugInfo())
+ Ops.push_back(BM->getString("//__" + CheckSum.getKindAsString().str() +
+ ":" + CheckSum.Value.str())
+ ->getId());
+ else if (BM->getDebugInfoEIS() ==
+ SPIRVEIS_NonSemantic_Shader_DebugInfo_200) {
+ SPIRVDebug::FileChecksumKind ChecksumKind =
+ SPIRV::DbgChecksumKindMap::map(CheckSum.Kind);
+
+ Ops.push_back(
+ BM->addIntegerConstant(static_cast<SPIRVTypeInt *>(getInt32Ty()),
+ ChecksumKind)
+ ->getId());
+ Ops.push_back(BM->getString(CheckSum.Value.str())->getId());
+ }
}
if (F && F->getRawSource() && isNonSemanticDebugInfo()) {
constexpr size_t MaxStrSize = MaxNumWords * 4 - 1;
const size_t NumWords = getSizeInWords(Str);
+ if (BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Shader_DebugInfo_200 &&
+ Ops.size() == MinOperandCount) {
+ Ops.push_back(getDebugInfoNoneId());
+ Ops.push_back(getDebugInfoNoneId());
+ }
Ops.push_back(BM->getString(Str.substr(0, MaxStrSize))->getId());
SPIRVExtInst *Source = static_cast<SPIRVExtInst *>(
BM->addDebugInfo(SPIRVDebug::Source, getVoidTy(), Ops));
return String->getStr();
}
-Optional<std::string>
-SPIRVToLLVMDbgTran::getStringContinued(const SPIRVId Id,
- SPIRVExtInst *DebugInst) {
- if (getDbgInst<SPIRVDebug::DebugInfoNone>(Id))
- return std::string();
+const std::string
+SPIRVToLLVMDbgTran::getStringSourceContinued(const SPIRVId Id,
+ SPIRVExtInst *DebugInst) {
+ if (!isValidId(Id) || getDbgInst<SPIRVDebug::DebugInfoNone>(Id))
+ return "";
std::string Str = BM->get<SPIRVString>(Id)->getStr();
using namespace SPIRVDebug::Operand::SourceContinued;
for (auto *I : DebugInst->getContinuedInstructions()) {
ParseChecksum(ChecksumStr));
}
- return getDIFile(getString(SourceArgs[FileIdx]), None,
- getStringContinued(SourceArgs[TextIdx], Source));
+ Optional<DIFile::ChecksumInfo<StringRef>> CS;
+ SPIRVWord StrIdx = SourceArgs[TextIdx];
+ if (Source->getExtSetKind() == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) {
+ if (!getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumKind]) &&
+ !getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumValue])) {
+ llvm::DIFile::ChecksumKind Kind = SPIRV::DbgChecksumKindMap::rmap(
+ static_cast<SPIRVDebug::FileChecksumKind>(
+ BM->get<SPIRVConstant>(SourceArgs[ChecksumKind])
+ ->getZExtIntValue()));
+ StringRef Checksum = getString(SourceArgs[ChecksumValue]);
+ size_t ChecksumEndPos = Checksum.find_if_not(llvm::isHexDigit);
+ CS.emplace(Kind, Checksum.substr(0, ChecksumEndPos));
+ }
+
+ if (SourceArgs.size() == MaxOperandCount)
+ StrIdx = SourceArgs[TextNonSemIdx];
+ else
+ StrIdx = SPIRVID_INVALID;
+ }
+
+ return getDIFile(getString(SourceArgs[FileIdx]), CS,
+ getStringSourceContinued(StrIdx, Source));
}
DIBuilder &SPIRVToLLVMDbgTran::getDIBuilder(const SPIRVExtInst *DebugInst) {
return nullptr;
}
const std::string &getString(const SPIRVId Id);
- Optional<std::string> getStringContinued(const SPIRVId Id,
- SPIRVExtInst *DebugInst);
+ const std::string getStringSourceContinued(const SPIRVId Id,
+ SPIRVExtInst *DebugInst);
SPIRVWord getConstantValueOrLiteral(const std::vector<SPIRVWord> &,
const SPIRVWord,
const SPIRVExtInstSetKind);
#include "spirv/unified1/spirv.hpp"
#include "spirv_internal.hpp"
#include "llvm/BinaryFormat/Dwarf.h"
+#include "llvm/IR/DebugInfoMetadata.h"
namespace SPIRVDebug {
ImportedDeclaration = 1,
};
+enum FileChecksumKind {
+ MD5 = 0,
+ SHA1 = 1,
+ SHA256 = 2,
+};
+
namespace Operand {
namespace CompilationUnit {
enum {
FileIdx = 0,
TextIdx = 1,
- MinOperandCount = 1
+ // For NonSemantic.Shader.DebugInfo.200
+ ChecksumKind = 1,
+ ChecksumValue = 2,
+ TextNonSemIdx = 3,
+ MinOperandCount = 1,
+ MaxOperandCount = 4
};
}
add(dwarf::DW_TAG_imported_declaration, SPIRVDebug::ImportedDeclaration);
}
+typedef SPIRVMap<llvm::DIFile::ChecksumKind, SPIRVDebug::FileChecksumKind>
+ DbgChecksumKindMap;
+template <>
+inline void DbgChecksumKindMap::init() {
+ add(llvm::DIFile::CSK_MD5, SPIRVDebug::MD5);
+ add(llvm::DIFile::CSK_SHA1, SPIRVDebug::SHA1);
+ add(llvm::DIFile::CSK_SHA256, SPIRVDebug::SHA256);
+}
+
} // namespace SPIRV
#endif // SPIRV_DEBUG_H
; ./clang -cc1 -debug-info-kind=standalone -S -emit-llvm -triple spir -gcodeview -gcodeview-ghash main.cpp
; RUN: llvm-as %s -o %t.bc
-; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix CHECK-SPIRV
+; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix CHECK-SPIRV-OCL
; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM
+; RUN: llvm-spirv %t.bc -spirv-text --spirv-debug-info-version=nonsemantic-shader-200 -o - | FileCheck %s --check-prefix CHECK-SPIRV-200
+; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -o %t.spv
+; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
+; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
+; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM
+
; ModuleID = 'source.bc'
source_filename = "main.cpp"
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
; CHECK-LLVM: !DIFile(filename: "main.cpp"
; CHECK-LLVM-SAME: checksumkind: CSK_MD5, checksum: "7bb56387968a9caa6e9e35fff94eaf7b"
-; CHECK-SPIRV: String [[#REG:]] "//__CSK_MD5:7bb56387968a9caa6e9e35fff94eaf7b"
-; CHECK-SPIRV: DebugSource
-; CHECK-SPIRV-SAME: [[#REG]]
+
+; CHECK-SPIRV-OCL: String [[#REG:]] "//__CSK_MD5:7bb56387968a9caa6e9e35fff94eaf7b"
+; CHECK-SPIRV-OCL: DebugSource [[#]] [[#REG]]
+
+; 0 means MD5
+; CHECK-SPIRV-200: String [[#Val:]] "7bb56387968a9caa6e9e35fff94eaf7b"
+; CHECK-SPIRV-200: TypeInt [[#TypeInt32:]] 32
+; CHECK-SPIRV-200: Constant [[#TypeInt32]] [[#Kind:]] 0
+; CHECK-SPIRV-200: DebugSource [[#]] [[#Kind]] [[#Val]]
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 7d09e1d7cf27ce781e83f9d388a7a3e1e6487ead)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
!1 = !DIFile(filename: "<stdin>", directory: "oneAPI", checksumkind: CSK_MD5, checksum: "7bb56387968a9caa6e9e35fff94eaf7b")
!12 = !DISubroutineType(types: !13)
!13 = !{!14}
!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!15 = !DILocation(line: 2, column: 3, scope: !10)
\ No newline at end of file
+!15 = !DILocation(line: 2, column: 3, scope: !10)
; RUN: llvm-as %s -o %t.bc\r
-; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix CHECK-SPIRV\r
+; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix CHECK-SPIRV-OCL\r
; RUN: llvm-spirv %t.bc -o %t.spv\r
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc\r
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll\r
; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM\r
\r
+; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -spirv-text -o - | FileCheck %s --check-prefix CHECK-SPIRV-200\r
+; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -o %t.spv\r
+; RUN: llvm-spirv -r %t.spv -o %t.rev.bc\r
+; RUN: llvm-dis %t.rev.bc -o %t.rev.ll\r
+; RUN: FileCheck %s --input-file %t.rev.ll --check-prefixes=CHECK-LLVM,CHECK-LLVM-200\r
+\r
; ModuleID = 'array-transform.bc'\r
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"\r
target triple = "spir64-unknown-unknown"\r
\r
; CHECK-LLVM: !DIFile(filename: "array-transform.cpp"\r
; CHECK-LLVM-SAME: checksumkind: CSK_MD5, checksum: "7768106c1e51aa084de0ffae6fbe50c4"\r
-; CHECK-SPIRV: String [[#ChecksumInfo:]] "//__CSK_MD5:7768106c1e51aa084de0ffae6fbe50c4"\r
-; CHECK-SPIRV: DebugSource\r
-; CHECK-SPIRV-SAME: [[#ChecksumInfo]]\r
+; CHECK-LLVM-200-SAME: source: "int main() {}"\r
+\r
+; CHECK-SPIRV-OCL: String [[#ChecksumInfo:]] "//__CSK_MD5:7768106c1e51aa084de0ffae6fbe50c4"\r
+; CHECK-SPIRV-OCL: DebugSource\r
+; CHECK-SPIRV-OCL-SAME: [[#ChecksumInfo]]\r
+\r
+; CHECK-SPIRV-200: String [[#Val:]] "7768106c1e51aa084de0ffae6fbe50c4"\r
+; CHECK-SPIRV-200: String [[#Source:]] "int main() {}"\r
+; CHECK-SPIRV-200: TypeInt [[#TypeInt32:]] 32\r
+; 0 means MD5\r
+; CHECK-SPIRV-200: Constant [[#TypeInt32]] [[#Kind:]] 0\r
+; CHECK-SPIRV-200: DebugSource [[#]] [[#Kind]] [[#Val]] [[#Source]]\r
\r
!0 = !{i32 2, !"Debug Info Version", i32 3}\r
!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !2, producer: "spirv", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, imports: !3)\r
-!2 = !DIFile(filename: "array-transform.cpp", directory: "D:\\path\\to", checksumkind: CSK_MD5, checksum: "7768106c1e51aa084de0ffae6fbe50c4")\r
+!2 = !DIFile(filename: "array-transform.cpp", directory: "D:\\path\\to", checksumkind: CSK_MD5, checksum: "7768106c1e51aa084de0ffae6fbe50c4", source: "int main() {}")\r
!3 = !{}\r
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-100 -spirv-text -o %t.spt
-; RUN: FileCheck %s --input-file %t.spt --check-prefix CHECK-SPIRV
+; RUN: FileCheck %s --input-file %t.spt --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-100
; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-100 -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM
+; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -spirv-text -o %t.spt
+; RUN: FileCheck %s --input-file %t.spt --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-200
+; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -o %t.spv
+; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
+; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
+; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM
+
; CHECK-LLVM: !DIFile(filename: "t.c", directory: "/test", source: "A
; CHECK-LLVM-SAME-COUNT-200000: A
; CHECK-LLVM-SAME: MayThe4thBeWithYou
; CHECK-SPIRV-SAME-COUNT-262130: A
; CHECK-SPIRV: String [[#Str3:]] "A
; CHECK-SPIRV-SAME-COUNT-5755: A
-; CHECK-SPIRV: DebugSource [[#]] [[#Str]]
+; CHECK-SPIRV-100: DebugSource [[#]] [[#Str]]
+; CHECK-SPIRV-200: [[#NONE:]] [[#]] DebugInfoNone
+; CHECK-SPIRV-200: DebugSource [[#]] [[#NONE]] [[#NONE]] [[#Str]]
; CHECK-SPIRV: DebugSourceContinued [[#Str2]]
; CHECK-SPIRV: DebugSourceContinued [[#Str3]]