mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 18:24:00 +00:00
SLPVectorizer: Lazily allocate the map for block numbering.
There is no point in creating it if we're not going to vectorize anything. Creating the map is expensive as it creates large values. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207916 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -42,6 +42,7 @@
|
|||||||
#include "llvm/Transforms/Utils/GlobalStatus.h"
|
#include "llvm/Transforms/Utils/GlobalStatus.h"
|
||||||
#include "llvm/Transforms/Utils/ModuleUtils.h"
|
#include "llvm/Transforms/Utils/ModuleUtils.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <deque>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
#define DEBUG_TYPE "globalopt"
|
#define DEBUG_TYPE "globalopt"
|
||||||
@ -2166,7 +2167,7 @@ class Evaluator {
|
|||||||
public:
|
public:
|
||||||
Evaluator(const DataLayout *DL, const TargetLibraryInfo *TLI)
|
Evaluator(const DataLayout *DL, const TargetLibraryInfo *TLI)
|
||||||
: DL(DL), TLI(TLI) {
|
: DL(DL), TLI(TLI) {
|
||||||
ValueStack.push_back(make_unique<DenseMap<Value*, Constant*>>());
|
ValueStack.emplace_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
~Evaluator() {
|
~Evaluator() {
|
||||||
@ -2191,13 +2192,13 @@ public:
|
|||||||
|
|
||||||
Constant *getVal(Value *V) {
|
Constant *getVal(Value *V) {
|
||||||
if (Constant *CV = dyn_cast<Constant>(V)) return CV;
|
if (Constant *CV = dyn_cast<Constant>(V)) return CV;
|
||||||
Constant *R = ValueStack.back()->lookup(V);
|
Constant *R = ValueStack.back().lookup(V);
|
||||||
assert(R && "Reference to an uncomputed value!");
|
assert(R && "Reference to an uncomputed value!");
|
||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setVal(Value *V, Constant *C) {
|
void setVal(Value *V, Constant *C) {
|
||||||
(*ValueStack.back())[V] = C;
|
ValueStack.back()[V] = C;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DenseMap<Constant*, Constant*> &getMutatedMemory() const {
|
const DenseMap<Constant*, Constant*> &getMutatedMemory() const {
|
||||||
@ -2212,9 +2213,9 @@ private:
|
|||||||
Constant *ComputeLoadResult(Constant *P);
|
Constant *ComputeLoadResult(Constant *P);
|
||||||
|
|
||||||
/// ValueStack - As we compute SSA register values, we store their contents
|
/// ValueStack - As we compute SSA register values, we store their contents
|
||||||
/// here. The back of the vector contains the current function and the stack
|
/// here. The back of the deque contains the current function and the stack
|
||||||
/// contains the values in the calling frames.
|
/// contains the values in the calling frames.
|
||||||
SmallVector<std::unique_ptr<DenseMap<Value*, Constant*>>, 4> ValueStack;
|
std::deque<DenseMap<Value*, Constant*>> ValueStack;
|
||||||
|
|
||||||
/// CallStack - This is used to detect recursion. In pathological situations
|
/// CallStack - This is used to detect recursion. In pathological situations
|
||||||
/// we could hit exponential behavior, but at least there is nothing
|
/// we could hit exponential behavior, but at least there is nothing
|
||||||
@ -2526,7 +2527,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
|
|||||||
|
|
||||||
Constant *RetVal = nullptr;
|
Constant *RetVal = nullptr;
|
||||||
// Execute the call, if successful, use the return value.
|
// Execute the call, if successful, use the return value.
|
||||||
ValueStack.push_back(make_unique<DenseMap<Value *, Constant *>>());
|
ValueStack.emplace_back();
|
||||||
if (!EvaluateFunction(Callee, RetVal, Formals)) {
|
if (!EvaluateFunction(Callee, RetVal, Formals)) {
|
||||||
DEBUG(dbgs() << "Failed to evaluate function.\n");
|
DEBUG(dbgs() << "Failed to evaluate function.\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -73,8 +73,6 @@ struct BlockNumbering {
|
|||||||
|
|
||||||
BlockNumbering(BasicBlock *Bb) : BB(Bb), Valid(false) {}
|
BlockNumbering(BasicBlock *Bb) : BB(Bb), Valid(false) {}
|
||||||
|
|
||||||
BlockNumbering() : BB(nullptr), Valid(false) {}
|
|
||||||
|
|
||||||
void numberInstructions() {
|
void numberInstructions() {
|
||||||
unsigned Loc = 0;
|
unsigned Loc = 0;
|
||||||
InstrIdx.clear();
|
InstrIdx.clear();
|
||||||
@ -346,17 +344,10 @@ public:
|
|||||||
typedef SmallVector<StoreInst *, 8> StoreList;
|
typedef SmallVector<StoreInst *, 8> StoreList;
|
||||||
|
|
||||||
BoUpSLP(Function *Func, ScalarEvolution *Se, const DataLayout *Dl,
|
BoUpSLP(Function *Func, ScalarEvolution *Se, const DataLayout *Dl,
|
||||||
TargetTransformInfo *Tti, TargetLibraryInfo *TLi, AliasAnalysis *Aa, LoopInfo *Li,
|
TargetTransformInfo *Tti, TargetLibraryInfo *TLi, AliasAnalysis *Aa,
|
||||||
DominatorTree *Dt) :
|
LoopInfo *Li, DominatorTree *Dt)
|
||||||
F(Func), SE(Se), DL(Dl), TTI(Tti), TLI(TLi), AA(Aa), LI(Li), DT(Dt),
|
: F(Func), SE(Se), DL(Dl), TTI(Tti), TLI(TLi), AA(Aa), LI(Li), DT(Dt),
|
||||||
Builder(Se->getContext()) {
|
Builder(Se->getContext()) {}
|
||||||
// Setup the block numbering utility for all of the blocks in the
|
|
||||||
// function.
|
|
||||||
for (Function::iterator it = F->begin(), e = F->end(); it != e; ++it) {
|
|
||||||
BasicBlock *BB = it;
|
|
||||||
BlocksNumbers[BB] = BlockNumbering(BB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Vectorize the tree that starts with the elements in \p VL.
|
/// \brief Vectorize the tree that starts with the elements in \p VL.
|
||||||
/// Returns the vectorized root.
|
/// Returns the vectorized root.
|
||||||
@ -528,6 +519,13 @@ private:
|
|||||||
/// Numbers instructions in different blocks.
|
/// Numbers instructions in different blocks.
|
||||||
DenseMap<BasicBlock *, BlockNumbering> BlocksNumbers;
|
DenseMap<BasicBlock *, BlockNumbering> BlocksNumbers;
|
||||||
|
|
||||||
|
/// \brief Get the corresponding instruction numbering list for a given
|
||||||
|
/// BasicBlock. The list is allocated lazily.
|
||||||
|
BlockNumbering &getBlockNumbering(BasicBlock *BB) {
|
||||||
|
auto I = BlocksNumbers.insert(std::make_pair(BB, BlockNumbering(BB)));
|
||||||
|
return I.first->second;
|
||||||
|
}
|
||||||
|
|
||||||
/// Reduction operators.
|
/// Reduction operators.
|
||||||
ValueSet *RdxOps;
|
ValueSet *RdxOps;
|
||||||
|
|
||||||
@ -715,7 +713,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Make sure that we can schedule this unknown user.
|
// Make sure that we can schedule this unknown user.
|
||||||
BlockNumbering &BN = BlocksNumbers[BB];
|
BlockNumbering &BN = getBlockNumbering(BB);
|
||||||
int UserIndex = BN.getIndex(UI);
|
int UserIndex = BN.getIndex(UI);
|
||||||
if (UserIndex < MyLastIndex) {
|
if (UserIndex < MyLastIndex) {
|
||||||
|
|
||||||
@ -1328,8 +1326,8 @@ Value *BoUpSLP::getSinkBarrier(Instruction *Src, Instruction *Dst) {
|
|||||||
|
|
||||||
int BoUpSLP::getLastIndex(ArrayRef<Value *> VL) {
|
int BoUpSLP::getLastIndex(ArrayRef<Value *> VL) {
|
||||||
BasicBlock *BB = cast<Instruction>(VL[0])->getParent();
|
BasicBlock *BB = cast<Instruction>(VL[0])->getParent();
|
||||||
assert(BB == getSameBlock(VL) && BlocksNumbers.count(BB) && "Invalid block");
|
assert(BB == getSameBlock(VL) && "Invalid block");
|
||||||
BlockNumbering &BN = BlocksNumbers[BB];
|
BlockNumbering &BN = getBlockNumbering(BB);
|
||||||
|
|
||||||
int MaxIdx = BN.getIndex(BB->getFirstNonPHI());
|
int MaxIdx = BN.getIndex(BB->getFirstNonPHI());
|
||||||
for (unsigned i = 0, e = VL.size(); i < e; ++i)
|
for (unsigned i = 0, e = VL.size(); i < e; ++i)
|
||||||
@ -1339,8 +1337,8 @@ int BoUpSLP::getLastIndex(ArrayRef<Value *> VL) {
|
|||||||
|
|
||||||
Instruction *BoUpSLP::getLastInstruction(ArrayRef<Value *> VL) {
|
Instruction *BoUpSLP::getLastInstruction(ArrayRef<Value *> VL) {
|
||||||
BasicBlock *BB = cast<Instruction>(VL[0])->getParent();
|
BasicBlock *BB = cast<Instruction>(VL[0])->getParent();
|
||||||
assert(BB == getSameBlock(VL) && BlocksNumbers.count(BB) && "Invalid block");
|
assert(BB == getSameBlock(VL) && "Invalid block");
|
||||||
BlockNumbering &BN = BlocksNumbers[BB];
|
BlockNumbering &BN = getBlockNumbering(BB);
|
||||||
|
|
||||||
int MaxIdx = BN.getIndex(cast<Instruction>(VL[0]));
|
int MaxIdx = BN.getIndex(cast<Instruction>(VL[0]));
|
||||||
for (unsigned i = 1, e = VL.size(); i < e; ++i)
|
for (unsigned i = 1, e = VL.size(); i < e; ++i)
|
||||||
@ -1762,9 +1760,9 @@ Value *BoUpSLP::vectorizeTree() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Function::iterator it = F->begin(), e = F->end(); it != e; ++it) {
|
for (auto &BN : BlocksNumbers)
|
||||||
BlocksNumbers[it].forget();
|
BN.second.forget();
|
||||||
}
|
|
||||||
Builder.ClearInsertionPoint();
|
Builder.ClearInsertionPoint();
|
||||||
|
|
||||||
return VectorizableTree[0].VectorizedValue;
|
return VectorizableTree[0].VectorizedValue;
|
||||||
|
Reference in New Issue
Block a user