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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00: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 00:22:06 +00:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
2014-03-06 00:46:21 +00:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2012-04-03 00:43:49 +00: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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::dwarf;
|
|
|
|
|
2014-10-03 20:01:09 +00:00
|
|
|
namespace {
|
|
|
|
class HeaderBuilder {
|
2015-01-20 05:02:42 +00:00
|
|
|
/// \brief Whether there are any fields yet.
|
|
|
|
///
|
|
|
|
/// Note that this is not equivalent to \c Chars.empty(), since \a concat()
|
|
|
|
/// may have been called already with an empty string.
|
|
|
|
bool IsEmpty;
|
2014-10-03 20:01:09 +00:00
|
|
|
SmallVector<char, 256> Chars;
|
|
|
|
|
|
|
|
public:
|
2015-01-20 05:02:42 +00:00
|
|
|
HeaderBuilder() : IsEmpty(true) {}
|
|
|
|
HeaderBuilder(const HeaderBuilder &X) : IsEmpty(X.IsEmpty), Chars(X.Chars) {}
|
|
|
|
HeaderBuilder(HeaderBuilder &&X)
|
|
|
|
: IsEmpty(X.IsEmpty), Chars(std::move(X.Chars)) {}
|
2014-10-03 20:01:09 +00:00
|
|
|
|
|
|
|
template <class Twineable> HeaderBuilder &concat(Twineable &&X) {
|
2015-01-20 05:02:42 +00:00
|
|
|
if (IsEmpty)
|
|
|
|
IsEmpty = false;
|
|
|
|
else
|
|
|
|
Chars.push_back(0);
|
2014-10-03 20:01:09 +00:00
|
|
|
Twine(X).toVector(Chars);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
MDString *get(LLVMContext &Context) const {
|
|
|
|
return MDString::get(Context, StringRef(Chars.begin(), Chars.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HeaderBuilder get(unsigned Tag) {
|
2015-01-20 05:02:42 +00:00
|
|
|
return HeaderBuilder().concat("0x" + Twine::utohexstr(Tag));
|
2014-10-03 20:01:09 +00: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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
2010-12-07 23:58:00 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
|
2014-04-09 06:08:46 +00:00
|
|
|
: M(m), VMContext(M.getContext()), TempEnumTypes(nullptr),
|
|
|
|
TempRetainTypes(nullptr), TempSubprograms(nullptr), TempGVs(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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
DeclareFn(nullptr), ValueFn(nullptr),
|
|
|
|
AllowUnresolvedNodes(AllowUnresolvedNodes) {}
|
|
|
|
|
|
|
|
void DIBuilder::trackIfUnresolved(MDNode *N) {
|
2015-01-19 19:09:14 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
return;
|
2015-01-19 19:09:14 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00: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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
|
2011-08-15 23:00:00 +00:00
|
|
|
void DIBuilder::finalize() {
|
2011-08-16 22:09:43 +00:00
|
|
|
DIArray Enums = getOrCreateArray(AllEnumTypes);
|
|
|
|
DIType(TempEnumTypes).replaceAllUsesWith(Enums);
|
|
|
|
|
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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
SmallVector<Metadata *, 16> RetainValues;
|
2013-08-29 23:17:54 +00:00
|
|
|
// 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.
|
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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
SmallPtrSet<Metadata *, 16> RetainSet;
|
2013-08-29 23:17:54 +00:00
|
|
|
for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
|
2014-11-19 07:49:26 +00:00
|
|
|
if (RetainSet.insert(AllRetainTypes[I]).second)
|
2013-08-29 23:17:54 +00:00
|
|
|
RetainValues.push_back(AllRetainTypes[I]);
|
|
|
|
DIArray RetainTypes = getOrCreateArray(RetainValues);
|
2011-08-16 22:09:43 +00:00
|
|
|
DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
|
|
|
|
|
|
|
|
DIArray SPs = getOrCreateArray(AllSubprograms);
|
|
|
|
DIType(TempSubprograms).replaceAllUsesWith(SPs);
|
2011-08-19 23:28:12 +00:00
|
|
|
for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
|
|
|
|
DISubprogram SP(SPs.getElement(i));
|
2012-04-23 19:00:11 +00:00
|
|
|
if (MDNode *Temp = SP.getVariablesNodes()) {
|
2015-02-17 15:29:18 +00:00
|
|
|
const auto &PV = PreservedVariables.lookup(SP);
|
|
|
|
SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
|
2012-04-23 19:00:11 +00:00
|
|
|
DIArray AV = getOrCreateArray(Variables);
|
|
|
|
DIType(Temp).replaceAllUsesWith(AV);
|
|
|
|
}
|
2011-08-19 23:28:12 +00:00
|
|
|
}
|
2011-08-16 22:09:43 +00:00
|
|
|
|
|
|
|
DIArray GVs = getOrCreateArray(AllGVs);
|
|
|
|
DIType(TempGVs).replaceAllUsesWith(GVs);
|
2013-04-22 06:12:31 +00:00
|
|
|
|
2015-02-17 15:29:18 +00:00
|
|
|
SmallVector<Metadata *, 16> RetainValuesI(AllImportedModules.begin(),
|
|
|
|
AllImportedModules.end());
|
2014-02-28 21:27:57 +00:00
|
|
|
DIArray IMs = getOrCreateArray(RetainValuesI);
|
2013-04-22 06:12:31 +00:00
|
|
|
DIType(TempImportedModules).replaceAllUsesWith(IMs);
|
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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
|
|
|
|
// Now that all temp nodes have been replaced or deleted, resolve remaining
|
|
|
|
// cycles.
|
|
|
|
for (const auto &N : UnresolvedNodes)
|
2015-01-19 23:13:14 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
UnresolvedNodes.clear();
|
|
|
|
|
|
|
|
// Can't handle unresolved nodes anymore.
|
|
|
|
AllowUnresolvedNodes = false;
|
2011-08-16 22:09:43 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 21:32:15 +00:00
|
|
|
/// If N is compile unit return NULL otherwise return N.
|
2011-08-16 22:09:43 +00:00
|
|
|
static MDNode *getNonCompileUnitScope(MDNode *N) {
|
|
|
|
if (DIDescriptor(N).isCompileUnit())
|
2014-04-09 06:08:46 +00:00
|
|
|
return nullptr;
|
2011-08-16 22:09:43 +00:00
|
|
|
return N;
|
2011-08-15 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 00:51:47 +00:00
|
|
|
DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
|
|
|
|
StringRef Directory,
|
|
|
|
StringRef Producer, bool isOptimized,
|
|
|
|
StringRef Flags, unsigned RunTimeVer,
|
2014-02-27 01:24:56 +00:00
|
|
|
StringRef SplitName,
|
2014-06-24 17:02:03 +00:00
|
|
|
DebugEmissionKind Kind,
|
|
|
|
bool EmitDebugInfo) {
|
2014-02-27 01:24:56 +00:00
|
|
|
|
2015-02-07 06:35:30 +00:00
|
|
|
assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
|
2012-01-10 18:18:52 +00:00
|
|
|
(Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
|
|
|
|
"Invalid Language tag");
|
|
|
|
assert(!Filename.empty() &&
|
|
|
|
"Unable to create compile unit without filename");
|
2011-08-16 22:09:43 +00:00
|
|
|
|
2015-02-12 21:52:11 +00:00
|
|
|
// TODO: Once we make MDCompileUnit distinct, stop using temporaries here
|
|
|
|
// (just start with operands assigned to nullptr).
|
|
|
|
TempEnumTypes = MDTuple::getTemporary(VMContext, None).release();
|
|
|
|
TempRetainTypes = MDTuple::getTemporary(VMContext, None).release();
|
|
|
|
TempSubprograms = MDTuple::getTemporary(VMContext, None).release();
|
|
|
|
TempGVs = MDTuple::getTemporary(VMContext, None).release();
|
|
|
|
TempImportedModules = MDTuple::getTemporary(VMContext, None).release();
|
2013-04-22 06:12:31 +00:00
|
|
|
|
2015-02-12 21:52:11 +00:00
|
|
|
// TODO: Switch to getDistinct(). We never want to merge compile units based
|
|
|
|
// on contents.
|
2015-03-03 17:24:31 +00:00
|
|
|
MDNode *CUNode = MDCompileUnit::get(
|
|
|
|
VMContext, Lang, MDFile::get(VMContext, Filename, Directory), Producer,
|
|
|
|
isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes,
|
|
|
|
TempRetainTypes, TempSubprograms, TempGVs, TempImportedModules);
|
2011-05-03 16:18:28 +00:00
|
|
|
|
|
|
|
// Create a named metadata so that it is easier to find cu in a module.
|
2014-06-24 17:02:03 +00:00
|
|
|
// Note that we only generate this when the caller wants to actually
|
|
|
|
// emit debug information. When we are only interested in tracking
|
|
|
|
// source line locations throughout the backend, we prevent codegen from
|
|
|
|
// emitting debug info in the final output by not generating llvm.dbg.cu.
|
|
|
|
if (EmitDebugInfo) {
|
|
|
|
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
|
|
|
|
NMD->addOperand(CUNode);
|
|
|
|
}
|
2013-07-19 00:51:47 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
trackIfUnresolved(CUNode);
|
2013-07-19 00:51:47 +00:00
|
|
|
return DICompileUnit(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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-05-20 22:50:35 +00:00
|
|
|
static DIImportedEntity
|
2014-04-06 06:29:01 +00:00
|
|
|
createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
|
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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
Metadata *NS, unsigned Line, StringRef Name,
|
|
|
|
SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
|
2015-03-03 17:24:31 +00:00
|
|
|
DIImportedEntity M = MDImportedEntity::get(C, Tag, Context, NS, Line, Name);
|
2013-05-07 21:35:53 +00:00
|
|
|
assert(M.Verify() && "Imported module should be valid");
|
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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
AllImportedModules.emplace_back(M.get());
|
2013-05-07 21:35:53 +00:00
|
|
|
return M;
|
|
|
|
}
|
|
|
|
|
2013-05-20 22:50:35 +00:00
|
|
|
DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
|
2014-04-06 06:29:01 +00:00
|
|
|
DINameSpace NS,
|
|
|
|
unsigned Line) {
|
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
|
|
|
Context, NS, Line, StringRef(), AllImportedModules);
|
2013-05-20 22:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
|
|
|
|
DIImportedEntity NS,
|
2014-04-06 06:29:01 +00:00
|
|
|
unsigned Line) {
|
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
|
|
|
Context, NS, Line, StringRef(), AllImportedModules);
|
2013-05-20 22:50:35 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 21:35:53 +00:00
|
|
|
DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
|
2014-11-06 17:46:55 +00:00
|
|
|
DIDescriptor Decl,
|
2014-04-06 06:29:01 +00:00
|
|
|
unsigned Line, StringRef Name) {
|
2014-11-06 17:46:55 +00:00
|
|
|
// Make sure to use the unique identifier based metadata reference for
|
|
|
|
// types that have one.
|
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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
Metadata *V =
|
|
|
|
Decl.isType() ? static_cast<Metadata *>(DIType(Decl).getRef()) : Decl;
|
2014-04-06 06:29:01 +00:00
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
|
2014-11-06 17:46:55 +00:00
|
|
|
Context, V, Line, Name,
|
2014-04-06 06:29:01 +00:00
|
|
|
AllImportedModules);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
|
|
|
|
DIImportedEntity Imp,
|
|
|
|
unsigned Line, StringRef Name) {
|
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
|
|
|
|
Context, Imp, Line, Name, AllImportedModules);
|
2013-04-22 06:12:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 18:56:12 +00:00
|
|
|
DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDFile::get(VMContext, Filename, Directory);
|
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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 17:34:33 +00:00
|
|
|
DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
|
2011-09-12 18:26:08 +00:00
|
|
|
assert(!Name.empty() && "Unable to create enumerator without name");
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDEnumerator::get(VMContext, Val, 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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 22:50:59 +00:00
|
|
|
DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
|
2011-09-14 23:13:28 +00:00
|
|
|
assert(!Name.empty() && "Unable to create type without name");
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
|
2011-09-14 23:13:28 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 22:50:59 +00:00
|
|
|
DIBasicType DIBuilder::createNullPtrType() {
|
|
|
|
return createUnspecifiedType("decltype(nullptr)");
|
|
|
|
}
|
|
|
|
|
2013-02-12 00:40:41 +00:00
|
|
|
DIBasicType
|
|
|
|
DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, unsigned Encoding) {
|
2011-09-12 18:26:08 +00:00
|
|
|
assert(!Name.empty() && "Unable to create type without name");
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
|
|
|
|
AlignInBits, Encoding);
|
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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 06:41:57 +00:00
|
|
|
DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
|
|
|
|
FromTy.getRef(), 0, 0, 0, 0);
|
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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 06:41:57 +00:00
|
|
|
DIDerivedType
|
|
|
|
DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, StringRef Name) {
|
2015-03-03 17:24:31 +00:00
|
|
|
// FIXME: Why is there a name here?
|
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
|
|
|
|
nullptr, 0, nullptr, PointeeTy.getRef(), SizeInBits,
|
|
|
|
AlignInBits, 0, 0);
|
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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2014-12-23 19:11:47 +00:00
|
|
|
DIDerivedType
|
|
|
|
DIBuilder::createMemberPointerType(DIType PointeeTy, DIType Base,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
|
|
|
|
nullptr, 0, nullptr, PointeeTy.getRef(), SizeInBits,
|
|
|
|
AlignInBits, 0, 0, Base.getRef());
|
2013-01-07 05:51:15 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 06:41:57 +00:00
|
|
|
DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
|
2013-07-01 21:02:01 +00:00
|
|
|
assert(RTy.isType() && "Unable to create reference type");
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
|
|
|
|
RTy.getRef(), 0, 0, 0, 0);
|
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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 06:41:57 +00:00
|
|
|
DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
|
|
|
|
unsigned LineNo, DIDescriptor Context) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name,
|
|
|
|
File.getFileNode(), LineNo,
|
|
|
|
DIScope(getNonCompileUnitScope(Context)).getRef(),
|
|
|
|
Ty.getRef(), 0, 0, 0, 0);
|
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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 18:35:53 +00:00
|
|
|
DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
|
2010-11-04 18:45:27 +00:00
|
|
|
// typedefs are encoded in DIDerivedType format.
|
2013-07-01 21:02:01 +00:00
|
|
|
assert(Ty.isType() && "Invalid type!");
|
|
|
|
assert(FriendTy.isType() && "Invalid friend type!");
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0,
|
|
|
|
Ty.getRef(), FriendTy.getRef(), 0, 0, 0, 0);
|
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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 23:31:31 +00:00
|
|
|
DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
|
|
|
|
uint64_t BaseOffset,
|
|
|
|
unsigned Flags) {
|
2013-07-01 21:02:01 +00:00
|
|
|
assert(Ty.isType() && "Unable to create inheritance");
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
|
|
|
|
0, Ty.getRef(), BaseTy.getRef(), 0, 0, BaseOffset,
|
|
|
|
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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 23:31:31 +00:00
|
|
|
DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
|
|
|
|
DIFile File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits, unsigned Flags,
|
|
|
|
DIType Ty) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
|
|
|
|
DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, 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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
static Metadata *getConstantOrNull(Constant *C) {
|
|
|
|
if (C)
|
|
|
|
return ConstantAsMetadata::get(C);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-15 00:23:49 +00:00
|
|
|
DIDerivedType DIBuilder::createStaticMemberType(DIDescriptor Scope,
|
|
|
|
StringRef Name, DIFile File,
|
|
|
|
unsigned LineNumber, DIType Ty,
|
|
|
|
unsigned Flags,
|
|
|
|
llvm::Constant *Val) {
|
2013-01-16 01:22:23 +00:00
|
|
|
// TAG_member is encoded in DIDerivedType format.
|
|
|
|
Flags |= DIDescriptor::FlagStaticMember;
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
|
|
|
|
DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), 0, 0, 0,
|
|
|
|
Flags, getConstantOrNull(Val));
|
2013-01-16 01:22:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 23:31:31 +00:00
|
|
|
DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
|
|
|
|
unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits, unsigned Flags,
|
|
|
|
DIType Ty, MDNode *PropertyNode) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
|
|
|
LineNumber, getNonCompileUnitScope(File),
|
|
|
|
Ty.getRef(), SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
Flags, PropertyNode);
|
2011-04-16 00:11:51 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 23:31:31 +00:00
|
|
|
DIObjCProperty
|
|
|
|
DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
|
|
|
|
StringRef GetterName, StringRef SetterName,
|
|
|
|
unsigned PropertyAttributes, DIType Ty) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
|
|
|
|
SetterName, PropertyAttributes, Ty);
|
2012-02-04 00:59:25 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 21:02:40 +00:00
|
|
|
DITemplateTypeParameter
|
2011-02-22 18:56:12 +00:00
|
|
|
DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
|
2015-02-13 03:35:29 +00:00
|
|
|
DIType Ty) {
|
2015-02-18 20:30:45 +00:00
|
|
|
assert(!DIScope(getNonCompileUnitScope(Context)).getRef() &&
|
|
|
|
"Expected compile unit");
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDTemplateTypeParameter::get(VMContext, Name, Ty.getRef());
|
2011-02-02 21:38:25 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 03:35:29 +00:00
|
|
|
static DITemplateValueParameter
|
|
|
|
createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
|
|
|
|
DIDescriptor Context, StringRef Name,
|
|
|
|
DIType Ty, Metadata *MD) {
|
2015-02-18 20:30:45 +00:00
|
|
|
assert(!DIScope(getNonCompileUnitScope(Context)).getRef() &&
|
|
|
|
"Expected compile unit");
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDTemplateValueParameter::get(VMContext, Tag, Name, Ty.getRef(), MD);
|
2011-02-02 22:35:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-22 18:59:11 +00:00
|
|
|
DITemplateValueParameter
|
|
|
|
DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
|
2015-02-13 03:35:29 +00:00
|
|
|
DIType Ty, Constant *Val) {
|
2014-11-15 00:05:04 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
|
2015-02-13 03:35:29 +00:00
|
|
|
getConstantOrNull(Val));
|
2013-06-22 18:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DITemplateValueParameter
|
|
|
|
DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
|
2015-02-13 03:35:29 +00:00
|
|
|
DIType Ty, StringRef Val) {
|
2014-11-15 00:05:04 +00:00
|
|
|
return createTemplateValueParameterHelper(
|
|
|
|
VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
|
2015-02-13 03:35:29 +00:00
|
|
|
MDString::get(VMContext, Val));
|
2013-06-22 18:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DITemplateValueParameter
|
|
|
|
DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
|
2015-02-13 03:35:29 +00:00
|
|
|
DIType Ty, DIArray Val) {
|
2014-11-15 00:05:04 +00:00
|
|
|
return createTemplateValueParameterHelper(
|
|
|
|
VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
|
2015-02-13 03:35:29 +00:00
|
|
|
Val);
|
2013-06-22 18:59:11 +00:00
|
|
|
}
|
|
|
|
|
2013-03-26 23:46:39 +00:00
|
|
|
DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
|
|
|
|
DIFile File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits,
|
|
|
|
unsigned Flags, DIType DerivedFrom,
|
|
|
|
DIArray Elements,
|
2013-09-06 23:54:23 +00:00
|
|
|
DIType VTableHolder,
|
2013-08-27 23:06:40 +00:00
|
|
|
MDNode *TemplateParams,
|
|
|
|
StringRef UniqueIdentifier) {
|
2013-07-01 21:02:01 +00:00
|
|
|
assert((!Context || Context.isScope() || Context.isType()) &&
|
2013-03-11 23:21:19 +00:00
|
|
|
"createClassType should be called with a valid Context");
|
|
|
|
// TAG_class_type is encoded in DICompositeType format.
|
2015-03-03 17:24:31 +00:00
|
|
|
DICompositeType R = MDCompositeType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
|
|
|
|
DIScope(getNonCompileUnitScope(Context)).getRef(), DerivedFrom.getRef(),
|
|
|
|
SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, 0,
|
|
|
|
VTableHolder.getRef(), TemplateParams, UniqueIdentifier);
|
2013-08-29 23:17:54 +00:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(R);
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(R);
|
2013-03-11 23:21:19 +00:00
|
|
|
return R;
|
2012-07-06 02:35:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-25 01:07:18 +00:00
|
|
|
DICompositeType DIBuilder::createStructType(DIDescriptor Context,
|
|
|
|
StringRef Name, DIFile File,
|
|
|
|
unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
unsigned Flags, DIType DerivedFrom,
|
|
|
|
DIArray Elements,
|
|
|
|
unsigned RunTimeLang,
|
2013-09-06 23:54:23 +00:00
|
|
|
DIType VTableHolder,
|
2013-08-27 23:06:40 +00:00
|
|
|
StringRef UniqueIdentifier) {
|
2015-03-03 17:24:31 +00:00
|
|
|
DICompositeType R = MDCompositeType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
|
|
|
|
DIScope(getNonCompileUnitScope(Context)).getRef(), DerivedFrom.getRef(),
|
|
|
|
SizeInBits, AlignInBits, 0, Flags, Elements, RunTimeLang,
|
|
|
|
VTableHolder.getRef(), nullptr, UniqueIdentifier);
|
2013-08-29 23:17:54 +00:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(R);
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(R);
|
2013-03-11 23:21:19 +00:00
|
|
|
return R;
|
2010-12-07 23:25:47 +00:00
|
|
|
}
|
|
|
|
|
2013-04-02 22:55:52 +00:00
|
|
|
DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
|
|
|
|
DIFile File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, unsigned Flags,
|
|
|
|
DIArray Elements,
|
2013-08-27 23:06:40 +00:00
|
|
|
unsigned RunTimeLang,
|
|
|
|
StringRef UniqueIdentifier) {
|
2015-03-03 17:24:31 +00:00
|
|
|
DICompositeType R = MDCompositeType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
|
|
|
|
DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
|
|
|
|
AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr,
|
|
|
|
UniqueIdentifier);
|
2013-08-29 23:17:54 +00:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(R);
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(R);
|
2013-08-29 23:17:54 +00:00
|
|
|
return R;
|
2010-12-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 22:24:06 +00:00
|
|
|
DISubroutineType DIBuilder::createSubroutineType(DIFile File,
|
|
|
|
DITypeArray ParameterTypes,
|
|
|
|
unsigned Flags) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDSubroutineType::get(VMContext, Flags, ParameterTypes);
|
2010-12-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 06:41:57 +00:00
|
|
|
DICompositeType DIBuilder::createEnumerationType(
|
|
|
|
DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
|
2013-08-27 23:06:40 +00:00
|
|
|
DIType UnderlyingType, StringRef UniqueIdentifier) {
|
2015-03-03 17:24:31 +00:00
|
|
|
DICompositeType CTy = MDCompositeType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
|
|
|
|
DIScope(getNonCompileUnitScope(Scope)).getRef(), UnderlyingType.getRef(),
|
|
|
|
SizeInBits, AlignInBits, 0, 0, Elements, 0, nullptr, nullptr,
|
|
|
|
UniqueIdentifier);
|
2013-11-18 23:33:32 +00:00
|
|
|
AllEnumTypes.push_back(CTy);
|
2013-08-29 23:17:54 +00:00
|
|
|
if (!UniqueIdentifier.empty())
|
2013-11-18 23:33:32 +00:00
|
|
|
retainType(CTy);
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(CTy);
|
2013-11-18 23:33:32 +00:00
|
|
|
return CTy;
|
2010-12-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 06:41:57 +00:00
|
|
|
DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
|
|
|
|
DIType Ty, DIArray Subscripts) {
|
2015-03-03 17:24:31 +00:00
|
|
|
auto *R = MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
|
|
|
|
nullptr, 0, nullptr, Ty.getRef(), Size,
|
|
|
|
AlignInBits, 0, 0, Subscripts, 0, nullptr);
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(R);
|
|
|
|
return R;
|
2010-12-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 03:13:46 +00:00
|
|
|
DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
|
|
|
|
DIType Ty, DIArray Subscripts) {
|
2015-03-03 17:24:31 +00:00
|
|
|
auto *R = MDCompositeType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty.getRef(),
|
|
|
|
Size, AlignInBits, 0, DIType::FlagVector, Subscripts, 0, nullptr);
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(R);
|
|
|
|
return R;
|
2010-12-08 01:50:15 +00:00
|
|
|
}
|
2010-12-07 23:25:47 +00:00
|
|
|
|
2014-10-03 20:01:09 +00:00
|
|
|
static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty,
|
|
|
|
unsigned FlagsToSet) {
|
2015-03-03 17:24:31 +00:00
|
|
|
TempMDType NewTy = cast<MDType>(static_cast<MDNode *>(Ty))->clone();
|
|
|
|
NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
|
|
|
|
return MDNode::replaceWithUniqued(std::move(NewTy));
|
2014-10-03 20:01:09 +00:00
|
|
|
}
|
2014-10-02 22:15:31 +00:00
|
|
|
|
2014-10-03 20:01:09 +00:00
|
|
|
DIType DIBuilder::createArtificialType(DIType Ty) {
|
2015-03-03 17:24:31 +00:00
|
|
|
// FIXME: Restrict this to the nodes where it's valid.
|
2014-10-03 20:01:09 +00:00
|
|
|
if (Ty.isArtificial())
|
|
|
|
return Ty;
|
|
|
|
return createTypeWithFlags(VMContext, Ty, DIType::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);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-04 15:01:38 +00:00
|
|
|
}
|
2010-12-07 23:25:47 +00:00
|
|
|
|
2012-09-12 23:36:19 +00:00
|
|
|
DIType DIBuilder::createObjectPointerType(DIType Ty) {
|
2015-03-03 17:24:31 +00:00
|
|
|
// FIXME: Restrict this to the nodes where it's valid.
|
2012-09-12 23:36:19 +00:00
|
|
|
if (Ty.isObjectPointer())
|
|
|
|
return Ty;
|
2014-10-03 20:01:09 +00:00
|
|
|
unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial;
|
|
|
|
return createTypeWithFlags(VMContext, Ty, Flags);
|
2012-09-12 23:36:19 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
void DIBuilder::retainType(DIType T) { AllRetainTypes.emplace_back(T); }
|
2010-12-08 01:50:15 +00:00
|
|
|
|
2014-07-29 18:20:39 +00:00
|
|
|
DIBasicType DIBuilder::createUnspecifiedParameter() {
|
2014-07-29 22:58:13 +00:00
|
|
|
return DIBasicType();
|
2010-12-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 23:31:31 +00:00
|
|
|
DICompositeType
|
|
|
|
DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
|
|
|
|
DIFile F, unsigned Line, unsigned RuntimeLang,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits,
|
|
|
|
StringRef UniqueIdentifier) {
|
2015-03-03 17:24:31 +00:00
|
|
|
// FIXME: Define in terms of createReplaceableForwardDecl() by calling
|
|
|
|
// replaceWithUniqued().
|
|
|
|
DICompositeType RetTy = MDCompositeType::get(
|
|
|
|
VMContext, Tag, Name, F.getFileNode(), Line,
|
|
|
|
DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
|
|
|
|
AlignInBits, 0, DIDescriptor::FlagFwdDecl, nullptr, RuntimeLang, nullptr,
|
|
|
|
nullptr, UniqueIdentifier);
|
2014-05-06 03:41:57 +00:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(RetTy);
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(RetTy);
|
2014-05-06 03:41:57 +00:00
|
|
|
return RetTy;
|
|
|
|
}
|
|
|
|
|
2015-02-11 17:45:05 +00:00
|
|
|
DICompositeType DIBuilder::createReplaceableCompositeType(
|
2014-05-06 03:41:57 +00:00
|
|
|
unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line,
|
|
|
|
unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
|
2015-02-11 17:45:05 +00:00
|
|
|
unsigned Flags, StringRef UniqueIdentifier) {
|
2015-03-03 17:24:31 +00:00
|
|
|
DICompositeType RetTy =
|
|
|
|
MDCompositeType::getTemporary(
|
|
|
|
VMContext, Tag, Name, F.getFileNode(), Line,
|
|
|
|
DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
|
|
|
|
AlignInBits, 0, Flags, nullptr, RuntimeLang,
|
|
|
|
nullptr, nullptr, UniqueIdentifier).release();
|
2013-08-29 23:17:54 +00:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(RetTy);
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(RetTy);
|
2013-07-02 18:37:35 +00:00
|
|
|
return RetTy;
|
2012-02-08 00:22:26 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
DIArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) {
|
2011-04-24 10:11:03 +00:00
|
|
|
return DIArray(MDNode::get(VMContext, Elements));
|
2010-12-07 23:25:47 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
|
|
|
|
SmallVector<llvm::Metadata *, 16> Elts;
|
2014-07-28 19:33:20 +00:00
|
|
|
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
|
|
|
|
if (Elements[i] && isa<MDNode>(Elements[i]))
|
|
|
|
Elts.push_back(DIType(cast<MDNode>(Elements[i])).getRef());
|
|
|
|
else
|
|
|
|
Elts.push_back(Elements[i]);
|
|
|
|
}
|
|
|
|
return DITypeArray(MDNode::get(VMContext, Elts));
|
|
|
|
}
|
|
|
|
|
2012-12-04 21:34:03 +00:00
|
|
|
DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDSubrange::get(VMContext, Count, Lo);
|
2010-12-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 17:24:31 +00:00
|
|
|
static void checkGlobalVariableScope(DIDescriptor Context) {
|
2014-11-21 19:47:48 +00:00
|
|
|
MDNode *TheCtx = getNonCompileUnitScope(Context);
|
|
|
|
if (DIScope(TheCtx).isCompositeType()) {
|
|
|
|
assert(!DICompositeType(TheCtx).getIdentifier() &&
|
|
|
|
"Context of a global variable should not be a type with identifier");
|
|
|
|
}
|
2014-09-17 09:28:34 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 00:23:49 +00:00
|
|
|
DIGlobalVariable DIBuilder::createGlobalVariable(
|
|
|
|
DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F,
|
|
|
|
unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val,
|
|
|
|
MDNode *Decl) {
|
2015-03-03 17:24:31 +00:00
|
|
|
checkGlobalVariableScope(Context);
|
|
|
|
|
|
|
|
auto *N = MDGlobalVariable::get(VMContext, Context, Name, LinkageName, F,
|
|
|
|
LineNumber, Ty, isLocalToUnit, true,
|
|
|
|
getConstantOrNull(Val), Decl);
|
|
|
|
AllGVs.push_back(N);
|
|
|
|
return N;
|
2014-09-17 09:28:34 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 00:23:49 +00:00
|
|
|
DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl(
|
|
|
|
DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F,
|
|
|
|
unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val,
|
|
|
|
MDNode *Decl) {
|
2015-03-03 17:24:31 +00:00
|
|
|
checkGlobalVariableScope(Context);
|
|
|
|
|
|
|
|
return MDGlobalVariable::getTemporary(VMContext, Context, Name, LinkageName,
|
|
|
|
F, LineNumber, Ty, isLocalToUnit, false,
|
|
|
|
getConstantOrNull(Val), Decl).release();
|
2010-12-07 23:25:47 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 18:56:12 +00:00
|
|
|
DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
|
2010-12-07 23:58:00 +00:00
|
|
|
StringRef Name, DIFile File,
|
2014-03-18 02:34:58 +00:00
|
|
|
unsigned LineNo, DITypeRef Ty,
|
2011-03-01 22:58:13 +00:00
|
|
|
bool AlwaysPreserve, unsigned Flags,
|
|
|
|
unsigned ArgNo) {
|
2015-03-03 17:24:31 +00:00
|
|
|
// FIXME: Why getNonCompileUnitScope()?
|
|
|
|
// FIXME: Why is "!Context" okay here?
|
|
|
|
// FIXME: WHy doesn't this check for a subprogram or lexical block (AFAICT
|
|
|
|
// the only valid scopes)?
|
2013-03-11 23:21:19 +00:00
|
|
|
DIDescriptor Context(getNonCompileUnitScope(Scope));
|
2013-07-01 21:02:01 +00:00
|
|
|
assert((!Context || Context.isScope()) &&
|
2013-03-11 23:21:19 +00:00
|
|
|
"createLocalVariable should be called with a valid Context");
|
2015-03-03 17:24:31 +00:00
|
|
|
|
|
|
|
auto *Node =
|
|
|
|
MDLocalVariable::get(VMContext, Tag, getNonCompileUnitScope(Scope), Name,
|
|
|
|
File, LineNo, Ty, ArgNo, Flags);
|
2010-12-07 23:58:00 +00:00
|
|
|
if (AlwaysPreserve) {
|
|
|
|
// The optimizer may remove local variable. If there is an interest
|
|
|
|
// to preserve variable info in such situation then stash it in a
|
|
|
|
// named mdnode.
|
|
|
|
DISubprogram Fn(getDISubprogram(Scope));
|
2014-10-15 16:11:41 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
PreservedVariables[Fn].emplace_back(Node);
|
2010-12-07 23:58:00 +00:00
|
|
|
}
|
2015-03-03 17:24:31 +00:00
|
|
|
return Node;
|
2010-12-07 23:58:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 22:13:27 +00:00
|
|
|
DIExpression DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDExpression::get(VMContext, Addr);
|
2010-12-07 23:25:47 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 22:13:27 +00:00
|
|
|
DIExpression DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
|
|
|
|
// TODO: Remove the callers of this signed version and delete.
|
|
|
|
SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
|
|
|
|
return createExpression(Addr);
|
|
|
|
}
|
|
|
|
|
2015-03-03 17:24:31 +00:00
|
|
|
DIExpression DIBuilder::createBitPieceExpression(unsigned OffsetInBytes,
|
|
|
|
unsigned SizeInBytes) {
|
|
|
|
uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes};
|
|
|
|
return MDExpression::get(VMContext, Addr);
|
2014-10-01 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 23:31:31 +00:00
|
|
|
DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
|
|
|
|
StringRef LinkageName, DIFile File,
|
|
|
|
unsigned LineNo, DICompositeType Ty,
|
2013-10-10 18:40:01 +00:00
|
|
|
bool isLocalToUnit, bool isDefinition,
|
2013-10-15 23:31:31 +00:00
|
|
|
unsigned ScopeLine, unsigned Flags,
|
|
|
|
bool isOptimized, Function *Fn,
|
|
|
|
MDNode *TParams, MDNode *Decl) {
|
2013-10-10 18:40:01 +00:00
|
|
|
// dragonegg does not generate identifier for types, so using an empty map
|
|
|
|
// to resolve the context should be fine.
|
|
|
|
DITypeIdentifierMap EmptyMap;
|
|
|
|
return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
|
|
|
|
LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
|
|
|
|
Flags, isOptimized, Fn, TParams, Decl);
|
|
|
|
}
|
|
|
|
|
2014-09-17 09:28:34 +00:00
|
|
|
DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
|
|
|
|
StringRef LinkageName, DIFile File,
|
|
|
|
unsigned LineNo, DICompositeType Ty,
|
|
|
|
bool isLocalToUnit, bool isDefinition,
|
|
|
|
unsigned ScopeLine, unsigned Flags,
|
|
|
|
bool isOptimized, Function *Fn,
|
|
|
|
MDNode *TParams, MDNode *Decl) {
|
2015-03-03 17:24:31 +00:00
|
|
|
assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
|
|
|
|
"function types should be subroutines");
|
|
|
|
auto *Node = MDSubprogram::get(
|
|
|
|
VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name,
|
|
|
|
LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit, isDefinition,
|
|
|
|
ScopeLine, nullptr, 0, 0, Flags, isOptimized, getConstantOrNull(Fn),
|
|
|
|
TParams, Decl, MDNode::getTemporary(VMContext, None).release());
|
|
|
|
|
|
|
|
if (isDefinition)
|
|
|
|
AllSubprograms.push_back(Node);
|
|
|
|
trackIfUnresolved(Node);
|
|
|
|
return Node;
|
2014-09-17 09:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DISubprogram
|
|
|
|
DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,
|
|
|
|
StringRef LinkageName, DIFile File,
|
|
|
|
unsigned LineNo, DICompositeType Ty,
|
|
|
|
bool isLocalToUnit, bool isDefinition,
|
|
|
|
unsigned ScopeLine, unsigned Flags,
|
|
|
|
bool isOptimized, Function *Fn,
|
|
|
|
MDNode *TParams, MDNode *Decl) {
|
2015-03-03 17:24:31 +00:00
|
|
|
return MDSubprogram::getTemporary(
|
|
|
|
VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name,
|
|
|
|
LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit,
|
|
|
|
isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
|
|
|
|
getConstantOrNull(Fn), TParams, Decl, nullptr).release();
|
2014-09-17 09:28:34 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 23:31:31 +00:00
|
|
|
DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
|
|
|
|
StringRef LinkageName, DIFile F,
|
2013-05-22 23:22:18 +00:00
|
|
|
unsigned LineNo, DICompositeType Ty,
|
2013-10-15 23:31:31 +00:00
|
|
|
bool isLocalToUnit, bool isDefinition,
|
2010-12-08 20:42:44 +00:00
|
|
|
unsigned VK, unsigned VIndex,
|
2013-10-15 23:31:31 +00:00
|
|
|
DIType VTableHolder, unsigned Flags,
|
|
|
|
bool isOptimized, Function *Fn,
|
2011-04-05 22:52:06 +00:00
|
|
|
MDNode *TParam) {
|
2013-05-22 23:22:18 +00:00
|
|
|
assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
|
|
|
|
"function types should be subroutines");
|
2013-10-15 23:31:36 +00:00
|
|
|
assert(getNonCompileUnitScope(Context) &&
|
|
|
|
"Methods should have both a Context and a context that isn't "
|
|
|
|
"the compile unit.");
|
2015-03-03 17:24:31 +00:00
|
|
|
// FIXME: Do we want to use different scope/lines?
|
|
|
|
auto *Node = MDSubprogram::get(
|
|
|
|
VMContext, DIScope(Context).getRef(), Name, LinkageName, F.getFileNode(),
|
|
|
|
LineNo, Ty, isLocalToUnit, isDefinition, LineNo, VTableHolder.getRef(),
|
|
|
|
VK, VIndex, Flags, isOptimized, getConstantOrNull(Fn), TParam, nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
2013-02-18 07:10:22 +00:00
|
|
|
if (isDefinition)
|
|
|
|
AllSubprograms.push_back(Node);
|
2013-03-21 20:28:52 +00:00
|
|
|
DISubprogram S(Node);
|
2013-07-01 21:02:01 +00:00
|
|
|
assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
|
2015-02-17 19:17:39 +00:00
|
|
|
trackIfUnresolved(S);
|
2013-03-21 20:28:52 +00:00
|
|
|
return S;
|
2010-12-08 20:42:44 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 18:56:12 +00:00
|
|
|
DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
|
2010-12-07 23:25:47 +00:00
|
|
|
DIFile File, unsigned LineNo) {
|
2015-03-03 17:24:31 +00:00
|
|
|
DINameSpace R = MDNamespace::get(VMContext, getNonCompileUnitScope(Scope),
|
|
|
|
File.getFileNode(), Name, LineNo);
|
2013-03-11 23:21:19 +00:00
|
|
|
assert(R.Verify() &&
|
|
|
|
"createNameSpace should return a verifiable DINameSpace");
|
|
|
|
return R;
|
2010-12-07 23:25:47 +00:00
|
|
|
}
|
|
|
|
|
2011-10-11 22:59:11 +00:00
|
|
|
DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
|
2014-08-21 22:45:21 +00:00
|
|
|
DIFile File,
|
|
|
|
unsigned Discriminator) {
|
2015-03-03 17:24:31 +00:00
|
|
|
DILexicalBlockFile R = MDLexicalBlockFile::get(
|
|
|
|
VMContext, Scope, File.getFileNode(), Discriminator);
|
2013-03-11 23:21:19 +00:00
|
|
|
assert(
|
|
|
|
R.Verify() &&
|
|
|
|
"createLexicalBlockFile should return a verifiable DILexicalBlockFile");
|
|
|
|
return R;
|
2011-10-11 22:59:11 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 18:56:12 +00:00
|
|
|
DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
|
2014-08-21 22:45:21 +00:00
|
|
|
unsigned Line, unsigned Col) {
|
2015-03-03 17:24:31 +00:00
|
|
|
// Make these distinct, to avoid merging two lexical blocks on the same
|
|
|
|
// file/line/column.
|
|
|
|
DILexicalBlock R = MDLexicalBlock::getDistinct(
|
|
|
|
VMContext, getNonCompileUnitScope(Scope), File.getFileNode(), Line, Col);
|
2013-03-11 23:21:19 +00:00
|
|
|
assert(R.Verify() &&
|
|
|
|
"createLexicalBlock should return a verifiable DILexicalBlock");
|
|
|
|
return R;
|
2010-12-08 01:50:15 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
|
|
|
|
assert(V && "no value passed to dbg intrinsic");
|
|
|
|
return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
|
|
|
|
}
|
|
|
|
|
2011-02-22 18:56:12 +00:00
|
|
|
Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
DIExpression Expr,
|
2010-12-07 23:25:47 +00:00
|
|
|
Instruction *InsertBefore) {
|
2013-06-29 05:01:19 +00:00
|
|
|
assert(VarInfo.isVariable() &&
|
|
|
|
"empty or invalid DIVariable passed to dbg.declare");
|
2010-12-07 23:25:47 +00:00
|
|
|
if (!DeclareFn)
|
|
|
|
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
|
|
|
|
|
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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2011-07-15 08:37:34 +00:00
|
|
|
return CallInst::Create(DeclareFn, Args, "", InsertBefore);
|
2010-12-07 23:25:47 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 18:56:12 +00:00
|
|
|
Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
DIExpression Expr,
|
2010-12-07 23:25:47 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2013-06-29 05:01:19 +00:00
|
|
|
assert(VarInfo.isVariable() &&
|
|
|
|
"empty or invalid DIVariable passed to dbg.declare");
|
2010-12-07 23:25:47 +00:00
|
|
|
if (!DeclareFn)
|
|
|
|
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
|
|
|
|
|
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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2010-12-07 23:25:47 +00:00
|
|
|
|
|
|
|
// If this block already has a terminator then insert this intrinsic
|
|
|
|
// before the terminator.
|
|
|
|
if (TerminatorInst *T = InsertAtEnd->getTerminator())
|
2011-07-15 08:37:34 +00:00
|
|
|
return CallInst::Create(DeclareFn, Args, "", T);
|
2010-12-07 23:25:47 +00:00
|
|
|
else
|
2011-07-15 08:37:34 +00:00
|
|
|
return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
|
2010-12-07 23:25:47 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 18:56:12 +00:00
|
|
|
Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
|
2010-12-07 23:25:47 +00:00
|
|
|
DIVariable VarInfo,
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
DIExpression Expr,
|
2010-12-07 23:25:47 +00:00
|
|
|
Instruction *InsertBefore) {
|
|
|
|
assert(V && "no value passed to dbg.value");
|
2013-06-29 05:01:19 +00:00
|
|
|
assert(VarInfo.isVariable() &&
|
|
|
|
"empty or invalid DIVariable passed to dbg.value");
|
2010-12-07 23:25:47 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
|
|
|
|
ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2011-07-15 08:37:34 +00:00
|
|
|
return CallInst::Create(ValueFn, Args, "", InsertBefore);
|
2010-12-07 23:25:47 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 18:56:12 +00:00
|
|
|
Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
|
2010-12-07 23:25:47 +00:00
|
|
|
DIVariable VarInfo,
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
DIExpression Expr,
|
2010-12-07 23:25:47 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
assert(V && "no value passed to dbg.value");
|
2013-06-29 05:01:19 +00:00
|
|
|
assert(VarInfo.isVariable() &&
|
|
|
|
"empty or invalid DIVariable passed to dbg.value");
|
2010-12-07 23:25:47 +00: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.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
|
|
|
|
ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2011-07-15 08:37:34 +00:00
|
|
|
return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
|
2010-12-07 23:25:47 +00:00
|
|
|
}
|
2014-12-18 00:46:16 +00:00
|
|
|
|
|
|
|
void DIBuilder::replaceVTableHolder(DICompositeType &T, DICompositeType VTableHolder) {
|
|
|
|
T.setContainingType(VTableHolder);
|
|
|
|
|
|
|
|
// If this didn't create a self-reference, just return.
|
|
|
|
if (T != VTableHolder)
|
|
|
|
return;
|
|
|
|
|
2015-02-11 17:45:10 +00: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 00:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DIBuilder::replaceArrays(DICompositeType &T, DIArray Elements,
|
|
|
|
DIArray TParams) {
|
|
|
|
T.setArrays(Elements, TParams);
|
|
|
|
|
|
|
|
// If T isn't resolved, there's no problem.
|
|
|
|
if (!T->isResolved())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If "T" is resolved, it may be due to a self-reference cycle. Track the
|
|
|
|
// arrays explicitly if they're unresolved, or else the cycles will be
|
|
|
|
// orphaned.
|
|
|
|
if (Elements)
|
|
|
|
trackIfUnresolved(Elements);
|
|
|
|
if (TParams)
|
|
|
|
trackIfUnresolved(TParams);
|
|
|
|
}
|