1//===- DXILDebugInfoMap.h - DXIL debug info serialization ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_TARGET_DIRECTX_DXILWRITER_DXILDEBUGINFOMAP_H
10#define LLVM_LIB_TARGET_DIRECTX_DXILWRITER_DXILDEBUGINFOMAP_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/IR/Function.h"
14#include "llvm/IR/Instruction.h"
15#include <memory>
16
17namespace llvm {
18namespace dxil {
19
20class DXILDebugInfoMap {
21 struct InstructionDeleter {
22 void operator()(Instruction *I) { I->deleteValue(); }
23 };
24
25public:
26 using FuncMap = DenseMap<const Function *, std::unique_ptr<Function>>;
27 using InstMap = DenseMap<const Instruction *,
28 std::unique_ptr<Instruction, InstructionDeleter>>;
29 using MDMap = DenseMap<const Metadata *, const Metadata *>;
30
31 DXILDebugInfoMap() = default;
32 DXILDebugInfoMap(const DXILDebugInfoMap &) = delete;
33 DXILDebugInfoMap(DXILDebugInfoMap &&) = default;
34
35 /// Completely replace one function with another in ValueEnumerator.
36 FuncMap FuncReplace;
37
38 /// Completely replace one instruction with another in ValueEnumerator.
39 InstMap InstReplace;
40
41 /// Enumerate extra metadata when Key is encountered in ValueEnumerator.
42 MDMap MDExtra;
43
44 /// Completely replace one metadata with another in ValueEnumerator.
45 MDMap MDReplace;
46
47 const Function &getDXILFunction(const Function &F) const {
48 auto It = FuncReplace.find(Val: &F);
49 if (It != FuncReplace.end())
50 return *It->second.get();
51 return F;
52 }
53
54 const Instruction &getDXILInstruction(const Instruction &I) const {
55 auto It = InstReplace.find(Val: &I);
56 if (It != InstReplace.end())
57 return *It->second.get();
58 return I;
59 }
60
61 const Metadata *getDXILMetadata(const Metadata *M) const {
62 return MDReplace.lookup_or(Val: M, Default&: M);
63 }
64};
65
66DXILDebugInfoMap collectDXILDebugInfo(Module &M);
67
68} // namespace dxil
69} // namespace llvm
70
71#endif // LLVM_LIB_TARGET_DIRECTX_DXILWRITER_DXILDEBUGINFOMAP_H
72