47 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements the lowering of LLVM inline asm calls to machine code10// 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 19using namespace llvm;20 21SPIRVInlineAsmLowering::SPIRVInlineAsmLowering(const SPIRVTargetLowering &TLI)22 : InlineAsmLowering(&TLI) {}23 24bool 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(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>(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));39 return true;40 }41 }42 }43 return ValOp ? InlineAsmLowering::lowerAsmOperandForConstraint(44 ValOp, Constraint, Ops, MIRBuilder)45 : false;46}47