summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
diff options
context:
space:
mode:
authorEugene Zelenko <eugene.zelenko@gmail.com>2017-09-13 21:43:53 +0000
committerEugene Zelenko <eugene.zelenko@gmail.com>2017-09-13 21:43:53 +0000
commit8002c504cda71900e6d981d420a3671798f18188 (patch)
tree84b591488acd1b8d41a225202112b69258ea9e11 /llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
parentc0d066468e4b4b0e2fa4c8cda2f7f998afe43d15 (diff)
downloadbcm5719-llvm-8002c504cda71900e6d981d420a3671798f18188.tar.gz
bcm5719-llvm-8002c504cda71900e6d981d420a3671798f18188.zip
[Transforms] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 313198
Diffstat (limited to 'llvm/lib/Transforms/Scalar/ConstantHoisting.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/ConstantHoisting.cpp50
1 files changed, 35 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
index 122c9314e02..58a910ded21 100644
--- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -34,18 +34,38 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Scalar/ConstantHoisting.h"
-#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/BlockFrequencyInfo.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
-#include "llvm/IR/GetElementPtrTypeIterator.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/Value.h"
#include "llvm/Pass.h"
+#include "llvm/Support/BlockFrequency.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/Local.h"
+#include <algorithm>
+#include <cassert>
+#include <cstdint>
+#include <iterator>
#include <tuple>
+#include <utility>
using namespace llvm;
using namespace consthoist;
@@ -62,10 +82,12 @@ static cl::opt<bool> ConstHoistWithBlockFrequency(
"without hoisting."));
namespace {
+
/// \brief The constant hoisting pass.
class ConstantHoistingLegacyPass : public FunctionPass {
public:
static char ID; // Pass identification, replacement for typeid
+
ConstantHoistingLegacyPass() : FunctionPass(ID) {
initializeConstantHoistingLegacyPassPass(*PassRegistry::getPassRegistry());
}
@@ -87,9 +109,11 @@ public:
private:
ConstantHoistingPass Impl;
};
-}
+
+} // end anonymous namespace
char ConstantHoistingLegacyPass::ID = 0;
+
INITIALIZE_PASS_BEGIN(ConstantHoistingLegacyPass, "consthoist",
"Constant Hoisting", false, false)
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
@@ -128,7 +152,6 @@ bool ConstantHoistingLegacyPass::runOnFunction(Function &Fn) {
return MadeChange;
}
-
/// \brief Find the constant materialization insertion point.
Instruction *ConstantHoistingPass::findMatInsertPt(Instruction *Inst,
unsigned Idx) const {
@@ -217,8 +240,9 @@ static void findBestInsertionSet(DominatorTree &DT, BlockFrequencyInfo &BFI,
}
// Visit Orders in bottom-up order.
- typedef std::pair<SmallPtrSet<BasicBlock *, 16>, BlockFrequency>
- InsertPtsCostPair;
+ using InsertPtsCostPair =
+ std::pair<SmallPtrSet<BasicBlock *, 16>, BlockFrequency>;
+
// InsertPtsMap is a map from a BB to the best insertion points for the
// subtree of BB (subtree not including the BB itself).
DenseMap<BasicBlock *, InsertPtsCostPair> InsertPtsMap;
@@ -310,7 +334,6 @@ SmallPtrSet<Instruction *, 8> ConstantHoistingPass::findConstantInsertionPoint(
return InsertPts;
}
-
/// \brief Record constant integer ConstInt for instruction Inst at operand
/// index Idx.
///
@@ -351,7 +374,6 @@ void ConstantHoistingPass::collectConstantCandidates(
}
}
-
/// \brief Check the operand for instruction Inst at index Idx.
void ConstantHoistingPass::collectConstantCandidates(
ConstCandMapType &ConstCandMap, Instruction *Inst, unsigned Idx) {
@@ -393,7 +415,6 @@ void ConstantHoistingPass::collectConstantCandidates(
}
}
-
/// \brief Scan the instruction for expensive integer constants and record them
/// in the constant candidate vector.
void ConstantHoistingPass::collectConstantCandidates(
@@ -427,9 +448,8 @@ void ConstantHoistingPass::collectConstantCandidates(Function &Fn) {
// bit widths (APInt Operator- does not like that). If the value cannot be
// represented in uint64 we return an "empty" APInt. This is then interpreted
// as the value is not in range.
-static llvm::Optional<APInt> calculateOffsetDiff(const APInt &V1,
- const APInt &V2) {
- llvm::Optional<APInt> Res = None;
+static Optional<APInt> calculateOffsetDiff(const APInt &V1, const APInt &V2) {
+ Optional<APInt> Res = None;
unsigned BW = V1.getBitWidth() > V2.getBitWidth() ?
V1.getBitWidth() : V2.getBitWidth();
uint64_t LimVal1 = V1.getLimitedValue();
@@ -496,9 +516,9 @@ ConstantHoistingPass::maximizeConstantsInRange(ConstCandVecType::iterator S,
DEBUG(dbgs() << "Cost: " << Cost << "\n");
for (auto C2 = S; C2 != E; ++C2) {
- llvm::Optional<APInt> Diff = calculateOffsetDiff(
- C2->ConstInt->getValue(),
- ConstCand->ConstInt->getValue());
+ Optional<APInt> Diff = calculateOffsetDiff(
+ C2->ConstInt->getValue(),
+ ConstCand->ConstInt->getValue());
if (Diff) {
const int ImmCosts =
TTI->getIntImmCodeSizeCost(Opcode, OpndIdx, Diff.getValue(), Ty);
OpenPOWER on IntegriCloud