2001-06-07 04:29:01 +08:00
|
|
|
//===-- Value.cpp - Implement the Value class -----------------------------===//
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-07 04:29:01 +08:00
|
|
|
//
|
2009-04-01 06:11:05 +08:00
|
|
|
// This file implements the Value, ValueHandle, and User classes.
|
2001-06-07 04:29:01 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Value.h"
|
2009-08-19 02:28:58 +08:00
|
|
|
#include "LLVMContextImpl.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2017-11-17 08:30:24 +08:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2019-11-15 07:15:48 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constant.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
2014-07-10 13:27:53 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2021-04-19 17:31:41 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
[IR] De-virtualize ~Value to save a vptr
Summary:
Implements PR889
Removing the virtual table pointer from Value saves 1% of RSS when doing
LTO of llc on Linux. The impact on time was positive, but too noisy to
conclusively say that performance improved. Here is a link to the
spreadsheet with the original data:
https://docs.google.com/spreadsheets/d/1F4FHir0qYnV0MEp2sYYp_BuvnJgWlWPhWOwZ6LbW7W4/edit?usp=sharing
This change makes it invalid to directly delete a Value, User, or
Instruction pointer. Instead, such code can be rewritten to a null check
and a call Value::deleteValue(). Value objects tend to have their
lifetimes managed through iplist, so for the most part, this isn't a big
deal. However, there are some places where LLVM deletes values, and
those places had to be migrated to deleteValue. I have also created
llvm::unique_value, which has a custom deleter, so it can be used in
place of std::unique_ptr<Value>.
I had to add the "DerivedUser" Deleter escape hatch for MemorySSA, which
derives from User outside of lib/IR. Code in IR cannot include MemorySSA
headers or call the MemoryAccess object destructors without introducing
a circular dependency, so we need some level of indirection.
Unfortunately, no class derived from User may have any virtual methods,
because adding a virtual method would break User::getHungOffOperands(),
which assumes that it can find the use list immediately prior to the
User object. I've added a static_assert to the appropriate OperandTraits
templates to help people avoid this trap.
Reviewers: chandlerc, mehdi_amini, pete, dberlin, george.burgess.iv
Reviewed By: chandlerc
Subscribers: krytarowski, eraman, george.burgess.iv, mzolotukhin, Prazek, nlewycky, hans, inglorion, pcc, tejohnson, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D31261
llvm-svn: 303362
2017-05-19 01:24:10 +08:00
|
|
|
#include "llvm/IR/DerivedUser.h"
|
2014-03-04 18:40:04 +08:00
|
|
|
#include "llvm/IR/GetElementPtrTypeIterator.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/InstrTypes.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
2015-02-10 05:08:03 +08:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/Operator.h"
|
2014-03-04 19:17:44 +08:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/ValueSymbolTable.h"
|
2019-11-15 07:15:48 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2006-11-17 16:03:48 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 02:01:40 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-04-01 06:11:05 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2015-03-24 03:32:43 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2001-06-07 04:29:01 +08:00
|
|
|
#include <algorithm>
|
2016-02-03 02:20:45 +08:00
|
|
|
|
2003-11-22 04:23:48 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2021-03-20 02:15:29 +08:00
|
|
|
static cl::opt<unsigned> UseDerefAtPointSemantics(
|
|
|
|
"use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false),
|
|
|
|
cl::desc("Deref attributes and metadata infer facts at definition only"));
|
|
|
|
|
2001-06-07 04:29:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Value Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
2011-07-18 12:54:35 +08:00
|
|
|
static inline Type *checkType(Type *Ty) {
|
2001-12-13 08:41:27 +08:00
|
|
|
assert(Ty && "Value defined with a null type: Error!");
|
2014-06-10 07:32:20 +08:00
|
|
|
return Ty;
|
2001-12-13 08:41:27 +08:00
|
|
|
}
|
|
|
|
|
2011-07-18 12:54:35 +08:00
|
|
|
Value::Value(Type *ty, unsigned scid)
|
2019-09-14 01:21:24 +08:00
|
|
|
: VTy(checkType(ty)), UseList(nullptr), SubclassID(scid), HasValueHandle(0),
|
|
|
|
SubclassOptionalData(0), SubclassData(0), NumUserOperands(0),
|
|
|
|
IsUsedByMD(false), HasName(false), HasMetadata(false) {
|
2017-11-14 05:55:01 +08:00
|
|
|
static_assert(ConstantFirstVal == 0, "!(SubclassID < ConstantFirstVal)");
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-10 01:41:24 +08:00
|
|
|
// FIXME: Why isn't this in the subclass gunk??
|
2012-12-20 12:11:02 +08:00
|
|
|
// Note, we cannot call isa<CallInst> before the CallInst has been
|
|
|
|
// constructed.
|
2021-06-11 07:18:57 +08:00
|
|
|
unsigned OpCode = 0;
|
|
|
|
if (SubclassID >= InstructionVal)
|
|
|
|
OpCode = SubclassID - InstructionVal;
|
|
|
|
if (OpCode == Instruction::Call || OpCode == Instruction::Invoke ||
|
|
|
|
OpCode == Instruction::CallBr)
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-10 01:41:24 +08:00
|
|
|
assert((VTy->isFirstClassType() || VTy->isVoidTy() || VTy->isStructTy()) &&
|
2021-06-11 07:18:57 +08:00
|
|
|
"invalid CallBase type!");
|
2012-12-20 12:11:02 +08:00
|
|
|
else if (SubclassID != BasicBlockVal &&
|
2017-11-14 05:55:01 +08:00
|
|
|
(/*SubclassID < ConstantFirstVal ||*/ SubclassID > ConstantLastVal))
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-10 01:41:24 +08:00
|
|
|
assert((VTy->isFirstClassType() || VTy->isVoidTy()) &&
|
2004-07-07 01:44:17 +08:00
|
|
|
"Cannot create non-first-class values except for constants!");
|
[IR] De-virtualize ~Value to save a vptr
Summary:
Implements PR889
Removing the virtual table pointer from Value saves 1% of RSS when doing
LTO of llc on Linux. The impact on time was positive, but too noisy to
conclusively say that performance improved. Here is a link to the
spreadsheet with the original data:
https://docs.google.com/spreadsheets/d/1F4FHir0qYnV0MEp2sYYp_BuvnJgWlWPhWOwZ6LbW7W4/edit?usp=sharing
This change makes it invalid to directly delete a Value, User, or
Instruction pointer. Instead, such code can be rewritten to a null check
and a call Value::deleteValue(). Value objects tend to have their
lifetimes managed through iplist, so for the most part, this isn't a big
deal. However, there are some places where LLVM deletes values, and
those places had to be migrated to deleteValue. I have also created
llvm::unique_value, which has a custom deleter, so it can be used in
place of std::unique_ptr<Value>.
I had to add the "DerivedUser" Deleter escape hatch for MemorySSA, which
derives from User outside of lib/IR. Code in IR cannot include MemorySSA
headers or call the MemoryAccess object destructors without introducing
a circular dependency, so we need some level of indirection.
Unfortunately, no class derived from User may have any virtual methods,
because adding a virtual method would break User::getHungOffOperands(),
which assumes that it can find the use list immediately prior to the
User object. I've added a static_assert to the appropriate OperandTraits
templates to help people avoid this trap.
Reviewers: chandlerc, mehdi_amini, pete, dberlin, george.burgess.iv
Reviewed By: chandlerc
Subscribers: krytarowski, eraman, george.burgess.iv, mzolotukhin, Prazek, nlewycky, hans, inglorion, pcc, tejohnson, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D31261
llvm-svn: 303362
2017-05-19 01:24:10 +08:00
|
|
|
static_assert(sizeof(Value) == 2 * sizeof(void *) + 2 * sizeof(unsigned),
|
2016-02-27 02:08:59 +08:00
|
|
|
"Value too big");
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2007-12-10 10:14:30 +08:00
|
|
|
Value::~Value() {
|
2009-04-01 06:11:05 +08:00
|
|
|
// Notify all ValueHandles (if present) that this value is going away.
|
|
|
|
if (HasValueHandle)
|
|
|
|
ValueHandleBase::ValueIsDeleted(this);
|
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 (isUsedByMetadata())
|
|
|
|
ValueAsMetadata::handleDeletion(this);
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2019-09-14 01:21:24 +08:00
|
|
|
// Remove associated metadata from context.
|
|
|
|
if (HasMetadata)
|
|
|
|
clearMetadata();
|
|
|
|
|
2001-06-07 04:29:01 +08:00
|
|
|
#ifndef NDEBUG // Only in -g mode...
|
2001-06-11 23:04:40 +08:00
|
|
|
// Check to make sure that there are no uses of this value that are still
|
|
|
|
// around when the value is destroyed. If there are, then we have a dangling
|
2015-03-11 07:55:38 +08:00
|
|
|
// reference and something is wrong. This code is here to print out where
|
|
|
|
// the value is still being referenced.
|
2001-06-11 23:04:40 +08:00
|
|
|
//
|
2020-02-07 07:07:20 +08:00
|
|
|
// Note that use_empty() cannot be called here, as it eventually downcasts
|
|
|
|
// 'this' to GlobalValue (derived class of Value), but GlobalValue has already
|
|
|
|
// been destructed, so accessing it is UB.
|
|
|
|
//
|
|
|
|
if (!materialized_use_empty()) {
|
2011-11-16 00:27:03 +08:00
|
|
|
dbgs() << "While deleting: " << *VTy << " %" << getName() << "\n";
|
2015-03-11 07:55:38 +08:00
|
|
|
for (auto *U : users())
|
|
|
|
dbgs() << "Use still stuck around after Def is destroyed:" << *U << "\n";
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
#endif
|
2020-02-07 07:07:20 +08:00
|
|
|
assert(materialized_use_empty() && "Uses remain when a value is destroyed!");
|
2009-08-05 07:07:12 +08:00
|
|
|
|
|
|
|
// If this value is named, destroy the name. This should not be in a symtab
|
|
|
|
// at this point.
|
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
|
|
|
destroyValueName();
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
[IR] De-virtualize ~Value to save a vptr
Summary:
Implements PR889
Removing the virtual table pointer from Value saves 1% of RSS when doing
LTO of llc on Linux. The impact on time was positive, but too noisy to
conclusively say that performance improved. Here is a link to the
spreadsheet with the original data:
https://docs.google.com/spreadsheets/d/1F4FHir0qYnV0MEp2sYYp_BuvnJgWlWPhWOwZ6LbW7W4/edit?usp=sharing
This change makes it invalid to directly delete a Value, User, or
Instruction pointer. Instead, such code can be rewritten to a null check
and a call Value::deleteValue(). Value objects tend to have their
lifetimes managed through iplist, so for the most part, this isn't a big
deal. However, there are some places where LLVM deletes values, and
those places had to be migrated to deleteValue. I have also created
llvm::unique_value, which has a custom deleter, so it can be used in
place of std::unique_ptr<Value>.
I had to add the "DerivedUser" Deleter escape hatch for MemorySSA, which
derives from User outside of lib/IR. Code in IR cannot include MemorySSA
headers or call the MemoryAccess object destructors without introducing
a circular dependency, so we need some level of indirection.
Unfortunately, no class derived from User may have any virtual methods,
because adding a virtual method would break User::getHungOffOperands(),
which assumes that it can find the use list immediately prior to the
User object. I've added a static_assert to the appropriate OperandTraits
templates to help people avoid this trap.
Reviewers: chandlerc, mehdi_amini, pete, dberlin, george.burgess.iv
Reviewed By: chandlerc
Subscribers: krytarowski, eraman, george.burgess.iv, mzolotukhin, Prazek, nlewycky, hans, inglorion, pcc, tejohnson, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D31261
llvm-svn: 303362
2017-05-19 01:24:10 +08:00
|
|
|
void Value::deleteValue() {
|
|
|
|
switch (getValueID()) {
|
|
|
|
#define HANDLE_VALUE(Name) \
|
|
|
|
case Value::Name##Val: \
|
|
|
|
delete static_cast<Name *>(this); \
|
|
|
|
break;
|
|
|
|
#define HANDLE_MEMORY_VALUE(Name) \
|
|
|
|
case Value::Name##Val: \
|
|
|
|
static_cast<DerivedUser *>(this)->DeleteValue( \
|
|
|
|
static_cast<DerivedUser *>(this)); \
|
|
|
|
break;
|
2020-06-25 06:54:21 +08:00
|
|
|
#define HANDLE_CONSTANT(Name) \
|
|
|
|
case Value::Name##Val: \
|
|
|
|
llvm_unreachable("constants should be destroyed with destroyConstant"); \
|
|
|
|
break;
|
[IR] De-virtualize ~Value to save a vptr
Summary:
Implements PR889
Removing the virtual table pointer from Value saves 1% of RSS when doing
LTO of llc on Linux. The impact on time was positive, but too noisy to
conclusively say that performance improved. Here is a link to the
spreadsheet with the original data:
https://docs.google.com/spreadsheets/d/1F4FHir0qYnV0MEp2sYYp_BuvnJgWlWPhWOwZ6LbW7W4/edit?usp=sharing
This change makes it invalid to directly delete a Value, User, or
Instruction pointer. Instead, such code can be rewritten to a null check
and a call Value::deleteValue(). Value objects tend to have their
lifetimes managed through iplist, so for the most part, this isn't a big
deal. However, there are some places where LLVM deletes values, and
those places had to be migrated to deleteValue. I have also created
llvm::unique_value, which has a custom deleter, so it can be used in
place of std::unique_ptr<Value>.
I had to add the "DerivedUser" Deleter escape hatch for MemorySSA, which
derives from User outside of lib/IR. Code in IR cannot include MemorySSA
headers or call the MemoryAccess object destructors without introducing
a circular dependency, so we need some level of indirection.
Unfortunately, no class derived from User may have any virtual methods,
because adding a virtual method would break User::getHungOffOperands(),
which assumes that it can find the use list immediately prior to the
User object. I've added a static_assert to the appropriate OperandTraits
templates to help people avoid this trap.
Reviewers: chandlerc, mehdi_amini, pete, dberlin, george.burgess.iv
Reviewed By: chandlerc
Subscribers: krytarowski, eraman, george.burgess.iv, mzolotukhin, Prazek, nlewycky, hans, inglorion, pcc, tejohnson, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D31261
llvm-svn: 303362
2017-05-19 01:24:10 +08:00
|
|
|
#define HANDLE_INSTRUCTION(Name) /* nothing */
|
|
|
|
#include "llvm/IR/Value.def"
|
|
|
|
|
|
|
|
#define HANDLE_INST(N, OPC, CLASS) \
|
|
|
|
case Value::InstructionVal + Instruction::OPC: \
|
|
|
|
delete static_cast<CLASS *>(this); \
|
|
|
|
break;
|
|
|
|
#define HANDLE_USER_INST(N, OPC, CLASS)
|
|
|
|
#include "llvm/IR/Instruction.def"
|
|
|
|
|
|
|
|
default:
|
|
|
|
llvm_unreachable("attempting to delete unknown value kind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void Value::destroyValueName() {
|
|
|
|
ValueName *Name = getValueName();
|
2020-04-13 01:44:03 +08:00
|
|
|
if (Name) {
|
|
|
|
MallocAllocator Allocator;
|
|
|
|
Name->Destroy(Allocator);
|
|
|
|
}
|
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
|
|
|
setValueName(nullptr);
|
|
|
|
}
|
|
|
|
|
2005-02-01 09:24:21 +08:00
|
|
|
bool Value::hasNUses(unsigned N) const {
|
2018-11-20 03:54:27 +08:00
|
|
|
return hasNItems(use_begin(), use_end(), N);
|
2005-02-01 09:24:21 +08:00
|
|
|
}
|
|
|
|
|
2005-02-24 00:51:11 +08:00
|
|
|
bool Value::hasNUsesOrMore(unsigned N) const {
|
2018-11-20 03:54:27 +08:00
|
|
|
return hasNItemsOrMore(use_begin(), use_end(), N);
|
2005-02-24 00:51:11 +08:00
|
|
|
}
|
|
|
|
|
2020-08-26 22:06:03 +08:00
|
|
|
bool Value::hasOneUser() const {
|
|
|
|
if (use_empty())
|
|
|
|
return false;
|
|
|
|
if (hasOneUse())
|
|
|
|
return true;
|
|
|
|
return std::equal(++user_begin(), user_end(), user_begin());
|
|
|
|
}
|
|
|
|
|
2020-03-12 07:39:05 +08:00
|
|
|
static bool isUnDroppableUser(const User *U) { return !U->isDroppable(); }
|
|
|
|
|
2021-09-16 05:06:18 +08:00
|
|
|
Use *Value::getSingleUndroppableUse() {
|
|
|
|
Use *Result = nullptr;
|
|
|
|
for (Use &U : uses()) {
|
|
|
|
if (!U.getUser()->isDroppable()) {
|
|
|
|
if (Result)
|
|
|
|
return nullptr;
|
|
|
|
Result = &U;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2021-09-21 04:37:38 +08:00
|
|
|
User *Value::getUniqueUndroppableUser() {
|
|
|
|
User *Result = nullptr;
|
|
|
|
for (auto *U : users()) {
|
|
|
|
if (!U->isDroppable()) {
|
|
|
|
if (Result && Result != U)
|
|
|
|
return nullptr;
|
|
|
|
Result = U;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-03-12 07:39:05 +08:00
|
|
|
bool Value::hasNUndroppableUses(unsigned int N) const {
|
|
|
|
return hasNItems(user_begin(), user_end(), N, isUnDroppableUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::hasNUndroppableUsesOrMore(unsigned int N) const {
|
|
|
|
return hasNItemsOrMore(user_begin(), user_end(), N, isUnDroppableUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Value::dropDroppableUses(
|
|
|
|
llvm::function_ref<bool(const Use *)> ShouldDrop) {
|
|
|
|
SmallVector<Use *, 8> ToBeEdited;
|
|
|
|
for (Use &U : uses())
|
|
|
|
if (U.getUser()->isDroppable() && ShouldDrop(&U))
|
|
|
|
ToBeEdited.push_back(&U);
|
2020-07-28 22:48:47 +08:00
|
|
|
for (Use *U : ToBeEdited)
|
|
|
|
dropDroppableUse(*U);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Value::dropDroppableUsesIn(User &Usr) {
|
|
|
|
assert(Usr.isDroppable() && "Expected a droppable user!");
|
|
|
|
for (Use &UsrOp : Usr.operands()) {
|
|
|
|
if (UsrOp.get() == this)
|
|
|
|
dropDroppableUse(UsrOp);
|
2020-03-12 07:39:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 22:48:47 +08:00
|
|
|
void Value::dropDroppableUse(Use &U) {
|
|
|
|
U.removeFromList();
|
2021-04-07 04:17:35 +08:00
|
|
|
if (auto *Assume = dyn_cast<AssumeInst>(U.getUser())) {
|
2020-07-28 22:48:47 +08:00
|
|
|
unsigned OpNo = U.getOperandNo();
|
|
|
|
if (OpNo == 0)
|
|
|
|
U.set(ConstantInt::getTrue(Assume->getContext()));
|
|
|
|
else {
|
|
|
|
U.set(UndefValue::get(U.get()->getType()));
|
|
|
|
CallInst::BundleOpInfo &BOI = Assume->getBundleOpInfoForOperand(OpNo);
|
2020-08-29 03:46:16 +08:00
|
|
|
BOI.Tag = Assume->getContext().pImpl->getOrInsertBundleTag("ignore");
|
2020-07-28 22:48:47 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("unkown droppable use");
|
2020-07-25 02:11:19 +08:00
|
|
|
}
|
|
|
|
|
2008-09-26 06:42:01 +08:00
|
|
|
bool Value::isUsedInBasicBlock(const BasicBlock *BB) const {
|
2013-05-15 07:45:56 +08:00
|
|
|
// This can be computed either by scanning the instructions in BB, or by
|
|
|
|
// scanning the use list of this Value. Both lists can be very long, but
|
|
|
|
// usually one is quite short.
|
|
|
|
//
|
|
|
|
// Scan both lists simultaneously until one is exhausted. This limits the
|
|
|
|
// search to the shorter list.
|
|
|
|
BasicBlock::const_iterator BI = BB->begin(), BE = BB->end();
|
2014-03-09 11:16:01 +08:00
|
|
|
const_user_iterator UI = user_begin(), UE = user_end();
|
2013-05-15 07:45:56 +08:00
|
|
|
for (; BI != BE && UI != UE; ++BI, ++UI) {
|
|
|
|
// Scan basic block: Check if this Value is used by the instruction at BI.
|
2016-08-12 11:55:06 +08:00
|
|
|
if (is_contained(BI->operands(), this))
|
2011-12-06 01:23:27 +08:00
|
|
|
return true;
|
2013-05-15 07:45:56 +08:00
|
|
|
// Scan use list: Check if the use at UI is in BB.
|
2016-08-12 11:55:06 +08:00
|
|
|
const auto *User = dyn_cast<Instruction>(*UI);
|
2008-06-13 05:15:59 +08:00
|
|
|
if (User && User->getParent() == BB)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-17 07:20:42 +08:00
|
|
|
unsigned Value::getNumUses() const {
|
|
|
|
return (unsigned)std::distance(use_begin(), use_end());
|
|
|
|
}
|
2005-02-01 09:24:21 +08:00
|
|
|
|
2007-02-11 08:37:27 +08:00
|
|
|
static bool getSymTab(Value *V, ValueSymbolTable *&ST) {
|
2014-04-09 14:08:46 +08:00
|
|
|
ST = nullptr;
|
2007-02-11 08:37:27 +08:00
|
|
|
if (Instruction *I = dyn_cast<Instruction>(V)) {
|
2005-03-06 03:51:50 +08:00
|
|
|
if (BasicBlock *P = I->getParent())
|
|
|
|
if (Function *PP = P->getParent())
|
2016-09-17 14:00:02 +08:00
|
|
|
ST = PP->getValueSymbolTable();
|
2007-02-11 08:37:27 +08:00
|
|
|
} else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
|
2009-09-20 12:03:34 +08:00
|
|
|
if (Function *P = BB->getParent())
|
2016-09-17 14:00:02 +08:00
|
|
|
ST = P->getValueSymbolTable();
|
2007-02-11 08:37:27 +08:00
|
|
|
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
|
2009-09-20 12:03:34 +08:00
|
|
|
if (Module *P = GV->getParent())
|
2007-02-06 04:47:22 +08:00
|
|
|
ST = &P->getValueSymbolTable();
|
2007-02-11 08:37:27 +08:00
|
|
|
} else if (Argument *A = dyn_cast<Argument>(V)) {
|
2009-09-20 12:03:34 +08:00
|
|
|
if (Function *P = A->getParent())
|
2016-09-17 14:00:02 +08:00
|
|
|
ST = P->getValueSymbolTable();
|
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
|
|
|
} else {
|
2007-02-11 08:37:27 +08:00
|
|
|
assert(isa<Constant>(V) && "Unknown value type!");
|
|
|
|
return true; // no name is setable for this.
|
2005-03-06 03:51:50 +08:00
|
|
|
}
|
2007-02-11 08:37:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-02 06:24:01 +08:00
|
|
|
ValueName *Value::getValueName() const {
|
|
|
|
if (!HasName) return nullptr;
|
|
|
|
|
|
|
|
LLVMContext &Ctx = getContext();
|
|
|
|
auto I = Ctx.pImpl->ValueNames.find(this);
|
|
|
|
assert(I != Ctx.pImpl->ValueNames.end() &&
|
|
|
|
"No name entry found!");
|
|
|
|
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Value::setValueName(ValueName *VN) {
|
|
|
|
LLVMContext &Ctx = getContext();
|
|
|
|
|
|
|
|
assert(HasName == Ctx.pImpl->ValueNames.count(this) &&
|
|
|
|
"HasName bit out of sync!");
|
|
|
|
|
|
|
|
if (!VN) {
|
|
|
|
if (HasName)
|
|
|
|
Ctx.pImpl->ValueNames.erase(this);
|
|
|
|
HasName = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HasName = true;
|
|
|
|
Ctx.pImpl->ValueNames[this] = VN;
|
|
|
|
}
|
|
|
|
|
2009-07-26 08:51:56 +08:00
|
|
|
StringRef Value::getName() const {
|
2009-07-26 17:22:02 +08:00
|
|
|
// Make sure the empty string is still a C string. For historical reasons,
|
|
|
|
// some clients want to call .data() on the result and expect it to be null
|
|
|
|
// terminated.
|
2015-06-02 06:24:01 +08:00
|
|
|
if (!hasName())
|
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 StringRef("", 0);
|
|
|
|
return getValueName()->getKey();
|
2007-08-10 23:34:35 +08:00
|
|
|
}
|
|
|
|
|
2015-05-19 08:24:26 +08:00
|
|
|
void Value::setNameImpl(const Twine &NewName) {
|
Add a flag to the LLVMContext to disable name for Value other than GlobalValue
Summary:
This is intended to be a performance flag, on the same level as clang
cc1 option "--disable-free". LLVM will never initialize it by default,
it will be up to the client creating the LLVMContext to request this
behavior. Clang will do it by default in Release build (just like
--disable-free).
"opt" and "llc" can opt-in using -disable-named-value command line
option.
When performing LTO on llvm-tblgen, the initial merging of IR peaks
at 92MB without this patch, and 86MB after this patch,setNameImpl()
drops from 6.5MB to 0.5MB.
The total link time goes from ~29.5s to ~27.8s.
Compared to a compile-time flag (like the IRBuilder one), it performs
very close. I profiled on SROA and obtain these results:
420ms with IRBuilder that preserve name
372ms with IRBuilder that strip name
375ms with IRBuilder that preserve name, and a runtime flag to strip
Reviewers: chandlerc, dexonsmith, bogner
Subscribers: joker.eph, llvm-commits
Differential Revision: http://reviews.llvm.org/D17946
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 263086
2016-03-10 09:28:54 +08:00
|
|
|
// Fast-path: LLVMContext can be set to strip out non-GlobalValue names
|
2016-04-02 11:46:17 +08:00
|
|
|
if (getContext().shouldDiscardValueNames() && !isa<GlobalValue>(this))
|
Add a flag to the LLVMContext to disable name for Value other than GlobalValue
Summary:
This is intended to be a performance flag, on the same level as clang
cc1 option "--disable-free". LLVM will never initialize it by default,
it will be up to the client creating the LLVMContext to request this
behavior. Clang will do it by default in Release build (just like
--disable-free).
"opt" and "llc" can opt-in using -disable-named-value command line
option.
When performing LTO on llvm-tblgen, the initial merging of IR peaks
at 92MB without this patch, and 86MB after this patch,setNameImpl()
drops from 6.5MB to 0.5MB.
The total link time goes from ~29.5s to ~27.8s.
Compared to a compile-time flag (like the IRBuilder one), it performs
very close. I profiled on SROA and obtain these results:
420ms with IRBuilder that preserve name
372ms with IRBuilder that strip name
375ms with IRBuilder that preserve name, and a runtime flag to strip
Reviewers: chandlerc, dexonsmith, bogner
Subscribers: joker.eph, llvm-commits
Differential Revision: http://reviews.llvm.org/D17946
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 263086
2016-03-10 09:28:54 +08:00
|
|
|
return;
|
|
|
|
|
2009-08-20 07:37:23 +08:00
|
|
|
// Fast path for common IRBuilder case of setName("") when there is no name.
|
|
|
|
if (NewName.isTriviallyEmpty() && !hasName())
|
|
|
|
return;
|
|
|
|
|
2009-08-19 13:08:06 +08:00
|
|
|
SmallString<256> NameData;
|
2010-01-13 20:45:23 +08:00
|
|
|
StringRef NameRef = NewName.toStringRef(NameData);
|
2013-11-20 05:12:39 +08:00
|
|
|
assert(NameRef.find_first_of(0) == StringRef::npos &&
|
|
|
|
"Null bytes are not allowed in names");
|
2007-02-13 02:52:59 +08:00
|
|
|
|
2009-07-26 08:42:33 +08:00
|
|
|
// Name isn't changing?
|
2010-01-13 20:45:23 +08:00
|
|
|
if (getName() == NameRef)
|
2009-07-26 08:42:33 +08:00
|
|
|
return;
|
|
|
|
|
2010-01-05 21:12:22 +08:00
|
|
|
assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-11 08:37:27 +08:00
|
|
|
// Get the symbol table to update for this object.
|
|
|
|
ValueSymbolTable *ST;
|
|
|
|
if (getSymTab(this, ST))
|
|
|
|
return; // Cannot set a name on this value (e.g. constant).
|
2005-03-06 03:51:50 +08:00
|
|
|
|
2007-02-12 13:18:08 +08:00
|
|
|
if (!ST) { // No symbol table to update? Just do the change.
|
2010-01-13 20:45:23 +08:00
|
|
|
if (NameRef.empty()) {
|
2007-02-12 13:18:08 +08:00
|
|
|
// Free the name for this 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
|
|
|
destroyValueName();
|
2007-02-13 02:52:59 +08:00
|
|
|
return;
|
2005-03-06 10:14:28 +08:00
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-13 02:52:59 +08:00
|
|
|
// NOTE: Could optimize for the case the name is shrinking to not deallocate
|
|
|
|
// then reallocated.
|
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
|
|
|
destroyValueName();
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-13 02:52:59 +08:00
|
|
|
// Create the new name.
|
2020-04-13 01:44:03 +08:00
|
|
|
MallocAllocator Allocator;
|
|
|
|
setValueName(ValueName::Create(NameRef, Allocator));
|
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
|
|
|
getValueName()->setValue(this);
|
2007-02-12 13:18:08 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-12 13:18:08 +08:00
|
|
|
// NOTE: Could optimize for the case the name is shrinking to not deallocate
|
|
|
|
// then reallocated.
|
|
|
|
if (hasName()) {
|
|
|
|
// Remove old name.
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
ST->removeValueName(getValueName());
|
|
|
|
destroyValueName();
|
2007-02-12 13:18:08 +08:00
|
|
|
|
2010-01-13 20:45:23 +08:00
|
|
|
if (NameRef.empty())
|
2007-02-13 02:52:59 +08:00
|
|
|
return;
|
2005-03-06 10:14:28 +08:00
|
|
|
}
|
2007-02-12 13:18:08 +08:00
|
|
|
|
|
|
|
// Name is changing to something new.
|
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
|
|
|
setValueName(ST->createValueName(NameRef, this));
|
2005-03-06 03:51:50 +08:00
|
|
|
}
|
|
|
|
|
2015-05-19 08:24:26 +08:00
|
|
|
void Value::setName(const Twine &NewName) {
|
|
|
|
setNameImpl(NewName);
|
|
|
|
if (Function *F = dyn_cast<Function>(this))
|
|
|
|
F->recalculateIntrinsicID();
|
|
|
|
}
|
|
|
|
|
2007-02-11 08:37:27 +08:00
|
|
|
void Value::takeName(Value *V) {
|
2014-04-09 14:08:46 +08:00
|
|
|
ValueSymbolTable *ST = nullptr;
|
2007-02-16 04:01:43 +08:00
|
|
|
// If this value has a name, drop it.
|
|
|
|
if (hasName()) {
|
|
|
|
// Get the symtab this is in.
|
|
|
|
if (getSymTab(this, ST)) {
|
|
|
|
// We can't set a name on this value, but we need to clear V's name if
|
|
|
|
// it has one.
|
2009-07-26 08:34:27 +08:00
|
|
|
if (V->hasName()) V->setName("");
|
2007-02-16 04:01:43 +08:00
|
|
|
return; // Cannot set a name on this value (e.g. constant).
|
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
// Remove old name.
|
|
|
|
if (ST)
|
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
|
|
|
ST->removeValueName(getValueName());
|
|
|
|
destroyValueName();
|
2009-09-20 12:03:34 +08:00
|
|
|
}
|
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
// Now we know that this has no name.
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
// If V has no name either, we're done.
|
|
|
|
if (!V->hasName()) return;
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
// Get this's symtab if we didn't before.
|
|
|
|
if (!ST) {
|
|
|
|
if (getSymTab(this, ST)) {
|
|
|
|
// Clear V's name.
|
2009-07-26 08:34:27 +08:00
|
|
|
V->setName("");
|
2007-02-16 04:01:43 +08:00
|
|
|
return; // Cannot set a name on this value (e.g. constant).
|
|
|
|
}
|
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
// Get V's ST, this should always succed, because V has a name.
|
|
|
|
ValueSymbolTable *VST;
|
|
|
|
bool Failure = getSymTab(V, VST);
|
2010-12-23 08:58:24 +08:00
|
|
|
assert(!Failure && "V has a name, so it should have a ST!"); (void)Failure;
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
// If these values are both in the same symtab, we can do this very fast.
|
|
|
|
// This works even if both values have no symtab yet.
|
|
|
|
if (ST == VST) {
|
|
|
|
// Take the name!
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
setValueName(V->getValueName());
|
|
|
|
V->setValueName(nullptr);
|
|
|
|
getValueName()->setValue(this);
|
2007-02-11 09:04:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
// Otherwise, things are slightly more complex. Remove V's name from VST and
|
|
|
|
// then reinsert it into ST.
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
if (VST)
|
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
|
|
|
VST->removeValueName(V->getValueName());
|
|
|
|
setValueName(V->getValueName());
|
|
|
|
V->setValueName(nullptr);
|
|
|
|
getValueName()->setValue(this);
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2007-02-16 04:01:43 +08:00
|
|
|
if (ST)
|
|
|
|
ST->reinsertValue(this);
|
2007-02-11 08:37:27 +08:00
|
|
|
}
|
|
|
|
|
2021-01-12 08:31:40 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
std::string Value::getNameOrAsOperand() const {
|
|
|
|
if (!getName().empty())
|
|
|
|
return std::string(getName());
|
|
|
|
|
|
|
|
std::string BBName;
|
|
|
|
raw_string_ostream OS(BBName);
|
|
|
|
printAsOperand(OS, false);
|
|
|
|
return OS.str();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-13 14:26:18 +08:00
|
|
|
void Value::assertModuleIsMaterializedImpl() const {
|
2016-02-04 05:13:23 +08:00
|
|
|
#ifndef NDEBUG
|
2016-01-16 03:00:20 +08:00
|
|
|
const GlobalValue *GV = dyn_cast<GlobalValue>(this);
|
|
|
|
if (!GV)
|
|
|
|
return;
|
|
|
|
const Module *M = GV->getParent();
|
|
|
|
if (!M)
|
|
|
|
return;
|
|
|
|
assert(M->isMaterialized());
|
2016-02-04 05:13:23 +08:00
|
|
|
#endif
|
2016-01-16 03:00:20 +08:00
|
|
|
}
|
|
|
|
|
2016-02-04 05:13:23 +08:00
|
|
|
#ifndef NDEBUG
|
2014-08-21 13:55:13 +08:00
|
|
|
static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
|
2014-05-13 09:23:21 +08:00
|
|
|
Constant *C) {
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!Cache.insert(Expr).second)
|
2014-05-13 09:23:21 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
for (auto &O : Expr->operands()) {
|
|
|
|
if (O == C)
|
|
|
|
return true;
|
|
|
|
auto *CE = dyn_cast<ConstantExpr>(O);
|
|
|
|
if (!CE)
|
|
|
|
continue;
|
|
|
|
if (contains(Cache, CE, C))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool contains(Value *Expr, Value *V) {
|
|
|
|
if (Expr == V)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
auto *C = dyn_cast<Constant>(V);
|
|
|
|
if (!C)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto *CE = dyn_cast<ConstantExpr>(Expr);
|
|
|
|
if (!CE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SmallPtrSet<ConstantExpr *, 4> Cache;
|
|
|
|
return contains(Cache, CE, C);
|
|
|
|
}
|
2016-02-03 02:20:45 +08:00
|
|
|
#endif // NDEBUG
|
2007-02-11 08:37:27 +08:00
|
|
|
|
2018-08-10 02:28:54 +08:00
|
|
|
void Value::doRAUW(Value *New, ReplaceMetadataUses ReplaceMetaUses) {
|
2011-07-15 14:18:52 +08:00
|
|
|
assert(New && "Value::replaceAllUsesWith(<null>) is invalid!");
|
2014-05-13 09:23:21 +08:00
|
|
|
assert(!contains(New, this) &&
|
|
|
|
"this->replaceAllUsesWith(expr(this)) is NOT valid!");
|
2011-07-15 14:18:52 +08:00
|
|
|
assert(New->getType() == getType() &&
|
|
|
|
"replaceAllUses of value with new value of different type!");
|
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
// Notify all ValueHandles (if present) that this value is going away.
|
|
|
|
if (HasValueHandle)
|
|
|
|
ValueHandleBase::ValueIsRAUWd(this, New);
|
2018-08-10 02:28:54 +08:00
|
|
|
if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
|
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
|
|
|
ValueAsMetadata::handleRAUW(this, New);
|
2013-03-02 02:48:54 +08:00
|
|
|
|
2017-12-16 08:18:12 +08:00
|
|
|
while (!materialized_use_empty()) {
|
2008-09-19 23:13:20 +08:00
|
|
|
Use &U = *UseList;
|
2003-08-29 13:09:37 +08:00
|
|
|
// Must handle Constants specially, we cannot call replaceUsesOfWith on a
|
2007-08-21 08:21:07 +08:00
|
|
|
// constant because they are uniqued.
|
2014-05-17 03:35:39 +08:00
|
|
|
if (auto *C = dyn_cast<Constant>(U.getUser())) {
|
2007-08-21 08:21:07 +08:00
|
|
|
if (!isa<GlobalValue>(C)) {
|
2016-02-11 06:47:15 +08:00
|
|
|
C->handleOperandChange(this, New);
|
2007-08-21 08:21:07 +08:00
|
|
|
continue;
|
|
|
|
}
|
2003-08-29 13:09:37 +08:00
|
|
|
}
|
2013-03-02 02:48:54 +08:00
|
|
|
|
2007-08-21 08:21:07 +08:00
|
|
|
U.set(New);
|
2003-08-29 13:09:37 +08:00
|
|
|
}
|
2013-03-02 02:48:54 +08:00
|
|
|
|
2011-06-23 17:09:15 +08:00
|
|
|
if (BasicBlock *BB = dyn_cast<BasicBlock>(this))
|
|
|
|
BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
|
2003-08-29 13:09:37 +08:00
|
|
|
}
|
|
|
|
|
2016-12-08 05:47:32 +08:00
|
|
|
void Value::replaceAllUsesWith(Value *New) {
|
2018-08-10 02:28:54 +08:00
|
|
|
doRAUW(New, ReplaceMetadataUses::Yes);
|
2016-12-08 05:47:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Value::replaceNonMetadataUsesWith(Value *New) {
|
2018-08-10 02:28:54 +08:00
|
|
|
doRAUW(New, ReplaceMetadataUses::No);
|
2016-12-08 05:47:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-25 05:55:49 +08:00
|
|
|
void Value::replaceUsesWithIf(Value *New,
|
|
|
|
llvm::function_ref<bool(Use &U)> ShouldReplace) {
|
|
|
|
assert(New && "Value::replaceUsesWithIf(<null>) is invalid!");
|
|
|
|
assert(New->getType() == getType() &&
|
|
|
|
"replaceUses of value with new value of different type!");
|
|
|
|
|
2021-06-29 04:37:45 +08:00
|
|
|
SmallVector<TrackingVH<Constant>, 8> Consts;
|
|
|
|
SmallPtrSet<Constant *, 8> Visited;
|
|
|
|
|
2021-11-06 10:39:06 +08:00
|
|
|
for (Use &U : llvm::make_early_inc_range(uses())) {
|
2021-05-25 05:55:49 +08:00
|
|
|
if (!ShouldReplace(U))
|
|
|
|
continue;
|
|
|
|
// Must handle Constants specially, we cannot call replaceUsesOfWith on a
|
|
|
|
// constant because they are uniqued.
|
|
|
|
if (auto *C = dyn_cast<Constant>(U.getUser())) {
|
|
|
|
if (!isa<GlobalValue>(C)) {
|
2021-06-29 04:37:45 +08:00
|
|
|
if (Visited.insert(C).second)
|
|
|
|
Consts.push_back(TrackingVH<Constant>(C));
|
2021-05-25 05:55:49 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
U.set(New);
|
|
|
|
}
|
2021-06-29 04:37:45 +08:00
|
|
|
|
|
|
|
while (!Consts.empty()) {
|
|
|
|
// FIXME: handleOperandChange() updates all the uses in a given Constant,
|
|
|
|
// not just the one passed to ShouldReplace
|
|
|
|
Consts.pop_back_val()->handleOperandChange(this, New);
|
|
|
|
}
|
2021-05-25 05:55:49 +08:00
|
|
|
}
|
|
|
|
|
2021-04-19 17:31:41 +08:00
|
|
|
/// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
|
|
|
|
/// with New.
|
|
|
|
static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) {
|
|
|
|
SmallVector<DbgVariableIntrinsic *> DbgUsers;
|
|
|
|
findDbgUsers(DbgUsers, V);
|
|
|
|
for (auto *DVI : DbgUsers) {
|
|
|
|
if (DVI->getParent() != BB)
|
|
|
|
DVI->replaceVariableLocationOp(V, New);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 07:36:44 +08:00
|
|
|
// Like replaceAllUsesWith except it does not handle constants or basic blocks.
|
|
|
|
// This routine leaves uses within BB.
|
|
|
|
void Value::replaceUsesOutsideBlock(Value *New, BasicBlock *BB) {
|
|
|
|
assert(New && "Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
|
|
|
|
assert(!contains(New, this) &&
|
|
|
|
"this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
|
|
|
|
assert(New->getType() == getType() &&
|
|
|
|
"replaceUses of value with new value of different type!");
|
|
|
|
assert(BB && "Basic block that may contain a use of 'New' must be defined\n");
|
|
|
|
|
2021-04-19 17:31:41 +08:00
|
|
|
replaceDbgUsesOutsideBlock(this, New, BB);
|
[IR] Value: add replaceUsesWithIf() utility
Summary:
While there is always a `Value::replaceAllUsesWith()`,
sometimes the replacement needs to be conditional.
I have only cleaned a few cases where `replaceUsesWithIf()`
could be used, to both add test coverage,
and show that it is actually useful.
Reviewers: jdoerfert, spatel, RKSimon, craig.topper
Reviewed By: jdoerfert
Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, aheejin, george.burgess.iv, asbirlea, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65528
llvm-svn: 367548
2019-08-01 20:32:08 +08:00
|
|
|
replaceUsesWithIf(New, [BB](Use &U) {
|
|
|
|
auto *I = dyn_cast<Instruction>(U.getUser());
|
|
|
|
// Don't replace if it's an instruction in the BB basic block.
|
|
|
|
return !I || I->getParent() != BB;
|
|
|
|
});
|
2014-11-22 07:36:44 +08:00
|
|
|
}
|
|
|
|
|
2012-03-10 16:39:09 +08:00
|
|
|
namespace {
|
|
|
|
// Various metrics for how much to strip off of pointers.
|
|
|
|
enum PointerStripKind {
|
|
|
|
PSK_ZeroIndices,
|
2019-10-08 01:28:03 +08:00
|
|
|
PSK_ZeroIndicesAndAliases,
|
2019-08-23 03:56:14 +08:00
|
|
|
PSK_ZeroIndicesSameRepresentation,
|
2021-02-15 04:24:36 +08:00
|
|
|
PSK_ForAliasAnalysis,
|
2012-03-15 07:19:53 +08:00
|
|
|
PSK_InBoundsConstantIndices,
|
|
|
|
PSK_InBounds
|
2012-03-10 16:39:09 +08:00
|
|
|
};
|
|
|
|
|
2020-06-19 18:01:59 +08:00
|
|
|
template <PointerStripKind StripKind> static void NoopCallback(const Value *) {}
|
|
|
|
|
2012-03-10 16:39:09 +08:00
|
|
|
template <PointerStripKind StripKind>
|
2020-06-19 16:32:09 +08:00
|
|
|
static const Value *stripPointerCastsAndOffsets(
|
|
|
|
const Value *V,
|
2020-06-19 18:01:59 +08:00
|
|
|
function_ref<void(const Value *)> Func = NoopCallback<StripKind>) {
|
2012-03-10 16:39:09 +08:00
|
|
|
if (!V->getType()->isPointerTy())
|
|
|
|
return V;
|
2010-06-29 05:16:52 +08:00
|
|
|
|
|
|
|
// Even though we don't look through PHI nodes, we could be called on an
|
|
|
|
// instruction in an unreachable block, which may be on a cycle.
|
2017-03-27 13:47:03 +08:00
|
|
|
SmallPtrSet<const Value *, 4> Visited;
|
2010-06-29 05:16:52 +08:00
|
|
|
|
|
|
|
Visited.insert(V);
|
2008-12-30 05:06:19 +08:00
|
|
|
do {
|
2020-06-19 16:32:09 +08:00
|
|
|
Func(V);
|
2017-03-27 13:47:03 +08:00
|
|
|
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
|
2012-03-10 16:39:09 +08:00
|
|
|
switch (StripKind) {
|
|
|
|
case PSK_ZeroIndices:
|
2019-10-08 01:28:03 +08:00
|
|
|
case PSK_ZeroIndicesAndAliases:
|
2019-08-23 03:56:14 +08:00
|
|
|
case PSK_ZeroIndicesSameRepresentation:
|
2021-02-15 04:24:36 +08:00
|
|
|
case PSK_ForAliasAnalysis:
|
2012-03-10 16:39:09 +08:00
|
|
|
if (!GEP->hasAllZeroIndices())
|
|
|
|
return V;
|
|
|
|
break;
|
2012-03-15 07:19:53 +08:00
|
|
|
case PSK_InBoundsConstantIndices:
|
2012-03-10 16:39:09 +08:00
|
|
|
if (!GEP->hasAllConstantIndices())
|
|
|
|
return V;
|
2016-08-17 13:10:15 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2012-03-10 16:39:09 +08:00
|
|
|
case PSK_InBounds:
|
|
|
|
if (!GEP->isInBounds())
|
|
|
|
return V;
|
|
|
|
break;
|
|
|
|
}
|
2009-07-18 07:55:56 +08:00
|
|
|
V = GEP->getPointerOperand();
|
Introduce Value::stripPointerCastsSameRepresentation
This patch allows current users of Value::stripPointerCasts() to force
the result of the function to have the same representation as the value
it was called on. This is useful in various cases, e.g., (non-)null
checks.
In this patch only a single call site was adjusted to fix an existing
misuse that would cause nonnull where they may be wrong. Uses in
attribute deduction and other areas, e.g., D60047, are to be expected.
For a discussion on this topic, please see [0].
[0] http://lists.llvm.org/pipermail/llvm-dev/2018-December/128423.html
Reviewers: hfinkel, arsenm, reames
Subscribers: wdng, hiraditya, bollu, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61607
llvm-svn: 362545
2019-06-05 04:21:46 +08:00
|
|
|
} else if (Operator::getOpcode(V) == Instruction::BitCast) {
|
|
|
|
V = cast<Operator>(V)->getOperand(0);
|
2020-06-25 02:11:49 +08:00
|
|
|
if (!V->getType()->isPointerTy())
|
|
|
|
return V;
|
2019-08-23 03:56:14 +08:00
|
|
|
} else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
|
2013-11-15 09:34:59 +08:00
|
|
|
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
|
Introduce Value::stripPointerCastsSameRepresentation
This patch allows current users of Value::stripPointerCasts() to force
the result of the function to have the same representation as the value
it was called on. This is useful in various cases, e.g., (non-)null
checks.
In this patch only a single call site was adjusted to fix an existing
misuse that would cause nonnull where they may be wrong. Uses in
attribute deduction and other areas, e.g., D60047, are to be expected.
For a discussion on this topic, please see [0].
[0] http://lists.llvm.org/pipermail/llvm-dev/2018-December/128423.html
Reviewers: hfinkel, arsenm, reames
Subscribers: wdng, hiraditya, bollu, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61607
llvm-svn: 362545
2019-06-05 04:21:46 +08:00
|
|
|
// TODO: If we know an address space cast will not change the
|
|
|
|
// representation we could look through it here as well.
|
2009-07-18 07:55:56 +08:00
|
|
|
V = cast<Operator>(V)->getOperand(0);
|
2019-10-08 01:28:03 +08:00
|
|
|
} else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
|
|
|
|
V = cast<GlobalAlias>(V)->getAliasee();
|
2021-02-15 04:24:36 +08:00
|
|
|
} else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
|
|
|
|
cast<PHINode>(V)->getNumIncomingValues() == 1) {
|
|
|
|
V = cast<PHINode>(V)->getIncomingValue(0);
|
2008-12-30 05:06:19 +08:00
|
|
|
} else {
|
2019-01-07 15:31:49 +08:00
|
|
|
if (const auto *Call = dyn_cast<CallBase>(V)) {
|
|
|
|
if (const Value *RV = Call->getReturnedArgOperand()) {
|
2016-07-11 09:32:20 +08:00
|
|
|
V = RV;
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-03 19:03:01 +08:00
|
|
|
// The result of launder.invariant.group must alias it's argument,
|
Handle invariant.group.barrier in BasicAA
Summary:
llvm.invariant.group.barrier returns pointer that mustalias
pointer it takes. It can't be marked with `returned` attribute,
because it would be remove easily. The other reason is that
only Alias Analysis can know about this, because if any other
pass would know it, then the result would be replaced with it's
argument, which would be invalid.
We can think about returned pointer as something that mustalias, but
it doesn't have to be bitwise the same as the argument.
Reviewers: dberlin, chandlerc, hfinkel, sanjoy
Subscribers: reames, nlewycky, rsmith, anna, amharc
Differential Revision: https://reviews.llvm.org/D31585
llvm-svn: 301227
2017-04-25 03:37:17 +08:00
|
|
|
// but it can't be marked with returned attribute, that's why it needs
|
|
|
|
// special case.
|
2021-02-15 04:24:36 +08:00
|
|
|
if (StripKind == PSK_ForAliasAnalysis &&
|
2019-01-07 15:31:49 +08:00
|
|
|
(Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
|
|
|
|
Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
|
|
|
|
V = Call->getArgOperand(0);
|
Handle invariant.group.barrier in BasicAA
Summary:
llvm.invariant.group.barrier returns pointer that mustalias
pointer it takes. It can't be marked with `returned` attribute,
because it would be remove easily. The other reason is that
only Alias Analysis can know about this, because if any other
pass would know it, then the result would be replaced with it's
argument, which would be invalid.
We can think about returned pointer as something that mustalias, but
it doesn't have to be bitwise the same as the argument.
Reviewers: dberlin, chandlerc, hfinkel, sanjoy
Subscribers: reames, nlewycky, rsmith, anna, amharc
Differential Revision: https://reviews.llvm.org/D31585
llvm-svn: 301227
2017-04-25 03:37:17 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2008-12-30 05:06:19 +08:00
|
|
|
return V;
|
2008-05-08 06:54:15 +08:00
|
|
|
}
|
2010-02-16 19:11:14 +08:00
|
|
|
assert(V->getType()->isPointerTy() && "Unexpected operand type!");
|
2014-11-19 15:49:26 +08:00
|
|
|
} while (Visited.insert(V).second);
|
2010-06-29 05:16:52 +08:00
|
|
|
|
|
|
|
return V;
|
2008-05-08 06:54:15 +08:00
|
|
|
}
|
2016-02-03 02:20:45 +08:00
|
|
|
} // end anonymous namespace
|
2012-03-10 16:39:09 +08:00
|
|
|
|
2017-03-27 13:47:03 +08:00
|
|
|
const Value *Value::stripPointerCasts() const {
|
2019-08-23 03:56:14 +08:00
|
|
|
return stripPointerCastsAndOffsets<PSK_ZeroIndices>(this);
|
2013-05-06 09:48:55 +08:00
|
|
|
}
|
|
|
|
|
2019-10-08 01:28:03 +08:00
|
|
|
const Value *Value::stripPointerCastsAndAliases() const {
|
|
|
|
return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(this);
|
|
|
|
}
|
|
|
|
|
Introduce Value::stripPointerCastsSameRepresentation
This patch allows current users of Value::stripPointerCasts() to force
the result of the function to have the same representation as the value
it was called on. This is useful in various cases, e.g., (non-)null
checks.
In this patch only a single call site was adjusted to fix an existing
misuse that would cause nonnull where they may be wrong. Uses in
attribute deduction and other areas, e.g., D60047, are to be expected.
For a discussion on this topic, please see [0].
[0] http://lists.llvm.org/pipermail/llvm-dev/2018-December/128423.html
Reviewers: hfinkel, arsenm, reames
Subscribers: wdng, hiraditya, bollu, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61607
llvm-svn: 362545
2019-06-05 04:21:46 +08:00
|
|
|
const Value *Value::stripPointerCastsSameRepresentation() const {
|
2019-08-23 03:56:14 +08:00
|
|
|
return stripPointerCastsAndOffsets<PSK_ZeroIndicesSameRepresentation>(this);
|
2012-03-10 16:39:09 +08:00
|
|
|
}
|
|
|
|
|
2017-03-27 13:47:03 +08:00
|
|
|
const Value *Value::stripInBoundsConstantOffsets() const {
|
2012-03-15 07:19:53 +08:00
|
|
|
return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(this);
|
Handle invariant.group.barrier in BasicAA
Summary:
llvm.invariant.group.barrier returns pointer that mustalias
pointer it takes. It can't be marked with `returned` attribute,
because it would be remove easily. The other reason is that
only Alias Analysis can know about this, because if any other
pass would know it, then the result would be replaced with it's
argument, which would be invalid.
We can think about returned pointer as something that mustalias, but
it doesn't have to be bitwise the same as the argument.
Reviewers: dberlin, chandlerc, hfinkel, sanjoy
Subscribers: reames, nlewycky, rsmith, anna, amharc
Differential Revision: https://reviews.llvm.org/D31585
llvm-svn: 301227
2017-04-25 03:37:17 +08:00
|
|
|
}
|
|
|
|
|
2021-02-15 04:24:36 +08:00
|
|
|
const Value *Value::stripPointerCastsForAliasAnalysis() const {
|
|
|
|
return stripPointerCastsAndOffsets<PSK_ForAliasAnalysis>(this);
|
2012-03-10 16:39:09 +08:00
|
|
|
}
|
|
|
|
|
2020-05-14 01:49:15 +08:00
|
|
|
const Value *Value::stripAndAccumulateConstantOffsets(
|
|
|
|
const DataLayout &DL, APInt &Offset, bool AllowNonInbounds,
|
2021-10-24 00:12:54 +08:00
|
|
|
bool AllowInvariantGroup,
|
2020-05-14 01:49:15 +08:00
|
|
|
function_ref<bool(Value &, APInt &)> ExternalAnalysis) const {
|
2019-07-11 09:14:48 +08:00
|
|
|
if (!getType()->isPtrOrPtrVectorTy())
|
2013-08-22 19:25:11 +08:00
|
|
|
return this;
|
|
|
|
|
2019-07-11 09:14:48 +08:00
|
|
|
unsigned BitWidth = Offset.getBitWidth();
|
|
|
|
assert(BitWidth == DL.getIndexTypeSizeInBits(getType()) &&
|
2018-02-14 14:58:08 +08:00
|
|
|
"The offset bit width does not match the DL specification.");
|
2013-08-22 19:25:11 +08:00
|
|
|
|
|
|
|
// Even though we don't look through PHI nodes, we could be called on an
|
|
|
|
// instruction in an unreachable block, which may be on a cycle.
|
2017-03-27 13:47:03 +08:00
|
|
|
SmallPtrSet<const Value *, 4> Visited;
|
2013-08-22 19:25:11 +08:00
|
|
|
Visited.insert(this);
|
2017-03-27 13:47:03 +08:00
|
|
|
const Value *V = this;
|
2013-08-22 19:25:11 +08:00
|
|
|
do {
|
2017-03-27 13:47:03 +08:00
|
|
|
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
|
2019-07-11 09:14:48 +08:00
|
|
|
// If in-bounds was requested, we do not strip non-in-bounds GEPs.
|
|
|
|
if (!AllowNonInbounds && !GEP->isInBounds())
|
2013-08-22 19:25:11 +08:00
|
|
|
return V;
|
2019-07-11 09:14:48 +08:00
|
|
|
|
|
|
|
// If one of the values we have visited is an addrspacecast, then
|
|
|
|
// the pointer type of this GEP may be different from the type
|
|
|
|
// of the Ptr parameter which was passed to this function. This
|
|
|
|
// means when we construct GEPOffset, we need to use the size
|
|
|
|
// of GEP's pointer type rather than the size of the original
|
|
|
|
// pointer type.
|
|
|
|
APInt GEPOffset(DL.getIndexTypeSizeInBits(V->getType()), 0);
|
2020-05-14 01:49:15 +08:00
|
|
|
if (!GEP->accumulateConstantOffset(DL, GEPOffset, ExternalAnalysis))
|
2013-08-22 19:25:11 +08:00
|
|
|
return V;
|
2019-07-11 09:14:48 +08:00
|
|
|
|
|
|
|
// Stop traversal if the pointer offset wouldn't fit in the bit-width
|
|
|
|
// provided by the Offset argument. This can happen due to AddrSpaceCast
|
|
|
|
// stripping.
|
|
|
|
if (GEPOffset.getMinSignedBits() > BitWidth)
|
|
|
|
return V;
|
|
|
|
|
2020-05-14 01:49:15 +08:00
|
|
|
// External Analysis can return a result higher/lower than the value
|
|
|
|
// represents. We need to detect overflow/underflow.
|
|
|
|
APInt GEPOffsetST = GEPOffset.sextOrTrunc(BitWidth);
|
|
|
|
if (!ExternalAnalysis) {
|
|
|
|
Offset += GEPOffsetST;
|
|
|
|
} else {
|
|
|
|
bool Overflow = false;
|
|
|
|
APInt OldOffset = Offset;
|
|
|
|
Offset = Offset.sadd_ov(GEPOffsetST, Overflow);
|
|
|
|
if (Overflow) {
|
|
|
|
Offset = OldOffset;
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
}
|
2013-08-22 19:25:11 +08:00
|
|
|
V = GEP->getPointerOperand();
|
2019-07-11 09:14:48 +08:00
|
|
|
} else if (Operator::getOpcode(V) == Instruction::BitCast ||
|
|
|
|
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
|
2013-08-22 19:25:11 +08:00
|
|
|
V = cast<Operator>(V)->getOperand(0);
|
2017-03-27 13:47:03 +08:00
|
|
|
} else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
|
2019-07-11 09:14:48 +08:00
|
|
|
if (!GA->isInterposable())
|
|
|
|
V = GA->getAliasee();
|
|
|
|
} else if (const auto *Call = dyn_cast<CallBase>(V)) {
|
|
|
|
if (const Value *RV = Call->getReturnedArgOperand())
|
2016-07-11 09:32:20 +08:00
|
|
|
V = RV;
|
2021-10-24 00:12:54 +08:00
|
|
|
if (AllowInvariantGroup && Call->isLaunderOrStripInvariantGroup())
|
|
|
|
V = Call->getArgOperand(0);
|
2013-08-22 19:25:11 +08:00
|
|
|
}
|
2019-07-11 09:14:48 +08:00
|
|
|
assert(V->getType()->isPtrOrPtrVectorTy() && "Unexpected operand type!");
|
2014-11-19 15:49:26 +08:00
|
|
|
} while (Visited.insert(V).second);
|
2013-08-22 19:25:11 +08:00
|
|
|
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
2020-06-19 16:32:09 +08:00
|
|
|
const Value *
|
|
|
|
Value::stripInBoundsOffsets(function_ref<void(const Value *)> Func) const {
|
|
|
|
return stripPointerCastsAndOffsets<PSK_InBounds>(this, Func);
|
2012-03-10 16:39:09 +08:00
|
|
|
}
|
2008-05-08 06:54:15 +08:00
|
|
|
|
2021-04-01 23:29:47 +08:00
|
|
|
bool Value::canBeFreed() const {
|
|
|
|
assert(getType()->isPointerTy());
|
2021-03-25 07:18:09 +08:00
|
|
|
|
|
|
|
// Cases that can simply never be deallocated
|
|
|
|
// *) Constants aren't allocated per se, thus not deallocated either.
|
2021-04-01 23:29:47 +08:00
|
|
|
if (isa<Constant>(this))
|
2021-03-25 07:18:09 +08:00
|
|
|
return false;
|
|
|
|
|
2021-03-26 05:47:31 +08:00
|
|
|
// Handle byval/byref/sret/inalloca/preallocated arguments. The storage
|
|
|
|
// lifetime is guaranteed to be longer than the callee's lifetime.
|
2021-04-17 02:37:36 +08:00
|
|
|
if (auto *A = dyn_cast<Argument>(this)) {
|
2021-03-26 05:47:31 +08:00
|
|
|
if (A->hasPointeeInMemoryValueAttr())
|
|
|
|
return false;
|
2021-04-17 02:37:36 +08:00
|
|
|
// A pointer to an object in a function which neither frees, nor can arrange
|
|
|
|
// for another thread to free on its behalf, can not be freed in the scope
|
|
|
|
// of the function. Note that this logic is restricted to memory
|
|
|
|
// allocations in existance before the call; a nofree function *is* allowed
|
|
|
|
// to free memory it allocated.
|
|
|
|
const Function *F = A->getParent();
|
|
|
|
if (F->doesNotFreeMemory() && F->hasNoSync())
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-26 05:47:31 +08:00
|
|
|
|
2021-03-25 07:18:09 +08:00
|
|
|
const Function *F = nullptr;
|
2021-04-01 23:29:47 +08:00
|
|
|
if (auto *I = dyn_cast<Instruction>(this))
|
2021-03-25 07:18:09 +08:00
|
|
|
F = I->getFunction();
|
2021-04-01 23:29:47 +08:00
|
|
|
if (auto *A = dyn_cast<Argument>(this))
|
2021-03-25 07:18:09 +08:00
|
|
|
F = A->getParent();
|
|
|
|
|
|
|
|
if (!F)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// With garbage collection, deallocation typically occurs solely at or after
|
|
|
|
// safepoints. If we're compiling for a collector which uses the
|
|
|
|
// gc.statepoint infrastructure, safepoints aren't explicitly present
|
|
|
|
// in the IR until after lowering from abstract to physical machine model.
|
|
|
|
// The collector could chose to mix explicit deallocation and gc'd objects
|
|
|
|
// which is why we need the explicit opt in on a per collector basis.
|
|
|
|
if (!F->hasGC())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const auto &GCName = F->getGC();
|
2021-04-20 14:59:03 +08:00
|
|
|
if (GCName == "statepoint-example") {
|
|
|
|
auto *PT = cast<PointerType>(this->getType());
|
|
|
|
if (PT->getAddressSpace() != 1)
|
|
|
|
// For the sake of this example GC, we arbitrarily pick addrspace(1) as
|
|
|
|
// our GC managed heap. This must match the same check in
|
|
|
|
// RewriteStatepointsForGC (and probably needs better factored.)
|
2021-03-25 07:18:09 +08:00
|
|
|
return true;
|
2021-04-20 14:59:03 +08:00
|
|
|
|
|
|
|
// It is cheaper to scan for a declaration than to scan for a use in this
|
|
|
|
// function. Note that gc.statepoint is a type overloaded function so the
|
|
|
|
// usual trick of requesting declaration of the intrinsic from the module
|
|
|
|
// doesn't work.
|
|
|
|
for (auto &Fn : *F->getParent())
|
|
|
|
if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2021-03-25 07:18:09 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 05:20:16 +08:00
|
|
|
uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
|
2021-03-20 02:15:29 +08:00
|
|
|
bool &CanBeNull,
|
|
|
|
bool &CanBeFreed) const {
|
2016-04-27 20:51:01 +08:00
|
|
|
assert(getType()->isPointerTy() && "must be pointer");
|
|
|
|
|
2017-12-18 05:20:16 +08:00
|
|
|
uint64_t DerefBytes = 0;
|
2016-04-27 20:51:01 +08:00
|
|
|
CanBeNull = false;
|
2021-04-01 23:29:47 +08:00
|
|
|
CanBeFreed = UseDerefAtPointSemantics && canBeFreed();
|
2016-04-27 20:51:01 +08:00
|
|
|
if (const Argument *A = dyn_cast<Argument>(this)) {
|
|
|
|
DerefBytes = A->getDereferenceableBytes();
|
2020-06-26 07:17:24 +08:00
|
|
|
if (DerefBytes == 0) {
|
|
|
|
// Handle byval/byref/inalloca/preallocated arguments
|
|
|
|
if (Type *ArgMemTy = A->getPointeeInMemoryValueType()) {
|
|
|
|
if (ArgMemTy->isSized()) {
|
|
|
|
// FIXME: Why isn't this the type alloc size?
|
|
|
|
DerefBytes = DL.getTypeStoreSize(ArgMemTy).getKnownMinSize();
|
|
|
|
}
|
|
|
|
}
|
2016-06-02 08:52:48 +08:00
|
|
|
}
|
2020-06-26 07:17:24 +08:00
|
|
|
|
2016-04-27 20:51:01 +08:00
|
|
|
if (DerefBytes == 0) {
|
|
|
|
DerefBytes = A->getDereferenceableOrNullBytes();
|
|
|
|
CanBeNull = true;
|
|
|
|
}
|
2019-01-07 15:31:49 +08:00
|
|
|
} else if (const auto *Call = dyn_cast<CallBase>(this)) {
|
2021-08-20 05:02:11 +08:00
|
|
|
DerefBytes = Call->getRetDereferenceableBytes();
|
2016-04-27 20:51:01 +08:00
|
|
|
if (DerefBytes == 0) {
|
2021-08-20 05:02:11 +08:00
|
|
|
DerefBytes = Call->getRetDereferenceableOrNullBytes();
|
2016-04-27 20:51:01 +08:00
|
|
|
CanBeNull = true;
|
|
|
|
}
|
|
|
|
} else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
|
|
|
|
if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
|
|
|
|
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
|
|
|
|
DerefBytes = CI->getLimitedValue();
|
|
|
|
}
|
|
|
|
if (DerefBytes == 0) {
|
|
|
|
if (MDNode *MD =
|
|
|
|
LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
|
|
|
|
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
|
|
|
|
DerefBytes = CI->getLimitedValue();
|
|
|
|
}
|
|
|
|
CanBeNull = true;
|
|
|
|
}
|
2019-07-24 01:19:56 +08:00
|
|
|
} else if (auto *IP = dyn_cast<IntToPtrInst>(this)) {
|
|
|
|
if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
|
|
|
|
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
|
|
|
|
DerefBytes = CI->getLimitedValue();
|
|
|
|
}
|
|
|
|
if (DerefBytes == 0) {
|
|
|
|
if (MDNode *MD =
|
|
|
|
IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
|
|
|
|
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
|
|
|
|
DerefBytes = CI->getLimitedValue();
|
|
|
|
}
|
|
|
|
CanBeNull = true;
|
|
|
|
}
|
2016-06-02 08:52:48 +08:00
|
|
|
} else if (auto *AI = dyn_cast<AllocaInst>(this)) {
|
2017-12-20 18:01:30 +08:00
|
|
|
if (!AI->isArrayAllocation()) {
|
2020-03-17 02:13:20 +08:00
|
|
|
DerefBytes =
|
|
|
|
DL.getTypeStoreSize(AI->getAllocatedType()).getKnownMinSize();
|
2016-06-02 08:52:48 +08:00
|
|
|
CanBeNull = false;
|
2021-03-20 02:15:29 +08:00
|
|
|
CanBeFreed = false;
|
2016-06-02 08:52:48 +08:00
|
|
|
}
|
|
|
|
} else if (auto *GV = dyn_cast<GlobalVariable>(this)) {
|
|
|
|
if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
|
|
|
|
// TODO: Don't outright reject hasExternalWeakLinkage but set the
|
|
|
|
// CanBeNull flag.
|
2020-03-17 02:13:20 +08:00
|
|
|
DerefBytes = DL.getTypeStoreSize(GV->getValueType()).getFixedSize();
|
2016-06-02 08:52:48 +08:00
|
|
|
CanBeNull = false;
|
2021-07-15 04:19:48 +08:00
|
|
|
CanBeFreed = false;
|
2016-06-02 08:52:48 +08:00
|
|
|
}
|
2016-04-27 20:51:01 +08:00
|
|
|
}
|
|
|
|
return DerefBytes;
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:55:18 +08:00
|
|
|
Align Value::getPointerAlignment(const DataLayout &DL) const {
|
2016-02-24 20:25:10 +08:00
|
|
|
assert(getType()->isPointerTy() && "must be pointer");
|
|
|
|
if (auto *GO = dyn_cast<GlobalObject>(this)) {
|
2019-03-08 18:44:06 +08:00
|
|
|
if (isa<Function>(GO)) {
|
2020-05-17 08:55:18 +08:00
|
|
|
Align FunctionPtrAlign = DL.getFunctionPtrAlign().valueOrOne();
|
2019-03-08 18:44:06 +08:00
|
|
|
switch (DL.getFunctionPtrAlignType()) {
|
|
|
|
case DataLayout::FunctionPtrAlignType::Independent:
|
2019-10-15 21:58:22 +08:00
|
|
|
return FunctionPtrAlign;
|
2019-03-08 18:44:06 +08:00
|
|
|
case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
|
2020-05-17 08:55:18 +08:00
|
|
|
return std::max(FunctionPtrAlign, GO->getAlign().valueOrOne());
|
2019-03-08 18:44:06 +08:00
|
|
|
}
|
2019-09-26 23:13:05 +08:00
|
|
|
llvm_unreachable("Unhandled FunctionPtrAlignType");
|
2019-03-08 18:44:06 +08:00
|
|
|
}
|
2019-10-15 21:58:22 +08:00
|
|
|
const MaybeAlign Alignment(GO->getAlignment());
|
|
|
|
if (!Alignment) {
|
2016-02-24 20:25:10 +08:00
|
|
|
if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
|
|
|
|
Type *ObjectType = GVar->getValueType();
|
|
|
|
if (ObjectType->isSized()) {
|
|
|
|
// If the object is defined in the current Module, we'll be giving
|
|
|
|
// it the preferred alignment. Otherwise, we have to assume that it
|
|
|
|
// may only have the minimum ABI alignment.
|
|
|
|
if (GVar->isStrongDefinitionForLinker())
|
2020-06-29 19:24:36 +08:00
|
|
|
return DL.getPreferredAlign(GVar);
|
2016-02-24 20:25:10 +08:00
|
|
|
else
|
2020-04-02 23:10:30 +08:00
|
|
|
return DL.getABITypeAlign(ObjectType);
|
2016-02-24 20:25:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-17 08:55:18 +08:00
|
|
|
return Alignment.valueOrOne();
|
2016-02-24 20:25:10 +08:00
|
|
|
} else if (const Argument *A = dyn_cast<Argument>(this)) {
|
2020-04-02 23:10:30 +08:00
|
|
|
const MaybeAlign Alignment = A->getParamAlign();
|
2019-10-15 21:58:22 +08:00
|
|
|
if (!Alignment && A->hasStructRetAttr()) {
|
2016-02-24 20:25:10 +08:00
|
|
|
// An sret parameter has at least the ABI alignment of the return type.
|
2020-09-23 23:03:38 +08:00
|
|
|
Type *EltTy = A->getParamStructRetType();
|
2016-02-24 20:25:10 +08:00
|
|
|
if (EltTy->isSized())
|
2020-04-02 23:10:30 +08:00
|
|
|
return DL.getABITypeAlign(EltTy);
|
2016-02-24 20:25:10 +08:00
|
|
|
}
|
2020-05-17 08:55:18 +08:00
|
|
|
return Alignment.valueOrOne();
|
2016-04-27 18:42:29 +08:00
|
|
|
} else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
|
2020-05-17 08:55:18 +08:00
|
|
|
return AI->getAlign();
|
2019-07-28 14:17:46 +08:00
|
|
|
} else if (const auto *Call = dyn_cast<CallBase>(this)) {
|
2020-05-17 08:55:18 +08:00
|
|
|
MaybeAlign Alignment = Call->getRetAlign();
|
2019-10-15 21:58:22 +08:00
|
|
|
if (!Alignment && Call->getCalledFunction())
|
2020-05-17 08:55:18 +08:00
|
|
|
Alignment = Call->getCalledFunction()->getAttributes().getRetAlignment();
|
|
|
|
return Alignment.valueOrOne();
|
2019-09-26 23:13:05 +08:00
|
|
|
} else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
|
2016-02-24 20:25:10 +08:00
|
|
|
if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
|
|
|
|
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
|
2020-05-17 08:55:18 +08:00
|
|
|
return Align(CI->getLimitedValue());
|
2016-02-24 20:25:10 +08:00
|
|
|
}
|
2020-01-22 06:04:47 +08:00
|
|
|
} else if (auto *CstPtr = dyn_cast<Constant>(this)) {
|
|
|
|
if (auto *CstInt = dyn_cast_or_null<ConstantInt>(ConstantExpr::getPtrToInt(
|
|
|
|
const_cast<Constant *>(CstPtr), DL.getIntPtrType(getType()),
|
|
|
|
/*OnlyIfReduced=*/true))) {
|
|
|
|
size_t TrailingZeros = CstInt->getValue().countTrailingZeros();
|
|
|
|
// While the actual alignment may be large, elsewhere we have
|
|
|
|
// an arbitrary upper alignmet limit, so let's clamp to it.
|
|
|
|
return Align(TrailingZeros < Value::MaxAlignmentExponent
|
|
|
|
? uint64_t(1) << TrailingZeros
|
|
|
|
: Value::MaximumAlignment);
|
|
|
|
}
|
2019-09-26 23:13:05 +08:00
|
|
|
}
|
2020-05-17 08:55:18 +08:00
|
|
|
return Align(1);
|
2016-02-24 20:25:10 +08:00
|
|
|
}
|
|
|
|
|
2017-03-27 13:47:03 +08:00
|
|
|
const Value *Value::DoPHITranslation(const BasicBlock *CurBB,
|
|
|
|
const BasicBlock *PredBB) const {
|
|
|
|
auto *PN = dyn_cast<PHINode>(this);
|
2008-12-02 15:16:45 +08:00
|
|
|
if (PN && PN->getParent() == CurBB)
|
|
|
|
return PN->getIncomingValueForBlock(PredBB);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2009-07-22 08:24:57 +08:00
|
|
|
LLVMContext &Value::getContext() const { return VTy->getContext(); }
|
|
|
|
|
2014-08-02 07:28:49 +08:00
|
|
|
void Value::reverseUseList() {
|
|
|
|
if (!UseList || !UseList->Next)
|
|
|
|
// No need to reverse 0 or 1 uses.
|
|
|
|
return;
|
|
|
|
|
|
|
|
Use *Head = UseList;
|
|
|
|
Use *Current = UseList->Next;
|
|
|
|
Head->Next = nullptr;
|
|
|
|
while (Current) {
|
|
|
|
Use *Next = Current->Next;
|
|
|
|
Current->Next = Head;
|
2020-05-16 00:47:40 +08:00
|
|
|
Head->Prev = &Current->Next;
|
2014-08-02 07:28:49 +08:00
|
|
|
Head = Current;
|
|
|
|
Current = Next;
|
|
|
|
}
|
|
|
|
UseList = Head;
|
2020-05-16 00:47:40 +08:00
|
|
|
Head->Prev = &UseList;
|
2014-08-02 07:28:49 +08:00
|
|
|
}
|
|
|
|
|
2016-09-11 02:14:54 +08:00
|
|
|
bool Value::isSwiftError() const {
|
|
|
|
auto *Arg = dyn_cast<Argument>(this);
|
|
|
|
if (Arg)
|
|
|
|
return Arg->hasSwiftErrorAttr();
|
|
|
|
auto *Alloca = dyn_cast<AllocaInst>(this);
|
|
|
|
if (!Alloca)
|
|
|
|
return false;
|
|
|
|
return Alloca->isSwiftError();
|
|
|
|
}
|
|
|
|
|
2021-04-29 12:25:51 +08:00
|
|
|
bool Value::isTransitiveUsedByMetadataOnly() const {
|
|
|
|
if (use_empty())
|
|
|
|
return false;
|
|
|
|
llvm::SmallVector<const User *, 32> WorkList;
|
|
|
|
llvm::SmallPtrSet<const User *, 32> Visited;
|
|
|
|
WorkList.insert(WorkList.begin(), user_begin(), user_end());
|
|
|
|
while (!WorkList.empty()) {
|
2021-09-20 04:44:23 +08:00
|
|
|
const User *U = WorkList.pop_back_val();
|
2021-04-29 12:25:51 +08:00
|
|
|
Visited.insert(U);
|
|
|
|
// If it is transitively used by a global value or a non-constant value,
|
|
|
|
// it's obviously not only used by metadata.
|
|
|
|
if (!isa<Constant>(U) || isa<GlobalValue>(U))
|
|
|
|
return false;
|
|
|
|
for (const User *UU : U->users())
|
|
|
|
if (!Visited.count(UU))
|
|
|
|
WorkList.push_back(UU);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ValueHandleBase Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
|
|
|
|
assert(List && "Handle list is null?");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
// Splice ourselves into the list.
|
|
|
|
Next = *List;
|
|
|
|
*List = this;
|
|
|
|
setPrevPtr(List);
|
|
|
|
if (Next) {
|
|
|
|
Next->setPrevPtr(&Next);
|
2017-04-27 14:02:18 +08:00
|
|
|
assert(getValPtr() == Next->getValPtr() && "Added to wrong list?");
|
2009-04-01 06:11:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-13 01:43:32 +08:00
|
|
|
void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
|
|
|
|
assert(List && "Must insert after existing node");
|
|
|
|
|
|
|
|
Next = List->Next;
|
|
|
|
setPrevPtr(&List->Next);
|
|
|
|
List->Next = this;
|
|
|
|
if (Next)
|
|
|
|
Next->setPrevPtr(&Next);
|
|
|
|
}
|
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
void ValueHandleBase::AddToUseList() {
|
2017-04-27 14:02:18 +08:00
|
|
|
assert(getValPtr() && "Null pointer doesn't have a use list!");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2017-04-27 14:02:18 +08:00
|
|
|
LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2017-04-27 14:02:18 +08:00
|
|
|
if (getValPtr()->HasValueHandle) {
|
2009-04-01 06:11:05 +08:00
|
|
|
// If this value already has a ValueHandle, then it must be in the
|
|
|
|
// ValueHandles map already.
|
2017-04-27 14:02:18 +08:00
|
|
|
ValueHandleBase *&Entry = pImpl->ValueHandles[getValPtr()];
|
2014-04-15 14:32:26 +08:00
|
|
|
assert(Entry && "Value doesn't have any handles?");
|
2009-06-18 01:36:57 +08:00
|
|
|
AddToExistingUseList(&Entry);
|
|
|
|
return;
|
2009-04-01 06:11:05 +08:00
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
// Ok, it doesn't have any handles yet, so we must insert it into the
|
|
|
|
// DenseMap. However, doing this insertion could cause the DenseMap to
|
|
|
|
// reallocate itself, which would invalidate all of the PrevP pointers that
|
|
|
|
// point into the old table. Handle this by checking for reallocation and
|
|
|
|
// updating the stale pointers only if needed.
|
2009-08-19 02:28:58 +08:00
|
|
|
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
|
2009-04-01 06:11:05 +08:00
|
|
|
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2017-04-27 14:02:18 +08:00
|
|
|
ValueHandleBase *&Entry = Handles[getValPtr()];
|
2014-04-15 14:32:26 +08:00
|
|
|
assert(!Entry && "Value really did already have handles?");
|
2009-04-01 06:11:05 +08:00
|
|
|
AddToExistingUseList(&Entry);
|
2017-04-27 14:02:18 +08:00
|
|
|
getValPtr()->HasValueHandle = true;
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
// If reallocation didn't happen or if this was the first insertion, don't
|
|
|
|
// walk the table.
|
2009-09-20 12:03:34 +08:00
|
|
|
if (Handles.isPointerIntoBucketsArray(OldBucketPtr) ||
|
2009-06-18 01:36:57 +08:00
|
|
|
Handles.size() == 1) {
|
2009-04-01 06:11:05 +08:00
|
|
|
return;
|
2009-06-18 01:36:57 +08:00
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
// Okay, reallocation did happen. Fix the Prev Pointers.
|
2009-08-19 02:28:58 +08:00
|
|
|
for (DenseMap<Value*, ValueHandleBase*>::iterator I = Handles.begin(),
|
|
|
|
E = Handles.end(); I != E; ++I) {
|
2017-04-27 14:02:18 +08:00
|
|
|
assert(I->second && I->first == I->second->getValPtr() &&
|
2012-04-08 18:16:43 +08:00
|
|
|
"List invariant broken!");
|
2009-04-01 06:11:05 +08:00
|
|
|
I->second->setPrevPtr(&I->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValueHandleBase::RemoveFromUseList() {
|
2017-04-27 14:02:18 +08:00
|
|
|
assert(getValPtr() && getValPtr()->HasValueHandle &&
|
2012-04-08 18:16:43 +08:00
|
|
|
"Pointer doesn't have a use list!");
|
2009-04-01 06:11:05 +08:00
|
|
|
|
|
|
|
// Unlink this from its use list.
|
|
|
|
ValueHandleBase **PrevPtr = getPrevPtr();
|
|
|
|
assert(*PrevPtr == this && "List invariant broken");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
*PrevPtr = Next;
|
|
|
|
if (Next) {
|
|
|
|
assert(Next->getPrevPtr() == &Next && "List invariant broken");
|
|
|
|
Next->setPrevPtr(PrevPtr);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
// If the Next pointer was null, then it is possible that this was the last
|
|
|
|
// ValueHandle watching VP. If so, delete its entry from the ValueHandles
|
|
|
|
// map.
|
2017-04-27 14:02:18 +08:00
|
|
|
LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
|
2009-08-19 02:28:58 +08:00
|
|
|
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
|
2009-04-01 06:11:05 +08:00
|
|
|
if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
|
2017-04-27 14:02:18 +08:00
|
|
|
Handles.erase(getValPtr());
|
|
|
|
getValPtr()->HasValueHandle = false;
|
2009-04-01 06:11:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValueHandleBase::ValueIsDeleted(Value *V) {
|
|
|
|
assert(V->HasValueHandle && "Should only be called if ValueHandles present");
|
|
|
|
|
|
|
|
// Get the linked list base, which is guaranteed to exist since the
|
|
|
|
// HasValueHandle flag is set.
|
2009-08-19 02:28:58 +08:00
|
|
|
LLVMContextImpl *pImpl = V->getContext().pImpl;
|
|
|
|
ValueHandleBase *Entry = pImpl->ValueHandles[V];
|
2009-04-01 06:11:05 +08:00
|
|
|
assert(Entry && "Value bit set but no entries exist");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2010-07-24 20:09:22 +08:00
|
|
|
// We use a local ValueHandleBase as an iterator so that ValueHandles can add
|
|
|
|
// and remove themselves from the list without breaking our iteration. This
|
|
|
|
// is not really an AssertingVH; we just have to give ValueHandleBase a kind.
|
|
|
|
// Note that we deliberately do not the support the case when dropping a value
|
|
|
|
// handle results in a new value handle being permanently added to the list
|
|
|
|
// (as might occur in theory for CallbackVH's): the new value handle will not
|
2010-07-27 14:53:14 +08:00
|
|
|
// be processed and the checking code will mete out righteous punishment if
|
2010-07-24 20:09:22 +08:00
|
|
|
// the handle is still present once we have finished processing all the other
|
|
|
|
// value handles (it is fine to momentarily add then remove a value handle).
|
2009-10-13 01:43:32 +08:00
|
|
|
for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
|
|
|
|
Iterator.RemoveFromUseList();
|
|
|
|
Iterator.AddToExistingUseListAfter(Entry);
|
|
|
|
assert(Entry->Next == &Iterator && "Loop invariant broken.");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-10-13 01:43:32 +08:00
|
|
|
switch (Entry->getKind()) {
|
2009-04-01 06:11:05 +08:00
|
|
|
case Assert:
|
2009-10-13 01:43:32 +08:00
|
|
|
break;
|
2017-05-02 01:07:54 +08:00
|
|
|
case Weak:
|
2017-05-02 01:07:49 +08:00
|
|
|
case WeakTracking:
|
2017-05-02 01:07:54 +08:00
|
|
|
// WeakTracking and Weak just go to null, which unlinks them
|
|
|
|
// from the list.
|
2014-04-09 14:08:46 +08:00
|
|
|
Entry->operator=(nullptr);
|
2009-04-01 06:11:05 +08:00
|
|
|
break;
|
|
|
|
case Callback:
|
2009-05-03 05:10:48 +08:00
|
|
|
// Forward to the subclass's implementation.
|
2009-10-13 01:43:32 +08:00
|
|
|
static_cast<CallbackVH*>(Entry)->deleted();
|
2009-05-03 05:10:48 +08:00
|
|
|
break;
|
2009-04-01 06:11:05 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-10-13 01:43:32 +08:00
|
|
|
// All callbacks, weak references, and assertingVHs should be dropped by now.
|
|
|
|
if (V->HasValueHandle) {
|
|
|
|
#ifndef NDEBUG // Only in +Asserts mode...
|
2011-11-16 00:27:03 +08:00
|
|
|
dbgs() << "While deleting: " << *V->getType() << " %" << V->getName()
|
2009-10-13 01:43:32 +08:00
|
|
|
<< "\n";
|
|
|
|
if (pImpl->ValueHandles[V]->getKind() == Assert)
|
|
|
|
llvm_unreachable("An asserting value handle still pointed to this"
|
|
|
|
" value!");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
llvm_unreachable("All references to V were not removed?");
|
|
|
|
}
|
2009-04-01 06:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ValueHandleBase::ValueIsRAUWd(Value *Old, Value *New) {
|
|
|
|
assert(Old->HasValueHandle &&"Should only be called if ValueHandles present");
|
|
|
|
assert(Old != New && "Changing value into itself!");
|
2014-10-23 12:08:42 +08:00
|
|
|
assert(Old->getType() == New->getType() &&
|
|
|
|
"replaceAllUses of value with new value of different type!");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
// Get the linked list base, which is guaranteed to exist since the
|
|
|
|
// HasValueHandle flag is set.
|
2009-08-19 02:28:58 +08:00
|
|
|
LLVMContextImpl *pImpl = Old->getContext().pImpl;
|
|
|
|
ValueHandleBase *Entry = pImpl->ValueHandles[Old];
|
|
|
|
|
2009-04-01 06:11:05 +08:00
|
|
|
assert(Entry && "Value bit set but no entries exist");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-10-13 01:43:32 +08:00
|
|
|
// We use a local ValueHandleBase as an iterator so that
|
|
|
|
// ValueHandles can add and remove themselves from the list without
|
|
|
|
// breaking our iteration. This is not really an AssertingVH; we
|
|
|
|
// just have to give ValueHandleBase some kind.
|
|
|
|
for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
|
|
|
|
Iterator.RemoveFromUseList();
|
|
|
|
Iterator.AddToExistingUseListAfter(Entry);
|
|
|
|
assert(Entry->Next == &Iterator && "Loop invariant broken.");
|
2009-09-20 12:03:34 +08:00
|
|
|
|
2009-10-13 01:43:32 +08:00
|
|
|
switch (Entry->getKind()) {
|
2009-04-01 06:11:05 +08:00
|
|
|
case Assert:
|
2017-05-02 01:07:54 +08:00
|
|
|
case Weak:
|
|
|
|
// Asserting and Weak handles do not follow RAUW implicitly.
|
2009-04-01 06:11:05 +08:00
|
|
|
break;
|
2017-05-02 01:07:49 +08:00
|
|
|
case WeakTracking:
|
2017-04-27 00:37:05 +08:00
|
|
|
// Weak goes to the new value, which will unlink it from Old's list.
|
2009-10-13 01:43:32 +08:00
|
|
|
Entry->operator=(New);
|
2009-04-01 06:11:05 +08:00
|
|
|
break;
|
|
|
|
case Callback:
|
2009-05-03 05:10:48 +08:00
|
|
|
// Forward to the subclass's implementation.
|
2009-10-13 01:43:32 +08:00
|
|
|
static_cast<CallbackVH*>(Entry)->allUsesReplacedWith(New);
|
2009-05-03 05:10:48 +08:00
|
|
|
break;
|
2009-04-01 06:11:05 +08:00
|
|
|
}
|
|
|
|
}
|
2010-07-27 14:53:14 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2017-05-02 00:28:58 +08:00
|
|
|
// If any new weak value handles were added while processing the
|
2010-07-27 14:53:14 +08:00
|
|
|
// list, then complain about it now.
|
|
|
|
if (Old->HasValueHandle)
|
|
|
|
for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
|
|
|
|
switch (Entry->getKind()) {
|
2017-05-02 01:07:49 +08:00
|
|
|
case WeakTracking:
|
2010-07-27 14:53:14 +08:00
|
|
|
dbgs() << "After RAUW from " << *Old->getType() << " %"
|
2011-11-16 00:27:03 +08:00
|
|
|
<< Old->getName() << " to " << *New->getType() << " %"
|
|
|
|
<< New->getName() << "\n";
|
2017-05-02 00:28:58 +08:00
|
|
|
llvm_unreachable(
|
2019-01-30 08:28:56 +08:00
|
|
|
"A weak tracking value handle still pointed to the old value!\n");
|
2010-07-27 14:53:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-01 06:11:05 +08:00
|
|
|
}
|
|
|
|
|
2013-11-19 08:57:56 +08:00
|
|
|
// Pin the vtable to this file.
|
|
|
|
void CallbackVH::anchor() {}
|