[llvm] r316724 - [Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Eugene Zelenko via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 26 18:09:08 PDT 2017
Author: eugenezelenko
Date: Thu Oct 26 18:09:08 2017
New Revision: 316724
URL: http://llvm.org/viewvc/llvm-project?rev=316724&view=rev
Log:
[Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Modified:
llvm/trunk/include/llvm/Transforms/IPO/SCCP.h
llvm/trunk/include/llvm/Transforms/SampleProfile.h
llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/trunk/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
llvm/trunk/lib/Transforms/ObjCARC/BlotMapVector.h
llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
llvm/trunk/lib/Transforms/ObjCARC/PtrState.cpp
llvm/trunk/lib/Transforms/ObjCARC/PtrState.h
llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp
llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp
Modified: llvm/trunk/include/llvm/Transforms/IPO/SCCP.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/SCCP.h?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/SCCP.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/SCCP.h Thu Oct 26 18:09:08 2017
@@ -21,14 +21,18 @@
#ifndef LLVM_TRANSFORMS_IPO_SCCP_H
#define LLVM_TRANSFORMS_IPO_SCCP_H
-#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
+
+class Module;
+
/// Pass to perform interprocedural constant propagation.
class IPSCCPPass : public PassInfoMixin<IPSCCPPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
-}
+
+} // end namespace llvm
+
#endif // LLVM_TRANSFORMS_IPO_SCCP_H
Modified: llvm/trunk/include/llvm/Transforms/SampleProfile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/SampleProfile.h?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/SampleProfile.h (original)
+++ llvm/trunk/include/llvm/Transforms/SampleProfile.h Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===- Transforms/SampleProfile.h - SamplePGO pass--------------*- C++ -*-===//
+//===- Transforms/SampleProfile.h - SamplePGO pass --------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -6,28 +6,35 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+//
/// \file
/// This file provides the interface for the sampled PGO loader pass.
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_SAMPLEPROFILE_H
#define LLVM_TRANSFORMS_SAMPLEPROFILE_H
#include "llvm/IR/PassManager.h"
+#include <string>
namespace llvm {
+class Module;
+
/// The sample profiler data loader pass.
class SampleProfileLoaderPass : public PassInfoMixin<SampleProfileLoaderPass> {
public:
- PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
SampleProfileLoaderPass(std::string File = "", bool IsThinLTOPreLink = false)
: ProfileFileName(File), IsThinLTOPreLink(IsThinLTOPreLink) {}
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+
private:
std::string ProfileFileName;
bool IsThinLTOPreLink;
};
-} // End llvm namespace
-#endif
+} // end namespace llvm
+
+#endif // LLVM_TRANSFORMS_SAMPLEPROFILE_H
Modified: llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===-- Transform/Utils/BasicBlockUtils.h - BasicBlock Utils ----*- C++ -*-===//
+//===- Transform/Utils/BasicBlockUtils.h - BasicBlock Utils -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -25,13 +25,15 @@
namespace llvm {
-class MemoryDependenceResults;
class DominatorTree;
-class LoopInfo;
+class Function;
class Instruction;
+class LoopInfo;
class MDNode;
+class MemoryDependenceResults;
class ReturnInst;
class TargetLibraryInfo;
+class Value;
/// Delete the specified block, which must have no predecessors.
void DeleteDeadBlock(BasicBlock *BB);
@@ -118,7 +120,6 @@ struct CriticalEdgeSplittingOptions {
/// IndirectBrInst. Splitting these edges will almost always create an invalid
/// program because the address of the new block won't be the one that is jumped
/// to.
-///
BasicBlock *SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
const CriticalEdgeSplittingOptions &Options =
CriticalEdgeSplittingOptions());
@@ -194,7 +195,6 @@ BasicBlock *SplitBlock(BasicBlock *Old,
/// no other analyses. In particular, it does not preserve LoopSimplify
/// (because it's complicated to handle the case where one of the edges being
/// split is an exit of a loop with other exits).
-///
BasicBlock *SplitBlockPredecessors(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
const char *Suffix,
DominatorTree *DT = nullptr,
@@ -212,7 +212,6 @@ BasicBlock *SplitBlockPredecessors(Basic
/// no other analyses. In particular, it does not preserve LoopSimplify
/// (because it's complicated to handle the case where one of the edges being
/// split is an exit of a loop with other exits).
-///
void SplitLandingPadPredecessors(BasicBlock *OrigBB,
ArrayRef<BasicBlock *> Preds,
const char *Suffix, const char *Suffix2,
Modified: llvm/trunk/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization --*- C++ -*---------===//
+//===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization ----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -6,6 +6,7 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+//
/// \file
/// This file contains a class ARCRuntimeEntryPoints for use in
/// creating/managing references to entry points to the arc objective c runtime.
@@ -16,15 +17,25 @@
/// WARNING: This file knows about how certain Objective-C library functions are
/// used. Naive LLVM IR transformations which would otherwise be
/// behavior-preserving may break these assumptions.
-///
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
#define LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
-#include "ObjCARC.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/Support/ErrorHandling.h"
+#include <cassert>
namespace llvm {
+
+class Constant;
+class LLVMContext;
+
namespace objcarc {
enum class ARCRuntimeEntryPointKind {
@@ -43,16 +54,7 @@ enum class ARCRuntimeEntryPointKind {
/// lazily to avoid cluttering up the Module with unused declarations.
class ARCRuntimeEntryPoints {
public:
- ARCRuntimeEntryPoints() : TheModule(nullptr),
- AutoreleaseRV(nullptr),
- Release(nullptr),
- Retain(nullptr),
- RetainBlock(nullptr),
- Autorelease(nullptr),
- StoreStrong(nullptr),
- RetainRV(nullptr),
- RetainAutorelease(nullptr),
- RetainAutoreleaseRV(nullptr) { }
+ ARCRuntimeEntryPoints() = default;
void init(Module *M) {
TheModule = M;
@@ -100,26 +102,34 @@ public:
private:
/// Cached reference to the module which we will insert declarations into.
- Module *TheModule;
+ Module *TheModule = nullptr;
/// Declaration for ObjC runtime function objc_autoreleaseReturnValue.
- Constant *AutoreleaseRV;
+ Constant *AutoreleaseRV = nullptr;
+
/// Declaration for ObjC runtime function objc_release.
- Constant *Release;
+ Constant *Release = nullptr;
+
/// Declaration for ObjC runtime function objc_retain.
- Constant *Retain;
+ Constant *Retain = nullptr;
+
/// Declaration for ObjC runtime function objc_retainBlock.
- Constant *RetainBlock;
+ Constant *RetainBlock = nullptr;
+
/// Declaration for ObjC runtime function objc_autorelease.
- Constant *Autorelease;
+ Constant *Autorelease = nullptr;
+
/// Declaration for objc_storeStrong().
- Constant *StoreStrong;
+ Constant *StoreStrong = nullptr;
+
/// Declaration for objc_retainAutoreleasedReturnValue().
- Constant *RetainRV;
+ Constant *RetainRV = nullptr;
+
/// Declaration for objc_retainAutorelease().
- Constant *RetainAutorelease;
+ Constant *RetainAutorelease = nullptr;
+
/// Declaration for objc_retainAutoreleaseReturnValue().
- Constant *RetainAutoreleaseRV;
+ Constant *RetainAutoreleaseRV = nullptr;
Constant *getVoidRetI8XEntryPoint(Constant *&Decl, StringRef Name) {
if (Decl)
@@ -170,10 +180,10 @@ private:
return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
}
+};
-}; // class ARCRuntimeEntryPoints
+} // end namespace objcarc
-} // namespace objcarc
-} // namespace llvm
+} // end namespace llvm
-#endif
+#endif // LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
Modified: llvm/trunk/lib/Transforms/ObjCARC/BlotMapVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/BlotMapVector.h?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/BlotMapVector.h (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/BlotMapVector.h Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===- BlotMapVector.h - A MapVector with the blot operation -*- C++ -*----===//
+//===- BlotMapVector.h - A MapVector with the blot operation ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,30 +7,29 @@
//
//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H
+#define LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H
+
#include "llvm/ADT/DenseMap.h"
-#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <utility>
#include <vector>
namespace llvm {
+
/// \brief An associative container with fast insertion-order (deterministic)
/// iteration over its elements. Plus the special blot operation.
template <class KeyT, class ValueT> class BlotMapVector {
/// Map keys to indices in Vector.
- typedef DenseMap<KeyT, size_t> MapTy;
+ using MapTy = DenseMap<KeyT, size_t>;
MapTy Map;
- typedef std::vector<std::pair<KeyT, ValueT>> VectorTy;
/// Keys and values.
+ using VectorTy = std::vector<std::pair<KeyT, ValueT>>;
VectorTy Vector;
public:
- typedef typename VectorTy::iterator iterator;
- typedef typename VectorTy::const_iterator const_iterator;
- iterator begin() { return Vector.begin(); }
- iterator end() { return Vector.end(); }
- const_iterator begin() const { return Vector.begin(); }
- const_iterator end() const { return Vector.end(); }
-
#ifdef EXPENSIVE_CHECKS
~BlotMapVector() {
assert(Vector.size() >= Map.size()); // May differ due to blotting.
@@ -46,6 +45,14 @@ public:
}
#endif
+ using iterator = typename VectorTy::iterator;
+ using const_iterator = typename VectorTy::const_iterator;
+
+ iterator begin() { return Vector.begin(); }
+ iterator end() { return Vector.end(); }
+ const_iterator begin() const { return Vector.begin(); }
+ const_iterator end() const { return Vector.end(); }
+
ValueT &operator[](const KeyT &Arg) {
std::pair<typename MapTy::iterator, bool> Pair =
Map.insert(std::make_pair(Arg, size_t(0)));
@@ -105,4 +112,7 @@ public:
return Map.empty();
}
};
-} //
+
+} // end namespace llvm
+
+#endif // LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H
Modified: llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp Thu Oct 26 18:09:08 2017
@@ -6,6 +6,7 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+//
/// \file
/// This file defines ObjC ARC optimizations. ARC stands for Automatic
/// Reference Counting and is a system for managing reference counts for objects
@@ -21,7 +22,7 @@
/// WARNING: This file knows about how certain Objective-C library functions are
/// used. Naive LLVM IR transformations which would otherwise be
/// behavior-preserving may break these assumptions.
-///
+//
//===----------------------------------------------------------------------===//
#include "ARCRuntimeEntryPoints.h"
@@ -31,16 +32,41 @@
#include "ProvenanceAnalysis.h"
#include "PtrState.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/ObjCARCAliasAnalysis.h"
+#include "llvm/Analysis/ObjCARCAnalysisUtils.h"
+#include "llvm/Analysis/ObjCARCInstKind.h"
+#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
-#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/CallSite.h"
+#include "llvm/IR/Constant.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include <cassert>
+#include <iterator>
+#include <utility>
using namespace llvm;
using namespace llvm::objcarc;
@@ -147,14 +173,15 @@ STATISTIC(NumReleasesAfterOpt,
#endif
namespace {
+
/// \brief Per-BasicBlock state.
class BBState {
/// The number of unique control paths from the entry which can reach this
/// block.
- unsigned TopDownPathCount;
+ unsigned TopDownPathCount = 0;
/// The number of unique control paths to exits from this block.
- unsigned BottomUpPathCount;
+ unsigned BottomUpPathCount = 0;
/// The top-down traversal uses this to record information known about a
/// pointer at the bottom of each block.
@@ -175,10 +202,10 @@ namespace {
public:
static const unsigned OverflowOccurredValue;
- BBState() : TopDownPathCount(0), BottomUpPathCount(0) { }
+ BBState() = default;
- typedef decltype(PerPtrTopDown)::iterator top_down_ptr_iterator;
- typedef decltype(PerPtrTopDown)::const_iterator const_top_down_ptr_iterator;
+ using top_down_ptr_iterator = decltype(PerPtrTopDown)::iterator;
+ using const_top_down_ptr_iterator = decltype(PerPtrTopDown)::const_iterator;
top_down_ptr_iterator top_down_ptr_begin() { return PerPtrTopDown.begin(); }
top_down_ptr_iterator top_down_ptr_end() { return PerPtrTopDown.end(); }
@@ -192,9 +219,9 @@ namespace {
return !PerPtrTopDown.empty();
}
- typedef decltype(PerPtrBottomUp)::iterator bottom_up_ptr_iterator;
- typedef decltype(
- PerPtrBottomUp)::const_iterator const_bottom_up_ptr_iterator;
+ using bottom_up_ptr_iterator = decltype(PerPtrBottomUp)::iterator;
+ using const_bottom_up_ptr_iterator =
+ decltype(PerPtrBottomUp)::const_iterator;
bottom_up_ptr_iterator bottom_up_ptr_begin() {
return PerPtrBottomUp.begin();
@@ -270,7 +297,8 @@ namespace {
}
// Specialized CFG utilities.
- typedef SmallVectorImpl<BasicBlock *>::const_iterator edge_iterator;
+ using edge_iterator = SmallVectorImpl<BasicBlock *>::const_iterator;
+
edge_iterator pred_begin() const { return Preds.begin(); }
edge_iterator pred_end() const { return Preds.end(); }
edge_iterator succ_begin() const { return Succs.begin(); }
@@ -282,13 +310,16 @@ namespace {
bool isExit() const { return Succs.empty(); }
};
- const unsigned BBState::OverflowOccurredValue = 0xffffffff;
-}
+} // end anonymous namespace
+
+const unsigned BBState::OverflowOccurredValue = 0xffffffff;
namespace llvm {
+
raw_ostream &operator<<(raw_ostream &OS,
BBState &BBState) LLVM_ATTRIBUTE_UNUSED;
-}
+
+} // end namespace llvm
void BBState::InitFromPred(const BBState &Other) {
PerPtrTopDown = Other.PerPtrTopDown;
@@ -391,7 +422,7 @@ raw_ostream &llvm::operator<<(raw_ostrea
// Dump the pointers we are tracking.
OS << " TopDown State:\n";
if (!BBInfo.hasTopDownPtrs()) {
- DEBUG(llvm::dbgs() << " NONE!\n");
+ DEBUG(dbgs() << " NONE!\n");
} else {
for (auto I = BBInfo.top_down_ptr_begin(), E = BBInfo.top_down_ptr_end();
I != E; ++I) {
@@ -411,7 +442,7 @@ raw_ostream &llvm::operator<<(raw_ostrea
OS << " BottomUp State:\n";
if (!BBInfo.hasBottomUpPtrs()) {
- DEBUG(llvm::dbgs() << " NONE!\n");
+ DEBUG(dbgs() << " NONE!\n");
} else {
for (auto I = BBInfo.bottom_up_ptr_begin(), E = BBInfo.bottom_up_ptr_end();
I != E; ++I) {
@@ -513,13 +544,16 @@ namespace {
public:
static char ID;
+
ObjCARCOpt() : FunctionPass(ID) {
initializeObjCARCOptPass(*PassRegistry::getPassRegistry());
}
};
-}
+
+} // end anonymous namespace
char ObjCARCOpt::ID = 0;
+
INITIALIZE_PASS_BEGIN(ObjCARCOpt,
"objc-arc", "ObjC ARC optimization", false, false)
INITIALIZE_PASS_DEPENDENCY(ObjCARCAAWrapperPass)
@@ -643,7 +677,6 @@ void ObjCARCOpt::OptimizeAutoreleaseRVCa
Class = ARCInstKind::Autorelease;
DEBUG(dbgs() << "New: " << *AutoreleaseRV << "\n");
-
}
/// Visit each call, one at a time, and make simplifications without doing any
@@ -692,7 +725,7 @@ void ObjCARCOpt::OptimizeIndividualCalls
new StoreInst(UndefValue::get(cast<PointerType>(Ty)->getElementType()),
Constant::getNullValue(Ty),
CI);
- llvm::Value *NewValue = UndefValue::get(CI->getType());
+ Value *NewValue = UndefValue::get(CI->getType());
DEBUG(dbgs() << "A null pointer-to-weak-pointer is undefined behavior."
"\nOld = " << *CI << "\nNew = " << *NewValue << "\n");
CI->replaceAllUsesWith(NewValue);
@@ -712,7 +745,7 @@ void ObjCARCOpt::OptimizeIndividualCalls
Constant::getNullValue(Ty),
CI);
- llvm::Value *NewValue = UndefValue::get(CI->getType());
+ Value *NewValue = UndefValue::get(CI->getType());
DEBUG(dbgs() << "A null pointer-to-weak-pointer is undefined behavior."
"\nOld = " << *CI << "\nNew = " << *NewValue << "\n");
@@ -1045,12 +1078,11 @@ ObjCARCOpt::CheckForCFGHazards(const Bas
continue;
break;
}
- case S_CanRelease: {
+ case S_CanRelease:
CheckForCanReleaseCFGHazard(SuccSSeq, SuccSRRIKnownSafe, S,
SomeSuccHasSame, AllSuccsHaveSame,
NotAllSeqEqualButKnownSafe);
break;
- }
case S_Retain:
case S_None:
case S_Stop:
@@ -1105,7 +1137,7 @@ bool ObjCARCOpt::VisitInstructionBottomU
// Don't do retain+release tracking for ARCInstKind::RetainRV, because
// it's better to let it remain as the first instruction after a call.
if (Class != ARCInstKind::RetainRV) {
- DEBUG(llvm::dbgs() << " Matching with: " << *Inst << "\n");
+ DEBUG(dbgs() << " Matching with: " << *Inst << "\n");
Retains[Inst] = S.GetRRInfo();
}
S.ClearSequenceProgress();
@@ -1147,7 +1179,6 @@ bool ObjCARCOpt::VisitInstructionBottomU
bool ObjCARCOpt::VisitBottomUp(BasicBlock *BB,
DenseMap<const BasicBlock *, BBState> &BBStates,
BlotMapVector<Value *, RRInfo> &Retains) {
-
DEBUG(dbgs() << "\n== ObjCARCOpt::VisitBottomUp ==\n");
bool NestingDetected = false;
@@ -1171,8 +1202,8 @@ bool ObjCARCOpt::VisitBottomUp(BasicBloc
}
}
- DEBUG(llvm::dbgs() << "Before:\n" << BBStates[BB] << "\n"
- << "Performing Dataflow:\n");
+ DEBUG(dbgs() << "Before:\n" << BBStates[BB] << "\n"
+ << "Performing Dataflow:\n");
// Visit all the instructions, bottom-up.
for (BasicBlock::iterator I = BB->end(), E = BB->begin(); I != E; --I) {
@@ -1197,7 +1228,7 @@ bool ObjCARCOpt::VisitBottomUp(BasicBloc
NestingDetected |= VisitInstructionBottomUp(II, BB, Retains, MyStates);
}
- DEBUG(llvm::dbgs() << "\nFinal State:\n" << BBStates[BB] << "\n");
+ DEBUG(dbgs() << "\nFinal State:\n" << BBStates[BB] << "\n");
return NestingDetected;
}
@@ -1210,7 +1241,7 @@ ObjCARCOpt::VisitInstructionTopDown(Inst
ARCInstKind Class = GetARCInstKind(Inst);
const Value *Arg = nullptr;
- DEBUG(llvm::dbgs() << " Class: " << Class << "\n");
+ DEBUG(dbgs() << " Class: " << Class << "\n");
switch (Class) {
case ARCInstKind::RetainBlock:
@@ -1236,7 +1267,7 @@ ObjCARCOpt::VisitInstructionTopDown(Inst
if (S.MatchWithRelease(MDKindCache, Inst)) {
// If we succeed, copy S's RRInfo into the Release -> {Retain Set
// Map}. Then we clear S.
- DEBUG(llvm::dbgs() << " Matching with: " << *Inst << "\n");
+ DEBUG(dbgs() << " Matching with: " << *Inst << "\n");
Releases[Inst] = S.GetRRInfo();
S.ClearSequenceProgress();
}
@@ -1298,8 +1329,8 @@ ObjCARCOpt::VisitTopDown(BasicBlock *BB,
}
}
- DEBUG(llvm::dbgs() << "Before:\n" << BBStates[BB] << "\n"
- << "Performing Dataflow:\n");
+ DEBUG(dbgs() << "Before:\n" << BBStates[BB] << "\n"
+ << "Performing Dataflow:\n");
// Visit all the instructions, top-down.
for (Instruction &Inst : *BB) {
@@ -1308,10 +1339,10 @@ ObjCARCOpt::VisitTopDown(BasicBlock *BB,
NestingDetected |= VisitInstructionTopDown(&Inst, Releases, MyStates);
}
- DEBUG(llvm::dbgs() << "\nState Before Checking for CFG Hazards:\n"
- << BBStates[BB] << "\n\n");
+ DEBUG(dbgs() << "\nState Before Checking for CFG Hazards:\n"
+ << BBStates[BB] << "\n\n");
CheckForCFGHazards(BB, BBStates, MyStates);
- DEBUG(llvm::dbgs() << "Final State:\n" << BBStates[BB] << "\n");
+ DEBUG(dbgs() << "Final State:\n" << BBStates[BB] << "\n");
return NestingDetected;
}
@@ -1400,7 +1431,6 @@ bool ObjCARCOpt::Visit(Function &F,
DenseMap<const BasicBlock *, BBState> &BBStates,
BlotMapVector<Value *, RRInfo> &Retains,
DenseMap<Value *, RRInfo> &Releases) {
-
// Use reverse-postorder traversals, because we magically know that loops
// will be well behaved, i.e. they won't repeatedly call retain on a single
// pointer without doing a release. We can't use the ReversePostOrderTraversal
@@ -1414,12 +1444,12 @@ bool ObjCARCOpt::Visit(Function &F,
// Use reverse-postorder on the reverse CFG for bottom-up.
bool BottomUpNestingDetected = false;
- for (BasicBlock *BB : reverse(ReverseCFGPostOrder))
+ for (BasicBlock *BB : llvm::reverse(ReverseCFGPostOrder))
BottomUpNestingDetected |= VisitBottomUp(BB, BBStates, Retains);
// Use reverse-postorder for top-down.
bool TopDownNestingDetected = false;
- for (BasicBlock *BB : reverse(PostOrder))
+ for (BasicBlock *BB : llvm::reverse(PostOrder))
TopDownNestingDetected |= VisitTopDown(BB, BBStates, Releases);
return TopDownNestingDetected && BottomUpNestingDetected;
@@ -1476,7 +1506,6 @@ void ObjCARCOpt::MoveCalls(Value *Arg, R
DeadInsts.push_back(OrigRelease);
DEBUG(dbgs() << "Deleting release: " << *OrigRelease << "\n");
}
-
}
bool ObjCARCOpt::PairUpRetainsAndReleases(
@@ -1524,7 +1553,6 @@ bool ObjCARCOpt::PairUpRetainsAndRelease
return false;
if (ReleasesToMove.Calls.insert(NewRetainRelease).second) {
-
// If we overflow when we compute the path count, don't remove/move
// anything.
const BBState &NRRBBState = BBStates[NewRetainRelease->getParent()];
@@ -1651,8 +1679,9 @@ bool ObjCARCOpt::PairUpRetainsAndRelease
// At this point, we are not going to remove any RR pairs, but we still are
// able to move RR pairs. If one of our pointers is afflicted with
// CFGHazards, we cannot perform such code motion so exit early.
- const bool WillPerformCodeMotion = RetainsToMove.ReverseInsertPts.size() ||
- ReleasesToMove.ReverseInsertPts.size();
+ const bool WillPerformCodeMotion =
+ !RetainsToMove.ReverseInsertPts.empty() ||
+ !ReleasesToMove.ReverseInsertPts.empty();
if (CFGHazardAfflicted && WillPerformCodeMotion)
return false;
}
@@ -2064,10 +2093,10 @@ void ObjCARCOpt::OptimizeReturns(Functio
#ifndef NDEBUG
void
ObjCARCOpt::GatherStatistics(Function &F, bool AfterOptimization) {
- llvm::Statistic &NumRetains =
- AfterOptimization? NumRetainsAfterOpt : NumRetainsBeforeOpt;
- llvm::Statistic &NumReleases =
- AfterOptimization? NumReleasesAfterOpt : NumReleasesBeforeOpt;
+ Statistic &NumRetains =
+ AfterOptimization ? NumRetainsAfterOpt : NumRetainsBeforeOpt;
+ Statistic &NumReleases =
+ AfterOptimization ? NumReleasesAfterOpt : NumReleasesBeforeOpt;
for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ) {
Instruction *Inst = &*I++;
Modified: llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp Thu Oct 26 18:09:08 2017
@@ -6,6 +6,7 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+//
/// \file
///
/// This file defines a special form of Alias Analysis called ``Provenance
@@ -19,13 +20,21 @@
/// WARNING: This file knows about how certain Objective-C library functions are
/// used. Naive LLVM IR transformations which would otherwise be
/// behavior-preserving may break these assumptions.
-///
+//
//===----------------------------------------------------------------------===//
#include "ProvenanceAnalysis.h"
-#include "ObjCARC.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/Analysis/ObjCARCAnalysisUtils.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Use.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Support/Casting.h"
+#include <utility>
using namespace llvm;
using namespace llvm::objcarc;
Modified: llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===- ProvenanceAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
+//===- ProvenanceAnalysis.h - ObjC ARC Optimization -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -6,6 +6,7 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+//
/// \file
///
/// This file declares a special form of Alias Analysis called ``Provenance
@@ -19,7 +20,7 @@
/// WARNING: This file knows about how certain Objective-C library functions are
/// used. Naive LLVM IR transformations which would otherwise be
/// behavior-preserving may break these assumptions.
-///
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
@@ -27,15 +28,15 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/Analysis/AliasAnalysis.h"
+#include <utility>
namespace llvm {
- class Value;
- class DataLayout;
- class PHINode;
- class SelectInst;
-}
-namespace llvm {
+class DataLayout;
+class PHINode;
+class SelectInst;
+class Value;
+
namespace objcarc {
/// \brief This is similar to BasicAliasAnalysis, and it uses many of the same
@@ -50,19 +51,19 @@ namespace objcarc {
class ProvenanceAnalysis {
AliasAnalysis *AA;
- typedef std::pair<const Value *, const Value *> ValuePairTy;
- typedef DenseMap<ValuePairTy, bool> CachedResultsTy;
+ using ValuePairTy = std::pair<const Value *, const Value *>;
+ using CachedResultsTy = DenseMap<ValuePairTy, bool>;
+
CachedResultsTy CachedResults;
bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL);
bool relatedSelect(const SelectInst *A, const Value *B);
bool relatedPHI(const PHINode *A, const Value *B);
- void operator=(const ProvenanceAnalysis &) = delete;
- ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;
-
public:
- ProvenanceAnalysis() {}
+ ProvenanceAnalysis() = default;
+ ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;
+ ProvenanceAnalysis &operator=(const ProvenanceAnalysis &) = delete;
void setAA(AliasAnalysis *aa) { AA = aa; }
@@ -76,6 +77,7 @@ public:
};
} // end namespace objcarc
+
} // end namespace llvm
-#endif
+#endif // LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
Modified: llvm/trunk/lib/Transforms/ObjCARC/PtrState.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/PtrState.cpp?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/PtrState.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/PtrState.cpp Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===--- PtrState.cpp -----------------------------------------------------===//
+//===- PtrState.cpp -------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,8 +10,20 @@
#include "PtrState.h"
#include "DependencyAnalysis.h"
#include "ObjCARC.h"
+#include "llvm/Analysis/ObjCARCAnalysisUtils.h"
+#include "llvm/Analysis/ObjCARCInstKind.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include <cassert>
+#include <iterator>
+#include <utility>
using namespace llvm;
using namespace llvm::objcarc;
Modified: llvm/trunk/lib/Transforms/ObjCARC/PtrState.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/PtrState.h?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/PtrState.h (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/PtrState.h Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===--- PtrState.h - ARC State for a Ptr -------------------*- C++ -*-----===//
+//===- PtrState.h - ARC State for a Ptr -------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -19,12 +19,16 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/ObjCARCInstKind.h"
-#include "llvm/IR/Instruction.h"
-#include "llvm/IR/Value.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Compiler.h"
namespace llvm {
+
+class BasicBlock;
+class Instruction;
+class MDNode;
+class raw_ostream;
+class Value;
+
namespace objcarc {
class ARCMDKindCache;
@@ -63,14 +67,14 @@ struct RRInfo {
/// of any intervening side effects.
///
/// KnownSafe is true when either of these conditions is satisfied.
- bool KnownSafe;
+ bool KnownSafe = false;
/// True of the objc_release calls are all marked with the "tail" keyword.
- bool IsTailCallRelease;
+ bool IsTailCallRelease = false;
/// If the Calls are objc_release calls and they all have a
/// clang.imprecise_release tag, this is the metadata tag.
- MDNode *ReleaseMetadata;
+ MDNode *ReleaseMetadata = nullptr;
/// For a top-down sequence, the set of objc_retains or
/// objc_retainBlocks. For bottom-up, the set of objc_releases.
@@ -82,11 +86,9 @@ struct RRInfo {
/// If this is true, we cannot perform code motion but can still remove
/// retain/release pairs.
- bool CFGHazardAfflicted;
+ bool CFGHazardAfflicted = false;
- RRInfo()
- : KnownSafe(false), IsTailCallRelease(false), ReleaseMetadata(nullptr),
- CFGHazardAfflicted(false) {}
+ RRInfo() = default;
void clear();
@@ -100,11 +102,11 @@ struct RRInfo {
class PtrState {
protected:
/// True if the reference count is known to be incremented.
- bool KnownPositiveRefCount;
+ bool KnownPositiveRefCount = false;
/// True if we've seen an opportunity for partial RR elimination, such as
/// pushing calls into a CFG triangle or into one side of a CFG diamond.
- bool Partial;
+ bool Partial = false;
/// The current position in the sequence.
unsigned char Seq : 8;
@@ -112,7 +114,7 @@ protected:
/// Unidirectional information about the current sequence.
RRInfo RRI;
- PtrState() : KnownPositiveRefCount(false), Partial(false), Seq(S_None) {}
+ PtrState() : Seq(S_None) {}
public:
bool IsKnownSafe() const { return RRI.KnownSafe; }
@@ -165,7 +167,7 @@ public:
};
struct BottomUpPtrState : PtrState {
- BottomUpPtrState() : PtrState() {}
+ BottomUpPtrState() = default;
/// (Re-)Initialize this bottom up pointer returning true if we detected a
/// pointer with nested releases.
@@ -186,7 +188,7 @@ struct BottomUpPtrState : PtrState {
};
struct TopDownPtrState : PtrState {
- TopDownPtrState() : PtrState() {}
+ TopDownPtrState() = default;
/// (Re-)Initialize this bottom up pointer returning true if we detected a
/// pointer with nested releases.
@@ -205,6 +207,7 @@ struct TopDownPtrState : PtrState {
};
} // end namespace objcarc
+
} // end namespace llvm
-#endif
+#endif // LLVM_LIB_TRANSFORMS_OBJCARC_PTRSTATE_H
Modified: llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===-- NVPTXInferAddressSpace.cpp - ---------------------*- C++ -*-===//
+//===- InferAddressSpace.cpp - --------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -89,28 +89,54 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constant.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Operator.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/Use.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
+#include "llvm/IR/ValueHandle.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
+#include <cassert>
+#include <iterator>
+#include <limits>
+#include <utility>
+#include <vector>
#define DEBUG_TYPE "infer-address-spaces"
using namespace llvm;
+static const unsigned UninitializedAddressSpace =
+ std::numeric_limits<unsigned>::max();
+
namespace {
-static const unsigned UninitializedAddressSpace = ~0u;
using ValueToAddrSpaceMapTy = DenseMap<const Value *, unsigned>;
@@ -171,13 +197,16 @@ private:
SmallVectorImpl<const Use *> *UndefUsesToFix) const;
unsigned joinAddressSpaces(unsigned AS1, unsigned AS2) const;
};
+
} // end anonymous namespace
char InferAddressSpaces::ID = 0;
namespace llvm {
+
void initializeInferAddressSpacesPass(PassRegistry &);
-}
+
+} // end namespace llvm
INITIALIZE_PASS(InferAddressSpaces, DEBUG_TYPE, "Infer address spaces",
false, false)
@@ -455,11 +484,10 @@ static Value *cloneInstructionWithNewAdd
NewGEP->setIsInBounds(GEP->isInBounds());
return NewGEP;
}
- case Instruction::Select: {
+ case Instruction::Select:
assert(I->getType()->isPointerTy());
return SelectInst::Create(I->getOperand(0), NewPointerOperands[1],
NewPointerOperands[2], "", nullptr, I);
- }
default:
llvm_unreachable("Unexpected opcode");
}
@@ -732,10 +760,9 @@ static bool isSimplePointerUseValidToRep
return OpNo == AtomicRMWInst::getPointerOperandIndex() &&
(VolatileIsAllowed || !RMW->isVolatile());
- if (auto *CmpX = dyn_cast<AtomicCmpXchgInst>(Inst)) {
+ if (auto *CmpX = dyn_cast<AtomicCmpXchgInst>(Inst))
return OpNo == AtomicCmpXchgInst::getPointerOperandIndex() &&
(VolatileIsAllowed || !CmpX->isVolatile());
- }
return false;
}
Modified: llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===-- StraightLineStrengthReduce.cpp - ------------------------*- C++ -*-===//
+//===- StraightLineStrengthReduce.cpp - -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -55,26 +55,45 @@
//
// - When (i' - i) is constant but i and i' are not, we could still perform
// SLSR.
+
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
+#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
+#include <cassert>
+#include <cstdint>
+#include <limits>
#include <list>
#include <vector>
using namespace llvm;
using namespace PatternMatch;
-namespace {
+static const unsigned UnknownAddressSpace =
+ std::numeric_limits<unsigned>::max();
-static const unsigned UnknownAddressSpace = ~0u;
+namespace {
class StraightLineStrengthReduce : public FunctionPass {
public:
@@ -88,20 +107,22 @@ public:
GEP, // &B[..][i * S][..]
};
- Candidate()
- : CandidateKind(Invalid), Base(nullptr), Index(nullptr),
- Stride(nullptr), Ins(nullptr), Basis(nullptr) {}
+ Candidate() = default;
Candidate(Kind CT, const SCEV *B, ConstantInt *Idx, Value *S,
Instruction *I)
- : CandidateKind(CT), Base(B), Index(Idx), Stride(S), Ins(I),
- Basis(nullptr) {}
- Kind CandidateKind;
- const SCEV *Base;
+ : CandidateKind(CT), Base(B), Index(Idx), Stride(S), Ins(I) {}
+
+ Kind CandidateKind = Invalid;
+
+ const SCEV *Base = nullptr;
+
// Note that Index and Stride of a GEP candidate do not necessarily have the
// same integer type. In that case, during rewriting, Stride will be
// sign-extended or truncated to Index's type.
- ConstantInt *Index;
- Value *Stride;
+ ConstantInt *Index = nullptr;
+
+ Value *Stride = nullptr;
+
// The instruction this candidate corresponds to. It helps us to rewrite a
// candidate with respect to its immediate basis. Note that one instruction
// can correspond to multiple candidates depending on how you associate the
@@ -116,16 +137,16 @@ public:
// or
//
// <Base: b, Index: 2, Stride: a + 1>
- Instruction *Ins;
+ Instruction *Ins = nullptr;
+
// Points to the immediate basis of this candidate, or nullptr if we cannot
// find any basis for this candidate.
- Candidate *Basis;
+ Candidate *Basis = nullptr;
};
static char ID;
- StraightLineStrengthReduce()
- : FunctionPass(ID), DL(nullptr), DT(nullptr), TTI(nullptr) {
+ StraightLineStrengthReduce() : FunctionPass(ID) {
initializeStraightLineStrengthReducePass(*PassRegistry::getPassRegistry());
}
@@ -148,46 +169,58 @@ private:
// Returns true if Basis is a basis for C, i.e., Basis dominates C and they
// share the same base and stride.
bool isBasisFor(const Candidate &Basis, const Candidate &C);
+
// Returns whether the candidate can be folded into an addressing mode.
bool isFoldable(const Candidate &C, TargetTransformInfo *TTI,
const DataLayout *DL);
+
// Returns true if C is already in a simplest form and not worth being
// rewritten.
bool isSimplestForm(const Candidate &C);
+
// Checks whether I is in a candidate form. If so, adds all the matching forms
// to Candidates, and tries to find the immediate basis for each of them.
void allocateCandidatesAndFindBasis(Instruction *I);
+
// Allocate candidates and find bases for Add instructions.
void allocateCandidatesAndFindBasisForAdd(Instruction *I);
+
// Given I = LHS + RHS, factors RHS into i * S and makes (LHS + i * S) a
// candidate.
void allocateCandidatesAndFindBasisForAdd(Value *LHS, Value *RHS,
Instruction *I);
// Allocate candidates and find bases for Mul instructions.
void allocateCandidatesAndFindBasisForMul(Instruction *I);
+
// Splits LHS into Base + Index and, if succeeds, calls
// allocateCandidatesAndFindBasis.
void allocateCandidatesAndFindBasisForMul(Value *LHS, Value *RHS,
Instruction *I);
+
// Allocate candidates and find bases for GetElementPtr instructions.
void allocateCandidatesAndFindBasisForGEP(GetElementPtrInst *GEP);
+
// A helper function that scales Idx with ElementSize before invoking
// allocateCandidatesAndFindBasis.
void allocateCandidatesAndFindBasisForGEP(const SCEV *B, ConstantInt *Idx,
Value *S, uint64_t ElementSize,
Instruction *I);
+
// Adds the given form <CT, B, Idx, S> to Candidates, and finds its immediate
// basis.
void allocateCandidatesAndFindBasis(Candidate::Kind CT, const SCEV *B,
ConstantInt *Idx, Value *S,
Instruction *I);
+
// Rewrites candidate C with respect to Basis.
void rewriteCandidateWithBasis(const Candidate &C, const Candidate &Basis);
+
// A helper function that factors ArrayIdx to a product of a stride and a
// constant index, and invokes allocateCandidatesAndFindBasis with the
// factorings.
void factorArrayIndex(Value *ArrayIdx, const SCEV *Base, uint64_t ElementSize,
GetElementPtrInst *GEP);
+
// Emit code that computes the "bump" from Basis to C. If the candidate is a
// GEP and the bump is not divisible by the element size of the GEP, this
// function sets the BumpWithUglyGEP flag to notify its caller to bump the
@@ -196,19 +229,22 @@ private:
IRBuilder<> &Builder, const DataLayout *DL,
bool &BumpWithUglyGEP);
- const DataLayout *DL;
- DominatorTree *DT;
+ const DataLayout *DL = nullptr;
+ DominatorTree *DT = nullptr;
ScalarEvolution *SE;
- TargetTransformInfo *TTI;
+ TargetTransformInfo *TTI = nullptr;
std::list<Candidate> Candidates;
+
// Temporarily holds all instructions that are unlinked (but not deleted) by
// rewriteCandidateWithBasis. These instructions will be actually removed
// after all rewriting finishes.
std::vector<Instruction *> UnlinkedInstructions;
};
-} // anonymous namespace
+
+} // end anonymous namespace
char StraightLineStrengthReduce::ID = 0;
+
INITIALIZE_PASS_BEGIN(StraightLineStrengthReduce, "slsr",
"Straight line strength reduction", false, false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
@@ -650,8 +686,8 @@ void StraightLineStrengthReduce::rewrite
else
Reduced = Builder.CreateGEP(nullptr, Basis.Ins, Bump);
}
+ break;
}
- break;
default:
llvm_unreachable("C.CandidateKind is invalid");
};
Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===-- BasicBlockUtils.cpp - BasicBlock Utilities -------------------------==//
+//===- BasicBlockUtils.cpp - BasicBlock Utilities --------------------------==//
//
// The LLVM Compiler Infrastructure
//
@@ -13,22 +13,34 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
-#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
-#include "llvm/IR/Constant.h"
-#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/CFG.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
-#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Type.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Transforms/Scalar.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Transforms/Utils/Local.h"
-#include <algorithm>
+#include <cassert>
+#include <cstdint>
+#include <string>
+#include <utility>
+#include <vector>
+
using namespace llvm;
void llvm::DeleteDeadBlock(BasicBlock *BB) {
@@ -454,7 +466,7 @@ BasicBlock *llvm::SplitBlockPredecessors
// node becomes an incoming value for BB's phi node. However, if the Preds
// list is empty, we need to insert dummy entries into the PHI nodes in BB to
// account for the newly created predecessor.
- if (Preds.size() == 0) {
+ if (Preds.empty()) {
// Insert dummy values as the incoming value.
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I)
cast<PHINode>(I)->addIncoming(UndefValue::get(I->getType()), NewBB);
@@ -675,7 +687,6 @@ void llvm::SplitBlockAndInsertIfThenElse
ReplaceInstWithInst(HeadOldTerm, HeadNewTerm);
}
-
Value *llvm::GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
BasicBlock *&IfFalse) {
PHINode *SomePHI = dyn_cast<PHINode>(BB->begin());
Modified: llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp Thu Oct 26 18:09:08 2017
@@ -1,4 +1,4 @@
-//===-- UnrollLoopPeel.cpp - Loop peeling utilities -----------------------===//
+//===- UnrollLoopPeel.cpp - Loop peeling utilities ------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -13,29 +13,42 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopIterator.h"
-#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
-#include "llvm/IR/Module.h"
+#include "llvm/Support/Casting.h"
+#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/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/LoopSimplify.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/UnrollLoop.h"
+#include "llvm/Transforms/Utils/ValueMapper.h"
#include <algorithm>
+#include <cassert>
+#include <cstdint>
+#include <limits>
using namespace llvm;
#define DEBUG_TYPE "loop-unroll"
+
STATISTIC(NumPeeled, "Number of loops peeled");
static cl::opt<unsigned> UnrollPeelMaxCount(
@@ -49,7 +62,8 @@ static cl::opt<unsigned> UnrollForcePeel
// Designates that a Phi is estimated to become invariant after an "infinite"
// number of loop iterations (i.e. only may become an invariant if the loop is
// fully unrolled).
-static const unsigned InfiniteIterationsToInvariance = UINT_MAX;
+static const unsigned InfiniteIterationsToInvariance =
+ std::numeric_limits<unsigned>::max();
// Check whether we are capable of peeling this loop.
static bool canPeel(Loop *L) {
@@ -210,8 +224,6 @@ void llvm::computePeelCount(Loop *L, uns
DEBUG(dbgs() << "Max peel cost: " << UP.Threshold << "\n");
}
}
-
- return;
}
/// \brief Update the branch weights of the latch of a peeled-off loop
@@ -236,7 +248,6 @@ void llvm::computePeelCount(Loop *L, uns
static void updateBranchWeights(BasicBlock *Header, BranchInst *LatchBR,
unsigned IterNumber, unsigned AvgIters,
uint64_t &PeeledHeaderWeight) {
-
// FIXME: Pick a more realistic distribution.
// Currently the proportion of weight we assign to the fall-through
// side of the branch drops linearly with the iteration number, and we use
@@ -272,7 +283,6 @@ static void cloneLoopBlocks(Loop *L, uns
LoopBlocksDFS &LoopBlocks, ValueToValueMapTy &VMap,
ValueToValueMapTy &LVMap, DominatorTree *DT,
LoopInfo *LI) {
-
BasicBlock *Header = L->getHeader();
BasicBlock *Latch = L->getLoopLatch();
BasicBlock *PreHeader = L->getLoopPreheader();
Modified: llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp?rev=316724&r1=316723&r2=316724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp Thu Oct 26 18:09:08 2017
@@ -15,16 +15,30 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/IR/Argument.h"
+#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
+#include "llvm/IR/GlobalAlias.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Instruction.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/IPO.h"
+
using namespace llvm;
+static const char *const metaNames[] = {
+ // See http://en.wikipedia.org/wiki/Metasyntactic_variable
+ "foo", "bar", "baz", "quux", "barney", "snork", "zot", "blam", "hoge",
+ "wibble", "wobble", "widget", "wombat", "ham", "eggs", "pluto", "spam"
+};
+
namespace {
// This PRNG is from the ISO C spec. It is intentionally simple and
@@ -43,12 +57,6 @@ namespace {
}
};
- static const char *const metaNames[] = {
- // See http://en.wikipedia.org/wiki/Metasyntactic_variable
- "foo", "bar", "baz", "quux", "barney", "snork", "zot", "blam", "hoge",
- "wibble", "wobble", "widget", "wombat", "ham", "eggs", "pluto", "spam"
- };
-
struct Renamer {
Renamer(unsigned int seed) {
prng.srand(seed);
@@ -62,7 +70,9 @@ namespace {
};
struct MetaRenamer : public ModulePass {
- static char ID; // Pass identification, replacement for typeid
+ // Pass identification, replacement for typeid
+ static char ID;
+
MetaRenamer() : ModulePass(ID) {
initializeMetaRenamerPass(*PassRegistry::getPassRegistry());
}
@@ -148,14 +158,17 @@ namespace {
return true;
}
};
-}
+
+} // end anonymous namespace
char MetaRenamer::ID = 0;
+
INITIALIZE_PASS_BEGIN(MetaRenamer, "metarenamer",
"Assign new names to everything", false, false)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_END(MetaRenamer, "metarenamer",
"Assign new names to everything", false, false)
+
//===----------------------------------------------------------------------===//
//
// MetaRenamer - Rename everything with metasyntactic names.
More information about the llvm-commits
mailing list