forked from KhronosGroup/SPIRV-LLVM-Translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPIRVToLLVMDbgTran.h
228 lines (179 loc) · 8.6 KB
/
SPIRVToLLVMDbgTran.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//===- SPIRVToLLVMDbgTran.h - Converts SPIR-V DebugInfo to LLVM -*- C++ -*-===//
//
// The LLVM/SPIR-V Translator
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
// Copyright (c) 2018 Intel Corporation. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal with the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimers.
// Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimers in the documentation
// and/or other materials provided with the distribution.
// Neither the names of Intel Corporation, nor the names of its
// contributors may be used to endorse or promote products derived from this
// Software without specific prior written permission.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
// THE SOFTWARE.
//
//===----------------------------------------------------------------------===//
//
// This file implements translation of debug info from SPIR-V to LLVM metadata
//
//===----------------------------------------------------------------------===//
#ifndef SPIRVTOLLVMDBGTRAN_H
#define SPIRVTOLLVMDBGTRAN_H
#include "SPIRVInstruction.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DebugLoc.h"
#include <unordered_map>
namespace llvm {
class Module;
class Value;
class Instruction;
class Type;
} // namespace llvm
using namespace llvm;
namespace SPIRV {
class SPIRVToLLVM;
class SPIRVEntry;
class SPIRVFunction;
class SPIRVValue;
class SPIRVToLLVMDbgTran {
public:
typedef std::vector<SPIRVWord> SPIRVWordVec;
SPIRVToLLVMDbgTran(SPIRVModule *TBM, Module *TM, SPIRVToLLVM *Reader);
void addDbgInfoVersion();
void transDbgInfo(const SPIRVValue *SV, Value *V);
template <typename T = MDNode>
T *transDebugInst(const SPIRVExtInst *DebugInst) {
assert((DebugInst->getExtSetKind() == SPIRVEIS_Debug ||
DebugInst->getExtSetKind() == SPIRVEIS_OpenCL_DebugInfo_100 ||
DebugInst->getExtSetKind() ==
SPIRVEIS_NonSemantic_Shader_DebugInfo_100 ||
DebugInst->getExtSetKind() ==
SPIRVEIS_NonSemantic_Shader_DebugInfo_200) &&
"Unexpected extended instruction set");
auto It = DebugInstCache.find(DebugInst);
if (It != DebugInstCache.end())
return static_cast<T *>(It->second);
MDNode *Res = transDebugInstImpl(DebugInst);
DebugInstCache[DebugInst] = Res;
return static_cast<T *>(Res);
}
DbgInstPtr transDebugIntrinsic(const SPIRVExtInst *DebugInst, BasicBlock *BB);
void finalize();
llvm::DebugLoc transDebugScope(const SPIRVInstruction *Inst);
private:
DIFile *getFile(const SPIRVId SourceId);
DIFile *
getDIFile(const std::string &FileName,
std::optional<DIFile::ChecksumInfo<StringRef>> CS = std::nullopt,
std::optional<StringRef> Source = std::nullopt);
DIFile *getDIFile(const SPIRVEntry *E);
unsigned getLineNo(const SPIRVEntry *E);
MDNode *transDebugInstImpl(const SPIRVExtInst *DebugInst);
DIType *transNonNullDebugType(const SPIRVExtInst *DebugInst);
llvm::DebugLoc transDebugLocation(const SPIRVExtInst *DebugInst);
MDNode *transDebugInlined(const SPIRVExtInst *Inst);
MDNode *transDebugInlinedNonSemanticShader200(const SPIRVExtInst *Inst);
void appendToSourceLangLiteral(DICompileUnit *CompileUnit,
SPIRVWord SourceLang);
DICompileUnit *transCompilationUnit(const SPIRVExtInst *DebugInst,
const std::string CompilerVersion = "",
const std::string Flags = "");
DIBasicType *transTypeBasic(const SPIRVExtInst *DebugInst);
DIDerivedType *transTypeQualifier(const SPIRVExtInst *DebugInst);
DIType *transTypePointer(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeArray(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeArrayOpenCL(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeArrayNonSemantic(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeArrayDynamic(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeVector(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeComposite(const SPIRVExtInst *DebugInst);
DISubrange *transTypeSubrange(const SPIRVExtInst *DebugInst);
DIStringType *transTypeString(const SPIRVExtInst *DebugInst);
DINode *transTypeMember(const SPIRVExtInst *DebugInst,
const SPIRVExtInst *ParentInst = nullptr,
DIScope *Scope = nullptr);
DINode *transTypeMemberOpenCL(const SPIRVExtInst *DebugInst);
DINode *transTypeMemberNonSemantic(const SPIRVExtInst *DebugInst,
const SPIRVExtInst *ParentInst,
DIScope *Scope);
DINode *transTypeEnum(const SPIRVExtInst *DebugInst);
DINode *transTypeTemplateParameter(const SPIRVExtInst *DebugInst);
DINode *transTypeTemplateTemplateParameter(const SPIRVExtInst *DebugInst);
DINode *transTypeTemplateParameterPack(const SPIRVExtInst *DebugInst);
MDNode *transTypeTemplate(const SPIRVExtInst *DebugInst);
DINode *transTypeFunction(const SPIRVExtInst *DebugInst);
DINode *transTypePtrToMember(const SPIRVExtInst *DebugInst);
DINode *transLexicalBlock(const SPIRVExtInst *DebugInst);
DINode *transLexicalBlockDiscriminator(const SPIRVExtInst *DebugInst);
DINode *transFunction(const SPIRVExtInst *DebugInst,
bool IsMainSubprogram = false);
DINode *transFunctionDefinition(const SPIRVExtInst *DebugInst);
void transFunctionBody(DISubprogram *DIS, SPIRVId FuncId);
DINode *transFunctionDecl(const SPIRVExtInst *DebugInst);
MDNode *transEntryPoint(const SPIRVExtInst *DebugInst);
MDNode *transGlobalVariable(const SPIRVExtInst *DebugInst);
DINode *transLocalVariable(const SPIRVExtInst *DebugInst);
DINode *transTypedef(const SPIRVExtInst *DebugInst);
DINode *transTypeInheritance(const SPIRVExtInst *DebugInst,
DIType *ChildClass = nullptr);
DINode *transImportedEntry(const SPIRVExtInst *DebugInst);
DINode *transModule(const SPIRVExtInst *DebugInst);
MDNode *transExpression(const SPIRVExtInst *DebugInst);
SPIRVModule *BM;
Module *M;
std::unordered_map<SPIRVId, std::unique_ptr<DIBuilder>> BuilderMap;
SPIRVToLLVM *SPIRVReader;
bool Enable;
std::unordered_map<std::string, DIFile *> FileMap;
std::unordered_map<SPIRVId, DISubprogram *> FuncMap;
std::unordered_map<const SPIRVExtInst *, MDNode *> DebugInstCache;
struct SplitFileName {
SplitFileName(const std::string &FileName);
std::string BaseName;
std::string Path;
};
DIScope *getScope(const SPIRVEntry *ScopeInst);
SPIRVExtInst *getDbgInst(const SPIRVId Id);
DIBuilder &getDIBuilder(const SPIRVExtInst *DebugInst);
template <SPIRVWord OpCode> SPIRVExtInst *getDbgInst(const SPIRVId Id) {
if (SPIRVExtInst *DI = getDbgInst(Id)) {
if (DI->getExtOp() == OpCode) {
return DI;
}
}
return nullptr;
}
const std::string &getString(const SPIRVId Id);
const std::string getStringSourceContinued(const SPIRVId Id,
SPIRVExtInst *DebugInst);
SPIRVWord getConstantValueOrLiteral(const std::vector<SPIRVWord> &,
const SPIRVWord,
const SPIRVExtInstSetKind);
std::string findModuleProducer();
std::optional<DIFile::ChecksumInfo<StringRef>> ParseChecksum(StringRef Text);
// BuildIdentifier and StoragePath must both be set or both unset.
// If StoragePath is empty both variables are unset and not valid.
uint64_t BuildIdentifier{0};
std::string StoragePath{};
void setBuildIdentifierAndStoragePath();
};
} // namespace SPIRV
#endif // SPIRVTOLLVMDBGTRAN_H