2007-10-06 21:00:36 +00:00
|
|
|
//===-- Analysis.cpp ------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-10-06 21:00:36 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-c/Analysis.h"
|
2011-08-19 01:36:54 +00:00
|
|
|
#include "llvm-c/Initialization.h"
|
2013-05-01 20:59:00 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2014-01-13 09:26:24 +00:00
|
|
|
#include "llvm/IR/Verifier.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/InitializePasses.h"
|
2013-05-01 20:59:00 +00:00
|
|
|
#include "llvm/PassRegistry.h"
|
2014-03-04 10:07:28 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-02-20 11:08:44 +00:00
|
|
|
#include <cstring>
|
2007-10-06 21:00:36 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2010-10-07 18:31:00 +00: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-25 19:25:40 +00:00
|
|
|
initializeBlockFrequencyInfoPass(Registry);
|
2011-06-04 01:16:30 +00:00
|
|
|
initializeBranchProbabilityInfoPass(Registry);
|
2012-11-02 21:48:17 +00:00
|
|
|
initializeCostModelAnalysisPass(Registry);
|
2010-10-07 18:31:00 +00:00
|
|
|
initializeCFGViewerPass(Registry);
|
|
|
|
initializeCFGPrinterPass(Registry);
|
|
|
|
initializeCFGOnlyViewerPass(Registry);
|
|
|
|
initializeCFGOnlyPrinterPass(Registry);
|
2014-09-02 21:43:13 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165708 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 07:32:34 +00:00
|
|
|
initializeDependenceAnalysisPass(Registry);
|
2013-11-12 22:47:20 +00:00
|
|
|
initializeDelinearizationPass(Registry);
|
2011-01-18 06:06:27 +00:00
|
|
|
initializeDominanceFrontierPass(Registry);
|
2010-10-07 18:31:00 +00: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-05 19:29:43 +00:00
|
|
|
initializeJumpInstrTableInfoPass(Registry);
|
2010-10-07 18:31:00 +00:00
|
|
|
initializeLazyValueInfoPass(Registry);
|
|
|
|
initializeLibCallAliasAnalysisPass(Registry);
|
|
|
|
initializeLintPass(Registry);
|
|
|
|
initializeLoopInfoPass(Registry);
|
|
|
|
initializeMemDepPrinterPass(Registry);
|
|
|
|
initializeMemoryDependenceAnalysisPass(Registry);
|
|
|
|
initializeModuleDebugInfoPrinterPass(Registry);
|
|
|
|
initializePostDominatorTreePass(Registry);
|
2014-07-19 18:29:29 +00:00
|
|
|
initializeRegionInfoPassPass(Registry);
|
2010-10-07 18:31:00 +00:00
|
|
|
initializeRegionViewerPass(Registry);
|
|
|
|
initializeRegionPrinterPass(Registry);
|
|
|
|
initializeRegionOnlyViewerPass(Registry);
|
|
|
|
initializeRegionOnlyPrinterPass(Registry);
|
|
|
|
initializeScalarEvolutionPass(Registry);
|
|
|
|
initializeScalarEvolutionAliasAnalysisPass(Registry);
|
2013-01-07 03:33:08 +00:00
|
|
|
initializeTargetTransformInfoAnalysisGroup(Registry);
|
2010-10-07 18:31:00 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
initializeScopedNoAliasAAPass(Registry);
|
2010-10-07 18:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
|
|
|
|
initializeAnalysis(*unwrap(R));
|
|
|
|
}
|
|
|
|
|
2010-01-09 22:27:07 +00:00
|
|
|
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
|
|
|
|
char **OutMessages) {
|
2014-04-15 04:59:12 +00:00
|
|
|
raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
|
2014-06-26 22:52:05 +00:00
|
|
|
std::string Messages;
|
|
|
|
raw_string_ostream MsgsOS(Messages);
|
2011-01-29 01:09:53 +00:00
|
|
|
|
2014-01-19 02:22:18 +00: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 01:09:53 +00:00
|
|
|
|
2014-06-26 22:52:05 +00:00
|
|
|
if (OutMessages)
|
|
|
|
*OutMessages = strdup(MsgsOS.str().c_str());
|
2011-01-29 01:09:53 +00:00
|
|
|
|
2007-10-06 21:00:36 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-01-09 22:27:07 +00:00
|
|
|
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) {
|
2014-01-19 02:22:18 +00:00
|
|
|
LLVMBool Result = verifyFunction(
|
2014-04-15 04:59:12 +00:00
|
|
|
*unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
|
|
|
|
: nullptr);
|
2014-01-19 02:22:18 +00:00
|
|
|
|
|
|
|
if (Action == LLVMAbortProcessAction && Result)
|
|
|
|
report_fatal_error("Broken function found, compilation aborted!");
|
|
|
|
|
|
|
|
return Result;
|
2007-10-06 21:00:36 +00:00
|
|
|
}
|
|
|
|
|
2008-03-31 16:22:09 +00:00
|
|
|
void LLVMViewFunctionCFG(LLVMValueRef Fn) {
|
|
|
|
Function *F = unwrap<Function>(Fn);
|
|
|
|
F->viewCFG();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) {
|
|
|
|
Function *F = unwrap<Function>(Fn);
|
|
|
|
F->viewCFGOnly();
|
|
|
|
}
|