]> granicus.if.org Git - llvm/commitdiff
[lanai] Add getIntImmCost in LanaiTargetTransformInfo.
authorJacques Pienaar <jpienaar@google.com>
Tue, 1 Aug 2017 18:40:08 +0000 (18:40 +0000)
committerJacques Pienaar <jpienaar@google.com>
Tue, 1 Aug 2017 18:40:08 +0000 (18:40 +0000)
Add simple int immediate cost function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309721 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Lanai/LanaiTargetTransformInfo.h

index d95c16fc3cafca0719397d9a3cce317ed0cccb36..12613ed273f11c42bc5a4c5364a594129775da86 100644 (file)
@@ -22,6 +22,7 @@
 #include "LanaiTargetMachine.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/BasicTTIImpl.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/Target/TargetLowering.h"
 
 namespace llvm {
@@ -49,6 +50,32 @@ public:
     return TTI::PSK_Software;
   }
 
+  int getIntImmCost(const APInt &Imm, Type *Ty) {
+    assert(Ty->isIntegerTy());
+    if (Imm == 0)
+      return TTI::TCC_Free;
+    if (isInt<16>(Imm.getSExtValue()))
+      return TTI::TCC_Basic;
+    if (isInt<21>(Imm.getZExtValue()))
+      return TTI::TCC_Basic;
+    if (isInt<32>(Imm.getSExtValue())) {
+      if ((Imm.getSExtValue() & 0xFFFF) == 0)
+        return TTI::TCC_Basic;
+      return 2 * TTI::TCC_Basic;
+    }
+
+    return 4 * TTI::TCC_Basic;
+  }
+
+  int getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) {
+    return getIntImmCost(Imm, Ty);
+  }
+
+  int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
+                    Type *Ty) {
+    return getIntImmCost(Imm, Ty);
+  }
+
   unsigned getArithmeticInstrCost(
       unsigned Opcode, Type *Ty,
       TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,