Commit Graph

2617 Commits

Author SHA1 Message Date
Lang Hames
fd6bad6c38 [ORC] Fix typo in LogicalDylib, add unit test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279892 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-27 00:19:05 +00:00
Tim Northover
b04cf870a6 GlobalISel: legalize sdiv and srem operations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279842 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26 17:46:13 +00:00
David Blaikie
dffc922b38 Fix ArrayRef initializer_list Ctor Test
The InitializerList test had undefined behavior by creating a dangling pointer to the temporary initializer list.  This patch removes the undefined behavior in the test by creating the initializer list directly.

Reviewers: mehdi_amini, dblaikie

Differential Revision: https://reviews.llvm.org/D23890

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279783 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-25 22:09:13 +00:00
David Blaikie
bf471b7adc DebugInfo: Add flag to CU to disable emission of inline debug info into the skeleton CU
In cases where .dwo/.dwp files are guaranteed to be available, skipping
the extra online (in the .o file) inline info can save a substantial
amount of space - see the original r221306 for more details there.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279650 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24 18:29:49 +00:00
Chandler Carruth
377af8df2b [PM] Introduce basic update capabilities to the new PM's CGSCC pass
manager, including both plumbing and logic to handle function pass
updates.

There are three fundamentally tied changes here:
1) Plumbing *some* mechanism for updating the CGSCC pass manager as the
   CG changes while passes are running.
2) Changing the CGSCC pass manager infrastructure to have support for
   the underlying graph to mutate mid-pass run.
3) Actually updating the CG after function passes run.

I can separate them if necessary, but I think its really useful to have
them together as the needs of #3 drove #2, and that in turn drove #1.

The plumbing technique is to extend the "run" method signature with
extra arguments. We provide the call graph that intrinsically is
available as it is the basis of the pass manager's IR units, and an
output parameter that records the results of updating the call graph
during an SCC passes's run. Note that "...UpdateResult" isn't a *great*
name here... suggestions very welcome.

I tried a pretty frustrating number of different data structures and such
for the innards of the update result. Every other one failed for one
reason or another. Sometimes I just couldn't keep the layers of
complexity right in my head. The thing that really worked was to just
directly provide access to the underlying structures used to walk the
call graph so that their updates could be informed by the *particular*
nature of the change to the graph.

The technique for how to make the pass management infrastructure cope
with mutating graphs was also something that took a really, really large
number of iterations to get to a place where I was happy. Here are some
of the considerations that drove the design:

- We operate at three levels within the infrastructure: RefSCC, SCC, and
  Node. In each case, we are working bottom up and so we want to
  continue to iterate on the "lowest" node as the graph changes. Look at
  how we iterate over nodes in an SCC running function passes as those
  function passes mutate the CG. We continue to iterate on the "lowest"
  SCC, which is the one that continues to contain the function just
  processed.

- The call graph structure re-uses SCCs (and RefSCCs) during mutation
  events for the *highest* entry in the resulting new subgraph, not the
  lowest. This means that it is necessary to continually update the
  current SCC or RefSCC as it shifts. This is really surprising and
  subtle, and took a long time for me to work out. I actually tried
  changing the call graph to provide the opposite behavior, and it
  breaks *EVERYTHING*. The graph update algorithms are really deeply
  tied to this particualr pattern.

- When SCCs or RefSCCs are split apart and refined and we continually
  re-pin our processing to the bottom one in the subgraph, we need to
  enqueue the newly formed SCCs and RefSCCs for subsequent processing.
  Queuing them presents a few challenges:
  1) SCCs and RefSCCs use wildly different iteration strategies at
     a high level. We end up needing to converge them on worklist
     approaches that can be extended in order to be able to handle the
     mutations.
  2) The order of the enqueuing need to remain bottom-up post-order so
     that we don't get surprising order of visitation for things like
     the inliner.
  3) We need the worklists to have set semantics so we don't duplicate
     things endlessly. We don't need a *persistent* set though because
     we always keep processing the bottom node!!!! This is super, super
     surprising to me and took a long time to convince myself this is
     correct, but I'm pretty sure it is... Once we sink down to the
     bottom node, we can't re-split out the same node in any way, and
     the postorder of the current queue is fixed and unchanging.
  4) We need to make sure that the "current" SCC or RefSCC actually gets
     enqueued here such that we re-visit it because we continue
     processing a *new*, *bottom* SCC/RefSCC.

