Commit Graph

97 Commits

Author SHA1 Message Date
Chandler Carruth
c95ce87c23 Make the User::value_op_iterator a random access iterator. I had written
this code ages ago and lost track of it. Seems worth doing though --
this thing can get called from places that would benefit from knowing
that std::distance is O(1). Also add a very fledgeling unittest for
Users and make sure various aspects of this seem to work reasonably.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206453 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-17 09:07:50 +00:00
Benjamin Kramer
479151ab7f Move MDBuilder's methods out of line.
Making them inline was a historical accident, they're neither hot nor
templated.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206109 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-12 14:26:59 +00:00
NAKAMURA Takumi
c112990260 Untabify.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204916 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-27 11:38:28 +00:00
NAKAMURA Takumi
2b8b9031f4 SmallVector<3> may be used here.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204915 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-27 11:33:11 +00:00
NAKAMURA Takumi
da56c39758 IRTests/InstructionsTest.cpp: Avoid initializer list.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204914 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-27 11:32:41 +00:00
Eli Bendersky
d8f4993cc7 Add a unit test for Invoke iteration, similar to the one for Call
The tests are refactored to use the same fixture.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204860 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-26 21:46:24 +00:00
Eli Bendersky
927eb31eb4 Fix bot breakage in InstructionsTest.
Makes sure the Call dies before the Function



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204856 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-26 21:11:34 +00:00
Eli Bendersky
1003e8fbfa Fix problem with r204836
In CallInst, op_end() points at the callee, which we don't want to iterate over
when just iterating over arguments. Now take this into account when returning
a iterator_range from arg_operands. Similar reasoning for InvokeInst.

Also adds a unit test to verify this actually works as expected.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204851 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-26 20:41:15 +00:00
Chandler Carruth
2d74092f5f [PM] As was pointed out in review, I need to define a custom swap in
order to use the single assignment. That's probably worth doing for
a lot of these types anyways as they may have non-trivial moves and so
getting copy elision in more places seems worthwhile.

I've tried to add some tests that actually catch this mistake, and one
of the types is now well tested but the others' tests still fail to
catch this. I'll keep working on tests, but this gets the core pattern
right.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203780 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-13 10:42:18 +00:00
Chandler Carruth
1b497a9fc4 [PM] While I'm here, fix a few other clang-format issues. Pulls some
lines under 80-columns, etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203434 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-10 02:12:14 +00:00
Chandler Carruth
15903b7dc5 [PM] Switch new pass manager from polymorphic_ptr to unique_ptr now that
it is available. Also make the move semantics sufficiently correct to
tolerate move-only passes, as the PassManagers *are* move-only passes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203391 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-09 11:49:53 +00:00
Benjamin Kramer
1dd31112ff [C++11] Now that the users are gone, rip out the duplicated traits from type_traits.h
Simplify the remaining ones a bit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203249 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-07 15:54:23 +00:00
Ahmed Charles
f4ccd11075 Replace OwningPtr<T> with std::unique_ptr<T>.
This compiles with no changes to clang/lld/lldb with MSVC and includes
overloads to various functions which are used by those projects and llvm
which have OwningPtr's as parameters. This should allow out of tree
projects some time to move. There are also no changes to libs/Target,
which should help out of tree targets have time to move, if necessary.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203083 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-06 05:51:42 +00:00
Chandler Carruth
8f124fe884 [Modules] Move the LeakDetector header into the IR library where the
source file had already been moved. Also move the unittest into the IR
unittest library.

This may seem an odd thing to put in the IR library but we only really
use this with instructions and it needs the LLVM context to work, so it
is intrinsically tied to the IR library.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202842 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04 12:46:06 +00:00
Chandler Carruth
19d764fb05 [Modules] Move the ConstantRange class into the IR library. This is
a bit surprising, as the class is almost entirely abstracted away from
any particular IR, however it encodes the comparsion predicates which
mutate ranges as ICmp predicate codes. This is reasonable as they're
used for both instructions and constants. Thus, it belongs in the IR
library with instructions and constants.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202838 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04 12:24:34 +00:00
Chandler Carruth
ff956e7568 [Modules] Move the NoFolder into the IR library as it creates
instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202834 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04 12:05:47 +00:00
Chandler Carruth
7225e27b4c [Modules] Move ValueMap to the IR library. While this class does not
directly care about the Value class (it is templated so that the key can
be any arbitrary Value subclass), it is in fact concretely tied to the
Value class through the ValueHandle's CallbackVH interface which relies
on the key type being some Value subclass to establish the value handle
chain.

