1//===- AMDGPUMCInstLower.h - Lower MachineInstr to MCInst ------*- 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/// \file
10/// Header of lower AMDGPU MachineInstrs to their corresponding MCInst.
11//
12//===----------------------------------------------------------------------===//
13//
14
15#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMCINSTLOWER_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMCINSTLOWER_H
17
18#include "AMDGPUTargetMachine.h"
19#include "llvm/IR/Constants.h"
20#include "llvm/Support/AMDGPUAddrSpace.h"
21#include "llvm/Support/Casting.h"
22
23namespace llvm {
24class AsmPrinter;
25class MCContext;
26
27class AMDGPUMCInstLower {
28 MCContext &Ctx;
29 const TargetSubtargetInfo &ST;
30 const AsmPrinter ≈
31
32public:
33 AMDGPUMCInstLower(MCContext &ctx, const TargetSubtargetInfo &ST,
34 const AsmPrinter &AP);
35
36 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
37
38 /// Lower a MachineInstr to an MCInst
39 void lower(const MachineInstr *MI, MCInst &OutMI) const;
40
41 void lowerT16D16Helper(const MachineInstr *MI, MCInst &OutMI) const;
42 void lowerT16FmaMixFP16(const MachineInstr *MI, MCInst &OutMI) const;
43};
44
45namespace {
46static inline const MCExpr *lowerAddrSpaceCast(const Constant *CV,
47 MCContext &OutContext) {
48 auto *CE = dyn_cast<ConstantExpr>(Val: CV);
49
50 // Lower null pointers in private and local address space.
51 // Clang generates addrspacecast for null pointers in private and local
52 // address space, which needs to be lowered.
53 if (CE && CE->getOpcode() == Instruction::AddrSpaceCast) {
54 auto *Op = CE->getOperand(i_nocapture: 0);
55 auto SrcAddr = Op->getType()->getPointerAddressSpace();
56 if (Op->isNullValue() && AMDGPU::getNullPointerValue(AS: SrcAddr) == 0) {
57 auto DstAddr = CE->getType()->getPointerAddressSpace();
58 return MCConstantExpr::create(Value: AMDGPU::getNullPointerValue(AS: DstAddr),
59 Ctx&: OutContext);
60 }
61 }
62 return nullptr;
63}
64} // namespace
65} // namespace llvm
66#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMCINSTLOWER_H
67