2015-02-02 19:53:21 +01:00
|
|
|
//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-02 19:53:21 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the debug info Metadata classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
|
|
|
#include "LLVMContextImpl.h"
|
|
|
|
#include "MetadataImpl.h"
|
2018-08-24 00:35:58 +02:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2015-04-07 03:21:40 +02:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2017-04-28 10:44:30 +02:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2015-02-18 21:32:57 +01:00
|
|
|
#include "llvm/IR/Function.h"
|
2017-11-07 00:15:21 +01:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2015-02-02 19:53:21 +01:00
|
|
|
|
2018-12-21 23:48:50 +01:00
|
|
|
#include <numeric>
|
|
|
|
|
2015-02-02 19:53:21 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2019-12-03 13:24:41 +01:00
|
|
|
const DIExpression::FragmentInfo DebugVariable::DefaultFragment = {
|
|
|
|
std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::min()};
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
|
[IR] Add a boolean field in DILocation to know if a line must covered or not
Summary:
Some lines have a hit counter where they should not have one.
For example, in C++, some cleanup is adding at the end of a scope represented by a '}'.
So such a line has a hit counter where a user expects to not have one.
The goal of the patch is to add this information in DILocation which is used to get the covered lines in GCOVProfiling.cpp.
A following patch in clang will add this information when generating IR (https://reviews.llvm.org/D49916).
Reviewers: marco-c, davidxl, vsk, javed.absar, rnk
Reviewed By: rnk
Subscribers: eraman, xur, danielcdh, aprantl, rnk, dblaikie, #debug-info, vsk, llvm-commits, sylvestre.ledru
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D49915
llvm-svn: 342631
2018-09-20 10:53:06 +02:00
|
|
|
unsigned Column, ArrayRef<Metadata *> MDs,
|
|
|
|
bool ImplicitCode)
|
2015-04-29 18:38:44 +02:00
|
|
|
: MDNode(C, DILocationKind, Storage, MDs) {
|
2015-02-02 19:53:21 +01:00
|
|
|
assert((MDs.size() == 1 || MDs.size() == 2) &&
|
|
|
|
"Expected a scope and optional inlined-at");
|
|
|
|
|
|
|
|
// Set line and column.
|
|
|
|
assert(Column < (1u << 16) && "Expected 16-bit column");
|
|
|
|
|
|
|
|
SubclassData32 = Line;
|
|
|
|
SubclassData16 = Column;
|
[IR] Add a boolean field in DILocation to know if a line must covered or not
Summary:
Some lines have a hit counter where they should not have one.
For example, in C++, some cleanup is adding at the end of a scope represented by a '}'.
So such a line has a hit counter where a user expects to not have one.
The goal of the patch is to add this information in DILocation which is used to get the covered lines in GCOVProfiling.cpp.
A following patch in clang will add this information when generating IR (https://reviews.llvm.org/D49916).
Reviewers: marco-c, davidxl, vsk, javed.absar, rnk
Reviewed By: rnk
Subscribers: eraman, xur, danielcdh, aprantl, rnk, dblaikie, #debug-info, vsk, llvm-commits, sylvestre.ledru
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D49915
llvm-svn: 342631
2018-09-20 10:53:06 +02:00
|
|
|
|
|
|
|
setImplicitCode(ImplicitCode);
|
2015-02-02 19:53:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void adjustColumn(unsigned &Column) {
|
|
|
|
// Set to unknown on overflow. We only have 16 bits to play with here.
|
|
|
|
if (Column >= (1u << 16))
|
|
|
|
Column = 0;
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
|
2015-02-02 19:53:21 +01:00
|
|
|
unsigned Column, Metadata *Scope,
|
[IR] Add a boolean field in DILocation to know if a line must covered or not
Summary:
Some lines have a hit counter where they should not have one.
For example, in C++, some cleanup is adding at the end of a scope represented by a '}'.
So such a line has a hit counter where a user expects to not have one.
The goal of the patch is to add this information in DILocation which is used to get the covered lines in GCOVProfiling.cpp.
A following patch in clang will add this information when generating IR (https://reviews.llvm.org/D49916).
Reviewers: marco-c, davidxl, vsk, javed.absar, rnk
Reviewed By: rnk
Subscribers: eraman, xur, danielcdh, aprantl, rnk, dblaikie, #debug-info, vsk, llvm-commits, sylvestre.ledru
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D49915
llvm-svn: 342631
2018-09-20 10:53:06 +02:00
|
|
|
Metadata *InlinedAt, bool ImplicitCode,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-06 23:50:13 +01:00
|
|
|
// Fixup column.
|
2015-02-02 19:53:21 +01:00
|
|
|
adjustColumn(Column);
|
|
|
|
|
|
|
|
if (Storage == Uniqued) {
|
[IR] Add a boolean field in DILocation to know if a line must covered or not
Summary:
Some lines have a hit counter where they should not have one.
For example, in C++, some cleanup is adding at the end of a scope represented by a '}'.
So such a line has a hit counter where a user expects to not have one.
The goal of the patch is to add this information in DILocation which is used to get the covered lines in GCOVProfiling.cpp.
A following patch in clang will add this information when generating IR (https://reviews.llvm.org/D49916).
Reviewers: marco-c, davidxl, vsk, javed.absar, rnk
Reviewed By: rnk
Subscribers: eraman, xur, danielcdh, aprantl, rnk, dblaikie, #debug-info, vsk, llvm-commits, sylvestre.ledru
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D49915
llvm-svn: 342631
2018-09-20 10:53:06 +02:00
|
|
|
if (auto *N = getUniqued(Context.pImpl->DILocations,
|
|
|
|
DILocationInfo::KeyTy(Line, Column, Scope,
|
|
|
|
InlinedAt, ImplicitCode)))
|
2015-02-02 19:53:21 +01:00
|
|
|
return N;
|
|
|
|
if (!ShouldCreate)
|
|
|
|
return nullptr;
|
|
|
|
} else {
|
|
|
|
assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<Metadata *, 2> Ops;
|
|
|
|
Ops.push_back(Scope);
|
|
|
|
if (InlinedAt)
|
|
|
|
Ops.push_back(InlinedAt);
|
[IR] Add a boolean field in DILocation to know if a line must covered or not
Summary:
Some lines have a hit counter where they should not have one.
For example, in C++, some cleanup is adding at the end of a scope represented by a '}'.
So such a line has a hit counter where a user expects to not have one.
The goal of the patch is to add this information in DILocation which is used to get the covered lines in GCOVProfiling.cpp.
A following patch in clang will add this information when generating IR (https://reviews.llvm.org/D49916).
Reviewers: marco-c, davidxl, vsk, javed.absar, rnk
Reviewed By: rnk
Subscribers: eraman, xur, danielcdh, aprantl, rnk, dblaikie, #debug-info, vsk, llvm-commits, sylvestre.ledru
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D49915
llvm-svn: 342631
2018-09-20 10:53:06 +02:00
|
|
|
return storeImpl(new (Ops.size()) DILocation(Context, Storage, Line, Column,
|
|
|
|
Ops, ImplicitCode),
|
2015-04-29 18:38:44 +02:00
|
|
|
Storage, Context.pImpl->DILocations);
|
2015-02-02 19:53:21 +01:00
|
|
|
}
|
|
|
|
|
2020-04-15 21:28:34 +02:00
|
|
|
const
|
|
|
|
DILocation *DILocation::getMergedLocations(ArrayRef<const DILocation *> Locs) {
|
|
|
|
if (Locs.empty())
|
|
|
|
return nullptr;
|
|
|
|
if (Locs.size() == 1)
|
|
|
|
return Locs[0];
|
|
|
|
auto *Merged = Locs[0];
|
|
|
|
for (auto I = std::next(Locs.begin()), E = Locs.end(); I != E; ++I) {
|
|
|
|
Merged = getMergedLocation(Merged, *I);
|
|
|
|
if (Merged == nullptr)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Merged;
|
|
|
|
}
|
|
|
|
|
2018-04-12 22:58:24 +02:00
|
|
|
const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
|
2018-08-24 00:35:58 +02:00
|
|
|
const DILocation *LocB) {
|
2017-11-07 00:15:21 +01:00
|
|
|
if (!LocA || !LocB)
|
|
|
|
return nullptr;
|
|
|
|
|
2018-08-24 00:35:58 +02:00
|
|
|
if (LocA == LocB)
|
2017-11-07 00:15:21 +01:00
|
|
|
return LocA;
|
|
|
|
|
|
|
|
SmallPtrSet<DILocation *, 5> InlinedLocationsA;
|
|
|
|
for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
|
|
|
|
InlinedLocationsA.insert(L);
|
2018-08-24 00:35:58 +02:00
|
|
|
SmallSet<std::pair<DIScope *, DILocation *>, 5> Locations;
|
|
|
|
DIScope *S = LocA->getScope();
|
|
|
|
DILocation *L = LocA->getInlinedAt();
|
|
|
|
while (S) {
|
|
|
|
Locations.insert(std::make_pair(S, L));
|
2019-05-07 04:06:37 +02:00
|
|
|
S = S->getScope();
|
2018-08-24 00:35:58 +02:00
|
|
|
if (!S && L) {
|
|
|
|
S = L->getScope();
|
|
|
|
L = L->getInlinedAt();
|
|
|
|
}
|
|
|
|
}
|
2017-11-07 00:15:21 +01:00
|
|
|
const DILocation *Result = LocB;
|
2018-08-24 00:35:58 +02:00
|
|
|
S = LocB->getScope();
|
|
|
|
L = LocB->getInlinedAt();
|
|
|
|
while (S) {
|
|
|
|
if (Locations.count(std::make_pair(S, L)))
|
2017-11-07 00:15:21 +01:00
|
|
|
break;
|
2019-05-07 04:06:37 +02:00
|
|
|
S = S->getScope();
|
2018-08-24 00:35:58 +02:00
|
|
|
if (!S && L) {
|
|
|
|
S = L->getScope();
|
|
|
|
L = L->getInlinedAt();
|
|
|
|
}
|
2017-11-07 00:15:21 +01:00
|
|
|
}
|
2018-08-25 01:30:57 +02:00
|
|
|
|
|
|
|
// If the two locations are irreconsilable, just pick one. This is misleading,
|
|
|
|
// but on the other hand, it's a "line 0" location.
|
|
|
|
if (!S || !isa<DILocalScope>(S))
|
|
|
|
S = LocA->getScope();
|
2018-08-24 00:35:58 +02:00
|
|
|
return DILocation::get(Result->getContext(), 0, 0, S, L);
|
2017-11-07 00:15:21 +01:00
|
|
|
}
|
|
|
|
|
2018-12-21 23:48:50 +01:00
|
|
|
Optional<unsigned> DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
|
2020-08-28 21:14:20 +02:00
|
|
|
std::array<unsigned, 3> Components = {BD, DF, CI};
|
2018-12-21 23:48:50 +01:00
|
|
|
uint64_t RemainingWork = 0U;
|
|
|
|
// We use RemainingWork to figure out if we have no remaining components to
|
|
|
|
// encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
|
|
|
|
// encode anything for the latter 2.
|
|
|
|
// Since any of the input components is at most 32 bits, their sum will be
|
|
|
|
// less than 34 bits, and thus RemainingWork won't overflow.
|
|
|
|
RemainingWork = std::accumulate(Components.begin(), Components.end(), RemainingWork);
|
|
|
|
|
|
|
|
int I = 0;
|
|
|
|
unsigned Ret = 0;
|
|
|
|
unsigned NextBitInsertionIndex = 0;
|
|
|
|
while (RemainingWork > 0) {
|
|
|
|
unsigned C = Components[I++];
|
|
|
|
RemainingWork -= C;
|
|
|
|
unsigned EC = encodeComponent(C);
|
|
|
|
Ret |= (EC << NextBitInsertionIndex);
|
|
|
|
NextBitInsertionIndex += encodingBits(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encoding may be unsuccessful because of overflow. We determine success by
|
|
|
|
// checking equivalence of components before & after encoding. Alternatively,
|
|
|
|
// we could determine Success during encoding, but the current alternative is
|
|
|
|
// simpler.
|
|
|
|
unsigned TBD, TDF, TCI = 0;
|
|
|
|
decodeDiscriminator(Ret, TBD, TDF, TCI);
|
|
|
|
if (TBD == BD && TDF == DF && TCI == CI)
|
|
|
|
return Ret;
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
|
|
|
|
unsigned &CI) {
|
|
|
|
BD = getUnsignedFromPrefixEncoding(D);
|
|
|
|
DF = getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(D));
|
|
|
|
CI = getUnsignedFromPrefixEncoding(
|
|
|
|
getNextComponentInDiscriminator(getNextComponentInDiscriminator(D)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-06 12:46:28 +02:00
|
|
|
DINode::DIFlags DINode::getFlag(StringRef Flag) {
|
|
|
|
return StringSwitch<DIFlags>(Flag)
|
2015-04-07 03:21:40 +02:00
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
2016-09-06 12:46:28 +02:00
|
|
|
.Default(DINode::FlagZero);
|
2015-04-07 03:21:40 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 07:57:50 +02:00
|
|
|
StringRef DINode::getFlagString(DIFlags Flag) {
|
2015-04-07 03:21:40 +02:00
|
|
|
switch (Flag) {
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) \
|
|
|
|
case Flag##NAME: \
|
|
|
|
return "DIFlag" #NAME;
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
}
|
2016-09-06 12:46:28 +02:00
|
|
|
return "";
|
2015-04-07 03:21:40 +02:00
|
|
|
}
|
|
|
|
|
2016-09-06 12:46:28 +02:00
|
|
|
DINode::DIFlags DINode::splitFlags(DIFlags Flags,
|
2016-09-06 19:03:02 +02:00
|
|
|
SmallVectorImpl<DIFlags> &SplitFlags) {
|
2016-10-26 00:11:52 +02:00
|
|
|
// Flags that are packed together need to be specially handled, so
|
|
|
|
// that, for example, we emit "DIFlagPublic" and not
|
|
|
|
// "DIFlagPrivate | DIFlagProtected".
|
2016-09-06 12:46:28 +02:00
|
|
|
if (DIFlags A = Flags & FlagAccessibility) {
|
2015-04-07 03:21:40 +02:00
|
|
|
if (A == FlagPrivate)
|
|
|
|
SplitFlags.push_back(FlagPrivate);
|
|
|
|
else if (A == FlagProtected)
|
|
|
|
SplitFlags.push_back(FlagProtected);
|
|
|
|
else
|
|
|
|
SplitFlags.push_back(FlagPublic);
|
|
|
|
Flags &= ~A;
|
|
|
|
}
|
2016-09-06 12:46:28 +02:00
|
|
|
if (DIFlags R = Flags & FlagPtrToMemberRep) {
|
2016-06-17 23:31:33 +02:00
|
|
|
if (R == FlagSingleInheritance)
|
|
|
|
SplitFlags.push_back(FlagSingleInheritance);
|
|
|
|
else if (R == FlagMultipleInheritance)
|
|
|
|
SplitFlags.push_back(FlagMultipleInheritance);
|
|
|
|
else
|
|
|
|
SplitFlags.push_back(FlagVirtualInheritance);
|
|
|
|
Flags &= ~R;
|
|
|
|
}
|
2016-10-26 00:11:52 +02:00
|
|
|
if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
|
|
|
|
Flags &= ~FlagIndirectVirtualBase;
|
|
|
|
SplitFlags.push_back(FlagIndirectVirtualBase);
|
|
|
|
}
|
2015-04-07 03:21:40 +02:00
|
|
|
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) \
|
2016-09-06 12:46:28 +02:00
|
|
|
if (DIFlags Bit = Flags & Flag##NAME) { \
|
2015-04-07 03:21:40 +02:00
|
|
|
SplitFlags.push_back(Bit); \
|
|
|
|
Flags &= ~Bit; \
|
|
|
|
}
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
return Flags;
|
|
|
|
}
|
|
|
|
|
2019-05-07 04:06:37 +02:00
|
|
|
DIScope *DIScope::getScope() const {
|
2015-04-29 18:38:44 +02:00
|
|
|
if (auto *T = dyn_cast<DIType>(this))
|
2015-04-11 19:37:23 +02:00
|
|
|
return T->getScope();
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(this))
|
2015-04-11 19:37:23 +02:00
|
|
|
return SP->getScope();
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
|
2016-04-23 23:08:00 +02:00
|
|
|
return LB->getScope();
|
2015-04-11 19:37:23 +02:00
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
if (auto *NS = dyn_cast<DINamespace>(this))
|
2016-04-23 23:08:00 +02:00
|
|
|
return NS->getScope();
|
2015-04-11 19:37:23 +02:00
|
|
|
|
Add LLVM IR debug info support for Fortran COMMON blocks
COMMON blocks are a feature of Fortran that has no direct analog in C languages, but they are similar to data sections in assembly language programming. A COMMON block is a named area of memory that holds a collection of variables. Fortran subprograms may map the COMMON block memory area to their own, possibly distinct, non-empty list of variables. A Fortran COMMON block might look like the following example.
COMMON /ALPHA/ I, J
For this construct, the compiler generates a new scope-like DI construct (!DICommonBlock) into which variables (see I, J above) can be placed. As the common block implies a range of storage with global lifetime, the !DICommonBlock refers to a !DIGlobalVariable. The Fortran variable that comprise the COMMON block are also linked via metadata to offsets within the global variable that stands for the entire common block.
@alpha_ = common global %alphabytes_ zeroinitializer, align 64, !dbg !27, !dbg !30, !dbg !33
!14 = distinct !DISubprogram(…)
!20 = distinct !DICommonBlock(scope: !14, declaration: !25, name: "alpha")
!25 = distinct !DIGlobalVariable(scope: !20, name: "common alpha", type: !24)
!27 = !DIGlobalVariableExpression(var: !25, expr: !DIExpression())
!29 = distinct !DIGlobalVariable(scope: !20, name: "i", file: !3, type: !28)
!30 = !DIGlobalVariableExpression(var: !29, expr: !DIExpression())
!31 = distinct !DIGlobalVariable(scope: !20, name: "j", file: !3, type: !28)
!32 = !DIExpression(DW_OP_plus_uconst, 4)
!33 = !DIGlobalVariableExpression(var: !31, expr: !32)
The DWARF generated for this is as follows.
DW_TAG_common_block:
DW_AT_name: alpha
DW_AT_location: @alpha_+0
DW_TAG_variable:
DW_AT_name: common alpha
DW_AT_type: array of 8 bytes
DW_AT_location: @alpha_+0
DW_TAG_variable:
DW_AT_name: i
DW_AT_type: integer*4
DW_AT_location: @Alpha+0
DW_TAG_variable:
DW_AT_name: j
DW_AT_type: integer*4
DW_AT_location: @Alpha+4
Patch by Eric Schweitz!
Differential Revision: https://reviews.llvm.org/D54327
llvm-svn: 357934
2019-04-08 21:13:55 +02:00
|
|
|
if (auto *CB = dyn_cast<DICommonBlock>(this))
|
|
|
|
return CB->getScope();
|
|
|
|
|
2015-06-30 01:03:47 +02:00
|
|
|
if (auto *M = dyn_cast<DIModule>(this))
|
2016-04-23 23:08:00 +02:00
|
|
|
return M->getScope();
|
2015-06-30 01:03:47 +02:00
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
|
2015-04-11 19:37:23 +02:00
|
|
|
"Unhandled type of scope.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
StringRef DIScope::getName() const {
|
|
|
|
if (auto *T = dyn_cast<DIType>(this))
|
2015-04-11 19:37:23 +02:00
|
|
|
return T->getName();
|
2015-04-29 18:38:44 +02:00
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(this))
|
2015-04-11 19:37:23 +02:00
|
|
|
return SP->getName();
|
2015-04-29 18:38:44 +02:00
|
|
|
if (auto *NS = dyn_cast<DINamespace>(this))
|
2015-04-11 19:37:23 +02:00
|
|
|
return NS->getName();
|
Add LLVM IR debug info support for Fortran COMMON blocks
COMMON blocks are a feature of Fortran that has no direct analog in C languages, but they are similar to data sections in assembly language programming. A COMMON block is a named area of memory that holds a collection of variables. Fortran subprograms may map the COMMON block memory area to their own, possibly distinct, non-empty list of variables. A Fortran COMMON block might look like the following example.
COMMON /ALPHA/ I, J
For this construct, the compiler generates a new scope-like DI construct (!DICommonBlock) into which variables (see I, J above) can be placed. As the common block implies a range of storage with global lifetime, the !DICommonBlock refers to a !DIGlobalVariable. The Fortran variable that comprise the COMMON block are also linked via metadata to offsets within the global variable that stands for the entire common block.
@alpha_ = common global %alphabytes_ zeroinitializer, align 64, !dbg !27, !dbg !30, !dbg !33
!14 = distinct !DISubprogram(…)
!20 = distinct !DICommonBlock(scope: !14, declaration: !25, name: "alpha")
!25 = distinct !DIGlobalVariable(scope: !20, name: "common alpha", type: !24)
!27 = !DIGlobalVariableExpression(var: !25, expr: !DIExpression())
!29 = distinct !DIGlobalVariable(scope: !20, name: "i", file: !3, type: !28)
!30 = !DIGlobalVariableExpression(var: !29, expr: !DIExpression())
!31 = distinct !DIGlobalVariable(scope: !20, name: "j", file: !3, type: !28)
!32 = !DIExpression(DW_OP_plus_uconst, 4)
!33 = !DIGlobalVariableExpression(var: !31, expr: !32)
The DWARF generated for this is as follows.
DW_TAG_common_block:
DW_AT_name: alpha
DW_AT_location: @alpha_+0
DW_TAG_variable:
DW_AT_name: common alpha
DW_AT_type: array of 8 bytes
DW_AT_location: @alpha_+0
DW_TAG_variable:
DW_AT_name: i
DW_AT_type: integer*4
DW_AT_location: @Alpha+0
DW_TAG_variable:
DW_AT_name: j
DW_AT_type: integer*4
DW_AT_location: @Alpha+4
Patch by Eric Schweitz!
Differential Revision: https://reviews.llvm.org/D54327
llvm-svn: 357934
2019-04-08 21:13:55 +02:00
|
|
|
if (auto *CB = dyn_cast<DICommonBlock>(this))
|
|
|
|
return CB->getName();
|
2015-06-30 01:03:47 +02:00
|
|
|
if (auto *M = dyn_cast<DIModule>(this))
|
|
|
|
return M->getName();
|
2015-04-29 18:38:44 +02:00
|
|
|
assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
|
|
|
|
isa<DICompileUnit>(this)) &&
|
2015-04-11 19:37:23 +02:00
|
|
|
"Unhandled type of scope.");
|
|
|
|
return "";
|
|
|
|
}
|
2015-04-07 03:21:40 +02:00
|
|
|
|
2015-02-02 21:20:56 +01:00
|
|
|
#ifndef NDEBUG
|
2015-02-02 21:01:03 +01:00
|
|
|
static bool isCanonical(const MDString *S) {
|
|
|
|
return !S || !S->getString().empty();
|
2015-02-02 20:54:05 +01:00
|
|
|
}
|
2015-02-02 21:20:56 +01:00
|
|
|
#endif
|
2015-02-02 20:54:05 +01:00
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
|
|
|
|
MDString *Header,
|
|
|
|
ArrayRef<Metadata *> DwarfOps,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-02 19:53:21 +01:00
|
|
|
unsigned Hash = 0;
|
|
|
|
if (Storage == Uniqued) {
|
2016-03-19 02:02:34 +01:00
|
|
|
GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
|
2015-04-29 18:38:44 +02:00
|
|
|
if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
|
2015-02-02 19:53:21 +01:00
|
|
|
return N;
|
|
|
|
if (!ShouldCreate)
|
|
|
|
return nullptr;
|
|
|
|
Hash = Key.getHash();
|
|
|
|
} else {
|
|
|
|
assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use a nullptr for empty headers.
|
2015-02-02 21:01:03 +01:00
|
|
|
assert(isCanonical(Header) && "Expected canonical MDString");
|
|
|
|
Metadata *PreOps[] = {Header};
|
2015-04-29 18:38:44 +02:00
|
|
|
return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
|
2015-02-02 19:53:21 +01:00
|
|
|
Context, Storage, Hash, Tag, PreOps, DwarfOps),
|
2015-04-29 18:38:44 +02:00
|
|
|
Storage, Context.pImpl->GenericDINodes);
|
2015-02-02 19:53:21 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
void GenericDINode::recalculateHash() {
|
|
|
|
setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
|
2015-02-02 19:53:21 +01:00
|
|
|
}
|
2015-02-10 01:52:32 +01:00
|
|
|
|
|
|
|
#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
|
|
|
|
#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
|
|
|
|
#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
|
|
|
|
do { \
|
|
|
|
if (Storage == Uniqued) { \
|
|
|
|
if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
|
|
|
|
CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
|
|
|
|
return N; \
|
|
|
|
if (!ShouldCreate) \
|
|
|
|
return nullptr; \
|
|
|
|
} else { \
|
|
|
|
assert(ShouldCreate && \
|
|
|
|
"Expected non-uniqued nodes to always be created"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
|
2016-04-13 19:42:56 +02:00
|
|
|
return storeImpl(new (array_lengthof(OPS)) \
|
2015-02-10 01:52:32 +01:00
|
|
|
CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
|
|
|
|
Storage, Context.pImpl->CLASS##s)
|
|
|
|
#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
|
|
|
|
return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
|
|
|
|
Storage, Context.pImpl->CLASS##s)
|
2015-02-10 02:59:57 +01:00
|
|
|
#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
|
2016-04-13 19:42:56 +02:00
|
|
|
return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
|
2015-02-10 02:59:57 +01:00
|
|
|
Storage, Context.pImpl->CLASS##s)
|
2017-04-27 01:59:52 +02:00
|
|
|
#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
|
|
|
|
return storeImpl(new (NUM_OPS) \
|
|
|
|
CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
|
|
|
|
Storage, Context.pImpl->CLASS##s)
|
2015-02-10 01:52:32 +01:00
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
|
2015-02-10 01:52:32 +01:00
|
|
|
StorageType Storage, bool ShouldCreate) {
|
[Metadata] Extend 'count' field of DISubrange to take a metadata node
Summary:
This patch extends the DISubrange 'count' field to take either a
(signed) constant integer value or a reference to a DILocalVariable
or DIGlobalVariable.
This is patch [1/3] in a series to extend LLVM's DISubrange Metadata
node to support debugging of C99 variable length arrays and vectors with
runtime length like the Scalable Vector Extension for AArch64. It is
also a first step towards representing more complex cases like arrays
in Fortran.
Reviewers: echristo, pcc, aprantl, dexonsmith, clayborg, kristof.beyls, dblaikie
Reviewed By: aprantl
Subscribers: rnk, probinson, fhahn, aemerson, rengolin, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D41695
llvm-svn: 323313
2018-01-24 10:56:07 +01:00
|
|
|
auto *CountNode = ConstantAsMetadata::get(
|
|
|
|
ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
|
2020-05-28 10:01:22 +02:00
|
|
|
auto *LB = ConstantAsMetadata::get(
|
|
|
|
ConstantInt::getSigned(Type::getInt64Ty(Context), Lo));
|
|
|
|
return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
|
|
|
|
ShouldCreate);
|
[Metadata] Extend 'count' field of DISubrange to take a metadata node
Summary:
This patch extends the DISubrange 'count' field to take either a
(signed) constant integer value or a reference to a DILocalVariable
or DIGlobalVariable.
This is patch [1/3] in a series to extend LLVM's DISubrange Metadata
node to support debugging of C99 variable length arrays and vectors with
runtime length like the Scalable Vector Extension for AArch64. It is
also a first step towards representing more complex cases like arrays
in Fortran.
Reviewers: echristo, pcc, aprantl, dexonsmith, clayborg, kristof.beyls, dblaikie
Reviewed By: aprantl
Subscribers: rnk, probinson, fhahn, aemerson, rengolin, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D41695
llvm-svn: 323313
2018-01-24 10:56:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
|
|
|
|
int64_t Lo, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2020-05-28 10:01:22 +02:00
|
|
|
auto *LB = ConstantAsMetadata::get(
|
|
|
|
ConstantInt::getSigned(Type::getInt64Ty(Context), Lo));
|
|
|
|
return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
|
|
|
|
ShouldCreate);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
|
|
|
|
Metadata *LB, Metadata *UB, Metadata *Stride,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, LB, UB, Stride));
|
|
|
|
Metadata *Ops[] = {CountNode, LB, UB, Stride};
|
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DISubrange, Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISubrange::CountType DISubrange::getCount() const {
|
|
|
|
if (!getRawCountNode())
|
|
|
|
return CountType();
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<ConstantAsMetadata>(getRawCountNode()))
|
|
|
|
return CountType(cast<ConstantInt>(MD->getValue()));
|
|
|
|
|
|
|
|
if (auto *DV = dyn_cast<DIVariable>(getRawCountNode()))
|
|
|
|
return CountType(DV);
|
|
|
|
|
|
|
|
return CountType();
|
|
|
|
}
|
|
|
|
|
|
|
|
DISubrange::BoundType DISubrange::getLowerBound() const {
|
|
|
|
Metadata *LB = getRawLowerBound();
|
|
|
|
if (!LB)
|
|
|
|
return BoundType();
|
|
|
|
|
|
|
|
assert((isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) ||
|
|
|
|
isa<DIExpression>(LB)) &&
|
|
|
|
"LowerBound must be signed constant or DIVariable or DIExpression");
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<ConstantAsMetadata>(LB))
|
|
|
|
return BoundType(cast<ConstantInt>(MD->getValue()));
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIVariable>(LB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIExpression>(LB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
return BoundType();
|
|
|
|
}
|
|
|
|
|
|
|
|
DISubrange::BoundType DISubrange::getUpperBound() const {
|
|
|
|
Metadata *UB = getRawUpperBound();
|
|
|
|
if (!UB)
|
|
|
|
return BoundType();
|
|
|
|
|
|
|
|
assert((isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) ||
|
|
|
|
isa<DIExpression>(UB)) &&
|
|
|
|
"UpperBound must be signed constant or DIVariable or DIExpression");
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<ConstantAsMetadata>(UB))
|
|
|
|
return BoundType(cast<ConstantInt>(MD->getValue()));
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIVariable>(UB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIExpression>(UB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
return BoundType();
|
|
|
|
}
|
|
|
|
|
|
|
|
DISubrange::BoundType DISubrange::getStride() const {
|
|
|
|
Metadata *ST = getRawStride();
|
|
|
|
if (!ST)
|
|
|
|
return BoundType();
|
|
|
|
|
|
|
|
assert((isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) ||
|
|
|
|
isa<DIExpression>(ST)) &&
|
|
|
|
"Stride must be signed constant or DIVariable or DIExpression");
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<ConstantAsMetadata>(ST))
|
|
|
|
return BoundType(cast<ConstantInt>(MD->getValue()));
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIVariable>(ST))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIExpression>(ST))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
return BoundType();
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2020-10-28 15:24:39 +01:00
|
|
|
DIGenericSubrange *DIGenericSubrange::getImpl(LLVMContext &Context,
|
|
|
|
Metadata *CountNode, Metadata *LB,
|
|
|
|
Metadata *UB, Metadata *Stride,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIGenericSubrange, (CountNode, LB, UB, Stride));
|
|
|
|
Metadata *Ops[] = {CountNode, LB, UB, Stride};
|
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGenericSubrange, Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIGenericSubrange::BoundType DIGenericSubrange::getCount() const {
|
|
|
|
Metadata *CB = getRawCountNode();
|
|
|
|
if (!CB)
|
|
|
|
return BoundType();
|
|
|
|
|
|
|
|
assert((isa<DIVariable>(CB) || isa<DIExpression>(CB)) &&
|
|
|
|
"Count must be signed constant or DIVariable or DIExpression");
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIVariable>(CB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIExpression>(CB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
return BoundType();
|
|
|
|
}
|
|
|
|
|
|
|
|
DIGenericSubrange::BoundType DIGenericSubrange::getLowerBound() const {
|
|
|
|
Metadata *LB = getRawLowerBound();
|
|
|
|
if (!LB)
|
|
|
|
return BoundType();
|
|
|
|
|
|
|
|
assert((isa<DIVariable>(LB) || isa<DIExpression>(LB)) &&
|
|
|
|
"LowerBound must be signed constant or DIVariable or DIExpression");
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIVariable>(LB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIExpression>(LB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
return BoundType();
|
|
|
|
}
|
|
|
|
|
|
|
|
DIGenericSubrange::BoundType DIGenericSubrange::getUpperBound() const {
|
|
|
|
Metadata *UB = getRawUpperBound();
|
|
|
|
if (!UB)
|
|
|
|
return BoundType();
|
|
|
|
|
|
|
|
assert((isa<DIVariable>(UB) || isa<DIExpression>(UB)) &&
|
|
|
|
"UpperBound must be signed constant or DIVariable or DIExpression");
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIVariable>(UB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIExpression>(UB))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
return BoundType();
|
|
|
|
}
|
|
|
|
|
|
|
|
DIGenericSubrange::BoundType DIGenericSubrange::getStride() const {
|
|
|
|
Metadata *ST = getRawStride();
|
|
|
|
if (!ST)
|
|
|
|
return BoundType();
|
|
|
|
|
|
|
|
assert((isa<DIVariable>(ST) || isa<DIExpression>(ST)) &&
|
|
|
|
"Stride must be signed constant or DIVariable or DIExpression");
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIVariable>(ST))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
if (auto *MD = dyn_cast<DIExpression>(ST))
|
|
|
|
return BoundType(MD);
|
|
|
|
|
|
|
|
return BoundType();
|
|
|
|
}
|
|
|
|
|
2020-07-01 14:07:35 +02:00
|
|
|
DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value,
|
2018-02-12 17:10:09 +01:00
|
|
|
bool IsUnsigned, MDString *Name,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2018-02-12 17:10:09 +01:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name));
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Ops[] = {Name};
|
2018-02-12 17:10:09 +01:00
|
|
|
DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
|
2015-02-20 00:56:07 +01:00
|
|
|
MDString *Name, uint64_t SizeInBits,
|
2016-10-18 16:31:22 +02:00
|
|
|
uint32_t AlignInBits, unsigned Encoding,
|
2018-08-14 21:35:34 +02:00
|
|
|
DIFlags Flags, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-03-19 02:02:34 +01:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIBasicType,
|
2018-08-14 21:35:34 +02:00
|
|
|
(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Ops[] = {nullptr, nullptr, Name};
|
2018-08-14 21:35:34 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,
|
|
|
|
Flags), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2018-07-06 19:32:39 +02:00
|
|
|
Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
|
|
|
|
switch (getEncoding()) {
|
|
|
|
case dwarf::DW_ATE_signed:
|
|
|
|
case dwarf::DW_ATE_signed_char:
|
|
|
|
return Signedness::Signed;
|
|
|
|
case dwarf::DW_ATE_unsigned:
|
|
|
|
case dwarf::DW_ATE_unsigned_char:
|
|
|
|
return Signedness::Unsigned;
|
|
|
|
default:
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-20 12:41:22 +02:00
|
|
|
DIStringType *DIStringType::getImpl(LLVMContext &Context, unsigned Tag,
|
|
|
|
MDString *Name, Metadata *StringLength,
|
|
|
|
Metadata *StringLengthExp,
|
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits,
|
|
|
|
unsigned Encoding, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIStringType, (Tag, Name, StringLength, StringLengthExp,
|
|
|
|
SizeInBits, AlignInBits, Encoding));
|
|
|
|
Metadata *Ops[] = {nullptr, nullptr, Name, StringLength, StringLengthExp};
|
|
|
|
DEFINE_GETIMPL_STORE(DIStringType, (Tag, SizeInBits, AlignInBits, Encoding),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DIDerivedType *DIDerivedType::getImpl(
|
2015-02-10 01:52:32 +01:00
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
|
2015-02-20 00:56:07 +01:00
|
|
|
unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
|
2017-03-09 00:55:44 +01:00
|
|
|
uint32_t AlignInBits, uint64_t OffsetInBits,
|
|
|
|
Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-03-19 02:02:34 +01:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIDerivedType,
|
|
|
|
(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
2017-03-09 00:55:44 +01:00
|
|
|
AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
|
|
|
|
ExtraData));
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
|
|
|
|
DEFINE_GETIMPL_STORE(
|
2017-03-09 00:55:44 +01:00
|
|
|
DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
DWARFAddressSpace, Flags), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DICompositeType *DICompositeType::getImpl(
|
2015-02-10 01:52:32 +01:00
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
|
2015-02-20 00:56:07 +01:00
|
|
|
unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
|
2016-10-18 16:31:22 +02:00
|
|
|
uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
|
2018-02-07 00:45:59 +01:00
|
|
|
Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
|
2020-07-20 16:20:37 +02:00
|
|
|
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
|
2020-10-10 14:18:35 +02:00
|
|
|
Metadata *Rank, StorageType Storage, bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-04-17 05:58:21 +02:00
|
|
|
|
2016-04-19 20:00:19 +02:00
|
|
|
// Keep this in sync with buildODRType.
|
2020-10-10 14:18:35 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(
|
|
|
|
DICompositeType,
|
|
|
|
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
|
|
|
|
OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
|
|
|
|
Identifier, Discriminator, DataLocation, Associated, Allocated, Rank));
|
2020-05-15 07:54:27 +02:00
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType,
|
|
|
|
Elements, VTableHolder, TemplateParams, Identifier,
|
2020-10-10 14:18:35 +02:00
|
|
|
Discriminator, DataLocation, Associated, Allocated,
|
|
|
|
Rank};
|
2015-04-29 18:38:44 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
|
2015-02-10 01:52:32 +01:00
|
|
|
AlignInBits, OffsetInBits, Flags),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2016-04-19 20:00:19 +02:00
|
|
|
DICompositeType *DICompositeType::buildODRType(
|
|
|
|
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
|
|
|
|
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
|
2016-10-18 16:31:22 +02:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
|
2016-09-06 12:46:28 +02:00
|
|
|
DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
|
2020-05-15 07:54:27 +02:00
|
|
|
Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
|
2020-10-10 14:18:35 +02:00
|
|
|
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
|
|
|
|
Metadata *Rank) {
|
2016-04-19 20:00:19 +02:00
|
|
|
assert(!Identifier.getString().empty() && "Expected valid identifier");
|
|
|
|
if (!Context.isODRUniquingDebugTypes())
|
|
|
|
return nullptr;
|
|
|
|
auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
|
|
|
|
if (!CT)
|
|
|
|
return CT = DICompositeType::getDistinct(
|
|
|
|
Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
|
2020-05-15 07:54:27 +02:00
|
|
|
VTableHolder, TemplateParams, &Identifier, Discriminator,
|
2020-10-10 14:18:35 +02:00
|
|
|
DataLocation, Associated, Allocated, Rank);
|
2016-04-19 20:00:19 +02:00
|
|
|
|
|
|
|
// Only mutate CT if it's a forward declaration and the new operands aren't.
|
|
|
|
assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
|
|
|
|
if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
|
|
|
|
return CT;
|
|
|
|
|
|
|
|
// Mutate CT in place. Keep this in sync with getImpl.
|
|
|
|
CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
Flags);
|
2020-05-15 07:54:27 +02:00
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType,
|
|
|
|
Elements, VTableHolder, TemplateParams, &Identifier,
|
2020-10-10 14:18:35 +02:00
|
|
|
Discriminator, DataLocation, Associated, Allocated,
|
|
|
|
Rank};
|
2016-05-02 18:45:02 +02:00
|
|
|
assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
|
2016-04-19 20:00:19 +02:00
|
|
|
"Mismatched number of operands");
|
|
|
|
for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
|
|
|
|
if (Ops[I] != CT->getOperand(I))
|
|
|
|
CT->setOperand(I, Ops[I]);
|
|
|
|
return CT;
|
|
|
|
}
|
|
|
|
|
2016-04-19 16:55:09 +02:00
|
|
|
DICompositeType *DICompositeType::getODRType(
|
|
|
|
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
|
|
|
|
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
|
2016-10-18 16:31:22 +02:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
|
2016-09-06 12:46:28 +02:00
|
|
|
DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
|
2020-05-15 07:54:27 +02:00
|
|
|
Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
|
2020-10-10 14:18:35 +02:00
|
|
|
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
|
|
|
|
Metadata *Rank) {
|
2016-04-19 16:55:09 +02:00
|
|
|
assert(!Identifier.getString().empty() && "Expected valid identifier");
|
|
|
|
if (!Context.isODRUniquingDebugTypes())
|
|
|
|
return nullptr;
|
|
|
|
auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
|
|
|
|
if (!CT)
|
|
|
|
CT = DICompositeType::getDistinct(
|
|
|
|
Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
|
2020-07-20 16:20:37 +02:00
|
|
|
TemplateParams, &Identifier, Discriminator, DataLocation, Associated,
|
2020-10-10 14:18:35 +02:00
|
|
|
Allocated, Rank);
|
2016-04-19 16:55:09 +02:00
|
|
|
return CT;
|
|
|
|
}
|
|
|
|
|
|
|
|
DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
|
|
|
|
MDString &Identifier) {
|
|
|
|
assert(!Identifier.getString().empty() && "Expected valid identifier");
|
|
|
|
if (!Context.isODRUniquingDebugTypes())
|
|
|
|
return nullptr;
|
|
|
|
return Context.pImpl->DITypeMap->lookup(&Identifier);
|
|
|
|
}
|
|
|
|
|
2016-09-06 19:03:02 +02:00
|
|
|
DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
|
|
|
|
uint8_t CC, Metadata *TypeArray,
|
2015-02-10 01:52:32 +01:00
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2016-06-08 22:34:29 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
|
2015-07-24 22:56:36 +02:00
|
|
|
Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
|
2016-06-08 22:34:29 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2017-09-19 20:14:45 +02:00
|
|
|
// FIXME: Implement this string-enum correspondence with a .def file and macros,
|
|
|
|
// so that the association is explicit rather than implied.
|
2018-02-12 20:45:54 +01:00
|
|
|
static const char *ChecksumKindName[DIFile::CSK_Last] = {
|
2020-03-13 00:25:01 +01:00
|
|
|
"CSK_MD5",
|
|
|
|
"CSK_SHA1",
|
|
|
|
"CSK_SHA256",
|
2016-12-25 11:12:09 +01:00
|
|
|
};
|
|
|
|
|
2018-02-12 20:45:54 +01:00
|
|
|
StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
|
|
|
|
assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
|
|
|
|
// The first space was originally the CSK_None variant, which is now
|
|
|
|
// obsolete, but the space is still reserved in ChecksumKind, so we account
|
|
|
|
// for it here.
|
|
|
|
return ChecksumKindName[CSKind - 1];
|
2016-12-25 11:12:09 +01:00
|
|
|
}
|
|
|
|
|
2018-02-12 20:45:54 +01:00
|
|
|
Optional<DIFile::ChecksumKind> DIFile::getChecksumKind(StringRef CSKindStr) {
|
|
|
|
return StringSwitch<Optional<DIFile::ChecksumKind>>(CSKindStr)
|
|
|
|
.Case("CSK_MD5", DIFile::CSK_MD5)
|
|
|
|
.Case("CSK_SHA1", DIFile::CSK_SHA1)
|
2020-03-13 00:25:01 +01:00
|
|
|
.Case("CSK_SHA256", DIFile::CSK_SHA256)
|
2018-02-12 20:45:54 +01:00
|
|
|
.Default(None);
|
2016-12-25 11:12:09 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
|
2018-02-12 20:45:54 +01:00
|
|
|
MDString *Directory,
|
|
|
|
Optional<DIFile::ChecksumInfo<MDString *>> CS,
|
2018-02-24 00:01:06 +01:00
|
|
|
Optional<MDString *> Source, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Filename) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(Directory) && "Expected canonical MDString");
|
2018-02-12 20:45:54 +01:00
|
|
|
assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
|
2018-02-24 00:01:06 +01:00
|
|
|
assert((!Source || isCanonical(*Source)) && "Expected canonical MDString");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS, Source));
|
|
|
|
Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr,
|
|
|
|
Source.getValueOr(nullptr)};
|
|
|
|
DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DICompileUnit *DICompileUnit::getImpl(
|
2015-02-10 01:52:32 +01:00
|
|
|
LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
|
|
|
|
MDString *Producer, bool IsOptimized, MDString *Flags,
|
|
|
|
unsigned RuntimeVersion, MDString *SplitDebugFilename,
|
|
|
|
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
|
2016-04-15 17:57:41 +02:00
|
|
|
Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
|
Change debug-info-for-profiling from a TargetOption to a function attribute.
Summary: LTO requires the debug-info-for-profiling to be a function attribute.
Reviewers: echristo, mehdi_amini, dblaikie, probinson, aprantl
Reviewed By: mehdi_amini, dblaikie, aprantl
Subscribers: aprantl, probinson, ahatanak, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D29203
llvm-svn: 293833
2017-02-01 23:45:09 +01:00
|
|
|
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
|
2020-01-14 22:37:04 +01:00
|
|
|
unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
|
2020-03-04 23:12:54 +01:00
|
|
|
MDString *SDK, StorageType Storage, bool ShouldCreate) {
|
2015-08-03 19:26:41 +02:00
|
|
|
assert(Storage != Uniqued && "Cannot unique DICompileUnit");
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Producer) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(Flags) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
|
2015-08-03 19:26:41 +02:00
|
|
|
|
2020-03-04 23:12:54 +01:00
|
|
|
Metadata *Ops[] = {File,
|
|
|
|
Producer,
|
|
|
|
Flags,
|
|
|
|
SplitDebugFilename,
|
|
|
|
EnumTypes,
|
|
|
|
RetainedTypes,
|
|
|
|
GlobalVariables,
|
|
|
|
ImportedEntities,
|
|
|
|
Macros,
|
|
|
|
SysRoot,
|
|
|
|
SDK};
|
2017-09-12 23:50:41 +02:00
|
|
|
return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
|
|
|
|
Context, Storage, SourceLanguage, IsOptimized,
|
|
|
|
RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
|
2018-11-13 21:08:10 +01:00
|
|
|
DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
|
|
|
|
Ops),
|
2015-08-03 19:26:41 +02:00
|
|
|
Storage);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2016-04-01 01:56:58 +02:00
|
|
|
Optional<DICompileUnit::DebugEmissionKind>
|
|
|
|
DICompileUnit::getEmissionKind(StringRef Str) {
|
|
|
|
return StringSwitch<Optional<DebugEmissionKind>>(Str)
|
|
|
|
.Case("NoDebug", NoDebug)
|
|
|
|
.Case("FullDebug", FullDebug)
|
|
|
|
.Case("LineTablesOnly", LineTablesOnly)
|
2018-08-01 21:38:20 +02:00
|
|
|
.Case("DebugDirectivesOnly", DebugDirectivesOnly)
|
2016-04-01 01:56:58 +02:00
|
|
|
.Default(None);
|
|
|
|
}
|
|
|
|
|
2018-08-16 23:29:55 +02:00
|
|
|
Optional<DICompileUnit::DebugNameTableKind>
|
|
|
|
DICompileUnit::getNameTableKind(StringRef Str) {
|
|
|
|
return StringSwitch<Optional<DebugNameTableKind>>(Str)
|
|
|
|
.Case("Default", DebugNameTableKind::Default)
|
|
|
|
.Case("GNU", DebugNameTableKind::GNU)
|
|
|
|
.Case("None", DebugNameTableKind::None)
|
|
|
|
.Default(None);
|
|
|
|
}
|
|
|
|
|
2018-07-06 21:26:00 +02:00
|
|
|
const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
|
2016-04-01 01:56:58 +02:00
|
|
|
switch (EK) {
|
|
|
|
case NoDebug: return "NoDebug";
|
|
|
|
case FullDebug: return "FullDebug";
|
|
|
|
case LineTablesOnly: return "LineTablesOnly";
|
2018-08-23 19:43:40 +02:00
|
|
|
case DebugDirectivesOnly: return "DebugDirectivesOnly";
|
2016-04-01 01:56:58 +02:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-08-16 23:29:55 +02:00
|
|
|
const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
|
|
|
|
switch (NTK) {
|
|
|
|
case DebugNameTableKind::Default:
|
|
|
|
return nullptr;
|
|
|
|
case DebugNameTableKind::GNU:
|
|
|
|
return "GNU";
|
|
|
|
case DebugNameTableKind::None:
|
|
|
|
return "None";
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DISubprogram *DILocalScope::getSubprogram() const {
|
|
|
|
if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
|
2015-03-30 23:32:28 +02:00
|
|
|
return Block->getScope()->getSubprogram();
|
2015-04-29 18:38:44 +02:00
|
|
|
return const_cast<DISubprogram *>(cast<DISubprogram>(this));
|
2015-03-30 23:32:28 +02:00
|
|
|
}
|
|
|
|
|
2016-04-21 18:58:49 +02:00
|
|
|
DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
|
|
|
|
if (auto *File = dyn_cast<DILexicalBlockFile>(this))
|
|
|
|
return File->getScope()->getNonLexicalBlockFileScope();
|
|
|
|
return const_cast<DILocalScope *>(this);
|
|
|
|
}
|
|
|
|
|
2018-11-28 22:14:32 +01:00
|
|
|
DISubprogram::DISPFlags DISubprogram::getFlag(StringRef Flag) {
|
|
|
|
return StringSwitch<DISPFlags>(Flag)
|
|
|
|
#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
.Default(SPFlagZero);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef DISubprogram::getFlagString(DISPFlags Flag) {
|
|
|
|
switch (Flag) {
|
2018-11-29 22:13:51 +01:00
|
|
|
// Appease a warning.
|
|
|
|
case SPFlagVirtuality:
|
2018-11-28 22:14:32 +01:00
|
|
|
return "";
|
|
|
|
#define HANDLE_DISP_FLAG(ID, NAME) \
|
|
|
|
case SPFlag##NAME: \
|
|
|
|
return "DISPFlag" #NAME;
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
DISubprogram::DISPFlags
|
|
|
|
DISubprogram::splitFlags(DISPFlags Flags,
|
|
|
|
SmallVectorImpl<DISPFlags> &SplitFlags) {
|
|
|
|
// Multi-bit fields can require special handling. In our case, however, the
|
|
|
|
// only multi-bit field is virtuality, and all its values happen to be
|
|
|
|
// single-bit values, so the right behavior just falls out.
|
|
|
|
#define HANDLE_DISP_FLAG(ID, NAME) \
|
|
|
|
if (DISPFlags Bit = Flags & SPFlag##NAME) { \
|
|
|
|
SplitFlags.push_back(Bit); \
|
|
|
|
Flags &= ~Bit; \
|
|
|
|
}
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
return Flags;
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DISubprogram *DISubprogram::getImpl(
|
2015-02-10 01:52:32 +01:00
|
|
|
LLVMContext &Context, Metadata *Scope, MDString *Name,
|
|
|
|
MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
|
2018-11-19 19:29:28 +01:00
|
|
|
unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
|
|
|
|
int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 04:40:45 +02:00
|
|
|
Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
|
2017-04-27 00:56:44 +02:00
|
|
|
Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(LinkageName) && "Expected canonical MDString");
|
2018-11-19 19:29:28 +01:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubprogram,
|
|
|
|
(Scope, Name, LinkageName, File, Line, Type, ScopeLine,
|
|
|
|
ContainingType, VirtualIndex, ThisAdjustment, Flags,
|
|
|
|
SPFlags, Unit, TemplateParams, Declaration,
|
|
|
|
RetainedNodes, ThrownTypes));
|
2017-04-27 01:59:52 +02:00
|
|
|
SmallVector<Metadata *, 11> Ops = {
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 04:40:45 +02:00
|
|
|
File, Scope, Name, LinkageName, Type, Unit,
|
|
|
|
Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes};
|
2017-04-27 01:59:52 +02:00
|
|
|
if (!ThrownTypes) {
|
|
|
|
Ops.pop_back();
|
|
|
|
if (!TemplateParams) {
|
|
|
|
Ops.pop_back();
|
|
|
|
if (!ContainingType)
|
|
|
|
Ops.pop_back();
|
|
|
|
}
|
|
|
|
}
|
2018-11-19 19:29:28 +01:00
|
|
|
DEFINE_GETIMPL_STORE_N(
|
|
|
|
DISubprogram,
|
|
|
|
(Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags), Ops,
|
|
|
|
Ops.size());
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
bool DISubprogram::describes(const Function *F) const {
|
2015-04-13 21:07:27 +02:00
|
|
|
assert(F && "Invalid function");
|
2020-03-02 18:39:27 +01:00
|
|
|
return F->getSubprogram() == this;
|
2015-04-13 21:07:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *File, unsigned Line,
|
|
|
|
unsigned Column, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-08-29 00:58:50 +02:00
|
|
|
// Fixup column.
|
|
|
|
adjustColumn(Column);
|
|
|
|
|
2015-03-30 18:37:48 +02:00
|
|
|
assert(Scope && "Expected scope");
|
2015-04-29 18:38:44 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Ops[] = {File, Scope};
|
2015-04-29 18:38:44 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Scope, Metadata *File,
|
|
|
|
unsigned Discriminator,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-03-30 18:37:48 +02:00
|
|
|
assert(Scope && "Expected scope");
|
2015-04-29 18:38:44 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Ops[] = {File, Scope};
|
2015-04-29 18:38:44 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
|
2017-04-29 00:25:46 +02:00
|
|
|
MDString *Name, bool ExportSymbols,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2017-04-29 00:25:46 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
|
|
|
|
// The nullptr is for DIScope's File operand. This should be refactored.
|
|
|
|
Metadata *Ops[] = {nullptr, Scope, Name};
|
|
|
|
DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
Add LLVM IR debug info support for Fortran COMMON blocks
COMMON blocks are a feature of Fortran that has no direct analog in C languages, but they are similar to data sections in assembly language programming. A COMMON block is a named area of memory that holds a collection of variables. Fortran subprograms may map the COMMON block memory area to their own, possibly distinct, non-empty list of variables. A Fortran COMMON block might look like the following example.
COMMON /ALPHA/ I, J
For this construct, the compiler generates a new scope-like DI construct (!DICommonBlock) into which variables (see I, J above) can be placed. As the common block implies a range of storage with global lifetime, the !DICommonBlock refers to a !DIGlobalVariable. The Fortran variable that comprise the COMMON block are also linked via metadata to offsets within the global variable that stands for the entire common block.
@alpha_ = common global %alphabytes_ zeroinitializer, align 64, !dbg !27, !dbg !30, !dbg !33
!14 = distinct !DISubprogram(…)
!20 = distinct !DICommonBlock(scope: !14, declaration: !25, name: "alpha")
!25 = distinct !DIGlobalVariable(scope: !20, name: "common alpha", type: !24)
!27 = !DIGlobalVariableExpression(var: !25, expr: !DIExpression())
!29 = distinct !DIGlobalVariable(scope: !20, name: "i", file: !3, type: !28)
!30 = !DIGlobalVariableExpression(var: !29, expr: !DIExpression())
!31 = distinct !DIGlobalVariable(scope: !20, name: "j", file: !3, type: !28)
!32 = !DIExpression(DW_OP_plus_uconst, 4)
!33 = !DIGlobalVariableExpression(var: !31, expr: !32)
The DWARF generated for this is as follows.
DW_TAG_common_block:
DW_AT_name: alpha
DW_AT_location: @alpha_+0
DW_TAG_variable:
DW_AT_name: common alpha
DW_AT_type: array of 8 bytes
DW_AT_location: @alpha_+0
DW_TAG_variable:
DW_AT_name: i
DW_AT_type: integer*4
DW_AT_location: @Alpha+0
DW_TAG_variable:
DW_AT_name: j
DW_AT_type: integer*4
DW_AT_location: @Alpha+4
Patch by Eric Schweitz!
Differential Revision: https://reviews.llvm.org/D54327
llvm-svn: 357934
2019-04-08 21:13:55 +02:00
|
|
|
DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
|
|
|
|
Metadata *Decl, MDString *Name,
|
|
|
|
Metadata *File, unsigned LineNo,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DICommonBlock, (Scope, Decl, Name, File, LineNo));
|
|
|
|
// The nullptr is for DIScope's File operand. This should be refactored.
|
|
|
|
Metadata *Ops[] = {Scope, Decl, Name, File};
|
|
|
|
DEFINE_GETIMPL_STORE(DICommonBlock, (LineNo), Ops);
|
|
|
|
}
|
|
|
|
|
2020-05-08 08:01:41 +02:00
|
|
|
DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File,
|
|
|
|
Metadata *Scope, MDString *Name,
|
|
|
|
MDString *ConfigurationMacros,
|
2020-03-04 01:05:23 +01:00
|
|
|
MDString *IncludePath, MDString *APINotesFile,
|
2020-12-17 17:08:46 +01:00
|
|
|
unsigned LineNo, bool IsDecl, StorageType Storage,
|
2020-05-08 08:01:41 +02:00
|
|
|
bool ShouldCreate) {
|
2015-06-30 01:03:47 +02:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2020-05-08 08:01:41 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIModule, (File, Scope, Name, ConfigurationMacros,
|
2020-12-17 17:08:46 +01:00
|
|
|
IncludePath, APINotesFile, LineNo, IsDecl));
|
2020-05-08 08:01:41 +02:00
|
|
|
Metadata *Ops[] = {File, Scope, Name, ConfigurationMacros,
|
|
|
|
IncludePath, APINotesFile};
|
2020-12-17 17:08:46 +01:00
|
|
|
DEFINE_GETIMPL_STORE(DIModule, (LineNo, IsDecl), Ops);
|
2015-06-30 01:03:47 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 06:22:12 +01:00
|
|
|
DITemplateTypeParameter *
|
|
|
|
DITemplateTypeParameter::getImpl(LLVMContext &Context, MDString *Name,
|
|
|
|
Metadata *Type, bool isDefault,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2020-03-02 06:22:12 +01:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type, isDefault));
|
2015-02-19 01:37:21 +01:00
|
|
|
Metadata *Ops[] = {Name, Type};
|
2020-03-02 06:22:12 +01:00
|
|
|
DEFINE_GETIMPL_STORE(DITemplateTypeParameter, (isDefault), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DITemplateValueParameter *DITemplateValueParameter::getImpl(
|
2015-02-19 01:37:21 +01:00
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
|
2020-03-02 06:22:12 +01:00
|
|
|
bool isDefault, Metadata *Value, StorageType Storage, bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2020-03-02 06:22:12 +01:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter,
|
|
|
|
(Tag, Name, Type, isDefault, Value));
|
2015-02-19 01:37:21 +01:00
|
|
|
Metadata *Ops[] = {Name, Type, Value};
|
2020-03-02 06:22:12 +01:00
|
|
|
DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag, isDefault), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DIGlobalVariable *
|
|
|
|
DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
|
2015-02-10 01:52:32 +01:00
|
|
|
MDString *LinkageName, Metadata *File, unsigned Line,
|
|
|
|
Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
|
|
|
|
Metadata *StaticDataMemberDeclaration,
|
2018-10-03 20:44:53 +02:00
|
|
|
Metadata *TemplateParams, uint32_t AlignInBits,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(LinkageName) && "Expected canonical MDString");
|
2018-10-03 20:44:53 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIGlobalVariable, (Scope, Name, LinkageName, File, Line,
|
|
|
|
Type, IsLocalToUnit, IsDefinition,
|
|
|
|
StaticDataMemberDeclaration,
|
|
|
|
TemplateParams, AlignInBits));
|
|
|
|
Metadata *Ops[] = {Scope,
|
|
|
|
Name,
|
|
|
|
File,
|
|
|
|
Type,
|
|
|
|
Name,
|
|
|
|
LinkageName,
|
|
|
|
StaticDataMemberDeclaration,
|
|
|
|
TemplateParams};
|
2016-10-20 02:13:12 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DIGlobalVariable,
|
2018-10-03 20:44:53 +02:00
|
|
|
(Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-07-31 20:58:39 +02:00
|
|
|
DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
|
|
|
|
MDString *Name, Metadata *File,
|
|
|
|
unsigned Line, Metadata *Type,
|
2016-09-06 12:46:28 +02:00
|
|
|
unsigned Arg, DIFlags Flags,
|
2016-10-26 23:32:29 +02:00
|
|
|
uint32_t AlignInBits,
|
2015-07-31 20:58:39 +02:00
|
|
|
StorageType Storage,
|
2015-04-16 00:29:27 +02:00
|
|
|
bool ShouldCreate) {
|
2015-04-28 03:07:33 +02:00
|
|
|
// 64K ought to be enough for any frontend.
|
|
|
|
assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
|
2015-02-13 02:39:44 +01:00
|
|
|
|
2015-03-27 18:56:39 +01:00
|
|
|
assert(Scope && "Expected scope");
|
2015-02-10 01:52:32 +01:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-07-31 20:58:39 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DILocalVariable,
|
2016-10-20 02:13:12 +02:00
|
|
|
(Scope, Name, File, Line, Type, Arg, Flags,
|
|
|
|
AlignInBits));
|
2015-04-16 00:29:27 +02:00
|
|
|
Metadata *Ops[] = {Scope, Name, File, Type};
|
2016-10-20 02:13:12 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2017-11-28 01:57:51 +01:00
|
|
|
Optional<uint64_t> DIVariable::getSizeInBits() const {
|
|
|
|
// This is used by the Verifier so be mindful of broken types.
|
|
|
|
const Metadata *RawType = getRawType();
|
|
|
|
while (RawType) {
|
|
|
|
// Try to get the size directly.
|
|
|
|
if (auto *T = dyn_cast<DIType>(RawType))
|
|
|
|
if (uint64_t Size = T->getSizeInBits())
|
|
|
|
return Size;
|
|
|
|
|
|
|
|
if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
|
|
|
|
// Look at the base type.
|
|
|
|
RawType = DT->getRawBaseType();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Missing type or size.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fail gracefully.
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 04:40:45 +02:00
|
|
|
DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
|
|
|
|
MDString *Name, Metadata *File, unsigned Line,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(Scope && "Expected scope");
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DILabel,
|
|
|
|
(Scope, Name, File, Line));
|
|
|
|
Metadata *Ops[] = {Scope, Name, File};
|
|
|
|
DEFINE_GETIMPL_STORE(DILabel, (Line), Ops);
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DIExpression *DIExpression::getImpl(LLVMContext &Context,
|
2015-02-10 01:52:32 +01:00
|
|
|
ArrayRef<uint64_t> Elements,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-04-29 18:38:44 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
|
|
|
|
DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
unsigned DIExpression::ExprOperand::getSize() const {
|
2019-07-31 18:51:28 +02:00
|
|
|
uint64_t Op = getOp();
|
|
|
|
|
|
|
|
if (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31)
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
switch (Op) {
|
2019-03-19 14:16:28 +01:00
|
|
|
case dwarf::DW_OP_LLVM_convert:
|
2016-12-05 19:04:47 +01:00
|
|
|
case dwarf::DW_OP_LLVM_fragment:
|
2019-07-31 18:51:28 +02:00
|
|
|
case dwarf::DW_OP_bregx:
|
2015-02-13 02:07:46 +01:00
|
|
|
return 3;
|
2016-09-13 03:12:59 +02:00
|
|
|
case dwarf::DW_OP_constu:
|
2019-07-31 18:51:28 +02:00
|
|
|
case dwarf::DW_OP_consts:
|
2019-04-30 09:58:57 +02:00
|
|
|
case dwarf::DW_OP_deref_size:
|
2017-06-13 18:54:44 +02:00
|
|
|
case dwarf::DW_OP_plus_uconst:
|
2019-06-18 01:39:41 +02:00
|
|
|
case dwarf::DW_OP_LLVM_tag_offset:
|
[DebugInfo] Add a DW_OP_LLVM_entry_value operation
Summary:
Internally in LLVM's metadata we use DW_OP_entry_value operations with
the same semantics as DWARF; that is, its operand specifies the number
of bytes that the entry value covers.
At the time of emitting entry values we don't know the emitted size of
the DWARF expression that the entry value will cover. Currently the size
is hardcoded to 1 in DIExpression, and other values causes the verifier
to fail. As the size is 1, that effectively means that we can only have
valid entry values for registers that can be encoded in one byte, which
are the registers with DWARF numbers 0 to 31 (as they can be encoded as
single-byte DW_OP_reg0..DW_OP_reg31 rather than a multi-byte
DW_OP_regx). It is a bit confusing, but it seems like llvm-dwarfdump
will print an operation "correctly", even if the byte size is less than
that, which may make it seem that we emit correct DWARF for registers
with DWARF numbers > 31. If you instead use readelf for such cases, it
will interpret the number of specified bytes as a DWARF expression. This
seems like a limitation in llvm-dwarfdump.
As suggested in D66746, a way forward would be to add an internal
variant of DW_OP_entry_value, DW_OP_LLVM_entry_value, whose operand
instead specifies the number of operations that the entry value covers,
and we then translate that into the byte size at the time of emission.
In this patch that internal operation is added. This patch keeps the
limitation that a entry value can only be applied to simple register
locations, but it will fix the issue with the size operand being
incorrect for DWARF numbers > 31.
Reviewers: aprantl, vsk, djtodoro, NikolaPrica
Reviewed By: aprantl
Subscribers: jyknight, fedor.sergeev, hiraditya, llvm-commits
Tags: #debug-info, #llvm
Differential Revision: https://reviews.llvm.org/D67492
llvm-svn: 374881
2019-10-15 13:31:21 +02:00
|
|
|
case dwarf::DW_OP_LLVM_entry_value:
|
2019-07-31 18:51:28 +02:00
|
|
|
case dwarf::DW_OP_regx:
|
2015-02-13 02:07:46 +01:00
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
bool DIExpression::isValid() const {
|
2015-02-13 02:07:46 +01:00
|
|
|
for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
|
|
|
|
// Check that there's space for the operand.
|
|
|
|
if (I->get() + I->getSize() > E->get())
|
|
|
|
return false;
|
|
|
|
|
2019-07-31 18:51:28 +02:00
|
|
|
uint64_t Op = I->getOp();
|
|
|
|
if ((Op >= dwarf::DW_OP_reg0 && Op <= dwarf::DW_OP_reg31) ||
|
|
|
|
(Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31))
|
|
|
|
return true;
|
|
|
|
|
2015-02-13 02:07:46 +01:00
|
|
|
// Check that the operand is valid.
|
2019-07-31 18:51:28 +02:00
|
|
|
switch (Op) {
|
2015-02-13 02:07:46 +01:00
|
|
|
default:
|
|
|
|
return false;
|
2016-12-05 19:04:47 +01:00
|
|
|
case dwarf::DW_OP_LLVM_fragment:
|
2016-12-20 03:09:43 +01:00
|
|
|
// A fragment operator must appear at the end.
|
2015-02-13 02:07:46 +01:00
|
|
|
return I->get() + I->getSize() == E->get();
|
2016-12-20 03:09:43 +01:00
|
|
|
case dwarf::DW_OP_stack_value: {
|
|
|
|
// Must be the last one or followed by a DW_OP_LLVM_fragment.
|
|
|
|
if (I->get() + I->getSize() == E->get())
|
|
|
|
break;
|
|
|
|
auto J = I;
|
|
|
|
if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-08 01:28:57 +01:00
|
|
|
case dwarf::DW_OP_swap: {
|
|
|
|
// Must be more than one implicit element on the stack.
|
|
|
|
|
|
|
|
// FIXME: A better way to implement this would be to add a local variable
|
|
|
|
// that keeps track of the stack depth and introduce something like a
|
|
|
|
// DW_LLVM_OP_implicit_location as a placeholder for the location this
|
|
|
|
// DIExpression is attached to, or else pass the number of implicit stack
|
|
|
|
// elements into isValid.
|
|
|
|
if (getNumElements() == 1)
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
[DebugInfo] Add a DW_OP_LLVM_entry_value operation
Summary:
Internally in LLVM's metadata we use DW_OP_entry_value operations with
the same semantics as DWARF; that is, its operand specifies the number
of bytes that the entry value covers.
At the time of emitting entry values we don't know the emitted size of
the DWARF expression that the entry value will cover. Currently the size
is hardcoded to 1 in DIExpression, and other values causes the verifier
to fail. As the size is 1, that effectively means that we can only have
valid entry values for registers that can be encoded in one byte, which
are the registers with DWARF numbers 0 to 31 (as they can be encoded as
single-byte DW_OP_reg0..DW_OP_reg31 rather than a multi-byte
DW_OP_regx). It is a bit confusing, but it seems like llvm-dwarfdump
will print an operation "correctly", even if the byte size is less than
that, which may make it seem that we emit correct DWARF for registers
with DWARF numbers > 31. If you instead use readelf for such cases, it
will interpret the number of specified bytes as a DWARF expression. This
seems like a limitation in llvm-dwarfdump.
As suggested in D66746, a way forward would be to add an internal
variant of DW_OP_entry_value, DW_OP_LLVM_entry_value, whose operand
instead specifies the number of operations that the entry value covers,
and we then translate that into the byte size at the time of emission.
In this patch that internal operation is added. This patch keeps the
limitation that a entry value can only be applied to simple register
locations, but it will fix the issue with the size operand being
incorrect for DWARF numbers > 31.
Reviewers: aprantl, vsk, djtodoro, NikolaPrica
Reviewed By: aprantl
Subscribers: jyknight, fedor.sergeev, hiraditya, llvm-commits
Tags: #debug-info, #llvm
Differential Revision: https://reviews.llvm.org/D67492
llvm-svn: 374881
2019-10-15 13:31:21 +02:00
|
|
|
case dwarf::DW_OP_LLVM_entry_value: {
|
|
|
|
// An entry value operator must appear at the beginning and the number of
|
|
|
|
// operations it cover can currently only be 1, because we support only
|
|
|
|
// entry values of a simple register location. One reason for this is that
|
|
|
|
// we currently can't calculate the size of the resulting DWARF block for
|
|
|
|
// other expressions.
|
2021-02-04 19:57:44 +01:00
|
|
|
return I->get() == expr_op_begin()->get() && I->getArg(0) == 1;
|
2019-06-27 15:52:34 +02:00
|
|
|
}
|
2021-01-15 09:10:33 +01:00
|
|
|
case dwarf::DW_OP_LLVM_implicit_pointer:
|
2019-03-19 14:16:28 +01:00
|
|
|
case dwarf::DW_OP_LLVM_convert:
|
2019-06-18 01:39:41 +02:00
|
|
|
case dwarf::DW_OP_LLVM_tag_offset:
|
2016-09-13 03:12:59 +02:00
|
|
|
case dwarf::DW_OP_constu:
|
2017-06-13 18:54:44 +02:00
|
|
|
case dwarf::DW_OP_plus_uconst:
|
2015-02-13 02:07:46 +01:00
|
|
|
case dwarf::DW_OP_plus:
|
2015-09-30 21:55:43 +02:00
|
|
|
case dwarf::DW_OP_minus:
|
2017-09-21 12:04:02 +02:00
|
|
|
case dwarf::DW_OP_mul:
|
2018-02-13 02:09:52 +01:00
|
|
|
case dwarf::DW_OP_div:
|
|
|
|
case dwarf::DW_OP_mod:
|
2018-02-09 20:19:55 +01:00
|
|
|
case dwarf::DW_OP_or:
|
2018-02-14 14:10:35 +01:00
|
|
|
case dwarf::DW_OP_and:
|
2018-02-13 02:09:46 +01:00
|
|
|
case dwarf::DW_OP_xor:
|
2018-02-13 02:09:49 +01:00
|
|
|
case dwarf::DW_OP_shl:
|
|
|
|
case dwarf::DW_OP_shr:
|
|
|
|
case dwarf::DW_OP_shra:
|
2015-02-13 02:07:46 +01:00
|
|
|
case dwarf::DW_OP_deref:
|
2019-04-30 09:58:57 +02:00
|
|
|
case dwarf::DW_OP_deref_size:
|
2017-03-08 01:28:57 +01:00
|
|
|
case dwarf::DW_OP_xderef:
|
2018-07-06 19:32:39 +02:00
|
|
|
case dwarf::DW_OP_lit0:
|
|
|
|
case dwarf::DW_OP_not:
|
|
|
|
case dwarf::DW_OP_dup:
|
2019-07-31 18:51:28 +02:00
|
|
|
case dwarf::DW_OP_regx:
|
|
|
|
case dwarf::DW_OP_bregx:
|
2020-05-15 07:28:29 +02:00
|
|
|
case dwarf::DW_OP_push_object_address:
|
2020-10-17 04:54:08 +02:00
|
|
|
case dwarf::DW_OP_over:
|
2020-10-28 15:24:39 +01:00
|
|
|
case dwarf::DW_OP_consts:
|
2015-02-13 02:07:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-30 09:58:57 +02:00
|
|
|
bool DIExpression::isImplicit() const {
|
2019-11-03 17:37:34 +01:00
|
|
|
if (!isValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (getNumElements() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (const auto &It : expr_ops()) {
|
|
|
|
switch (It.getOp()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case dwarf::DW_OP_stack_value:
|
|
|
|
case dwarf::DW_OP_LLVM_tag_offset:
|
|
|
|
return true;
|
2019-04-30 09:58:57 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-03 17:37:34 +01:00
|
|
|
|
2019-04-30 09:58:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-01 11:38:23 +02:00
|
|
|
bool DIExpression::isComplex() const {
|
|
|
|
if (!isValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (getNumElements() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If there are any elements other than fragment or tag_offset, then some
|
|
|
|
// kind of complex computation occurs.
|
|
|
|
for (const auto &It : expr_ops()) {
|
|
|
|
switch (It.getOp()) {
|
|
|
|
case dwarf::DW_OP_LLVM_tag_offset:
|
|
|
|
case dwarf::DW_OP_LLVM_fragment:
|
|
|
|
continue;
|
|
|
|
default: return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-22 06:27:12 +01:00
|
|
|
Optional<DIExpression::FragmentInfo>
|
|
|
|
DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
|
|
|
|
for (auto I = Start; I != End; ++I)
|
|
|
|
if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
|
|
|
|
DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
|
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
return None;
|
2015-04-07 05:49:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-28 10:44:30 +02:00
|
|
|
void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
|
|
|
|
int64_t Offset) {
|
|
|
|
if (Offset > 0) {
|
2017-06-14 15:14:38 +02:00
|
|
|
Ops.push_back(dwarf::DW_OP_plus_uconst);
|
2017-04-28 10:44:30 +02:00
|
|
|
Ops.push_back(Offset);
|
|
|
|
} else if (Offset < 0) {
|
2017-06-14 15:14:38 +02:00
|
|
|
Ops.push_back(dwarf::DW_OP_constu);
|
2017-04-28 10:44:30 +02:00
|
|
|
Ops.push_back(-Offset);
|
2017-06-14 15:14:38 +02:00
|
|
|
Ops.push_back(dwarf::DW_OP_minus);
|
2017-04-28 10:44:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 21:59:29 +02:00
|
|
|
bool DIExpression::extractIfOffset(int64_t &Offset) const {
|
|
|
|
if (getNumElements() == 0) {
|
|
|
|
Offset = 0;
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-14 15:14:38 +02:00
|
|
|
|
|
|
|
if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
|
2017-05-09 21:59:29 +02:00
|
|
|
Offset = Elements[1];
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-14 15:14:38 +02:00
|
|
|
|
|
|
|
if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
|
|
|
|
if (Elements[2] == dwarf::DW_OP_plus) {
|
|
|
|
Offset = Elements[1];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Elements[2] == dwarf::DW_OP_minus) {
|
|
|
|
Offset = -Elements[1];
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-09 21:59:29 +02:00
|
|
|
}
|
2017-06-14 15:14:38 +02:00
|
|
|
|
2017-05-09 21:59:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-05 20:33:47 +01:00
|
|
|
const DIExpression *DIExpression::extractAddressClass(const DIExpression *Expr,
|
|
|
|
unsigned &AddrClass) {
|
2019-11-03 17:37:34 +01:00
|
|
|
// FIXME: This seems fragile. Nothing that verifies that these elements
|
|
|
|
// actually map to ops and not operands.
|
2019-02-05 20:33:47 +01:00
|
|
|
const unsigned PatternSize = 4;
|
|
|
|
if (Expr->Elements.size() >= PatternSize &&
|
|
|
|
Expr->Elements[PatternSize - 4] == dwarf::DW_OP_constu &&
|
|
|
|
Expr->Elements[PatternSize - 2] == dwarf::DW_OP_swap &&
|
|
|
|
Expr->Elements[PatternSize - 1] == dwarf::DW_OP_xderef) {
|
|
|
|
AddrClass = Expr->Elements[PatternSize - 3];
|
|
|
|
|
|
|
|
if (Expr->Elements.size() == PatternSize)
|
|
|
|
return nullptr;
|
|
|
|
return DIExpression::get(Expr->getContext(),
|
|
|
|
makeArrayRef(&*Expr->Elements.begin(),
|
|
|
|
Expr->Elements.size() - PatternSize));
|
|
|
|
}
|
|
|
|
return Expr;
|
|
|
|
}
|
|
|
|
|
2019-05-20 12:35:57 +02:00
|
|
|
DIExpression *DIExpression::prepend(const DIExpression *Expr, uint8_t Flags,
|
|
|
|
int64_t Offset) {
|
2017-04-28 10:44:30 +02:00
|
|
|
SmallVector<uint64_t, 8> Ops;
|
2019-05-20 12:35:57 +02:00
|
|
|
if (Flags & DIExpression::DerefBefore)
|
2017-12-08 22:58:18 +01:00
|
|
|
Ops.push_back(dwarf::DW_OP_deref);
|
2018-07-03 14:39:52 +02:00
|
|
|
|
2017-04-28 10:44:30 +02:00
|
|
|
appendOffset(Ops, Offset);
|
2019-05-20 12:35:57 +02:00
|
|
|
if (Flags & DIExpression::DerefAfter)
|
2017-04-28 10:44:30 +02:00
|
|
|
Ops.push_back(dwarf::DW_OP_deref);
|
2017-12-08 22:58:18 +01:00
|
|
|
|
2019-05-20 12:35:57 +02:00
|
|
|
bool StackValue = Flags & DIExpression::StackValue;
|
2019-06-27 15:52:34 +02:00
|
|
|
bool EntryValue = Flags & DIExpression::EntryValue;
|
2019-05-20 12:35:57 +02:00
|
|
|
|
2019-06-27 15:52:34 +02:00
|
|
|
return prependOpcodes(Expr, Ops, StackValue, EntryValue);
|
2018-02-09 20:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-04-27 23:41:36 +02:00
|
|
|
DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
|
|
|
|
SmallVectorImpl<uint64_t> &Ops,
|
2019-06-27 15:52:34 +02:00
|
|
|
bool StackValue,
|
|
|
|
bool EntryValue) {
|
2018-07-06 23:06:20 +02:00
|
|
|
assert(Expr && "Can't prepend ops to this expression");
|
|
|
|
|
2019-06-27 15:52:34 +02:00
|
|
|
if (EntryValue) {
|
[DebugInfo] Add a DW_OP_LLVM_entry_value operation
Summary:
Internally in LLVM's metadata we use DW_OP_entry_value operations with
the same semantics as DWARF; that is, its operand specifies the number
of bytes that the entry value covers.
At the time of emitting entry values we don't know the emitted size of
the DWARF expression that the entry value will cover. Currently the size
is hardcoded to 1 in DIExpression, and other values causes the verifier
to fail. As the size is 1, that effectively means that we can only have
valid entry values for registers that can be encoded in one byte, which
are the registers with DWARF numbers 0 to 31 (as they can be encoded as
single-byte DW_OP_reg0..DW_OP_reg31 rather than a multi-byte
DW_OP_regx). It is a bit confusing, but it seems like llvm-dwarfdump
will print an operation "correctly", even if the byte size is less than
that, which may make it seem that we emit correct DWARF for registers
with DWARF numbers > 31. If you instead use readelf for such cases, it
will interpret the number of specified bytes as a DWARF expression. This
seems like a limitation in llvm-dwarfdump.
As suggested in D66746, a way forward would be to add an internal
variant of DW_OP_entry_value, DW_OP_LLVM_entry_value, whose operand
instead specifies the number of operations that the entry value covers,
and we then translate that into the byte size at the time of emission.
In this patch that internal operation is added. This patch keeps the
limitation that a entry value can only be applied to simple register
locations, but it will fix the issue with the size operand being
incorrect for DWARF numbers > 31.
Reviewers: aprantl, vsk, djtodoro, NikolaPrica
Reviewed By: aprantl
Subscribers: jyknight, fedor.sergeev, hiraditya, llvm-commits
Tags: #debug-info, #llvm
Differential Revision: https://reviews.llvm.org/D67492
llvm-svn: 374881
2019-10-15 13:31:21 +02:00
|
|
|
Ops.push_back(dwarf::DW_OP_LLVM_entry_value);
|
2021-02-04 19:57:44 +01:00
|
|
|
// Use a block size of 1 for the target register operand. The
|
|
|
|
// DWARF backend currently cannot emit entry values with a block
|
|
|
|
// size > 1.
|
|
|
|
Ops.push_back(1);
|
2019-06-27 15:52:34 +02:00
|
|
|
}
|
|
|
|
|
[DebugInfo] Corrections for salvageDebugInfo
Summary:
When salvaging a dbg.declare/dbg.addr we should not add
DW_OP_stack_value to the DIExpression
(see test/Transforms/InstCombine/salvage-dbg-declare.ll).
Consider this example
%vla = alloca i32, i64 2
call void @llvm.dbg.declare(metadata i32* %vla, metadata !1, metadata !DIExpression())
Instcombine will turn it into
%vla1 = alloca [2 x i32]
%vla1.sub = getelementptr inbounds [2 x i32], [2 x i32]* %vla, i64 0, i64 0
call void @llvm.dbg.declare(metadata [2 x i32]* %vla1.sub, metadata !19, metadata !DIExpression())
If the GEP can be eliminated, then the dbg.declare will be salvaged
and we should get
%vla1 = alloca [2 x i32]
call void @llvm.dbg.declare(metadata [2 x i32]* %vla1, metadata !19, metadata !DIExpression())
The problem was that salvageDebugInfo did not recognize dbg.declare
as being indirect (%vla1 points to the value, it does not hold the
value), so we incorrectly got
call void @llvm.dbg.declare(metadata [2 x i32]* %vla1, metadata !19, metadata !DIExpression(DW_OP_stack_value))
I also made sure that llvm::salvageDebugInfo and
DIExpression::prependOpcodes do not add DW_OP_stack_value to
the DIExpression in case no new operands are added to the
DIExpression. That way we avoid to, unneccessarily, turn a
register location expression into an implicit location expression
in some situations (see test11 in test/Transforms/LICM/sinking.ll).
Reviewers: aprantl, vsk
Reviewed By: aprantl, vsk
Subscribers: JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D48837
llvm-svn: 336191
2018-07-03 13:29:00 +02:00
|
|
|
// If there are no ops to prepend, do not even add the DW_OP_stack_value.
|
|
|
|
if (Ops.empty())
|
|
|
|
StackValue = false;
|
2018-07-06 23:06:20 +02:00
|
|
|
for (auto Op : Expr->expr_ops()) {
|
|
|
|
// A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
|
|
|
|
if (StackValue) {
|
|
|
|
if (Op.getOp() == dwarf::DW_OP_stack_value)
|
|
|
|
StackValue = false;
|
|
|
|
else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
|
|
|
|
Ops.push_back(dwarf::DW_OP_stack_value);
|
|
|
|
StackValue = false;
|
2017-04-28 10:44:30 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-06 23:06:21 +02:00
|
|
|
Op.appendToVector(Ops);
|
2018-07-06 23:06:20 +02:00
|
|
|
}
|
2017-04-28 10:44:30 +02:00
|
|
|
if (StackValue)
|
|
|
|
Ops.push_back(dwarf::DW_OP_stack_value);
|
2017-04-28 19:51:05 +02:00
|
|
|
return DIExpression::get(Expr->getContext(), Ops);
|
2017-04-28 10:44:30 +02:00
|
|
|
}
|
|
|
|
|
2018-07-26 22:56:53 +02:00
|
|
|
DIExpression *DIExpression::append(const DIExpression *Expr,
|
|
|
|
ArrayRef<uint64_t> Ops) {
|
|
|
|
assert(Expr && !Ops.empty() && "Can't append ops to this expression");
|
|
|
|
|
|
|
|
// Copy Expr's current op list.
|
|
|
|
SmallVector<uint64_t, 16> NewOps;
|
|
|
|
for (auto Op : Expr->expr_ops()) {
|
|
|
|
// Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
|
|
|
|
if (Op.getOp() == dwarf::DW_OP_stack_value ||
|
|
|
|
Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
|
|
|
|
NewOps.append(Ops.begin(), Ops.end());
|
|
|
|
|
|
|
|
// Ensure that the new opcodes are only appended once.
|
|
|
|
Ops = None;
|
|
|
|
}
|
|
|
|
Op.appendToVector(NewOps);
|
|
|
|
}
|
|
|
|
|
|
|
|
NewOps.append(Ops.begin(), Ops.end());
|
[DwarfDebug] Fix an assertion error when emitting call site info that combines two DW_OP_stack_values
When compiling
```
struct S {
float w;
};
void f(long w, long b);
void g(struct S s) {
int w = s.w;
f(w, w*4);
}
```
I get Assertion failed: ((!CombinedExpr || CombinedExpr->isValid()) && "Combined debug expression is invalid").
That's because we combine two epxressions that both end in DW_OP_stack_value:
```
(lldb) p Expr->dump()
!DIExpression(DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_LLVM_convert, 64, DW_ATE_signed, DW_OP_stack_value)
(lldb) p Param.Expr->dump()
!DIExpression(DW_OP_constu, 4, DW_OP_mul, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_LLVM_convert, 64, DW_ATE_signed, DW_OP_stack_value)
(lldb) p CombinedExpr->isValid()
(bool) $0 = false
(lldb) p CombinedExpr->dump()
!DIExpression(4097, 32, 5, 4097, 64, 5, 16, 4, 30, 4097, 32, 5, 4097, 64, 5, 159, 159)
```
I believe that in this particular case combining two stack values is
safe, but I didn't want to sink the special handling into
DIExpression::append() because I do want everyone to think about what
they are doing.
Patch by Adrian Prantl.
Fixes PR45181.
rdar://problem/60383095
Differential Revision: https://reviews.llvm.org/D76164
2020-03-17 02:11:36 +01:00
|
|
|
auto *result = DIExpression::get(Expr->getContext(), NewOps);
|
|
|
|
assert(result->isValid() && "concatenated expression is not valid");
|
|
|
|
return result;
|
2018-07-26 22:56:53 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 19:32:39 +02:00
|
|
|
DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
|
|
|
|
ArrayRef<uint64_t> Ops) {
|
|
|
|
assert(Expr && !Ops.empty() && "Can't append ops to this expression");
|
2018-07-26 22:56:53 +02:00
|
|
|
assert(none_of(Ops,
|
|
|
|
[](uint64_t Op) {
|
|
|
|
return Op == dwarf::DW_OP_stack_value ||
|
|
|
|
Op == dwarf::DW_OP_LLVM_fragment;
|
|
|
|
}) &&
|
|
|
|
"Can't append this op");
|
2018-07-06 19:32:39 +02:00
|
|
|
|
|
|
|
// Append a DW_OP_deref after Expr's current op list if it's non-empty and
|
|
|
|
// has no DW_OP_stack_value.
|
|
|
|
//
|
|
|
|
// Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
|
|
|
|
Optional<FragmentInfo> FI = Expr->getFragmentInfo();
|
|
|
|
unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
|
2018-07-26 22:56:53 +02:00
|
|
|
ArrayRef<uint64_t> ExprOpsBeforeFragment =
|
|
|
|
Expr->getElements().drop_back(DropUntilStackValue);
|
|
|
|
bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
|
|
|
|
(ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
|
|
|
|
bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
|
|
|
|
|
|
|
|
// Append a DW_OP_deref after Expr's current op list if needed, then append
|
|
|
|
// the new ops, and finally ensure that a single DW_OP_stack_value is present.
|
2018-07-06 19:32:39 +02:00
|
|
|
SmallVector<uint64_t, 16> NewOps;
|
|
|
|
if (NeedsDeref)
|
|
|
|
NewOps.push_back(dwarf::DW_OP_deref);
|
|
|
|
NewOps.append(Ops.begin(), Ops.end());
|
2018-07-26 22:56:53 +02:00
|
|
|
if (NeedsStackValue)
|
|
|
|
NewOps.push_back(dwarf::DW_OP_stack_value);
|
|
|
|
return DIExpression::append(Expr, NewOps);
|
2018-07-06 19:32:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-07 01:45:34 +01:00
|
|
|
Optional<DIExpression *> DIExpression::createFragmentExpression(
|
|
|
|
const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
|
2017-08-30 22:04:17 +02:00
|
|
|
SmallVector<uint64_t, 8> Ops;
|
|
|
|
// Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
|
|
|
|
if (Expr) {
|
|
|
|
for (auto Op : Expr->expr_ops()) {
|
2017-11-07 01:45:34 +01:00
|
|
|
switch (Op.getOp()) {
|
|
|
|
default: break;
|
2019-11-22 17:40:32 +01:00
|
|
|
case dwarf::DW_OP_shr:
|
|
|
|
case dwarf::DW_OP_shra:
|
|
|
|
case dwarf::DW_OP_shl:
|
2017-11-07 01:45:34 +01:00
|
|
|
case dwarf::DW_OP_plus:
|
2019-11-22 17:40:32 +01:00
|
|
|
case dwarf::DW_OP_plus_uconst:
|
2017-11-07 01:45:34 +01:00
|
|
|
case dwarf::DW_OP_minus:
|
2019-11-22 17:40:32 +01:00
|
|
|
// We can't safely split arithmetic or shift operations into multiple
|
|
|
|
// fragments because we can't express carry-over between fragments.
|
2017-11-07 01:45:34 +01:00
|
|
|
//
|
|
|
|
// FIXME: We *could* preserve the lowest fragment of a constant offset
|
|
|
|
// operation if the offset fits into SizeInBits.
|
|
|
|
return None;
|
|
|
|
case dwarf::DW_OP_LLVM_fragment: {
|
2017-08-30 22:04:17 +02:00
|
|
|
// Make the new offset point into the existing fragment.
|
|
|
|
uint64_t FragmentOffsetInBits = Op.getArg(0);
|
[DebugInfo] Correction for an assert in DIExpression::createFragmentExpression
Summary:
When we create a fragment expression, and there already is an
old fragment expression, we assert that the new fragment is
within the range for the old fragment.
If for example the old fragment expression says that we
describe bit 10-16 of a variable (Offset=10, Size=6),
and we now want to create a new fragment expression only
describing bit 3-6 of the original value, then the resulting
fragment expression should have Offset=13, Size=3.
The assert is supposed to catch if the resulting fragment
expression is outside the range for the old fragment. However,
it used to verify that the Offset+Size of the new fragment was
smaller or equal than Offset+Size for the old fragment. What
we really want to check is that Offset+Size of the new fragment
is smaller than the Size of the old fragment.
Reviewers: aprantl, vsk
Reviewed By: aprantl
Subscribers: davide, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D46391
llvm-svn: 331465
2018-05-03 19:04:21 +02:00
|
|
|
uint64_t FragmentSizeInBits = Op.getArg(1);
|
|
|
|
(void)FragmentSizeInBits;
|
|
|
|
assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
|
2017-08-30 22:04:17 +02:00
|
|
|
"new fragment outside of original fragment");
|
|
|
|
OffsetInBits += FragmentOffsetInBits;
|
2017-11-07 01:45:34 +01:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-30 22:04:17 +02:00
|
|
|
}
|
2018-07-06 23:06:21 +02:00
|
|
|
Op.appendToVector(Ops);
|
2017-08-30 22:04:17 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-01 13:25:38 +02:00
|
|
|
assert(Expr && "Unknown DIExpression");
|
2017-08-30 22:04:17 +02:00
|
|
|
Ops.push_back(dwarf::DW_OP_LLVM_fragment);
|
|
|
|
Ops.push_back(OffsetInBits);
|
|
|
|
Ops.push_back(SizeInBits);
|
|
|
|
return DIExpression::get(Expr->getContext(), Ops);
|
|
|
|
}
|
|
|
|
|
2016-12-20 03:09:43 +01:00
|
|
|
bool DIExpression::isConstant() const {
|
|
|
|
// Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
|
|
|
|
if (getNumElements() != 3 && getNumElements() != 6)
|
|
|
|
return false;
|
|
|
|
if (getElement(0) != dwarf::DW_OP_constu ||
|
|
|
|
getElement(2) != dwarf::DW_OP_stack_value)
|
|
|
|
return false;
|
|
|
|
if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:24:39 +01:00
|
|
|
bool DIExpression::isSignedConstant() const {
|
|
|
|
// Recognize DW_OP_consts C
|
|
|
|
if (getNumElements() != 2)
|
|
|
|
return false;
|
|
|
|
if (getElement(0) != dwarf::DW_OP_consts)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-18 15:28:24 +01:00
|
|
|
DIExpression::ExtOps DIExpression::getExtOps(unsigned FromSize, unsigned ToSize,
|
|
|
|
bool Signed) {
|
|
|
|
dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
|
|
|
|
DIExpression::ExtOps Ops{{dwarf::DW_OP_LLVM_convert, FromSize, TK,
|
|
|
|
dwarf::DW_OP_LLVM_convert, ToSize, TK}};
|
|
|
|
return Ops;
|
|
|
|
}
|
|
|
|
|
2019-11-21 09:45:20 +01:00
|
|
|
DIExpression *DIExpression::appendExt(const DIExpression *Expr,
|
|
|
|
unsigned FromSize, unsigned ToSize,
|
|
|
|
bool Signed) {
|
2019-12-18 15:28:24 +01:00
|
|
|
return appendToStack(Expr, getExtOps(FromSize, ToSize, Signed));
|
2019-11-21 09:45:20 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 03:09:43 +01:00
|
|
|
DIGlobalVariableExpression *
|
|
|
|
DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
|
|
|
|
Metadata *Expression, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression));
|
|
|
|
Metadata *Ops[] = {Variable, Expression};
|
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops);
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DIObjCProperty *DIObjCProperty::getImpl(
|
2015-02-10 01:52:32 +01:00
|
|
|
LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
|
|
|
|
MDString *GetterName, MDString *SetterName, unsigned Attributes,
|
|
|
|
Metadata *Type, StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(GetterName) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(SetterName) && "Expected canonical MDString");
|
2016-03-19 02:02:34 +01:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
|
|
|
|
SetterName, Attributes, Type));
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
|
2015-04-29 18:38:44 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
|
2015-02-10 01:52:32 +01:00
|
|
|
Metadata *Scope, Metadata *Entity,
|
2017-07-19 02:09:54 +02:00
|
|
|
Metadata *File, unsigned Line,
|
|
|
|
MDString *Name, StorageType Storage,
|
2015-02-10 01:52:32 +01:00
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2017-07-19 02:09:54 +02:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
|
|
|
|
(Tag, Scope, Entity, File, Line, Name));
|
|
|
|
Metadata *Ops[] = {Scope, Entity, Name, File};
|
2015-04-29 18:38:44 +02:00
|
|
|
DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
|
2015-02-10 01:52:32 +01:00
|
|
|
}
|
2015-12-10 13:56:35 +01:00
|
|
|
|
|
|
|
DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
|
|
|
|
unsigned Line, MDString *Name, MDString *Value,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-03-19 02:02:34 +01:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
|
2015-12-10 13:56:35 +01:00
|
|
|
Metadata *Ops[] = { Name, Value };
|
|
|
|
DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
|
|
|
|
unsigned Line, Metadata *File,
|
|
|
|
Metadata *Elements, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIMacroFile,
|
|
|
|
(MIType, Line, File, Elements));
|
|
|
|
Metadata *Ops[] = { File, Elements };
|
|
|
|
DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
|
|
|
|
}
|