1 //===-- NVPTXTargetTransformInfo.cpp - NVPTX specific TTI pass ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // This file implements a TargetTransformInfo analysis pass specific to the
12 // NVPTX 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.
16 //===----------------------------------------------------------------------===//
18 #include "NVPTXTargetMachine.h"
19 #include "llvm/Analysis/LoopInfo.h"
20 #include "llvm/Analysis/TargetTransformInfo.h"
21 #include "llvm/Analysis/ValueTracking.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Target/CostTable.h"
24 #include "llvm/Target/TargetLowering.h"
27 #define DEBUG_TYPE "NVPTXtti"
29 // Declare the pass initialization routine locally as target-specific passes
30 // don't have a target-wide initialization entry point, and so we rely on the
31 // pass constructor initialization.
33 void initializeNVPTXTTIPass(PassRegistry &);
38 class NVPTXTTI final : public ImmutablePass, public TargetTransformInfo {
39 const NVPTXTargetMachine *TM;
40 const NVPTXSubtarget *ST;
41 const NVPTXTargetLowering *TLI;
43 /// Estimate the overhead of scalarizing an instruction. Insert and Extract
44 /// are set if the result needs to be inserted and/or extracted from vectors.
45 unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;
48 NVPTXTTI() : ImmutablePass(ID), TM(nullptr), ST(nullptr), TLI(nullptr) {
49 llvm_unreachable("This pass cannot be directly constructed");
52 NVPTXTTI(const NVPTXTargetMachine *TM)
53 : ImmutablePass(ID), TM(TM), ST(TM->getSubtargetImpl()),
54 TLI(TM->getSubtargetImpl()->getTargetLowering()) {
55 initializeNVPTXTTIPass(*PassRegistry::getPassRegistry());
58 void initializePass() override { pushTTIStack(this); }
60 void getAnalysisUsage(AnalysisUsage &AU) const override {
61 TargetTransformInfo::getAnalysisUsage(AU);
64 /// Pass identification.
67 /// Provide necessary pointer adjustments for the two base classes.
68 void *getAdjustedAnalysisPointer(const void *ID) override {
69 if (ID == &TargetTransformInfo::ID)
70 return (TargetTransformInfo *)this;
74 bool hasBranchDivergence() const override;
79 } // end anonymous namespace
81 INITIALIZE_AG_PASS(NVPTXTTI, TargetTransformInfo, "NVPTXtti",
82 "NVPTX Target Transform Info", true, true, false)
83 char NVPTXTTI::ID = 0;
86 llvm::createNVPTXTargetTransformInfoPass(const NVPTXTargetMachine *TM) {
87 return new NVPTXTTI(TM);
90 bool NVPTXTTI::hasBranchDivergence() const { return true; }