Skip to content

Commit 9976e57

Browse files
[WebAssembly][GlobalISel] Part 1 - Setup skeleton (llvm#178796)
This PR is the first step towards bringing GlobalISel to the Wasm backend. Split from llvm#157161
1 parent 4a7e572 commit 9976e57

19 files changed

+930
-1
lines changed

llvm/lib/Target/WebAssembly/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ tablegen(LLVM WebAssemblyGenDisassemblerTables.inc -gen-disassembler)
99
tablegen(LLVM WebAssemblyGenFastISel.inc -gen-fast-isel)
1010
tablegen(LLVM WebAssemblyGenInstrInfo.inc -gen-instr-info)
1111
tablegen(LLVM WebAssemblyGenMCCodeEmitter.inc -gen-emitter)
12+
tablegen(LLVM WebAssemblyGenRegisterBank.inc -gen-register-bank)
1213
tablegen(LLVM WebAssemblyGenRegisterInfo.inc -gen-register-info)
1314
tablegen(LLVM WebAssemblyGenSDNodeInfo.inc -gen-sd-node-info)
1415
tablegen(LLVM WebAssemblyGenSubtargetInfo.inc -gen-subtarget)
1516

17+
set(LLVM_TARGET_DEFINITIONS WebAssemblyGISel.td)
18+
tablegen(LLVM WebAssemblyGenGlobalISel.inc -gen-global-isel)
19+
tablegen(LLVM WebAssemblyGenPreLegalizeGICombiner.inc -gen-global-isel-combiner
20+
-combiners="WebAssemblyPreLegalizerCombiner")
21+
tablegen(LLVM WebAssemblyGenPostLegalizeGICombiner.inc -gen-global-isel-combiner
22+
-combiners="WebAssemblyPostLegalizerCombiner")
23+
1624
add_public_tablegen_target(WebAssemblyCommonTableGen)
1725

1826
add_llvm_target(WebAssemblyCodeGen
27+
GISel/WebAssemblyCallLowering.cpp
28+
GISel/WebAssemblyInstructionSelector.cpp
29+
GISel/WebAssemblyPostLegalizerCombiner.cpp
30+
GISel/WebAssemblyPreLegalizerCombiner.cpp
31+
GISel/WebAssemblyLegalizerInfo.cpp
32+
GISel/WebAssemblyRegisterBankInfo.cpp
1933
WebAssemblyAddMissingPrototypes.cpp
2034
WebAssemblyArgumentMove.cpp
2135
WebAssemblyAsmPrinter.cpp
@@ -72,6 +86,7 @@ add_llvm_target(WebAssemblyCodeGen
7286
CodeGen
7387
CodeGenTypes
7488
Core
89+
GlobalISel
7590
MC
7691
Scalar
7792
SelectionDAG
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//===-- WebAssemblyCallLowering.cpp - Call lowering for GlobalISel -*- C++ -*-//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// This file implements the lowering of LLVM calls to machine code calls for
11+
/// GlobalISel.
12+
///
13+
//===----------------------------------------------------------------------===//
14+
15+
#include "WebAssemblyCallLowering.h"
16+
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
17+
#include "WebAssemblyISelLowering.h"
18+
#include "WebAssemblyMachineFunctionInfo.h"
19+
#include "WebAssemblySubtarget.h"
20+
#include "WebAssemblyUtilities.h"
21+
#include "llvm/CodeGen/Analysis.h"
22+
#include "llvm/IR/DataLayout.h"
23+
#include "llvm/IR/DebugLoc.h"
24+
#include "llvm/IR/Value.h"
25+
26+
#define DEBUG_TYPE "wasm-call-lowering"
27+
28+
using namespace llvm;
29+
30+
WebAssemblyCallLowering::WebAssemblyCallLowering(
31+
const WebAssemblyTargetLowering &TLI)
32+
: CallLowering(&TLI) {}
33+
34+
bool WebAssemblyCallLowering::canLowerReturn(MachineFunction &MF,
35+
CallingConv::ID CallConv,
36+
SmallVectorImpl<BaseArgInfo> &Outs,
37+
bool IsVarArg) const {
38+
return WebAssembly::canLowerReturn(Outs.size(),
39+
&MF.getSubtarget<WebAssemblySubtarget>());
40+
}
41+
42+
bool WebAssemblyCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
43+
const Value *Val,
44+
ArrayRef<Register> VRegs,
45+
FunctionLoweringInfo &FLI,
46+
Register SwiftErrorVReg) const {
47+
if (!Val)
48+
return true; // allow only void returns for now
49+
50+
return false;
51+
}
52+
53+
bool WebAssemblyCallLowering::lowerFormalArguments(
54+
MachineIRBuilder &MIRBuilder, const Function &F,
55+
ArrayRef<ArrayRef<Register>> VRegs, FunctionLoweringInfo &FLI) const {
56+
if (VRegs.empty())
57+
return true; // allow only empty signatures for now
58+
59+
return false;
60+
}
61+
62+
bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
63+
CallLoweringInfo &Info) const {
64+
return false;
65+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-- WebAssemblyCallLowering.h - Call lowering for GlobalISel -*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// This file describes how to lower LLVM calls to machine code calls.
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_GISEL_WEBASSEMBLYCALLLOWERING_H
15+
#define LLVM_LIB_TARGET_WEBASSEMBLY_GISEL_WEBASSEMBLYCALLLOWERING_H
16+
17+
#include "WebAssemblyISelLowering.h"
18+
#include "llvm/CodeGen/GlobalISel/CallLowering.h"
19+
#include "llvm/IR/CallingConv.h"
20+
21+
namespace llvm {
22+
23+
class WebAssemblyTargetLowering;
24+
25+
class WebAssemblyCallLowering : public CallLowering {
26+
public:
27+
WebAssemblyCallLowering(const WebAssemblyTargetLowering &TLI);
28+
29+
bool canLowerReturn(MachineFunction &MF, CallingConv::ID CallConv,
30+
SmallVectorImpl<BaseArgInfo> &Outs,
31+
bool IsVarArg) const override;
32+
bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val,
33+
ArrayRef<Register> VRegs, FunctionLoweringInfo &FLI,
34+
Register SwiftErrorVReg) const override;
35+
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F,
36+
ArrayRef<ArrayRef<Register>> VRegs,
37+
FunctionLoweringInfo &FLI) const override;
38+
bool lowerCall(MachineIRBuilder &MIRBuilder,
39+
CallLoweringInfo &Info) const override;
40+
};
41+
} // namespace llvm
42+
43+
#endif
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//===- WebAssemblyInstructionSelector.cpp ------------------------*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// This file implements the targeting of the InstructionSelector class for
10+
/// WebAssembly.
11+
/// \todo This should be generated by TableGen.
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "GISel/WebAssemblyRegisterBankInfo.h"
15+
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
16+
#include "WebAssemblyRegisterInfo.h"
17+
#include "WebAssemblySubtarget.h"
18+
#include "WebAssemblyTargetMachine.h"
19+
#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"
20+
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
21+
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
22+
#include "llvm/CodeGen/GlobalISel/Utils.h"
23+
#include "llvm/CodeGen/MachineOperand.h"
24+
#include "llvm/CodeGen/TargetLowering.h"
25+
#include "llvm/IR/IntrinsicsWebAssembly.h"
26+
27+
#define DEBUG_TYPE "wasm-isel"
28+
29+
using namespace llvm;
30+
31+
namespace {
32+
33+
#define GET_GLOBALISEL_PREDICATE_BITSET
34+
#include "WebAssemblyGenGlobalISel.inc"
35+
#undef GET_GLOBALISEL_PREDICATE_BITSET
36+
37+
class WebAssemblyInstructionSelector : public InstructionSelector {
38+
public:
39+
WebAssemblyInstructionSelector(const WebAssemblyTargetMachine &TM,
40+
const WebAssemblySubtarget &STI,
41+
const WebAssemblyRegisterBankInfo &RBI);
42+
43+
bool select(MachineInstr &I) override;
44+
45+
static const char *getName() { return DEBUG_TYPE; }
46+
47+
private:
48+
bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
49+
50+
const WebAssemblyTargetMachine &TM;
51+
// const WebAssemblySubtarget &STI;
52+
const WebAssemblyInstrInfo &TII;
53+
const WebAssemblyRegisterInfo &TRI;
54+
const WebAssemblyRegisterBankInfo &RBI;
55+
56+
#define GET_GLOBALISEL_PREDICATES_DECL
57+
#include "WebAssemblyGenGlobalISel.inc"
58+
#undef GET_GLOBALISEL_PREDICATES_DECL
59+
60+
#define GET_GLOBALISEL_TEMPORARIES_DECL
61+
#include "WebAssemblyGenGlobalISel.inc"
62+
#undef GET_GLOBALISEL_TEMPORARIES_DECL
63+
};
64+
65+
} // end anonymous namespace
66+
67+
#define GET_GLOBALISEL_IMPL
68+
#include "WebAssemblyGenGlobalISel.inc"
69+
#undef GET_GLOBALISEL_IMPL
70+
71+
WebAssemblyInstructionSelector::WebAssemblyInstructionSelector(
72+
const WebAssemblyTargetMachine &TM, const WebAssemblySubtarget &STI,
73+
const WebAssemblyRegisterBankInfo &RBI)
74+
: TM(TM), /*STI(STI),*/ TII(*STI.getInstrInfo()),
75+
TRI(*STI.getRegisterInfo()), RBI(RBI),
76+
77+
#define GET_GLOBALISEL_PREDICATES_INIT
78+
#include "WebAssemblyGenGlobalISel.inc"
79+
#undef GET_GLOBALISEL_PREDICATES_INIT
80+
#define GET_GLOBALISEL_TEMPORARIES_INIT
81+
#include "WebAssemblyGenGlobalISel.inc"
82+
#undef GET_GLOBALISEL_TEMPORARIES_INIT
83+
{
84+
}
85+
86+
bool WebAssemblyInstructionSelector::select(MachineInstr &I) {
87+
if (selectImpl(I, *CoverageInfo))
88+
return true;
89+
90+
return false;
91+
}
92+
93+
namespace llvm {
94+
InstructionSelector *
95+
createWebAssemblyInstructionSelector(const WebAssemblyTargetMachine &TM,
96+
const WebAssemblySubtarget &Subtarget,
97+
const WebAssemblyRegisterBankInfo &RBI) {
98+
return new WebAssemblyInstructionSelector(TM, Subtarget, RBI);
99+
}
100+
} // namespace llvm
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===- WebAssemblyLegalizerInfo.cpp ------------------------------*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// This file implements the targeting of the Machinelegalizer class for
10+
/// WebAssembly.
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "WebAssemblyLegalizerInfo.h"
14+
15+
#define DEBUG_TYPE "wasm-legalinfo"
16+
17+
using namespace llvm;
18+
using namespace LegalizeActions;
19+
20+
WebAssemblyLegalizerInfo::WebAssemblyLegalizerInfo(
21+
const WebAssemblySubtarget &ST) {
22+
getLegacyLegalizerInfo().computeTables();
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- WebAssemblyLegalizerInfo.h --------------------------------*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// This file declares the targeting of the Machinelegalizer class for
10+
/// WebAssembly.
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_GISEL_WEBASSEMBLYMACHINELEGALIZER_H
14+
#define LLVM_LIB_TARGET_WEBASSEMBLY_GISEL_WEBASSEMBLYMACHINELEGALIZER_H
15+
16+
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
17+
18+
namespace llvm {
19+
20+
class WebAssemblySubtarget;
21+
22+
/// This class provides the information for the WebAssembly target legalizer for
23+
/// GlobalISel.
24+
class WebAssemblyLegalizerInfo : public LegalizerInfo {
25+
public:
26+
WebAssemblyLegalizerInfo(const WebAssemblySubtarget &ST);
27+
};
28+
} // namespace llvm
29+
#endif

0 commit comments

Comments
 (0)