X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FScalar%2FAlignmentFromAssumptions.cpp;h=3c2c0cbc3d2c769b40b78cbd6c73e1b87b96fa2c;hb=dabf510ba1b95298551a310c96e1ae1f681f816a;hp=a662accf69fbe7d54a8148f14fc03149359b99cb;hpb=feae6677424f5d25e084b0525707c033e5ecea5e;p=oota-llvm.git diff --git a/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp b/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp index a662accf69f..3c2c0cbc3d2 100644 --- a/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp +++ b/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp @@ -21,17 +21,17 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/Statistic.h" -#include "llvm/Analysis/AssumptionTracker.h" +#include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/LoopInfo.h" -#include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" +#include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" -#include "llvm/IR/DataLayout.h" +#include "llvm/IR/Module.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -50,17 +50,17 @@ struct AlignmentFromAssumptions : public FunctionPass { initializeAlignmentFromAssumptionsPass(*PassRegistry::getPassRegistry()); } - bool runOnFunction(Function &F); + bool runOnFunction(Function &F) override; - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(); - AU.addRequired(); + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired(); + AU.addRequired(); AU.addRequired(); AU.setPreservesCFG(); - AU.addPreserved(); + AU.addPreserved(); AU.addPreserved(); - AU.addPreserved(); + AU.addPreserved(); } // For memory transfers, we need a common alignment for both the source and @@ -69,10 +69,8 @@ struct AlignmentFromAssumptions : public FunctionPass { // another assumption later, then we may change the alignment at that point. DenseMap NewDestAlignments, NewSrcAlignments; - AssumptionTracker *AT; ScalarEvolution *SE; DominatorTree *DT; - const DataLayout *DL; bool extractAlignmentInfo(CallInst *I, Value *&AAPtr, const SCEV *&AlignSCEV, const SCEV *&OffSCEV); @@ -84,9 +82,9 @@ char AlignmentFromAssumptions::ID = 0; static const char aip_name[] = "Alignment from assumptions"; INITIALIZE_PASS_BEGIN(AlignmentFromAssumptions, AA_NAME, aip_name, false, false) -INITIALIZE_PASS_DEPENDENCY(AssumptionTracker) +INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_DEPENDENCY(ScalarEvolution) +INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass) INITIALIZE_PASS_END(AlignmentFromAssumptions, AA_NAME, aip_name, false, false) @@ -124,7 +122,7 @@ static unsigned getNewAlignmentDiff(const SCEV *DiffSCEV, // If the displacement is not an exact multiple, but the remainder is a // constant, then return this remainder (but only if it is a power of 2). - uint64_t DiffUnitsAbs = abs64(DiffUnits); + uint64_t DiffUnitsAbs = std::abs(DiffUnits); if (isPowerOf2_64(DiffUnitsAbs)) return (unsigned) DiffUnitsAbs; } @@ -141,6 +139,10 @@ static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV, const SCEV *PtrSCEV = SE->getSCEV(Ptr); const SCEV *DiffSCEV = SE->getMinusSCEV(PtrSCEV, AASCEV); + // On 32-bit platforms, DiffSCEV might now have type i32 -- we've always + // sign-extended OffSCEV to i64, so make sure they agree again. + DiffSCEV = SE->getNoopOrSignExtend(DiffSCEV, OffSCEV->getType()); + // What we really want to know is the overall offset to the aligned // address. This address is displaced by the provided offset. DiffSCEV = SE->getMinusSCEV(DiffSCEV, OffSCEV); @@ -179,7 +181,9 @@ static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV, DEBUG(dbgs() << "\tnew start alignment: " << NewAlignment << "\n"); DEBUG(dbgs() << "\tnew inc alignment: " << NewIncAlignment << "\n"); - if (NewAlignment > NewIncAlignment) { + if (!NewAlignment || !NewIncAlignment) { + return 0; + } else if (NewAlignment > NewIncAlignment) { if (NewAlignment % NewIncAlignment == 0) { DEBUG(dbgs() << "\tnew start/inc alignment: " << NewIncAlignment << "\n"); @@ -191,7 +195,7 @@ static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV, NewAlignment << "\n"); return NewAlignment; } - } else if (NewIncAlignment == NewAlignment && NewIncAlignment) { + } else if (NewIncAlignment == NewAlignment) { DEBUG(dbgs() << "\tnew start/inc alignment: " << NewAlignment << "\n"); return NewAlignment; @@ -311,7 +315,7 @@ bool AlignmentFromAssumptions::processAssumption(CallInst *ACall) { continue; if (Instruction *K = dyn_cast(J)) - if (isValidAssumeForContext(ACall, K, DL, DT)) + if (isValidAssumeForContext(ACall, K, DT)) WorkList.push_back(K); } @@ -395,7 +399,7 @@ bool AlignmentFromAssumptions::processAssumption(CallInst *ACall) { Visited.insert(J); for (User *UJ : J->users()) { Instruction *K = cast(UJ); - if (!Visited.count(K) && isValidAssumeForContext(ACall, K, DL, DT)) + if (!Visited.count(K) && isValidAssumeForContext(ACall, K, DT)) WorkList.push_back(K); } } @@ -405,17 +409,16 @@ bool AlignmentFromAssumptions::processAssumption(CallInst *ACall) { bool AlignmentFromAssumptions::runOnFunction(Function &F) { bool Changed = false; - AT = &getAnalysis(); - SE = &getAnalysis(); + auto &AC = getAnalysis().getAssumptionCache(F); + SE = &getAnalysis().getSE(); DT = &getAnalysis().getDomTree(); - DataLayoutPass *DLP = getAnalysisIfAvailable(); - DL = DLP ? &DLP->getDataLayout() : nullptr; NewDestAlignments.clear(); NewSrcAlignments.clear(); - for (auto &I : AT->assumptions(&F)) - Changed |= processAssumption(I); + for (auto &AssumeVH : AC.assumptions()) + if (AssumeVH) + Changed |= processAssumption(cast(AssumeVH)); return Changed; }