- We also need the ability to *skip* SCCs and RefSCCs that get merged
  into a larger component. We even need the ability to skip *nodes* from
  an SCC that are no longer part of that SCC.

This led to the design you see in the patch which uses SetVector-based
worklists. The RefSCC worklist is always empty until an update occurs
and is just used to handle those RefSCCs created by updates as the
others don't even exist yet and are formed on-demand during the
bottom-up walk. The SCC worklist is pre-populated from the RefSCC, and
we push new SCCs onto it and blacklist existing SCCs on it to get the
desired processing.

We then *directly* update these when updating the call graph as I was
never able to find a satisfactory abstraction around the update
strategy.

Finally, we need to compute the updates for function passes. This is
mostly used as an initial customer of all the update mechanisms to drive
their design to at least cover some real set of use cases. There are
a bunch of interesting things that came out of doing this:

- It is really nice to do this a function at a time because that
  function is likely hot in the cache. This means we want even the
  function pass adaptor to support online updates to the call graph!

- To update the call graph after arbitrary function pass mutations is
  quite hard. We have to build a fairly comprehensive set of
  data structures and then process them. Fortunately, some of this code
  is related to the code for building the cal graph in the first place.
  Unfortunately, very little of it makes any sense to share because the
  nature of what we're doing is so very different. I've factored out the
  one part that made sense at least.

- We need to transfer these updates into the various structures for the
  CGSCC pass manager. Once those were more sanely worked out, this
  became relatively easier. But some of those needs necessitated changes
  to the LazyCallGraph interface to make it significantly easier to
  extract the changed SCCs from an update operation.

- We also need to update the CGSCC analysis manager as the shape of the
  graph changes. When an SCC is merged away we need to clear analyses
  associated with it from the analysis manager which we didn't have
  support for in the analysis manager infrsatructure. New SCCs are easy!
  But then we have the case that the original SCC has its shape changed
  but remains in the call graph. There we need to *invalidate* the
  analyses associated with it.

- We also need to invalidate analyses after we *finish* processing an
  SCC. But the analyses we need to invalidate here are *only those for
  the newly updated SCC*!!! Because we only continue processing the
  bottom SCC, if we split SCCs apart the original one gets invalidated
  once when its shape changes and is not processed farther so its
  analyses will be correct. It is the bottom SCC which continues being
  processed and needs to have the "normal" invalidation done based on
  the preserved analyses set.

All of this is mostly background and context for the changes here.

Many thanks to all the reviewers who helped here. Especially Sanjoy who
caught several interesting bugs in the graph algorithms, David, Sean,
and others who all helped with feedback.

Differential Revision: http://reviews.llvm.org/D21464

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279618 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24 09:37:14 +00:00
Matthias Braun
fa5c5c7db3 CodeGen: Remove MachineFunctionAnalysis => Enable (Machine)ModulePasses
Re-apply this patch, hopefully I will get away without any warnings
in the constructor now.

This patch removes the MachineFunctionAnalysis. Instead we keep a
map from IR Function to MachineFunction in the MachineModuleInfo.

This allows the insertion of ModulePasses into the codegen pipeline
without breaking it because the MachineFunctionAnalysis gets dropped
before a module pass.

Peak memory should stay unchanged without a ModulePass in the codegen
pipeline: Previously the MachineFunction was freed at the end of a codegen
function pipeline because the MachineFunctionAnalysis was dropped; With
this patch the MachineFunction is freed after the AsmPrinter has
finished.

Differential Revision: http://reviews.llvm.org/D23736

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279602 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24 01:52:46 +00:00
Matthias Braun
43f89c5079 MachineModuleInfo: Avoid dummy constructor, use INITIALIZE_TM_PASS
Change this pass constructor to just accept a const TargetMachine * and
use INITIALIZE_TM_PASS, that way we can get rid of the dummy
constructor. The pass will still fail when calling the default
constructor leading to TM == nullptr, this is no different than before
but is more in line what other codegen passes are doing and avoids the
dummy constructor.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279598 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24 00:42:05 +00:00
Richard Smith
5a65f77485 Revert r279564. It introduces undefined behavior (binding a reference to a
dereferenced null pointer) in MachineModuleInfo::MachineModuleInfo that causes
-Werror builds (including several buildbots) to fail.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279580 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 22:08:27 +00:00
Matthias Braun
1bb228f703 CodeGen: Remove MachineFunctionAnalysis => Enable (Machine)ModulePasses
Re-apply this commit with the deletion of a MachineFunction delegated to
a separate pass to avoid use after free when doing this directly in
AsmPrinter.

