1 | //===--- SPIRVCallLowering.h - Call lowering --------------------*- 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 | // This file describes how to lower LLVM calls to machine code calls. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_LIB_TARGET_SPIRV_SPIRVCALLLOWERING_H |
14 | #define LLVM_LIB_TARGET_SPIRV_SPIRVCALLLOWERING_H |
15 | |
16 | #include "SPIRVGlobalRegistry.h" |
17 | #include "llvm/CodeGen/GlobalISel/CallLowering.h" |
18 | |
19 | namespace llvm { |
20 | |
21 | class SPIRVGlobalRegistry; |
22 | class SPIRVTargetLowering; |
23 | |
24 | class SPIRVCallLowering : public CallLowering { |
25 | private: |
26 | // Used to create and assign function, argument, and return type information. |
27 | SPIRVGlobalRegistry *GR; |
28 | |
29 | // Used to postpone producing of indirect function pointer types |
30 | // after all indirect calls info is collected |
31 | struct SPIRVIndirectCall { |
32 | const Type *RetTy = nullptr; |
33 | SmallVector<Type *> ArgTys; |
34 | SmallVector<Register> ArgRegs; |
35 | Register Callee; |
36 | }; |
37 | void produceIndirectPtrTypes(MachineIRBuilder &MIRBuilder) const; |
38 | mutable SmallVector<SPIRVIndirectCall> IndirectCalls; |
39 | |
40 | public: |
41 | SPIRVCallLowering(const SPIRVTargetLowering &TLI, SPIRVGlobalRegistry *GR); |
42 | |
43 | // Built OpReturn or OpReturnValue. |
44 | bool lowerReturn(MachineIRBuilder &MIRBuiler, const Value *Val, |
45 | ArrayRef<Register> VRegs, FunctionLoweringInfo &FLI, |
46 | Register SwiftErrorVReg) const override; |
47 | |
48 | // Build OpFunction, OpFunctionParameter, and any EntryPoint or Linkage data. |
49 | bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, |
50 | ArrayRef<ArrayRef<Register>> VRegs, |
51 | FunctionLoweringInfo &FLI) const override; |
52 | |
53 | // Build OpCall, or replace with a builtin function. |
54 | bool lowerCall(MachineIRBuilder &MIRBuilder, |
55 | CallLoweringInfo &Info) const override; |
56 | }; |
57 | } // end namespace llvm |
58 | |
59 | #endif // LLVM_LIB_TARGET_SPIRV_SPIRVCALLLOWERING_H |
60 | |