Ironically, the unittest is already in the right library.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202824 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04 11:26:31 +00:00
Chandler Carruth
eb3d76da81 [Modules] Move ValueHandle into the IR library where Value itself lives.
Move the test for this class into the IR unittests as well.

This uncovers that ValueMap too is in the IR library. Ironically, the
unittest for ValueMap is useless in the Support library (honestly, so
was the ValueHandle test) and so it already lives in the IR unittests.
Mmmm, tasty layering.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202821 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04 11:17:44 +00:00
Chandler Carruth
df3d8e8b4d [Modules] Move the LLVM IR pattern match header into the IR library, it
obviously is coupled to the IR.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202818 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04 11:08:18 +00:00
Yaron Keren
b62b44ccc5 Cleaning up a bunch of pre-Visual C++ 2012 build hacks.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202806 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04 09:23:33 +00:00
Chandler Carruth
fc6d7d6cf5 [C++11] Replace LLVM_STATIC_ASSERT with static_assert, we now have
access to it on all host toolchains.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202642 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-02 13:10:45 +00:00
Benjamin Kramer
d628f19f5d [C++11] Replace llvm::next and llvm::prior with std::next and std::prev.
Remove the old functions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202636 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-02 12:27:27 +00:00
Rafael Espindola
3f0a9af13b Fix resetting the DataLayout in a Module.
No tool does this currently, but as everything else in a module we should be
able to change its DataLayout.

Most of the fix is in DataLayout to make sure it can be reset properly.

The test uses Module::setDataLayout since the fact that we mutate a DataLayout
is an implementation detail. The module could hold a OwningPtr<DataLayout> and
the DataLayout itself could be immutable.

Thanks to Philip Reames for pushing me in the right direction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202198 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-25 22:23:04 +00:00
Rafael Espindola
57edc9d4ff Make DataLayout a plain object, not a pass.
Instead, have a DataLayoutPass that holds one. This will allow parts of LLVM
don't don't handle passes to also use DataLayout.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202168 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-25 17:30:31 +00:00
Chandler Carruth
77b655c1c9 [PM] Don't require analysis results to be const in the new pass manager.
I think this was just over-eagerness on my part. The analysis results
need to often be non-const because they need to (in some cases at least)
be updated by the transformation pass in order to remain correct. It
also makes lazy analyses (a common case) needlessly annoying to write in
order to make their entire state mutable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200881 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-05 21:41:42 +00:00
Matt Arsenault
79e3fb53d6 Bug 18228 - Fix accepting bitcasts between vectors of pointers with a
different number of elements.

Bitcasts were passing with vectors of pointers with different number of
elements since the number of elements was checking
SrcTy->getVectorNumElements() == SrcTy->getVectorNumElements() which
isn't helpful. The addrspacecast was also wrong, but that case at least
is caught by the verifier. Refactor bitcast and addrspacecast handling
in castIsValid to be more readable and fix this problem.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199821 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-22 19:21:33 +00:00
Chandler Carruth
e608d695de [PM] Make the verifier work independently of any pass manager.
This makes the 'verifyFunction' and 'verifyModule' functions totally
independent operations on the LLVM IR. It also cleans up their API a bit
by lifting the abort behavior into their clients and just using an
optional raw_ostream parameter to control printing.

The implementation of the verifier is now just an InstVisitor with no
multiple inheritance. It also is significantly more const-correct, and
hides the const violations internally. The two layers that force us to
break const correctness are building a DomTree and dispatching through
the InstVisitor.

A new VerifierPass is used to implement the legacy pass manager
interface in terms of the other pieces.

The error messages produced may be slightly different now, and we may
have slightly different short circuiting behavior with different usage
models of the verifier, but generally everything works equivalently and
this unblocks wiring the verifier up to the new pass manager.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199569 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-19 02:22:18 +00:00
Chandler Carruth
7f2eff792a [PM] Split DominatorTree into a concrete analysis result object which
can be used by both the new pass manager and the old.

This removes it from any of the virtual mess of the pass interfaces and
lets it derive cleanly from the DominatorTreeBase<> template. In turn,
tons of boilerplate interface can be nuked and it turns into a very
straightforward extension of the base DominatorTree interface.

The old analysis pass is now a simple wrapper. The names and style of
this split should match the split between CallGraph and
CallGraphWrapperPass. All of the users of DominatorTree have been
updated to match using many of the same tricks as with CallGraph. The
goal is that the common type remains the resulting DominatorTree rather
than the pass. This will make subsequent work toward the new pass
manager significantly easier.

