llvm.org GIT mirror llvm / 3c334d6
[WebAssembly] Skeleton FastISel support git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245860 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 5 years ago
8 changed file(s) with 143 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
418418 const TargetRegisterClass *RC, unsigned Op0,
419419 bool Op0IsKill, uint64_t Imm1, uint64_t Imm2);
420420
421 /// \brief Emit a MachineInstr with two register operands and a result
421 /// \brief Emit a MachineInstr with a floating point immediate, and a result
422422 /// register in the given register class.
423 unsigned fastEmitInst_f(unsigned MachineInstOpcode,
424 const TargetRegisterClass *RC,
425 const ConstantFP *FPImm);
426
427 /// \brief Emit a MachineInstr with one register operand, a floating point
428 /// immediate, and a result register in the given register class.
423429 unsigned fastEmitInst_rf(unsigned MachineInstOpcode,
424430 const TargetRegisterClass *RC, unsigned Op0,
425431 bool Op0IsKill, const ConstantFP *FPImm);
18661866 return ResultReg;
18671867 }
18681868
1869 unsigned FastISel::fastEmitInst_f(unsigned MachineInstOpcode,
1870 const TargetRegisterClass *RC,
1871 const ConstantFP *FPImm) {
1872 const MCInstrDesc &II = TII.get(MachineInstOpcode);
1873
1874 unsigned ResultReg = createResultReg(RC);
1875
1876 if (II.getNumDefs() >= 1)
1877 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1878 .addFPImm(FPImm);
1879 else {
1880 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
1881 .addFPImm(FPImm);
1882 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1883 TII.get(TargetOpcode::COPY), ResultReg).addReg(II.ImplicitDefs[0]);
1884 }
1885 return ResultReg;
1886 }
1887
18691888 unsigned FastISel::fastEmitInst_rf(unsigned MachineInstOpcode,
18701889 const TargetRegisterClass *RC, unsigned Op0,
18711890 bool Op0IsKill, const ConstantFP *FPImm) {
11
22 tablegen(LLVM WebAssemblyGenAsmWriter.inc -gen-asm-writer)
33 tablegen(LLVM WebAssemblyGenDAGISel.inc -gen-dag-isel)
4 tablegen(LLVM WebAssemblyGenFastISel.inc -gen-fast-isel)
45 tablegen(LLVM WebAssemblyGenInstrInfo.inc -gen-instr-info)
56 tablegen(LLVM WebAssemblyGenMCCodeEmitter.inc -gen-emitter)
67 tablegen(LLVM WebAssemblyGenRegisterInfo.inc -gen-register-info)
1011 add_llvm_target(WebAssemblyCodeGen
1112 Relooper.cpp
1213 WebAssemblyAsmPrinter.cpp
14 WebAssemblyFastISel.cpp
1315 WebAssemblyFrameLowering.cpp
1416 WebAssemblyISelDAGToDAG.cpp
1517 WebAssemblyISelLowering.cpp
1414 BUILT_SOURCES = \
1515 WebAssemblyGenAsmWriter.inc \
1616 WebAssemblyGenDAGISel.inc \
17 WebAssemblyGenFastISel.inc \
1718 WebAssemblyGenInstrInfo.inc \
1819 WebAssemblyGenMCCodeEmitter.inc \
1920 WebAssemblyGenRegisterInfo.inc \
0 //===-- WebAssemblyFastISel.cpp - WebAssembly FastISel implementation -----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file defines the WebAssembly-specific support for the FastISel
11 /// class. Some of the target-specific code is generated by tablegen in the file
12 /// WebAssemblyGenFastISel.inc, which is #included here.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #include "WebAssembly.h"
17 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
18 #include "WebAssemblySubtarget.h"
19 #include "WebAssemblyTargetMachine.h"
20 #include "llvm/Analysis/BranchProbabilityInfo.h"
21 #include "llvm/CodeGen/FastISel.h"
22 #include "llvm/CodeGen/FunctionLoweringInfo.h"
23 #include "llvm/CodeGen/MachineConstantPool.h"
24 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineInstrBuilder.h"
26 #include "llvm/CodeGen/MachineRegisterInfo.h"
27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/GetElementPtrTypeIterator.h"
31 #include "llvm/IR/GlobalAlias.h"
32 #include "llvm/IR/GlobalVariable.h"
33 #include "llvm/IR/Instructions.h"
34 #include "llvm/IR/IntrinsicInst.h"
35 #include "llvm/IR/Operator.h"
36 using namespace llvm;
37
38 #define DEBUG_TYPE "wasm-fastisel"
39
40 namespace {
41
42 class WebAssemblyFastISel final : public FastISel {
43 /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
44 /// right decision when generating code for different targets.
45 const WebAssemblySubtarget *Subtarget;
46 LLVMContext *Context;
47
48 // Call handling routines.
49 private:
50 public:
51 // Backend specific FastISel code.
52 WebAssemblyFastISel(FunctionLoweringInfo &FuncInfo,
53 const TargetLibraryInfo *LibInfo)
54 : FastISel(FuncInfo, LibInfo, /*SkipTargetIndependentISel=*/true) {
55 Subtarget = &FuncInfo.MF->getSubtarget();
56 Context = &FuncInfo.Fn->getContext();
57 }
58
59 bool fastSelectInstruction(const Instruction *I) override;
60
61 #include "WebAssemblyGenFastISel.inc"
62 };
63
64 } // end anonymous namespace
65
66 bool WebAssemblyFastISel::fastSelectInstruction(const Instruction *I) {
67 switch (I->getOpcode()) {
68 default:
69 break;
70 // TODO: add fast-isel selection cases here...
71 }
72
73 // Fall back to target-independent instruction selection.
74 return selectOperator(I, I->getOpcode());
75 }
76
77 FastISel *WebAssembly::createFastISel(FunctionLoweringInfo &FuncInfo,
78 const TargetLibraryInfo *LibInfo) {
79 return new WebAssemblyFastISel(FuncInfo, LibInfo);
80 }
148148 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
149149 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
150150 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand);
151 }
152
153 FastISel *WebAssemblyTargetLowering::createFastISel(
154 FunctionLoweringInfo &FuncInfo, const TargetLibraryInfo *LibInfo) const {
155 return WebAssembly::createFastISel(FuncInfo, LibInfo);
151156 }
152157
153158 MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout &DL,
4444 /// right decision when generating code for different targets.
4545 const WebAssemblySubtarget *Subtarget;
4646
47 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
48 const TargetLibraryInfo *LibInfo) const override;
49
4750 MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
4851
4952 const char *getTargetNodeName(unsigned Opcode) const override;
6568 SmallVectorImpl &InVals) const override;
6669 };
6770
71 namespace WebAssembly {
72 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
73 const TargetLibraryInfo *libInfo);
74 } // end namespace WebAssembly
75
6876 } // end namespace llvm
6977
7078 #endif
0 ; RUN: llc < %s -asm-verbose=false \
1 ; RUN: -fast-isel -fast-isel-abort=1 -verify-machineinstrs \
2 ; RUN: | FileCheck %s
3
4 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
5 target triple = "wasm32-unknown-unknown"
6
7 ; This tests very minimal fast-isel functionality.
8
9 ; CHECK-LABEL: immediate_f32
10 ; CHECK: (immediate 0x1.4p1)
11 define float @immediate_f32() {
12 ret float 2.5
13 }
14
15 ; CHECK-LABEL: immediate_f64
16 ; CHECK: (immediate 0x1.4p1)
17 define double @immediate_f64() {
18 ret double 2.5
19 }