AMDGPUTargetTransformInfo.cpp revision 263508
1//===-- AMDGPUTargetTransformInfo.cpp - AMDGPU 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// 10// \file 11// This file implements a TargetTransformInfo analysis pass specific to the 12// AMDGPU target machine. It uses the target's detailed information to provide 13// more precise answers to certain TTI queries, while letting the target 14// independent and default TTI implementations handle the rest. 15// 16//===----------------------------------------------------------------------===// 17 18#define DEBUG_TYPE "AMDGPUtti" 19#include "AMDGPU.h" 20#include "AMDGPUTargetMachine.h" 21#include "llvm/Analysis/TargetTransformInfo.h" 22#include "llvm/Support/Debug.h" 23#include "llvm/Target/TargetLowering.h" 24#include "llvm/Target/CostTable.h" 25using namespace llvm; 26 27// Declare the pass initialization routine locally as target-specific passes 28// don't have a target-wide initialization entry point, and so we rely on the 29// pass constructor initialization. 30namespace llvm { 31void initializeAMDGPUTTIPass(PassRegistry &); 32} 33 34namespace { 35 36class AMDGPUTTI : public ImmutablePass, public TargetTransformInfo { 37 const AMDGPUTargetMachine *TM; 38 const AMDGPUSubtarget *ST; 39 const AMDGPUTargetLowering *TLI; 40 41 /// Estimate the overhead of scalarizing an instruction. Insert and Extract 42 /// are set if the result needs to be inserted and/or extracted from vectors. 43 unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const; 44 45public: 46 AMDGPUTTI() : ImmutablePass(ID), TM(0), ST(0), TLI(0) { 47 llvm_unreachable("This pass cannot be directly constructed"); 48 } 49 50 AMDGPUTTI(const AMDGPUTargetMachine *TM) 51 : ImmutablePass(ID), TM(TM), ST(TM->getSubtargetImpl()), 52 TLI(TM->getTargetLowering()) { 53 initializeAMDGPUTTIPass(*PassRegistry::getPassRegistry()); 54 } 55 56 virtual void initializePass() { pushTTIStack(this); } 57 58 virtual void finalizePass() { popTTIStack(); } 59 60 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 61 TargetTransformInfo::getAnalysisUsage(AU); 62 } 63 64 /// Pass identification. 65 static char ID; 66 67 /// Provide necessary pointer adjustments for the two base classes. 68 virtual void *getAdjustedAnalysisPointer(const void *ID) { 69 if (ID == &TargetTransformInfo::ID) 70 return (TargetTransformInfo *)this; 71 return this; 72 } 73 74 virtual bool hasBranchDivergence() const; 75 76 /// @} 77}; 78 79} // end anonymous namespace 80 81INITIALIZE_AG_PASS(AMDGPUTTI, TargetTransformInfo, "AMDGPUtti", 82 "AMDGPU Target Transform Info", true, true, false) 83char AMDGPUTTI::ID = 0; 84 85ImmutablePass * 86llvm::createAMDGPUTargetTransformInfoPass(const AMDGPUTargetMachine *TM) { 87 return new AMDGPUTTI(TM); 88} 89 90bool AMDGPUTTI::hasBranchDivergence() const { return true; } 91