2015-06-30 07:51:55 +08:00
|
|
|
//- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-06-30 07:51:55 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This file defines the interfaces that WebAssembly uses to lower LLVM
|
2015-06-30 07:51:55 +08:00
|
|
|
/// code into a selection DAG.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
|
|
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
|
|
|
|
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
namespace WebAssemblyISD {
|
|
|
|
|
2015-08-12 04:13:18 +08:00
|
|
|
enum NodeType : unsigned {
|
2015-06-30 07:51:55 +08:00
|
|
|
FIRST_NUMBER = ISD::BUILTIN_OP_END,
|
2015-08-25 06:16:48 +08:00
|
|
|
#define HANDLE_NODETYPE(NODE) NODE,
|
|
|
|
#include "WebAssemblyISD.def"
|
|
|
|
#undef HANDLE_NODETYPE
|
2015-06-30 07:51:55 +08:00
|
|
|
};
|
|
|
|
|
2018-09-05 09:27:38 +08:00
|
|
|
} // end namespace WebAssemblyISD
|
2015-06-30 07:51:55 +08:00
|
|
|
|
|
|
|
class WebAssemblySubtarget;
|
|
|
|
class WebAssemblyTargetMachine;
|
|
|
|
|
|
|
|
class WebAssemblyTargetLowering final : public TargetLowering {
|
2018-09-05 09:27:38 +08:00
|
|
|
public:
|
2015-06-30 07:51:55 +08:00
|
|
|
WebAssemblyTargetLowering(const TargetMachine &TM,
|
|
|
|
const WebAssemblySubtarget &STI);
|
|
|
|
|
2018-09-05 09:27:38 +08:00
|
|
|
private:
|
2015-06-30 07:51:55 +08:00
|
|
|
/// Keep a pointer to the WebAssemblySubtarget around so that we can make the
|
|
|
|
/// right decision when generating code for different targets.
|
|
|
|
const WebAssemblySubtarget *Subtarget;
|
2015-07-23 05:28:15 +08:00
|
|
|
|
2018-08-07 08:22:22 +08:00
|
|
|
AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
|
2015-08-25 02:44:37 +08:00
|
|
|
FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
|
|
|
|
const TargetLibraryInfo *LibInfo) const override;
|
2015-08-03 08:00:11 +08:00
|
|
|
MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
|
2017-11-28 09:13:40 +08:00
|
|
|
MachineBasicBlock *
|
|
|
|
EmitInstrWithCustomInserter(MachineInstr &MI,
|
|
|
|
MachineBasicBlock *MBB) const override;
|
2015-08-12 04:13:18 +08:00
|
|
|
const char *getTargetNodeName(unsigned Opcode) const override;
|
2018-09-05 09:27:38 +08:00
|
|
|
std::pair<unsigned, const TargetRegisterClass *>
|
|
|
|
getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
|
|
|
|
StringRef Constraint, MVT VT) const override;
|
2015-11-20 07:04:59 +08:00
|
|
|
bool isCheapToSpeculateCttz() const override;
|
|
|
|
bool isCheapToSpeculateCtlz() const override;
|
2015-12-16 06:01:29 +08:00
|
|
|
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
|
2017-07-21 19:59:37 +08:00
|
|
|
unsigned AS,
|
|
|
|
Instruction *I = nullptr) const override;
|
2016-01-26 11:39:31 +08:00
|
|
|
bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align,
|
2019-06-13 01:14:03 +08:00
|
|
|
MachineMemOperand::Flags Flags,
|
2016-01-26 11:39:31 +08:00
|
|
|
bool *Fast) const override;
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
|
2019-09-27 10:06:50 +08:00
|
|
|
bool isVectorLoadExtDesirable(SDValue ExtVal) const override;
|
2018-06-29 01:27:09 +08:00
|
|
|
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
|
|
|
|
EVT VT) const override;
|
2018-08-03 05:44:24 +08:00
|
|
|
bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
|
|
|
|
MachineFunction &MF,
|
|
|
|
unsigned Intrinsic) const override;
|
2018-06-29 01:27:09 +08:00
|
|
|
|
2015-08-25 06:16:48 +08:00
|
|
|
SDValue LowerCall(CallLoweringInfo &CLI,
|
|
|
|
SmallVectorImpl<SDValue> &InVals) const override;
|
2015-07-23 05:28:15 +08:00
|
|
|
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
|
|
|
|
bool isVarArg,
|
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
|
|
|
LLVMContext &Context) const override;
|
|
|
|
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
|
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
2016-06-12 23:39:02 +08:00
|
|
|
const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
|
2015-07-23 05:28:15 +08:00
|
|
|
SelectionDAG &DAG) const override;
|
|
|
|
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
|
|
|
|
bool IsVarArg,
|
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
2016-06-12 23:39:02 +08:00
|
|
|
const SDLoc &DL, SelectionDAG &DAG,
|
2015-07-23 05:28:15 +08:00
|
|
|
SmallVectorImpl<SDValue> &InVals) const override;
|
2015-08-25 06:16:48 +08:00
|
|
|
|
2019-05-24 02:09:26 +08:00
|
|
|
void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
|
|
|
|
SelectionDAG &DAG) const override;
|
|
|
|
|
2019-07-11 13:55:47 +08:00
|
|
|
const char *getClearCacheBuiltinName() const override {
|
|
|
|
report_fatal_error("llvm.clear_cache is not supported on wasm");
|
|
|
|
}
|
|
|
|
|
2015-08-25 06:16:48 +08:00
|
|
|
// Custom lowering hooks.
|
|
|
|
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
|
2015-12-12 07:49:46 +08:00
|
|
|
SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
|
2019-05-23 09:24:01 +08:00
|
|
|
SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
|
2016-02-17 07:48:04 +08:00
|
|
|
SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
|
2015-08-25 06:16:48 +08:00
|
|
|
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
|
2015-11-26 00:55:01 +08:00
|
|
|
SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
|
2015-09-17 00:51:30 +08:00
|
|
|
SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
|
2015-12-05 07:22:35 +08:00
|
|
|
SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
|
2016-02-17 02:18:36 +08:00
|
|
|
SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
|
[WebAssembly] Exception handling: Switch to the new proposal
Summary:
This switches the EH implementation to the new proposal:
https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md
(The previous proposal was
https://github.com/WebAssembly/exception-handling/blob/master/proposals/old/Exceptions.md)
- Instruction changes
- Now we have one single `catch` instruction that returns a except_ref
value
- `throw` now can take variable number of operations
- `rethrow` does not have 'depth' argument anymore
- `br_on_exn` queries an except_ref to see if it matches the tag and
branches to the given label if true.
- `extract_exception` is a pseudo instruction that simulates popping
values from wasm stack. This is to make `br_on_exn`, a very special
instruction, work: `br_on_exn` puts values onto the stack only if it
is taken, and the # of values can vay depending on the tag.
- Now there's only one `catch` per `try`, this patch removes all special
handling for terminate pad with a call to `__clang_call_terminate`.
Before it was the only case there are two catch clauses (a normal
`catch` and `catch_all` per `try`).
- Make `rethrow` act as a terminator like `throw`. This splits BB after
`rethrow` in WasmEHPrepare, and deletes an unnecessary `unreachable`
after `rethrow` in LateEHPrepare.
- Now we stop at all catchpads (because we add wasm `catch` instruction
that catches all exceptions), this creates new
`findWasmUnwindDestinations` function in SelectionDAGBuilder.
- Now we use `br_on_exn` instrution to figure out if an except_ref
matches the current tag or not, LateEHPrepare generates this sequence
for catch pads:
```
catch
block i32
br_on_exn $__cpp_exception
end_block
extract_exception
```
- Branch analysis for `br_on_exn` in WebAssemblyInstrInfo
- Other various misc. changes to switch to the new proposal.
Reviewers: dschuff
Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D57134
llvm-svn: 352598
2019-01-30 11:21:57 +08:00
|
|
|
SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const;
|
2019-01-11 06:32:11 +08:00
|
|
|
SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
|
2019-01-30 10:23:29 +08:00
|
|
|
SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
|
2018-09-08 05:54:46 +08:00
|
|
|
SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
|
2018-11-02 08:06:56 +08:00
|
|
|
SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
|
2018-10-20 09:31:18 +08:00
|
|
|
SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
|
2015-06-30 07:51:55 +08:00
|
|
|
};
|
|
|
|
|
2015-08-25 02:44:37 +08:00
|
|
|
namespace WebAssembly {
|
|
|
|
FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
|
|
|
|
const TargetLibraryInfo *libInfo);
|
2018-09-05 09:27:38 +08:00
|
|
|
} // end namespace WebAssembly
|
2015-08-25 02:44:37 +08:00
|
|
|
|
2018-09-05 09:27:38 +08:00
|
|
|
} // end namespace llvm
|
2015-06-30 07:51:55 +08:00
|
|
|
|
|
|
|
#endif
|