|
| 1 | +//===-- JSTargetTransformInfo.cpp - JS specific TTI pass ------------------===// |
| 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 analysis pass specific to the |
| 11 | +/// JS target machine. It uses the target's detailed information to provide |
| 12 | +/// more precise answers to certain TTI queries, while letting the target |
| 13 | +/// 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 "llvm/Analysis/TargetTransformInfo.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 | +// 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) |
| 42 | + : ImmutablePass(ID) { |
| 43 | + initializeJSTTIPass(*PassRegistry::getPassRegistry()); |
| 44 | + } |
| 45 | + |
| 46 | + virtual void initializePass() { |
| 47 | + pushTTIStack(this); |
| 48 | + } |
| 49 | + |
| 50 | + virtual void finalizePass() { |
| 51 | + popTTIStack(); |
| 52 | + } |
| 53 | + |
| 54 | + virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 55 | + TargetTransformInfo::getAnalysisUsage(AU); |
| 56 | + } |
| 57 | + |
| 58 | + /// Pass identification. |
| 59 | + static char ID; |
| 60 | + |
| 61 | + /// Provide necessary pointer adjustments for the two base classes. |
| 62 | + virtual void *getAdjustedAnalysisPointer(const void *ID) { |
| 63 | + if (ID == &TargetTransformInfo::ID) |
| 64 | + return (TargetTransformInfo*)this; |
| 65 | + return this; |
| 66 | + } |
| 67 | + |
| 68 | + virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const; |
| 69 | + |
| 70 | + virtual unsigned getRegisterBitWidth(bool Vector) const; |
| 71 | +}; |
| 72 | + |
| 73 | +} // end anonymous namespace |
| 74 | + |
| 75 | +INITIALIZE_AG_PASS(JSTTI, TargetTransformInfo, "jstti", |
| 76 | + "JS Target Transform Info", true, true, false) |
| 77 | +char JSTTI::ID = 0; |
| 78 | + |
| 79 | +ImmutablePass * |
| 80 | +llvm::createJSTargetTransformInfoPass(const JSTargetMachine *TM) { |
| 81 | + return new JSTTI(TM); |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +//===----------------------------------------------------------------------===// |
| 86 | +// |
| 87 | +// JS cost model. |
| 88 | +// |
| 89 | +//===----------------------------------------------------------------------===// |
| 90 | + |
| 91 | +JSTTI::PopcntSupportKind JSTTI::getPopcntSupport(unsigned TyWidth) const { |
| 92 | + assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2"); |
| 93 | + // Hopefully we'll get popcnt in ES7, but for now, we just have software. |
| 94 | + return PSK_Software; |
| 95 | +} |
| 96 | + |
| 97 | +unsigned JSTTI::getRegisterBitWidth(bool Vector) const { |
| 98 | + if (Vector) { |
| 99 | + return 128; |
| 100 | + } |
| 101 | + |
| 102 | + return 32; |
| 103 | +} |
0 commit comments