2014-05-29 09:55:07 +08:00
|
|
|
//===- LoadCombine.cpp - Combine Adjacent Loads ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This transformation combines adjacent loads.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
2014-11-04 07:19:16 +08:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
|
|
|
#include "llvm/Analysis/AliasSetTracker.h"
|
[PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible
with the new pass manager, and no longer relying on analysis groups.
This builds essentially a ground-up new AA infrastructure stack for
LLVM. The core ideas are the same that are used throughout the new pass
manager: type erased polymorphism and direct composition. The design is
as follows:
- FunctionAAResults is a type-erasing alias analysis results aggregation
interface to walk a single query across a range of results from
different alias analyses. Currently this is function-specific as we
always assume that aliasing queries are *within* a function.
- AAResultBase is a CRTP utility providing stub implementations of
various parts of the alias analysis result concept, notably in several
cases in terms of other more general parts of the interface. This can
be used to implement only a narrow part of the interface rather than
the entire interface. This isn't really ideal, this logic should be
hoisted into FunctionAAResults as currently it will cause
a significant amount of redundant work, but it faithfully models the
behavior of the prior infrastructure.
- All the alias analysis passes are ported to be wrapper passes for the
legacy PM and new-style analysis passes for the new PM with a shared
result object. In some cases (most notably CFL), this is an extremely
naive approach that we should revisit when we can specialize for the
new pass manager.
- BasicAA has been restructured to reflect that it is much more
fundamentally a function analysis because it uses dominator trees and
loop info that need to be constructed for each function.
All of the references to getting alias analysis results have been
updated to use the new aggregation interface. All the preservation and
other pass management code has been updated accordingly.
The way the FunctionAAResultsWrapperPass works is to detect the
available alias analyses when run, and add them to the results object.
This means that we should be able to continue to respect when various
passes are added to the pipeline, for example adding CFL or adding TBAA
passes should just cause their results to be available and to get folded
into this. The exception to this rule is BasicAA which really needs to
be a function pass due to using dominator trees and loop info. As
a consequence, the FunctionAAResultsWrapperPass directly depends on
BasicAA and always includes it in the aggregation.
This has significant implications for preserving analyses. Generally,
most passes shouldn't bother preserving FunctionAAResultsWrapperPass
because rebuilding the results just updates the set of known AA passes.
The exception to this rule are LoopPass instances which need to preserve
all the function analyses that the loop pass manager will end up
needing. This means preserving both BasicAAWrapperPass and the
aggregating FunctionAAResultsWrapperPass.
Now, when preserving an alias analysis, you do so by directly preserving
that analysis. This is only necessary for non-immutable-pass-provided
alias analyses though, and there are only three of interest: BasicAA,
GlobalsAA (formerly GlobalsModRef), and SCEVAA. Usually BasicAA is
preserved when needed because it (like DominatorTree and LoopInfo) is
marked as a CFG-only pass. I've expanded GlobalsAA into the preserved
set everywhere we previously were preserving all of AliasAnalysis, and
I've added SCEVAA in the intersection of that with where we preserve
SCEV itself.
One significant challenge to all of this is that the CGSCC passes were
actually using the alias analysis implementations by taking advantage of
a pretty amazing set of loop holes in the old pass manager's analysis
management code which allowed analysis groups to slide through in many
cases. Moving away from analysis groups makes this problem much more
obvious. To fix it, I've leveraged the flexibility the design of the new
PM components provides to just directly construct the relevant alias
analyses for the relevant functions in the IPO passes that need them.
This is a bit hacky, but should go away with the new pass manager, and
is already in many ways cleaner than the prior state.
Another significant challenge is that various facilities of the old
alias analysis infrastructure just don't fit any more. The most
significant of these is the alias analysis 'counter' pass. That pass
relied on the ability to snoop on AA queries at different points in the
analysis group chain. Instead, I'm planning to build printing
functionality directly into the aggregation layer. I've not included
that in this patch merely to keep it smaller.
Note that all of this needs a nearly complete rewrite of the AA
documentation. I'm planning to do that, but I'd like to make sure the
new design settles, and to flesh out a bit more of what it looks like in
the new pass manager first.
Differential Revision: http://reviews.llvm.org/D12080
llvm-svn: 247167
2015-09-10 01:55:00 +08:00
|
|
|
#include "llvm/Analysis/GlobalsModRef.h"
|
2014-05-29 09:55:07 +08:00
|
|
|
#include "llvm/Analysis/TargetFolder.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/IRBuilder.h"
|
2015-03-24 03:32:43 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2015-03-05 02:43:29 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2015-03-24 03:32:43 +08:00
|
|
|
#include "llvm/Pass.h"
|
2014-05-29 09:55:07 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "load-combine"
|
|
|
|
|
|
|
|
STATISTIC(NumLoadsAnalyzed, "Number of loads analyzed for combining");
|
|
|
|
STATISTIC(NumLoadsCombined, "Number of loads combined");
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct PointerOffsetPair {
|
|
|
|
Value *Pointer;
|
|
|
|
uint64_t Offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LoadPOPPair {
|
2015-04-12 02:57:14 +08:00
|
|
|
LoadPOPPair() = default;
|
2014-05-29 09:55:07 +08:00
|
|
|
LoadPOPPair(LoadInst *L, PointerOffsetPair P, unsigned O)
|
|
|
|
: Load(L), POP(P), InsertOrder(O) {}
|
|
|
|
LoadInst *Load;
|
|
|
|
PointerOffsetPair POP;
|
|
|
|
/// \brief The new load needs to be created before the first load in IR order.
|
|
|
|
unsigned InsertOrder;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LoadCombine : public BasicBlockPass {
|
|
|
|
LLVMContext *C;
|
2014-11-04 07:19:16 +08:00
|
|
|
AliasAnalysis *AA;
|
2014-05-29 09:55:07 +08:00
|
|
|
|
|
|
|
public:
|
2015-03-10 10:37:25 +08:00
|
|
|
LoadCombine() : BasicBlockPass(ID), C(nullptr), AA(nullptr) {
|
2015-09-09 17:46:16 +08:00
|
|
|
initializeLoadCombinePass(*PassRegistry::getPassRegistry());
|
2014-05-29 09:55:07 +08:00
|
|
|
}
|
2014-07-31 03:23:59 +08:00
|
|
|
|
|
|
|
using llvm::Pass::doInitialization;
|
2014-05-29 09:55:07 +08:00
|
|
|
bool doInitialization(Function &) override;
|
|
|
|
bool runOnBasicBlock(BasicBlock &BB) override;
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
|
|
|
|
|
|
const char *getPassName() const override { return "LoadCombine"; }
|
|
|
|
static char ID;
|
|
|
|
|
2016-03-14 05:05:13 +08:00
|
|
|
typedef IRBuilder<TargetFolder> BuilderTy;
|
2014-05-29 09:55:07 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
BuilderTy *Builder;
|
|
|
|
|
|
|
|
PointerOffsetPair getPointerOffsetPair(LoadInst &);
|
|
|
|
bool combineLoads(DenseMap<const Value *, SmallVector<LoadPOPPair, 8>> &);
|
|
|
|
bool aggregateLoads(SmallVectorImpl<LoadPOPPair> &);
|
|
|
|
bool combineLoads(SmallVectorImpl<LoadPOPPair> &);
|
|
|
|
};
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2014-05-29 09:55:07 +08:00
|
|
|
|
|
|
|
bool LoadCombine::doInitialization(Function &F) {
|
|
|
|
DEBUG(dbgs() << "LoadCombine function: " << F.getName() << "\n");
|
|
|
|
C = &F.getContext();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PointerOffsetPair LoadCombine::getPointerOffsetPair(LoadInst &LI) {
|
|
|
|
PointerOffsetPair POP;
|
|
|
|
POP.Pointer = LI.getPointerOperand();
|
|
|
|
POP.Offset = 0;
|
|
|
|
while (isa<BitCastInst>(POP.Pointer) || isa<GetElementPtrInst>(POP.Pointer)) {
|
|
|
|
if (auto *GEP = dyn_cast<GetElementPtrInst>(POP.Pointer)) {
|
2015-03-10 10:37:25 +08:00
|
|
|
auto &DL = LI.getModule()->getDataLayout();
|
|
|
|
unsigned BitWidth = DL.getPointerTypeSizeInBits(GEP->getType());
|
2014-05-29 09:55:07 +08:00
|
|
|
APInt Offset(BitWidth, 0);
|
2015-03-10 10:37:25 +08:00
|
|
|
if (GEP->accumulateConstantOffset(DL, Offset))
|
2014-05-29 09:55:07 +08:00
|
|
|
POP.Offset += Offset.getZExtValue();
|
|
|
|
else
|
|
|
|
// Can't handle GEPs with variable indices.
|
|
|
|
return POP;
|
|
|
|
POP.Pointer = GEP->getPointerOperand();
|
|
|
|
} else if (auto *BC = dyn_cast<BitCastInst>(POP.Pointer))
|
|
|
|
POP.Pointer = BC->getOperand(0);
|
|
|
|
}
|
|
|
|
return POP;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoadCombine::combineLoads(
|
|
|
|
DenseMap<const Value *, SmallVector<LoadPOPPair, 8>> &LoadMap) {
|
|
|
|
bool Combined = false;
|
|
|
|
for (auto &Loads : LoadMap) {
|
|
|
|
if (Loads.second.size() < 2)
|
|
|
|
continue;
|
|
|
|
std::sort(Loads.second.begin(), Loads.second.end(),
|
|
|
|
[](const LoadPOPPair &A, const LoadPOPPair &B) {
|
|
|
|
return A.POP.Offset < B.POP.Offset;
|
|
|
|
});
|
|
|
|
if (aggregateLoads(Loads.second))
|
|
|
|
Combined = true;
|
|
|
|
}
|
|
|
|
return Combined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Try to aggregate loads from a sorted list of loads to be combined.
|
|
|
|
///
|
|
|
|
/// It is guaranteed that no writes occur between any of the loads. All loads
|
|
|
|
/// have the same base pointer. There are at least two loads.
|
|
|
|
bool LoadCombine::aggregateLoads(SmallVectorImpl<LoadPOPPair> &Loads) {
|
|
|
|
assert(Loads.size() >= 2 && "Insufficient loads!");
|
|
|
|
LoadInst *BaseLoad = nullptr;
|
|
|
|
SmallVector<LoadPOPPair, 8> AggregateLoads;
|
|
|
|
bool Combined = false;
|
|
|
|
uint64_t PrevOffset = -1ull;
|
|
|
|
uint64_t PrevSize = 0;
|
|
|
|
for (auto &L : Loads) {
|
|
|
|
if (PrevOffset == -1ull) {
|
|
|
|
BaseLoad = L.Load;
|
|
|
|
PrevOffset = L.POP.Offset;
|
2015-03-10 10:37:25 +08:00
|
|
|
PrevSize = L.Load->getModule()->getDataLayout().getTypeStoreSize(
|
|
|
|
L.Load->getType());
|
2014-05-29 09:55:07 +08:00
|
|
|
AggregateLoads.push_back(L);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (L.Load->getAlignment() > BaseLoad->getAlignment())
|
|
|
|
continue;
|
|
|
|
if (L.POP.Offset > PrevOffset + PrevSize) {
|
|
|
|
// No other load will be combinable
|
|
|
|
if (combineLoads(AggregateLoads))
|
|
|
|
Combined = true;
|
|
|
|
AggregateLoads.clear();
|
|
|
|
PrevOffset = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (L.POP.Offset != PrevOffset + PrevSize)
|
|
|
|
// This load is offset less than the size of the last load.
|
|
|
|
// FIXME: We may want to handle this case.
|
|
|
|
continue;
|
|
|
|
PrevOffset = L.POP.Offset;
|
2015-03-10 10:37:25 +08:00
|
|
|
PrevSize = L.Load->getModule()->getDataLayout().getTypeStoreSize(
|
|
|
|
L.Load->getType());
|
2014-05-29 09:55:07 +08:00
|
|
|
AggregateLoads.push_back(L);
|
|
|
|
}
|
|
|
|
if (combineLoads(AggregateLoads))
|
|
|
|
Combined = true;
|
|
|
|
return Combined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Given a list of combinable load. Combine the maximum number of them.
|
|
|
|
bool LoadCombine::combineLoads(SmallVectorImpl<LoadPOPPair> &Loads) {
|
|
|
|
// Remove loads from the end while the size is not a power of 2.
|
|
|
|
unsigned TotalSize = 0;
|
|
|
|
for (const auto &L : Loads)
|
|
|
|
TotalSize += L.Load->getType()->getPrimitiveSizeInBits();
|
|
|
|
while (TotalSize != 0 && !isPowerOf2_32(TotalSize))
|
|
|
|
TotalSize -= Loads.pop_back_val().Load->getType()->getPrimitiveSizeInBits();
|
|
|
|
if (Loads.size() < 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DEBUG({
|
|
|
|
dbgs() << "***** Combining Loads ******\n";
|
|
|
|
for (const auto &L : Loads) {
|
|
|
|
dbgs() << L.POP.Offset << ": " << *L.Load << "\n";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Find first load. This is where we put the new load.
|
|
|
|
LoadPOPPair FirstLP;
|
|
|
|
FirstLP.InsertOrder = -1u;
|
|
|
|
for (const auto &L : Loads)
|
|
|
|
if (L.InsertOrder < FirstLP.InsertOrder)
|
|
|
|
FirstLP = L;
|
|
|
|
|
|
|
|
unsigned AddressSpace =
|
|
|
|
FirstLP.POP.Pointer->getType()->getPointerAddressSpace();
|
|
|
|
|
|
|
|
Builder->SetInsertPoint(FirstLP.Load);
|
|
|
|
Value *Ptr = Builder->CreateConstGEP1_64(
|
|
|
|
Builder->CreatePointerCast(Loads[0].POP.Pointer,
|
|
|
|
Builder->getInt8PtrTy(AddressSpace)),
|
|
|
|
Loads[0].POP.Offset);
|
|
|
|
LoadInst *NewLoad = new LoadInst(
|
|
|
|
Builder->CreatePointerCast(
|
|
|
|
Ptr, PointerType::get(IntegerType::get(Ptr->getContext(), TotalSize),
|
|
|
|
Ptr->getType()->getPointerAddressSpace())),
|
|
|
|
Twine(Loads[0].Load->getName()) + ".combined", false,
|
|
|
|
Loads[0].Load->getAlignment(), FirstLP.Load);
|
|
|
|
|
|
|
|
for (const auto &L : Loads) {
|
|
|
|
Builder->SetInsertPoint(L.Load);
|
|
|
|
Value *V = Builder->CreateExtractInteger(
|
2015-03-10 10:37:25 +08:00
|
|
|
L.Load->getModule()->getDataLayout(), NewLoad,
|
|
|
|
cast<IntegerType>(L.Load->getType()),
|
2014-05-29 09:55:07 +08:00
|
|
|
L.POP.Offset - Loads[0].POP.Offset, "combine.extract");
|
|
|
|
L.Load->replaceAllUsesWith(V);
|
|
|
|
}
|
|
|
|
|
|
|
|
NumLoadsCombined = NumLoadsCombined + Loads.size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoadCombine::runOnBasicBlock(BasicBlock &BB) {
|
2015-03-10 10:37:25 +08:00
|
|
|
if (skipOptnoneFunction(BB))
|
2014-05-29 09:55:07 +08:00
|
|
|
return false;
|
|
|
|
|
[PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible
with the new pass manager, and no longer relying on analysis groups.
This builds essentially a ground-up new AA infrastructure stack for
LLVM. The core ideas are the same that are used throughout the new pass
manager: type erased polymorphism and direct composition. The design is
as follows:
- FunctionAAResults is a type-erasing alias analysis results aggregation
interface to walk a single query across a range of results from
different alias analyses. Currently this is function-specific as we
always assume that aliasing queries are *within* a function.
- AAResultBase is a CRTP utility providing stub implementations of
various parts of the alias analysis result concept, notably in several
cases in terms of other more general parts of the interface. This can
be used to implement only a narrow part of the interface rather than
the entire interface. This isn't really ideal, this logic should be
hoisted into FunctionAAResults as currently it will cause
a significant amount of redundant work, but it faithfully models the
behavior of the prior infrastructure.
- All the alias analysis passes are ported to be wrapper passes for the
legacy PM and new-style analysis passes for the new PM with a shared
result object. In some cases (most notably CFL), this is an extremely
naive approach that we should revisit when we can specialize for the
new pass manager.
- BasicAA has been restructured to reflect that it is much more
fundamentally a function analysis because it uses dominator trees and
loop info that need to be constructed for each function.
All of the references to getting alias analysis results have been
updated to use the new aggregation interface. All the preservation and
other pass management code has been updated accordingly.
The way the FunctionAAResultsWrapperPass works is to detect the
available alias analyses when run, and add them to the results object.
This means that we should be able to continue to respect when various
passes are added to the pipeline, for example adding CFL or adding TBAA
passes should just cause their results to be available and to get folded
into this. The exception to this rule is BasicAA which really needs to
be a function pass due to using dominator trees and loop info. As
a consequence, the FunctionAAResultsWrapperPass directly depends on
BasicAA and always includes it in the aggregation.
This has significant implications for preserving analyses. Generally,
most passes shouldn't bother preserving FunctionAAResultsWrapperPass
because rebuilding the results just updates the set of known AA passes.
The exception to this rule are LoopPass instances which need to preserve
all the function analyses that the loop pass manager will end up
needing. This means preserving both BasicAAWrapperPass and the
aggregating FunctionAAResultsWrapperPass.
Now, when preserving an alias analysis, you do so by directly preserving
that analysis. This is only necessary for non-immutable-pass-provided
alias analyses though, and there are only three of interest: BasicAA,
GlobalsAA (formerly GlobalsModRef), and SCEVAA. Usually BasicAA is
preserved when needed because it (like DominatorTree and LoopInfo) is
marked as a CFG-only pass. I've expanded GlobalsAA into the preserved
set everywhere we previously were preserving all of AliasAnalysis, and
I've added SCEVAA in the intersection of that with where we preserve
SCEV itself.
One significant challenge to all of this is that the CGSCC passes were
actually using the alias analysis implementations by taking advantage of
a pretty amazing set of loop holes in the old pass manager's analysis
management code which allowed analysis groups to slide through in many
cases. Moving away from analysis groups makes this problem much more
obvious. To fix it, I've leveraged the flexibility the design of the new
PM components provides to just directly construct the relevant alias
analyses for the relevant functions in the IPO passes that need them.
This is a bit hacky, but should go away with the new pass manager, and
is already in many ways cleaner than the prior state.
Another significant challenge is that various facilities of the old
alias analysis infrastructure just don't fit any more. The most
significant of these is the alias analysis 'counter' pass. That pass
relied on the ability to snoop on AA queries at different points in the
analysis group chain. Instead, I'm planning to build printing
functionality directly into the aggregation layer. I've not included
that in this patch merely to keep it smaller.
Note that all of this needs a nearly complete rewrite of the AA
documentation. I'm planning to do that, but I'd like to make sure the
new design settles, and to flesh out a bit more of what it looks like in
the new pass manager first.
Differential Revision: http://reviews.llvm.org/D12080
llvm-svn: 247167
2015-09-10 01:55:00 +08:00
|
|
|
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
2014-11-04 07:19:16 +08:00
|
|
|
|
2016-03-14 05:05:13 +08:00
|
|
|
IRBuilder<TargetFolder> TheBuilder(
|
2015-03-10 10:37:25 +08:00
|
|
|
BB.getContext(), TargetFolder(BB.getModule()->getDataLayout()));
|
2014-05-29 09:55:07 +08:00
|
|
|
Builder = &TheBuilder;
|
|
|
|
|
|
|
|
DenseMap<const Value *, SmallVector<LoadPOPPair, 8>> LoadMap;
|
2014-11-04 07:19:16 +08:00
|
|
|
AliasSetTracker AST(*AA);
|
2014-05-29 09:55:07 +08:00
|
|
|
|
|
|
|
bool Combined = false;
|
|
|
|
unsigned Index = 0;
|
|
|
|
for (auto &I : BB) {
|
2014-11-04 07:19:16 +08:00
|
|
|
if (I.mayThrow() || (I.mayWriteToMemory() && AST.containsUnknown(&I))) {
|
2014-05-29 09:55:07 +08:00
|
|
|
if (combineLoads(LoadMap))
|
|
|
|
Combined = true;
|
|
|
|
LoadMap.clear();
|
2014-11-04 07:19:16 +08:00
|
|
|
AST.clear();
|
2014-05-29 09:55:07 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LoadInst *LI = dyn_cast<LoadInst>(&I);
|
|
|
|
if (!LI)
|
|
|
|
continue;
|
|
|
|
++NumLoadsAnalyzed;
|
|
|
|
if (!LI->isSimple() || !LI->getType()->isIntegerTy())
|
|
|
|
continue;
|
|
|
|
auto POP = getPointerOffsetPair(*LI);
|
|
|
|
if (!POP.Pointer)
|
|
|
|
continue;
|
|
|
|
LoadMap[POP.Pointer].push_back(LoadPOPPair(LI, POP, Index++));
|
2014-11-04 07:19:16 +08:00
|
|
|
AST.add(LI);
|
2014-05-29 09:55:07 +08:00
|
|
|
}
|
|
|
|
if (combineLoads(LoadMap))
|
|
|
|
Combined = true;
|
|
|
|
return Combined;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadCombine::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesCFG();
|
2014-11-04 07:19:16 +08:00
|
|
|
|
[PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible
with the new pass manager, and no longer relying on analysis groups.
This builds essentially a ground-up new AA infrastructure stack for
LLVM. The core ideas are the same that are used throughout the new pass
manager: type erased polymorphism and direct composition. The design is
as follows:
- FunctionAAResults is a type-erasing alias analysis results aggregation
interface to walk a single query across a range of results from
different alias analyses. Currently this is function-specific as we
always assume that aliasing queries are *within* a function.
- AAResultBase is a CRTP utility providing stub implementations of
various parts of the alias analysis result concept, notably in several
cases in terms of other more general parts of the interface. This can
be used to implement only a narrow part of the interface rather than
the entire interface. This isn't really ideal, this logic should be
hoisted into FunctionAAResults as currently it will cause
a significant amount of redundant work, but it faithfully models the
behavior of the prior infrastructure.
- All the alias analysis passes are ported to be wrapper passes for the
legacy PM and new-style analysis passes for the new PM with a shared
result object. In some cases (most notably CFL), this is an extremely
naive approach that we should revisit when we can specialize for the
new pass manager.
- BasicAA has been restructured to reflect that it is much more
fundamentally a function analysis because it uses dominator trees and
loop info that need to be constructed for each function.
All of the references to getting alias analysis results have been
updated to use the new aggregation interface. All the preservation and
other pass management code has been updated accordingly.
The way the FunctionAAResultsWrapperPass works is to detect the
available alias analyses when run, and add them to the results object.
This means that we should be able to continue to respect when various
passes are added to the pipeline, for example adding CFL or adding TBAA
passes should just cause their results to be available and to get folded
into this. The exception to this rule is BasicAA which really needs to
be a function pass due to using dominator trees and loop info. As
a consequence, the FunctionAAResultsWrapperPass directly depends on
BasicAA and always includes it in the aggregation.
This has significant implications for preserving analyses. Generally,
most passes shouldn't bother preserving FunctionAAResultsWrapperPass
because rebuilding the results just updates the set of known AA passes.
The exception to this rule are LoopPass instances which need to preserve
all the function analyses that the loop pass manager will end up
needing. This means preserving both BasicAAWrapperPass and the
aggregating FunctionAAResultsWrapperPass.
Now, when preserving an alias analysis, you do so by directly preserving
that analysis. This is only necessary for non-immutable-pass-provided
alias analyses though, and there are only three of interest: BasicAA,
GlobalsAA (formerly GlobalsModRef), and SCEVAA. Usually BasicAA is
preserved when needed because it (like DominatorTree and LoopInfo) is
marked as a CFG-only pass. I've expanded GlobalsAA into the preserved
set everywhere we previously were preserving all of AliasAnalysis, and
I've added SCEVAA in the intersection of that with where we preserve
SCEV itself.
One significant challenge to all of this is that the CGSCC passes were
actually using the alias analysis implementations by taking advantage of
a pretty amazing set of loop holes in the old pass manager's analysis
management code which allowed analysis groups to slide through in many
cases. Moving away from analysis groups makes this problem much more
obvious. To fix it, I've leveraged the flexibility the design of the new
PM components provides to just directly construct the relevant alias
analyses for the relevant functions in the IPO passes that need them.
This is a bit hacky, but should go away with the new pass manager, and
is already in many ways cleaner than the prior state.
Another significant challenge is that various facilities of the old
alias analysis infrastructure just don't fit any more. The most
significant of these is the alias analysis 'counter' pass. That pass
relied on the ability to snoop on AA queries at different points in the
analysis group chain. Instead, I'm planning to build printing
functionality directly into the aggregation layer. I've not included
that in this patch merely to keep it smaller.
Note that all of this needs a nearly complete rewrite of the AA
documentation. I'm planning to do that, but I'd like to make sure the
new design settles, and to flesh out a bit more of what it looks like in
the new pass manager first.
Differential Revision: http://reviews.llvm.org/D12080
llvm-svn: 247167
2015-09-10 01:55:00 +08:00
|
|
|
AU.addRequired<AAResultsWrapperPass>();
|
|
|
|
AU.addPreserved<GlobalsAAWrapperPass>();
|
2014-05-29 09:55:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char LoadCombine::ID = 0;
|
|
|
|
|
|
|
|
BasicBlockPass *llvm::createLoadCombinePass() {
|
|
|
|
return new LoadCombine();
|
|
|
|
}
|
|
|
|
|
2014-11-04 07:19:16 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(LoadCombine, "load-combine", "Combine Adjacent Loads",
|
|
|
|
false, false)
|
[PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible
with the new pass manager, and no longer relying on analysis groups.
This builds essentially a ground-up new AA infrastructure stack for
LLVM. The core ideas are the same that are used throughout the new pass
manager: type erased polymorphism and direct composition. The design is
as follows:
- FunctionAAResults is a type-erasing alias analysis results aggregation
interface to walk a single query across a range of results from
different alias analyses. Currently this is function-specific as we
always assume that aliasing queries are *within* a function.
- AAResultBase is a CRTP utility providing stub implementations of
various parts of the alias analysis result concept, notably in several
cases in terms of other more general parts of the interface. This can
be used to implement only a narrow part of the interface rather than
the entire interface. This isn't really ideal, this logic should be
hoisted into FunctionAAResults as currently it will cause
a significant amount of redundant work, but it faithfully models the
behavior of the prior infrastructure.
- All the alias analysis passes are ported to be wrapper passes for the
legacy PM and new-style analysis passes for the new PM with a shared
result object. In some cases (most notably CFL), this is an extremely
naive approach that we should revisit when we can specialize for the
new pass manager.
- BasicAA has been restructured to reflect that it is much more
fundamentally a function analysis because it uses dominator trees and
loop info that need to be constructed for each function.
All of the references to getting alias analysis results have been
updated to use the new aggregation interface. All the preservation and
other pass management code has been updated accordingly.
The way the FunctionAAResultsWrapperPass works is to detect the
available alias analyses when run, and add them to the results object.
This means that we should be able to continue to respect when various
passes are added to the pipeline, for example adding CFL or adding TBAA
passes should just cause their results to be available and to get folded
into this. The exception to this rule is BasicAA which really needs to
be a function pass due to using dominator trees and loop info. As
a consequence, the FunctionAAResultsWrapperPass directly depends on
BasicAA and always includes it in the aggregation.
This has significant implications for preserving analyses. Generally,
most passes shouldn't bother preserving FunctionAAResultsWrapperPass
because rebuilding the results just updates the set of known AA passes.
The exception to this rule are LoopPass instances which need to preserve
all the function analyses that the loop pass manager will end up
needing. This means preserving both BasicAAWrapperPass and the
aggregating FunctionAAResultsWrapperPass.
Now, when preserving an alias analysis, you do so by directly preserving
that analysis. This is only necessary for non-immutable-pass-provided
alias analyses though, and there are only three of interest: BasicAA,
GlobalsAA (formerly GlobalsModRef), and SCEVAA. Usually BasicAA is
preserved when needed because it (like DominatorTree and LoopInfo) is
marked as a CFG-only pass. I've expanded GlobalsAA into the preserved
set everywhere we previously were preserving all of AliasAnalysis, and
I've added SCEVAA in the intersection of that with where we preserve
SCEV itself.
One significant challenge to all of this is that the CGSCC passes were
actually using the alias analysis implementations by taking advantage of
a pretty amazing set of loop holes in the old pass manager's analysis
management code which allowed analysis groups to slide through in many
cases. Moving away from analysis groups makes this problem much more
obvious. To fix it, I've leveraged the flexibility the design of the new
PM components provides to just directly construct the relevant alias
analyses for the relevant functions in the IPO passes that need them.
This is a bit hacky, but should go away with the new pass manager, and
is already in many ways cleaner than the prior state.
Another significant challenge is that various facilities of the old
alias analysis infrastructure just don't fit any more. The most
significant of these is the alias analysis 'counter' pass. That pass
relied on the ability to snoop on AA queries at different points in the
analysis group chain. Instead, I'm planning to build printing
functionality directly into the aggregation layer. I've not included
that in this patch merely to keep it smaller.
Note that all of this needs a nearly complete rewrite of the AA
documentation. I'm planning to do that, but I'd like to make sure the
new design settles, and to flesh out a bit more of what it looks like in
the new pass manager first.
Differential Revision: http://reviews.llvm.org/D12080
llvm-svn: 247167
2015-09-10 01:55:00 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
|
2014-11-04 07:19:16 +08:00
|
|
|
INITIALIZE_PASS_END(LoadCombine, "load-combine", "Combine Adjacent Loads",
|
|
|
|
false, false)
|
|
|
|
|