1 /*========================== begin_copyright_notice ============================
2 
3 Copyright (C) 2020-2021 Intel Corporation
4 
5 SPDX-License-Identifier: MIT
6 
7 ============================= end_copyright_notice ===========================*/
8 
9 #ifndef LIB_GENXCODEGEN_DEBUG_INFO_H
10 #define LIB_GENXCODEGEN_DEBUG_INFO_H
11 
12 #include <llvm/Pass.h>
13 #include <llvm/PassRegistry.h>
14 #include <llvm/ADT/APFloat.h>
15 #include <llvm/ADT/SmallVector.h>
16 #include <llvm/Support/Error.h>
17 
18 #include "Probe/Assertion.h"
19 
20 #include <unordered_map>
21 #include <map>
22 
23 class VISAKernel;
24 class VISABuilder;
25 class ModuleToVisaTransformInfo;
26 struct ProgramInfo;
27 
28 namespace IGC {
29   struct DebugEmitterOpts;
30 } // namespace IGC
31 
32 namespace llvm {
33 
34 class Function;
35 class Instruction;
36 class FunctionGroup;
37 class GenXModule;
38 
39 namespace genx {
40 namespace di {
41 
42 struct VisaMapping {
43   struct Mapping {
44     unsigned VisaIdx = 0;
45     const Instruction *Inst = nullptr;
46   };
47   std::vector<Mapping> V2I;
48 };
49 } // namespace di
50 } // namespace genx
51 
52 //--------------------------------------------------------------------
53 // Builds and holds the debug information for the current module
54 class GenXDebugInfo : public ModulePass {
55 
56   using ElfBin = std::vector<char>;
57   using DbgInfoStorage = std::unordered_map<const Function *, ElfBin>;
58   DbgInfoStorage ElfOutputs;
59 
60   void cleanup();
61   void processKernel(const IGC::DebugEmitterOpts &Opts, const ProgramInfo &PD);
62   void processPrimaryFunction(const IGC::DebugEmitterOpts &Opts,
63                               const ModuleToVisaTransformInfo &MVTI,
64                               const GenXModule &GM, VISABuilder &VB,
65                               const Function &PF);
66 
67 public:
68   static char ID;
69 
GenXDebugInfo()70   explicit GenXDebugInfo() : ModulePass(ID) {}
~GenXDebugInfo()71   ~GenXDebugInfo() { cleanup(); }
72 
getPassName()73   StringRef getPassName() const override { return "GenX Debug Info"; }
74   void getAnalysisUsage(AnalysisUsage &AU) const override;
75   bool runOnModule(Module &M) override;
releaseMemory()76   void releaseMemory() override { cleanup(); }
77 
getModuleDebug()78   const DbgInfoStorage &getModuleDebug() const { return ElfOutputs; }
79 };
80 
81 void initializeGenXDebugInfoPass(PassRegistry &);
82 
83 } // namespace llvm
84 
85 #endif // LIB_GENXCODEGEN_DEBUG_INFO_H
86