LLVM 22.0.0git
VEISelLowering.h
Go to the documentation of this file.
1//===-- VEISelLowering.h - VE DAG Lowering Interface ------------*- 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//
9// This file defines the interfaces that VE uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_VE_VEISELLOWERING_H
15#define LLVM_LIB_TARGET_VE_VEISELLOWERING_H
16
17#include "VE.h"
19
20namespace llvm {
21class VESubtarget;
22
23/// Convert a DAG integer condition code to a VE ICC condition.
25 switch (CC) {
26 default:
27 llvm_unreachable("Unknown integer condition code!");
28 case ISD::SETEQ:
29 return VECC::CC_IEQ;
30 case ISD::SETNE:
31 return VECC::CC_INE;
32 case ISD::SETLT:
33 return VECC::CC_IL;
34 case ISD::SETGT:
35 return VECC::CC_IG;
36 case ISD::SETLE:
37 return VECC::CC_ILE;
38 case ISD::SETGE:
39 return VECC::CC_IGE;
40 case ISD::SETULT:
41 return VECC::CC_IL;
42 case ISD::SETULE:
43 return VECC::CC_ILE;
44 case ISD::SETUGT:
45 return VECC::CC_IG;
46 case ISD::SETUGE:
47 return VECC::CC_IGE;
48 }
49}
50
51/// Convert a DAG floating point condition code to a VE FCC condition.
53 switch (CC) {
54 default:
55 llvm_unreachable("Unknown fp condition code!");
56 case ISD::SETFALSE:
57 return VECC::CC_AF;
58 case ISD::SETEQ:
59 case ISD::SETOEQ:
60 return VECC::CC_EQ;
61 case ISD::SETNE:
62 case ISD::SETONE:
63 return VECC::CC_NE;
64 case ISD::SETLT:
65 case ISD::SETOLT:
66 return VECC::CC_L;
67 case ISD::SETGT:
68 case ISD::SETOGT:
69 return VECC::CC_G;
70 case ISD::SETLE:
71 case ISD::SETOLE:
72 return VECC::CC_LE;
73 case ISD::SETGE:
74 case ISD::SETOGE:
75 return VECC::CC_GE;
76 case ISD::SETO:
77 return VECC::CC_NUM;
78 case ISD::SETUO:
79 return VECC::CC_NAN;
80 case ISD::SETUEQ:
81 return VECC::CC_EQNAN;
82 case ISD::SETUNE:
83 return VECC::CC_NENAN;
84 case ISD::SETULT:
85 return VECC::CC_LNAN;
86 case ISD::SETUGT:
87 return VECC::CC_GNAN;
88 case ISD::SETULE:
89 return VECC::CC_LENAN;
90 case ISD::SETUGE:
91 return VECC::CC_GENAN;
92 case ISD::SETTRUE:
93 return VECC::CC_AT;
94 }
95}
96
97/// getImmVal - get immediate representation of integer value
98inline static uint64_t getImmVal(const ConstantSDNode *N) {
99 return N->getSExtValue();
100}
101
102/// getFpImmVal - get immediate representation of floating point value
103inline static uint64_t getFpImmVal(const ConstantFPSDNode *N) {
104 const APInt &Imm = N->getValueAPF().bitcastToAPInt();
105 uint64_t Val = Imm.getZExtValue();
106 if (Imm.getBitWidth() == 32) {
107 // Immediate value of float place places at higher bits on VE.
108 Val <<= 32;
109 }
110 return Val;
111}
112
113class VECustomDAG;
114
116 const VESubtarget *Subtarget;
117
118 void initRegisterClasses();
119 void initSPUActions();
120 void initVPUActions();
121
122public:
123 VETargetLowering(const TargetMachine &TM, const VESubtarget &STI);
124
125 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
126 return MVT::i32;
127 }
128
129 Register getRegisterByName(const char *RegName, LLT VT,
130 const MachineFunction &MF) const override;
131
132 /// getSetCCResultType - Return the ISD::SETCC ValueType
134 EVT VT) const override;
135
137 bool isVarArg,
139 const SDLoc &dl, SelectionDAG &DAG,
140 SmallVectorImpl<SDValue> &InVals) const override;
141
143 SmallVectorImpl<SDValue> &InVals) const override;
144
146 bool isVarArg,
147 const SmallVectorImpl<ISD::OutputArg> &ArgsFlags,
148 LLVMContext &Context,
149 const Type *RetTy) const override;
150 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
152 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
153 SelectionDAG &DAG) const override;
154
155 /// Helper functions for atomic operations.
156 bool shouldInsertFencesForAtomic(const Instruction *I) const override {
157 // VE uses release consistency, so need fence for each atomics.
158 return true;
159 }
161 AtomicOrdering Ord) const override;
163 AtomicOrdering Ord) const override;
165 shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
167 return ISD::ANY_EXTEND;
168 }
169
170 /// Custom Lower {
172 getCustomOperationAction(SDNode &) const override;
173
174 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
175 unsigned getJumpTableEncoding() const override;
177 const MachineBasicBlock *MBB,
178 unsigned Uid,
179 MCContext &Ctx) const override;
181 SelectionDAG &DAG) const override;
182 // VE doesn't need getPICJumpTableRelocBaseExpr since it is used for only
183 // EK_LabelDifference32.
184
202
206 /// } Custom Lower
207
208 /// Replace the results of node with an illegal result
209 /// type with new values built out of custom code.
210 ///
212 SelectionDAG &DAG) const override;
213
214 /// Custom Inserter {
217 MachineBasicBlock *MBB) const override;
219 MachineBasicBlock *MBB) const;
221 MachineBasicBlock *MBB) const;
223 MachineBasicBlock *BB) const;
224
226 MachineBasicBlock *DispatchBB, int FI,
227 int Offset) const;
228 // Setup basic block address.
230 MachineBasicBlock *TargetBB, const DebugLoc &DL) const;
231 // Prepare function/variable address.
233 StringRef Symbol, const DebugLoc &DL, bool IsLocal,
234 bool IsCall) const;
235 /// } Custom Inserter
236
237 /// VVP Lowering {
241
248 /// } VVPLowering
249
250 /// Custom DAGCombine {
251 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
252
253 SDValue combineSelect(SDNode *N, DAGCombinerInfo &DCI) const;
254 SDValue combineSelectCC(SDNode *N, DAGCombinerInfo &DCI) const;
255 SDValue combineTRUNCATE(SDNode *N, DAGCombinerInfo &DCI) const;
256 /// } Custom DAGCombine
257
258 SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const;
259 SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF,
260 SelectionDAG &DAG) const;
262
263 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
264 bool isFPImmLegal(const APFloat &Imm, EVT VT,
265 bool ForCodeSize) const override;
266 /// Returns true if the target allows unaligned memory accesses of the
267 /// specified type.
268 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, Align A,
270 unsigned *Fast) const override;
271
272 /// Inline Assembly {
273
274 ConstraintType getConstraintType(StringRef Constraint) const override;
275 std::pair<unsigned, const TargetRegisterClass *>
277 StringRef Constraint, MVT VT) const override;
278
279 /// } Inline Assembly
280
281 /// Target Optimization {
282
283 // Return lower limit for number of blocks in a jump table.
284 unsigned getMinimumJumpTableEntries() const override;
285
286 // SX-Aurora VE's s/udiv is 5-9 times slower than multiply.
287 bool isIntDivCheap(EVT, AttributeList) const override { return false; }
288 // VE doesn't have rem.
289 bool hasStandaloneRem(EVT) const override { return false; }
290 // VE LDZ instruction returns 64 if the input is zero.
291 bool isCheapToSpeculateCtlz(Type *) const override { return true; }
292 // VE LDZ instruction is fast.
293 bool isCtlzFast() const override { return true; }
294 // VE has NND instruction.
295 bool hasAndNot(SDValue Y) const override;
296
297 /// } Target Optimization
298};
299} // namespace llvm
300
301#endif // LLVM_LIB_TARGET_VE_VEISELLOWERING_H
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
IRTranslator LLVM IR MI
#define RegName(no)
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
This file describes how to lower LLVM code to machine code.
Class for arbitrary precision integers.
Definition APInt.h:78
an instruction that atomically reads a memory location, combines it with another value,...
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
A debug info location.
Definition DebugLoc.h:124
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Machine Value Type.
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
Flags
Flags values. These may be or'd together.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
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.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
TargetLowering(const TargetLowering &)=delete
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
SDValue splitMaskArithmetic(SDValue Op, SelectionDAG &DAG) const
SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
SDValue lowerVVP_GATHER_SCATTER(SDValue Op, VECustomDAG &) const
bool isCheapToSpeculateCtlz(Type *) const override
Return true if it is cheap to speculate a call to intrinsic ctlz.
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
SDValue lowerToVVP(SDValue Op, SelectionDAG &DAG) const
} Custom Inserter
SDValue lowerJumpTable(SDValue Op, SelectionDAG &DAG) const
MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
Return the type to use for a scalar shift opcode, given the shifted amount type.
SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG) const override
Returns relocation base for the given PIC jumptable.
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
getSetCCResultType - Return the ISD::SETCC ValueType
SDValue lowerVVP_LOAD_STORE(SDValue Op, VECustomDAG &) const
SDValue lowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const
bool shouldInsertFencesForAtomic(const Instruction *I) const override
Helper functions for atomic operations.
bool hasAndNot(SDValue Y) const override
Return true if the target has a bitwise and-not operation: X = ~A & B This can be used to simplify se...
SDValue lowerVAARG(SDValue Op, SelectionDAG &DAG) const
SDValue combineSelect(SDNode *N, DAGCombinerInfo &DCI) const
bool isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const override
isFPImmLegal - Returns true if the target can instruction select the specified FP immediate natively.
VETargetLowering(const TargetMachine &TM, const VESubtarget &STI)
Instruction * emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const override
Custom Lower {.
SDValue lowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
SDValue lowerLOAD(SDValue Op, SelectionDAG &DAG) const
MachineBasicBlock * emitEHSjLjLongJmp(MachineInstr &MI, MachineBasicBlock *MBB) const
SDValue legalizePackedAVL(SDValue Op, VECustomDAG &CDAG) const
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
} VVPLowering
TargetLoweringBase::AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const
SDValue combineSelectCC(SDNode *N, DAGCombinerInfo &DCI) const
SDValue lowerEH_SJLJ_SETUP_DISPATCH(SDValue Op, SelectionDAG &DAG) const
unsigned getMinimumJumpTableEntries() const override
} Inline Assembly
SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &dl, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array,...
MachineBasicBlock * emitSjLjDispatchBlock(MachineInstr &MI, MachineBasicBlock *BB) const
Instruction * emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const override
Register prepareMBB(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, MachineBasicBlock *TargetBB, const DebugLoc &DL) const
void setupEntryBlockForSjLj(MachineInstr &MI, MachineBasicBlock *MBB, MachineBasicBlock *DispatchBB, int FI, int Offset) const
SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
Custom Inserter {.
MachineBasicBlock * emitEHSjLjSetJmp(MachineInstr &MI, MachineBasicBlock *MBB) const
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, Align A, MachineMemOperand::Flags Flags, unsigned *Fast) const override
Returns true if the target allows unaligned memory accesses of the specified type.
SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const
bool hasStandaloneRem(EVT) const override
Return true if the target can handle a standalone remainder operation.
SDValue lowerSTORE(SDValue Op, SelectionDAG &DAG) const
TargetLoweringBase::LegalizeAction getCustomOperationAction(SDNode &) const override
Custom Lower {.
ISD::NodeType getExtendForAtomicOps() const override
Returns how the platform's atomic operations are extended (ZERO_EXTEND, SIGN_EXTEND,...
SDValue splitPackedLoadStore(SDValue Op, VECustomDAG &CDAG) const
SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const
SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const
SDValue lowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const
SDValue legalizeInternalVectorOp(SDValue Op, SelectionDAG &DAG) const
Register prepareSymbol(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, StringRef Symbol, const DebugLoc &DL, bool IsLocal, bool IsCall) const
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array,...
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
} Custom Lower
SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const
SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
SDValue splitVectorOp(SDValue Op, VECustomDAG &CDAG) const
SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const
} Custom DAGCombine
SDValue combineTRUNCATE(SDNode *N, DAGCombinerInfo &DCI) const
bool isCtlzFast() const override
Return true if ctlz instruction is fast.
SDValue legalizeInternalLoadStoreOp(SDValue Op, VECustomDAG &CDAG) const
const MCExpr * LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI, const MachineBasicBlock *MBB, unsigned Uid, MCContext &Ctx) const override
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &ArgsFlags, LLVMContext &Context, const Type *RetTy) const override
This hook should be implemented to check whether the return values described by the Outs array can fi...
SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const
unsigned getJumpTableEncoding() const override
JumpTable for VE.
SDValue lowerATOMIC_SWAP(SDValue Op, SelectionDAG &DAG) const
bool isIntDivCheap(EVT, AttributeList) const override
Return true if integer divide is usually cheaper than a sequence of several shifts,...
SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
Register getRegisterByName(const char *RegName, LLT VT, const MachineFunction &MF) const override
Return the register ID of the name passed in.
SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF, SelectionDAG &DAG) const
ConstraintType getConstraintType(StringRef Constraint) const override
Inline Assembly {.
SDValue lowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const
SDValue lowerToTLSGeneralDynamicModel(SDValue Op, SelectionDAG &DAG) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition ISDOpcodes.h:41
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition ISDOpcodes.h:841
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
CondCode
Definition VE.h:43
@ CC_GENAN
Definition VE.h:66
@ CC_EQNAN
Definition VE.h:65
@ CC_G
Definition VE.h:54
@ CC_NENAN
Definition VE.h:64
@ CC_LE
Definition VE.h:59
@ CC_LENAN
Definition VE.h:67
@ CC_ILE
Definition VE.h:50
@ CC_NUM
Definition VE.h:60
@ CC_EQ
Definition VE.h:57
@ CC_GNAN
Definition VE.h:62
@ CC_IG
Definition VE.h:45
@ CC_INE
Definition VE.h:47
@ CC_AF
Definition VE.h:53
@ CC_L
Definition VE.h:55
@ CC_GE
Definition VE.h:58
@ CC_NE
Definition VE.h:56
@ CC_LNAN
Definition VE.h:63
@ CC_IEQ
Definition VE.h:48
@ CC_AT
Definition VE.h:68
@ CC_NAN
Definition VE.h:61
@ CC_IGE
Definition VE.h:49
@ CC_IL
Definition VE.h:46
This is an optimization pass for GlobalISel generic memory operations.
static uint64_t getFpImmVal(const ConstantFPSDNode *N)
getFpImmVal - get immediate representation of floating point value
@ Offset
Definition DWP.cpp:532
static uint64_t getImmVal(const ConstantSDNode *N)
getImmVal - get immediate representation of integer value
static VECC::CondCode fpCondCode2Fcc(ISD::CondCode CC)
Convert a DAG floating point condition code to a VE FCC condition.
AtomicOrdering
Atomic ordering for LLVM's memory model.
DWARFExpression::Operation Op
static VECC::CondCode intCondCode2Icc(ISD::CondCode CC)
Convert a DAG integer condition code to a VE ICC condition.
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
This structure contains all information that is necessary for lowering calls.