LLVM  14.0.0git
WebAssemblyISelLowering.h
Go to the documentation of this file.
1 //- WebAssemblyISelLowering.h - WebAssembly 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 /// \file
10 /// This file defines the interfaces that WebAssembly uses to lower LLVM
11 /// code into a selection DAG.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
17 
19 
20 namespace llvm {
21 
22 namespace WebAssemblyISD {
23 
24 enum NodeType : unsigned {
26 #define HANDLE_NODETYPE(NODE) NODE,
27 #define HANDLE_MEM_NODETYPE(NODE)
28 #include "WebAssemblyISD.def"
30 #undef HANDLE_NODETYPE
31 #undef HANDLE_MEM_NODETYPE
32 #define HANDLE_NODETYPE(NODE)
33 #define HANDLE_MEM_NODETYPE(NODE) NODE,
34 #include "WebAssemblyISD.def"
35 #undef HANDLE_NODETYPE
36 #undef HANDLE_MEM_NODETYPE
37 };
38 
39 } // end namespace WebAssemblyISD
40 
41 class WebAssemblySubtarget;
42 
44 public:
46  const WebAssemblySubtarget &STI);
47 
48  enum WasmAddressSpace : unsigned {
49  // WebAssembly uses the following address spaces:
50  // AS 0 : is the default address space for values in linear memory
51  DEFAULT = 0,
52  // AS 1 : is a non-integral address space for global variables
53  GLOBAL = 1,
54  // AS 10 : is a non-integral address space for externref values
55  EXTERNREF = 10,
56  // AS 20 : is a non-integral address space for funcref values
57  FUNCREF = 20,
58  };
59 
60  MVT getPointerTy(const DataLayout &DL, uint32_t AS = 0) const override {
61  if (AS == WasmAddressSpace::EXTERNREF)
62  return MVT::externref;
63  if (AS == WasmAddressSpace::FUNCREF)
64  return MVT::funcref;
65  return TargetLowering::getPointerTy(DL, AS);
66  }
67  MVT getPointerMemTy(const DataLayout &DL, uint32_t AS = 0) const override {
68  if (AS == WasmAddressSpace::EXTERNREF)
69  return MVT::externref;
70  if (AS == WasmAddressSpace::FUNCREF)
71  return MVT::funcref;
73  }
74 
75  static bool isFuncrefType(const Type *Ty);
76  static bool isExternrefType(const Type *Ty);
77 
78 private:
79  /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
80  /// right decision when generating code for different targets.
81  const WebAssemblySubtarget *Subtarget;
82 
83  AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
84  bool shouldScalarizeBinop(SDValue VecOp) const override;
85  FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
86  const TargetLibraryInfo *LibInfo) const override;
87  MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
89  EmitInstrWithCustomInserter(MachineInstr &MI,
90  MachineBasicBlock *MBB) const override;
91  const char *getTargetNodeName(unsigned Opcode) const override;
92  std::pair<unsigned, const TargetRegisterClass *>
93  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
94  StringRef Constraint, MVT VT) const override;
95  bool isCheapToSpeculateCttz() const override;
96  bool isCheapToSpeculateCtlz() const override;
97  bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
98  unsigned AS,
99  Instruction *I = nullptr) const override;
100  bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, Align Alignment,
102  bool *Fast) const override;
103  bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
104  bool isVectorLoadExtDesirable(SDValue ExtVal) const override;
105  bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
106  EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
107  EVT VT) const override;
108  bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
109  MachineFunction &MF,
110  unsigned Intrinsic) const override;
111 
112  void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known,
113  const APInt &DemandedElts,
114  const SelectionDAG &DAG,
115  unsigned Depth) const override;
116 
118  getPreferredVectorAction(MVT VT) const override;
119 
120  SDValue LowerCall(CallLoweringInfo &CLI,
121  SmallVectorImpl<SDValue> &InVals) const override;
122  bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
123  bool isVarArg,
125  LLVMContext &Context) const override;
126  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
128  const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
129  SelectionDAG &DAG) const override;
130  SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
131  bool IsVarArg,
133  const SDLoc &DL, SelectionDAG &DAG,
134  SmallVectorImpl<SDValue> &InVals) const override;
135 
136  void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
137  SelectionDAG &DAG) const override;
138 
139  const char *getClearCacheBuiltinName() const override {
140  report_fatal_error("llvm.clear_cache is not supported on wasm");
141  }
142 
143  // Custom lowering hooks.
144  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
145  SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
146  SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
147  SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
148  SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
149  SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
150  SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
151  SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
152  SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
153  SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
154  SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
155  SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const;
156  SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
157  SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
158  SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
159  SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
160  SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
161  SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
162  SDValue LowerFP_TO_INT_SAT(SDValue Op, SelectionDAG &DAG) const;
163  SDValue LowerLoad(SDValue Op, SelectionDAG &DAG) const;
164  SDValue LowerStore(SDValue Op, SelectionDAG &DAG) const;
165 
166  // Custom DAG combine hooks
167  SDValue
168  PerformDAGCombine(SDNode *N,
169  TargetLowering::DAGCombinerInfo &DCI) const override;
170 };
171 
172 namespace WebAssembly {
173 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
174  const TargetLibraryInfo *libInfo);
175 } // end namespace WebAssembly
176 
177 } // end namespace llvm
178 
179 #endif
llvm::TargetLoweringBase::getPointerMemTy
virtual MVT getPointerMemTy(const DataLayout &DL, uint32_t AS=0) const
Return the in-memory pointer type for the given address space, defaults to the pointer type from the ...
Definition: TargetLowering.h:353
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::SDLoc
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Definition: SelectionDAGNodes.h:1086
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::WebAssemblyTargetLowering::isFuncrefType
static bool isFuncrefType(const Type *Ty)
Definition: WebAssemblyISelLowering.cpp:1391
llvm::SDNode
Represents one node in the SelectionDAG.
Definition: SelectionDAGNodes.h:455
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:233
llvm::Depth
@ Depth
Definition: SIMachineScheduler.h:36
llvm::WebAssemblyISD::NodeType
NodeType
Definition: WebAssemblyISelLowering.h:24
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::AttributeList
Definition: Attributes.h:398
Results
Function Alias Analysis Results
Definition: AliasAnalysis.cpp:847
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1567
llvm::WebAssemblyTargetLowering::EXTERNREF
@ EXTERNREF
Definition: WebAssemblyISelLowering.h:55
llvm::WebAssemblyTargetLowering::WebAssemblyTargetLowering
WebAssemblyTargetLowering(const TargetMachine &TM, const WebAssemblySubtarget &STI)
Definition: WebAssemblyISelLowering.cpp:43
llvm::WebAssemblyTargetLowering
Definition: WebAssemblyISelLowering.h:43
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MVT::funcref
@ funcref
Definition: MachineValueType.h:270
TargetLowering.h
llvm::WebAssemblyTargetLowering::WasmAddressSpace
WasmAddressSpace
Definition: WebAssemblyISelLowering.h:48
llvm::WebAssembly::createFastISel
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
Definition: WebAssemblyFastISel.cpp:1431
llvm::SelectionDAG
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:216
llvm::EVT
Extended Value Type.
Definition: ValueTypes.h:35
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3189
llvm::Instruction
Definition: Instruction.h:45
llvm::WebAssemblyTargetLowering::DEFAULT
@ DEFAULT
Definition: WebAssemblyISelLowering.h:51
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::WebAssemblyTargetLowering::isExternrefType
static bool isExternrefType(const Type *Ty)
Definition: WebAssemblyISelLowering.cpp:1396
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MVT::externref
@ externref
Definition: MachineValueType.h:271
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::WebAssemblyISD::FIRST_NUMBER
@ FIRST_NUMBER
Definition: WebAssemblyISelLowering.h:25
llvm::WebAssemblyTargetLowering::FUNCREF
@ FUNCREF
Definition: WebAssemblyISelLowering.h:57
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::MachineMemOperand::Flags
Flags
Flags values. These may be or'd together.
Definition: MachineMemOperand.h:131
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
llvm::FunctionLoweringInfo
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Definition: FunctionLoweringInfo.h:53
llvm::MVT
Machine Value Type.
Definition: MachineValueType.h:31
llvm::FastISel
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition: FastISel.h:65
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::WebAssemblyTargetLowering::getPointerMemTy
MVT getPointerMemTy(const DataLayout &DL, uint32_t AS=0) const override
Return the in-memory pointer type for the given address space, defaults to the pointer type from the ...
Definition: WebAssemblyISelLowering.h:67
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
AddrMode
AddrMode
Definition: MSP430Disassembler.cpp:142
llvm::WebAssemblySubtarget
Definition: WebAssemblySubtarget.h:35
llvm::ISD::BUILTIN_OP_END
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:1249
llvm::AtomicRMWInst
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:726
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::WebAssemblyTargetLowering::GLOBAL
@ GLOBAL
Definition: WebAssemblyISelLowering.h:53
llvm::GlobalAddressSDNode
Definition: SelectionDAGNodes.h:1718
llvm::KnownBits
Definition: KnownBits.h:23
llvm::TargetLoweringBase::AtomicExpansionKind
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
Definition: TargetLowering.h:250
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:321
llvm::TargetLoweringBase::LegalizeTypeAction
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
Definition: TargetLowering.h:206
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:219
llvm::SDValue
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Definition: SelectionDAGNodes.h:138
llvm::ISD::FIRST_TARGET_MEMORY_OPCODE
static const int FIRST_TARGET_MEMORY_OPCODE
FIRST_TARGET_MEMORY_OPCODE - Target-specific pre-isel operations which do not reference a specific me...
Definition: ISDOpcodes.h:1261
N
#define N
llvm::MipsISD::Ins
@ Ins
Definition: MipsISelLowering.h:157
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1475
llvm::WebAssemblyISD::FIRST_MEM_OPCODE
@ FIRST_MEM_OPCODE
Definition: WebAssemblyISelLowering.h:29
llvm::WebAssemblyTargetLowering::getPointerTy
MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const override
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
Definition: WebAssemblyISelLowering.h:60
llvm::TargetLoweringBase::getPointerTy
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
Definition: TargetLowering.h:346