forked from KhronosGroup/SPIRV-LLVM-Translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPIRVToLLVMDbgTran.h
178 lines (138 loc) · 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
//===- 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 "SPIRVModule.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 &&
"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);
}
Instruction *transDebugIntrinsic(const SPIRVExtInst *DebugInst,
BasicBlock *BB);
void finalize();
private:
DIFile *getFile(const SPIRVId SourceId);
DIFile *getDIFile(const std::string &FileName);
DIFile *getDIFile(const SPIRVEntry *E);
unsigned getLineNo(const SPIRVEntry *E);
MDNode *transDebugInstImpl(const SPIRVExtInst *DebugInst);
llvm::DebugLoc transDebugLocation(const SPIRVExtInst *DebugInst);
llvm::DebugLoc transDebugScope(const SPIRVInstruction *Inst);
MDNode *transDebugInlined(const SPIRVExtInst *Inst);
DICompileUnit *transCompileUnit(const SPIRVExtInst *DebugInst);
DIBasicType *transTypeBasic(const SPIRVExtInst *DebugInst);
DIDerivedType *transTypeQualifier(const SPIRVExtInst *DebugInst);
DIType *transTypePointer(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeArray(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeVector(const SPIRVExtInst *DebugInst);
DICompositeType *transTypeComposite(const SPIRVExtInst *DebugInst);
DINode *transTypeMember(const SPIRVExtInst *DebugInst);
DINode *transTypeEnum(const SPIRVExtInst *DebugInst);
DINode *transTemplateParameter(const SPIRVExtInst *DebugInst);
DINode *transTemplateTemplateParameter(const SPIRVExtInst *DebugInst);
DINode *transTemplateParameterPack(const SPIRVExtInst *DebugInst);
MDNode *transTemplate(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);
DINode *transFunctionDecl(const SPIRVExtInst *DebugInst);
MDNode *transGlobalVariable(const SPIRVExtInst *DebugInst);
DINode *transLocalVariable(const SPIRVExtInst *DebugInst);
DINode *transTypedef(const SPIRVExtInst *DebugInst);
DINode *transInheritance(const SPIRVExtInst *DebugInst);
DINode *transImportedEntry(const SPIRVExtInst *DebugInst);
MDNode *transExpression(const SPIRVExtInst *DebugInst);
SPIRVModule *BM;
Module *M;
DIBuilder Builder;
SPIRVToLLVM *SPIRVReader;
DICompileUnit *CU;
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);
template <SPIRVWord OpCode> SPIRVExtInst *getDbgInst(const SPIRVId Id) {
if (SPIRVExtInst *DI = getDbgInst(Id)) {
if (DI->getExtOp() == OpCode) {
return DI;
}
}
return nullptr;
}
StringRef getString(const SPIRVId Id);
};
} // namespace SPIRV
#endif // SPIRVTOLLVMDBGTRAN_H