summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Metadata.cpp
Commit message (Collapse)AuthorAgeFilesLines
* IR: Enable uniquing callbacks during MDNode::replaceWithUniqued()Duncan P. N. Exon Smith2015-03-311-0/+4
| | | | | | | | | | | | | | | | Uniqued nodes have more complete registration with `ReplaceableMetadataImpl` so that they can update themselves when operands change. Fix a bug where `MDNode::replaceWithUniqued()` wasn't enabling these callbacks. The two most obvious ways missing callbacks causes problems is that auto-resolution fails and re-uniquing (on changed operands) just doesn't happen. I've added tests for both -- in both cases, I confirmed that the final check was failing before the fix. rdar://problem/20365935 llvm-svn: 233751
* IR: Use the new DebugLoc API, NFCDuncan P. N. Exon Smith2015-03-301-2/+2
| | | | | | | | Update lib/IR and lib/Bitcode to use the new `DebugLoc` API. Added an explicit conversion to `bool` (avoiding a conversion to `MDLocation`), since a couple of these use cases need to handle broken code. llvm-svn: 233585
* IR: Add MDNode::replaceWithPermanent()Duncan P. N. Exon Smith2015-02-101-0/+16
| | | | | | | | | | | | | | | | Add new API for converting temporaries that may self-reference. Self-referencing nodes are not allowed to be uniqued, so sending them into `replaceWithUniqued()` is dangerous (and this commit adds assertions that prevent it). `replaceWithPermanent()` has similar semantics to `get()` followed by calls to `replaceOperandWith()`. In particular, if there's a self-reference, it returns a distinct node; otherwise, it returns a uniqued one. Like `replaceWithUniqued()` and `replaceWithDistinct()` (well, it calls out to them) it mutates the temporary node in place if possible, only calling `replaceAllUsesWith()` on a uniquing collision. llvm-svn: 228726
* Metadata: Use <algorithm> to simplify code. NFC.Benjamin Kramer2015-02-081-30/+12
| | | | llvm-svn: 228550
* Correctly combine alias.scope metadata by a union instead of intersectingBjorn Steinbrink2015-02-081-0/+22
| | | | | | | | | | | | | | | | | Summary: The alias.scope metadata represents sets of things an instruction might alias with. When generically combining the metadata from two instructions the result must be the union of the original sets, because the new instruction might alias with anything any of the original instructions aliased with. Reviewers: hfinkel Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D7490 llvm-svn: 228525
* IR: Split out DebugInfoMetadata.h, NFCDuncan P. N. Exon Smith2015-02-021-105/+2
| | | | | | | | | Move debug-info-centred `Metadata` subclasses into their own header/source file. A couple of private template functions are needed from both `Metadata.cpp` and `DebugInfoMetadata.cpp`, so I've moved them to `lib/IR/MetadataImpl.h`. llvm-svn: 227835
* Fix some file headers, NFCDuncan P. N. Exon Smith2015-02-021-1/+1
| | | | llvm-svn: 227826
* IR: Change GenericDwarfNode::getHeader() to StringRefDuncan P. N. Exon Smith2015-01-221-6/+4
| | | | | | | Simplify the API to use a `StringRef` directly rather than exposing the `MDString` bits underneath. llvm-svn: 226876
* IR: DwarfNode => DebugNode, NFCDuncan P. N. Exon Smith2015-01-221-7/+7
| | | | | | | | | These things are potentially used for non-DWARF data (see the discussion in PR22235), so take the `Dwarf` out of the name. Since the new name gives fewer clues, update the doxygen to properly describe what they are. llvm-svn: 226874
* IR: Update references to temporaries before deletingDuncan P. N. Exon Smith2015-01-221-0/+1
| | | | | | | | | | | | | | | | During `MDNode::deleteTemporary()`, call `replaceAllUsesWith(nullptr)` to update all tracking references to `nullptr`. This fixes PR22280, where inverted destruction order between tracking references and the temporaries themselves caused a use-after-free in `LLParser`. An alternative fix would be to add an assertion that there are no users, and continue to fix inverted destruction order in clients (like `LLParser`), but instead I decided to make getting-teardown-right easy. (If someone disagrees let me know.) llvm-svn: 226866
* IR: Move MDNode clone() methods from ValueMapper to MDNode, NFCDuncan P. N. Exon Smith2015-01-201-0/+11
| | | | | | | | Now that the clone methods used by `MapMetadata()` don't do any remapping (and return a temporary), they make more sense as member functions on `MDNode` (and subclasses). llvm-svn: 226541
* IR: Canonicalize GenericDwarfNode empty headers to nullDuncan P. N. Exon Smith2015-01-201-0/+4
| | | | llvm-svn: 226532
* IR: Detect whether to call recalculateHash() via SFINAE, NFCDuncan P. N. Exon Smith2015-01-201-18/+33
| | | | | | | | Rather than relying on updating switch statements correctly, detect whether `setHash()` exists in the subclass. If so, call `recalculateHash()` and `setHash(0)` appropriately. llvm-svn: 226531
* IR: Introduce GenericDwarfNodeDuncan P. N. Exon Smith2015-01-201-5/+40
| | | | | | | | | | | | As part of PR22235, introduce `DwarfNode` and `GenericDwarfNode`. The former is a metadata node with a DWARF tag. The latter matches our current (generic) schema of a header with string (and stringified integer) data and an arbitrary number of operands. This doesn't move it into place yet; that change will require a large number of testcase updates. llvm-svn: 226529
* IR: Cleanup MDNode field use, NFCDuncan P. N. Exon Smith2015-01-191-19/+14
| | | | | | | | | Swap usage of `SubclassData32` and `MDNodeSubclassData`, and rename `MDNodeSubclassData` to `NumUnresolved`. Small drive-by cleanup to `countUnresolvedOperands()` since otherwise the name clash with local vars named `NumUnresolved` would be confusing. llvm-svn: 226523
* IR: Move replaceWithUniqued(), etc., to source file, NFCDuncan P. N. Exon Smith2015-01-191-0/+19
| | | | llvm-svn: 226522
* IR: Cleanup MDNode::MDNode(), NFCDuncan P. N. Exon Smith2015-01-191-10/+9
| | | | llvm-svn: 226521
* IR: Merge UniquableMDNode back into MDNode, NFCDuncan P. N. Exon Smith2015-01-191-41/+36
| | | | | | | | | As pointed out in r226501, the distinction between `MDNode` and `UniquableMDNode` is confusing. When we need subclasses of `MDNode` that don't use all its functionality it might make sense to break it apart again, but until then this makes the code clearer. llvm-svn: 226520
* IR: Extract MDNodeOpsKey, NFCDuncan P. N. Exon Smith2015-01-191-27/+2
| | | | | | Make the MDTuple operand hashing logic reusable. llvm-svn: 226519
* IR: Simplify uniquifyImpl(), NFCDuncan P. N. Exon Smith2015-01-191-27/+27
| | | | llvm-svn: 226518
* IR: Simplify erasing from uniquing store, NFCDuncan P. N. Exon Smith2015-01-191-7/+1
| | | | llvm-svn: 226517
* IR: Allow temporary nodes to become uniqued or distinctDuncan P. N. Exon Smith2015-01-191-0/+27
| | | | | | | | | | | Add `MDNode::replaceWithUniqued()` and `MDNode::replaceWithDistinct()`, which mutate temporary nodes to become uniqued or distinct. On uniquing collisions, the unique version is returned and the node is deleted. This takes advantage of temporary nodes being folded back in, and should let me clean up some awkward logic in `MapMetadata()`. llvm-svn: 226510
* IR: Split out countUnresolvedOperands(), NFCDuncan P. N. Exon Smith2015-01-191-4/+8
| | | | llvm-svn: 226508
* IR: Remove MDNodeFwdDeclDuncan P. N. Exon Smith2015-01-191-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove `MDNodeFwdDecl` (as promised in r226481). Aside from API changes, there's no real functionality change here. `MDNode::getTemporary()` now forwards to `MDTuple::getTemporary()`, which returns a tuple with `isTemporary()` equal to true. The main point is that we can now add temporaries of other `MDNode` subclasses, needed for PR22235 (I introduced `MDNodeFwdDecl` in the first place because I didn't recognize this need, and thought they were only needed to handle forward references). A few things left out of (or highlighted by) this commit: - I've had to remove the (few) uses of `std::unique_ptr<>` to deal with temporaries, since the destructor is no longer public. `getTemporary()` should probably return the equivalent of `std::unique_ptr<T, MDNode::deleteTemporary>`. - `MDLocation::getTemporary()` doesn't exist yet (worse, it actually does exist, but does the wrong thing: `MDNode::getTemporary()` is inherited and returns an `MDTuple`). - `MDNode` now only has one subclass, `UniquableMDNode`, and the distinction between them is actually somewhat confusing. I'll fix those up next. llvm-svn: 226501
* IR: Extract out and reuse `storeImpl()`, NFCDuncan P. N. Exon Smith2015-01-191-28/+20
| | | | llvm-svn: 226499
* IR: Extract out getUniqued(), NFCDuncan P. N. Exon Smith2015-01-191-28/+24
| | | | llvm-svn: 226498
* IR: Reuse `getImpl()` for `getDistinct()`, NFCDuncan P. N. Exon Smith2015-01-191-48/+54
| | | | | | | | Merge `getDistinct()`'s implementation with those of `get()` and `getIfExists()` for both `MDTuple` and `MDLocation`. This will make it easier to scale to supporting temporaries. llvm-svn: 226497
* IR: Simplify MDNode::setOperand(), NFCDuncan P. N. Exon Smith2015-01-191-5/+1
| | | | llvm-svn: 226492
* IR: Simplify handleChangedOperand() fast path, NFCDuncan P. N. Exon Smith2015-01-191-3/+1
| | | | | | | Use `isUniqued()` instead of `isStoredDistinctInContext()`, and remove an assertion that won't be valid once temporaries are merged back in. llvm-svn: 226491
* IR: Remove direct comparisons against Metadata::Storage, NFCDuncan P. N. Exon Smith2015-01-191-3/+3
| | | | llvm-svn: 226490
* IR: Assert that resolve() is only called on uniqued nodes, NFCDuncan P. N. Exon Smith2015-01-191-1/+3
| | | | | | | | | Add an assertion in `UniquableMDNode::resolve()` to prevent temporaries from being resolved (once they're merged back in). Needed to shuffle order of `resolve()` and `storeDistinctInContext()` to prevent it from firing. llvm-svn: 226489
* IR: Unify code for MDNode::isResolved(), NFCDuncan P. N. Exon Smith2015-01-191-6/+0
| | | | | | | | | | Unify the definitions of `MDNode::isResolved()` and `UniquableMDNode::isResolved()`. Previously, `UniquableMDNode` could answer this question more efficiently, but now that RAUW support has been unified with `MDNodeFwdDecl`, `MDNode` doesn't need any casts to figure out the answer. llvm-svn: 226485
* IR: Store RAUW support and Context in the same pointer, NFCDuncan P. N. Exon Smith2015-01-191-5/+9
| | | | | | | | | | | | | | Add an `LLVMContext &` to `ReplaceableMetadataImpl`, create a class that either holds a reference to an `LLVMContext` or owns a `ReplaceableMetadataImpl`, and use the new class in `MDNode`. - This saves a pointer in `UniquableMDNode` at the cost of a pointer in `ValueAsMetadata` (which didn't used to store the `LLVMContext`). There are far more of the former. - Unifies RAUW support between `MDNodeFwdDecl` (which is going away, see r226481) and `UniquableMDNode`. llvm-svn: 226484
* IR: Add isUniqued() and isTemporary()Duncan P. N. Exon Smith2015-01-191-1/+1
| | | | | | | | Change `MDNode::isDistinct()` to only apply to 'distinct' nodes (not temporaries), and introduce `MDNode::isUniqued()` and `MDNode::isTemporary()` for the other two possibilities. llvm-svn: 226482
* IR: Use an enum to describe Metadata storage, NFCDuncan P. N. Exon Smith2015-01-191-19/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | More clearly describe the type of storage used for `Metadata`. - `Uniqued`: uniqued, stored in the context. - `Distinct`: distinct, stored in the context. - `Temporary`: not owned by anyone. This is the first in a series of commits to fix a design problem with `MDNodeFwdDecl` that I need to solve for PR22235. While `MDNodeFwdDecl` works well as a forward declaration, we use `MDNode::getTemporary()` for more than forward declarations -- we also need to create early versions of nodes (with fields not filled in) that we'll fill out later (see `DIBuilder::finalize()` and `CGDebugInfo::finalize()` for examples). This was a blind spot I had when I introduced `MDNodeFwdDecl` (which David Blaikie (indirectly) highlighted in an unrelated review [1]). [1]: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150112/252381.html In general, we need `MDTuple::getTemporary()` to give a temporary tuple (like `MDNodeFwdDecl`), `MDLocation::getTemporary()` to give a temporary location, and (the problem at hand) `GenericDebugMDNode::getTemporary()` to give a temporary generic debug node. So I need to fold the idea of "temporary" nodes back into `UniquableMDNode`. (More commits to follow as I refactor.) llvm-svn: 226481
* IR: Allow 16-bits for column infoDuncan P. N. Exon Smith2015-01-161-3/+3
| | | | | | Raise the limit for column information from 8 bits to 16 bits. llvm-svn: 226291
* IR: Fix a use-after-free in RAUWDuncan P. N. Exon Smith2015-01-141-0/+5
| | | | | | | | | | Happened pretty commonly during `LLVMContext` teardown when `clang -g` hit an error. This fixes the use-after-free. Next I'll clean up teardown so that it's not RAUW'ing when metadata-tracked values are deleted (only really causes a problem if the graph is mid-construction when teardown starts, but it's still unnecessary work). llvm-svn: 226029
* IR: Add MDLocation classDuncan P. N. Exon Smith2015-01-131-3/+90
| | | | | | | | | | | Add a new subclass of `UniquableMDNode`, `MDLocation`. This will be the IR version of `DebugLoc` and `DILocation`. The goal is to rename this to `DILocation` once the IR classes supersede the `DI`-prefixed wrappers. This isn't used anywhere yet. Part of PR21433. llvm-svn: 225824
* IR: Remove an invalid assertion when replacing resolved operandsDuncan P. N. Exon Smith2015-01-131-3/+5
| | | | | | | | | This adds back the testcase from r225738, and adds to it. Looks like we need both sides for now (the assertion was incorrect both ways, and although it seemed reasonable (when written correctly) it wasn't particularly important). llvm-svn: 225745
* Revert "IR: Fix an inverted assertion when replacing resolved operands"Duncan P. N. Exon Smith2015-01-131-1/+1
| | | | | | | | This reverts commit r225738. Maybe the assertion is just plain wrong, but this version fails on WAY more bots. I'll make sure both ways work in a follow-up but I want to get bots green in the meantime. llvm-svn: 225742
* IR: Fix an inverted assertion when replacing resolved operandsDuncan P. N. Exon Smith2015-01-131-1/+1
| | | | | | | Add a unit test, since this bug was only exposed by clang tests. Thanks to Rafael for tracking this down! llvm-svn: 225738
* IR: Prepare for a new UniquableMDNode subclass, NFCDuncan P. N. Exon Smith2015-01-121-11/+56
| | | | | | | | Add generic dispatch for the parts of `UniquableMDNode` that cast to `MDTuple`. This makes adding other subclasses (like PR21433's `MDLocation`) easier. llvm-svn: 225697
* IR: Stop erasing MDNodes from uniquing sets during teardownDuncan P. N. Exon Smith2015-01-121-12/+0
| | | | | | | | | | Stop erasing `MDNode`s from the uniquing sets in `LLVMContextImpl` during teardown (in particular, during `UniquableMDNode::~UniquableMDNode()`). Although it's currently feasible, there isn't any clear benefit and it may not be feasible for other subclasses (which don't explicitly store the lookup hash). llvm-svn: 225696
* IR: Move creation logic to MDNodeFwdDecl, NFCDuncan P. N. Exon Smith2015-01-121-6/+2
| | | | | | | Same as with `MDTuple`, factor out a `friend MDNode` by moving creation logic to the concrete subclass. llvm-svn: 225690
* IR: Move creation logic down to MDTuple, NFCDuncan P. N. Exon Smith2015-01-121-6/+6
| | | | | | | | | Move creation logic for `MDTuple`s down where it belongs. Once there are a few more subclasses, these functions really won't make much sense here (the `friend` relationship was already awkward). For now, leave the `MDNode` versions around, but have it forward down. llvm-svn: 225685
* IR: Push storeDistinctInContext() down to UniquableMDNode, NFCDuncan P. N. Exon Smith2015-01-121-1/+1
| | | | llvm-svn: 225683
* IR: Split GenericMDNode into MDTuple and UniquableMDNodeDuncan P. N. Exon Smith2015-01-121-36/+39
| | | | | | | | | | | | | | | | | | | | | | | | | Split `GenericMDNode` into two classes (with more descriptive names). - `UniquableMDNode` will be a common subclass for `MDNode`s that are sometimes uniqued like constants, and sometimes 'distinct'. This class gets the (short-lived) RAUW support and related API. - `MDTuple` is the basic tuple that has always been returned by `MDNode::get()`. This is as opposed to more specific nodes to be added soon, which have additional fields, custom assembly syntax, and extra semantics. This class gets the hash-related logic, since other sublcasses of `UniquableMDNode` may need to hash based on other fields. To keep this diff from getting too big, I've added casts to `MDTuple` that won't really scale as new subclasses of `UniquableMDNode` are added, but I'll clean those up incrementally. (No functionality change intended.) llvm-svn: 225682
* IR: Invert logic to simplify control flow, NFCDuncan P. N. Exon Smith2015-01-121-8/+5
| | | | llvm-svn: 225670
* IR: Separate out decrementUnresolvedOperandCount(), NFCDuncan P. N. Exon Smith2015-01-121-6/+8
| | | | llvm-svn: 225667
* IR: Prevent handleChangedOperand() recursionDuncan P. N. Exon Smith2015-01-121-8/+6
| | | | | | | | | | | Instead of returning early on `handleChangedOperand()` recursion (finally identified (and test added) in r225657), prevent it upfront by releasing operands before RAUW. Aside from massively different program flow, there should be no functionality change ;). llvm-svn: 225665
OpenPOWER on IntegriCloud