Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===-- JSTargetTransformInfo.cpp - JS specific TTI pass ------------------===// | 1 //===-- JSTargetTransformInfo.cpp - JS specific TTI ------------*- C++ -*-===// |
|
jvoung (off chromium)
2015/05/26 20:39:45
don't need the *- C++ -* in a .cpp file (just .h)
Derek Schuff
2015/05/26 22:01:32
Done.
| |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// \file | 9 /// \file |
| 10 /// This file implements a TargetTransformInfo analysis pass specific to the | 10 /// This file implements a TargetTransformInfo::Concept conforming object |
| 11 /// JS target machine. It uses the target's detailed information to provide | 11 /// specific to the JS target machine. It uses the target's detailed information |
| 12 /// more precise answers to certain TTI queries, while letting the target | 12 /// to provide more precise answers to certain TTI queries, while letting the |
| 13 /// independent and default TTI implementations handle the rest. | 13 /// target independent and default TTI implementations handle the rest. |
| 14 /// | 14 /// |
| 15 //===----------------------------------------------------------------------===// | 15 //===----------------------------------------------------------------------===// |
| 16 | 16 |
| 17 #define DEBUG_TYPE "jstti" | 17 #define DEBUG_TYPE "jstti" |
| 18 #include "JS.h" | 18 #include "JS.h" |
| 19 #include "JSTargetMachine.h" | 19 #include "JSTargetMachine.h" |
| 20 #include "llvm/Analysis/TargetTransformInfo.h" | 20 #include "JSTargetTransformInfo.h" |
| 21 #include "llvm/Support/Debug.h" | 21 #include "llvm/Support/Debug.h" |
| 22 #include "llvm/Target/TargetLowering.h" | 22 #include "llvm/Target/TargetLowering.h" |
| 23 #include "llvm/Target/CostTable.h" | 23 #include "llvm/Target/CostTable.h" |
| 24 using namespace llvm; | 24 using namespace llvm; |
| 25 | 25 |
| 26 // Declare the pass initialization routine locally as target-specific passes | |
| 27 // don't havve a target-wide initialization entry point, and so we rely on the | |
| 28 // pass constructor initialization. | |
| 29 namespace llvm { | |
| 30 void initializeJSTTIPass(PassRegistry &); | |
| 31 } | |
| 32 | |
| 33 namespace { | |
| 34 | |
| 35 class JSTTI : public ImmutablePass, public TargetTransformInfo { | |
| 36 public: | |
| 37 JSTTI() : ImmutablePass(ID) { | |
| 38 llvm_unreachable("This pass cannot be directly constructed"); | |
| 39 } | |
| 40 | |
| 41 JSTTI(const JSTargetMachine *TM) : ImmutablePass(ID) { | |
| 42 initializeJSTTIPass(*PassRegistry::getPassRegistry()); | |
| 43 } | |
| 44 | |
| 45 void initializePass() override { pushTTIStack(this); } | |
| 46 | |
| 47 void getAnalysisUsage(AnalysisUsage &AU) const override { | |
| 48 TargetTransformInfo::getAnalysisUsage(AU); | |
| 49 } | |
| 50 | |
| 51 /// Pass identification. | |
| 52 static char ID; | |
| 53 | |
| 54 /// Provide necessary pointer adjustments for the two base classes. | |
| 55 void *getAdjustedAnalysisPointer(const void *ID) override { | |
| 56 if (ID == &TargetTransformInfo::ID) | |
| 57 return (TargetTransformInfo *)this; | |
| 58 return this; | |
| 59 } | |
| 60 | |
| 61 PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const override; | |
| 62 | |
| 63 unsigned getRegisterBitWidth(bool Vector) const override; | |
| 64 | |
| 65 unsigned getArithmeticInstrCost( | |
| 66 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info = OK_AnyValue, | |
| 67 OperandValueKind Opd2Info = OK_AnyValue, | |
| 68 OperandValueProperties Opd1PropInfo = OP_None, | |
| 69 OperandValueProperties Opd2PropInfo = OP_None) const override; | |
| 70 | |
| 71 unsigned getVectorInstrCost(unsigned Opcode, Type *Val, | |
| 72 unsigned Index = -1) const override; | |
| 73 | |
| 74 void getUnrollingPreferences(const Function *F, Loop *L, | |
| 75 UnrollingPreferences &UP) const override; | |
| 76 }; | |
| 77 | |
| 78 } // end anonymous namespace | |
| 79 | |
| 80 INITIALIZE_AG_PASS(JSTTI, TargetTransformInfo, "jstti", | |
| 81 "JS Target Transform Info", true, true, false) | |
| 82 char JSTTI::ID = 0; | |
| 83 | |
| 84 ImmutablePass * | |
| 85 llvm::createJSTargetTransformInfoPass(const JSTargetMachine *TM) { | |
| 86 return new JSTTI(TM); | |
| 87 } | |
| 88 | |
| 89 | |
| 90 //===----------------------------------------------------------------------===// | 26 //===----------------------------------------------------------------------===// |
| 91 // | 27 // |
| 92 // JS cost model. | 28 // JS cost model. |
| 93 // | 29 // |
| 94 //===----------------------------------------------------------------------===// | 30 //===----------------------------------------------------------------------===// |
| 95 | 31 |
| 96 JSTTI::PopcntSupportKind JSTTI::getPopcntSupport(unsigned TyWidth) const { | 32 TargetTransformInfo::PopcntSupportKind JSTTI::getPopcntSupport( |
| 33 unsigned TyWidth) { | |
| 97 assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2"); | 34 assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2"); |
| 98 // Hopefully we'll get popcnt in ES7, but for now, we just have software. | 35 // Hopefully we'll get popcnt in ES7, but for now, we just have software. |
| 99 return PSK_Software; | 36 return TargetTransformInfo::PSK_Software; |
| 100 } | 37 } |
| 101 | 38 |
| 102 unsigned JSTTI::getRegisterBitWidth(bool Vector) const { | 39 unsigned JSTTI::getRegisterBitWidth(bool Vector) const { |
| 103 if (Vector) { | 40 if (Vector) { |
| 104 return 128; | 41 return 128; |
| 105 } | 42 } |
| 106 | 43 |
| 107 return 32; | 44 return 32; |
| 108 } | 45 } |
| 109 | 46 |
| 110 unsigned JSTTI::getArithmeticInstrCost( | 47 unsigned JSTTI::getArithmeticInstrCost( |
| 111 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info, | 48 unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info, |
| 112 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, | 49 TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, |
| 113 OperandValueProperties Opd2PropInfo) const { | 50 TTI::OperandValueProperties Opd2PropInfo) { |
| 114 const unsigned Nope = 65536; | 51 const unsigned Nope = 65536; |
| 115 | 52 |
| 116 unsigned Cost = TargetTransformInfo::getArithmeticInstrCost(Opcode, Ty, Opd1In fo, Opd2Info); | 53 unsigned Cost = BasicTTIImplBase<JSTTI>::getArithmeticInstrCost(Opcode, Ty, Op d1Info, Opd2Info); |
| 117 | 54 |
| 118 if (VectorType *VTy = dyn_cast<VectorType>(Ty)) { | 55 if (VectorType *VTy = dyn_cast<VectorType>(Ty)) { |
| 119 switch (VTy->getNumElements()) { | 56 switch (VTy->getNumElements()) { |
| 120 case 4: | 57 case 4: |
| 121 // SIMD.js supports int32x4 and float32x4, and we can emulate <4 x i1>. | 58 // SIMD.js supports int32x4 and float32x4, and we can emulate <4 x i1>. |
| 122 if (!VTy->getElementType()->isIntegerTy(1) && | 59 if (!VTy->getElementType()->isIntegerTy(1) && |
| 123 !VTy->getElementType()->isIntegerTy(32) && | 60 !VTy->getElementType()->isIntegerTy(32) && |
| 124 !VTy->getElementType()->isFloatTy()) | 61 !VTy->getElementType()->isFloatTy()) |
| 125 { | 62 { |
| 126 return Nope; | 63 return Nope; |
| 127 } | 64 } |
| 128 break; | 65 break; |
| 129 default: | 66 default: |
| 130 // Wait until the other types are optimized. | 67 // Wait until the other types are optimized. |
| 131 return Nope; | 68 return Nope; |
| 132 } | 69 } |
| 133 | 70 |
| 134 switch (Opcode) { | 71 switch (Opcode) { |
| 135 case Instruction::LShr: | 72 case Instruction::LShr: |
| 136 case Instruction::AShr: | 73 case Instruction::AShr: |
| 137 case Instruction::Shl: | 74 case Instruction::Shl: |
| 138 // SIMD.js' shifts are currently only ByScalar. | 75 // SIMD.js' shifts are currently only ByScalar. |
| 139 if (Opd2Info != OK_UniformValue && Opd2Info != OK_UniformConstantValue) | 76 if (Opd2Info != TTI::OK_UniformValue && Opd2Info != TTI::OK_UniformConst antValue) |
| 140 Cost = Cost * VTy->getNumElements() + 100; | 77 Cost = Cost * VTy->getNumElements() + 100; |
| 141 break; | 78 break; |
| 142 } | 79 } |
| 143 } | 80 } |
| 144 | 81 |
| 145 return Cost; | 82 return Cost; |
| 146 } | 83 } |
| 147 | 84 |
| 148 unsigned JSTTI::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) c onst { | 85 unsigned JSTTI::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { |
| 149 unsigned Cost = TargetTransformInfo::getVectorInstrCost(Opcode, Val, Index); | 86 unsigned Cost = BasicTTIImplBase::getVectorInstrCost(Opcode, Val, Index); |
| 150 | 87 |
| 151 // SIMD.js' insert/extract currently only take constant indices. | 88 // SIMD.js' insert/extract currently only take constant indices. |
| 152 if (Index == -1u) | 89 if (Index == -1u) |
| 153 return Cost + 100; | 90 return Cost + 100; |
| 154 | 91 |
| 155 return Cost; | 92 return Cost; |
| 156 } | 93 } |
| 157 | 94 |
| 158 void JSTTI::getUnrollingPreferences(const Function *F, Loop *L, | 95 void JSTTI::getUnrollingPreferences(Loop *L, |
| 159 UnrollingPreferences &UP) const { | 96 TTI::UnrollingPreferences &UP) const { |
| 160 // We generally don't want a lot of unrolling. | 97 // We generally don't want a lot of unrolling. |
| 161 UP.Partial = false; | 98 UP.Partial = false; |
| 162 UP.Runtime = false; | 99 UP.Runtime = false; |
| 163 } | 100 } |
| OLD | NEW |