2007-10-07 05:00:36 +08:00
|
|
|
//===-- Analysis.cpp ------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-10-07 05:00:36 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-c/Analysis.h"
|
2011-08-19 09:36:54 +08:00
|
|
|
#include "llvm-c/Initialization.h"
|
2013-05-02 04:59:00 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2014-01-13 17:26:24 +08:00
|
|
|
#include "llvm/IR/Verifier.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2013-05-02 04:59:00 +08:00
|
|
|
#include "llvm/PassRegistry.h"
|
2014-03-04 18:07:28 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-02-20 19:08:44 +08:00
|
|
|
#include <cstring>
|
2007-10-07 05:00:36 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2010-10-08 02:31:00 +08:00
|
|
|
/// initializeAnalysis - Initialize all passes linked into the Analysis library.
|
|
|
|
void llvm::initializeAnalysis(PassRegistry &Registry) {
|
|
|
|
initializeAliasAnalysisAnalysisGroup(Registry);
|
|
|
|
initializeAliasAnalysisCounterPass(Registry);
|
|
|
|
initializeAAEvalPass(Registry);
|
|
|
|
initializeAliasDebuggerPass(Registry);
|
|
|
|
initializeAliasSetPrinterPass(Registry);
|
|
|
|
initializeNoAAPass(Registry);
|
|
|
|
initializeBasicAliasAnalysisPass(Registry);
|
2011-07-26 03:25:40 +08:00
|
|
|
initializeBlockFrequencyInfoPass(Registry);
|
2011-06-04 09:16:30 +08:00
|
|
|
initializeBranchProbabilityInfoPass(Registry);
|
2012-11-03 05:48:17 +08:00
|
|
|
initializeCostModelAnalysisPass(Registry);
|
2010-10-08 02:31:00 +08:00
|
|
|
initializeCFGViewerPass(Registry);
|
|
|
|
initializeCFGPrinterPass(Registry);
|
|
|
|
initializeCFGOnlyViewerPass(Registry);
|
|
|
|
initializeCFGOnlyPrinterPass(Registry);
|
2014-09-03 05:43:13 +08:00
|
|
|
initializeCFLAliasAnalysisPass(Registry);
|
dependence analysis
Patch from Preston Briggs <preston.briggs@gmail.com>.
This is an updated version of the dependence-analysis patch, including an MIV
test based on Banerjee's inequalities.
It's a fairly complete implementation of the paper
Practical Dependence Testing
Gina Goff, Ken Kennedy, and Chau-Wen Tseng
PLDI 1991
It cannot yet propagate constraints between coupled RDIV subscripts (discussed
in Section 5.3.2 of the paper).
It's organized as a FunctionPass with a single entry point that supports testing
for dependence between two instructions in a function. If there's no dependence,
it returns null. If there's a dependence, it returns a pointer to a Dependence
which can be queried about details (what kind of dependence, is it loop
independent, direction and distance vector entries, etc). I haven't included
every imaginable feature, but there's a good selection that should be adequate
for supporting many loop transformations. Of course, it can be extended as
necessary.
Included in the patch file are many test cases, commented with C code showing
the loops and array references.
llvm-svn: 165708
2012-10-11 15:32:34 +08:00
|
|
|
initializeDependenceAnalysisPass(Registry);
|
2013-11-13 06:47:20 +08:00
|
|
|
initializeDelinearizationPass(Registry);
|
2011-01-18 14:06:27 +08:00
|
|
|
initializeDominanceFrontierPass(Registry);
|
2010-10-08 02:31:00 +08:00
|
|
|
initializeDomViewerPass(Registry);
|
|
|
|
initializeDomPrinterPass(Registry);
|
|
|
|
initializeDomOnlyViewerPass(Registry);
|
|
|
|
initializePostDomViewerPass(Registry);
|
|
|
|
initializeDomOnlyPrinterPass(Registry);
|
|
|
|
initializePostDomPrinterPass(Registry);
|
|
|
|
initializePostDomOnlyViewerPass(Registry);
|
|
|
|
initializePostDomOnlyPrinterPass(Registry);
|
|
|
|
initializeIVUsersPass(Registry);
|
|
|
|
initializeInstCountPass(Registry);
|
|
|
|
initializeIntervalPartitionPass(Registry);
|
2014-06-06 03:29:43 +08:00
|
|
|
initializeJumpInstrTableInfoPass(Registry);
|
2010-10-08 02:31:00 +08:00
|
|
|
initializeLazyValueInfoPass(Registry);
|
|
|
|
initializeLibCallAliasAnalysisPass(Registry);
|
|
|
|
initializeLintPass(Registry);
|
2015-01-17 22:16:18 +08:00
|
|
|
initializeLoopInfoWrapperPassPass(Registry);
|
2010-10-08 02:31:00 +08:00
|
|
|
initializeMemDepPrinterPass(Registry);
|
|
|
|
initializeMemoryDependenceAnalysisPass(Registry);
|
|
|
|
initializeModuleDebugInfoPrinterPass(Registry);
|
|
|
|
initializePostDominatorTreePass(Registry);
|
2014-07-20 02:29:29 +08:00
|
|
|
initializeRegionInfoPassPass(Registry);
|
2010-10-08 02:31:00 +08:00
|
|
|
initializeRegionViewerPass(Registry);
|
|
|
|
initializeRegionPrinterPass(Registry);
|
|
|
|
initializeRegionOnlyViewerPass(Registry);
|
|
|
|
initializeRegionOnlyPrinterPass(Registry);
|
|
|
|
initializeScalarEvolutionPass(Registry);
|
|
|
|
initializeScalarEvolutionAliasAnalysisPass(Registry);
|
[PM] Change the core design of the TTI analysis to use a polymorphic
type erased interface and a single analysis pass rather than an
extremely complex analysis group.
The end result is that the TTI analysis can contain a type erased
implementation that supports the polymorphic TTI interface. We can build
one from a target-specific implementation or from a dummy one in the IR.
I've also factored all of the code into "mix-in"-able base classes,
including CRTP base classes to facilitate calling back up to the most
specialized form when delegating horizontally across the surface. These
aren't as clean as I would like and I'm planning to work on cleaning
some of this up, but I wanted to start by putting into the right form.
There are a number of reasons for this change, and this particular
design. The first and foremost reason is that an analysis group is
complete overkill, and the chaining delegation strategy was so opaque,
confusing, and high overhead that TTI was suffering greatly for it.
Several of the TTI functions had failed to be implemented in all places
because of the chaining-based delegation making there be no checking of
this. A few other functions were implemented with incorrect delegation.
The message to me was very clear working on this -- the delegation and
analysis group structure was too confusing to be useful here.
The other reason of course is that this is *much* more natural fit for
the new pass manager. This will lay the ground work for a type-erased
per-function info object that can look up the correct subtarget and even
cache it.
Yet another benefit is that this will significantly simplify the
interaction of the pass managers and the TargetMachine. See the future
work below.
The downside of this change is that it is very, very verbose. I'm going
to work to improve that, but it is somewhat an implementation necessity
in C++ to do type erasure. =/ I discussed this design really extensively
with Eric and Hal prior to going down this path, and afterward showed
them the result. No one was really thrilled with it, but there doesn't
seem to be a substantially better alternative. Using a base class and
virtual method dispatch would make the code much shorter, but as
discussed in the update to the programmer's manual and elsewhere,
a polymorphic interface feels like the more principled approach even if
this is perhaps the least compelling example of it. ;]
Ultimately, there is still a lot more to be done here, but this was the
huge chunk that I couldn't really split things out of because this was
the interface change to TTI. I've tried to minimize all the other parts
of this. The follow up work should include at least:
1) Improving the TargetMachine interface by having it directly return
a TTI object. Because we have a non-pass object with value semantics
and an internal type erasure mechanism, we can narrow the interface
of the TargetMachine to *just* do what we need: build and return
a TTI object that we can then insert into the pass pipeline.
2) Make the TTI object be fully specialized for a particular function.
This will include splitting off a minimal form of it which is
sufficient for the inliner and the old pass manager.
3) Add a new pass manager analysis which produces TTI objects from the
target machine for each function. This may actually be done as part
of #2 in order to use the new analysis to implement #2.
4) Work on narrowing the API between TTI and the targets so that it is
easier to understand and less verbose to type erase.
5) Work on narrowing the API between TTI and its clients so that it is
easier to understand and less verbose to forward.
6) Try to improve the CRTP-based delegation. I feel like this code is
just a bit messy and exacerbating the complexity of implementing
the TTI in each target.
Many thanks to Eric and Hal for their help here. I ended up blocked on
this somewhat more abruptly than I expected, and so I appreciate getting
it sorted out very quickly.
Differential Revision: http://reviews.llvm.org/D7293
llvm-svn: 227669
2015-01-31 11:43:40 +08:00
|
|
|
initializeTargetTransformInfoWrapperPassPass(Registry);
|
2010-10-08 02:31:00 +08:00
|
|
|
initializeTypeBasedAliasAnalysisPass(Registry);
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
llvm-svn: 213864
2014-07-24 22:25:39 +08:00
|
|
|
initializeScopedNoAliasAAPass(Registry);
|
2010-10-08 02:31:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
|
|
|
|
initializeAnalysis(*unwrap(R));
|
|
|
|
}
|
|
|
|
|
2010-01-10 06:27:07 +08:00
|
|
|
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
|
|
|
|
char **OutMessages) {
|
2014-04-15 12:59:12 +08:00
|
|
|
raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
|
2014-06-27 06:52:05 +08:00
|
|
|
std::string Messages;
|
|
|
|
raw_string_ostream MsgsOS(Messages);
|
2011-01-29 09:09:53 +08:00
|
|
|
|
2014-01-19 10:22:18 +08:00
|
|
|
LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
|
|
|
|
|
|
|
|
// Duplicate the output to stderr.
|
|
|
|
if (DebugOS && OutMessages)
|
|
|
|
*DebugOS << MsgsOS.str();
|
|
|
|
|
|
|
|
if (Action == LLVMAbortProcessAction && Result)
|
|
|
|
report_fatal_error("Broken module found, compilation aborted!");
|
2011-01-29 09:09:53 +08:00
|
|
|
|
2014-06-27 06:52:05 +08:00
|
|
|
if (OutMessages)
|
|
|
|
*OutMessages = strdup(MsgsOS.str().c_str());
|
2011-01-29 09:09:53 +08:00
|
|
|
|
2007-10-07 05:00:36 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-01-10 06:27:07 +08:00
|
|
|
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) {
|
2014-01-19 10:22:18 +08:00
|
|
|
LLVMBool Result = verifyFunction(
|
2014-04-15 12:59:12 +08:00
|
|
|
*unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
|
|
|
|
: nullptr);
|
2014-01-19 10:22:18 +08:00
|
|
|
|
|
|
|
if (Action == LLVMAbortProcessAction && Result)
|
|
|
|
report_fatal_error("Broken function found, compilation aborted!");
|
|
|
|
|
|
|
|
return Result;
|
2007-10-07 05:00:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-01 00:22:09 +08:00
|
|
|
void LLVMViewFunctionCFG(LLVMValueRef Fn) {
|
|
|
|
Function *F = unwrap<Function>(Fn);
|
|
|
|
F->viewCFG();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) {
|
|
|
|
Function *F = unwrap<Function>(Fn);
|
|
|
|
F->viewCFGOnly();
|
|
|
|
}
|