This patch removes the MachineFunctionAnalysis. Instead we keep a
map from IR Function to MachineFunction in the MachineModuleInfo.

This allows the insertion of ModulePasses into the codegen pipeline
without breaking it because the MachineFunctionAnalysis gets dropped
before a module pass.

Peak memory should stay unchanged without a ModulePass in the codegen
pipeline: Previously the MachineFunction was freed at the end of a codegen
function pipeline because the MachineFunctionAnalysis was dropped; With
this patch the MachineFunction is freed after the AsmPrinter has
finished.

Differential Revision: http://reviews.llvm.org/D23736

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279564 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 20:58:29 +00:00
Tim Northover
585ed95521 GlobalISel: extend legalizer interface to handle multiple types.
Instructions like G_ICMP have multiple types that may need to be legalized (the
boolean output and nearly arbitrary inputs in this case). So the legalizer must
be capable of deciding what to do for each of them separately.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279554 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 19:30:42 +00:00
Duncan P. N. Exon Smith
bda1572261 Rename unittests/ADT/ilistTest.cpp to ilistTestTemp.cpp (temporarily)
I'll rename this to IListTest.cpp after a waiting period (tonight?
tomorrow?), with a full explanation in that commit.

First, I'm moving it aside because Git doesn't play well with case-only
filename changes on case-insensitive file systems (and I suspect the
same is true of SVN).  This two-stage change should help to avoid
spurious failures on bots that don't do clean checkouts.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279524 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 15:56:50 +00:00
Matthias Braun
eb3b7392bb Revert "(HEAD -> master, origin/master, origin/HEAD) CodeGen: Remove MachineFunctionAnalysis => Enable (Machine)ModulePasses"
Reverting while tracking down a use after free.

This reverts commit r279502.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279503 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 05:17:11 +00:00
Matthias Braun
ded269b907 CodeGen: Remove MachineFunctionAnalysis => Enable (Machine)ModulePasses
This patch removes the MachineFunctionAnalysis. Instead we keep a
map from IR Function to MachineFunction in the MachineModuleInfo.

This allows the insertion of ModulePasses into the codegen pipeline
without breaking it because the MachineFunctionAnalysis gets dropped
before a module pass.

Peak memory should stay unchanged without a ModulePass in the codegen
pipeline: Previously the MachineFunction was freed at the end of a codegen
function pipeline because the MachineFunctionAnalysis was dropped; With
this patch the MachineFunction is freed after the AsmPrinter has
finished.

Differential Revision: http://reviews.llvm.org/D23736

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279502 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 03:20:09 +00:00
Duncan P. N. Exon Smith
fd2abc5908 ADT: Separate some list manipulation API into ilist_base, NFC
Separate algorithms in iplist<T> that don't depend on T into ilist_base,
and unit test them.

While I was adding unit tests for these algorithms anyway, I also added
unit tests for ilist_node_base and ilist_sentinel<T>.

To make the algorithms and unit tests easier to write, I also did the
following minor changes as a drive-by:
- encapsulate Prev/Next in ilist_node_base to so that algorithms are
  easier to read, and
- update ilist_node_access API to take nodes by reference.

There should be no real functionality change here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279484 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 22:21:07 +00:00
Duncan P. N. Exon Smith
9ed748efef Fix header comment for unittests/ADT/ilistTest.cpp
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279483 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 22:04:16 +00:00
Tim Shen
3d515f61b6 [ADT] Actually mutate the iterator VisitStack.back().second, not its copy.
Summary: Before the change, *Opt never actually gets updated by the end
of toNext(), so for every next time the loop has to start over from
child_begin(). This bug doesn't affect the correctness, since Visited prevents
it from re-entering the same node again; but it's slow.

Reviewers: dberris, dblaikie, dannyb

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D23649

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279482 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 21:59:26 +00:00
Tim Shen
22fca38c9c [GraphTraits] Replace all NodeType usage with NodeRef
This should finish the GraphTraits migration.

