LLVM 23.0.0git
DXILDebugInfo.cpp
Go to the documentation of this file.
1//===--- DXILDebugInfo.cpp - analysis&lowering for Debug info -*- 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#include "DXILDebugInfo.h"
11#include "llvm/IR/DebugInfo.h"
12#include "llvm/IR/Module.h"
13
14#define DEBUG_TYPE "dx-debug-info"
15
16using namespace llvm;
17using namespace llvm::dxil;
18
22 DIF.processModule(M);
23
24 for (DICompileUnit *CU : DIF.compile_units()) {
25 DISourceLanguageName Lang = CU->getSourceLanguage();
26 if (Lang.hasVersionedName()) {
27 auto LangName = static_cast<dwarf::SourceLanguageName>(Lang.getName());
28 Lang = dwarf::toDW_LANG(LangName, Lang.getVersion())
29 .value_or(dwarf::SourceLanguage{});
30 auto *NewCU = DICompileUnit::getDistinct(
31 M.getContext(), Lang, CU->getFile(), CU->getProducer(),
32 CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
33 CU->getSplitDebugFilename(), CU->getEmissionKind(),
34 CU->getEnumTypes(), CU->getRetainedTypes(), CU->getGlobalVariables(),
35 CU->getImportedEntities(), CU->getMacros(), CU->getDWOId(),
36 CU->getSplitDebugInlining(), CU->getDebugInfoForProfiling(),
37 CU->getNameTableKind(), CU->getRangesBaseAddress(), CU->getSysRoot(),
38 CU->getSDK());
39 Res.MDReplace.insert({CU, NewCU});
40 }
41 }
42
43 std::vector<std::pair<const DICompileUnit *, const Metadata *>> CUSubprograms;
44
45 for (const Function &F : M) {
46 if (const DISubprogram *SP = F.getSubprogram()) {
47 auto *FunctionMD = ConstantAsMetadata::get(const_cast<Function *>(&F));
48 Res.MDExtra.insert({SP, FunctionMD});
49 }
50 }
51
52 for (const DISubprogram *SP : DIF.subprograms()) {
53 if (SP->getUnit())
54 CUSubprograms.push_back(
55 {SP->getUnit(), static_cast<const Metadata *>(SP)});
56 }
57
58 std::stable_sort(
59 CUSubprograms.begin(), CUSubprograms.end(), [](auto &&A, auto &&B) {
60 return std::less<const DICompileUnit *>()(A.first, B.first);
61 });
62 for (auto It = CUSubprograms.begin(), End = CUSubprograms.end(); It != End;) {
63 const DICompileUnit *CU = It->first;
64 const DICompileUnit *NewCU =
67 do {
68 Subprograms.push_back(const_cast<Metadata *>(It->second));
69 } while (++It != End && It->first == CU);
70 const auto *SubprogramsMD = MDTuple::get(M.getContext(), Subprograms);
71 Res.MDExtra.insert({NewCU, SubprogramsMD});
72 }
73
74 return Res;
75}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:537
Wrapper structure that holds a language name and its version.
uint32_t getVersion() const
Returns language version. Only valid for versioned language names.
uint16_t getName() const
Returns a versioned or unversioned language name.
Subprogram description. Uses SubclassData1.
Utility to find all debug info in a module.
Definition DebugInfo.h:105
LLVM_ABI void processModule(const Module &M)
Process entire module and collect debug info anchors.
iterator_range< subprogram_iterator > subprograms() const
Definition DebugInfo.h:151
iterator_range< compile_unit_iterator > compile_units() const
Definition DebugInfo.h:149
ValueT lookup_or(const_arg_type_t< KeyT > Val, U &&Default) const
Definition DenseMap.h:215
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:239
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1580
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1529
Root of the metadata hierarchy.
Definition Metadata.h:64
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MDMap MDExtra
Enumerate extra metadata when Key is encountered in ValueEnumerator.
MDMap MDReplace
Completely replace one metadata with another in ValueEnumerator.
SourceLanguageName
Definition Dwarf.h:223
std::optional< SourceLanguage > toDW_LANG(SourceLanguageName name, uint32_t version)
Convert a DWARF 6 pair of language name and version to a DWARF 5 DW_LANG.
Definition Dwarf.h:231
DXILDebugInfoMap run(Module &M)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559