Lines Matching +full:local +full:- +full:bd +full:- +full:address +full:- +full:broken

1 //===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
31 // Use FS-AFDO discriminator.
33 "enable-fs-discriminator", cl::Hidden,
45 : Variable(DII->getVariable()),
46 Fragment(DII->getExpression()->getFragmentInfo()),
47 InlinedAt(DII->getDebugLoc().getInlinedAt()) {}
50 : Variable(DVR->getVariable()),
51 Fragment(DVR->getExpression()->getFragmentInfo()),
52 InlinedAt(DVR->getDebugLoc().getInlinedAt()) {}
55 : DebugVariable(DVI->getVariable(), std::nullopt,
56 DVI->getDebugLoc()->getInlinedAt()) {}
63 "Expected a scope and optional inlined-at");
66 assert(Column < (1u << 16) && "Expected 16-bit column");
88 if (auto *N = getUniqued(Context.pImpl->DILocations,
95 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
104 Storage, Context.pImpl->DILocations);
128 LLVMContext &C = LocA->getContext();
137 // Walk through LocA and its inlined-at locations, populate them in ALocs and
138 // save the index for the subprogram and inlined-at pair, which we use to find
140 for (auto [L, I] = std::make_pair(LocA, 0U); L; L = L->getInlinedAt(), I++) {
143 {L->getScope()->getSubprogram(), L->getInlinedAt()}, I);
152 // location with the same subprogram and inlined-at location as in LocA's
153 // chain. Since the two locations have the same inlined-at location we do
155 for (auto [L, I] = std::make_pair(LocB, 0U); L; L = L->getInlinedAt(), I++) {
162 auto IT = ALookup.find({L->getScope()->getSubprogram(), L->getInlinedAt()});
166 // The + 1 is to account for the &*rev_it = &(it - 1) relationship.
167 ARIt = LocVec::reverse_iterator(ALocs.begin() + IT->second + 1);
178 // inlined-at location for the created location.
180 DILocation *InlinedAt) -> DILocation * {
182 return DILocation::get(C, L1->getLine(), L1->getColumn(), L1->getScope(),
187 if (L1->getScope()->getSubprogram() != L2->getScope()->getSubprogram())
191 auto GetNearestCommonScope = [](DIScope *S1, DIScope *S2) -> DIScope * {
193 for (; S1; S1 = S1->getScope()) {
199 for (; S2; S2 = S2->getScope()) {
209 auto Scope = GetNearestCommonScope(L1->getScope(), L2->getScope());
212 bool SameLine = L1->getLine() == L2->getLine();
213 bool SameCol = L1->getColumn() == L2->getColumn();
214 unsigned Line = SameLine ? L1->getLine() : 0;
215 unsigned Col = SameLine && SameCol ? L1->getColumn() : 0;
220 DILocation *Result = ARIt != ALocs.rend() ? (*ARIt)->getInlinedAt() : nullptr;
222 // If we have found a common starting location, walk up the inlined-at chains
230 // location in the inlined-at chains of LocA and LocB, so we break here.
241 // historically picked A's scope, and a nullptr inlined-at location, so that
244 return DILocation::get(C, 0, 0, LocA->getScope(), nullptr);
248 DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
249 std::array<unsigned, 3> Components = {BD, DF, CI};
252 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
264 RemainingWork -= C;
276 if (TBD == BD && TDF == DF && TCI == CI)
281 void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
283 BD = getUnsignedFromPrefixEncoding(D);
346 return T->getScope();
349 return SP->getScope();
352 return LB->getScope();
355 return NS->getScope();
358 return CB->getScope();
361 return M->getScope();
370 return T->getName();
372 return SP->getName();
374 return NS->getName();
376 return CB->getName();
378 return M->getName();
387 return !S || !S->getString().empty();
399 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
405 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
413 Storage, Context.pImpl->GenericDINodes);
425 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
432 "Expected non-uniqued nodes to always be created"); \
438 Storage, Context.pImpl->CLASS##s)
442 Storage, Context.pImpl->CLASS##s)
445 Storage, Context.pImpl->CLASS##s)
449 Storage, Context.pImpl->CLASS##s)
491 return BoundType(cast<ConstantInt>(MD->getValue()));
512 return BoundType(cast<ConstantInt>(MD->getValue()));
533 return BoundType(cast<ConstantInt>(MD->getValue()));
554 return BoundType(cast<ConstantInt>(MD->getValue()));
712 if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
713 return static_cast<uint32_t>(CI->getZExtValue());
719 return C->getValue();
728 return C->getValue();
734 return C->getValue();
803 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
811 if (CT->getTag() != Tag)
815 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
816 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
820 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
826 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
828 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
829 if (Ops[I] != CT->getOperand(I))
830 CT->setOperand(I, Ops[I]);
845 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
853 if (CT->getTag() != Tag)
864 return Context.pImpl->DITypeMap->lookup(&Identifier);
888 // FIXME: Implement this string-enum correspondence with a .def file and macros,
901 return ChecksumKindName[CSKind - 1];
920 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
924 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr, Source};
1034 // We're assuming virtuality is the low-order field.
1049 return Block->getScope()->getSubprogram();
1055 return File->getScope()->getNonLexicalBlockFileScope();
1066 Scope = Scope->getScope()) {
1068 CachedResult = cast<DIScope>(It->second);
1074 // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
1078 TempMDNode ClonedScope = ScopeToUpdate->clone();
1111 // Multi-bit fields can require special handling. In our case, however, the
1112 // only multi-bit field is virtuality, and all its values happen to be
1113 // single-bit values, so the right behavior just falls out.
1167 return F->getSubprogram() == this;
1311 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
1328 // This is used by the Verifier so be mindful of broken types.
1333 if (uint64_t Size = T->getSizeInBits())
1338 RawType = DT->getRawBaseType();
1373 return singleLocElts->size() > 0 &&
1380 return singleLocElts->size() > 0 &&
1386 return singleLocElts->size() == 1 &&
1393 // Uniqued DIAssignID are not supported as the instance address *is* the ID.
1428 if (I->get() + I->getSize() > E->get())
1431 uint64_t Op = I->getOp();
1442 return I->get() + I->getSize() == E->get();
1445 if (I->get() + I->getSize() == E->get())
1448 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
1455 // FIXME: A better way to implement this would be to add a local variable
1471 if (FirstOp->getOp() == dwarf::DW_OP_LLVM_arg && FirstOp->getArg(0) == 0)
1473 return I->get() == FirstOp->get() && I->getArg(0) == 1;
1568 if (ExprOpBegin->getOp() == dwarf::DW_OP_LLVM_arg) {
1569 if (ExprOpBegin->getArg(0) != 0)
1585 // An empty expression is already non-variadic.
1599 if (auto FragmentInfo = Expr->getFragmentInfo()) {
1600 UndefOps.append({dwarf::DW_OP_LLVM_fragment, FragmentInfo->OffsetInBits,
1601 FragmentInfo->SizeInBits});
1603 return DIExpression::get(Expr->getContext(), UndefOps);
1608 if (any_of(Expr->expr_ops(), [](auto ExprOp) {
1613 NewOps.reserve(Expr->getNumElements() + 2);
1615 NewOps.append(Expr->elements_begin(), Expr->elements_end());
1616 return DIExpression::get(Expr->getContext(), NewOps);
1624 if (auto Elts = Expr->getSingleLocationExpressionElements())
1625 return DIExpression::get(Expr->getContext(), *Elts);
1635 if (none_of(Expr->expr_ops(), [](auto ExprOp) {
1642 Ops.append(Expr->elements_begin(), Expr->elements_end());
1648 for (auto Op : Expr->expr_ops()) {
1675 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
1676 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
1683 std::optional<uint64_t> InitialActiveBits = Var->getSizeInBits();
1696 std::optional<DIBasicType::Signedness> VarSign = Var->getSignedness();
1726 uint64_t AbsMinusOne = -(Offset+1);
1755 Offset = -SingleLocElts[1];
1772 auto ExprOpEnd = expr_op_iterator(SingleLocEltsOpt->end());
1773 auto ExprOpIt = expr_op_iterator(SingleLocEltsOpt->begin());
1775 uint64_t Op = ExprOpIt->getOp();
1782 OffsetInBytes += ExprOpIt->getArg(0);
1784 uint64_t Value = ExprOpIt->getArg(0);
1786 if (ExprOpIt->getOp() == dwarf::DW_OP_plus)
1788 else if (ExprOpIt->getOp() == dwarf::DW_OP_minus)
1789 OffsetInBytes -= Value;
1817 auto SingleLocEltsOpt = Expr->getSingleLocationExpressionElements();
1824 SingleLocElts[PatternSize - 4] == dwarf::DW_OP_constu &&
1825 SingleLocElts[PatternSize - 2] == dwarf::DW_OP_swap &&
1826 SingleLocElts[PatternSize - 1] == dwarf::DW_OP_xderef) {
1827 AddrClass = SingleLocElts[PatternSize - 3];
1832 Expr->getContext(),
1833 ArrayRef(&*SingleLocElts.begin(), SingleLocElts.size() - PatternSize));
1859 // Handle non-variadic intrinsics by prepending the opcodes.
1860 if (!any_of(Expr->expr_ops(),
1863 "Location Index must be 0 for a non-variadic expression.");
1869 for (auto Op : Expr->expr_ops()) {
1886 return DIExpression::get(Expr->getContext(), NewOps);
1895 for (auto Op : Expr->expr_ops()) {
1905 --Arg;
1908 return DIExpression::get(Expr->getContext(), NewOps);
1927 for (auto Op : Expr->expr_ops()) {
1941 return DIExpression::get(Expr->getContext(), Ops);
1950 for (auto Op : Expr->expr_ops()) {
1963 DIExpression::get(Expr->getContext(), NewOps)->foldConstantMath();
1964 assert(result->isValid() && "concatenated expression is not valid");
1979 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
1983 std::optional<FragmentInfo> FI = Expr->getFragmentInfo();
1986 Expr->getElements().drop_back(DropUntilStackValue);
1987 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
2012 for (auto Op : Expr->expr_ops()) {
2023 // fragments because we can't express carry-over between fragments.
2036 // address. It's okay to split the value loaded from that address.
2070 Ops.push_back(ExtractOffsetInBits - OffsetInBits);
2084 assert((!Expr->isImplicit() || CanSplitValue) && "Expr can't be split");
2091 return DIExpression::get(Expr->getContext(), Ops);
2114 auto MemOffsetFromDbgInBytes = SliceStart->getPointerOffsetFrom(DbgPtr, DL);
2121 SliceOffsetInBits - (DbgPtrOffsetInBits + DbgExtractOffsetInBits);
2124 // Out-param. Invert offset to get offset from debug location.
2125 OffsetFromLocationInBits = -MemStartRelToDbgStartInBits;
2130 Result = {0, 0}; // Out-param.
2150 std::max<int64_t>(0, MemEndRelToVarInBits - MemFragStart);
2157 Result = std::nullopt; // Out-param.
2159 Result = TrimmedSliceOfVariable; // Out-param.
2166 APInt NewInt = CI->getValue();
2313 auto ExistingIt = Context.pImpl->DIArgLists.find_as(DIArgListKeyInfo(Args));
2314 if (ExistingIt != Context.pImpl->DIArgLists.end())
2317 Context.pImpl->DIArgLists.insert(NewArgList);
2328 getContext().pImpl->DIArgLists.erase(this);
2335 VM = ValueAsMetadata::get(PoisonValue::get(VM->getValue()->getType()));
2342 DIArgList *ExistingArgList = getUniqued(getContext().pImpl->DIArgLists, this);
2350 getContext().pImpl->DIArgLists.insert(this);