brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 23ed55d Raw
71 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9/// \file10/// Header of lower AMDGPU MachineInstrs to their corresponding MCInst.11//12//===----------------------------------------------------------------------===//13//14 15#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMCINSTLOWER_H16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMCINSTLOWER_H17 18#include "AMDGPUTargetMachine.h"19#include "llvm/IR/Constants.h"20#include "llvm/Support/Casting.h"21 22namespace llvm {23class AsmPrinter;24class MCContext;25 26class AMDGPUMCInstLower {27  MCContext &Ctx;28  const TargetSubtargetInfo &ST;29  const AsmPrinter &AP;30 31public:32  AMDGPUMCInstLower(MCContext &ctx, const TargetSubtargetInfo &ST,33                    const AsmPrinter &AP);34 35  bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;36 37  /// Lower a MachineInstr to an MCInst38  void lower(const MachineInstr *MI, MCInst &OutMI) const;39 40  void lowerT16D16Helper(const MachineInstr *MI, MCInst &OutMI) const;41  void lowerT16FmaMixFP16(const MachineInstr *MI, MCInst &OutMI) const;42};43 44namespace {45static inline const MCExpr *lowerAddrSpaceCast(const TargetMachine &TM,46                                               const Constant *CV,47                                               MCContext &OutContext) {48  // TargetMachine does not support llvm-style cast. Use C++-style cast.49  // This is safe since TM is always of type AMDGPUTargetMachine or its50  // derived class.51  auto &AT = static_cast<const AMDGPUTargetMachine &>(TM);52  auto *CE = dyn_cast<ConstantExpr>(CV);53 54  // Lower null pointers in private and local address space.55  // Clang generates addrspacecast for null pointers in private and local56  // address space, which needs to be lowered.57  if (CE && CE->getOpcode() == Instruction::AddrSpaceCast) {58    auto *Op = CE->getOperand(0);59    auto SrcAddr = Op->getType()->getPointerAddressSpace();60    if (Op->isNullValue() && AT.getNullPointerValue(SrcAddr) == 0) {61      auto DstAddr = CE->getType()->getPointerAddressSpace();62      return MCConstantExpr::create(AT.getNullPointerValue(DstAddr),63                                    OutContext);64    }65  }66  return nullptr;67}68} // namespace69} // namespace llvm70#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMCINSTLOWER_H71