LLVM  14.0.0git
AMDGPUMCInstLower.h
Go to the documentation of this file.
1 //===- AMDGPUMCInstLower.h - Lower AMDGPU MachineInstr to an MCInst -------===//
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 
30  MCContext &Ctx;
31  const TargetSubtargetInfo &ST;
32  const AsmPrinter ≈
33 
34 public:
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 
44 namespace {
45 static 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 its
50  // 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 local
56  // 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 } // namespace
69 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMCINSTLOWER_H
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
AMDGPUMCInstLower
Definition: AMDGPUMCInstLower.h:29
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::AMDGPUTargetMachine
Definition: AMDGPUTargetMachine.h:30
Constants.h
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:80
llvm::TargetSubtargetInfo
TargetSubtargetInfo - Generic base class for all target subtargets.
Definition: TargetSubtargetInfo.h:59
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:325
Casting.h
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:81
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
AMDGPUTargetMachine.h