OLD | NEW |
| (Empty) |
1 //===-- JSTargetTransformInfo.cpp - JS specific TTI ------------*- C++ -*-===// | |
2 // | |
3 // The LLVM Compiler Infrastructure | |
4 // | |
5 // This file is distributed under the University of Illinois Open Source | |
6 // License. See LICENSE.TXT for details. | |
7 // | |
8 //===----------------------------------------------------------------------===// | |
9 /// \file | |
10 /// This file implements a TargetTransformInfo::Concept conforming object | |
11 /// specific to the JS target machine. It uses the target's detailed information | |
12 /// to provide more precise answers to certain TTI queries, while letting the | |
13 /// target independent and default TTI implementations handle the rest. | |
14 /// | |
15 //===----------------------------------------------------------------------===// | |
16 | |
17 #define DEBUG_TYPE "jstti" | |
18 #include "JS.h" | |
19 #include "JSTargetMachine.h" | |
20 #include "JSTargetTransformInfo.h" | |
21 #include "llvm/Support/Debug.h" | |
22 #include "llvm/Target/TargetLowering.h" | |
23 #include "llvm/Target/CostTable.h" | |
24 using namespace llvm; | |
25 | |
26 //===----------------------------------------------------------------------===// | |
27 // | |
28 // JS cost model. | |
29 // | |
30 //===----------------------------------------------------------------------===// | |
31 | |
32 TargetTransformInfo::PopcntSupportKind JSTTI::getPopcntSupport( | |
33 unsigned TyWidth) { | |
34 assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2"); | |
35 // Hopefully we'll get popcnt in ES7, but for now, we just have software. | |
36 return TargetTransformInfo::PSK_Software; | |
37 } | |
38 | |
39 unsigned JSTTI::getRegisterBitWidth(bool Vector) const { | |
40 if (Vector) { | |
41 return 128; | |
42 } | |
43 | |
44 return 32; | |
45 } | |
46 | |
47 unsigned JSTTI::getArithmeticInstrCost( | |
48 unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info, | |
49 TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, | |
50 TTI::OperandValueProperties Opd2PropInfo) { | |
51 const unsigned Nope = 65536; | |
52 | |
53 unsigned Cost = BasicTTIImplBase<JSTTI>::getArithmeticInstrCost(Opcode, Ty, Op
d1Info, Opd2Info); | |
54 | |
55 if (VectorType *VTy = dyn_cast<VectorType>(Ty)) { | |
56 switch (VTy->getNumElements()) { | |
57 case 4: | |
58 // SIMD.js supports int32x4 and float32x4, and we can emulate <4 x i1>. | |
59 if (!VTy->getElementType()->isIntegerTy(1) && | |
60 !VTy->getElementType()->isIntegerTy(32) && | |
61 !VTy->getElementType()->isFloatTy()) | |
62 { | |
63 return Nope; | |
64 } | |
65 break; | |
66 default: | |
67 // Wait until the other types are optimized. | |
68 return Nope; | |
69 } | |
70 | |
71 switch (Opcode) { | |
72 case Instruction::LShr: | |
73 case Instruction::AShr: | |
74 case Instruction::Shl: | |
75 // SIMD.js' shifts are currently only ByScalar. | |
76 if (Opd2Info != TTI::OK_UniformValue && Opd2Info != TTI::OK_UniformConst
antValue) | |
77 Cost = Cost * VTy->getNumElements() + 100; | |
78 break; | |
79 } | |
80 } | |
81 | |
82 return Cost; | |
83 } | |
84 | |
85 unsigned JSTTI::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { | |
86 unsigned Cost = BasicTTIImplBase::getVectorInstrCost(Opcode, Val, Index); | |
87 | |
88 // SIMD.js' insert/extract currently only take constant indices. | |
89 if (Index == -1u) | |
90 return Cost + 100; | |
91 | |
92 return Cost; | |
93 } | |
94 | |
95 void JSTTI::getUnrollingPreferences(Loop *L, | |
96 TTI::UnrollingPreferences &UP) const { | |
97 // We generally don't want a lot of unrolling. | |
98 UP.Partial = false; | |
99 UP.Runtime = false; | |
100 } | |
OLD | NEW |