Differential Revision: http://reviews.llvm.org/D23730


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279475 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 21:09:30 +00:00
Vitaly Buka
939300ca39 [asan] Add support of lifetime poisoning into ComputeASanStackFrameLayout
Summary:
We are going to combine poisoning of red zones and scope poisoning.

PR27453

Reviewers: kcc, eugenis

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D23623

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279373 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-20 16:48:24 +00:00
Duncan P. N. Exon Smith
250933d6c4 Move unittests/Support/IteratorTest.cpp to unittests/ADT/
This testing stuff from ADT, not Support.  Fix the file location.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279372 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-20 14:58:31 +00:00
Vitaly Buka
b2ae2edf5a Revert "[asan] Add support of lifetime poisoning into ComputeASanStackFrameLayout"
This reverts commit r279020.

Speculative revert in hope to fix asan test on arm.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279332 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 22:12:58 +00:00
Tim Shen
f6e737e783 [GraphTraits] Make nodes_iterator dereference to NodeType*/NodeRef
Currently nodes_iterator may dereference to a NodeType* or a NodeType&. Make them all dereference to NodeType*, which is NodeRef later.

Differential Revision: https://reviews.llvm.org/D23704
Differential Revision: https://reviews.llvm.org/D23705


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279326 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 21:20:13 +00:00
Tim Shen
878c720c8a [ADT] add pointer_iterator, the opposite of pointee_iterator
Differential Revision: https://reviews.llvm.org/D23703

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279323 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 21:04:45 +00:00
Duncan P. N. Exon Smith
3cef1f9cbf Reapply "ADT: Remove UB in ilist (and use a circular linked list)"
This reverts commit r279053, reapplying r278974 after fixing PR29035
with r279104.

Note that r279312 has been committed in the meantime, and this has been
rebased on top of that.  Otherwise it's identical to r278974.

Note for maintainers of out-of-tree code (that I missed in the original
message): if the new isKnownSentinel() assertion is firing from
ilist_iterator<>::operator*(), this patch has identified a bug in your
code.  There are a few common patterns:
- Some IR-related APIs htake an IRUnit* that might be nullptr, and pass
  in an incremented iterator as an insertion point.  Some old code was
  using "&*++I", which in the case of end() only worked by fluke.  If
  the IRUnit in question inherits from ilist_node_with_parent<>, you can
  use "I->getNextNode()".  Otherwise, use "List.getNextNode(*I)".
- In most other cases, crashes on &*I just need to check for I==end()
  before dereferencing.
- There's also occasional code that sends iterators into a function, and
  then starts calling I->getOperand() (or other API).  Either check for
  end() before the entering the function, or early exit.

Note for if the static_assert with HasObsoleteCustomization is firing
for you:
- r278513 has examples of how to stop using custom sentinel traits.
- r278532 removed ilist_nextprev_traits since no one was using it.  See
  lld's r278469 for the only migration I needed to do.

Original commit message follows.

----

This removes the undefined behaviour (UB) in ilist/ilist_node/etc.,
mainly by removing (gutting) the ilist_sentinel_traits customization
point and canonicalizing on a single, efficient memory layout.  This
fixes PR26753.

The new ilist is a doubly-linked circular list.
- ilist_node_base has two ilist_node_base*: Next and Prev.  Size-of: two
  pointers.
- ilist_node<T> (size-of: two pointers) is a type-safe wrapper around
  ilist_node_base.
- ilist_iterator<T> (size-of: two pointers) operates on an
  ilist_node<T>*, and downcasts to T* on dereference.
- ilist_sentinel<T> (size-of: two pointers) is a wrapper around
  ilist_node<T> that has some extra API for list management.
- ilist<T> (size-of: two pointers) has an ilist_sentinel<T>, whose
  address is returned for end().

The new memory layout matches ilist_half_embedded_sentinel_traits<T>
exactly.  The Head pointer that previously lived in ilist<T> is
effectively glued to the ilist_half_node<T> that lived in
ilist_half_embedded_sentinel_traits<T>, becoming the Next and Prev in
the ilist_sentinel_node<T>, respectively.  sizeof(ilist<T>) is now the
size of two pointers, and there is never any additional storage for a
sentinel.

This is a much simpler design for a doubly-linked list, removing most of
the corner cases of list manipulation (add, remove, etc.).  In follow-up
commits, I intend to move as many algorithms as possible into a
non-templated base class (ilist_base) to reduce code size.

