summaryrefslogtreecommitdiff
path: root/lib/Target
diff options
context:
space:
mode:
authorJuergen Ributzka <juergen@apple.com>2014-01-25 02:02:55 +0000
committerJuergen Ributzka <juergen@apple.com>2014-01-25 02:02:55 +0000
commit943ce55f395ded8654a9a84ac8fc0fc9ee61483a (patch)
tree497606f0f3802860015cb8f702bcaf071c417838 /lib/Target
parent1d1670227b5c2db7054f6fd70cc46c86914eaf53 (diff)
downloadllvm-943ce55f395ded8654a9a84ac8fc0fc9ee61483a.tar.gz
llvm-943ce55f395ded8654a9a84ac8fc0fc9ee61483a.tar.bz2
llvm-943ce55f395ded8654a9a84ac8fc0fc9ee61483a.tar.xz
Revert "Revert "Add Constant Hoisting Pass" (r200034)"
This reverts commit r200058 and adds the using directive for ARMTargetTransformInfo to silence two g++ overload warnings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200062 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r--lib/Target/ARM/ARMTargetTransformInfo.cpp2
-rw-r--r--lib/Target/X86/X86TargetTransformInfo.cpp95
2 files changed, 96 insertions, 1 deletions
diff --git a/lib/Target/ARM/ARMTargetTransformInfo.cpp b/lib/Target/ARM/ARMTargetTransformInfo.cpp
index 75247dfe35..25caa11b92 100644
--- a/lib/Target/ARM/ARMTargetTransformInfo.cpp
+++ b/lib/Target/ARM/ARMTargetTransformInfo.cpp
@@ -76,7 +76,7 @@ public:
/// \name Scalar TTI Implementations
/// @{
-
+ using TargetTransformInfo::getIntImmCost;
virtual unsigned
getIntImmCost(const APInt &Imm, Type *Ty) const LLVM_OVERRIDE;
diff --git a/lib/Target/X86/X86TargetTransformInfo.cpp b/lib/Target/X86/X86TargetTransformInfo.cpp
index da2b021da9..781be2fddd 100644
--- a/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -18,6 +18,7 @@
#include "X86.h"
#include "X86TargetMachine.h"
#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Support/Debug.h"
#include "llvm/Target/CostTable.h"
#include "llvm/Target/TargetLowering.h"
@@ -107,6 +108,14 @@ public:
virtual unsigned getReductionCost(unsigned Opcode, Type *Ty,
bool IsPairwiseForm) const LLVM_OVERRIDE;
+ virtual unsigned getIntImmCost(const APInt &Imm,
+ Type *Ty) const LLVM_OVERRIDE;
+
+ virtual unsigned getIntImmCost(unsigned Opcode, const APInt &Imm,
+ Type *Ty) const LLVM_OVERRIDE;
+ virtual unsigned getIntImmCost(Intrinsic::ID IID, const APInt &Imm,
+ Type *Ty) const LLVM_OVERRIDE;
+
/// @}
};
@@ -694,3 +703,89 @@ unsigned X86TTI::getReductionCost(unsigned Opcode, Type *ValTy,
return TargetTransformInfo::getReductionCost(Opcode, ValTy, IsPairwise);
}
+unsigned X86TTI::getIntImmCost(const APInt &Imm, Type *Ty) const {
+ assert(Ty->isIntegerTy());
+
+ unsigned BitSize = Ty->getPrimitiveSizeInBits();
+ if (BitSize == 0)
+ return ~0U;
+
+ if (Imm.getBitWidth() <= 64 &&
+ (isInt<32>(Imm.getSExtValue()) || isUInt<32>(Imm.getZExtValue())))
+ return TCC_Basic;
+ else
+ return 2 * TCC_Basic;
+}
+
+unsigned X86TTI::getIntImmCost(unsigned Opcode, const APInt &Imm,
+ Type *Ty) const {
+ assert(Ty->isIntegerTy());
+
+ unsigned BitSize = Ty->getPrimitiveSizeInBits();
+ if (BitSize == 0)
+ return ~0U;
+
+ switch (Opcode) {
+ case Instruction::Add:
+ case Instruction::Sub:
+ case Instruction::Mul:
+ case Instruction::UDiv:
+ case Instruction::SDiv:
+ case Instruction::URem:
+ case Instruction::SRem:
+ case Instruction::Shl:
+ case Instruction::LShr:
+ case Instruction::AShr:
+ case Instruction::And:
+ case Instruction::Or:
+ case Instruction::Xor:
+ case Instruction::ICmp:
+ if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
+ return TCC_Free;
+ else
+ return X86TTI::getIntImmCost(Imm, Ty);
+ case Instruction::Trunc:
+ case Instruction::ZExt:
+ case Instruction::SExt:
+ case Instruction::IntToPtr:
+ case Instruction::PtrToInt:
+ case Instruction::BitCast:
+ case Instruction::Call:
+ case Instruction::Select:
+ case Instruction::Ret:
+ case Instruction::Load:
+ case Instruction::Store:
+ return X86TTI::getIntImmCost(Imm, Ty);
+ }
+ return TargetTransformInfo::getIntImmCost(Opcode, Imm, Ty);
+}
+
+unsigned X86TTI::getIntImmCost(Intrinsic::ID IID, const APInt &Imm,
+ Type *Ty) const {
+ assert(Ty->isIntegerTy());
+
+ unsigned BitSize = Ty->getPrimitiveSizeInBits();
+ if (BitSize == 0)
+ return ~0U;
+
+ switch (IID) {
+ default: return TargetTransformInfo::getIntImmCost(IID, Imm, Ty);
+ case Intrinsic::sadd_with_overflow:
+ case Intrinsic::uadd_with_overflow:
+ case Intrinsic::ssub_with_overflow:
+ case Intrinsic::usub_with_overflow:
+ case Intrinsic::smul_with_overflow:
+ case Intrinsic::umul_with_overflow:
+ if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
+ return TCC_Free;
+ else
+ return X86TTI::getIntImmCost(Imm, Ty);
+ case Intrinsic::experimental_stackmap:
+ case Intrinsic::experimental_patchpoint_void:
+ case Intrinsic::experimental_patchpoint_i64:
+ if (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))
+ return TCC_Free;
+ else
+ return X86TTI::getIntImmCost(Imm, Ty);
+ }
+}