Cleanup whitespace
[oota-llvm.git] / lib / Analysis / TargetTransformInfo.cpp
index b23223d56f4c8c6878f76868b8ee94d5f92d27c4..0dcdd12a4099bdbdd00cc3b627679a3eed37a50d 100644 (file)
@@ -9,12 +9,12 @@
 
 #define DEBUG_TYPE "tti"
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/CallSite.h"
 #include "llvm/IR/DataLayout.h"
-#include "llvm/IR/Operator.h"
 #include "llvm/IR/Instruction.h"
-#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Instructions.h"
-#include "llvm/Support/CallSite.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Operator.h"
 #include "llvm/Support/ErrorHandling.h"
 
 using namespace llvm;
@@ -35,16 +35,6 @@ void TargetTransformInfo::pushTTIStack(Pass *P) {
     PTTI->TopTTI = this;
 }
 
-void TargetTransformInfo::popTTIStack() {
-  TopTTI = 0;
-
-  // Walk up the chain and update the top TTI pointer.
-  for (TargetTransformInfo *PTTI = PrevTTI; PTTI; PTTI = PTTI->PrevTTI)
-    PTTI->TopTTI = PrevTTI;
-
-  PrevTTI = 0;
-}
-
 void TargetTransformInfo::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<TargetTransformInfo>();
 }
@@ -158,6 +148,16 @@ unsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
   return PrevTTI->getIntImmCost(Imm, Ty);
 }
 
+unsigned TargetTransformInfo::getIntImmCost(unsigned Opcode, const APInt &Imm,
+                                            Type *Ty) const {
+  return PrevTTI->getIntImmCost(Opcode, Imm, Ty);
+}
+
+unsigned TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, const APInt &Imm,
+                                            Type *Ty) const {
+  return PrevTTI->getIntImmCost(IID, Imm, Ty);
+}
+
 unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
   return PrevTTI->getNumberOfRegisters(Vector);
 }
@@ -224,24 +224,30 @@ unsigned TargetTransformInfo::getAddressComputationCost(Type *Tp,
   return PrevTTI->getAddressComputationCost(Tp, IsComplex);
 }
 