Moreover, this fixes the UB in ilist_iterator/getNext/getPrev
operations.  Previously, ilist_iterator<T> operated on a T*, even when
the sentinel was not of type T (i.e., ilist_embedded_sentinel_traits and
ilist_half_embedded_sentinel_traits).  This added UB to all operations
involving end().   Now, ilist_iterator<T> operates on an ilist_node<T>*,
and only downcasts when the full type is guaranteed to be T*.

What did we lose?  There used to be a crash (in some configurations) on
++end().  Curiously (via UB), ++end() would return begin() for users of
ilist_half_embedded_sentinel_traits<T>, but otherwise ++end() would
cause a nice dependable nullptr dereference, crashing instead of a
possible infinite loop.  Options:
 1. Lose that behaviour.
 2. Keep it, by stealing a bit from Prev in asserts builds.
 3. Crash on dereference instead, using the same technique.

Hans convinced me (because of the number of problems this and r278532
exposed on Windows) that we really need some assertion here, at least in
the short term.  I've opted for #3 since I think it catches more bugs.

I added only a couple of unit tests to root out specific bugs I hit
during bring-up, but otherwise this is tested implicitly via the
extensive usage throughout LLVM.

Planned follow-ups:
- Remove ilist_*sentinel_traits<T>.  Here I've just gutted them to
  prevent build failures in sub-projects.  Once I stop referring to them
  in sub-projects, I'll come back and delete them.
- Add ilist_base and move algorithms there.
- Check and fix move construction and assignment.

Eventually, there are other interesting directions:
- Rewrite reverse iterators, so that rbegin().getNodePtr()==&*rbegin().
  This allows much simpler logic when erasing elements during a reverse
  traversal.
- Remove ilist_traits::createNode, by deleting the remaining API that
  creates nodes.  Intrusive lists shouldn't be creating nodes
  themselves.
- Remove ilist_traits::deleteNode, by (1) asserting that lists are empty
  on destruction and (2) changing API that calls it to take a Deleter
  functor (intrusive lists shouldn't be in the memory management
  business).
- Reconfigure the remaining callback traits (addNodeToList, etc.) to be
  higher-level, pulling out a simple_ilist<T> that is much easier to
  read and understand.
- Allow tags (e.g., ilist_node<T,tag1> and ilist_node<T,tag2>) so that T
  can be a member of multiple intrusive lists.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279314 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 20:40:12 +00:00
Duncan P. N. Exon Smith
118c0049a1 Reapply "ADT: Tidy up ilist_traits static asserts, NFC"
This spiritually reapplies r279012 (reverted in r279052) without the
r278974 parts.  The differences:

  - Only the HasGetNext trait exists here, so I've only cleaned up (and
    tested) it.  I still added HasObsoleteCustomization since I know
    this will be expanding when r278974 is reapplied.

  - I changed the unit tests to use static_assert to catch problems
    earlier in the build.

  - I added negative tests for the type traits.

Original commit message follows.

----

Change the ilist traits to use decltype instead of sizeof, and add
HasObsoleteCustomization so that additions to this list don't
need to be added in two places.

I suspect this will now work with MSVC, since the trait tested in
r278991 seems to work.  If for some reason it continues to fail on
Windows I'll follow up by adding back the #ifndef _MSC_VER.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279312 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 20:17:23 +00:00
Chandler Carruth
8c28aa1da8 [PM] Re-instate r279227 and r279228 with a fix to the way the templating
was done to hopefully appease MSVC.

As an upside, this also implements the suggestion Sanjoy made in code
review, so two for one! =]

I'll be watching the bots to see if there are still issues.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279295 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 18:36:06 +00:00
Chandler Carruth
7d191bbd95 [PM] Revert r279227 and r279228 until I can find someone to help me
solve completely opaque MSVC build errors. It complains about lots of
stuff with this change without givin nearly enough information to even
try to fix.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279231 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 10:51:55 +00:00
Chandler Carruth
7fdf9ef04b [PM] Fix a compile error with GCC. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279228 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 09:53:10 +00:00
Chandler Carruth
73e7eb0a79 [PM] Make the the new pass manager support fully generic extra arguments
to run methods, both for transform passes and analysis passes.

