1 //===--- SPIRVInlineAsmLowering.cpp - Inline Asm lowering -------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the lowering of LLVM inline asm calls to machine code
10 // calls for GlobalISel.
12 //===----------------------------------------------------------------------===//
14 #include "SPIRVInlineAsmLowering.h"
15 #include "SPIRVSubtarget.h"
16 #include "llvm/IR/IntrinsicInst.h"
17 #include "llvm/IR/IntrinsicsSPIRV.h"
21 SPIRVInlineAsmLowering::SPIRVInlineAsmLowering(const SPIRVTargetLowering
&TLI
)
22 : InlineAsmLowering(&TLI
) {}
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
)) {
30 } else if (ConstantFP
*CFP
= dyn_cast
<ConstantFP
>(Val
)) {
31 Ops
.push_back(MachineOperand::CreateFPImm(CFP
));
33 } else if (auto *II
= dyn_cast
<IntrinsicInst
>(Val
)) {
34 if (II
->getIntrinsicID() == Intrinsic::spv_track_constant
) {
35 if (isa
<ConstantInt
>(II
->getOperand(0))) {
36 ValOp
= II
->getOperand(0);
37 } else if (ConstantFP
*CFP
= dyn_cast
<ConstantFP
>(II
->getOperand(0))) {
38 Ops
.push_back(MachineOperand::CreateFPImm(CFP
));
43 return ValOp
? InlineAsmLowering::lowerAsmOperandForConstraint(
44 ValOp
, Constraint
, Ops
, MIRBuilder
)