Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
//===--- DIBuilder.cpp - Debug Information Builder ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the DIBuilder.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-06 08:22:06 +08:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2014-03-06 08:46:21 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2012-04-03 08:43:49 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::dwarf;
|
|
|
|
|
2014-10-04 04:01:09 +08:00
|
|
|
namespace {
|
|
|
|
class HeaderBuilder {
|
2015-01-20 13:02:42 +08: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-04 04:01:09 +08:00
|
|
|
SmallVector<char, 256> Chars;
|
|
|
|
|
|
|
|
public:
|
2015-01-20 13:02:42 +08: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-04 04:01:09 +08:00
|
|
|
|
|
|
|
template <class Twineable> HeaderBuilder &concat(Twineable &&X) {
|
2015-01-20 13:02:42 +08:00
|
|
|
if (IsEmpty)
|
|
|
|
IsEmpty = false;
|
|
|
|
else
|
|
|
|
Chars.push_back(0);
|
2014-10-04 04:01:09 +08: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 13:02:42 +08:00
|
|
|
return HeaderBuilder().concat("0x" + Twine::utohexstr(Tag));
|
2014-10-04 04:01:09 +08:00
|
|
|
}
|
|
|
|
};
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
2010-12-08 07:58:00 +08:00
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
|
2014-04-09 14:08:46 +08: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.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
DeclareFn(nullptr), ValueFn(nullptr),
|
|
|
|
AllowUnresolvedNodes(AllowUnresolvedNodes) {}
|
|
|
|
|
|
|
|
void DIBuilder::trackIfUnresolved(MDNode *N) {
|
2015-01-20 03:09:14 +08:00
|
|
|
if (!N)
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
return;
|
2015-01-20 03:09:14 +08:00
|
|
|
if (N->isResolved())
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes");
|
|
|
|
UnresolvedNodes.emplace_back(N);
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
}
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
|
2011-08-16 07:00:00 +08:00
|
|
|
void DIBuilder::finalize() {
|
2015-04-17 00:36:23 +08:00
|
|
|
TempEnumTypes->replaceAllUsesWith(MDTuple::get(VMContext, AllEnumTypes));
|
2011-08-17 06:09:43 +08:00
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
SmallVector<Metadata *, 16> RetainValues;
|
2013-08-30 07:17:54 +08: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.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
SmallPtrSet<Metadata *, 16> RetainSet;
|
2013-08-30 07:17:54 +08:00
|
|
|
for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
|
2014-11-19 15:49:26 +08:00
|
|
|
if (RetainSet.insert(AllRetainTypes[I]).second)
|
2013-08-30 07:17:54 +08:00
|
|
|
RetainValues.push_back(AllRetainTypes[I]);
|
2015-04-17 00:36:23 +08:00
|
|
|
TempRetainTypes->replaceAllUsesWith(MDTuple::get(VMContext, RetainValues));
|
2011-08-17 06:09:43 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDSubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
|
2015-04-08 00:50:39 +08:00
|
|
|
TempSubprograms->replaceAllUsesWith(SPs.get());
|
2015-04-17 00:36:23 +08:00
|
|
|
for (auto *SP : SPs) {
|
2015-04-14 11:40:37 +08:00
|
|
|
if (MDTuple *Temp = SP->getVariables().get()) {
|
2015-02-17 23:29:18 +08:00
|
|
|
const auto &PV = PreservedVariables.lookup(SP);
|
|
|
|
SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
|
2012-04-24 03:00:11 +08:00
|
|
|
DIArray AV = getOrCreateArray(Variables);
|
2015-04-11 02:01:58 +08:00
|
|
|
TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
|
2012-04-24 03:00:11 +08:00
|
|
|
}
|
2011-08-20 07:28:12 +08:00
|
|
|
}
|
2011-08-17 06:09:43 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
TempGVs->replaceAllUsesWith(MDTuple::get(VMContext, AllGVs));
|
2013-04-22 14:12:31 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
TempImportedModules->replaceAllUsesWith(MDTuple::get(
|
|
|
|
VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
|
|
|
|
AllImportedModules.end())));
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
|
|
|
|
// Now that all temp nodes have been replaced or deleted, resolve remaining
|
|
|
|
// cycles.
|
|
|
|
for (const auto &N : UnresolvedNodes)
|
2015-01-20 07:13:14 +08:00
|
|
|
if (N && !N->isResolved())
|
|
|
|
N->resolveCycles();
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
UnresolvedNodes.clear();
|
|
|
|
|
|
|
|
// Can't handle unresolved nodes anymore.
|
|
|
|
AllowUnresolvedNodes = false;
|
2011-08-17 06:09:43 +08:00
|
|
|
}
|
|
|
|
|
2014-10-02 05:32:15 +08:00
|
|
|
/// If N is compile unit return NULL otherwise return N.
|
2015-04-17 00:36:23 +08:00
|
|
|
static MDScope *getNonCompileUnitScope(MDScope *N) {
|
2015-03-27 08:34:10 +08:00
|
|
|
if (!N || isa<MDCompileUnit>(N))
|
2014-04-09 14:08:46 +08:00
|
|
|
return nullptr;
|
2015-03-27 08:34:10 +08:00
|
|
|
return cast<MDScope>(N);
|
2011-08-16 07:00:00 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompileUnit *DIBuilder::createCompileUnit(
|
|
|
|
unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer,
|
|
|
|
bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
|
|
|
|
DebugEmissionKind Kind, bool EmitDebugInfo) {
|
2014-02-27 09:24:56 +08:00
|
|
|
|
2015-02-07 14:35:30 +08:00
|
|
|
assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
|
2012-01-11 02:18:52 +08:00
|
|
|
(Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
|
|
|
|
"Invalid Language tag");
|
|
|
|
assert(!Filename.empty() &&
|
|
|
|
"Unable to create compile unit without filename");
|
2011-08-17 06:09:43 +08:00
|
|
|
|
2015-02-13 05:52:11 +08:00
|
|
|
// TODO: Once we make MDCompileUnit distinct, stop using temporaries here
|
|
|
|
// (just start with operands assigned to nullptr).
|
2015-04-11 02:01:58 +08:00
|
|
|
TempEnumTypes = MDTuple::getTemporary(VMContext, None);
|
|
|
|
TempRetainTypes = MDTuple::getTemporary(VMContext, None);
|
|
|
|
TempSubprograms = MDTuple::getTemporary(VMContext, None);
|
|
|
|
TempGVs = MDTuple::getTemporary(VMContext, None);
|
|
|
|
TempImportedModules = MDTuple::getTemporary(VMContext, None);
|
2013-04-22 14:12:31 +08:00
|
|
|
|
2015-02-13 05:52:11 +08:00
|
|
|
// TODO: Switch to getDistinct(). We never want to merge compile units based
|
|
|
|
// on contents.
|
2015-04-07 07:18:49 +08:00
|
|
|
MDCompileUnit *CUNode = MDCompileUnit::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, Lang, MDFile::get(VMContext, Filename, Directory), Producer,
|
2015-04-11 02:01:58 +08:00
|
|
|
isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes.get(),
|
|
|
|
TempRetainTypes.get(), TempSubprograms.get(), TempGVs.get(),
|
|
|
|
TempImportedModules.get());
|
2011-05-04 00:18:28 +08:00
|
|
|
|
|
|
|
// Create a named metadata so that it is easier to find cu in a module.
|
2014-06-25 01:02:03 +08: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 08:51:47 +08:00
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
trackIfUnresolved(CUNode);
|
2015-04-07 07:18:49 +08:00
|
|
|
return CUNode;
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
static MDImportedEntity*
|
|
|
|
createImportedModule(LLVMContext &C, dwarf::Tag Tag, MDScope* 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.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
Metadata *NS, unsigned Line, StringRef Name,
|
|
|
|
SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
|
2015-04-17 00:36:23 +08:00
|
|
|
auto *M =
|
2015-04-07 12:07:31 +08:00
|
|
|
MDImportedEntity::get(C, Tag, Context, DebugNodeRef(NS), Line, Name);
|
2015-04-14 09:46:44 +08:00
|
|
|
AllImportedModules.emplace_back(M);
|
2013-05-08 05:35:53 +08:00
|
|
|
return M;
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDImportedEntity* DIBuilder::createImportedModule(MDScope* Context,
|
|
|
|
MDNamespace* NS,
|
2014-04-06 14:29:01 +08:00
|
|
|
unsigned Line) {
|
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
|
|
|
Context, NS, Line, StringRef(), AllImportedModules);
|
2013-05-21 06:50:35 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDImportedEntity* DIBuilder::createImportedModule(MDScope* Context,
|
|
|
|
MDImportedEntity* NS,
|
2014-04-06 14:29:01 +08:00
|
|
|
unsigned Line) {
|
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
|
|
|
Context, NS, Line, StringRef(), AllImportedModules);
|
2013-05-21 06:50:35 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDImportedEntity *DIBuilder::createImportedDeclaration(MDScope *Context,
|
|
|
|
DebugNode *Decl,
|
|
|
|
unsigned Line,
|
|
|
|
StringRef Name) {
|
2014-11-07 01:46:55 +08:00
|
|
|
// Make sure to use the unique identifier based metadata reference for
|
|
|
|
// types that have one.
|
2014-04-06 14:29:01 +08:00
|
|
|
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
|
2015-04-17 00:36:23 +08:00
|
|
|
Context, DebugNodeRef::get(Decl), Line, Name,
|
|
|
|
AllImportedModules);
|
2013-04-22 14:12:31 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDFile* DIBuilder::createFile(StringRef Filename, StringRef Directory) {
|
2015-03-04 01:24:31 +08: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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
|
2011-09-13 02:26:08 +08:00
|
|
|
assert(!Name.empty() && "Unable to create enumerator without name");
|
2015-03-04 01:24:31 +08: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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDBasicType *DIBuilder::createUnspecifiedType(StringRef Name) {
|
2011-09-15 07:13:28 +08:00
|
|
|
assert(!Name.empty() && "Unable to create type without name");
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
|
2011-09-15 07:13:28 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDBasicType *DIBuilder::createNullPtrType() {
|
2013-06-28 06:50:59 +08:00
|
|
|
return createUnspecifiedType("decltype(nullptr)");
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
unsigned Encoding) {
|
2011-09-13 02:26:08 +08:00
|
|
|
assert(!Name.empty() && "Unable to create type without name");
|
2015-03-04 01:24:31 +08: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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createQualifiedType(unsigned Tag, MDType *FromTy) {
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
|
2015-04-07 03:03:45 +08:00
|
|
|
MDTypeRef::get(FromTy), 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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createPointerType(MDType *PointeeTy,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
StringRef Name) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Why is there a name here?
|
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
|
2015-04-07 03:03:45 +08:00
|
|
|
nullptr, 0, nullptr, MDTypeRef::get(PointeeTy),
|
|
|
|
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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createMemberPointerType(MDType *PointeeTy,
|
|
|
|
MDType *Base,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits) {
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
|
2015-04-07 03:03:45 +08:00
|
|
|
nullptr, 0, nullptr, MDTypeRef::get(PointeeTy),
|
|
|
|
SizeInBits, AlignInBits, 0, 0, MDTypeRef::get(Base));
|
2013-01-07 13:51:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createReferenceType(unsigned Tag, MDType *RTy) {
|
2015-04-07 07:18:49 +08:00
|
|
|
assert(RTy && "Unable to create reference type");
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
|
2015-04-07 03:03:45 +08:00
|
|
|
MDTypeRef::get(RTy), 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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createTypedef(MDType *Ty, StringRef Name,
|
|
|
|
MDFile *File, unsigned LineNo,
|
|
|
|
MDScope *Context) {
|
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
|
|
|
|
LineNo,
|
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Context)),
|
|
|
|
MDTypeRef::get(Ty), 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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createFriend(MDType *Ty, MDType *FriendTy) {
|
2015-04-07 07:18:49 +08:00
|
|
|
assert(Ty && "Invalid type!");
|
|
|
|
assert(FriendTy && "Invalid friend type!");
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0,
|
2015-04-07 03:03:45 +08:00
|
|
|
MDTypeRef::get(Ty), MDTypeRef::get(FriendTy), 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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createInheritance(MDType *Ty, MDType *BaseTy,
|
|
|
|
uint64_t BaseOffset,
|
|
|
|
unsigned Flags) {
|
2015-04-07 07:18:49 +08:00
|
|
|
assert(Ty && "Unable to create inheritance");
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
|
2015-04-07 03:03:45 +08:00
|
|
|
0, MDTypeRef::get(Ty), MDTypeRef::get(BaseTy), 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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createMemberType(MDScope *Scope, StringRef Name,
|
|
|
|
MDFile *File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits,
|
|
|
|
unsigned Flags, MDType *Ty) {
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDDerivedType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Scope)), MDTypeRef::get(Ty),
|
|
|
|
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);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-27 08:34:10 +08:00
|
|
|
static ConstantAsMetadata *getConstantOrNull(Constant *C) {
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
if (C)
|
|
|
|
return ConstantAsMetadata::get(C);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createStaticMemberType(MDScope *Scope, StringRef Name,
|
|
|
|
MDFile *File,
|
|
|
|
unsigned LineNumber,
|
|
|
|
MDType *Ty, unsigned Flags,
|
|
|
|
llvm::Constant *Val) {
|
2015-04-16 09:53:33 +08:00
|
|
|
Flags |= DebugNode::FlagStaticMember;
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDDerivedType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Scope)), MDTypeRef::get(Ty), 0, 0,
|
|
|
|
0, Flags, getConstantOrNull(Val));
|
2013-01-16 09:22:23 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDDerivedType *DIBuilder::createObjCIVar(StringRef Name, MDFile *File,
|
|
|
|
unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits, unsigned Flags,
|
|
|
|
MDType *Ty, MDNode *PropertyNode) {
|
2015-04-07 03:03:45 +08:00
|
|
|
return MDDerivedType::get(
|
|
|
|
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
|
|
|
|
MDScopeRef::get(getNonCompileUnitScope(File)), MDTypeRef::get(Ty),
|
|
|
|
SizeInBits, AlignInBits, OffsetInBits, Flags, PropertyNode);
|
2011-04-16 08:11:51 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDObjCProperty *
|
|
|
|
DIBuilder::createObjCProperty(StringRef Name, MDFile *File, unsigned LineNumber,
|
2013-10-16 07:31:31 +08:00
|
|
|
StringRef GetterName, StringRef SetterName,
|
2015-04-17 00:36:23 +08:00
|
|
|
unsigned PropertyAttributes, MDType *Ty) {
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
|
|
|
|
SetterName, PropertyAttributes, Ty);
|
2012-02-04 08:59:25 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDTemplateTypeParameter *
|
|
|
|
DIBuilder::createTemplateTypeParameter(MDScope *Context, StringRef Name,
|
|
|
|
MDType *Ty) {
|
2015-04-16 09:37:00 +08:00
|
|
|
assert((!Context || isa<MDCompileUnit>(Context)) && "Expected compile unit");
|
2015-04-07 03:03:45 +08:00
|
|
|
return MDTemplateTypeParameter::get(VMContext, Name, MDTypeRef::get(Ty));
|
2011-02-03 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
static MDTemplateValueParameter *
|
2015-02-13 11:35:29 +08:00
|
|
|
createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScope *Context, StringRef Name, MDType *Ty,
|
|
|
|
Metadata *MD) {
|
2015-04-16 09:37:00 +08:00
|
|
|
assert((!Context || isa<MDCompileUnit>(Context)) && "Expected compile unit");
|
2015-04-07 03:03:45 +08:00
|
|
|
return MDTemplateValueParameter::get(VMContext, Tag, Name, MDTypeRef::get(Ty),
|
|
|
|
MD);
|
2011-02-03 06:35:53 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDTemplateValueParameter *
|
|
|
|
DIBuilder::createTemplateValueParameter(MDScope *Context, StringRef Name,
|
|
|
|
MDType *Ty, Constant *Val) {
|
2014-11-15 08:05:04 +08:00
|
|
|
return createTemplateValueParameterHelper(
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
|
2015-02-13 11:35:29 +08:00
|
|
|
getConstantOrNull(Val));
|
2013-06-23 02:59:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDTemplateValueParameter *
|
|
|
|
DIBuilder::createTemplateTemplateParameter(MDScope *Context, StringRef Name,
|
|
|
|
MDType *Ty, StringRef Val) {
|
2014-11-15 08:05:04 +08:00
|
|
|
return createTemplateValueParameterHelper(
|
|
|
|
VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
|
2015-02-13 11:35:29 +08:00
|
|
|
MDString::get(VMContext, Val));
|
2013-06-23 02:59:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDTemplateValueParameter *
|
|
|
|
DIBuilder::createTemplateParameterPack(MDScope *Context, StringRef Name,
|
|
|
|
MDType *Ty, DIArray Val) {
|
2014-11-15 08:05:04 +08:00
|
|
|
return createTemplateValueParameterHelper(
|
|
|
|
VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
|
2015-04-08 00:50:39 +08:00
|
|
|
Val.get());
|
2013-06-23 02:59:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompositeType *DIBuilder::createClassType(
|
|
|
|
MDScope *Context, StringRef Name, MDFile *File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
|
|
|
|
unsigned Flags, MDType *DerivedFrom, DIArray Elements, MDType *VTableHolder,
|
|
|
|
MDNode *TemplateParams, StringRef UniqueIdentifier) {
|
2015-04-07 07:18:49 +08:00
|
|
|
assert((!Context || isa<MDScope>(Context)) &&
|
2013-03-12 07:21:19 +08:00
|
|
|
"createClassType should be called with a valid Context");
|
2015-04-17 00:36:23 +08:00
|
|
|
|
|
|
|
auto *R = MDCompositeType::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Context)),
|
2015-04-07 03:03:45 +08:00
|
|
|
MDTypeRef::get(DerivedFrom), SizeInBits, AlignInBits, OffsetInBits, Flags,
|
|
|
|
Elements, 0, MDTypeRef::get(VTableHolder),
|
|
|
|
cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
|
2013-08-30 07:17:54 +08:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(R);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
2013-03-12 07:21:19 +08:00
|
|
|
return R;
|
2012-07-06 10:35:57 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompositeType *DIBuilder::createStructType(
|
|
|
|
MDScope *Context, StringRef Name, MDFile *File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
|
|
|
|
MDType *DerivedFrom, DIArray Elements, unsigned RunTimeLang,
|
|
|
|
MDType *VTableHolder, StringRef UniqueIdentifier) {
|
|
|
|
auto *R = MDCompositeType::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Context)),
|
2015-04-07 03:03:45 +08:00
|
|
|
MDTypeRef::get(DerivedFrom), SizeInBits, AlignInBits, 0, Flags, Elements,
|
|
|
|
RunTimeLang, MDTypeRef::get(VTableHolder), nullptr, UniqueIdentifier);
|
2013-08-30 07:17:54 +08:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(R);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
2013-03-12 07:21:19 +08:00
|
|
|
return R;
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompositeType* DIBuilder::createUnionType(MDScope * Scope, StringRef Name,
|
|
|
|
MDFile* File, unsigned LineNumber,
|
2013-04-03 06:55:52 +08:00
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, unsigned Flags,
|
|
|
|
DIArray Elements,
|
2013-08-28 07:06:40 +08:00
|
|
|
unsigned RunTimeLang,
|
|
|
|
StringRef UniqueIdentifier) {
|
2015-04-17 00:36:23 +08:00
|
|
|
auto *R = MDCompositeType::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits,
|
|
|
|
AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr,
|
|
|
|
UniqueIdentifier);
|
2013-08-30 07:17:54 +08:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(R);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
2013-08-30 07:17:54 +08:00
|
|
|
return R;
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDSubroutineType *DIBuilder::createSubroutineType(MDFile *File,
|
|
|
|
DITypeArray ParameterTypes,
|
|
|
|
unsigned Flags) {
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDSubroutineType::get(VMContext, Flags, ParameterTypes);
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompositeType *DIBuilder::createEnumerationType(
|
|
|
|
MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNumber,
|
2013-02-18 14:41:57 +08:00
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDType *UnderlyingType, StringRef UniqueIdentifier) {
|
|
|
|
auto *CTy = MDCompositeType::get(
|
2015-03-04 01:24:31 +08:00
|
|
|
VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Scope)),
|
2015-04-07 03:03:45 +08:00
|
|
|
MDTypeRef::get(UnderlyingType), SizeInBits, AlignInBits, 0, 0, Elements,
|
|
|
|
0, nullptr, nullptr, UniqueIdentifier);
|
2013-11-19 07:33:32 +08:00
|
|
|
AllEnumTypes.push_back(CTy);
|
2013-08-30 07:17:54 +08:00
|
|
|
if (!UniqueIdentifier.empty())
|
2013-11-19 07:33:32 +08:00
|
|
|
retainType(CTy);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(CTy);
|
2013-11-19 07:33:32 +08:00
|
|
|
return CTy;
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
|
|
|
|
MDType *Ty, DIArray Subscripts) {
|
2015-03-04 01:24:31 +08:00
|
|
|
auto *R = MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
|
2015-04-07 03:03:45 +08:00
|
|
|
nullptr, 0, nullptr, MDTypeRef::get(Ty), Size,
|
2015-03-04 01:24:31 +08:00
|
|
|
AlignInBits, 0, 0, Subscripts, 0, nullptr);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
|
|
|
return R;
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompositeType *DIBuilder::createVectorType(uint64_t Size,
|
|
|
|
uint64_t AlignInBits, MDType *Ty,
|
|
|
|
DIArray Subscripts) {
|
2015-04-07 03:03:45 +08:00
|
|
|
auto *R =
|
|
|
|
MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0,
|
|
|
|
nullptr, MDTypeRef::get(Ty), Size, AlignInBits, 0,
|
2015-04-16 09:01:28 +08:00
|
|
|
DebugNode::FlagVector, Subscripts, 0, nullptr);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(R);
|
|
|
|
return R;
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
2010-12-08 07:25:47 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
static MDType *createTypeWithFlags(LLVMContext &Context, MDType *Ty,
|
|
|
|
unsigned FlagsToSet) {
|
|
|
|
auto NewTy = Ty->clone();
|
2015-03-04 01:24:31 +08:00
|
|
|
NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
|
|
|
|
return MDNode::replaceWithUniqued(std::move(NewTy));
|
2014-10-04 04:01:09 +08:00
|
|
|
}
|
2014-10-03 06:15:31 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDType *DIBuilder::createArtificialType(MDType *Ty) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Restrict this to the nodes where it's valid.
|
2015-04-16 09:01:28 +08:00
|
|
|
if (Ty->isArtificial())
|
2014-10-04 04:01:09 +08:00
|
|
|
return Ty;
|
2015-04-16 09:01:28 +08:00
|
|
|
return createTypeWithFlags(VMContext, Ty, DebugNode::FlagArtificial);
|
Introduce DIBuilder. It is intended to be a front-end friendly interface to emit debuggging information entries in LLVM IR.
To create debugging information for a pointer, using DIBUilder front-end just needs
DBuilder.CreatePointerType(Ty, Size);
instead of
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
TheCU, "", getOrCreateMainFile(),
0, Size, 0, 0, 0, OCTy);
llvm-svn: 118248
2010-11-04 23:01:38 +08:00
|
|
|
}
|
2010-12-08 07:25:47 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDType *DIBuilder::createObjectPointerType(MDType *Ty) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Restrict this to the nodes where it's valid.
|
2015-04-16 09:01:28 +08:00
|
|
|
if (Ty->isObjectPointer())
|
2012-09-13 07:36:19 +08:00
|
|
|
return Ty;
|
2015-04-16 09:01:28 +08:00
|
|
|
unsigned Flags = DebugNode::FlagObjectPointer | DebugNode::FlagArtificial;
|
2014-10-04 04:01:09 +08:00
|
|
|
return createTypeWithFlags(VMContext, Ty, Flags);
|
2012-09-13 07:36:19 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
void DIBuilder::retainType(MDType *T) {
|
2015-04-16 09:01:28 +08:00
|
|
|
assert(T && "Expected non-null type");
|
2015-03-28 07:00:49 +08:00
|
|
|
AllRetainTypes.emplace_back(T);
|
|
|
|
}
|
2010-12-08 09:50:15 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
|
2010-12-08 09:50:15 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompositeType*
|
|
|
|
DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, MDScope * Scope,
|
|
|
|
MDFile* F, unsigned Line, unsigned RuntimeLang,
|
2013-10-16 07:31:31 +08:00
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits,
|
|
|
|
StringRef UniqueIdentifier) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Define in terms of createReplaceableForwardDecl() by calling
|
|
|
|
// replaceWithUniqued().
|
2015-04-17 00:36:23 +08:00
|
|
|
auto *RetTy = MDCompositeType::get(
|
2015-04-07 03:03:45 +08:00
|
|
|
VMContext, Tag, Name, F, Line,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits,
|
|
|
|
AlignInBits, 0, DebugNode::FlagFwdDecl, nullptr, RuntimeLang, nullptr,
|
|
|
|
nullptr, UniqueIdentifier);
|
2014-05-06 11:41:57 +08:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(RetTy);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(RetTy);
|
2014-05-06 11:41:57 +08:00
|
|
|
return RetTy;
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDCompositeType* DIBuilder::createReplaceableCompositeType(
|
|
|
|
unsigned Tag, StringRef Name, MDScope * Scope, MDFile* F, unsigned Line,
|
2014-05-06 11:41:57 +08:00
|
|
|
unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
|
2015-02-12 01:45:05 +08:00
|
|
|
unsigned Flags, StringRef UniqueIdentifier) {
|
2015-04-17 00:36:23 +08:00
|
|
|
auto *RetTy = MDCompositeType::getTemporary(
|
|
|
|
VMContext, Tag, Name, F, Line,
|
|
|
|
MDScopeRef::get(getNonCompileUnitScope(Scope)), nullptr,
|
|
|
|
SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang,
|
|
|
|
nullptr, nullptr, UniqueIdentifier).release();
|
2013-08-30 07:17:54 +08:00
|
|
|
if (!UniqueIdentifier.empty())
|
|
|
|
retainType(RetTy);
|
2015-02-18 03:17:39 +08:00
|
|
|
trackIfUnresolved(RetTy);
|
2013-07-03 02:37:35 +08:00
|
|
|
return RetTy;
|
2012-02-08 08:22:26 +08:00
|
|
|
}
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
DIArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) {
|
2015-04-17 00:36:23 +08:00
|
|
|
return MDTuple::get(VMContext, Elements);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
|
|
|
|
SmallVector<llvm::Metadata *, 16> Elts;
|
2014-07-29 03:33:20 +08:00
|
|
|
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
|
|
|
|
if (Elements[i] && isa<MDNode>(Elements[i]))
|
2015-04-07 07:18:49 +08:00
|
|
|
Elts.push_back(MDTypeRef::get(cast<MDType>(Elements[i])));
|
2014-07-29 03:33:20 +08:00
|
|
|
else
|
|
|
|
Elts.push_back(Elements[i]);
|
|
|
|
}
|
|
|
|
return DITypeArray(MDNode::get(VMContext, Elts));
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDSubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDSubrange::get(VMContext, Count, Lo);
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
static void checkGlobalVariableScope(MDScope * Context) {
|
2015-04-07 07:34:41 +08:00
|
|
|
#ifndef NDEBUG
|
2015-04-16 09:01:28 +08:00
|
|
|
if (auto *CT =
|
2015-04-07 07:18:49 +08:00
|
|
|
dyn_cast_or_null<MDCompositeType>(getNonCompileUnitScope(Context)))
|
2015-04-16 09:01:28 +08:00
|
|
|
assert(CT->getIdentifier().empty() &&
|
2014-11-22 03:47:48 +08:00
|
|
|
"Context of a global variable should not be a type with identifier");
|
2015-04-07 07:34:41 +08:00
|
|
|
#endif
|
2014-09-17 17:28:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDGlobalVariable *DIBuilder::createGlobalVariable(
|
|
|
|
MDScope *Context, StringRef Name, StringRef LinkageName, MDFile *F,
|
|
|
|
unsigned LineNumber, MDType *Ty, bool isLocalToUnit, Constant *Val,
|
2014-11-15 08:23:49 +08:00
|
|
|
MDNode *Decl) {
|
2015-03-04 01:24:31 +08:00
|
|
|
checkGlobalVariableScope(Context);
|
|
|
|
|
2015-04-16 09:37:00 +08:00
|
|
|
auto *N = MDGlobalVariable::get(VMContext, cast_or_null<MDScope>(Context),
|
|
|
|
Name, LinkageName, F, LineNumber,
|
|
|
|
MDTypeRef::get(Ty), isLocalToUnit, true, Val,
|
|
|
|
cast_or_null<MDDerivedType>(Decl));
|
2015-03-04 01:24:31 +08:00
|
|
|
AllGVs.push_back(N);
|
|
|
|
return N;
|
2014-09-17 17:28:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
|
|
|
|
MDScope *Context, StringRef Name, StringRef LinkageName, MDFile *F,
|
|
|
|
unsigned LineNumber, MDType *Ty, bool isLocalToUnit, Constant *Val,
|
2014-11-15 08:23:49 +08:00
|
|
|
MDNode *Decl) {
|
2015-03-04 01:24:31 +08:00
|
|
|
checkGlobalVariableScope(Context);
|
|
|
|
|
2015-03-28 01:29:58 +08:00
|
|
|
return MDGlobalVariable::getTemporary(
|
2015-04-16 09:37:00 +08:00
|
|
|
VMContext, cast_or_null<MDScope>(Context), Name, LinkageName, F,
|
|
|
|
LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, Val,
|
|
|
|
cast_or_null<MDDerivedType>(Decl))
|
|
|
|
.release();
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDLocalVariable *DIBuilder::createLocalVariable(
|
|
|
|
unsigned Tag, MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNo,
|
|
|
|
MDType *Ty, bool AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
|
2015-03-04 01:24:31 +08: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)?
|
2015-04-17 00:36:23 +08:00
|
|
|
MDScope* Context = getNonCompileUnitScope(Scope);
|
2015-03-04 01:24:31 +08:00
|
|
|
|
2015-04-07 03:03:45 +08:00
|
|
|
auto *Node = MDLocalVariable::get(
|
2015-04-16 09:37:00 +08:00
|
|
|
VMContext, Tag, cast_or_null<MDLocalScope>(Context), Name, File, LineNo,
|
|
|
|
MDTypeRef::get(Ty), ArgNo, Flags);
|
2010-12-08 07:58:00 +08: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.
|
2015-04-17 00:36:23 +08:00
|
|
|
MDSubprogram *Fn = getDISubprogram(Scope);
|
2014-10-16 00:11:41 +08:00
|
|
|
assert(Fn && "Missing subprogram for local variable");
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
PreservedVariables[Fn].emplace_back(Node);
|
2010-12-08 07:58:00 +08:00
|
|
|
}
|
2015-03-04 01:24:31 +08:00
|
|
|
return Node;
|
2010-12-08 07:58:00 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDExpression* DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDExpression::get(VMContext, Addr);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDExpression* DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
|
2015-02-10 06:13:27 +08:00
|
|
|
// TODO: Remove the callers of this signed version and delete.
|
|
|
|
SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
|
|
|
|
return createExpression(Addr);
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDExpression* DIBuilder::createBitPieceExpression(unsigned OffsetInBytes,
|
2015-03-04 01:24:31 +08:00
|
|
|
unsigned SizeInBytes) {
|
|
|
|
uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes};
|
|
|
|
return MDExpression::get(VMContext, Addr);
|
2014-10-02 05:32:12 +08:00
|
|
|
}
|
|
|
|
|
2015-04-21 02:20:03 +08:00
|
|
|
MDSubprogram *DIBuilder::createFunction(MDScopeRef Context, StringRef Name,
|
|
|
|
StringRef LinkageName, MDFile *File,
|
|
|
|
unsigned LineNo, MDSubroutineType *Ty,
|
|
|
|
bool isLocalToUnit, bool isDefinition,
|
|
|
|
unsigned ScopeLine, unsigned Flags,
|
|
|
|
bool isOptimized, Function *Fn,
|
|
|
|
MDNode *TParams, MDNode *Decl) {
|
2013-10-11 02:40:01 +08: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);
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDSubprogram* DIBuilder::createFunction(MDScope * Context, StringRef Name,
|
|
|
|
StringRef LinkageName, MDFile* File,
|
|
|
|
unsigned LineNo, MDSubroutineType* Ty,
|
2014-09-17 17:28:34 +08:00
|
|
|
bool isLocalToUnit, bool isDefinition,
|
|
|
|
unsigned ScopeLine, unsigned Flags,
|
|
|
|
bool isOptimized, Function *Fn,
|
|
|
|
MDNode *TParams, MDNode *Decl) {
|
2015-04-16 09:01:28 +08:00
|
|
|
assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
|
2015-03-04 01:24:31 +08:00
|
|
|
"function types should be subroutines");
|
|
|
|
auto *Node = MDSubprogram::get(
|
2015-04-17 00:36:23 +08:00
|
|
|
VMContext, MDScopeRef::get(getNonCompileUnitScope(Context)), Name,
|
|
|
|
LinkageName, File, LineNo, Ty,
|
2015-04-16 07:19:27 +08:00
|
|
|
isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
|
|
|
|
Fn, cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
|
2015-03-31 00:19:15 +08:00
|
|
|
MDTuple::getTemporary(VMContext, None).release());
|
2015-03-04 01:24:31 +08:00
|
|
|
|
|
|
|
if (isDefinition)
|
|
|
|
AllSubprograms.push_back(Node);
|
|
|
|
trackIfUnresolved(Node);
|
|
|
|
return Node;
|
2014-09-17 17:28:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDSubprogram*
|
|
|
|
DIBuilder::createTempFunctionFwdDecl(MDScope * Context, StringRef Name,
|
|
|
|
StringRef LinkageName, MDFile* File,
|
|
|
|
unsigned LineNo, MDSubroutineType* Ty,
|
2014-09-17 17:28:34 +08:00
|
|
|
bool isLocalToUnit, bool isDefinition,
|
|
|
|
unsigned ScopeLine, unsigned Flags,
|
|
|
|
bool isOptimized, Function *Fn,
|
|
|
|
MDNode *TParams, MDNode *Decl) {
|
2015-03-04 01:24:31 +08:00
|
|
|
return MDSubprogram::getTemporary(
|
2015-04-17 00:36:23 +08:00
|
|
|
VMContext, MDScopeRef::get(getNonCompileUnitScope(Context)), Name,
|
|
|
|
LinkageName, File, LineNo, Ty,
|
2015-04-16 09:01:28 +08:00
|
|
|
isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags,
|
|
|
|
isOptimized, Fn, cast_or_null<MDTuple>(TParams),
|
2015-04-17 00:36:23 +08:00
|
|
|
cast_or_null<MDSubprogram>(Decl), nullptr).release();
|
2014-09-17 17:28:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDSubprogram *
|
|
|
|
DIBuilder::createMethod(MDScope *Context, StringRef Name, StringRef LinkageName,
|
|
|
|
MDFile *F, unsigned LineNo, MDSubroutineType *Ty,
|
|
|
|
bool isLocalToUnit, bool isDefinition, unsigned VK,
|
|
|
|
unsigned VIndex, MDType *VTableHolder, unsigned Flags,
|
|
|
|
bool isOptimized, Function *Fn, MDNode *TParam) {
|
2015-04-16 09:01:28 +08:00
|
|
|
assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
|
2013-05-23 07:22:18 +08:00
|
|
|
"function types should be subroutines");
|
2013-10-16 07:31:36 +08:00
|
|
|
assert(getNonCompileUnitScope(Context) &&
|
|
|
|
"Methods should have both a Context and a context that isn't "
|
|
|
|
"the compile unit.");
|
2015-03-04 01:24:31 +08:00
|
|
|
// FIXME: Do we want to use different scope/lines?
|
2015-04-07 07:18:49 +08:00
|
|
|
auto *SP = MDSubprogram::get(
|
2015-04-16 07:19:27 +08:00
|
|
|
VMContext, MDScopeRef::get(cast<MDScope>(Context)), Name, LinkageName, F,
|
2015-04-17 00:36:23 +08:00
|
|
|
LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
|
|
|
|
MDTypeRef::get(VTableHolder), VK, VIndex, Flags, isOptimized, Fn,
|
2015-04-16 09:01:28 +08:00
|
|
|
cast_or_null<MDTuple>(TParam), nullptr, nullptr);
|
2015-03-04 01:24:31 +08:00
|
|
|
|
2013-02-18 15:10:22 +08:00
|
|
|
if (isDefinition)
|
2015-04-07 07:18:49 +08:00
|
|
|
AllSubprograms.push_back(SP);
|
|
|
|
trackIfUnresolved(SP);
|
|
|
|
return SP;
|
2010-12-09 04:42:44 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDNamespace* DIBuilder::createNameSpace(MDScope * Scope, StringRef Name,
|
|
|
|
MDFile* File, unsigned LineNo) {
|
2015-04-07 03:49:39 +08:00
|
|
|
return MDNamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name,
|
|
|
|
LineNo);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDLexicalBlockFile* DIBuilder::createLexicalBlockFile(MDScope * Scope,
|
|
|
|
MDFile* File,
|
2014-08-22 06:45:21 +08:00
|
|
|
unsigned Discriminator) {
|
2015-04-16 07:19:27 +08:00
|
|
|
return MDLexicalBlockFile::get(VMContext, Scope, File, Discriminator);
|
2011-10-12 06:59:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
MDLexicalBlock* DIBuilder::createLexicalBlock(MDScope * Scope, MDFile* File,
|
2014-08-22 06:45:21 +08:00
|
|
|
unsigned Line, unsigned Col) {
|
2015-03-04 01:24:31 +08:00
|
|
|
// Make these distinct, to avoid merging two lexical blocks on the same
|
|
|
|
// file/line/column.
|
2015-04-07 03:49:39 +08:00
|
|
|
return MDLexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
|
2015-04-16 07:19:27 +08:00
|
|
|
File, Line, Col);
|
2010-12-08 09:50:15 +08:00
|
|
|
}
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
|
|
|
|
assert(V && "no value passed to dbg intrinsic");
|
|
|
|
return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
|
|
|
|
}
|
|
|
|
|
2015-04-16 05:18:07 +08:00
|
|
|
static Instruction *withDebugLoc(Instruction *I, const MDLocation *DL) {
|
|
|
|
I->setDebugLoc(const_cast<MDLocation *>(DL));
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
Instruction *DIBuilder::insertDeclare(Value *Storage, MDLocalVariable* VarInfo,
|
|
|
|
MDExpression* Expr, const MDLocation *DL,
|
2010-12-08 07:25:47 +08:00
|
|
|
Instruction *InsertBefore) {
|
2015-04-17 00:36:23 +08:00
|
|
|
assert(VarInfo && "empty or invalid MDLocalVariable* passed to dbg.declare");
|
2015-04-16 05:18:07 +08:00
|
|
|
assert(DL && "Expected debug loc");
|
|
|
|
assert(DL->getScope()->getSubprogram() ==
|
|
|
|
VarInfo->getScope()->getSubprogram() &&
|
|
|
|
"Expected matching subprograms");
|
2010-12-08 07:25:47 +08:00
|
|
|
if (!DeclareFn)
|
|
|
|
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.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2015-04-16 05:18:07 +08:00
|
|
|
return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
Instruction *DIBuilder::insertDeclare(Value *Storage, MDLocalVariable* VarInfo,
|
|
|
|
MDExpression* Expr, const MDLocation *DL,
|
2010-12-08 07:25:47 +08:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2015-04-17 00:36:23 +08:00
|
|
|
assert(VarInfo && "empty or invalid MDLocalVariable* passed to dbg.declare");
|
2015-04-16 05:18:07 +08:00
|
|
|
assert(DL && "Expected debug loc");
|
|
|
|
assert(DL->getScope()->getSubprogram() ==
|
|
|
|
VarInfo->getScope()->getSubprogram() &&
|
|
|
|
"Expected matching subprograms");
|
2010-12-08 07:25:47 +08:00
|
|
|
if (!DeclareFn)
|
|
|
|
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.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2010-12-08 07:25:47 +08:00
|
|
|
|
|
|
|
// If this block already has a terminator then insert this intrinsic
|
|
|
|
// before the terminator.
|
|
|
|
if (TerminatorInst *T = InsertAtEnd->getTerminator())
|
2015-04-16 05:18:07 +08:00
|
|
|
return withDebugLoc(CallInst::Create(DeclareFn, Args, "", T), DL);
|
|
|
|
return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertAtEnd), DL);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 02:56:12 +08:00
|
|
|
Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDLocalVariable* VarInfo,
|
|
|
|
MDExpression* Expr,
|
2015-04-16 05:18:07 +08:00
|
|
|
const MDLocation *DL,
|
2010-12-08 07:25:47 +08:00
|
|
|
Instruction *InsertBefore) {
|
|
|
|
assert(V && "no value passed to dbg.value");
|
2015-04-17 00:36:23 +08:00
|
|
|
assert(VarInfo && "empty or invalid MDLocalVariable* passed to dbg.value");
|
2015-04-16 05:18:07 +08:00
|
|
|
assert(DL && "Expected debug loc");
|
|
|
|
assert(DL->getScope()->getSubprogram() ==
|
|
|
|
VarInfo->getScope()->getSubprogram() &&
|
|
|
|
"Expected matching subprograms");
|
2010-12-08 07:25:47 +08:00
|
|
|
if (!ValueFn)
|
|
|
|
ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
|
|
|
|
ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2015-04-16 05:18:07 +08:00
|
|
|
return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertBefore), DL);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 02:56:12 +08:00
|
|
|
Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
|
2015-04-17 00:36:23 +08:00
|
|
|
MDLocalVariable* VarInfo,
|
|
|
|
MDExpression* Expr,
|
2015-04-16 05:18:07 +08:00
|
|
|
const MDLocation *DL,
|
2010-12-08 07:25:47 +08:00
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
assert(V && "no value passed to dbg.value");
|
2015-04-17 00:36:23 +08:00
|
|
|
assert(VarInfo && "empty or invalid MDLocalVariable* passed to dbg.value");
|
2015-04-16 05:18:07 +08:00
|
|
|
assert(DL && "Expected debug loc");
|
|
|
|
assert(DL->getScope()->getSubprogram() ==
|
|
|
|
VarInfo->getScope()->getSubprogram() &&
|
|
|
|
"Expected matching subprograms");
|
2010-12-08 07:25:47 +08:00
|
|
|
if (!ValueFn)
|
|
|
|
ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
trackIfUnresolved(VarInfo);
|
|
|
|
trackIfUnresolved(Expr);
|
|
|
|
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
|
|
|
|
ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
|
|
|
|
MetadataAsValue::get(VMContext, VarInfo),
|
|
|
|
MetadataAsValue::get(VMContext, Expr)};
|
2015-04-16 05:18:07 +08:00
|
|
|
|
|
|
|
return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL);
|
2010-12-08 07:25:47 +08:00
|
|
|
}
|
2014-12-18 08:46:16 +08:00
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
void DIBuilder::replaceVTableHolder(MDCompositeType* &T, MDCompositeType* VTableHolder) {
|
2015-04-07 12:12:02 +08:00
|
|
|
{
|
2015-04-17 00:36:23 +08:00
|
|
|
TypedTrackingMDRef<MDCompositeType> N(T);
|
2015-04-07 12:12:02 +08:00
|
|
|
N->replaceVTableHolder(MDTypeRef::get(VTableHolder));
|
|
|
|
T = N.get();
|
|
|
|
}
|
2014-12-18 08:46:16 +08:00
|
|
|
|
|
|
|
// If this didn't create a self-reference, just return.
|
|
|
|
if (T != VTableHolder)
|
|
|
|
return;
|
|
|
|
|
2015-02-12 01:45:10 +08:00
|
|
|
// Look for unresolved operands. T will drop RAUW support, orphaning any
|
|
|
|
// cycles underneath it.
|
|
|
|
if (T->isResolved())
|
|
|
|
for (const MDOperand &O : T->operands())
|
|
|
|
if (auto *N = dyn_cast_or_null<MDNode>(O))
|
|
|
|
trackIfUnresolved(N);
|
2014-12-18 08:46:16 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:23 +08:00
|
|
|
void DIBuilder::replaceArrays(MDCompositeType* &T, DIArray Elements,
|
2014-12-18 08:46:16 +08:00
|
|
|
DIArray TParams) {
|
2015-04-07 12:12:02 +08:00
|
|
|
{
|
2015-04-17 00:36:23 +08:00
|
|
|
TypedTrackingMDRef<MDCompositeType> N(T);
|
2015-04-07 12:12:02 +08:00
|
|
|
if (Elements)
|
2015-04-07 12:14:33 +08:00
|
|
|
N->replaceElements(Elements);
|
2015-04-07 12:12:02 +08:00
|
|
|
if (TParams)
|
2015-04-08 01:30:52 +08:00
|
|
|
N->replaceTemplateParams(MDTemplateParameterArray(TParams));
|
2015-04-07 12:12:02 +08:00
|
|
|
T = N.get();
|
|
|
|
}
|
2014-12-18 08:46:16 +08:00
|
|
|
|
|
|
|
// If T isn't resolved, there's no problem.
|
|
|
|
if (!T->isResolved())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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)
|
2015-04-08 00:50:39 +08:00
|
|
|
trackIfUnresolved(Elements.get());
|
2014-12-18 08:46:16 +08:00
|
|
|
if (TParams)
|
2015-04-08 00:50:39 +08:00
|
|
|
trackIfUnresolved(TParams.get());
|
2014-12-18 08:46:16 +08:00
|
|
|
}
|