annotate mlir/lib/Target/LLVMIR/DebugTranslation.h @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===- DebugTranslation.h - MLIR to LLVM Debug conversion -------*- C++ -*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 //
anatofuz
parents:
diff changeset
9 // This file implements the translation between an MLIR debug information and
anatofuz
parents:
diff changeset
10 // the corresponding LLVMIR representation.
anatofuz
parents:
diff changeset
11 //
anatofuz
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 #ifndef MLIR_LIB_TARGET_LLVMIR_DEBUGTRANSLATION_H_
anatofuz
parents:
diff changeset
15 #define MLIR_LIB_TARGET_LLVMIR_DEBUGTRANSLATION_H_
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 #include "mlir/IR/Location.h"
anatofuz
parents:
diff changeset
18 #include "llvm/ADT/SmallString.h"
anatofuz
parents:
diff changeset
19 #include "llvm/ADT/StringMap.h"
anatofuz
parents:
diff changeset
20 #include "llvm/IR/DIBuilder.h"
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 namespace mlir {
anatofuz
parents:
diff changeset
23 class Operation;
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 namespace LLVM {
anatofuz
parents:
diff changeset
26 class LLVMFuncOp;
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 namespace detail {
anatofuz
parents:
diff changeset
29 class DebugTranslation {
anatofuz
parents:
diff changeset
30 public:
anatofuz
parents:
diff changeset
31 DebugTranslation(Operation *module, llvm::Module &llvmModule);
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 /// Finalize the translation of debug information.
anatofuz
parents:
diff changeset
34 void finalize();
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 /// Translate the given location to an llvm debug location.
anatofuz
parents:
diff changeset
37 const llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope);
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 /// Translate the debug information for the given function.
anatofuz
parents:
diff changeset
40 void translate(LLVMFuncOp func, llvm::Function &llvmFunc);
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 private:
anatofuz
parents:
diff changeset
43 /// Translate the given location to an llvm debug location with the given
anatofuz
parents:
diff changeset
44 /// scope and inlinedAt parameters.
anatofuz
parents:
diff changeset
45 const llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope,
anatofuz
parents:
diff changeset
46 const llvm::DILocation *inlinedAt);
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 /// Create an llvm debug file for the given file path.
anatofuz
parents:
diff changeset
49 llvm::DIFile *translateFile(StringRef fileName);
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 /// A mapping between mlir location+scope and the corresponding llvm debug
anatofuz
parents:
diff changeset
52 /// metadata.
anatofuz
parents:
diff changeset
53 DenseMap<std::pair<Location, llvm::DILocalScope *>, const llvm::DILocation *>
anatofuz
parents:
diff changeset
54 locationToLoc;
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 /// A mapping between filename and llvm debug file.
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
57 /// TODO: Change this to DenseMap<Identifier, ...> when we can
150
anatofuz
parents:
diff changeset
58 /// access the Identifier filename in FileLineColLoc.
anatofuz
parents:
diff changeset
59 llvm::StringMap<llvm::DIFile *> fileMap;
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 /// A string containing the current working directory of the compiler.
anatofuz
parents:
diff changeset
62 SmallString<256> currentWorkingDir;
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 /// Debug information fields.
anatofuz
parents:
diff changeset
65 llvm::DIBuilder builder;
anatofuz
parents:
diff changeset
66 llvm::LLVMContext &llvmCtx;
anatofuz
parents:
diff changeset
67 llvm::DICompileUnit *compileUnit;
anatofuz
parents:
diff changeset
68 };
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 } // end namespace detail
anatofuz
parents:
diff changeset
71 } // end namespace LLVM
anatofuz
parents:
diff changeset
72 } // end namespace mlir
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 #endif // MLIR_LIB_TARGET_LLVMIR_DEBUGTRANSLATION_H_