summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/Scalarizer.cpp
diff options
context:
space:
mode:
authorEugene Zelenko <eugene.zelenko@gmail.com>2017-10-20 21:47:29 +0000
committerEugene Zelenko <eugene.zelenko@gmail.com>2017-10-20 21:47:29 +0000
commit99241d75c17a524b2be2a12d0d5321d52f6d4116 (patch)
tree6ae53b428471e89833356cf427144f2647c1eed7 /llvm/lib/Transforms/Scalar/Scalarizer.cpp
parent12fd3da9d166b0fc1148f014318218e0542a75b6 (diff)
downloadbcm5719-llvm-99241d75c17a524b2be2a12d0d5321d52f6d4116.tar.gz
bcm5719-llvm-99241d75c17a524b2be2a12d0d5321d52f6d4116.zip
[Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 316241
Diffstat (limited to 'llvm/lib/Transforms/Scalar/Scalarizer.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/Scalarizer.cpp94
1 files changed, 62 insertions, 32 deletions
diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
index d11855f2f3a..34ed126155b 100644
--- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp
+++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
@@ -1,4 +1,4 @@
-//===--- Scalarizer.cpp - Scalarize vector operations ---------------------===//
+//===- Scalarizer.cpp - Scalarize vector operations -----------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -14,36 +14,59 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/VectorUtils.h"
+#include "llvm/IR/Argument.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstVisitor.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/Options.h"
#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+#include <cassert>
+#include <cstdint>
+#include <iterator>
+#include <map>
+#include <utility>
using namespace llvm;
#define DEBUG_TYPE "scalarizer"
namespace {
+
// Used to store the scattered form of a vector.
-typedef SmallVector<Value *, 8> ValueVector;
+using ValueVector = SmallVector<Value *, 8>;
// Used to map a vector Value to its scattered form. We use std::map
// because we want iterators to persist across insertion and because the
// values are relatively large.
-typedef std::map<Value *, ValueVector> ScatterMap;
+using ScatterMap = std::map<Value *, ValueVector>;
// Lists Instructions that have been replaced with scalar implementations,
// along with a pointer to their scattered forms.
-typedef SmallVector<std::pair<Instruction *, ValueVector *>, 16> GatherList;
+using GatherList = SmallVector<std::pair<Instruction *, ValueVector *>, 16>;
// Provides a very limited vector-like interface for lazily accessing one
// component of a scattered vector or vector pointer.
class Scatterer {
public:
- Scatterer() {}
+ Scatterer() = default;
// Scatter V into Size components. If new instructions are needed,
// insert them before BBI in BB. If Cache is nonnull, use it to cache
@@ -71,10 +94,12 @@ private:
// called Name that compares X and Y in the same way as FCI.
struct FCmpSplitter {
FCmpSplitter(FCmpInst &fci) : FCI(fci) {}
+
Value *operator()(IRBuilder<> &Builder, Value *Op0, Value *Op1,
const Twine &Name) const {
return Builder.CreateFCmp(FCI.getPredicate(), Op0, Op1, Name);
}
+
FCmpInst &FCI;
};
@@ -82,10 +107,12 @@ struct FCmpSplitter {
// called Name that compares X and Y in the same way as ICI.
struct ICmpSplitter {
ICmpSplitter(ICmpInst &ici) : ICI(ici) {}
+
Value *operator()(IRBuilder<> &Builder, Value *Op0, Value *Op1,
const Twine &Name) const {
return Builder.CreateICmp(ICI.getPredicate(), Op0, Op1, Name);
}
+
ICmpInst &ICI;
};
@@ -93,16 +120,18 @@ struct ICmpSplitter {
// a binary operator like BO called Name with operands X and Y.
struct BinarySplitter {
BinarySplitter(BinaryOperator &bo) : BO(bo) {}
+
Value *operator()(IRBuilder<> &Builder, Value *Op0, Value *Op1,
const Twine &Name) const {
return Builder.CreateBinOp(BO.getOpcode(), Op0, Op1, Name);
}
+
BinaryOperator &BO;
};
// Information about a load or store that we're scalarizing.
struct VectorLayout {
- VectorLayout() : VecTy(nullptr), ElemTy(nullptr), VecAlign(0), ElemSize(0) {}
+ VectorLayout() = default;
// Return the alignment of element I.
uint64_t getElemAlign(unsigned I) {
@@ -110,16 +139,16 @@ struct VectorLayout {
}
// The type of the vector.
- VectorType *VecTy;
+ VectorType *VecTy = nullptr;
// The type of each element.
- Type *ElemTy;
+ Type *ElemTy = nullptr;
// The alignment of the vector.
- uint64_t VecAlign;
+ uint64_t VecAlign = 0;
// The size of each element.
- uint64_t ElemSize;
+ uint64_t ElemSize = 0;
};
class Scalarizer : public FunctionPass,
@@ -127,8 +156,7 @@ class Scalarizer : public FunctionPass,
public:
static char ID;
- Scalarizer() :
- FunctionPass(ID) {
+ Scalarizer() : FunctionPass(ID) {
initializeScalarizerPass(*PassRegistry::getPassRegistry());
}
@@ -137,19 +165,19 @@ public:
// InstVisitor methods. They return true if the instruction was scalarized,
// false if nothing changed.
- bool visitInstruction(Instruction &) { return false; }
+ bool visitInstruction(Instruction &I) { return false; }
bool visitSelectInst(SelectInst &SI);
- bool visitICmpInst(ICmpInst &);
- bool visitFCmpInst(FCmpInst &);
- bool visitBinaryOperator(BinaryOperator &);
- bool visitGetElementPtrInst(GetElementPtrInst &);
- bool visitCastInst(CastInst &);
- bool visitBitCastInst(BitCastInst &);
- bool visitShuffleVectorInst(ShuffleVectorInst &);
- bool visitPHINode(PHINode &);
- bool visitLoadInst(LoadInst &);
- bool visitStoreInst(StoreInst &);
- bool visitCallInst(CallInst &I);
+ bool visitICmpInst(ICmpInst &ICI);
+ bool visitFCmpInst(FCmpInst &FCI);
+ bool visitBinaryOperator(BinaryOperator &BO);
+ bool visitGetElementPtrInst(GetElementPtrInst &GEPI);
+ bool visitCastInst(CastInst &CI);
+ bool visitBitCastInst(BitCastInst &BCI);
+ bool visitShuffleVectorInst(ShuffleVectorInst &SVI);
+ bool visitPHINode(PHINode &PHI);
+ bool visitLoadInst(LoadInst &LI);
+ bool visitStoreInst(StoreInst &SI);
+ bool visitCallInst(CallInst &ICI);
static void registerOptions() {
// This is disabled by default because having separate loads and stores
@@ -162,11 +190,12 @@ public:
}
private:
- Scatterer scatter(Instruction *, Value *);
- void gather(Instruction *, const ValueVector &);
+ Scatterer scatter(Instruction *Point, Value *V);
+ void gather(Instruction *Op, const ValueVector &CV);
bool canTransferMetadata(unsigned Kind);
- void transferMetadata(Instruction *, const ValueVector &);
- bool getVectorLayout(Type *, unsigned, VectorLayout &, const DataLayout &);
+ void transferMetadata(Instruction *Op, const ValueVector &CV);
+ bool getVectorLayout(Type *Ty, unsigned Alignment, VectorLayout &Layout,
+ const DataLayout &DL);
bool finish();
template<typename T> bool splitBinary(Instruction &, const T &);
@@ -179,9 +208,10 @@ private:
bool ScalarizeLoadStore;
};
-char Scalarizer::ID = 0;
} // end anonymous namespace
+char Scalarizer::ID = 0;
+
INITIALIZE_PASS_WITH_OPTIONS(Scalarizer, "scalarizer",
"Scalarize vector operations", false, false)
@@ -222,7 +252,7 @@ Value *Scatterer::operator[](unsigned I) {
// Search through a chain of InsertElementInsts looking for element I.
// Record other elements in the cache. The new V is still suitable
// for all uncached indices.
- for (;;) {
+ while (true) {
InsertElementInst *Insert = dyn_cast<InsertElementInst>(V);
if (!Insert)
break;
OpenPOWER on IntegriCloud