summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Metadata.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* IR: Add test for handleChangedOperand() recursionDuncan P. N. Exon Smith2015-01-121-2/+0
| | | | | | | Turns out this can happen. Remove the `FIXME` and add a testcase that crashes without the extra logic. llvm-svn: 225657
* IR: Separate out recalculateHash(), NFCDuncan P. N. Exon Smith2015-01-121-11/+13
| | | | llvm-svn: 225655
* IR: Separate out helper: resolveAfterOperandChange(), NFCDuncan P. N. Exon Smith2015-01-121-15/+18
| | | | llvm-svn: 225654
* IR: Use SubclassData32 directly, NFCDuncan P. N. Exon Smith2015-01-121-8/+11
| | | | | | | Simplify some logic by accessing `SubclassData32` directly instead of relying on API. llvm-svn: 225653
* IR: Don't allow operands to become unresolvedDuncan P. N. Exon Smith2015-01-121-6/+10
| | | | | | | Operands shouldn't change from being resolved to unresolved during graph construction. Simplify the logic based on that assumption. llvm-svn: 225649
* IR: Remove redundant comment, NFCDuncan P. N. Exon Smith2015-01-121-1/+0
| | | | llvm-svn: 225648
* IR: Simplify code, NFCDuncan P. N. Exon Smith2015-01-121-1/+1
| | | | llvm-svn: 225647
* IR: Simplify replaceOperandWith(), NFCDuncan P. N. Exon Smith2015-01-121-4/+3
| | | | | | | | This will call `handleChangedOperand()` less frequently, but in that case (i.e., `isStoredDistinctInContext()`) it has identical logic to here. llvm-svn: 225643
* IR: Remove redundant calls to MDNode::setHash(), NFCDuncan P. N. Exon Smith2015-01-121-2/+0
| | | | | | `storeDistinctInContext()` already calls `setHash(0)`. llvm-svn: 225642
* IR: Add MDNode::getDistinct()Duncan P. N. Exon Smith2015-01-071-2/+12
| | | | | | | | | | Allow distinct `MDNode`s to be explicitly created. There's no way (yet) of representing their distinctness in assembly/bitcode, however, so this still isn't first-class. Part of PR22111. llvm-svn: 225406
* Linker: Don't use MDNode::replaceOperandWith()Duncan P. N. Exon Smith2015-01-071-0/+5
| | | | | | | | | | | `MDNode::replaceOperandWith()` changes all instances of metadata. Stop using it when linking module flags, since (due to uniquing) the flag values could be used by other metadata. Instead, use new API `NamedMDNode::setOperand()` to update the reference directly. llvm-svn: 225397
* IR: Don't drop MDNode uniquing on null operandsDuncan P. N. Exon Smith2015-01-051-7/+2
| | | | | | | | | | Now that `LLVMContextImpl` can call `MDNode::dropAllReferences()` to prevent teardown madness, stop dropping uniquing just because an operand drops to null. Part of PR21532. llvm-svn: 225223
* IR: Prune arguments to ValueAsMetadata::ValueAsMetadata()Duncan P. N. Exon Smith2015-01-051-2/+2
| | | | | | `LLVMContext` isn't actually used. llvm-svn: 225200
* The leak detector is dead, long live asan and valgrind.Rafael Espindola2014-12-221-3/+0
| | | | | | | In resent times asan and valgrind have found way more memory management bugs in llvm than the special purpose leak detector. llvm-svn: 224703
* Delete debugging cruft that crept in with r223802.Nick Lewycky2014-12-171-3/+0
| | | | llvm-svn: 224407
* IR: Don't track nullptr on metadata RAUWDuncan P. N. Exon Smith2014-12-121-1/+2
| | | | | | | | | | | | | | | | | The RAUW support in `Metadata` supports going to `nullptr` specifically to handle values being deleted, causing `ValueAsMetadata` to be deleted. Fix the case where the reference is from a `TrackingMDRef` (as opposed to an `MDOperand` or a `MetadataAsValue`). This is surprisingly rare -- metadata tracked by `TrackingMDRef` going to null -- but it came up in an openSUSE bootstrap during inlining. The tracking ref was held by the `ValueMap` because it was referencing a local, the basic block containing the local became dead after it had been merged in, and when the local was deleted, the tracking ref asserted in an `isa`. llvm-svn: 224146
* IR: Move call to dropAllReferences() to MDNode subclassesDuncan P. N. Exon Smith2014-12-101-0/+1
| | | | | | | Don't call `dropAllReferences()` from `MDNode::~MDNode()`, call it directly from `~MDNodeFwdDecl()` and `~GenericMDNode()`. llvm-svn: 223904
* IR: Fix memory corruption in MDNode new/deleteDuncan P. N. Exon Smith2014-12-091-4/+8
| | | | | | | | | | | | | | | There were two major problems with `MDNode` memory management. 1. `MDNode::operator new()` called a placement array constructor for `MDOperand`. What? Each operand needs to be placed individually. 2. `MDNode::operator delete()` failed to destruct the `MDOperand`s at all. Frankly it's hard to understand how this worked locally, how this survived an LTO bootstrap, or how it worked on most of the bots. llvm-svn: 223858
* IR: Metadata: Detect an RAUW recursionDuncan P. N. Exon Smith2014-12-091-0/+9
| | | | | | | | | | Speculatively handle a recursion in `GenericMDNode::handleChangedOperand()`. I'm hoping this fixes the failing hexagon bot [1]. [1]: http://lab.llvm.org:8011/builders/llvm-hexagon-elf/builds/13434 llvm-svn: 223849
* IR: Metadata/Value split: RAUW in a deterministic orderDuncan P. N. Exon Smith2014-12-091-21/+38
| | | | | | | | | | | RAUW in a deterministic order to try to recover the hexagon bot [1], whose tests started failing once my GCC fixes were in for r223802. Otherwise, I'm not sure why tests would fail there and not here. [1]: http://lab.llvm.org:8011/builders/llvm-hexagon-elf/builds/13426 llvm-svn: 223829
* Fix a GCC build failure from r223802Duncan P. N. Exon Smith2014-12-091-1/+2
| | | | llvm-svn: 223806
* IR: Split Metadata from ValueDuncan P. N. Exon Smith2014-12-091-313/+550
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* IR: Revert r223618 behaviour of MDNode::concatenate()Duncan P. N. Exon Smith2014-12-071-12/+23
| | | | | | | | | | | | | r223618 including special handling of `MDNode::intersect()`: if the first operand is a self-reference with the same operands you're trying to return, return it instead. Reuse that handling in `MDNode::concatenate()` in the hopes that it fixes a polly test that seems to rely on the old behaviour [1]. [1]: http://lab.llvm.org:8011/builders/polly-amd64-linux/builds/25167 llvm-svn: 223619
* IR: Drop uniquing for self-referencing MDNodesDuncan P. N. Exon Smith2014-12-071-1/+15
| | | | | | | | | | | | | | | It doesn't make sense to unique self-referencing nodes. Drop uniquing for them. Note that `MDNode::intersect()` occasionally returns self-referencing nodes. Previously these would be returned by `MDNode::get()`. I'm not convinced this was intended behaviour -- to me it seems it should return a node whose only operand is the self-reference -- but I don't know much about alias scopes so I'm preserving it for now. This is part of PR21532. llvm-svn: 223618
* IR: Disallow function-local metadata attachmentsDuncan P. N. Exon Smith2014-12-061-0/+2
| | | | | | | | Metadata attachments to instructions cannot be function-local. This is part of PR21532. llvm-svn: 223574
* IR: Disallow complicated function-local metadataDuncan P. N. Exon Smith2014-12-061-48/+27
| | | | | | | | | | Disallow complex types of function-local metadata. The only valid function-local metadata is an `MDNode` whose sole argument is a non-metadata function-local value. Part of PR21532. llvm-svn: 223564
* IR: Stop relying on GetStringMapEntryFromValue()Duncan P. N. Exon Smith2014-12-051-1/+3
| | | | | | It relies on undefined behaviour. llvm-svn: 223438
* IR: Sink MDNode::Hash down to GenericMDNode::HashDuncan P. N. Exon Smith2014-11-181-1/+1
| | | | | | Part of PR21532. llvm-svn: 222212
* IR: Move MDNode operands from the back to the frontDuncan P. N. Exon Smith2014-11-181-56/+41
| | | | | | | | | | | | | | | | | Having the operands at the back prevents subclasses from safely adding fields. Move them to the front. Instead of replicating the custom `malloc()`, `free()` and `DestroyFlag` logic that was there before, overload `new` and `delete`. I added calls to a new `GenericMDNode::dropAllReferences()` in `LLVMContextImpl::~LLVMContextImpl()`. There's a maze of callbacks happening during teardown, and this resolves them before we enter the destructors. Part of PR21532. llvm-svn: 222211
* IR: Split MDNode into GenericMDNode and MDNodeFwdDeclDuncan P. N. Exon Smith2014-11-181-26/+41
| | | | | | | | | | | | | | | | | | | Split `MDNode` into two classes: - `GenericMDNode`, which is uniquable (and for now, always starts uniqued). Once `Metadata` is split from the `Value` hierarchy, this class will lose the ability to RAUW itself. - `MDNodeFwdDecl`, which is used for the "temporary" interface, is never uniqued, and isn't managed by `LLVMContext` at all. I've left most of the guts in `MDNode` for now, but I'll incrementally move things to the right places (or delete the functionality, as appropriate). Part of PR21532. llvm-svn: 222205
* IR: Simplify uniquing for MDNodeDuncan P. N. Exon Smith2014-11-171-54/+35
| | | | | | | | | | | | | | | | | | Change uniquing from a `FoldingSet` to a `DenseSet` with custom `DenseMapInfo`. Unfortunately, this doesn't save any memory, since `DenseSet<T>` is a simple wrapper for `DenseMap<T, char>`, but I'll come back to fix that later. I used the name `GenericDenseMapInfo` to the custom `DenseMapInfo` since I'll be splitting `MDNode` into two classes soon: `MDNodeFwdDecl` for temporaries, and `GenericMDNode` for everything else. I also added a non-debug-info reduced version of a type-uniquing test that started failing on an earlier draft of this patch. Part of PR21532. llvm-svn: 222191
* IR: Make MDString inherit from MetadataDuncan P. N. Exon Smith2014-11-141-3/+0
| | | | llvm-svn: 222022
* IR: Take an LLVMContext in Metadata::Metadata()Duncan P. N. Exon Smith2014-11-141-1/+4
| | | | llvm-svn: 222019
* Add a blank line, NFCDuncan P. N. Exon Smith2014-11-141-0/+1
| | | | llvm-svn: 222018
* IR: Rewrite uniquing and creation of MDStringDuncan P. N. Exon Smith2014-11-141-7/+15
| | | | | | | | | | Stop using `Value::getName()` to get the string behind an `MDString`. Switch to `StringMapEntry<MDString>` so that we can find the string by its coallocation. This is part of PR21532. llvm-svn: 221960
* IR: Create the Metadata classDuncan P. N. Exon Smith2014-11-131-2/+2
| | | | | | | | | This will become the root of a new class hierarchy separate from `Value`. As a first step, stick it between `Value` and `MDNode`. This is part of PR21532. llvm-svn: 221886
* Revert "IR: MDNode => Value"Duncan P. N. Exon Smith2014-11-111-28/+18
| | | | | | | | | | | | | | | | | Instead, we're going to separate metadata from the Value hierarchy. See PR21532. This reverts commit r221375. This reverts commit r221373. This reverts commit r221359. This reverts commit r221167. This reverts commit r221027. This reverts commit r221024. This reverts commit r221023. This reverts commit r220995. This reverts commit r220994. llvm-svn: 221711
* IR: MDNode => Value: NamedMDNode::getOperator()Duncan P. N. Exon Smith2014-11-051-7/+6
| | | | | | | | | | | | | Change `NamedMDNode::getOperator()` from returning `MDNode *` to returning `Value *`. To reduce boilerplate at some call sites, add a `getOperatorAsMDNode()` for named metadata that's expected to only return `MDNode` -- for now, that's everything, but debug node named metadata (such as llvm.dbg.cu and llvm.dbg.sp) will soon change. This is part of PR21433. Note that there's a follow-up patch to clang for the API change. llvm-svn: 221375
* IR: MDNode => Value: NamedMDNode::addOperand()Duncan P. N. Exon Smith2014-11-051-1/+2
| | | | | | | Change `NamedMDNode::addOperand()` to take a `Value *` instead of an `MDNode *`. This is part of PR21433. llvm-svn: 221359
* IR: Metadata: Remove unnecessary dyn_castDuncan P. N. Exon Smith2014-11-051-1/+1
| | | | llvm-svn: 221328
* IR: MDNode => Value: Instruction::getAllMetadataOtherThanDebugLoc()Duncan P. N. Exon Smith2014-11-031-3/+2
| | | | | | | Change `Instruction::getAllMetadataOtherThanDebugLoc()` from a vector of `MDNode` to one of `Value`. Part of PR21433. llvm-svn: 221167
* IR: MDNode => Value: Instruction::getAllMetadata()Duncan P. N. Exon Smith2014-11-011-2/+2
| | | | | | | Change `Instruction::getAllMetadata()` to modify a vector of `Value` instead of `MDNode` and update call sites. This is part of PR21433. llvm-svn: 221027
* IR: MDNode => Value: Instruction::getMetadata()Duncan P. N. Exon Smith2014-11-011-4/+4
| | | | | | | | | | Change `Instruction::getMetadata()` to return `Value` as part of PR21433. Update most callers to use `Instruction::getMDNode()`, which wraps the result in a `cast_or_null<MDNode>`. llvm-svn: 221024
* IR: MDNode => Value: Add Instruction::getMDNode()Duncan P. N. Exon Smith2014-10-311-0/+8
| | | | | | | | | | Add `Instruction::getMDNode()` that casts to `MDNode` before changing `Instruction::getMetadata()` to return `Value`. This avoids adding `cast_or_null<MDNode>` boiler-plate throughout the code. Part of PR21433. llvm-svn: 221023
* IR: Instruction::setMetadata() should use cast_or_nullDuncan P. N. Exon Smith2014-10-311-1/+1
| | | | | | | | | Not sure why this assertion didn't fire locally [1], but in r220994 `Instruction::setMetadata()` should be using `cast_or_null`. [1]: http://lab.llvm.org:8011/builders/llvm-hexagon-elf/builds/12327 llvm-svn: 220995
* IR: MDNode => Value: Instruction::setMetadata()Duncan P. N. Exon Smith2014-10-311-6/+9
| | | | | | | Change `Instruction::setMetadata()` API to accept `Value` instead of `MDNode`. Part of PR21433. llvm-svn: 220994
* IR: Cleanup comments for Value, User, and MDNodeDuncan P. N. Exon Smith2014-10-151-14/+4
| | | | | | | | | | | | | A follow-up commit will modify the memory-layout of `Value`, `User`, and `MDNode`. First fix the comments to be doxygen-friendly (and to follow the coding standards). - Use "\brief" instead of "repeatedName -". - Add a brief intro where it was missing. - Remove duplicated comments from source files (and a couple of noisy/trivial comments altogether). llvm-svn: 219844
* Add scoped-noalias metadataHal Finkel2014-07-241-0/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds scoped noalias metadata. The primary motivations for this feature are: 1. To preserve noalias function attribute information when inlining 2. To provide the ability to model block-scope C99 restrict pointers Neither of these two abilities are added here, only the necessary infrastructure. In fact, there should be no change to existing functionality, only the addition of new features. The logic that converts noalias function parameters into this metadata during inlining will come in a follow-up commit. What is added here is the ability to generally specify noalias memory-access sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA nodes: !scope0 = metadata !{ metadata !"scope of foo()" } !scope1 = metadata !{ metadata !"scope 1", metadata !scope0 } !scope2 = metadata !{ metadata !"scope 2", metadata !scope0 } !scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 } !scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 } Loads and stores can be tagged with an alias-analysis scope, and also, with a noalias tag for a specific scope: ... = load %ptr1, !alias.scope !{ !scope1 } ... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 } When evaluating an aliasing query, if one of the instructions is associated with an alias.scope id that is identical to the noalias scope associated with the other instruction, or is a descendant (in the scope hierarchy) of the noalias scope associated with the other instruction, then the two memory accesses are assumed not to alias. Note that is the first element of the scope metadata is a string, then it can be combined accross functions and translation units. The string can be replaced by a self-reference to create globally unqiue scope identifiers. [Note: This overview is slightly stylized, since the metadata nodes really need to just be numbers (!0 instead of !scope0), and the scope lists are also global unnamed metadata.] Existing noalias metadata in a callee is "cloned" for use by the inlined code. This is necessary because the aliasing scopes are unique to each call site (because of possible control dependencies on the aliasing properties). For example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } -- now just because we know that a1 does not alias with b1 at the first call site, and a2 does not alias with b2 at the second call site, we cannot let inlining these functons have the metadata imply that a1 does not alias with b2. llvm-svn: 213864
* AA metadata refactoring (introduce AAMDNodes)Hal Finkel2014-07-241-0/+4
| | | | | | | | | | | | | | | | | | | | In order to enable the preservation of noalias function parameter information after inlining, and the representation of block-level __restrict__ pointer information (etc.), additional kinds of aliasing metadata will be introduced. This metadata needs to be carried around in AliasAnalysis::Location objects (and MMOs at the SDAG level), and so we need to generalize the current scheme (which is hard-coded to just one TBAA MDNode*). This commit introduces only the necessary refactoring to allow for the introduction of other aliasing metadata types, but does not actually introduce any (that will come in a follow-up commit). What it does introduce is a new AAMDNodes structure to hold all of the aliasing metadata nodes associated with a particular memory-accessing instruction, and uses that structure instead of the raw MDNode* in AliasAnalysis::Location, etc. No functionality change intended. llvm-svn: 213859
* The count() function for STL datatypes returns unsigned, even where it'sYaron Keren2014-06-201-1/+1
| | | | | | | | | | | | | | | | | only 1/0 result like std::set. Some of the LLVM ADT already return unsigned count(), while others still return bool count(). In continuation to r197879, this patch modifies DenseMap, DenseSet, ScopedHashTable, ValueMap:: count() to return size_type instead of bool, 1 instead of true and 0 instead of false. size_type is typedef-ed locally within each class to size_t. http://reviews.llvm.org/D4018 Reviewed by dblaikie. llvm-svn: 211350
OpenPOWER on IntegriCloud