Also in numerous places things became cleaner because I switched from
re-running the pass (!!! mid way through some other passes run!!!) to
directly recomputing the domtree.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199104 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-13 13:07:17 +00:00
Chandler Carruth
56e1394c88 [cleanup] Move the Dominators.h and Verifier.h headers into the IR
directory. These passes are already defined in the IR library, and it
doesn't make any sense to have the headers in Analysis.

Long term, I think there is going to be a much better way to divide
these matters. The dominators code should be fully separated into the
abstract graph algorithm and have that put in Support where it becomes
obvious that evn Clang's CFGBlock's can use it. Then the verifier can
manually construct dominance information from the Support-driven
interface while the Analysis library can provide a pass which both
caches, reconstructs, and supports a nice update API.

But those are very long term, and so I don't want to leave the really
confusing structure until that day arrives.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199082 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-13 09:26:24 +00:00
Chandler Carruth
8a5351f0f5 [PM] Rename the IR printing pass header to a more generic and correct
name to match the source file which I got earlier. Update the include
sites. Also modernize the comments in the header to use the more
recommended doxygen style.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199041 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-12 11:10:32 +00:00
Chandler Carruth
b56749c3b7 [PM] Add names to passes under the new pass manager, and a debug output
mode that can be used to debug the execution of everything.

No support for analyses here, that will come later. This already helps
show parts of the opt commandline integration that isn't working. Tests
of that will start using it as the bugs are fixed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199004 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-11 11:52:05 +00:00
Chandler Carruth
bc65a8d518 Move the LLVM IR asm writer header files into the IR directory, as they
are part of the core IR library in order to support dumping and other
basic functionality.

Rename the 'Assembly' include directory to 'AsmParser' to match the
library name and the only functionality left their -- printing has been
in the core IR library for quite some time.

Update all of the #includes to match.

All of this started because I wanted to have the layering in good shape
before I started adding support for printing LLVM IR using the new pass
infrastructure, and commandline support for the new pass infrastructure.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198688 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-07 12:34:26 +00:00
Chandler Carruth
a2a28517f1 Add in a unittest for the one-use pattern matcher.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198552 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-05 09:14:53 +00:00
Chandler Carruth
272690897e Add support to the pattern match library for matching NSW and NUW
instructions. I needed this for a quick experiment I was making, and
while I've no idea if that will ever get committed, I didn't want to
throw away the pattern match code and for anyone else to have to write
it again. I've added unittests to make sure this works correctly.

In fun news, this also uncovered the IRBuilder bug. Doh!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198541 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-05 03:28:29 +00:00
Chandler Carruth
b54a0ac20a Fix a bug in IRBuilder that's been there for who knows how long. It
failed to correctly propagate the NUW and NSW flags to the constant
folder for two instructions. I've added a unittest to cover flag
propagation for the rest of the instructions and constant expressions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198538 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-05 03:22:33 +00:00
Chandler Carruth
3f62424ea0 Use a shorter name for the IRBuilder member. This will help the tests
I'm adding next be a lot more readable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198534 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-05 02:23:11 +00:00
Chandler Carruth
478ea5d37d Simplify the PatternMatch unittest by giving it a module, function, and
basic block to hold instructions, and managing all of their lifetimes in
a fixture. This makes it easy to sink the expectations into the test
cases themselves which also makes things a bit more explicit and clearer
IMO.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198532 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-05 02:07:20 +00:00
David Blaikie
028b816496 Use LLVM_STATIC_ASSERT rather than a hand-rolled implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198330 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-02 18:29:40 +00:00
Alp Toker
f8735544dc Rename 'assert' to something less loaded in CompileAssertHasType
Suggested by Aaron Ballman.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198288 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-01 23:34:16 +00:00
Alp Toker
a18007d9d6 Silence g++ 4.9 build issue in unit tests
Stopgap measure until we can just use static_assert().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198273 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-01 06:57:01 +00:00
Rafael Espindola
f343bc9956 Use a: and s: instead of a0: and s0: in the DataLayout strings.
They are equivalent and the size of 'a' and 's' is unused.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197259 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-13 18:56:34 +00:00
NAKAMURA Takumi
3aabdebde2 [CMake] Update LLVM_LINK_COMPONENTS for each CMakeLists.txt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196908 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-10 11:13:32 +00:00
Michael Ilseman
faf4d59137 Use present fast-math flags when applicable in CreateBinOp
We were previously not adding fast-math flags through CreateBinOp()
when it happened to be making a floating point binary operator. This
patch updates it to do so similarly to directly calling CreateF*().



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196438 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-05 00:32:09 +00:00
Diego Novillo
97add46aee Fix dominator descendants for unreachable blocks.
When a block is unreachable, asking its dom tree descendants should
return the empty set. However, the computation of the descendants
was causing a segmentation fault because the dom tree node we get
from the basic block is initially NULL.

