1 | //===--- SPIRVInlineAsmLowering.cpp - Inline Asm 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 implements the lowering of LLVM inline asm calls to machine code |
10 | // calls for GlobalISel. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "SPIRVInlineAsmLowering.h" |
15 | #include "SPIRVSubtarget.h" |
16 | #include "llvm/IR/IntrinsicInst.h" |
17 | #include "llvm/IR/IntrinsicsSPIRV.h" |
18 | |
19 | using namespace llvm; |
20 | |
21 | SPIRVInlineAsmLowering::SPIRVInlineAsmLowering(const SPIRVTargetLowering &TLI) |
22 | : InlineAsmLowering(&TLI) {} |
23 | |
24 | bool SPIRVInlineAsmLowering::lowerAsmOperandForConstraint( |
25 | Value *Val, StringRef Constraint, std::vector<MachineOperand> &Ops, |
26 | MachineIRBuilder &MIRBuilder) const { |
27 | Value *ValOp = nullptr; |
28 | if (isa<ConstantInt>(Val)) { |
29 | ValOp = Val; |
30 | } else if (ConstantFP *CFP = dyn_cast<ConstantFP>(Val)) { |
31 | Ops.push_back(x: MachineOperand::CreateFPImm(CFP)); |
32 | return true; |
33 | } else if (auto *II = dyn_cast<IntrinsicInst>(Val)) { |
34 | if (II->getIntrinsicID() == Intrinsic::spv_track_constant) { |
35 | if (isa<ConstantInt>(Val: II->getOperand(i_nocapture: 0))) { |
36 | ValOp = II->getOperand(i_nocapture: 0); |
37 | } else if (ConstantFP *CFP = dyn_cast<ConstantFP>(Val: II->getOperand(i_nocapture: 0))) { |
38 | Ops.push_back(x: MachineOperand::CreateFPImm(CFP)); |
39 | return true; |
40 | } |
41 | } |
42 | } |
43 | return ValOp ? InlineAsmLowering::lowerAsmOperandForConstraint( |
44 | Val: ValOp, Constraint, Ops, MIRBuilder) |
45 | : false; |
46 | } |
47 |