-
Notifications
You must be signed in to change notification settings - Fork 222
/
LLVMToSPIRVDbgTran.h
191 lines (161 loc) · 8.09 KB
/
LLVMToSPIRVDbgTran.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
//===- LLVMToSPIRVDbgTran.h - Converts LLVM DebugInfo to SPIR-V -*- 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 LLVM metadata to SPIR-V
//
//===----------------------------------------------------------------------===//
#ifndef LLVMTOSPIRVDBGTRAN_HPP_
#define LLVMTOSPIRVDBGTRAN_HPP_
#include "SPIRVModule.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Module.h"
using namespace llvm;
namespace SPIRV {
class LLVMToSPIRVBase;
class LLVMToSPIRVDbgTran {
public:
typedef std::vector<SPIRVWord> SPIRVWordVec;
LLVMToSPIRVDbgTran(Module *TM = nullptr, SPIRVModule *TBM = nullptr,
LLVMToSPIRVBase *Writer = nullptr)
: BM(TBM), M(TM), SPIRVWriter(Writer), VoidT(nullptr),
DebugInfoNone(nullptr) {}
void transDebugMetadata();
void setModule(Module *Mod) { M = Mod; }
// Mixing translation of regular instructions and debug info creates a mess.
// To avoid it we translate debug info intrinsics in two steps:
// 1. First time we meet debug info intrinsic during translation of a basic
// block. At this time we create corresponding SPIRV debug info instruction,
// but with dummy operands. Doing so we a) map llvm value to spirv value,
// b) get a place for SPIRV debug info intrinsic in SPIRV basic block.
// We also remember all debug intrinsics.
SPIRVValue *createDebugDeclarePlaceholder(const DbgVariableIntrinsic *DbgDecl,
SPIRVBasicBlock *BB);
SPIRVValue *createDebugValuePlaceholder(const DbgVariableIntrinsic *DbgValue,
SPIRVBasicBlock *BB);
private:
// 2. After translation of all regular instructions we deal with debug info.
// We iterate over debug intrinsics stored on the first step, get its mapped
// SPIRV instruction and tweak the operands.
void finalizeDebugDeclare(const DbgVariableIntrinsic *DbgDecl);
void finalizeDebugValue(const DbgVariableIntrinsic *DbgValue);
// Emit DebugScope and OpLine instructions
void transLocationInfo();
// Dispatcher
SPIRVEntry *transDbgEntry(const MDNode *DIEntry);
SPIRVEntry *transDbgEntryImpl(const MDNode *MDN);
// Helper methods
SPIRVType *getVoidTy();
SPIRVType *getInt32Ty();
SPIRVEntry *getScope(DIScope *SR);
SPIRVEntry *getGlobalVariable(const DIGlobalVariable *GV);
inline bool isNonSemanticDebugInfo();
void transformToConstant(std::vector<SPIRVWord> &Ops,
std::vector<SPIRVWord> Idxs);
// No debug info
SPIRVEntry *getDebugInfoNone();
SPIRVId getDebugInfoNoneId();
// Compilation unit
SPIRVEntry *transDbgCompileUnit(const DICompileUnit *CU);
/// The following methods (till the end of the file) implement translation
/// of debug instrtuctions described in the spec.
// Types
SPIRVEntry *transDbgBaseType(const DIBasicType *BT);
SPIRVEntry *transDbgPointerType(const DIDerivedType *PT);
SPIRVEntry *transDbgQualifiedType(const DIDerivedType *QT);
SPIRVEntry *transDbgArrayType(const DICompositeType *AT);
SPIRVEntry *transDbgArrayTypeOpenCL(const DICompositeType *AT);
SPIRVEntry *transDbgArrayTypeNonSemantic(const DICompositeType *AT);
SPIRVEntry *transDbgArrayTypeDynamic(const DICompositeType *AT);
SPIRVEntry *transDbgSubrangeType(const DISubrange *ST);
SPIRVEntry *transDbgStringType(const DIStringType *ST);
SPIRVEntry *transDbgTypeDef(const DIDerivedType *D);
SPIRVEntry *transDbgSubroutineType(const DISubroutineType *FT);
SPIRVEntry *transDbgEnumType(const DICompositeType *ET);
SPIRVEntry *transDbgCompositeType(const DICompositeType *CT);
SPIRVEntry *transDbgMemberType(const DIDerivedType *MT);
SPIRVEntry *transDbgMemberTypeOpenCL(const DIDerivedType *MT);
SPIRVEntry *transDbgMemberTypeNonSemantic(const DIDerivedType *MT);
SPIRVEntry *transDbgInheritance(const DIDerivedType *DT);
SPIRVEntry *transDbgPtrToMember(const DIDerivedType *DT);
// Templates
SPIRVEntry *transDbgTemplateParams(DITemplateParameterArray TPA,
const SPIRVEntry *Target);
SPIRVEntry *transDbgTemplateParameter(const DITemplateParameter *TP);
SPIRVEntry *
transDbgTemplateTemplateParameter(const DITemplateValueParameter *TP);
SPIRVEntry *transDbgTemplateParameterPack(const DITemplateValueParameter *TP);
// Global objects
SPIRVEntry *transDbgGlobalVariable(const DIGlobalVariable *GV);
SPIRVEntry *transDbgFunction(const DISubprogram *Func);
SPIRVEntry *transDbgFuncDefinition(SPIRVValue *SPVFunc, SPIRVEntry *DbgFunc);
SPIRVEntry *transDbgEntryPoint(const DISubprogram *Func, SPIRVEntry *DbgFunc);
// Location information
SPIRVEntry *transDbgScope(const DIScope *S);
SPIRVEntry *transDebugLoc(const DebugLoc &Loc, SPIRVBasicBlock *BB,
SPIRVInstruction *InsertBefore = nullptr);
SPIRVEntry *transDbgInlinedAt(const DILocation *D);
SPIRVEntry *transDbgInlinedAtNonSemanticShader200(const DILocation *D);
template <class T> SPIRVExtInst *getSource(const T *DIEntry);
SPIRVEntry *transDbgFileType(const DIFile *F);
// Generate instructions recording identifier and file where debug information
// was split to
void generateBuildIdentifierAndStoragePath(const DICompileUnit *DIEntry);
// Local Variables
SPIRVEntry *transDbgLocalVariable(const DILocalVariable *Var);
// DWARF expressions
SPIRVEntry *transDbgExpression(const DIExpression *Expr);
// Imported declarations and modules
SPIRVEntry *transDbgImportedEntry(const DIImportedEntity *IE);
// A module in programming language. Example - Fortran module, clang module.
SPIRVEntry *transDbgModule(const DIModule *IE);
// Flags
SPIRVWord mapDebugFlags(DINode::DIFlags DFlags);
SPIRVWord transDebugFlags(const DINode *DN);
SPIRVModule *BM;
Module *M;
LLVMToSPIRVBase *SPIRVWriter;
std::unordered_map<const MDNode *, SPIRVEntry *> MDMap;
std::unordered_map<std::string, SPIRVExtInst *> FileMap;
DebugInfoFinder DIF;
SPIRVType *VoidT = nullptr;
SPIRVType *Int32T = nullptr;
SPIRVEntry *DebugInfoNone;
std::unordered_map<const DICompileUnit *, SPIRVExtInst *> SPIRVCUMap;
std::vector<const DbgVariableIntrinsic *> DbgDeclareIntrinsics;
std::vector<const DbgVariableIntrinsic *> DbgValueIntrinsics;
inline static SPIRVExtInst *BuildIdentifierInsn{nullptr};
inline static SPIRVExtInst *StoragePathInsn{nullptr};
}; // class LLVMToSPIRVDbgTran
} // namespace SPIRV
#endif // LLVMTOSPIRVDBGTRAN_HPP_