16#include "llvm/IR/IntrinsicsDirectX.h"
20#define DEBUG_TYPE "dx-debug-info"
33 Constant *ZeroOffset = ConstantInt::get(Int64Ty, 0);
49 Function *
F = getDeclarationIfExists(&M, Intrinsic::dbg_value);
57 {FT->getParamType(0), Int64Ty, FT->getParamType(1), FT->getParamType(2)},
63 for (
User *U :
F->users()) {
70 M.convertFromNewDbgValues();
86 std::pair<Instruction *, DbgValueInst *>>
95 F.removeFnAttrs(AttrMask);
96 F.removeRetAttrs(AttrMask);
97 for (
unsigned ArgNo = 0; ArgNo !=
F.arg_size(); ++ArgNo)
98 F.removeParamAttrs(ArgNo, AttrMask);
100 bool IsEntryBlock =
true;
101 DbgVariablesSeen.
clear();
105 DbgValueFragments.
clear();
107 I.eraseMetadataIf([](
unsigned KindID,
MDNode *) {
108 return KindID == LLVMContext::MD_DIAssignID;
111 NextNonDebugInst = &
I;
115 DL->eraseFromParent();
126 std::pair<Instruction *, DbgValueInst *> &
DbgValue = DbgValues[V];
127 std::pair<Instruction *, DbgValueInst *> &DbgValueFragment =
128 DbgValueFragments[{V, E}];
132 if (DbgValueFragment.first == NextNonDebugInst) {
133 DV->eraseFromParent();
140 if (DbgValueFragment.second &&
141 DbgValueFragment.second ==
DbgValue.second &&
142 DbgValueFragment.second->getValue() == DV->getValue()) {
149 if (DV->getIntrinsicID() == Intrinsic::dbg_value) {
157 if (
A.isStringAttribute() ||
158 (
A.getKindAsEnum() != Attribute::NoUnwind &&
159 A.getKindAsEnum() != Attribute::Memory))
165 {DV->getArgOperand(0), DV->getArgOperand(1),
166 DV->getArgOperand(2)},
167 {},
"", std::next(DV->getIterator())));
170 DV->eraseFromParent();
172 DbgValue = DbgValueFragment = {NextNonDebugInst, NewDV};
181 if (!DV || DbgVariablesSeen.
contains(DV->getVariable()))
184 DV->eraseFromParent();
187 DbgVariablesSeen.
insert(DV->getVariable());
190 IsEntryBlock =
false;
199 [](
Metadata *M) { return isa<DILabel>(M); }),
201 SP->replaceRetainedNodes(
MDTuple::get(M.getContext(), MDs));
219 M.getContext(), Lang,
CU->getFile(),
CU->getProducer(),
220 CU->isOptimized(),
CU->getFlags(),
CU->getRuntimeVersion(),
221 CU->getSplitDebugFilename(),
CU->getEmissionKind(),
222 CU->getEnumTypes(),
CU->getRetainedTypes(),
CU->getGlobalVariables(),
223 CU->getImportedEntities(),
CU->getMacros(),
CU->getDWOId(),
224 CU->getSplitDebugInlining(),
CU->getDebugInfoForProfiling(),
225 CU->getNameTableKind(),
CU->getRangesBaseAddress(),
CU->getSysRoot(),
231 std::vector<std::pair<const DICompileUnit *, const Metadata *>> CUSubprograms;
243 static constexpr auto SupportedDIFlags =
245 static constexpr auto SupportedDISPFlags =
247 if (SP->isDistinct() || SP->getFlags() & ~SupportedDIFlags ||
248 SP->getSPFlags() & ~SupportedDISPFlags) {
250 M.getContext(), SP->getScope(), SP->getName(), SP->getLinkageName(),
251 SP->getFile(), SP->getLine(), SP->getType(), SP->getScopeLine(),
252 SP->getContainingType(), SP->getVirtualIndex(),
253 SP->getThisAdjustment(), SP->getFlags() & SupportedDIFlags,
254 SP->getSPFlags() & SupportedDISPFlags, SP->getUnit(),
255 SP->getTemplateParams(), SP->getDeclaration(), SP->getRetainedNodes(),
256 SP->getThrownTypes(), SP->getAnnotations(), SP->getTargetFuncName(),
257 SP->getKeyInstructionsEnabled());
262 const Metadata *FunctionMD = It->second;
269 CUSubprograms.push_back(
270 {SP->getUnit(),
static_cast<const Metadata *
>(SP)});
274 CUSubprograms.begin(), CUSubprograms.end(), [](
auto &&
A,
auto &&
B) {
275 return std::less<const DICompileUnit *>()(A.first, B.first);
277 for (
auto It = CUSubprograms.begin(), End = CUSubprograms.end(); It != End;) {
284 }
while (++It != End && It->first ==
CU);
285 const auto *SubprogramsMD =
MDTuple::get(M.getContext(), Subprograms);
291 GV.getDebugInfo(GVEs);
293 if (GVE->getExpression()->getNumElements())
299 It->second =
nullptr;
308 const Metadata *Scope = CB->getScope();
319 SR->getName(), SR->getSizeInBits(),
320 SR->getAlignInBits(), dwarf::DW_ATE_unsigned,
321 SR->getNumExtraInhabitants(),
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static void replaceDbgVariableIntr(DbgVariableIntrinsic *DVI, Function *NewF, DXILDebugInfoMap &Res)
static void replaceDbgValue(Module &M, DXILDebugInfoMap &Res)
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
Class recording the (high level) value of a variable.
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
AttributeMask & addAttribute(Attribute::AttrKind Val)
Add an attribute to the mask.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM Basic Block Representation.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setTailCall(bool IsTc=true)
This is an important base class in LLVM.
A pair of DIGlobalVariable and DIExpression.
Base class for scope-like contexts.
Wrapper structure that holds source language identity metadata that includes language name,...
uint32_t getVersion() const
Returns language version. Only valid for versioned language names.
bool hasVersionedName() const
uint16_t getName() const
Returns a versioned or unversioned language name.
Subprogram description. Uses SubclassData1.
DISPFlags
Debug info subprogram flags.
This represents the llvm.dbg.value instruction.
This is the common base class for debug info intrinsics for variables.
Utility to find all debug info in a module.
LLVM_ABI void processModule(const Module &M)
Process entire module and collect debug info anchors.
LLVM_ABI void reset()
Clear all lists.
iterator_range< global_variable_expression_iterator > global_variables() const
iterator_range< subprogram_iterator > subprograms() const
iterator_range< type_iterator > types() const
iterator_range< scope_iterator > scopes() const
iterator_range< compile_unit_iterator > compile_units() const
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
ValueT lookup_or(const_arg_type_t< KeyT > Val, U &&Default) const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
void removeFnAttrs(const AttributeMask &Attrs)
AttributeList getAttributes() const
Return the attribute list for this Function.
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Value * getOperand(unsigned i) const
LLVM Value Representation.
LLVMContext & getContext() const
All values hold a context through their type.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
InstMap InstReplace
Completely replace one instruction with another in ValueEnumerator.
MDMap MDExtra
Enumerate extra metadata when Key is encountered in ValueEnumerator.
FuncMap FuncReplace
Completely replace one function with another in ValueEnumerator.
MDMap MDReplace
Completely replace one metadata with another in ValueEnumerator.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
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.
DXILDebugInfoMap run(Module &M)
const AttributeMask & getNonDXILAttributeMask()
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
auto cast_or_null(const Y &Val)
auto reverse(ContainerTy &&C)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.