| 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/Casting.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | class AsmPrinter; |
| 24 | class MCContext; |
| 25 | } // namespace llvm |
| 26 | |
| 27 | using namespace llvm; |
| 28 | |
| 29 | class AMDGPUMCInstLower { |
| 30 | MCContext &Ctx; |
| 31 | const TargetSubtargetInfo &ST; |
| 32 | const AsmPrinter ≈ |
| 33 | |
| 34 | public: |
| 35 | AMDGPUMCInstLower(MCContext &ctx, const TargetSubtargetInfo &ST, |
| 36 | const AsmPrinter &AP); |
| 37 | |
| 38 | bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const; |
| 39 | |
| 40 | /// Lower a MachineInstr to an MCInst |
| 41 | void lower(const MachineInstr *MI, MCInst &OutMI) const; |
| 42 | |
| 43 | void lowerT16D16Helper(const MachineInstr *MI, MCInst &OutMI) const; |
| 44 | }; |
| 45 | |
| 46 | namespace { |
| 47 | static inline const MCExpr *lowerAddrSpaceCast(const TargetMachine &TM, |
| 48 | const Constant *CV, |
| 49 | MCContext &OutContext) { |
| 50 | // TargetMachine does not support llvm-style cast. Use C++-style cast. |
| 51 | // This is safe since TM is always of type AMDGPUTargetMachine or its |
| 52 | // derived class. |
| 53 | auto &AT = static_cast<const AMDGPUTargetMachine &>(TM); |
| 54 | auto *CE = dyn_cast<ConstantExpr>(Val: CV); |
| 55 | |
| 56 | // Lower null pointers in private and local address space. |
| 57 | // Clang generates addrspacecast for null pointers in private and local |
| 58 | // address space, which needs to be lowered. |
| 59 | if (CE && CE->getOpcode() == Instruction::AddrSpaceCast) { |
| 60 | auto *Op = CE->getOperand(i_nocapture: 0); |
| 61 | auto SrcAddr = Op->getType()->getPointerAddressSpace(); |
| 62 | if (Op->isNullValue() && AT.getNullPointerValue(AddrSpace: SrcAddr) == 0) { |
| 63 | auto DstAddr = CE->getType()->getPointerAddressSpace(); |
| 64 | return MCConstantExpr::create(Value: AT.getNullPointerValue(AddrSpace: DstAddr), |
| 65 | Ctx&: OutContext); |
| 66 | } |
| 67 | } |
| 68 | return nullptr; |
| 69 | } |
| 70 | } // namespace |
| 71 | #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMCINSTLOWER_H |
| 72 | |