1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

clang-format some files in preparation of coming patch reviews.

llvm-svn: 268583
This commit is contained in:
Dehao Chen 2016-05-05 00:54:54 +00:00
parent de3dbc167b
commit 07daedc517
4 changed files with 719 additions and 762 deletions

View File

@ -42,8 +42,7 @@ struct LICMSafetyInfo {
bool HeaderMayThrow; // Same as previous, but specific to loop header
// Used to update funclet bundle operands.
DenseMap<BasicBlock *, ColorVector> BlockColors;
LICMSafetyInfo() : MayThrow(false), HeaderMayThrow(false)
{}
LICMSafetyInfo() : MayThrow(false), HeaderMayThrow(false) {}
};
/// The RecurrenceDescriptor is used to identify recurrences variables in a
@ -325,8 +324,7 @@ bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE,
/// If ScalarEvolution is passed in, it will be preserved.
///
/// Returns true if any modifications are made to the loop.
bool formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
ScalarEvolution *SE);
bool formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution *SE);
/// \brief Put a loop nest into LCSSA form.
///
@ -403,7 +401,6 @@ void addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
/// All loop passes should call this as part of implementing their \c
/// getAnalysisUsage.
void getLoopAnalysisUsage(AnalysisUsage &AU);
}
#endif

View File

