[C++] Use 'nullptr'. Target edition.
[oota-llvm.git] / lib / Target / AArch64 / AArch64TargetTransformInfo.cpp
1 //===- AArch64TargetTransformInfo.cpp - AArch64 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 /// AArch64 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 #include "AArch64.h"
18 #include "AArch64TargetMachine.h"
19 #include "llvm/Analysis/TargetTransformInfo.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Target/CostTable.h"
22 #include "llvm/Target/TargetLowering.h"
23 using namespace llvm;
24
25 #define DEBUG_TYPE "aarch64tti"
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.
30 namespace llvm {
31 void initializeAArch64TTIPass(PassRegistry &);
32 }
33
34 namespace {
35
36 class AArch64TTI final : public ImmutablePass, public TargetTransformInfo {
37   const AArch64Subtarget *ST;
38   const AArch64TargetLowering *TLI;
39
40 public:
41   AArch64TTI() : ImmutablePass(ID), ST(nullptr), TLI(nullptr) {
42     llvm_unreachable("This pass cannot be directly constructed");
43   }
44
45   AArch64TTI(const AArch64TargetMachine *TM)
46       : ImmutablePass(ID), ST(TM->getSubtargetImpl()),
47         TLI(TM->getTargetLowering()) {
48     initializeAArch64TTIPass(*PassRegistry::getPassRegistry());
49   }
50
51   virtual void initializePass() override {
52     pushTTIStack(this);
53   }
54
55   virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
56     TargetTransformInfo::getAnalysisUsage(AU);
57   }
58
59   /// Pass identification.
60   static char ID;
61
62   /// Provide necessary pointer adjustments for the two base classes.
63   virtual void *getAdjustedAnalysisPointer(const void *ID) override {
64     if (ID == &TargetTransformInfo::ID)
65       return (TargetTransformInfo*)this;
66     return this;
67   }
68
69   /// \name Scalar TTI Implementations
70   /// @{
71
72   /// @}
73
74
75   /// \name Vector TTI Implementations
76   /// @{
77
78   unsigned getNumberOfRegisters(bool Vector) const {
79     if (Vector) {
80       if (ST->hasNEON())
81         return 32;
82       return 0;
83     }
84     return 32;
85   }
86
87   unsigned getRegisterBitWidth(bool Vector) const {
88     if (Vector) {
89       if (ST->hasNEON())
90         return 128;
91       return 0;
92     }
93     return 64;
94   }
95
96   unsigned getMaximumUnrollFactor() const override { return 2; }
97   /// @}
98 };
99
100 } // end anonymous namespace
101
102 INITIALIZE_AG_PASS(AArch64TTI, TargetTransformInfo, "aarch64tti",
103                    "AArch64 Target Transform Info", true, true, false)
104 char AArch64TTI::ID = 0;
105
106 ImmutablePass *
107 llvm::createAArch64TargetTransformInfoPass(const AArch64TargetMachine *TM) {
108   return new AArch64TTI(TM);
109 }