LLVM 23.0.0git
RISCVInlineAsmLowering.cpp
Go to the documentation of this file.
1//===-- lib/CodeGen/GlobalISel/InlineAsmLowering.cpp ----------------------===//
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 from LLVM IR inline asm to MIR INLINEASM
11///
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/StringRef.h"
18#include "llvm/IR/Constants.h"
20
21using namespace llvm;
22
25
27 Value *Val, StringRef Constraint, std::vector<MachineOperand> &Ops,
28 MachineIRBuilder &MIRBuilder) const {
29 if (Constraint.size() != 1)
30 return false;
31
32 // RISC-V specific constraints.
33 switch (Constraint[0]) {
34 case 'I': // 12-bit signed immediate operand.
35 if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
36 int64_t ExtVal = CI->getSExtValue();
37 if (isInt<12>(ExtVal)) {
38 Ops.push_back(MachineOperand::CreateImm(ExtVal));
39 return true;
40 }
41 }
42 return false;
43 case 'J': // Integer zero operand.
44 if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
45 if (CI->isZero()) {
46 Ops.push_back(MachineOperand::CreateImm(0));
47 return true;
48 }
49 }
50 return false;
51 case 'K': // 5-bit unsigned immediate operand.
52 if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
53 uint64_t ExtVal = CI->getZExtValue();
54 if (isUInt<5>(ExtVal)) {
55 Ops.push_back(MachineOperand::CreateImm(ExtVal));
56 return true;
57 }
58 }
59 return false;
60 case 'S': // Alias for s.
62 MIRBuilder);
63 default:
64 // Target-independent constraints.
66 MIRBuilder);
67 }
68}
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file describes how to lower LLVM inline asm to machine code INLINEASM.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file describes how to lower LLVM inline asm to machine code INLINEASM.
This is the shared class of boolean and integer constants.
Definition Constants.h:87
InlineAsmLowering(const TargetLowering *TLI)
virtual bool lowerAsmOperandForConstraint(Value *Val, StringRef Constraint, std::vector< MachineOperand > &Ops, MachineIRBuilder &MIRBuilder) const
Lower the specified operand into the Ops vector.
Helper class to build MachineInstr.
static MachineOperand CreateImm(int64_t Val)
RISCVInlineAsmLowering(const TargetLowering *TLI)
bool lowerAsmOperandForConstraint(Value *Val, StringRef Constraint, std::vector< MachineOperand > &Ops, MachineIRBuilder &MIRBuilder) const override
Lower the specified operand into the Ops vector.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:165
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:189