@ -30,7 +30,6 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AliasSetTracker.h"
@ -59,6 +58,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
@ -86,8 +86,7 @@ static bool sink(Instruction &I, const LoopInfo *LI, const DominatorTree *DT,
const Loop *CurLoop, AliasSetTracker *CurAST,
const LICMSafetyInfo *SafetyInfo);
static bool isGuaranteedToExecute(const Instruction &Inst,
const DominatorTree *DT,
const Loop *CurLoop,
const DominatorTree *DT, const Loop *CurLoop,
const LICMSafetyInfo *SafetyInfo);
static bool isSafeToExecuteUnconditionally(const Instruction &Inst,
const DominatorTree *DT,
@ -225,9 +224,9 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
// Loop over all of the alias sets in the tracker object.
for (AliasSet &AS : *CurAST)
Changed |= promoteLoopAccessesToScalars(AS, ExitBlocks, InsertPts,
PIC, LI, DT, TLI, CurLoop,
CurAST, &SafetyInfo);
Changed |=
promoteLoopAccessesToScalars(AS, ExitBlocks, InsertPts, PIC, LI, DT,
TLI, CurLoop, CurAST, &SafetyInfo);
// Once we have promoted values across the loop body we have to recursively
// reform LCSSA as any nested loop may now have values defined within the
@ -275,13 +274,14 @@ bool llvm::sinkRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
AliasSetTracker *CurAST, LICMSafetyInfo *SafetyInfo) {
// Verify inputs.
assert(N != nullptr && AA != nullptr && LI != nullptr &&
DT != nullptr && CurLoop != nullptr && CurAST != nullptr &&
SafetyInfo != nullptr && "Unexpected input to sinkRegion");
assert(N != nullptr && AA != nullptr && LI != nullptr && DT != nullptr &&
CurLoop != nullptr && CurAST != nullptr && SafetyInfo != nullptr &&
"Unexpected input to sinkRegion");
BasicBlock *BB = N->getBlock();
// If this subregion is not in the top level loop at all, exit.
if (!CurLoop->contains(BB)) return false;
if (!CurLoop->contains(BB))
return false;
// We are processing blocks in reverse dfo, so process children first.
bool Changed = false;
@ -291,7 +291,8 @@ bool llvm::sinkRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
// Only need to process the contents of this block if it is not part of a
// subloop (which would already have been processed).
if (inSubLoop(BB,CurLoop,LI)) return Changed;
if (inSubLoop(BB, CurLoop, LI))
return Changed;
for (BasicBlock::iterator II = BB->end(); II != BB->begin();) {
Instruction &I = *--II;
@ -330,14 +331,15 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
DominatorTree *DT, TargetLibraryInfo *TLI, Loop *CurLoop,
AliasSetTracker *CurAST, LICMSafetyInfo *SafetyInfo) {
// Verify inputs.
assert(N != nullptr && AA != nullptr && LI != nullptr &&
DT != nullptr && CurLoop != nullptr && CurAST != nullptr &&
SafetyInfo != nullptr && "Unexpected input to hoistRegion");
assert(N != nullptr && AA != nullptr && LI != nullptr && DT != nullptr &&
CurLoop != nullptr && CurAST != nullptr && SafetyInfo != nullptr &&
"Unexpected input to hoistRegion");
BasicBlock *BB = N->getBlock();
// If this subregion is not in the top level loop at all, exit.
if (!CurLoop->contains(BB)) return false;
if (!CurLoop->contains(BB))
return false;
// Only need to process the contents of this block if it is not part of a
// subloop (which would already have been processed).
@ -364,7 +366,8 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
//
if (CurLoop->hasLoopInvariantOperands(&I) &&
canSinkOrHoistInst(I, AA, DT, TLI, CurLoop, CurAST, SafetyInfo) &&
isSafeToExecuteUnconditionally(I, DT, TLI, CurLoop, SafetyInfo,
isSafeToExecuteUnconditionally(
I, DT, TLI, CurLoop, SafetyInfo,
CurLoop->getLoopPreheader()->getTerminator()))
Changed |= hoist(I, DT, CurLoop, SafetyInfo);
}
@ -392,7 +395,8 @@ void llvm::computeLICMSafetyInfo(LICMSafetyInfo * SafetyInfo, Loop * CurLoop) {
SafetyInfo->MayThrow = SafetyInfo->HeaderMayThrow;
// Iterate over loop instructions and compute safety info.
for (Loop::block_iterator BB = CurLoop->block_begin(),
BBE = CurLoop->block_end(); (BB != BBE) && !SafetyInfo->MayThrow ; ++BB)
BBE = CurLoop->block_end();
(BB != BBE) && !SafetyInfo->MayThrow; ++BB)
for (BasicBlock::iterator I = (*BB)->begin(), E = (*BB)->end();
(I != E) && !SafetyInfo->MayThrow; ++I)
SafetyInfo->MayThrow |= I->mayThrow();
@ -467,7 +471,8 @@ bool canSinkOrHoistInst(Instruction &I, AliasAnalysis *AA, DominatorTree *DT,
break;
}
}
if (!FoundMod) return true;
if (!FoundMod)
return true;
}
// FIXME: This should use mod/ref information to see if we can hoist or
@ -589,7 +594,8 @@ CloneInstructionInExitBlock(Instruction &I, BasicBlock &ExitBlock, PHINode &PN,
}
ExitBlock.getInstList().insert(ExitBlock.getFirstInsertionPt(), New);
if (!I.getName().empty()) New->setName(I.getName() + ".le");
if (!I.getName().empty())
New->setName(I.getName() + ".le");
// Build LCSSA PHI nodes for any in-loop operands. Note that this is
// particularly cheap because we can rip off the PHI node that we're
@ -623,8 +629,10 @@ static bool sink(Instruction &I, const LoopInfo *LI, const DominatorTree *DT,
const LICMSafetyInfo *SafetyInfo) {
DEBUG(dbgs() << "LICM sinking instruction: " << I << "\n");
bool Changed = false;
if (isa<LoadInst>(I)) ++NumMovedLoads;
else if (isa<CallInst>(I)) ++NumMovedCalls;
if (isa<LoadInst>(I))
++NumMovedLoads;
else if (isa<CallInst>(I))
++NumMovedCalls;
++NumSunk;
Changed = true;
@ -688,8 +696,8 @@ static bool sink(Instruction &I, const LoopInfo *LI, const DominatorTree *DT,
static bool hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
const LICMSafetyInfo *SafetyInfo) {
auto *Preheader = CurLoop->getLoopPreheader();
DEBUG(dbgs() << "LICM hoisting to " << Preheader->getName() << ": "
<< I << "\n");
DEBUG(dbgs() << "LICM hoisting to " << Preheader->getName() << ": " << I
<< "\n");
// Metadata can be dependent on conditions we are hoisting above.
// Conservatively strip all metadata on the instruction unless we were
@ -705,8 +713,10 @@ static bool hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
// Move the new node to the Preheader, before its terminator.
I.moveBefore(Preheader->getTerminator());
if (isa<LoadInst>(I)) ++NumMovedLoads;
else if (isa<CallInst>(I)) ++NumMovedCalls;
if (isa<LoadInst>(I))
++NumMovedLoads;
else if (isa<CallInst>(I))
++NumMovedCalls;
++NumHoisted;
return true;
}
@ -727,8 +737,7 @@ static bool isSafeToExecuteUnconditionally(const Instruction &Inst,
}
static bool isGuaranteedToExecute(const Instruction &Inst,
const DominatorTree *DT,
const Loop *CurLoop,
const DominatorTree *DT, const Loop *CurLoop,
const LICMSafetyInfo *SafetyInfo) {
// We have to check to make sure that the instruction dominates all
@ -784,8 +793,7 @@ namespace {
if (!L->contains(BB)) {
// We need to create an LCSSA PHI node for the incoming value and
// store that.
PHINode *PN =
PHINode::Create(I->getType(), PredCache.size(BB),
PHINode *PN = PHINode::Create(I->getType(), PredCache.size(BB),
I->getName() + ".lcssa", &BB->front());
for (BasicBlock *Pred : PredCache.get(BB))
PN->addIncoming(I, Pred);
@ -795,9 +803,8 @@ namespace {
}
public:
LoopPromoter(Value *SP,
ArrayRef<const Instruction *> Insts,
SSAUpdater &S, SmallPtrSetImpl<Value *> &PMA,
LoopPromoter(Value *SP, ArrayRef<const Instruction *> Insts, SSAUpdater &S,
SmallPtrSetImpl<Value *> &PMA,
SmallVectorImpl<BasicBlock *> &LEB,
SmallVectorImpl<Instruction *> &LIP, PredIteratorCache &PIC,
AliasSetTracker &ast, LoopInfo &li, DebugLoc dl, int alignment,
@ -830,7 +837,8 @@ namespace {
StoreInst *NewSI = new StoreInst(LiveInValue, Ptr, InsertPos);
NewSI->setAlignment(Alignment);
NewSI->setDebugLoc(DL);
if (AATags) NewSI->setAAMetadata(AATags);
if (AATags)
NewSI->setAAMetadata(AATags);
}
}
@ -838,9 +846,7 @@ namespace {
// Update alias analysis.
AST.copyValue(LI, V);
}
void instructionDeleted(Instruction *I) const override {
AST.deleteValue(I);
}
void instructionDeleted(Instruction *I) const override { AST.deleteValue(I); }
};
} // end anon namespace
@ -849,19 +855,14 @@ namespace {
/// the stores in the loop, looking for stores to Must pointers which are
/// loop invariant.
///
bool llvm::promoteLoopAccessesToScalars(AliasSet &AS,
SmallVectorImpl<BasicBlock*>&ExitBlocks,
SmallVectorImpl<Instruction*>&InsertPts,
PredIteratorCache &PIC, LoopInfo *LI,
DominatorTree *DT,
const TargetLibraryInfo *TLI,
Loop *CurLoop,
AliasSetTracker *CurAST,
LICMSafetyInfo * SafetyInfo) {
bool llvm::promoteLoopAccessesToScalars(
AliasSet &AS, SmallVectorImpl<BasicBlock *> &ExitBlocks,
SmallVectorImpl<Instruction *> &InsertPts, PredIteratorCache &PIC,
LoopInfo *LI, DominatorTree *DT, const TargetLibraryInfo *TLI,
Loop *CurLoop, AliasSetTracker *CurAST, LICMSafetyInfo *SafetyInfo) {
// Verify inputs.
assert(LI != nullptr && DT != nullptr &&
CurLoop != nullptr && CurAST != nullptr &&
SafetyInfo != nullptr &&
assert(LI != nullptr && DT != nullptr && CurLoop != nullptr &&
CurAST != nullptr && SafetyInfo != nullptr &&
"Unexpected Input to promoteLoopAccessesToScalars");
// We can promote this alias set if it has a store, if it is a "Must" alias
@ -954,10 +955,8 @@ bool llvm::promoteLoopAccessesToScalars(AliasSet &AS,
return Changed;
if (!GuaranteedToExecute && !CanSpeculateLoad)
CanSpeculateLoad =
isSafeToExecuteUnconditionally(*Load, DT, TLI, CurLoop,
SafetyInfo,
Preheader->getTerminator());
CanSpeculateLoad = isSafeToExecuteUnconditionally(
*Load, DT, TLI, CurLoop, SafetyInfo, Preheader->getTerminator());
} else if (const StoreInst *Store = dyn_cast<StoreInst>(UI)) {
// Stores *of* the pointer are not interesting, only stores *to* the
// pointer.
@ -983,16 +982,13 @@ bool llvm::promoteLoopAccessesToScalars(AliasSet &AS,
}
if (!GuaranteedToExecute)
GuaranteedToExecute = isGuaranteedToExecute(*UI, DT,
CurLoop, SafetyInfo);
GuaranteedToExecute =
isGuaranteedToExecute(*UI, DT, CurLoop, SafetyInfo);
if (!GuaranteedToExecute && !CanSpeculateLoad) {
CanSpeculateLoad =
isDereferenceableAndAlignedPointer(Store->getPointerOperand(),
Store->getAlignment(), MDL,
Preheader->getTerminator(),
DT, TLI);
CanSpeculateLoad = isDereferenceableAndAlignedPointer(
Store->getPointerOperand(), Store->getAlignment(), MDL,
Preheader->getTerminator(), DT, TLI);
}
} else
return Changed; // Not a load or store.
@ -1016,8 +1012,8 @@ bool llvm::promoteLoopAccessesToScalars(AliasSet &AS,
// paths which originally didn't have them without violating the memory
// model.
Value *Object = GetUnderlyingObject(SomePtr, MDL);
PromotionIsLegal = isAllocLikeFn(Object, TLI) &&
!PointerMayBeCaptured(Object, true, true);
PromotionIsLegal =
isAllocLikeFn(Object, TLI) && !PointerMayBeCaptured(Object, true, true);
}
if (!PromotionIsLegal)
return Changed;
@ -1038,7 +1034,8 @@ bool llvm::promoteLoopAccessesToScalars(AliasSet &AS,
return Changed;
// Otherwise, this is safe to promote, lets do it!
DEBUG(dbgs() << "LICM: Promoting value stored to in loop: " <<*SomePtr<<'\n');
DEBUG(dbgs() << "LICM: Promoting value stored to in loop: " << *SomePtr
<< '\n');
Changed = true;
++NumPromoted;
@ -1051,18 +1048,17 @@ bool llvm::promoteLoopAccessesToScalars(AliasSet &AS,
// We use the SSAUpdater interface to insert phi nodes as required.
SmallVector<PHINode *, 16> NewPHIs;
SSAUpdater SSA(&NewPHIs);
LoopPromoter Promoter(SomePtr, LoopUses, SSA,
PointerMustAliases, ExitBlocks,
LoopPromoter Promoter(SomePtr, LoopUses, SSA, PointerMustAliases, ExitBlocks,
InsertPts, PIC, *CurAST, *LI, DL, Alignment, AATags);
// Set up the preheader to have a definition of the value. It is the live-out
// value from the preheader that uses in the loop will use.
LoadInst *PreheaderLoad =
new LoadInst(SomePtr, SomePtr->getName()+".promoted",
Preheader->getTerminator());
LoadInst *PreheaderLoad = new LoadInst(
SomePtr, SomePtr->getName() + ".promoted", Preheader->getTerminator());
PreheaderLoad->setAlignment(Alignment);
PreheaderLoad->setDebugLoc(DL);
if (AATags) PreheaderLoad->setAAMetadata(AATags);
if (AATags)
PreheaderLoad->setAAMetadata(AATags);
SSA.AddAvailableValue(Preheader, PreheaderLoad);
// Rewrite all the loads in the loop and remember all the definitions from
@ -1157,7 +1153,6 @@ void LICM::deleteAnalysisLoop(Loop *L) {
LoopToAliasSetMap.erase(L);
}
/// Return true if the body of this loop may store into the memory
/// location pointed to by V.
///
@ -1175,4 +1170,3 @@ static bool inSubLoop(BasicBlock *BB, Loop *CurLoop, LoopInfo *LI) {
assert(CurLoop->contains(BB) && "Only valid if BB is IN the loop");
return LI->getLoopFor(BB) != CurLoop;
}

View File

@ -12,11 +12,10 @@
// counts of loops easily.
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/CodeMetrics.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/LoopUnrollAnalyzer.h"
@ -32,6 +31,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/UnrollLoop.h"
#include <climits>
@ -60,19 +60,20 @@ static cl::opt<unsigned> UnrollMaxIterationsCountToAnalyze(
cl::desc("Don't allow loop unrolling to simulate more than this number of"
"iterations when checking full unroll profitability"));
static cl::opt<unsigned>
UnrollCount("unroll-count", cl::Hidden,
static cl::opt<unsigned> UnrollCount(
"unroll-count", cl::Hidden,
cl::desc("Use this unroll count for all loops including those with "
"unroll_count pragma values, for testing purposes"));
static cl::opt<unsigned>
UnrollMaxCount("unroll-max-count", cl::Hidden,
static cl::opt<unsigned> UnrollMaxCount(
"unroll-max-count", cl::Hidden,
cl::desc("Set the max unroll count for partial and runtime unrolling, for"
"testing purposes"));
static cl::opt<unsigned>
UnrollFullMaxCount("unroll-full-max-count", cl::Hidden,
cl::desc("Set the max unroll count for full unrolling, for testing purposes"));
static cl::opt<unsigned> UnrollFullMaxCount(
"unroll-full-max-count", cl::Hidden,
cl::desc(
"Set the max unroll count for full unrolling, for testing purposes"));
static cl::opt<bool>
UnrollAllowPartial("unroll-allow-partial", cl::Hidden,
@ -83,12 +84,11 @@ static cl::opt<bool>
UnrollRuntime("unroll-runtime", cl::ZeroOrMore, cl::Hidden,
cl::desc("Unroll loops with run-time trip counts"));
static cl::opt<unsigned>
PragmaUnrollThreshold("pragma-unroll-threshold", cl::init(16 * 1024), cl::Hidden,
static cl::opt<unsigned> PragmaUnrollThreshold(
"pragma-unroll-threshold", cl::init(16 * 1024), cl::Hidden,
cl::desc("Unrolled size limit for loops with an unroll(full) or "
"unroll_count pragma."));
/// A magic value for use with the Threshold parameter to indicate
/// that the loop unroll should be performed regardless of how much
/// code expansion would result.
@ -453,7 +453,8 @@ static unsigned UnrollCountPragmaValue(const Loop *L) {
// unrolling pass is run more than once (which it generally is).
static void SetLoopAlreadyUnrolled(Loop *L) {
MDNode *LoopID = L->getLoopID();
if (!LoopID) return;
if (!LoopID)
return;
// First remove any existing loop unrolling metadata.
SmallVector<Metadata *, 4> MDs;
@ -514,9 +515,9 @@ static bool canUnrollCompletely(Loop *L, unsigned Threshold,
(int64_t)UnrolledCost - (int64_t)DynamicCostSavingsDiscount <=
(int64_t)Threshold) {
DEBUG(dbgs() << " Can fully unroll, because unrolling will reduce the "
"expected dynamic cost by " << PercentDynamicCostSaved
<< "% (threshold: " << PercentDynamicCostSavedThreshold
<< "%)\n"
"expected dynamic cost by "
<< PercentDynamicCostSaved << "% (threshold: "
<< PercentDynamicCostSavedThreshold << "%)\n"
<< " and the unrolled cost (" << UnrolledCost
<< ") is less than the max threshold ("
<< DynamicCostSavingsDiscount << ").\n");

File diff suppressed because it is too large Load Diff