AMDGPU/SI: Test commit
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyFastISel.cpp
1 //===-- WebAssemblyFastISel.cpp - WebAssembly FastISel implementation -----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
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.
14 ///
15 //===----------------------------------------------------------------------===//
16
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"
37 using namespace llvm;
38
39 #define DEBUG_TYPE "wasm-fastisel"
40
41 namespace {
42
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;
47   LLVMContext *Context;
48
49   // Call handling routines.
50 private:
51 public:
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();
58   }
59
60   bool fastSelectInstruction(const Instruction *I) override;
61
62 #include "WebAssemblyGenFastISel.inc"
63 };
64
65 } // end anonymous namespace
66
67 bool WebAssemblyFastISel::fastSelectInstruction(const Instruction *I) {
68   switch (I->getOpcode()) {
69   default:
70     break;
71     // TODO: add fast-isel selection cases here...
72   }
73
74   // Fall back to target-independent instruction selection.
75   return selectOperator(I, I->getOpcode());
76 }
77
78 FastISel *WebAssembly::createFastISel(FunctionLoweringInfo &FuncInfo,
79                                       const TargetLibraryInfo *LibInfo) {
80   return new WebAssemblyFastISel(FuncInfo, LibInfo);
81 }