This also allows the analysis manager to use a different set of extra
arguments from the pass manager where useful. Consider passes over
analysis produced units of IR like SCCs of the call graph or loops.
Passes of this nature will often want to refer to the analysis result
that was used to compute their IR units (the call graph or LoopInfo).
And for transformations, they may want to communicate special update
information to the outer pass manager. With this change, it becomes
possible to have a run method for a loop pass that looks more like:

  PreservedAnalyses run(Loop &L, AnalysisManager<Loop, LoopInfo> &AM,
                        LoopInfo &LI, LoopUpdateRecord &UR);

And to query the analysis manager like:

    AM.getResult<MyLoopAnalysis>(L, LI);

This makes accessing the known-available analyses convenient and clear,
and it makes passing customized data structures around easy.

My initial use case is going to be in updating the pass manager layers
when the analysis units of IR change. But there are more use cases here
such as having a layer that lets inner passes signal whether certain
additional passes should be run because of particular simplifications
made. Two desires for this have come up in the past: triggering
additional optimization after successfully unrolling loops, and
triggering additional inlining after collapsing indirect calls to direct
calls.

Despite adding this layer of generic extensibility, the *only* change to
existing, simple usage are for places where we forward declare the
AnalysisManager template. We really shouldn't be doing this because of
the fragility exposed here, but currently it makes coping with the
legacy PM code easier.

Differential Revision: http://reviews.llvm.org/D21462

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279227 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 09:45:16 +00:00
Chandler Carruth
d319716acc [ADT] Add the worlds simplest STL extra. Or at least close to it.
This is a little class template that just builds an inheritance chain of
empty classes. Despite how simple this is, it can be used to really
nicely create ranked overload sets. I've added a unittest as much to
document this as test it. You can pass an object of this type as an
argument to a function overload set an it will call the first viable and
enabled candidate at or below the rank of the object.

I'm planning to use this in a subsequent commit to more clearly rank
overload candidates used for SFINAE. All credit for this technique and
both lines of code here to Richard Smith who was helping me rewrite the
SFINAE check in question to much more effectively capture the intended
set of checks.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279197 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 02:07:51 +00:00
Duncan P. N. Exon Smith
cd8d034cc5 Reapply "ADT: Remove references in has_rbegin for reverse()"
This reverts commit r279086, reapplying r279084.  I'm not sure what I
ran before, because the compile failure for ADTTests reproduced locally.

The problem is that TestRev is calling BidirectionalVector::rbegin()
when the BidirectionalVector is const, but rbegin() is always non-const.
I've updated BidirectionalVector::rbegin() to be callable from const.

Original commit message follows.

--

As a follow-up to r278991, add some tests that check that
decltype(reverse(R).begin()) == decltype(R.rbegin()), and get them
passing by adding std::remove_reference to has_rbegin.

I'm using static_assert instead of EXPECT_TRUE (and updated the other
has_rbegin check from r278991 in the same way) since I figure that's
more helpful.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279091 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 17:15:25 +00:00
Duncan P. N. Exon Smith
67f28904e3 Revert "ADT: Remove references in has_rbegin for reverse()"
This reverts commit r279084, since it failed on a bot:
  http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/41733

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279086 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 16:27:41 +00:00
Duncan P. N. Exon Smith
e32f5ce95d ADT: Remove references in has_rbegin for reverse()
As a follow-up to r278991, add some tests that check that
decltype(reverse(R).begin()) == decltype(R.rbegin()), and get them
passing by adding std::remove_reference to has_rbegin.

I'm using static_assert instead of EXPECT_TRUE (and updated the other
has_rbegin check from r278991 in the same way) since I figure that's
more helpful.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279084 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 16:22:54 +00:00
Diana Picus
9d8d6de2e0 Revert "ADT: Remove UB in ilist (and use a circular linked list)"
This reverts commit r278974 which broke some of our bots (e.g.
clang-cmake-aarch64-42vma, clang-cmake-aarch64-full).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279053 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 11:17:53 +00:00
Diana Picus
f1b025c185 Revert "ADT: Tidy up ilist_traits static asserts, NFC"
This reverts commit r279012.
r278974 broke some bots, I have to revert this to get to it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279052 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 11:17:47 +00:00
Lang Hames
b60f9a25c0 Revert r279016 -- it breaks win32-elf JIT tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279029 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 01:33:28 +00:00
Vitaly Buka
76e81b28c6 [asan] Add support of lifetime poisoning into ComputeASanStackFrameLayout
Summary:
We are going to combine poisoning of red zones and scope poisoning.

