LLVM  13.0.0git
HexagonISelDAGToDAG.h
Go to the documentation of this file.
1 //===-- HexagonISelDAGToDAG.h -----------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // Hexagon specific code to select Hexagon machine instructions for
9 // SelectionDAG operations.
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONISELDAGTODAG_H
13 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONISELDAGTODAG_H
14 
15 #include "HexagonSubtarget.h"
16 #include "HexagonTargetMachine.h"
17 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/CodeGen.h"
21 
22 #include <vector>
23 
24 namespace llvm {
25 class MachineFunction;
26 class HexagonInstrInfo;
27 class HexagonRegisterInfo;
28 
30  const HexagonSubtarget *HST;
31  const HexagonInstrInfo *HII;
32  const HexagonRegisterInfo *HRI;
33 public:
36  : SelectionDAGISel(tm, OptLevel), HST(nullptr), HII(nullptr),
37  HRI(nullptr) {}
38 
40  // Reset the subtarget each time through.
42  HII = HST->getInstrInfo();
43  HRI = HST->getRegisterInfo();
45  updateAligna();
46  return true;
47  }
48 
49  bool ComplexPatternFuncMutatesDAG() const override {
50  return true;
51  }
52  void PreprocessISelDAG() override;
53  void emitFunctionEntryCode() override;
54 
55  void Select(SDNode *N) override;
56 
57  // Complex Pattern Selectors.
58  inline bool SelectAddrGA(SDValue &N, SDValue &R);
59  inline bool SelectAddrGP(SDValue &N, SDValue &R);
60  inline bool SelectAnyImm(SDValue &N, SDValue &R);
61  inline bool SelectAnyInt(SDValue &N, SDValue &R);
62  bool SelectAnyImmediate(SDValue &N, SDValue &R, Align Alignment);
63  bool SelectGlobalAddress(SDValue &N, SDValue &R, bool UseGP, Align Alignment);
64  bool SelectAddrFI(SDValue &N, SDValue &R);
65  bool DetectUseSxtw(SDValue &N, SDValue &R);
66 
67  inline bool SelectAnyImm0(SDValue &N, SDValue &R);
68  inline bool SelectAnyImm1(SDValue &N, SDValue &R);
69  inline bool SelectAnyImm2(SDValue &N, SDValue &R);
70  inline bool SelectAnyImm3(SDValue &N, SDValue &R);
71 
72  StringRef getPassName() const override {
73  return "Hexagon DAG->DAG Pattern Instruction Selection";
74  }
75 
76  // Generate a machine instruction node corresponding to the circ/brev
77  // load intrinsic.
79  // Given the circ/brev load intrinsic and the already generated machine
80  // instruction, generate the appropriate store (that is a part of the
81  // intrinsic's functionality).
83 
84  void SelectFrameIndex(SDNode *N);
85  /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
86  /// inline asm expressions.
88  unsigned ConstraintID,
89  std::vector<SDValue> &OutOps) override;
91  bool SelectBrevLdIntrinsic(SDNode *IntN);
92  bool SelectNewCircIntrinsic(SDNode *IntN);
93  void SelectLoad(SDNode *N);
94  void SelectIndexedLoad(LoadSDNode *LD, const SDLoc &dl);
95  void SelectIndexedStore(StoreSDNode *ST, const SDLoc &dl);
96  void SelectStore(SDNode *N);
97  void SelectSHL(SDNode *N);
98  void SelectZeroExtend(SDNode *N);
101  void SelectConstant(SDNode *N);
102  void SelectConstantFP(SDNode *N);
103  void SelectV65Gather(SDNode *N);
106  void SelectAddSubCarry(SDNode *N);
107  void SelectVAlign(SDNode *N);
108  void SelectVAlignAddr(SDNode *N);
109  void SelectTypecast(SDNode *N);
110  void SelectP2D(SDNode *N);
111  void SelectD2P(SDNode *N);
112  void SelectQ2V(SDNode *N);
113  void SelectV2Q(SDNode *N);
114 
115  // Include the declarations autogenerated from the selection patterns.
116  #define GET_DAGISEL_DECL
117  #include "HexagonGenDAGISel.inc"
118 
119 private:
120  // This is really only to get access to ReplaceNode (which is a protected
121  // member). Any other members used by HvxSelector can be moved around to
122  // make them accessible).
123  friend struct HvxSelector;
124 
125  SDValue selectUndef(const SDLoc &dl, MVT ResTy) {
126  SDNode *U = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy);
127  return SDValue(U, 0);
128  }
129 
130  void SelectHvxShuffle(SDNode *N);
131  void SelectHvxRor(SDNode *N);
132  void SelectHvxVAlign(SDNode *N);
133 
134  bool keepsLowBits(const SDValue &Val, unsigned NumBits, SDValue &Src);
135  bool isAlignedMemNode(const MemSDNode *N) const;
136  bool isSmallStackStore(const StoreSDNode *N) const;
137  bool isPositiveHalfWord(const SDNode *N) const;
138  bool hasOneUse(const SDNode *N) const;
139 
140  // DAG preprocessing functions.
141  void ppSimplifyOrSelect0(std::vector<SDNode*> &&Nodes);
142  void ppAddrReorderAddShl(std::vector<SDNode*> &&Nodes);
143  void ppAddrRewriteAndSrl(std::vector<SDNode*> &&Nodes);
144  void ppHoistZextI1(std::vector<SDNode*> &&Nodes);
145 
146  // Function postprocessing.
147  void updateAligna();
148 
149  SmallDenseMap<SDNode *,int> RootWeights;
150  SmallDenseMap<SDNode *,int> RootHeights;
151  SmallDenseMap<const Value *,int> GAUsesInFunction;
152  int getWeight(SDNode *N);
153  int getHeight(SDNode *N);
154  SDValue getMultiplierForSHL(SDNode *N);
155  SDValue factorOutPowerOf2(SDValue V, unsigned Power);
156  unsigned getUsesInFunction(const Value *V);
157  SDValue balanceSubTree(SDNode *N, bool Factorize = false);
158  void rebalanceAddressTrees();
159 }; // end HexagonDAGToDAGISel
160 }
161 
162 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONISELDAGTODAG_H
llvm::HexagonDAGToDAGISel::SelectNewCircIntrinsic
bool SelectNewCircIntrinsic(SDNode *IntN)
Generate a machine instruction node for the new circlar buffer intrinsics.
Definition: HexagonISelDAGToDAG.cpp:359
llvm::HexagonDAGToDAGISel::ComplexPatternFuncMutatesDAG
bool ComplexPatternFuncMutatesDAG() const override
Return true if complex patterns for this target can mutate the DAG.
Definition: HexagonISelDAGToDAG.h:49
llvm
Definition: AllocatorList.h:23
llvm::HexagonDAGToDAGISel::PreprocessISelDAG
void PreprocessISelDAG() override
PreprocessISelDAG - This hook allows targets to hack on the graph before instruction selection starts...
Definition: HexagonISelDAGToDAG.cpp:1220
llvm::SDLoc
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Definition: SelectionDAGNodes.h:1078
llvm::HexagonDAGToDAGISel::SelectD2P
void SelectD2P(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:847
llvm::HexagonDAGToDAGISel::SelectAddrGA
bool SelectAddrGA(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1316
StringRef.h
llvm::HexagonDAGToDAGISel::SelectAnyImmediate
bool SelectAnyImmediate(SDValue &N, SDValue &R, Align Alignment)
Definition: HexagonISelDAGToDAG.cpp:1349
llvm::HexagonDAGToDAGISel::SelectAddSubCarry
void SelectAddSubCarry(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:761
llvm::ARM_MB::LD
@ LD
Definition: ARMBaseInfo.h:72
HexagonSubtarget.h
llvm::MachineSDNode
An SDNode that represents everything that will be needed to construct a MachineInstr.
Definition: SelectionDAGNodes.h:2523
llvm::HexagonTargetMachine
Definition: HexagonTargetMachine.h:25
llvm::SmallDenseMap
Definition: DenseMap.h:880
llvm::SDNode
Represents one node in the SelectionDAG.
Definition: SelectionDAGNodes.h:455
llvm::HexagonDAGToDAGISel::SelectV2Q
void SelectV2Q(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:856
llvm::LoadSDNode
This class is used to represent ISD::LOAD nodes.
Definition: SelectionDAGNodes.h:2256
llvm::MemSDNode
This is an abstract virtual class for memory operations.
Definition: SelectionDAGNodes.h:1246
llvm::HexagonDAGToDAGISel
Definition: HexagonISelDAGToDAG.h:29
HexagonTargetMachine.h
llvm::HexagonDAGToDAGISel::SelectP2D
void SelectP2D(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:840
llvm::HexagonDAGToDAGISel::StoreInstrForLoadIntrinsic
SDNode * StoreInstrForLoadIntrinsic(MachineSDNode *LoadN, SDNode *IntN)
Definition: HexagonISelDAGToDAG.cpp:216
SelectionDAG.h
llvm::HexagonDAGToDAGISel::SelectVAlignAddr
void SelectVAlignAddr(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:817
llvm::HexagonDAGToDAGISel::SelectSHL
void SelectSHL(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:568
llvm::HexagonDAGToDAGISel::SelectLoad
void SelectLoad(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:445
llvm::SelectionDAGISel::OptLevel
CodeGenOpt::Level OptLevel
Definition: SelectionDAGISel.h:51
llvm::HexagonDAGToDAGISel::SelectVAlign
void SelectVAlign(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:770
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::HvxSelector
Definition: HexagonISelDAGToDAGHVX.cpp:811
llvm::HexagonSubtarget::getInstrInfo
const HexagonInstrInfo * getInstrInfo() const override
Definition: HexagonSubtarget.h:119
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:576
llvm::HexagonDAGToDAGISel::SelectConstantFP
void SelectConstantFP(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:698
llvm::HexagonDAGToDAGISel::SelectV65GatherPred
void SelectV65GatherPred(SDNode *N)
Definition: HexagonISelDAGToDAGHVX.cpp:2392
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::HexagonDAGToDAGISel::SelectAnyImm0
bool SelectAnyImm0(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1328
llvm::HexagonDAGToDAGISel::SelectFrameIndex
void SelectFrameIndex(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:732
llvm::HexagonDAGToDAGISel::HexagonDAGToDAGISel
HexagonDAGToDAGISel(HexagonTargetMachine &tm, CodeGenOpt::Level OptLevel)
Definition: HexagonISelDAGToDAG.h:34
llvm::HexagonDAGToDAGISel::SelectConstant
void SelectConstant(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:719
llvm::StoreSDNode
This class is used to represent ISD::STORE nodes.
Definition: SelectionDAGNodes.h:2284
llvm::HexagonDAGToDAGISel::SelectAnyInt
bool SelectAnyInt(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1341
llvm::SelectionDAGISel::CurDAG
SelectionDAG * CurDAG
Definition: SelectionDAGISel.h:47
llvm::SelectionDAG::getMachineNode
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
Definition: SelectionDAG.cpp:8518
llvm::HexagonDAGToDAGISel::SelectAnyImm1
bool SelectAnyImm1(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1331
llvm::HexagonDAGToDAGISel::emitFunctionEntryCode
void emitFunctionEntryCode() override
Definition: HexagonISelDAGToDAG.cpp:1277
llvm::MVT
Machine Value Type.
Definition: MachineValueType.h:30
llvm::HexagonDAGToDAGISel::SelectZeroExtend
void SelectZeroExtend(SDNode *N)
llvm::HexagonDAGToDAGISel::SelectQ2V
void SelectQ2V(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:870
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::HexagonInstrInfo
Definition: HexagonInstrInfo.h:38
llvm::HexagonDAGToDAGISel::SelectIndexedStore
void SelectIndexedStore(StoreSDNode *ST, const SDLoc &dl)
Definition: HexagonISelDAGToDAG.cpp:463
SelectionDAGISel.h
llvm::HexagonDAGToDAGISel::SelectTypecast
void SelectTypecast(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:832
llvm::HexagonDAGToDAGISel::SelectIndexedLoad
void SelectIndexedLoad(LoadSDNode *LD, const SDLoc &dl)
Definition: HexagonISelDAGToDAG.cpp:66
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::HexagonDAGToDAGISel::SelectGlobalAddress
bool SelectGlobalAddress(SDValue &N, SDValue &R, bool UseGP, Align Alignment)
Definition: HexagonISelDAGToDAG.cpp:1390
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
llvm::HexagonDAGToDAGISel::tryLoadOfLoadIntrinsic
bool tryLoadOfLoadIntrinsic(LoadSDNode *N)
Definition: HexagonISelDAGToDAG.cpp:251
llvm::HexagonDAGToDAGISel::SelectAddrGP
bool SelectAddrGP(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1320
llvm::HexagonDAGToDAGISel::SelectIntrinsicWChain
void SelectIntrinsicWChain(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:625
llvm::SelectionDAGISel::MF
MachineFunction * MF
Definition: SelectionDAGISel.h:45
llvm::HexagonSubtarget::getRegisterInfo
const HexagonRegisterInfo * getRegisterInfo() const override
Definition: HexagonSubtarget.h:120
llvm::HexagonDAGToDAGISel::SelectBrevLdIntrinsic
bool SelectBrevLdIntrinsic(SDNode *IntN)
Definition: HexagonISelDAGToDAG.cpp:318
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::HexagonDAGToDAGISel::SelectV65Gather
void SelectV65Gather(SDNode *N)
Definition: HexagonISelDAGToDAGHVX.cpp:2430
llvm::HexagonDAGToDAGISel::SelectAddrFI
bool SelectAddrFI(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1304
llvm::HexagonDAGToDAGISel::SelectAnyImm
bool SelectAnyImm(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1324
llvm::SDValue
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Definition: SelectionDAGNodes.h:138
CodeGen.h
llvm::SelectionDAGISel
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
Definition: SelectionDAGISel.h:39
llvm::HexagonDAGToDAGISel::SelectInlineAsmMemoryOperand
bool SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID, std::vector< SDValue > &OutOps) override
SelectInlineAsmMemoryOperand - Implement addressing mode selection for inline asm expressions.
Definition: HexagonISelDAGToDAG.cpp:919
llvm::HexagonDAGToDAGISel::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: HexagonISelDAGToDAG.h:72
llvm::HexagonDAGToDAGISel::SelectAnyImm3
bool SelectAnyImm3(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1337
N
#define N
llvm::HexagonSubtarget
Definition: HexagonSubtarget.h:42
llvm::HexagonDAGToDAGISel::LoadInstrForLoadIntrinsic
MachineSDNode * LoadInstrForLoadIntrinsic(SDNode *IntN)
Definition: HexagonISelDAGToDAG.cpp:185
llvm::HexagonDAGToDAGISel::Select
void Select(SDNode *N) override
Main hook for targets to transform nodes into machine nodes.
Definition: HexagonISelDAGToDAG.cpp:883
llvm::HexagonDAGToDAGISel::SelectAnyImm2
bool SelectAnyImm2(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1334
llvm::HexagonDAGToDAGISel::SelectStore
void SelectStore(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:554
llvm::HexagonRegisterInfo
Definition: HexagonRegisterInfo.h:29
llvm::SelectionDAGISel::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: SelectionDAGISel.cpp:415
hasOneUse
static bool hasOneUse(unsigned Reg, MachineInstr *Def, MachineRegisterInfo &MRI, MachineDominatorTree &MDT, LiveIntervals &LIS)
Definition: WebAssemblyRegStackify.cpp:284
llvm::HexagonDAGToDAGISel::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: HexagonISelDAGToDAG.h:39
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::HexagonDAGToDAGISel::SelectIntrinsicWOChain
void SelectIntrinsicWOChain(SDNode *N)
Definition: HexagonISelDAGToDAG.cpp:662
llvm::HexagonDAGToDAGISel::SelectHVXDualOutput
void SelectHVXDualOutput(SDNode *N)
Definition: HexagonISelDAGToDAGHVX.cpp:2467
llvm::HexagonDAGToDAGISel::DetectUseSxtw
bool DetectUseSxtw(SDValue &N, SDValue &R)
Definition: HexagonISelDAGToDAG.cpp:1435