20 #include "llvm/IR/IntrinsicsWebAssembly.h" 27 #define DEBUG_TYPE "wasm-isel" 46 return "WebAssembly Instruction Selection";
51 "********** Function: " 57 if (Subtarget->hasAddr64())
59 "64-bit WebAssembly (wasm64) is not currently supported");
66 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
unsigned ConstraintID,
67 std::vector<SDValue> &OutOps)
override;
70 #include "WebAssemblyGenDAGISel.inc" 93 uint64_t SyncScopeID =
96 switch (SyncScopeID) {
101 Fence = CurDAG->getMachineNode(WebAssembly::COMPILER_FENCE,
110 Fence = CurDAG->getMachineNode(
114 CurDAG->getTargetConstant(0, DL,
MVT::i32),
122 ReplaceNode(Node, Fence);
123 CurDAG->RemoveDeadNode(Node);
128 const auto *GA = cast<GlobalAddressSDNode>(Node);
139 if (GA->getGlobal()->getThreadLocalMode() !=
141 !Subtarget->getTargetTriple().isOSEmscripten()) {
143 "non-Emscripten OSes: variable " +
144 GA->getGlobal()->getName(),
148 MVT PtrVT = TLI->getPointerTy(CurDAG->getDataLayout());
151 SDValue TLSBaseSym = CurDAG->getTargetExternalSymbol(
"__tls_base", PtrVT);
152 SDValue TLSOffsetSym = CurDAG->getTargetGlobalAddress(
153 GA->getGlobal(), DL, PtrVT, GA->getOffset(), 0);
155 MachineSDNode *TLSBase = CurDAG->getMachineNode(WebAssembly::GLOBAL_GET_I32,
158 WebAssembly::CONST_I32, DL,
MVT::i32, TLSOffsetSym);
160 CurDAG->getMachineNode(WebAssembly::ADD_I32, DL,
MVT::i32,
162 ReplaceNode(Node, TLSAddress);
167 unsigned IntNo = cast<ConstantSDNode>(Node->
getOperand(0))->getZExtValue();
169 case Intrinsic::wasm_tls_size: {
170 MVT PtrVT = TLI->getPointerTy(CurDAG->getDataLayout());
174 WebAssembly::GLOBAL_GET_I32, DL, PtrVT,
175 CurDAG->getTargetExternalSymbol(
"__tls_size",
MVT::i32));
176 ReplaceNode(Node, TLSSize);
179 case Intrinsic::wasm_tls_align: {
180 MVT PtrVT = TLI->getPointerTy(CurDAG->getDataLayout());
184 WebAssembly::GLOBAL_GET_I32, DL, PtrVT,
185 CurDAG->getTargetExternalSymbol(
"__tls_align",
MVT::i32));
186 ReplaceNode(Node, TLSAlign);
193 unsigned IntNo = cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue();
195 case Intrinsic::wasm_tls_base: {
196 MVT PtrVT = TLI->getPointerTy(CurDAG->getDataLayout());
201 CurDAG->getTargetExternalSymbol(
"__tls_base", PtrVT),
203 ReplaceNode(Node, TLSBase);
218 bool WebAssemblyDAGToDAGISel::SelectInlineAsmMemoryOperand(
219 const SDValue &
Op,
unsigned ConstraintID, std::vector<SDValue> &OutOps) {
220 switch (ConstraintID) {
224 OutOps.push_back(Op);
237 return new WebAssemblyDAGToDAGISel(TM, OptLevel);
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
void setNodeId(int Id)
Set unique node id.
SDNode * getNode() const
get the SDNode which holds the desired result
Synchronized with respect to signal handlers executing in the same thread.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
This file declares the WebAssembly-specific subclass of TargetMachine.
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
FunctionPass * createWebAssemblyISelDag(WebAssemblyTargetMachine &TM, CodeGenOpt::Level OptLevel)
This pass converts a legalized DAG into a WebAssembly-specific DAG, ready for instruction scheduling...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const SDValue & getOperand(unsigned Num) const
This file provides WebAssembly-specific target descriptions.
FunctionPass class - This class is used to implement most global optimizations.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Synchronized with respect to all concurrently executing threads.
void dump() const
Dump this node, for debugging.
An SDNode that represents everything that will be needed to construct a MachineInstr.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool hasBulkMemory() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...