1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
Commit Graph

98 Commits

Author SHA1 Message Date
Duncan P. N. Exon Smith
9c25a26692 IR: Extract MDNodeOpsKey, NFC
Make the MDTuple operand hashing logic reusable.

llvm-svn: 226519
2015-01-19 22:53:18 +00:00
Duncan P. N. Exon Smith
55777b83fd IR: Simplify uniquifyImpl(), NFC
llvm-svn: 226518
2015-01-19 22:52:07 +00:00
Duncan P. N. Exon Smith
a1b2f403fd IR: Simplify erasing from uniquing store, NFC
llvm-svn: 226517
2015-01-19 22:47:08 +00:00
Duncan P. N. Exon Smith
fef426ff75 IR: Allow temporary nodes to become uniqued or distinct
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
2015-01-19 22:24:52 +00:00
Duncan P. N. Exon Smith
844de4d931 IR: Split out countUnresolvedOperands(), NFC
llvm-svn: 226508
2015-01-19 22:18:29 +00:00
Duncan P. N. Exon Smith
0341a8121b IR: Remove MDNodeFwdDecl
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
2015-01-19 20:36:39 +00:00
Duncan P. N. Exon Smith
51357ceef8 IR: Extract out and reuse storeImpl(), NFC
llvm-svn: 226499
2015-01-19 20:18:13 +00:00
Duncan P. N. Exon Smith
d4b3654033 IR: Extract out getUniqued(), NFC
llvm-svn: 226498
2015-01-19 20:16:50 +00:00
Duncan P. N. Exon Smith
8b7ed86ca9 IR: Reuse getImpl() for getDistinct(), NFC
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
2015-01-19 20:14:15 +00:00
Duncan P. N. Exon Smith
cf9d31f7c4 IR: Simplify MDNode::setOperand(), NFC
llvm-svn: 226492
2015-01-19 19:29:25 +00:00
Duncan P. N. Exon Smith
8caa30d063 IR: Simplify handleChangedOperand() fast path, NFC
Use `isUniqued()` instead of `isStoredDistinctInContext()`, and remove
an assertion that won't be valid once temporaries are merged back in.

llvm-svn: 226491
2015-01-19 19:28:28 +00:00
Duncan P. N. Exon Smith
85d893bb11 IR: Remove direct comparisons against Metadata::Storage, NFC
llvm-svn: 226490
2015-01-19 19:26:24 +00:00
Duncan P. N. Exon Smith
fad6451545 IR: Assert that resolve() is only called on uniqued nodes, NFC
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
2015-01-19 19:25:33 +00:00
Duncan P. N. Exon Smith
143b7fce41 IR: Unify code for MDNode::isResolved(), NFC
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
2015-01-19 19:03:18 +00:00
Duncan P. N. Exon Smith
6da60093ee IR: Store RAUW support and Context in the same pointer, NFC
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
2015-01-19 19:02:06 +00:00
Duncan P. N. Exon Smith
671d652451 IR: Add isUniqued() and isTemporary()
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
2015-01-19 18:45:35 +00:00
Duncan P. N. Exon Smith
f397523f7d IR: Use an enum to describe Metadata storage, NFC
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
2015-01-19 18:36:18 +00:00
Duncan P. N. Exon Smith
97ed3e1e77 IR: Allow 16-bits for column info
Raise the limit for column information from 8 bits to 16 bits.

llvm-svn: 226291
2015-01-16 17:33:08 +00:00
Duncan P. N. Exon Smith
a8c04b6e0d IR: Fix a use-after-free in RAUW
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
2015-01-14 19:56:10 +00:00
Duncan P. N. Exon Smith
fee021d6c8 IR: Add MDLocation class
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
2015-01-13 20:44:56 +00:00
Duncan P. N. Exon Smith
c12048a55f IR: Remove an invalid assertion when replacing resolved operands
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
2015-01-13 00:46:34 +00:00
Duncan P. N. Exon Smith
197d61fb5f Revert "IR: Fix an inverted assertion when replacing resolved operands"
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
2015-01-13 00:34:21 +00:00
Duncan P. N. Exon Smith
a9129de19b IR: Fix an inverted assertion when replacing resolved operands
Add a unit test, since this bug was only exposed by clang tests.  Thanks
to Rafael for tracking this down!

llvm-svn: 225738
2015-01-13 00:10:38 +00:00
Duncan P. N. Exon Smith
22b541e541 IR: Prepare for a new UniquableMDNode subclass, NFC
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
2015-01-12 20:56:33 +00:00
Duncan P. N. Exon Smith
33f15baf62 IR: Stop erasing MDNodes from uniquing sets during teardown
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
2015-01-12 20:50:25 +00:00
Duncan P. N. Exon Smith
6cabe54de4 IR: Move creation logic to MDNodeFwdDecl, NFC
Same as with `MDTuple`, factor out a `friend MDNode` by moving creation
logic to the concrete subclass.