+unsigned TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
+                                               bool IsPairwise) const {
+  return PrevTTI->getReductionCost(Opcode, Ty, IsPairwise);
+}
+
 namespace {
 
-struct NoTTI : ImmutablePass, TargetTransformInfo {
+struct NoTTI final : ImmutablePass, TargetTransformInfo {
   const DataLayout *DL;
 
   NoTTI() : ImmutablePass(ID), DL(0) {
     initializeNoTTIPass(*PassRegistry::getPassRegistry());
   }
 
-  virtual void initializePass() {
+  virtual void initializePass() override {
     // Note that this subclass is special, and must *not* call initializeTTI as
     // it does not chain.
     TopTTI = this;
     PrevTTI = 0;
-    DL = getAnalysisIfAvailable<DataLayout>();
+    DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
+    DL = DLP ? &DLP->getDataLayout() : 0;
   }
 
-  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
     // Note that this subclass is special, and must *not* call
     // TTI::getAnalysisUsage as it breaks the recursion.
   }
@@ -250,13 +256,14 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
   static char ID;
 
   /// Provide necessary pointer adjustments for the two base classes.
-  virtual void *getAdjustedAnalysisPointer(const void *ID) {
+  virtual void *getAdjustedAnalysisPointer(const void *ID) override {
     if (ID == &TargetTransformInfo::ID)
       return (TargetTransformInfo*)this;
     return this;
   }
 
-  unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) const {
+  unsigned getOperationCost(unsigned Opcode, Type *Ty,
+                            Type *OpTy) const override {
     switch (Opcode) {
     default:
       // By default, just classify everything as 'basic'.
@@ -313,7 +320,7 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
   }
 
   unsigned getGEPCost(const Value *Ptr,
-                      ArrayRef<const Value *> Operands) const {
+                      ArrayRef<const Value *> Operands) const override {
     // In the basic model, we just assume that all-constant GEPs will be folded
     // into their uses via addressing modes.
     for (unsigned Idx = 0, Size = Operands.size(); Idx != Size; ++Idx)
@@ -323,7 +330,8 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
     return TCC_Free;
   }
 
-  unsigned getCallCost(FunctionType *FTy, int NumArgs = -1) const {
+  unsigned getCallCost(FunctionType *FTy, int NumArgs = -1) const override
+  {
     assert(FTy && "FunctionType must be provided to this routine.");
 
     // The target-independent implementation just measures the size of the
@@ -338,7 +346,8 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
     return TCC_Basic * (NumArgs + 1);
   }
 
-  unsigned getCallCost(const Function *F, int NumArgs = -1) const {
+  unsigned getCallCost(const Function *F, int NumArgs = -1) const override
+  {
     assert(F && "A concrete function must be provided to this routine.");
 
     if (NumArgs < 0)
@@ -359,7 +368,7 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
   }
 
   unsigned getCallCost(const Function *F,
-                       ArrayRef<const Value *> Arguments) const {
+                       ArrayRef<const Value *> Arguments) const override {
     // Simply delegate to generic handling of the call.
     // FIXME: We should use instsimplify or something else to catch calls which
     // will constant fold with these arguments.
@@ -367,7 +376,7 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
   }
 
   unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
-                            ArrayRef<Type *> ParamTys) const {
+                            ArrayRef<Type *> ParamTys) const override {
     switch (IID) {
     default:
       // Intrinsics rarely (if ever) have normal argument setup constraints.
@@ -389,8 +398,9 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
     }
   }
 
-  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
-                            ArrayRef<const Value *> Arguments) const {
+  unsigned
+  getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
+                   ArrayRef<const Value *> Arguments) const override {
     // Delegate to the generic intrinsic handling code. This mostly provides an
     // opportunity for targets to (for example) special case the cost of
     // certain intrinsics based on constants used as arguments.
@@ -401,7 +411,7 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
     return TopTTI->getIntrinsicCost(IID, RetTy, ParamTys);
   }
 
-  unsigned getUserCost(const User *U) const {
+  unsigned getUserCost(const User *U) const override {
     if (isa<PHINode>(U))
       return TCC_Free; // Model all PHI nodes as free.
 
@@ -418,12 +428,7 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
         return TopTTI->getCallCost(cast<FunctionType>(FTy), CS.arg_size());
       }
 
-      SmallVector<const Value *, 8> Arguments;
-      for (ImmutableCallSite::arg_iterator AI = CS.arg_begin(),
-                                           AE = CS.arg_end();
-           AI != AE; ++AI)
-        Arguments.push_back(*AI);
-
+      SmallVector<const Value *, 8> Arguments(CS.arg_begin(), CS.arg_end());
       return TopTTI->getCallCost(F, Arguments);
     }
 
@@ -441,9 +446,9 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
                                 U->getOperand(0)->getType() : 0);
   }
 
-  bool hasBranchDivergence() const { return false; }
+  bool hasBranchDivergence() const override { return false; }
 
-  bool isLoweredToCall(const Function *F) const {
+  bool isLoweredToCall(const Function *F) const override {
     // FIXME: These should almost certainly not be handled here, and instead
     // handled with the help of TLI or the target itself. This was largely
     // ported from existing analysis heuristics here so that such refactorings
@@ -474,124 +479,138 @@ struct NoTTI : ImmutablePass, TargetTransformInfo {
     return true;
   }
 
-  void getUnrollingPreferences(Loop *, UnrollingPreferences &) const { }
+  void getUnrollingPreferences(Loop *, UnrollingPreferences &) const override {
+  }
 
-  bool isLegalAddImmediate(int64_t Imm) const {
+  bool isLegalAddImmediate(int64_t Imm) const override {
     return false;
   }
 
-  bool isLegalICmpImmediate(int64_t Imm) const {
+  bool isLegalICmpImmediate(int64_t Imm) const override {
     return false;
   }
 
   bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
-                             bool HasBaseReg, int64_t Scale) const {
+                             bool HasBaseReg, int64_t Scale) const override
+  {
     // Guess that reg+reg addressing is allowed. This heuristic is taken from
     // the implementation of LSR.
     return !BaseGV && BaseOffset == 0 && Scale <= 1;
   }
 
   int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
-                           bool HasBaseReg, int64_t Scale) const {
+                           bool HasBaseReg, int64_t Scale) const override {
     // Guess that all legal addressing mode are free.
     if(isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, Scale))
       return 0;
     return -1;
   }
 
-
-  bool isTruncateFree(Type *Ty1, Type *Ty2) const {
+  bool isTruncateFree(Type *Ty1, Type *Ty2) const override {
     return false;
   }
 
-  bool isTypeLegal(Type *Ty) const {
+  bool isTypeLegal(Type *Ty) const override {
     return false;
   }
 
-  unsigned getJumpBufAlignment() const {
+  unsigned getJumpBufAlignment() const override {
     return 0;
   }
 
-  unsigned getJumpBufSize() const {
+  unsigned getJumpBufSize() const override {
     return 0;
   }
 
-  bool shouldBuildLookupTables() const {
+  bool shouldBuildLookupTables() const override {
     return true;
   }
 
-  PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const {
+  PopcntSupportKind
+  getPopcntSupport(unsigned IntTyWidthInBit) const override {
     return PSK_Software;
   }
 
-  bool haveFastSqrt(Type *Ty) const {
+  bool haveFastSqrt(Type *Ty) const override {
     return false;
   }
 
-  unsigned getIntImmCost(const APInt &Imm, Type *Ty) const {
-    return 1;
+  unsigned getIntImmCost(const APInt &Imm, Type *Ty) const override {
+    return TCC_Basic;
   }
 
-  unsigned getNumberOfRegisters(bool Vector) const {
+  unsigned getIntImmCost(unsigned Opcode, const APInt &Imm,
+                         Type *Ty) const override {
+    return TCC_Free;
+  }
+
+  unsigned getIntImmCost(Intrinsic::ID IID, const APInt &Imm,
+                         Type *Ty) const override {
+    return TCC_Free;
+  }
+
+  unsigned getNumberOfRegisters(bool Vector) const override {
     return 8;
   }
 
-  unsigned  getRegisterBitWidth(bool Vector) const {
+  unsigned  getRegisterBitWidth(bool Vector) const override {
     return 32;
   }
 
-  unsigned getMaximumUnrollFactor() const {
+  unsigned getMaximumUnrollFactor() const override {
     return 1;
   }
 
   unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind,
-                                  OperandValueKind) const {
+                                  OperandValueKind) const override {
     return 1;
   }
 
-  unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
-                          int Index = 0, Type *SubTp = 0) const {
+  unsigned getShuffleCost(ShuffleKind Kind, Type *Ty,
+                          int Index = 0, Type *SubTp = 0) const override {
     return 1;
   }
 
   unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
-                            Type *Src) const {
+                            Type *Src) const override {
     return 1;
   }
 
-  unsigned getCFInstrCost(unsigned Opcode) const {
+  unsigned getCFInstrCost(unsigned Opcode) const override {
     return 1;
   }
 
   unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
-                              Type *CondTy = 0) const {
+                              Type *CondTy = 0) const override {
     return 1;
   }
 
   unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
-                              unsigned Index = -1) const {
+                              unsigned Index = -1) const override {
     return 1;
   }
 
-  unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
-                           unsigned Alignment,
-                           unsigned AddressSpace) const {
+  unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
+                           unsigned AddressSpace) const override {
     return 1;
   }
 
-  unsigned getIntrinsicInstrCost(Intrinsic::ID ID,
-                                 Type *RetTy,
-                                 ArrayRef<Type*> Tys) const {
+  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
+                                 ArrayRef<Type*> Tys) const override {
     return 1;
   }
 
-  unsigned getNumberOfParts(Type *Tp) const {
+  unsigned getNumberOfParts(Type *Tp) const override {
     return 0;
   }
 
-  unsigned getAddressComputationCost(Type *Tp, bool) const {
+  unsigned getAddressComputationCost(Type *Tp, bool) const override {
     return 0;
   }
+
+  unsigned getReductionCost(unsigned, Type *, bool) const override {
+    return 1;
+  }
 };
 
 } // end anonymous namespace