LLVM 24.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"
20
21#include <vector>
22
23namespace llvm {
24class MachineFunction;
27
29 const HexagonSubtarget *HST;
30 const HexagonInstrInfo *HII;
31 const HexagonRegisterInfo *HRI;
32
33public:
35
38 : SelectionDAGISel(tm, OptLevel), HST(nullptr), HII(nullptr),
39 HRI(nullptr) {}
40
42 // Reset the subtarget each time through.
43 HST = &MF.getSubtarget<HexagonSubtarget>();
44 HII = HST->getInstrInfo();
45 HRI = HST->getRegisterInfo();
47 return true;
48 }
49
50 bool ComplexPatternFuncMutatesDAG() const override {
51 return true;
52 }
53 void PreprocessISelDAG() override;
54 void emitFunctionEntryCode() override;
55
56 void Select(SDNode *N) override;
57
58 // Complex Pattern Selectors.
59 inline bool SelectAddrGA(SDValue &N, SDValue &R);
60 inline bool SelectAddrGP(SDValue &N, SDValue &R);
61 inline bool SelectAnyImm(SDValue &N, SDValue &R);
62 inline bool SelectAnyInt(SDValue &N, SDValue &R);
63 bool SelectAnyImmediate(SDValue &N, SDValue &R, Align Alignment);
64 bool SelectGlobalAddress(SDValue &N, SDValue &R, bool UseGP, Align Alignment);
65 bool SelectAddrFI(SDValue &N, SDValue &R);
66 bool DetectUseSxtw(SDValue &N, SDValue &R);
67 bool DetectUseSxth(SDValue &N, SDValue &R);
68 bool DetectUseZxth(SDValue &N, SDValue &R);
69
70 inline bool SelectAnyImm0(SDValue &N, SDValue &R);
71 inline bool SelectAnyImm1(SDValue &N, SDValue &R);
72 inline bool SelectAnyImm2(SDValue &N, SDValue &R);
73 inline bool SelectAnyImm3(SDValue &N, SDValue &R);
74
75 // Generate a machine instruction node corresponding to the circ/brev
76 // load intrinsic.
78 // Given the circ/brev load intrinsic and the already generated machine
79 // instruction, generate the appropriate store (that is a part of the
80 // intrinsic's functionality).
82
84 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
85 /// inline asm expressions.
87 InlineAsm::ConstraintCode ConstraintID,
88 std::vector<SDValue> &OutOps) override;
90 bool SelectBrevLdIntrinsic(SDNode *IntN);
92 void SelectLoad(SDNode *N);
93 void SelectIndexedLoad(LoadSDNode *LD, const SDLoc &dl);
94 void SelectIndexedStore(StoreSDNode *ST, const SDLoc &dl);
95 void SelectStore(SDNode *N);
96 void SelectSHL(SDNode *N);
100 void SelectConstant(SDNode *N);
102 void SelectV65Gather(SDNode *N);
106 void SelectVAlign(SDNode *N);
108 void SelectTypecast(SDNode *N);
109 void SelectP2D(SDNode *N);
110 void SelectD2P(SDNode *N);
111 void SelectQ2V(SDNode *N);
112 void SelectV2Q(SDNode *N);
113 void SelectFDiv(SDNode *N);
114 void FDiv(SDNode *N);
115 void FastFDiv(SDNode *N);
116
117 bool isIEEEHVXIntrinsic(unsigned);
118 void translateIEEEIntrinsicToQFloat(SDNode *N, unsigned &Opcode);
119
120// Include the declarations autogenerated from the selection patterns.
121#define GET_DAGISEL_DECL
122#include "HexagonGenDAGISel.inc"
123
124private:
125 // This is really only to get access to ReplaceNode (which is a protected
126 // member). Any other members used by HvxSelector can be moved around to
127 // make them accessible).
128 friend struct HvxSelector;
129
130 SDValue selectUndef(const SDLoc &dl, MVT ResTy) {
131 SDNode *U = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy);
132 return SDValue(U, 0);
133 }
134
135 bool keepsLowBits(const SDValue &Val, unsigned NumBits, SDValue &Src);
136 bool isAlignedMemNode(const MemSDNode *N) const;
137 bool isSmallStackStore(const StoreSDNode *N) const;
138 bool isPositiveHalfWord(const SDNode *N) const;
139 bool hasOneUse(const SDNode *N) const;
140
141 // DAG preprocessing functions.
142 void PreprocessHvxISelDAG();
143 void ppSimplifyOrSelect0(std::vector<SDNode*> &&Nodes);
144 void ppAddrReorderAddShl(std::vector<SDNode*> &&Nodes);
145 void ppAddrRewriteAndSrl(std::vector<SDNode*> &&Nodes);
146 void ppHoistZextI1(std::vector<SDNode*> &&Nodes);
147 void ppHvxShuffleOfShuffle(std::vector<SDNode*> &&Nodes);
148
149 void SelectHvxExtractSubvector(SDNode *N);
150 void SelectHvxShuffle(SDNode *N);
151 void SelectHvxRor(SDNode *N);
152 void SelectHvxVAlign(SDNode *N);
153
154 SmallDenseMap<SDNode *,int> RootWeights;
155 SmallDenseMap<SDNode *,int> RootHeights;
156 SmallDenseMap<const Value *,int> GAUsesInFunction;
157 int getWeight(SDNode *N);
158 int getHeight(SDNode *N);
159 SDValue getMultiplierForSHL(SDNode *N);
160 SDValue factorOutPowerOf2(SDValue V, unsigned Power);
161 unsigned getUsesInFunction(const Value *V);
162 SDValue balanceSubTree(SDNode *N, bool Factorize = false);
163 void rebalanceAddressTrees();
164}; // end HexagonDAGToDAGISel
165
167public:
168 static char ID;
170 CodeGenOptLevel OptLevel);
171};
172}
173
174#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONISELDAGTODAG_H
return SDValue()
AMDGPU Register Bank Select
HexagonDAGToDAGISelLegacy(HexagonTargetMachine &tm, CodeGenOptLevel OptLevel)
bool DetectUseZxth(SDValue &N, SDValue &R)
void translateIEEEIntrinsicToQFloat(SDNode *N, unsigned &Opcode)
bool SelectNewCircIntrinsic(SDNode *IntN)
Generate a machine instruction node for the new circular buffer intrinsics.
bool tryLoadOfLoadIntrinsic(LoadSDNode *N)
void SelectIndexedLoad(LoadSDNode *LD, const SDLoc &dl)
MachineSDNode * LoadInstrForLoadIntrinsic(SDNode *IntN)
bool SelectAnyImm2(SDValue &N, SDValue &R)
bool SelectAnyImm(SDValue &N, SDValue &R)
bool SelectAnyImm0(SDValue &N, SDValue &R)
bool runOnMachineFunction(MachineFunction &MF) override
bool SelectAnyImm1(SDValue &N, SDValue &R)
bool DetectUseSxtw(SDValue &N, SDValue &R)
bool SelectBrevLdIntrinsic(SDNode *IntN)
bool DetectUseSxth(SDValue &N, SDValue &R)
bool SelectAddrFI(SDValue &N, SDValue &R)
SDNode * StoreInstrForLoadIntrinsic(MachineSDNode *LoadN, SDNode *IntN)
bool SelectAddrGP(SDValue &N, SDValue &R)
bool SelectAnyImmediate(SDValue &N, SDValue &R, Align Alignment)
bool SelectGlobalAddress(SDValue &N, SDValue &R, bool UseGP, Align Alignment)
bool SelectAnyImm3(SDValue &N, SDValue &R)
bool SelectAnyInt(SDValue &N, SDValue &R)
bool SelectAddrGA(SDValue &N, SDValue &R)
void PreprocessISelDAG() override
PreprocessISelDAG - This hook allows targets to hack on the graph before instruction selection starts...
bool SelectInlineAsmMemoryOperand(const SDValue &Op, InlineAsm::ConstraintCode ConstraintID, std::vector< SDValue > &OutOps) override
SelectInlineAsmMemoryOperand - Implement addressing mode selection for inline asm expressions.
HexagonDAGToDAGISel(HexagonTargetMachine &tm, CodeGenOptLevel OptLevel)
bool ComplexPatternFuncMutatesDAG() const override
Return true if complex patterns for this target can mutate the DAG.
void SelectIndexedStore(StoreSDNode *ST, const SDLoc &dl)
const HexagonRegisterInfo & getRegisterInfo() const
const HexagonInstrInfo * getInstrInfo() const override
This class is used to represent ISD::LOAD nodes.
Machine Value Type.
An SDNode that represents everything that will be needed to construct a MachineInstr.
This is an abstract virtual class for memory operations.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SelectionDAGISelLegacy(char &ID, std::unique_ptr< SelectionDAGISel > S)
SelectionDAGISel(TargetMachine &tm, CodeGenOptLevel OL=CodeGenOptLevel::Default)
virtual bool runOnMachineFunction(MachineFunction &mf)
This class is used to represent ISD::STORE nodes.
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
DWARFExpression::Operation Op
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39