1 //===-- WebAssemblyFastISel.cpp - WebAssembly FastISel implementation -----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file defines the WebAssembly-specific support for the FastISel
12 /// class. Some of the target-specific code is generated by tablegen in the file
13 /// WebAssemblyGenFastISel.inc, which is #included here.
15 //===----------------------------------------------------------------------===//
17 #include "WebAssembly.h"
18 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
19 #include "WebAssemblySubtarget.h"
20 #include "WebAssemblyTargetMachine.h"
21 #include "llvm/Analysis/BranchProbabilityInfo.h"
22 #include "llvm/CodeGen/FastISel.h"
23 #include "llvm/CodeGen/FunctionLoweringInfo.h"
24 #include "llvm/CodeGen/MachineConstantPool.h"
25 #include "llvm/CodeGen/MachineFrameInfo.h"
26 #include "llvm/CodeGen/MachineInstrBuilder.h"
27 #include "llvm/CodeGen/MachineRegisterInfo.h"
28 #include "llvm/IR/DataLayout.h"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/GetElementPtrTypeIterator.h"
32 #include "llvm/IR/GlobalAlias.h"
33 #include "llvm/IR/GlobalVariable.h"
34 #include "llvm/IR/Instructions.h"
35 #include "llvm/IR/IntrinsicInst.h"
36 #include "llvm/IR/Operator.h"
39 #define DEBUG_TYPE "wasm-fastisel"
43 class WebAssemblyFastISel final : public FastISel {
44 /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
45 /// right decision when generating code for different targets.
46 const WebAssemblySubtarget *Subtarget;
49 // Call handling routines.
52 // Backend specific FastISel code.
53 WebAssemblyFastISel(FunctionLoweringInfo &FuncInfo,
54 const TargetLibraryInfo *LibInfo)
55 : FastISel(FuncInfo, LibInfo, /*SkipTargetIndependentISel=*/true) {
56 Subtarget = &FuncInfo.MF->getSubtarget<WebAssemblySubtarget>();
57 Context = &FuncInfo.Fn->getContext();
60 bool fastSelectInstruction(const Instruction *I) override;
62 #include "WebAssemblyGenFastISel.inc"
65 } // end anonymous namespace
67 bool WebAssemblyFastISel::fastSelectInstruction(const Instruction *I) {
68 switch (I->getOpcode()) {
71 // TODO: add fast-isel selection cases here...
74 // Fall back to target-independent instruction selection.
75 return selectOperator(I, I->getOpcode());
78 FastISel *WebAssembly::createFastISel(FunctionLoweringInfo &FuncInfo,
79 const TargetLibraryInfo *LibInfo) {
80 return new WebAssemblyFastISel(FuncInfo, LibInfo);