[NVPTX] Add an NVPTX-specific TargetTransformInfo
[oota-llvm.git] / lib / Target / NVPTX / NVPTXTargetTransformInfo.cpp
1 //===-- NVPTXTargetTransformInfo.cpp - NVPTX 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 // 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.
15 //
16 //===----------------------------------------------------------------------===//
17
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"
25 using namespace llvm;
26
27 #define DEBUG_TYPE "NVPTXtti"
28
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.
32 namespace llvm {
33 void initializeNVPTXTTIPass(PassRegistry &);
34 }
35
36 namespace {
37
38 class NVPTXTTI final : public ImmutablePass, public TargetTransformInfo {
39   const NVPTXTargetMachine *TM;
40   const NVPTXSubtarget *ST;
41   const NVPTXTargetLowering *TLI;
42
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;
46
47 public:
48   NVPTXTTI() : ImmutablePass(ID), TM(nullptr), ST(nullptr), TLI(nullptr) {
49     llvm_unreachable("This pass cannot be directly constructed");
50   }
51
52   NVPTXTTI(const NVPTXTargetMachine *TM)
53       : ImmutablePass(ID), TM(TM), ST(TM->getSubtargetImpl()),
54         TLI(TM->getSubtargetImpl()->getTargetLowering()) {
55     initializeNVPTXTTIPass(*PassRegistry::getPassRegistry());
56   }
57
58   void initializePass() override { pushTTIStack(this); }
59
60   void getAnalysisUsage(AnalysisUsage &AU) const override {
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   void *getAdjustedAnalysisPointer(const void *ID) override {
69     if (ID == &TargetTransformInfo::ID)
70       return (TargetTransformInfo *)this;
71     return this;
72   }
73
74   bool hasBranchDivergence() const override;
75
76   /// @}
77 };
78
79 } // end anonymous namespace
80
81 INITIALIZE_AG_PASS(NVPTXTTI, TargetTransformInfo, "NVPTXtti",
82                    "NVPTX Target Transform Info", true, true, false)
83 char NVPTXTTI::ID = 0;
84
85 ImmutablePass *
86 llvm::createNVPTXTargetTransformInfoPass(const NVPTXTargetMachine *TM) {
87   return new NVPTXTTI(TM);
88 }
89
90 bool NVPTXTTI::hasBranchDivergence() const { return true; }