39#include "AMDGPUGenMCPseudoLowering.inc"
44 Ctx(ctx), ST(st), AP(ap) { }
119 unsigned Opcode =
MI->getOpcode();
125 if (Opcode == AMDGPU::S_SETPC_B64_return)
126 Opcode = AMDGPU::S_SETPC_B64;
127 else if (Opcode == AMDGPU::SI_CALL) {
130 OutMI.
setOpcode(
TII->pseudoToMCOpcode(AMDGPU::S_SWAPPC_B64));
137 }
else if (Opcode == AMDGPU::SI_TCRETURN) {
139 Opcode = AMDGPU::S_SETPC_B64;
142 int MCOpcode =
TII->pseudoToMCOpcode(Opcode);
143 if (MCOpcode == -1) {
144 LLVMContext &
C =
MI->getParent()->getParent()->getFunction().getContext();
145 C.emitError(
"AMDGPUMCInstLower::lower - Pseudo instruction doesn't have "
146 "a target-specific version: " +
Twine(
MI->getOpcode()));
157 int FIIdx = AMDGPU::getNamedOperandIdx(MCOpcode, AMDGPU::OpName::fi);
166 return MCInstLowering.lowerOperand(MO, MCOp);
172 if (
const GlobalVariable *GV = dyn_cast<const GlobalVariable>(CV)) {
173 if (std::optional<uint32_t>
Address =
198 LLVMContext &
C =
MI->getParent()->getParent()->getFunction().getContext();
199 C.emitError(
"Illegal instruction detected: " + Err);
203 if (
MI->isBundle()) {
214 if (
MI->getOpcode() == AMDGPU::SI_RETURN_TO_EPILOG) {
216 OutStreamer->emitRawComment(
" return to shader part epilog");
220 if (
MI->getOpcode() == AMDGPU::WAVE_BARRIER) {
226 if (
MI->getOpcode() == AMDGPU::SCHED_BARRIER) {
228 std::string HexString;
230 HexStream <<
format_hex(
MI->getOperand(0).getImm(), 10,
true);
231 OutStreamer->emitRawComment(
" sched_barrier mask(" + HexString +
")");
236 if (
MI->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER) {
238 std::string HexString;
240 HexStream <<
format_hex(
MI->getOperand(0).getImm(), 10,
true);
242 " sched_group_barrier mask(" + HexString +
") size(" +
243 Twine(
MI->getOperand(1).getImm()) +
") SyncID(" +
244 Twine(
MI->getOperand(2).getImm()) +
")");
249 if (
MI->getOpcode() == AMDGPU::IGLP_OPT) {
251 std::string HexString;
253 HexStream <<
format_hex(
MI->getOperand(0).getImm(), 10,
true);
254 OutStreamer->emitRawComment(
" iglp_opt mask(" + HexString +
")");
259 if (
MI->getOpcode() == AMDGPU::SI_MASKED_UNREACHABLE) {
261 OutStreamer->emitRawComment(
" divergent unreachable");
265 if (
MI->isMetaInstruction()) {
272 MCInstLowering.lower(
MI, TmpInst);
275#ifdef EXPENSIVE_CHECKS
284 if (!
MI->isPseudo() && STI.isCPUStringValid(STI.getCPU()) &&
292 InstEmitter->encodeInstruction(TmpInst, CodeStream, Fixups, STI);
298 if (DumpCodeInstEmitter) {
316 std::string &HexLine =
HexLines.back();
319 for (
size_t i = 0; i < CodeBytes.
size(); i += 4) {
320 unsigned int CodeDWord = *(
unsigned int *)&CodeBytes[i];
321 HexStream <<
format(
"%s%08X", (i > 0 ?
" " :
""), CodeDWord);
324 DisasmStream.
flush();
AMDGPU Assembly printer class.
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned MOFlags)
Header of lower AMDGPU MachineInstrs to their corresponding MCInst.
Provides AMDGPU specific target descriptions.
The AMDGPU TargetMachine interface definition for hw codegen targets.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const HexagonInstrInfo * TII
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const
AMDGPUMCInstLower(MCContext &ctx, const TargetSubtargetInfo &ST, const AsmPrinter &AP)
void lower(const MachineInstr *MI, MCInst &OutMI) const
Lower a MachineInstr to an MCInst.
std::vector< std::string > DisasmLines
std::vector< std::string > HexLines
bool emitPseudoExpansionLowering(MCStreamer &OutStreamer, const MachineInstr *MI)
tblgen'erated driver function for lowering simple MI->MC pseudo instructions.
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const
Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated pseudo lowering.
const MCExpr * lowerConstant(const Constant *CV) override
Lower the specified LLVM Constant to an MCExpr.
void emitInstruction(const MachineInstr *MI) override
Implemented in AMDGPUMCInstLower.cpp.
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override
Print the specified MCInst to the specified raw_ostream.
static std::optional< uint32_t > getLDSAbsoluteAddress(const GlobalValue &GV)
This class is intended to be used as a driving class for all asm writers.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
TargetMachine & TM
Target machine description.
MachineFunction * MF
The current machine function.
MCContext & OutContext
This is the context for the output file that we are streaming.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
bool isVerbose() const
Return true if assembly output should contain comments.
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
This is an important base class in LLVM.
const SIInstrInfo * getInstrInfo() const override
bool hasOffset3fBug() const
const SIRegisterInfo * getRegisterInfo() const override
This is an important class for using LLVM in a threaded context.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Base class for the full range of assembler expressions which are needed for parsing.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
Instances of this class represent operands of the MCInst class.
static MCOperand createReg(unsigned Reg)
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createImm(int64_t Val)
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
@ VK_AMDGPU_GOTPCREL32_LO
@ VK_AMDGPU_GOTPCREL32_HI
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
void setExternal(bool Value) const
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
instr_iterator instr_end()
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
MachineBasicBlock * getMBB() const
unsigned getTargetFlags() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
MCSymbol * getMCSymbol() const
@ MO_Immediate
Immediate operand.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
int64_t getOffset() const
Return the offset from the symbol in this operand.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
bool verifyInstruction(const MachineInstr &MI, StringRef &ErrInfo) const override
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetInstrInfo * getInstrInfo() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static IntegerType * getInt32Ty(LLVMContext &C)
LLVMContext & getContext() const
All values hold a context through their type.
Iterator for intrusive lists based on ilist_node.
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
MCCodeEmitter * createSIMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.