PR27453

Reviewers: kcc, eugenis

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D23623

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279020 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 00:56:58 +00:00
Lang Hames
5bc5c47fda [RuntimeDyld] Strip leading '_' from symbols on 32-bit windows in
RTDyldMemoryManager::getSymbolAddressInProcess()

This should allow JIT'd code for win32 to find in-process symbols. See
http://llvm.org/PR28699 .

Patch by James Holderness. Thanks James!



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279016 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 00:22:34 +00:00
Duncan P. N. Exon Smith
4ab1e666f8 ADT: Tidy up ilist_traits static asserts, NFC
Change the ilist traits to use decltype instead of sizeof, and add
HasObsoleteCustomization so that additions to this list don't need to be
added in two places.

I suspect this will now work with MSVC, since the trait tested in
r278991 seems to work.  If for some reason it continues to fail on
Windows I'll follow up by adding back the #ifndef _MSC_VER.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279012 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 23:47:56 +00:00
Pete Cooper
0f699212af Actually enable new test for const RangeAdapter. Missing from r278991
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279000 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 22:52:39 +00:00
Pete Cooper
cebbb5ed8d Fix reverse to work on const rbegin()/rend().
Duncan found that reverse worked on mutable rbegin(), but the has_rbegin
trait didn't work with a const method.  See http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160815/382890.html
for more details.

Turns out this was already solved in clang with has_getDecl.  Copied that and made it work for rbegin.

This includes the tests Duncan attached to that thread, including the traits test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278991 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 22:06:59 +00:00
Duncan P. N. Exon Smith
b2724ac8c1 ADT: Remove UB in ilist (and use a circular linked list)
This removes the undefined behaviour (UB) in ilist/ilist_node/etc.,
mainly by removing (gutting) the ilist_sentinel_traits customization
point and canonicalizing on a single, efficient memory layout.  This
fixes PR26753.

The new ilist is a doubly-linked circular list.
- ilist_node_base has two ilist_node_base*: Next and Prev.  Size-of: two
  pointers.
- ilist_node<T> (size-of: two pointers) is a type-safe wrapper around
  ilist_node_base.
- ilist_iterator<T> (size-of: two pointers) operates on an
  ilist_node<T>*, and downcasts to T* on dereference.
- ilist_sentinel<T> (size-of: two pointers) is a wrapper around
  ilist_node<T> that has some extra API for list management.
- ilist<T> (size-of: two pointers) has an ilist_sentinel<T>, whose
  address is returned for end().

The new memory layout matches ilist_half_embedded_sentinel_traits<T>
exactly.  The Head pointer that previously lived in ilist<T> is
effectively glued to the ilist_half_node<T> that lived in
ilist_half_embedded_sentinel_traits<T>, becoming the Next and Prev in
the ilist_sentinel_node<T>, respectively.  sizeof(ilist<T>) is now the
size of two pointers, and there is never any additional storage for a
sentinel.

This is a much simpler design for a doubly-linked list, removing most of
the corner cases of list manipulation (add, remove, etc.).  In follow-up
commits, I intend to move as many algorithms as possible into a
non-templated base class (ilist_base) to reduce code size.

Moreover, this fixes the UB in ilist_iterator/getNext/getPrev
operations.  Previously, ilist_iterator<T> operated on a T*, even when
the sentinel was not of type T (i.e., ilist_embedded_sentinel_traits and
ilist_half_embedded_sentinel_traits).  This added UB to all operations
involving end().   Now, ilist_iterator<T> operates on an ilist_node<T>*,
and only downcasts when the full type is guaranteed to be T*.

What did we lose?  There used to be a crash (in some configurations) on
++end().  Curiously (via UB), ++end() would return begin() for users of
ilist_half_embedded_sentinel_traits<T>, but otherwise ++end() would
cause a nice dependable nullptr dereference, crashing instead of a
possible infinite loop.  Options:
 1. Lose that behaviour.
 2. Keep it, by stealing a bit from Prev in asserts builds.
 3. Crash on dereference instead, using the same technique.

Hans convinced me (because of the number of problems this and r278532
exposed on Windows) that we really need some assertion here, at least in
the short term.  I've opted for #3 since I think it catches more bugs.