llvm-svn: 225690
2015-01-12 20:21:37 +00:00
Duncan P. N. Exon Smith
93902afff5 IR: Move creation logic down to MDTuple, NFC
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
2015-01-12 20:13:56 +00:00
Duncan P. N. Exon Smith
4ae78760c7 IR: Push storeDistinctInContext() down to UniquableMDNode, NFC
llvm-svn: 225683
2015-01-12 20:11:32 +00:00
Duncan P. N. Exon Smith
948aeade46 IR: Split GenericMDNode into MDTuple and UniquableMDNode
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
2015-01-12 20:09:34 +00:00
Duncan P. N. Exon Smith
e4cbad4421 IR: Invert logic to simplify control flow, NFC
llvm-svn: 225670
2015-01-12 19:45:44 +00:00
Duncan P. N. Exon Smith
b2ead3ec04 IR: Separate out decrementUnresolvedOperandCount(), NFC
llvm-svn: 225667
2015-01-12 19:43:15 +00:00
Duncan P. N. Exon Smith
1067d90f30 IR: Prevent handleChangedOperand() recursion
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
2015-01-12 19:36:35 +00:00
Duncan P. N. Exon Smith
d9bc3cb9c5 IR: Add test for handleChangedOperand() recursion
Turns out this can happen.  Remove the `FIXME` and add a testcase that
crashes without the extra logic.

llvm-svn: 225657
2015-01-12 19:22:04 +00:00
Duncan P. N. Exon Smith
73c51fa515 IR: Separate out recalculateHash(), NFC
llvm-svn: 225655
2015-01-12 19:16:34 +00:00
Duncan P. N. Exon Smith
566445f0e7 IR: Separate out helper: resolveAfterOperandChange(), NFC
llvm-svn: 225654
2015-01-12 19:14:15 +00:00
Duncan P. N. Exon Smith
7fbc7db604 IR: Use SubclassData32 directly, NFC
Simplify some logic by accessing `SubclassData32` directly instead of
relying on API.

llvm-svn: 225653
2015-01-12 19:12:37 +00:00
Duncan P. N. Exon Smith
e3010fd366 IR: Don't allow operands to become unresolved
Operands shouldn't change from being resolved to unresolved during graph
construction.  Simplify the logic based on that assumption.

llvm-svn: 225649
2015-01-12 18:59:40 +00:00
Duncan P. N. Exon Smith
10b54f125d IR: Remove redundant comment, NFC
llvm-svn: 225648
2015-01-12 18:45:32 +00:00
Duncan P. N. Exon Smith
7823c1b88a IR: Simplify code, NFC
llvm-svn: 225647
2015-01-12 18:45:01 +00:00
Duncan P. N. Exon Smith
f3e79c1049 IR: Simplify replaceOperandWith(), NFC
This will call `handleChangedOperand()` less frequently, but in that
case (i.e., `isStoredDistinctInContext()`) it has identical logic to
here.

llvm-svn: 225643
2015-01-12 18:01:45 +00:00
Duncan P. N. Exon Smith
5ea0131db5 IR: Remove redundant calls to MDNode::setHash(), NFC
`storeDistinctInContext()` already calls `setHash(0)`.

llvm-svn: 225642
2015-01-12 17:57:38 +00:00
Duncan P. N. Exon Smith
72fe04b84c IR: Add MDNode::getDistinct()
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
2015-01-07 22:24:46 +00:00
Duncan P. N. Exon Smith
0d2cbb7da2 Linker: Don't use MDNode::replaceOperandWith()
`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
2015-01-07 21:32:27 +00:00
Duncan P. N. Exon Smith
40b944ca0c IR: Don't drop MDNode uniquing on null operands
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
2015-01-05 23:31:54 +00:00
Duncan P. N. Exon Smith
6bcaa2e7bc IR: Prune arguments to ValueAsMetadata::ValueAsMetadata()
`LLVMContext` isn't actually used.

llvm-svn: 225200
2015-01-05 20:41:25 +00:00
Rafael Espindola
dbf446fea1 The leak detector is dead, long live asan and valgrind.
In resent times asan and valgrind have found way more memory management bugs
in llvm than the special purpose leak detector.

llvm-svn: 224703
2014-12-22 13:00:36 +00:00
Nick Lewycky
f60b003316 Delete debugging cruft that crept in with r223802.
llvm-svn: 224407
2014-12-17 01:56:51 +00:00
Duncan P. N. Exon Smith
77f50da5c2 IR: Don't track nullptr on metadata RAUW
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
2014-12-12 19:24:33 +00:00
Duncan P. N. Exon Smith
2fceb99340 IR: Move call to dropAllReferences() to MDNode subclasses
Don't call `dropAllReferences()` from `MDNode::~MDNode()`, call it
directly from `~MDNodeFwdDecl()` and `~GenericMDNode()`.

llvm-svn: 223904
2014-12-10 01:45:04 +00:00
Duncan P. N. Exon Smith
c0e64c52d3 IR: Fix memory corruption in MDNode new/delete
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
2014-12-09 23:56:39 +00:00