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();
131 bool Replace = DV->getIntrinsicID() != Intrinsic::dbg_value;
147 std::pair<Instruction *, DbgValueInst *> &
DbgValue = DbgValues[V];
148 std::pair<Instruction *, DbgValueInst *> &DbgValueFragment =
149 DbgValueFragments[{V, E}];
153 if (DbgValueFragment.first == NextNonDebugInst) {
154 DV->eraseFromParent();
161 if (DbgValueFragment.second &&
162 DbgValueFragment.second ==
DbgValue.second &&
163 DbgValueFragment.second->getValue() == DV->getValue()) {
174 if (
A.isStringAttribute() ||
175 (
A.getKindAsEnum() != Attribute::NoUnwind &&
176 A.getKindAsEnum() != Attribute::Memory))
182 std::next(DV->getIterator())));
185 DV->eraseFromParent();
189 DbgValue = DbgValueFragment = {NextNonDebugInst, NewDV};
198 if (!DV || DbgVariablesSeen.
contains(DV->getVariable()))
201 DV->eraseFromParent();
204 DbgVariablesSeen.
insert(DV->getVariable());
207 IsEntryBlock =
false;
216 [](
Metadata *M) { return isa<DILabel>(M); }),
218 SP->replaceRetainedNodes(
MDTuple::get(M.getContext(), MDs));
236 M.getContext(), Lang,
CU->getFile(),
CU->getProducer(),
237 CU->isOptimized(),
CU->getFlags(),
CU->getRuntimeVersion(),
238 CU->getSplitDebugFilename(),
CU->getEmissionKind(),
239 CU->getEnumTypes(),
CU->getRetainedTypes(),
CU->getGlobalVariables(),
240 CU->getImportedEntities(),
CU->getMacros(),
CU->getDWOId(),
241 CU->getSplitDebugInlining(),
CU->getDebugInfoForProfiling(),
242 CU->getNameTableKind(),
CU->getRangesBaseAddress(),
CU->getSysRoot(),
248 std::vector<std::pair<const DICompileUnit *, const Metadata *>> CUSubprograms;
260 static constexpr auto SupportedDIFlags =
262 static constexpr auto SupportedDISPFlags =
264 if (SP->isDistinct() || SP->getFlags() & ~SupportedDIFlags ||
265 SP->getSPFlags() & ~SupportedDISPFlags) {
267 M.getContext(), SP->getScope(), SP->getName(), SP->getLinkageName(),
268 SP->getFile(), SP->getLine(), SP->getType(), SP->getScopeLine(),
269 SP->getContainingType(), SP->getVirtualIndex(),
270 SP->getThisAdjustment(), SP->getFlags() & SupportedDIFlags,
271 SP->getSPFlags() & SupportedDISPFlags, SP->getUnit(),
272 SP->getTemplateParams(), SP->getDeclaration(), SP->getRetainedNodes(),
273 SP->getThrownTypes(), SP->getAnnotations(), SP->getTargetFuncName(),
274 SP->getKeyInstructionsEnabled());
279 const Metadata *FunctionMD = It->second;
286 CUSubprograms.push_back(
287 {SP->getUnit(),
static_cast<const Metadata *
>(SP)});
291 CUSubprograms.begin(), CUSubprograms.end(), [](
auto &&
A,
auto &&
B) {
292 return std::less<const DICompileUnit *>()(A.first, B.first);
294 for (
auto It = CUSubprograms.begin(), End = CUSubprograms.end(); It != End;) {
301 }
while (++It != End && It->first ==
CU);
302 const auto *SubprogramsMD =
MDTuple::get(M.getContext(), Subprograms);
308 GV.getDebugInfo(GVEs);
310 if (GVE->getExpression()->getNumElements())
316 It->second =
nullptr;
325 const Metadata *Scope = CB->getScope();
336 SR->getName(), SR->getSizeInBits(),
337 SR->getAlignInBits(), dwarf::DW_ATE_unsigned,
338 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.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
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)
static LLVM_ABI IntegerType * getInt1Ty(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.