Fixed by adding a test for a valid dom tree node before we iterate.

The patch also adds some unit tests to the existing dom tree tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196099 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-02 14:08:27 +00:00
Chandler Carruth
54fec07ec0 [PM] Split the CallGraph out from the ModulePass which creates the
CallGraph.

This makes the CallGraph a totally generic analysis object that is the
container for the graph data structure and the primary interface for
querying and manipulating it. The pass logic is separated into its own
class. For compatibility reasons, the pass provides wrapper methods for
most of the methods on CallGraph -- they all just forward.

This will allow the new pass manager infrastructure to provide its own
analysis pass that constructs the same CallGraph object and makes it
available. The idea is that in the new pass manager, the analysis pass's
'run' method returns a concrete analysis 'result'. Here, that result is
a 'CallGraph'. The 'run' method will typically do only minimal work,
deferring much of the work into the implementation of the result object
in order to be lazy about computing things, but when (like DomTree)
there is *some* up-front computation, the analysis does it prior to
handing the result back to the querying pass.

I know some of this is fairly ugly. I'm happy to change it around if
folks can suggest a cleaner interim state, but there is going to be some
amount of unavoidable ugliness during the transition period. The good
thing is that this is very limited and will naturally go away when the
old pass infrastructure goes away. It won't hang around to bother us
later.

Next up is the initial new-PM-style call graph analysis. =]

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195722 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-26 04:19:30 +00:00
Chandler Carruth
e510665548 [PM] Complete the cross-layer interfaces with a Module-to-Function
proxy. This lets a function pass query a module analysis manager.
However, the interface is const to indicate that only cached results can
be safely queried.

With this, I think the new pass manager is largely functionally complete
for modules and analyses. Still lots to test, and need to generalize to
SCCs and Loops, and need to build an adaptor layer to support the use of
existing Pass objects in the new managers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195538 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-23 01:25:07 +00:00
Chandler Carruth
2ea1151162 [PM] Rename TestAnalysisPass to TestFunctionAnalysis to clear the way
for a TestModuleAnalysis.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195537 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-23 01:25:02 +00:00
Chandler Carruth
b88831b204 [PM] Add support to the analysis managers to query explicitly for cached
results.

This is the last piece of infrastructure needed to effectively support
querying *up* the analysis layers. The next step will be to introduce
a proxy which provides access to those layers with appropriate use of
const to direct queries to the safe interface.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195525 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-23 00:38:42 +00:00
Chandler Carruth
4d32e85359 [PM] Switch the downward invalidation to be incremental where only the
one function's analyses are invalidated at a time. Also switch the
preservation of the proxy to *fully* preserve the lower (function)
analyses.

Combined, this gets both upward and downward analysis invalidation to
a point I'm happy with:

- A function pass invalidates its function analyses, and its parent's
  module analyses.
- A module pass invalidates all of its functions' analyses including the
  set of which functions are in the module.
- A function pass can preserve a module analysis pass.
- If all function passes preserve a module analysis pass, that
  preservation persists. If any doesn't the module analysis is
  invalidated.
- A module pass can opt into managing *all* function analysis
  invalidation itself or *none*.
- The conservative default is none, and the proxy takes the maximally
  conservative approach that works even if the set of functions has
  changed.
- If a module pass opts into managing function analysis invalidation it
  has to propagate the invalidation itself, the proxy just does nothing.

The only thing really missing is a way to query for a cached analysis or
nothing at all. With this, function passes can more safely request
a cached module analysis pass without fear of it accidentally running
part way through.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195519 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-22 23:38:07 +00:00
Chandler Carruth
5f347a9bd1 [PM] Teach the analysis managers to pass themselves as arguments to the
run methods of the analysis passes.

Also generalizes and re-uses the SFINAE for transformation passes so
that users can write an analysis pass and only accept an analysis
manager if that is useful to their pass.

This completes the plumbing to make an analysis manager available
through every pass's run method if desired so that passes no longer need
to be constructed around them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195451 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-22 12:11:02 +00:00