Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
//===--- DIBuilder.cpp - Debug Information Builder ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the DIBuilder.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-06 08:22:06 +08:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2017-10-04 04:36:40 +08:00
|
|
|
#include "llvm/IR/IRBuilder.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "LLVMContextImpl.h"
|
2018-02-24 07:01:06 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2014-03-06 08:46:21 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2012-04-03 08:43:49 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::dwarf;
|
|
|
|
|
2017-09-22 03:52:03 +08:00
|
|
|
cl::opt<bool>
|
|
|
|
UseDbgAddr("use-dbg-addr",
|
2017-12-01 08:53:10 +08:00
|
|
|
llvm::cl::desc("Use llvm.dbg.addr for all local variables"),
|
|
|
|
cl::init(false), cl::Hidden);
|
2017-09-22 03:52:03 +08:00
|
|
|
|
2018-01-20 05:21:49 +08:00
|
|
|
DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU)
|
|
|
|
: M(m), VMContext(M.getContext()), CUNode(CU),
|
[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 10:40:45 +08:00
|
|
|
DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr),
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
AllowUnresolvedNodes(AllowUnresolvedNodes) {}
|
|
|
|
|
|
|
|
void DIBuilder::trackIfUnresolved(MDNode *N) {
|
2015-01-20 03:09:14 +08:00
|
|
|
if (!N)
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
return;
|
2015-01-20 03:09:14 +08:00
|
|
|
if (N->isResolved())
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes");
|
|
|
|
UnresolvedNodes.emplace_back(N);
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
}
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
|
2017-06-02 04:42:44 +08:00
|
|
|
void DIBuilder::finalizeSubprogram(DISubprogram *SP) {
|
[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 10:40:45 +08:00
|
|
|
MDTuple *Temp = SP->getRetainedNodes().get();
|
2017-06-02 04:42:44 +08:00
|
|
|
if (!Temp || !Temp->isTemporary())
|
|
|
|
return;
|
|
|
|
|
[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 10:40:45 +08:00
|
|
|
SmallVector<Metadata *, 16> RetainedNodes;
|
2017-06-02 04:42:44 +08:00
|
|
|
|
|
|
|
auto PV = PreservedVariables.find(SP);
|
|
|
|
if (PV != PreservedVariables.end())
|
[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 10:40:45 +08:00
|
|
|
RetainedNodes.append(PV->second.begin(), PV->second.end());
|
2017-06-02 04:42:44 +08:00
|
|
|
|
[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 10:40:45 +08:00
|
|
|
auto PL = PreservedLabels.find(SP);
|
|
|
|
if (PL != PreservedLabels.end())
|
|
|
|
RetainedNodes.append(PL->second.begin(), PL->second.end());
|
|
|
|
|
|
|
|
DINodeArray Node = getOrCreateArray(RetainedNodes);
|
|
|
|
|
|
|
|
TempMDTuple(Temp)->replaceAllUsesWith(Node.get());
|
2017-06-02 04:42:44 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 07:00:00 +08:00
|
|
|
void DIBuilder::finalize() {
|
2015-07-07 00:22:12 +08:00
|
|
|
if (!CUNode) {
|
|
|
|
assert(!AllowUnresolvedNodes &&
|
|
|
|
"creating type nodes without a CU is not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
|
|
|
|
|
|
|
|
SmallVector<Metadata *, 16> RetainValues;
|
|
|
|
// Declarations and definitions of the same type may be retained. Some
|
|
|
|
// clients RAUW these pairs, leaving duplicates in the retained types
|
|
|
|
// list. Use a set to remove the duplicates while we transform the
|
|
|
|
// TrackingVHs back into Values.
|
|
|
|
SmallPtrSet<Metadata *, 16> RetainSet;
|
|
|
|
for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
|
|
|
|
if (RetainSet.insert(AllRetainTypes[I]).second)
|
|
|
|
RetainValues.push_back(AllRetainTypes[I]);
|
2015-07-07 00:36:02 +08:00
|
|
|
|
|
|
|
if (!RetainValues.empty())
|
|
|
|
CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
|
2015-07-07 00:22:12 +08:00
|
|
|
|
|
|
|
DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
|
2016-04-15 23:57:41 +08:00
|
|
|
for (auto *SP : SPs)
|
2017-06-02 04:42:44 +08:00
|
|
|
finalizeSubprogram(SP);
|
2016-04-15 23:57:41 +08:00
|
|
|
for (auto *N : RetainValues)
|
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(N))
|
2017-06-02 04:42:44 +08:00
|
|
|
finalizeSubprogram(SP);
|
2011-08-17 06:09:43 +08:00
|
|
|
|
2015-07-07 00:36:02 +08:00
|
|
|
if (!AllGVs.empty())
|
|
|
|
CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
|
2013-04-22 14:12:31 +08:00
|
|
|
|
2015-07-07 00:36:02 +08:00
|
|
|
if (!AllImportedModules.empty())
|
|
|
|
CUNode->replaceImportedEntities(MDTuple::get(
|
|
|
|
VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
|
|
|
|
AllImportedModules.end())));
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
|
2017-01-12 23:49:46 +08:00
|
|
|
for (const auto &I : AllMacrosPerParent) {
|
|
|
|
// DIMacroNode's with nullptr parent are DICompileUnit direct children.
|
|
|
|
if (!I.first) {
|
|
|
|
CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef()));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Otherwise, it must be a temporary DIMacroFile that need to be resolved.
|
|
|
|
auto *TMF = cast<DIMacroFile>(I.first);
|
|
|
|
auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file,
|
|
|
|
TMF->getLine(), TMF->getFile(),
|
|
|
|
getOrCreateMacroArray(I.second.getArrayRef()));
|
|
|
|
replaceTemporary(llvm::TempDIMacroNode(TMF), MF);
|
|
|
|
}
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
// Now that all temp nodes have been replaced or deleted, resolve remaining
|
|
|
|
// cycles.
|
|
|
|
for (const auto &N : UnresolvedNodes)
|
2015-01-20 07:13:14 +08:00
|
|
|
if (N && !N->isResolved())
|
|
|
|
N->resolveCycles();
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
UnresolvedNodes.clear();
|
|
|
|
|
|
|
|
// Can't handle unresolved nodes anymore.
|
|
|
|
AllowUnresolvedNodes = false;
|
2011-08-17 06:09:43 +08:00
|
|
|
}
|
|
|
|
|
2014-10-02 05:32:15 +08:00
|
|
|
/// If N is compile unit return NULL otherwise return N.
|
2015-04-30 00:38:44 +08:00
|
|
|
static DIScope *getNonCompileUnitScope(DIScope *N) {
|
|
|
|
if (!N || isa<DICompileUnit>(N))
|
2014-04-09 14:08:46 +08:00
|
|
|
return nullptr;
|
2015-04-30 00:38:44 +08:00
|
|
|
return cast<DIScope>(N);
|
2011-08-16 07:00:00 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompileUnit *DIBuilder::createCompileUnit(
|
2016-12-15 04:24:54 +08:00
|
|
|
unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized,
|
|
|
|
StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
|
2016-08-25 02:29:49 +08:00
|
|
|
DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
|
2017-09-13 05:50:41 +08:00
|
|
|
bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames) {
|
2014-02-27 09:24:56 +08:00
|
|
|
|
2015-02-07 14:35:30 +08:00
|
|
|
assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
|
2012-01-11 02:18:52 +08:00
|
|
|
(Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
|
|
|
|
"Invalid Language tag");
|
2011-08-17 06:09:43 +08:00
|
|
|
|
2015-07-03 06:32:52 +08:00
|
|
|
assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
|
|
|
|
CUNode = DICompileUnit::getDistinct(
|
2016-12-15 04:24:54 +08:00
|
|
|
VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
|
|
|
|
SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
|
2017-09-13 05:50:41 +08:00
|
|
|
SplitDebugInlining, DebugInfoForProfiling, GnuPubnames);
|
2011-05-04 00:18:28 +08:00
|
|
|
|
|
|
|
// Create a named metadata so that it is easier to find cu in a module.
|
2016-04-09 06:43:03 +08:00
|
|
|
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
|
|
|
|
NMD->addOperand(CUNode);
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
trackIfUnresolved(CUNode);
|
2015-04-07 07:18:49 +08:00
|
|
|
return CUNode;
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
static DIImportedEntity *
|
|
|
|
createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context,
|
2017-07-19 08:09:54 +08:00
|
|
|
Metadata *NS, DIFile *File, unsigned Line, StringRef Name,
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
|
2017-07-19 08:09:54 +08:00
|
|
|
if (Line)
|
|
|
|
assert(File && "Source location has line number but no file");
|
2016-03-13 19:11:39 +08:00
|
|
|
unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
|
2017-07-19 08:09:54 +08:00
|
|
|
auto *M =
|
|
|
|
DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), File, Line, Name);
|
2016-03-13 19:11:39 +08:00
|
|
|
if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
|
|
|
|
// A new Imported Entity was just added to the context.
|
|
|
|
// Add it to the Imported Modules list.
|
|
|
|
AllImportedModules.emplace_back(M);
|
2013-05-08 05:35:53 +08:00
|
|
|
return M;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
|
2017-07-19 08:09:54 +08:00
|
|
|
DINamespace *NS, DIFile *File,
|
2015-04-30 00:38:44 +08:00
|
|
|
unsigned Line) {
|
2014-04-06 14:29:01 +08:00
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
2017-07-19 08:09:54 +08:00
|
|
|
Context, NS, File, Line, StringRef(),
|
|
|
|
AllImportedModules);
|
2013-05-21 06:50:35 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
|
|
|
|
DIImportedEntity *NS,
|
2017-07-19 08:09:54 +08:00
|
|
|
DIFile *File, unsigned Line) {
|
2014-04-06 14:29:01 +08:00
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
2017-07-19 08:09:54 +08:00
|
|
|
Context, NS, File, Line, StringRef(),
|
|
|
|
AllImportedModules);
|
2013-05-21 06:50:35 +08:00
|
|
|
}
|
|
|
|
|
2015-06-30 07:03:47 +08:00
|
|
|
DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M,
|
2017-07-19 08:09:54 +08:00
|
|
|
DIFile *File, unsigned Line) {
|
2015-06-30 07:03:47 +08:00
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
2017-07-19 08:09:54 +08:00
|
|
|
Context, M, File, Line, StringRef(),
|
|
|
|
AllImportedModules);
|
2015-06-30 07:03:47 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context,
|
|
|
|
DINode *Decl,
|
2017-07-19 08:09:54 +08:00
|
|
|
DIFile *File,
|
2015-04-17 00:36:23 +08:00
|
|
|
unsigned Line,
|
|
|
|
StringRef Name) {
|
2014-11-07 01:46:55 +08:00
|
|
|
// Make sure to use the unique identifier based metadata reference for
|
|
|
|
// types that have one.
|
2014-04-06 14:29:01 +08:00
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
|
2017-07-19 08:09:54 +08:00
|
|
|
Context, Decl, File, Line, Name,
|
|
|
|
AllImportedModules);
|
2013-04-22 14:12:31 +08:00
|
|
|
}
|
|
|
|
|
2016-12-25 18:12:09 +08:00
|
|
|
DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory,
|
2018-02-24 07:01:06 +08:00
|
|
|
Optional<DIFile::ChecksumInfo<StringRef>> CS,
|
|
|
|
Optional<StringRef> Source) {
|
|
|
|
return DIFile::get(VMContext, Filename, Directory, CS, Source);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2017-01-12 23:49:46 +08:00
|
|
|
DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber,
|
|
|
|
unsigned MacroType, StringRef Name,
|
|
|
|
StringRef Value) {
|
|
|
|
assert(!Name.empty() && "Unable to create macro without name");
|
|
|
|
assert((MacroType == dwarf::DW_MACINFO_undef ||
|
|
|
|
MacroType == dwarf::DW_MACINFO_define) &&
|
|
|
|
"Unexpected macro type");
|
|
|
|
auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value);
|
|
|
|
AllMacrosPerParent[Parent].insert(M);
|
|
|
|
return M;
|
|
|
|
}
|
|
|
|
|
|
|
|
DIMacroFile *DIBuilder::createTempMacroFile(DIMacroFile *Parent,
|
|
|
|
unsigned LineNumber, DIFile *File) {
|
|
|
|
auto *MF = DIMacroFile::getTemporary(VMContext, dwarf::DW_MACINFO_start_file,
|
|
|
|
LineNumber, File, DIMacroNodeArray())
|
|
|
|
.release();
|
|
|
|
AllMacrosPerParent[Parent].insert(MF);
|
|
|
|
// Add the new temporary DIMacroFile to the macro per parent map as a parent.
|
|
|
|
// This is needed to assure DIMacroFile with no children to have an entry in
|
|
|
|
// the map. Otherwise, it will not be resolved in DIBuilder::finalize().
|
|
|
|
AllMacrosPerParent.insert({MF, {}});
|
|
|
|
return MF;
|
|
|
|
}
|
|
|
|
|
2018-02-13 00:10:09 +08:00
|
|
|
DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val,
|
|
|
|
bool IsUnsigned) {
|
2011-09-13 02:26:08 +08:00
|
|
|
assert(!Name.empty() && "Unable to create enumerator without name");
|
2018-02-13 00:10:09 +08:00
|
|
|
return DIEnumerator::get(VMContext, Val, IsUnsigned, Name);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) {
|
2011-09-15 07:13:28 +08:00
|
|
|
assert(!Name.empty() && "Unable to create type without name");
|
2015-04-30 00:38:44 +08:00
|
|
|
return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
|
2011-09-15 07:13:28 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIBasicType *DIBuilder::createNullPtrType() {
|
2013-06-28 06:50:59 +08:00
|
|
|
return createUnspecifiedType("decltype(nullptr)");
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
|
2018-08-15 03:35:34 +08:00
|
|
|
unsigned Encoding,
|
|
|
|
DINode::DIFlags Flags) {
|
2011-09-13 02:26:08 +08:00
|
|
|
assert(!Name.empty() && "Unable to create type without name");
|
2015-04-30 00:38:44 +08:00
|
|
|
return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
|
2018-08-15 03:35:34 +08:00
|
|
|
0, Encoding, Flags);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {
|
2016-04-24 05:08:00 +08:00
|
|
|
return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
|
2017-03-09 07:55:44 +08:00
|
|
|
0, 0, None, DINode::FlagZero);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2017-03-09 07:55:44 +08:00
|
|
|
DIDerivedType *DIBuilder::createPointerType(
|
|
|
|
DIType *PointeeTy,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits,
|
|
|
|
Optional<unsigned> DWARFAddressSpace,
|
|
|
|
StringRef Name) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Why is there a name here?
|
2015-04-30 00:38:44 +08:00
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
|
2016-04-24 05:08:00 +08:00
|
|
|
nullptr, 0, nullptr, PointeeTy, SizeInBits,
|
2017-03-09 07:55:44 +08:00
|
|
|
AlignInBits, 0, DWARFAddressSpace,
|
|
|
|
DINode::FlagZero);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy,
|
|
|
|
DIType *Base,
|
2015-04-17 00:36:23 +08:00
|
|
|
uint64_t SizeInBits,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint32_t AlignInBits,
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags Flags) {
|
2015-04-30 00:38:44 +08:00
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
|
2016-04-24 05:08:00 +08:00
|
|
|
nullptr, 0, nullptr, PointeeTy, SizeInBits,
|
2017-03-09 07:55:44 +08:00
|
|
|
AlignInBits, 0, None, Flags, Base);
|
2013-01-07 13:51:15 +08:00
|
|
|
}
|
|
|
|
|
2017-03-09 07:55:44 +08:00
|
|
|
DIDerivedType *DIBuilder::createReferenceType(
|
|
|
|
unsigned Tag, DIType *RTy,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits,
|
|
|
|
Optional<unsigned> DWARFAddressSpace) {
|
2015-04-07 07:18:49 +08:00
|
|
|
assert(RTy && "Unable to create reference type");
|
2016-04-24 05:08:00 +08:00
|
|
|
return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
|
2017-03-09 07:55:44 +08:00
|
|
|
SizeInBits, AlignInBits, 0, DWARFAddressSpace,
|
|
|
|
DINode::FlagZero);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
|
|
|
|
DIFile *File, unsigned LineNo,
|
|
|
|
DIScope *Context) {
|
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
|
2016-04-24 05:08:00 +08:00
|
|
|
LineNo, getNonCompileUnitScope(Context), Ty, 0, 0,
|
2017-03-09 07:55:44 +08:00
|
|
|
0, None, DINode::FlagZero);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) {
|
2015-04-07 07:18:49 +08:00
|
|
|
assert(Ty && "Invalid type!");
|
|
|
|
assert(FriendTy && "Invalid friend type!");
|
2016-04-24 05:08:00 +08:00
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
|
2017-03-09 07:55:44 +08:00
|
|
|
FriendTy, 0, 0, 0, None, DINode::FlagZero);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy,
|
2015-04-17 00:36:23 +08:00
|
|
|
uint64_t BaseOffset,
|
2018-05-15 05:21:22 +08:00
|
|
|
uint32_t VBPtrOffset,
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags Flags) {
|
2015-04-07 07:18:49 +08:00
|
|
|
assert(Ty && "Unable to create inheritance");
|
2018-05-15 05:21:22 +08:00
|
|
|
Metadata *ExtraData = ConstantAsMetadata::get(
|
|
|
|
ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset));
|
2015-04-30 00:38:44 +08:00
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
|
2018-05-15 05:21:22 +08:00
|
|
|
0, Ty, BaseTy, 0, 0, BaseOffset, None,
|
|
|
|
Flags, ExtraData);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name,
|
|
|
|
DIFile *File, unsigned LineNumber,
|
2015-04-17 00:36:23 +08:00
|
|
|
uint64_t SizeInBits,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint32_t AlignInBits,
|
2015-04-17 00:36:23 +08:00
|
|
|
uint64_t OffsetInBits,
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags Flags, DIType *Ty) {
|
2016-04-24 05:08:00 +08:00
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
|
|
|
LineNumber, getNonCompileUnitScope(Scope), Ty,
|
2017-03-09 07:55:44 +08:00
|
|
|
SizeInBits, AlignInBits, OffsetInBits, None, Flags);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-27 08:34:10 +08:00
|
|
|
static ConstantAsMetadata *getConstantOrNull(Constant *C) {
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
if (C)
|
|
|
|
return ConstantAsMetadata::get(C);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-02-07 07:45:59 +08:00
|
|
|
DIDerivedType *DIBuilder::createVariantMemberType(DIScope *Scope, StringRef Name,
|
|
|
|
DIFile *File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits,
|
|
|
|
Constant *Discriminant,
|
|
|
|
DINode::DIFlags Flags, DIType *Ty) {
|
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
|
|
|
LineNumber, getNonCompileUnitScope(Scope), Ty,
|
|
|
|
SizeInBits, AlignInBits, OffsetInBits, None, Flags,
|
|
|
|
getConstantOrNull(Discriminant));
|
|
|
|
}
|
|
|
|
|
2016-06-30 11:00:20 +08:00
|
|
|
DIDerivedType *DIBuilder::createBitFieldMemberType(
|
|
|
|
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
2016-10-20 08:13:12 +08:00
|
|
|
uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
|
|
|
|
DINode::DIFlags Flags, DIType *Ty) {
|
2016-06-30 11:00:20 +08:00
|
|
|
Flags |= DINode::FlagBitField;
|
|
|
|
return DIDerivedType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
|
2016-10-20 08:13:12 +08:00
|
|
|
getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0,
|
2017-03-09 07:55:44 +08:00
|
|
|
OffsetInBits, None, Flags,
|
2016-10-20 08:13:12 +08:00
|
|
|
ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
|
|
|
|
StorageOffsetInBits)));
|
2016-06-30 11:00:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 01:03:02 +08:00
|
|
|
DIDerivedType *
|
|
|
|
DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
|
|
|
|
unsigned LineNumber, DIType *Ty,
|
2016-10-20 08:13:12 +08:00
|
|
|
DINode::DIFlags Flags, llvm::Constant *Val,
|
|
|
|
uint32_t AlignInBits) {
|
2015-04-30 00:38:44 +08:00
|
|
|
Flags |= DINode::FlagStaticMember;
|
2016-04-24 05:08:00 +08:00
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
2016-10-20 08:13:12 +08:00
|
|
|
LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
|
2017-03-09 07:55:44 +08:00
|
|
|
AlignInBits, 0, None, Flags,
|
|
|
|
getConstantOrNull(Val));
|
2013-01-16 09:22:23 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 01:03:02 +08:00
|
|
|
DIDerivedType *
|
|
|
|
DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits,
|
2016-09-07 01:03:02 +08:00
|
|
|
uint64_t OffsetInBits, DINode::DIFlags Flags,
|
|
|
|
DIType *Ty, MDNode *PropertyNode) {
|
2016-04-24 05:08:00 +08:00
|
|
|
return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
|
|
|
LineNumber, getNonCompileUnitScope(File), Ty,
|
2017-03-09 07:55:44 +08:00
|
|
|
SizeInBits, AlignInBits, OffsetInBits, None, Flags,
|
2016-04-24 05:08:00 +08:00
|
|
|
PropertyNode);
|
2011-04-16 08:11:51 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIObjCProperty *
|
|
|
|
DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
|
2013-10-16 07:31:31 +08:00
|
|
|
StringRef GetterName, StringRef SetterName,
|
2015-04-30 00:38:44 +08:00
|
|
|
unsigned PropertyAttributes, DIType *Ty) {
|
|
|
|
return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
|
2016-04-24 05:08:00 +08:00
|
|
|
SetterName, PropertyAttributes, Ty);
|
2012-02-04 08:59:25 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DITemplateTypeParameter *
|
|
|
|
DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name,
|
|
|
|
DIType *Ty) {
|
|
|
|
assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
|
2016-04-24 05:08:00 +08:00
|
|
|
return DITemplateTypeParameter::get(VMContext, Name, Ty);
|
2011-02-03 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
static DITemplateValueParameter *
|
2015-02-13 11:35:29 +08:00
|
|
|
createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
|
2015-04-30 00:38:44 +08:00
|
|
|
DIScope *Context, StringRef Name, DIType *Ty,
|
2015-04-17 00:36:23 +08:00
|
|
|
Metadata *MD) {
|
2015-04-30 00:38:44 +08:00
|
|
|
assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
|
2016-04-24 05:08:00 +08:00
|
|
|
return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD);
|
2011-02-03 06:35:53 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DITemplateValueParameter *
|
|
|
|
DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name,
|
|
|
|
DIType *Ty, Constant *Val) {
|
2014-11-15 08:05:04 +08:00
|
|
|
return createTemplateValueParameterHelper(
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
|
2015-02-13 11:35:29 +08:00
|
|
|
getConstantOrNull(Val));
|
2013-06-23 02:59:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DITemplateValueParameter *
|
|
|
|
DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
|
|
|
|
DIType *Ty, StringRef Val) {
|
2014-11-15 08:05:04 +08:00
|
|
|
return createTemplateValueParameterHelper(
|
|
|
|
VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
|
2015-02-13 11:35:29 +08:00
|
|
|
MDString::get(VMContext, Val));
|
2013-06-23 02:59:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DITemplateValueParameter *
|
|
|
|
DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name,
|
|
|
|
DIType *Ty, DINodeArray Val) {
|
2014-11-15 08:05:04 +08:00
|
|
|
return createTemplateValueParameterHelper(
|
|
|
|
VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
|
2015-04-08 00:50:39 +08:00
|
|
|
Val.get());
|
2013-06-23 02:59:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompositeType *DIBuilder::createClassType(
|
|
|
|
DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
|
2015-04-30 00:38:44 +08:00
|
|
|
DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
|
|
|
|
assert((!Context || isa<DIScope>(Context)) &&
|
2013-03-12 07:21:19 +08:00
|
|
|
"createClassType should be called with a valid Context");
|
2015-04-17 00:36:23 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *R = DICompositeType::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
|
2016-04-24 05:08:00 +08:00
|
|
|
getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
|
|
|
|
OffsetInBits, Flags, Elements, 0, VTableHolder,
|
2015-04-07 03:03:45 +08:00
|
|
|
cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
2013-03-12 07:21:19 +08:00
|
|
|
return R;
|
2012-07-06 10:35:57 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompositeType *DIBuilder::createStructType(
|
|
|
|
DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
|
2015-04-30 00:38:44 +08:00
|
|
|
DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
|
|
|
|
DIType *VTableHolder, StringRef UniqueIdentifier) {
|
|
|
|
auto *R = DICompositeType::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
|
2016-04-24 05:08:00 +08:00
|
|
|
getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
|
|
|
|
Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
2013-03-12 07:21:19 +08:00
|
|
|
return R;
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompositeType *DIBuilder::createUnionType(
|
|
|
|
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
|
2015-04-30 00:38:44 +08:00
|
|
|
DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
|
|
|
|
auto *R = DICompositeType::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
|
2016-04-24 05:08:00 +08:00
|
|
|
getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
|
|
|
|
Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
2013-08-30 07:17:54 +08:00
|
|
|
return R;
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2018-02-07 07:45:59 +08:00
|
|
|
DICompositeType *DIBuilder::createVariantPart(
|
|
|
|
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
|
|
|
|
DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) {
|
|
|
|
auto *R = DICompositeType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
|
|
|
|
getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
|
|
|
|
Elements, 0, nullptr, nullptr, UniqueIdentifier, Discriminator);
|
|
|
|
trackIfUnresolved(R);
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2015-10-15 14:56:10 +08:00
|
|
|
DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes,
|
2016-09-07 01:03:02 +08:00
|
|
|
DINode::DIFlags Flags,
|
|
|
|
unsigned CC) {
|
2016-06-09 04:34:29 +08:00
|
|
|
return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompositeType *DIBuilder::createEnumerationType(
|
|
|
|
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
|
2018-02-13 00:10:09 +08:00
|
|
|
DIType *UnderlyingType, StringRef UniqueIdentifier, bool IsFixed) {
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *CTy = DICompositeType::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
|
2016-04-24 05:08:00 +08:00
|
|
|
getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
|
2018-02-13 00:10:09 +08:00
|
|
|
IsFixed ? DINode::FlagFixedEnum : DINode::FlagZero, Elements, 0, nullptr,
|
|
|
|
nullptr, UniqueIdentifier);
|
2013-11-19 07:33:32 +08:00
|
|
|
AllEnumTypes.push_back(CTy);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(CTy);
|
2013-11-19 07:33:32 +08:00
|
|
|
return CTy;
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2016-10-18 22:31:22 +08:00
|
|
|
DICompositeType *DIBuilder::createArrayType(uint64_t Size,
|
|
|
|
uint32_t AlignInBits, DIType *Ty,
|
2015-04-30 00:38:44 +08:00
|
|
|
DINodeArray Subscripts) {
|
|
|
|
auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
|
2016-04-24 05:08:00 +08:00
|
|
|
nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::FlagZero, Subscripts, 0, nullptr);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
|
|
|
return R;
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompositeType *DIBuilder::createVectorType(uint64_t Size,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint32_t AlignInBits, DIType *Ty,
|
2015-04-30 00:38:44 +08:00
|
|
|
DINodeArray Subscripts) {
|
2016-04-24 05:08:00 +08:00
|
|
|
auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
|
|
|
|
nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
|
|
|
|
DINode::FlagVector, Subscripts, 0, nullptr);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
|
|
|
return R;
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
2010-12-08 07:25:47 +08:00
|
|
|
|
2018-06-02 07:15:09 +08:00
|
|
|
DISubprogram *DIBuilder::createArtificialSubprogram(DISubprogram *SP) {
|
|
|
|
auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial);
|
|
|
|
return MDNode::replaceWithDistinct(std::move(NewSP));
|
|
|
|
}
|
|
|
|
|
|
|
|
static DIType *createTypeWithFlags(const DIType *Ty,
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags FlagsToSet) {
|
2018-06-02 07:15:09 +08:00
|
|
|
auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet);
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDNode::replaceWithUniqued(std::move(NewTy));
|
2014-10-04 04:01:09 +08:00
|
|
|
}
|
2014-10-03 06:15:31 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIType *DIBuilder::createArtificialType(DIType *Ty) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Restrict this to the nodes where it's valid.
|
2015-04-16 09:01:28 +08:00
|
|
|
if (Ty->isArtificial())
|
2014-10-04 04:01:09 +08:00
|
|
|
return Ty;
|
2018-06-02 07:15:09 +08:00
|
|
|
return createTypeWithFlags(Ty, DINode::FlagArtificial);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
2010-12-08 07:25:47 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Restrict this to the nodes where it's valid.
|
2015-04-16 09:01:28 +08:00
|
|
|
if (Ty->isObjectPointer())
|
2012-09-13 07:36:19 +08:00
|
|
|
return Ty;
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
|
2018-06-02 07:15:09 +08:00
|
|
|
return createTypeWithFlags(Ty, Flags);
|
2012-09-13 07:36:19 +08:00
|
|
|
}
|
|
|
|
|
2016-04-15 23:57:41 +08:00
|
|
|
void DIBuilder::retainType(DIScope *T) {
|
2015-04-16 09:01:28 +08:00
|
|
|
assert(T && "Expected non-null type");
|
2016-04-15 23:57:41 +08:00
|
|
|
assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
|
|
|
|
cast<DISubprogram>(T)->isDefinition() == false)) &&
|
|
|
|
"Expected type or subprogram declaration");
|
2015-03-28 07:00:49 +08:00
|
|
|
AllRetainTypes.emplace_back(T);
|
|
|
|
}
|
2010-12-08 09:50:15 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
|
2010-12-08 09:50:15 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompositeType *
|
|
|
|
DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope,
|
|
|
|
DIFile *F, unsigned Line, unsigned RuntimeLang,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits,
|
2013-10-16 07:31:31 +08:00
|
|
|
StringRef UniqueIdentifier) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Define in terms of createReplaceableForwardDecl() by calling
|
|
|
|
// replaceWithUniqued().
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *RetTy = DICompositeType::get(
|
2016-04-24 05:08:00 +08:00
|
|
|
VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
|
|
|
|
SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
|
|
|
|
nullptr, nullptr, UniqueIdentifier);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(RetTy);
|
2014-05-06 11:41:57 +08:00
|
|
|
return RetTy;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompositeType *DIBuilder::createReplaceableCompositeType(
|
|
|
|
unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
|
2016-10-18 22:31:22 +08:00
|
|
|
unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags Flags, StringRef UniqueIdentifier) {
|
2016-04-24 05:08:00 +08:00
|
|
|
auto *RetTy =
|
|
|
|
DICompositeType::getTemporary(
|
|
|
|
VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
|
|
|
|
SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
|
|
|
|
nullptr, UniqueIdentifier)
|
|
|
|
.release();
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(RetTy);
|
2013-07-03 02:37:35 +08:00
|
|
|
return RetTy;
|
2012-02-08 08:22:26 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) {
|
2015-04-17 00:36:23 +08:00
|
|
|
return MDTuple::get(VMContext, Elements);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2017-01-12 23:49:46 +08:00
|
|
|
DIMacroNodeArray
|
|
|
|
DIBuilder::getOrCreateMacroArray(ArrayRef<Metadata *> Elements) {
|
|
|
|
return MDTuple::get(VMContext, Elements);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
SmallVector<llvm::Metadata *, 16> Elts;
|
2014-07-29 03:33:20 +08:00
|
|
|
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
|
|
|
|
if (Elements[i] && isa<MDNode>(Elements[i]))
|
2016-04-24 05:08:00 +08:00
|
|
|
Elts.push_back(cast<DIType>(Elements[i]));
|
2014-07-29 03:33:20 +08:00
|
|
|
else
|
|
|
|
Elts.push_back(Elements[i]);
|
|
|
|
}
|
2015-04-30 00:38:44 +08:00
|
|
|
return DITypeRefArray(MDNode::get(VMContext, Elts));
|
2014-07-29 03:33:20 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
|
|
|
|
return DISubrange::get(VMContext, Count, Lo);
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
[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 17:56:07 +08:00
|
|
|
DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, Metadata *CountNode) {
|
|
|
|
return DISubrange::get(VMContext, CountNode, Lo);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
static void checkGlobalVariableScope(DIScope *Context) {
|
2015-04-07 07:34:41 +08:00
|
|
|
#ifndef NDEBUG
|
2015-04-16 09:01:28 +08:00
|
|
|
if (auto *CT =
|
2015-04-30 00:38:44 +08:00
|
|
|
dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context)))
|
2015-04-16 09:01:28 +08:00
|
|
|
assert(CT->getIdentifier().empty() &&
|
2014-11-22 03:47:48 +08:00
|
|
|
"Context of a global variable should not be a type with identifier");
|
2015-04-07 07:34:41 +08:00
|
|
|
#endif
|
2014-09-17 17:28:34 +08:00
|
|
|
}
|
|
|
|
|
2016-12-20 10:09:43 +08:00
|
|
|
DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression(
|
2015-04-30 00:38:44 +08:00
|
|
|
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
|
2016-12-20 10:09:43 +08:00
|
|
|
unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr,
|
|
|
|
MDNode *Decl, uint32_t AlignInBits) {
|
2015-03-04 01:24:31 +08:00
|
|
|
checkGlobalVariableScope(Context);
|
|
|
|
|
2016-12-20 10:09:43 +08:00
|
|
|
auto *GV = DIGlobalVariable::getDistinct(
|
2016-04-24 06:29:09 +08:00
|
|
|
VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
|
2016-12-20 10:09:43 +08:00
|
|
|
LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl),
|
|
|
|
AlignInBits);
|
2017-08-31 02:06:51 +08:00
|
|
|
if (!Expr)
|
|
|
|
Expr = createExpression();
|
2016-12-20 10:09:43 +08:00
|
|
|
auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
|
2015-03-04 01:24:31 +08:00
|
|
|
AllGVs.push_back(N);
|
|
|
|
return N;
|
2014-09-17 17:28:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
|
|
|
|
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
|
2016-12-20 10:09:43 +08:00
|
|
|
unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl,
|
|
|
|
uint32_t AlignInBits) {
|
2015-03-04 01:24:31 +08:00
|
|
|
checkGlobalVariableScope(Context);
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
return DIGlobalVariable::getTemporary(
|
|
|
|
VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
|
2016-12-20 10:09:43 +08:00
|
|
|
LineNumber, Ty, isLocalToUnit, false,
|
2016-10-20 08:13:12 +08:00
|
|
|
cast_or_null<DIDerivedType>(Decl), AlignInBits)
|
2015-04-16 09:37:00 +08:00
|
|
|
.release();
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-08-01 01:55:53 +08:00
|
|
|
static DILocalVariable *createLocalVariable(
|
|
|
|
LLVMContext &VMContext,
|
2016-04-21 04:14:09 +08:00
|
|
|
DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
|
2015-08-01 01:55:53 +08:00
|
|
|
DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
|
2016-10-20 08:13:12 +08:00
|
|
|
unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
|
|
|
|
uint32_t AlignInBits) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Why getNonCompileUnitScope()?
|
|
|
|
// FIXME: Why is "!Context" okay here?
|
2015-07-11 07:26:02 +08:00
|
|
|
// FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
|
2015-03-04 01:24:31 +08:00
|
|
|
// the only valid scopes)?
|
2015-04-30 00:38:44 +08:00
|
|
|
DIScope *Context = getNonCompileUnitScope(Scope);
|
2015-03-04 01:24:31 +08:00
|
|
|
|
2015-08-01 02:58:39 +08:00
|
|
|
auto *Node =
|
|
|
|
DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
|
2016-10-20 08:13:12 +08:00
|
|
|
File, LineNo, Ty, ArgNo, Flags, AlignInBits);
|
2010-12-08 07:58:00 +08:00
|
|
|
if (AlwaysPreserve) {
|
2015-07-11 07:26:02 +08:00
|
|
|
// The optimizer may remove local variables. If there is an interest
|
2010-12-08 07:58:00 +08:00
|
|
|
// to preserve variable info in such situation then stash it in a
|
|
|
|
// named mdnode.
|
2015-04-30 00:38:44 +08:00
|
|
|
DISubprogram *Fn = getDISubprogram(Scope);
|
2014-10-16 00:11:41 +08:00
|
|
|
assert(Fn && "Missing subprogram for local variable");
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
PreservedVariables[Fn].emplace_back(Node);
|
2010-12-08 07:58:00 +08:00
|
|
|
}
|
2015-03-04 01:24:31 +08:00
|
|
|
return Node;
|
2010-12-08 07:58:00 +08:00
|
|
|
}
|
|
|
|
|
2015-08-01 01:55:53 +08:00
|
|
|
DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name,
|
|
|
|
DIFile *File, unsigned LineNo,
|
|
|
|
DIType *Ty, bool AlwaysPreserve,
|
2016-10-20 08:13:12 +08:00
|
|
|
DINode::DIFlags Flags,
|
|
|
|
uint32_t AlignInBits) {
|
2015-08-01 01:55:53 +08:00
|
|
|
return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
|
|
|
|
/* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
|
2016-10-20 08:13:12 +08:00
|
|
|
Flags, AlignInBits);
|
2015-08-01 01:55:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DILocalVariable *DIBuilder::createParameterVariable(
|
|
|
|
DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
|
2016-09-06 18:46:28 +08:00
|
|
|
unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) {
|
2015-08-01 01:55:53 +08:00
|
|
|
assert(ArgNo && "Expected non-zero argument number for parameter");
|
|
|
|
return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
|
2016-10-20 08:13:12 +08:00
|
|
|
File, LineNo, Ty, AlwaysPreserve, Flags,
|
|
|
|
/* AlignInBits */0);
|
2015-08-01 01:55:53 +08:00
|
|
|
}
|
|
|
|
|
[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 10:40:45 +08:00
|
|
|
DILabel *DIBuilder::createLabel(
|
|
|
|
DIScope *Scope, StringRef Name, DIFile *File,
|
|
|
|
unsigned LineNo, bool AlwaysPreserve) {
|
|
|
|
DIScope *Context = getNonCompileUnitScope(Scope);
|
|
|
|
|
|
|
|
auto *Node =
|
|
|
|
DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
|
|
|
|
File, LineNo);
|
|
|
|
|
|
|
|
if (AlwaysPreserve) {
|
|
|
|
/// The optimizer may remove labels. If there is an interest
|
|
|
|
/// to preserve label info in such situation then append it to
|
|
|
|
/// the list of retained nodes of the DISubprogram.
|
|
|
|
DISubprogram *Fn = getDISubprogram(Scope);
|
|
|
|
assert(Fn && "Missing subprogram for label");
|
|
|
|
PreservedLabels[Fn].emplace_back(Node);
|
|
|
|
}
|
|
|
|
return Node;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {
|
|
|
|
return DIExpression::get(VMContext, Addr);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
|
2015-02-10 06:13:27 +08:00
|
|
|
// TODO: Remove the callers of this signed version and delete.
|
|
|
|
SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
|
|
|
|
return createExpression(Addr);
|
|
|
|
}
|
|
|
|
|
2015-08-27 06:50:16 +08:00
|
|
|
template <class... Ts>
|
|
|
|
static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
|
|
|
|
if (IsDistinct)
|
|
|
|
return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
|
|
|
|
return DISubprogram::get(std::forward<Ts>(Args)...);
|
|
|
|
}
|
|
|
|
|
2015-11-06 06:03:56 +08:00
|
|
|
DISubprogram *DIBuilder::createFunction(
|
|
|
|
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
|
|
|
|
unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
|
2016-09-07 01:03:02 +08:00
|
|
|
bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags,
|
2017-04-27 06:56:44 +08:00
|
|
|
bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl,
|
|
|
|
DITypeArray ThrownTypes) {
|
2016-04-15 23:57:41 +08:00
|
|
|
auto *Node = getSubprogram(
|
|
|
|
/* IsDistinct = */ isDefinition, VMContext,
|
2016-04-24 05:08:00 +08:00
|
|
|
getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty,
|
2016-07-01 10:41:21 +08:00
|
|
|
isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, 0, Flags,
|
|
|
|
isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl,
|
2017-04-27 06:56:44 +08:00
|
|
|
MDTuple::getTemporary(VMContext, None).release(), ThrownTypes);
|
2015-03-04 01:24:31 +08:00
|
|
|
|
|
|
|
if (isDefinition)
|
|
|
|
AllSubprograms.push_back(Node);
|
|
|
|
trackIfUnresolved(Node);
|
|
|
|
return Node;
|
2014-09-17 17:28:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DISubprogram *DIBuilder::createTempFunctionFwdDecl(
|
|
|
|
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
|
|
|
|
unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
|
2016-09-07 01:03:02 +08:00
|
|
|
bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags,
|
2017-04-27 06:56:44 +08:00
|
|
|
bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl,
|
|
|
|
DITypeArray ThrownTypes) {
|
2015-04-30 00:38:44 +08:00
|
|
|
return DISubprogram::getTemporary(
|
2016-04-24 05:08:00 +08:00
|
|
|
VMContext, getNonCompileUnitScope(Context), Name, LinkageName,
|
|
|
|
File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr,
|
2016-07-01 10:41:21 +08:00
|
|
|
0, 0, 0, Flags, isOptimized, isDefinition ? CUNode : nullptr,
|
2017-04-27 06:56:44 +08:00
|
|
|
TParams, Decl, nullptr, ThrownTypes)
|
2015-04-30 00:38:44 +08:00
|
|
|
.release();
|
|
|
|
}
|
|
|
|
|
2017-04-27 06:56:44 +08:00
|
|
|
DISubprogram *DIBuilder::createMethod(
|
|
|
|
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
|
|
|
|
unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
|
|
|
|
bool isDefinition, unsigned VK, unsigned VIndex, int ThisAdjustment,
|
|
|
|
DIType *VTableHolder, DINode::DIFlags Flags, bool isOptimized,
|
|
|
|
DITemplateParameterArray TParams, DITypeArray ThrownTypes) {
|
2013-10-16 07:31:36 +08:00
|
|
|
assert(getNonCompileUnitScope(Context) &&
|
|
|
|
"Methods should have both a Context and a context that isn't "
|
|
|
|
"the compile unit.");
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Do we want to use different scope/lines?
|
2015-11-06 06:03:56 +08:00
|
|
|
auto *SP = getSubprogram(
|
2016-04-24 05:08:00 +08:00
|
|
|
/* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name,
|
|
|
|
LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
|
2016-07-01 10:41:21 +08:00
|
|
|
VTableHolder, VK, VIndex, ThisAdjustment, Flags, isOptimized,
|
2017-04-27 06:56:44 +08:00
|
|
|
isDefinition ? CUNode : nullptr, TParams, nullptr, nullptr, ThrownTypes);
|
2015-03-04 01:24:31 +08:00
|
|
|
|
2013-02-18 15:10:22 +08:00
|
|
|
if (isDefinition)
|
2015-04-07 07:18:49 +08:00
|
|
|
AllSubprograms.push_back(SP);
|
|
|
|
trackIfUnresolved(SP);
|
|
|
|
return SP;
|
2010-12-09 04:42:44 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
|
2016-11-04 03:42:02 +08:00
|
|
|
bool ExportSymbols) {
|
2017-04-29 06:25:46 +08:00
|
|
|
|
|
|
|
// It is okay to *not* make anonymous top-level namespaces distinct, because
|
|
|
|
// all nodes that have an anonymous namespace as their parent scope are
|
|
|
|
// guaranteed to be unique and/or are linked to their containing
|
|
|
|
// DICompileUnit. This decision is an explicit tradeoff of link time versus
|
|
|
|
// memory usage versus code simplicity and may get revisited in the future.
|
|
|
|
return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
|
|
|
|
ExportSymbols);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-06-30 07:03:47 +08:00
|
|
|
DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,
|
|
|
|
StringRef ConfigurationMacros,
|
|
|
|
StringRef IncludePath,
|
|
|
|
StringRef ISysRoot) {
|
|
|
|
return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
|
|
|
|
ConfigurationMacros, IncludePath, ISysRoot);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope,
|
|
|
|
DIFile *File,
|
|
|
|
unsigned Discriminator) {
|
|
|
|
return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
|
2011-10-12 06:59:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
|
|
|
|
unsigned Line, unsigned Col) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// Make these distinct, to avoid merging two lexical blocks on the same
|
|
|
|
// file/line/column.
|
2015-04-30 00:38:44 +08:00
|
|
|
return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
|
2015-04-16 07:19:27 +08:00
|
|
|
File, Line, Col);
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2017-10-04 04:36:40 +08:00
|
|
|
Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
|
|
|
|
DIExpression *Expr, const DILocation *DL,
|
|
|
|
Instruction *InsertBefore) {
|
|
|
|
return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
|
|
|
|
InsertBefore);
|
|
|
|
}
|
|
|
|
|
|
|
|
Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
|
|
|
|
DIExpression *Expr, const DILocation *DL,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
// If this block already has a terminator then insert this intrinsic before
|
|
|
|
// the terminator. Otherwise, put it at the end of the block.
|
|
|
|
Instruction *InsertBefore = InsertAtEnd->getTerminator();
|
|
|
|
return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
|
|
|
|
}
|
|
|
|
|
[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 10:40:45 +08:00
|
|
|
Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
|
|
|
|
Instruction *InsertBefore) {
|
|
|
|
return insertLabel(
|
|
|
|
LabelInfo, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
|
|
|
|
InsertBefore);
|
|
|
|
}
|
|
|
|
|
|
|
|
Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr);
|
|
|
|
}
|
|
|
|
|
2017-10-04 04:36:40 +08:00
|
|
|
Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
|
|
|
|
DILocalVariable *VarInfo,
|
|
|
|
DIExpression *Expr,
|
|
|
|
const DILocation *DL,
|
|
|
|
Instruction *InsertBefore) {
|
|
|
|
return insertDbgValueIntrinsic(
|
|
|
|
V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
|
|
|
|
InsertBefore);
|
|
|
|
}
|
|
|
|
|
|
|
|
Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
|
|
|
|
DILocalVariable *VarInfo,
|
|
|
|
DIExpression *Expr,
|
|
|
|
const DILocation *DL,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This
|
|
|
|
/// abstracts over the various ways to specify an insert position.
|
|
|
|
static IRBuilder<> getIRBForDbgInsertion(const DILocation *DL,
|
|
|
|
BasicBlock *InsertBB,
|
|
|
|
Instruction *InsertBefore) {
|
|
|
|
IRBuilder<> B(DL->getContext());
|
|
|
|
if (InsertBefore)
|
|
|
|
B.SetInsertPoint(InsertBefore);
|
|
|
|
else if (InsertBB)
|
|
|
|
B.SetInsertPoint(InsertBB);
|
|
|
|
B.SetCurrentDebugLocation(DL);
|
|
|
|
return B;
|
|
|
|
}
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
|
|
|
|
assert(V && "no value passed to dbg intrinsic");
|
|
|
|
return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
|
|
|
|
}
|
|
|
|
|
2017-09-22 03:52:03 +08:00
|
|
|
static Function *getDeclareIntrin(Module &M) {
|
|
|
|
return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr
|
|
|
|
: Intrinsic::dbg_declare);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
|
|
|
|
DIExpression *Expr, const DILocation *DL,
|
2017-10-04 04:36:40 +08:00
|
|
|
BasicBlock *InsertBB, Instruction *InsertBefore) {
|
2015-04-30 00:38:44 +08:00
|
|
|
assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
|
2015-04-16 05:18:07 +08:00
|
|
|
assert(DL && "Expected debug loc");
|
|
|
|
assert(DL->getScope()->getSubprogram() ==
|
|
|
|
VarInfo->getScope()->getSubprogram() &&
|
|
|
|
"Expected matching subprograms");
|
2010-12-08 07:25:47 +08:00
|
|
|
if (!DeclareFn)
|
2017-09-22 03:52:03 +08:00
|
|
|
DeclareFn = getDeclareIntrin(M);
|
2010-12-08 07:25:47 +08:00
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2010-12-08 07:25:47 +08:00
|
|
|
|
2017-10-04 04:36:40 +08:00
|
|
|
IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
|
|
|
|
return B.CreateCall(DeclareFn, Args);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2017-10-04 04:36:40 +08:00
|
|
|
Instruction *DIBuilder::insertDbgValueIntrinsic(
|
|
|
|
Value *V, DILocalVariable *VarInfo, DIExpression *Expr,
|
|
|
|
const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
|
2010-12-08 07:25:47 +08:00
|
|
|
assert(V && "no value passed to dbg.value");
|
2015-04-30 00:38:44 +08:00
|
|
|
assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
|
2015-04-16 05:18:07 +08:00
|
|
|
assert(DL && "Expected debug loc");
|
|
|
|
assert(DL->getScope()->getSubprogram() ==
|
|
|
|
VarInfo->getScope()->getSubprogram() &&
|
|
|
|
"Expected matching subprograms");
|
2010-12-08 07:25:47 +08:00
|
|
|
if (!ValueFn)
|
|
|
|
ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2015-04-16 05:18:07 +08:00
|
|
|
|
2017-10-04 04:36:40 +08:00
|
|
|
IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
|
|
|
|
return B.CreateCall(ValueFn, Args);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
2014-12-18 08:46:16 +08:00
|
|
|
|
[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 10:40:45 +08:00
|
|
|
Instruction *DIBuilder::insertLabel(
|
|
|
|
DILabel *LabelInfo, const DILocation *DL,
|
|
|
|
BasicBlock *InsertBB, Instruction *InsertBefore) {
|
|
|
|
assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
|
|
|
|
assert(DL && "Expected debug loc");
|
|
|
|
assert(DL->getScope()->getSubprogram() ==
|
|
|
|
LabelInfo->getScope()->getSubprogram() &&
|
|
|
|
"Expected matching subprograms");
|
|
|
|
if (!LabelFn)
|
|
|
|
LabelFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_label);
|
|
|
|
|
|
|
|
trackIfUnresolved(LabelInfo);
|
|
|
|
Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
|
|
|
|
|
|
|
|
IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
|
|
|
|
return B.CreateCall(LabelFn, Args);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
void DIBuilder::replaceVTableHolder(DICompositeType *&T,
|
2017-11-09 06:04:43 +08:00
|
|
|
DIType *VTableHolder) {
|
2015-04-07 12:12:02 +08:00
|
|
|
{
|
2015-04-30 00:38:44 +08:00
|
|
|
TypedTrackingMDRef<DICompositeType> N(T);
|
2016-04-24 05:08:00 +08:00
|
|
|
N->replaceVTableHolder(VTableHolder);
|
2015-04-07 12:12:02 +08:00
|
|
|
T = N.get();
|
|
|
|
}
|
2014-12-18 08:46:16 +08:00
|
|
|
|
|
|
|
// If this didn't create a self-reference, just return.
|
|
|
|
if (T != VTableHolder)
|
|
|
|
return;
|
|
|
|
|
2015-02-12 01:45:10 +08:00
|
|
|
// Look for unresolved operands. T will drop RAUW support, orphaning any
|
|
|
|
// cycles underneath it.
|
|
|
|
if (T->isResolved())
|
|
|
|
for (const MDOperand &O : T->operands())
|
|
|
|
if (auto *N = dyn_cast_or_null<MDNode>(O))
|
|
|
|
trackIfUnresolved(N);
|
2014-12-18 08:46:16 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
|
|
|
|
DINodeArray TParams) {
|
2015-04-07 12:12:02 +08:00
|
|
|
{
|
2015-04-30 00:38:44 +08:00
|
|
|
TypedTrackingMDRef<DICompositeType> N(T);
|
2015-04-07 12:12:02 +08:00
|
|
|
if (Elements)
|
2015-04-07 12:14:33 +08:00
|
|
|
N->replaceElements(Elements);
|
2015-04-07 12:12:02 +08:00
|
|
|
if (TParams)
|
2015-04-30 00:38:44 +08:00
|
|
|
N->replaceTemplateParams(DITemplateParameterArray(TParams));
|
2015-04-07 12:12:02 +08:00
|
|
|
T = N.get();
|
|
|
|
}
|
2014-12-18 08:46:16 +08:00
|
|
|
|
|
|
|
// If T isn't resolved, there's no problem.
|
|
|
|
if (!T->isResolved())
|
|
|
|
return;
|
|
|
|
|
2015-07-11 07:26:02 +08:00
|
|
|
// If T is resolved, it may be due to a self-reference cycle. Track the
|
2014-12-18 08:46:16 +08:00
|
|
|
// arrays explicitly if they're unresolved, or else the cycles will be
|
|
|
|
// orphaned.
|
|
|
|
if (Elements)
|
2015-04-08 00:50:39 +08:00
|
|
|
trackIfUnresolved(Elements.get());
|
2014-12-18 08:46:16 +08:00
|
|
|
if (TParams)
|
2015-04-08 00:50:39 +08:00
|
|
|
trackIfUnresolved(TParams.get());
|
2014-12-18 08:46:16 +08:00
|
|
|
}
|