I added only a couple of unit tests to root out specific bugs I hit
during bring-up, but otherwise this is tested implicitly via the
extensive usage throughout LLVM.

Planned follow-ups:
- Remove ilist_*sentinel_traits<T>.  Here I've just gutted them to
  prevent build failures in sub-projects.  Once I stop referring to them
  in sub-projects, I'll come back and delete them.
- Add ilist_base and move algorithms there.
- Check and fix move construction and assignment.

Eventually, there are other interesting directions:
- Rewrite reverse iterators, so that rbegin().getNodePtr()==&*rbegin().
  This allows much simpler logic when erasing elements during a reverse
  traversal.
- Remove ilist_traits::createNode, by deleting the remaining API that
  creates nodes.  Intrusive lists shouldn't be creating nodes
  themselves.
- Remove ilist_traits::deleteNode, by (1) asserting that lists are empty
  on destruction and (2) changing API that calls it to take a Deleter
  functor (intrusive lists shouldn't be in the memory management
  business).
- Reconfigure the remaining callback traits (addNodeToList, etc.) to be
  higher-level, pulling out a simple_ilist<T> that is much easier to
  read and understand.
- Allow tags (e.g., ilist_node<T,tag1> and ilist_node<T,tag2>) so that T
  can be a member of multiple intrusive lists.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278974 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 20:44:33 +00:00
Adrian Prantl
926ddae882 Support the DW_AT_noreturn DWARF flag.
This is used to mark functions with the C++11 [[ noreturn ]] or C11 _Noreturn
attributes.

Patch by Victor Leschuk!

https://reviews.llvm.org/D23167

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278940 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 16:02:43 +00:00
Zijiao Ma
8db1b32c33 Remove the Triple tests that stressing the TargetParser's behaviour.
Now the tests of TargetParser is in place:
unittests/Support/TargetParserTest.cpp.
So the tests in TripleTest.cpp which actually stressing TargetParser's behavior could be removed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278899 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 03:17:07 +00:00
Duncan P. N. Exon Smith
eb6a210db6 ADT: Add some missing coverage for iplist::splice
These splices are interesting because they involve swapping two nodes in
the same list.  There are two ways to do this.  Assuming:

    A -> B -> [Sentinel]

You can either:
- splice B before A, with:        L.splice(A,       L, B) or
- splice A before Sentinel, with: L.splice(L.end(), L, A) to create:

    B -> A -> [Sentinel]

These two swapping-splices are somewhat interesting corner cases for
maintaining the list invariants.  The tests pass even with my new ilist
implementation, but I had some doubts about the latter when I was
looking at weird UB effects.  Since I can't find equivalent explicit
test coverage elsewhere it seems prudent to commit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278887 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 02:08:08 +00:00
Tim Shen
36b7d78473 [ADT] Change PostOrderIterator to use NodeRef. NFC.
Reviewers: dblaikie

Subscribers: mzolotukhin, llvm-commits

Differential Revision: https://reviews.llvm.org/D23522

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278752 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-15 21:52:54 +00:00
Tim Northover
b430a4adda GlobalISel: support loads and stores of strange types.
Before we mischaracterized structs and i1 types as a scalar with size 0 in
various ways.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278744 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-15 21:13:17 +00:00
Mehdi Amini
568382ff0e [ADT] Add a reserve() method to DenseSet as well as an insert() for R-value
Recommit 278600 with some fixes to make the test more robust.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278604 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-13 20:42:19 +00:00
Mehdi Amini
80f0510b4f Revert "[ADT] Add a reserve method to DenseSet as well as an insert() for R-value"
This reverts commit r278600. The unittest does not pass on MSVC, there is
an extra move. Investigating how to make it more robust.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278603 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-13 20:14:39 +00:00
Mehdi Amini
762481ded9 [ADT] Add a reserve method to DenseSet as well as an insert() for R-value
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278600 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-13 19:40:13 +00:00
Pete Cooper
fe45d14191 Add support to paternmatch for simple const Value cases.
Pattern match has some paths which can operate on constant instructions,
but not all.  This adds a version of m_value() to return const Value* and
changes ICmp matching to use auto so that it can match both constant and
mutable instructions.

Tests also included for both mutable and constant ICmpInst matching.

This will be used in a future commit to constify ValueTracking.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278570 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-12 22:16:05 +00:00