LLVM 20.0.0git
R600AsmPrinter.cpp
Go to the documentation of this file.
1//===-- R600AsmPrinter.cpp - R600 Assembly printer ------------------------===//
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///
11/// The R600AsmPrinter is used to print both assembly string and also binary
12/// code. When passed an MCAsmStreamer it prints assembly and when passed
13/// an MCObjectStreamer it outputs binary code.
14//
15//===----------------------------------------------------------------------===//
16
17#include "R600AsmPrinter.h"
19#include "R600Defines.h"
21#include "R600Subtarget.h"
23#include "llvm/MC/MCContext.h"
25#include "llvm/MC/MCStreamer.h"
27
28using namespace llvm;
29
32 std::unique_ptr<MCStreamer> &&Streamer) {
33 return new R600AsmPrinter(TM, std::move(Streamer));
34}
35
37 std::unique_ptr<MCStreamer> Streamer)
38 : AsmPrinter(TM, std::move(Streamer)) { }
39
41 return "R600 Assembly Printer";
42}
43
44void R600AsmPrinter::EmitProgramInfoR600(const MachineFunction &MF) {
45 unsigned MaxGPR = 0;
46 bool killPixel = false;
48 const R600RegisterInfo *RI = STM.getRegisterInfo();
50
51 for (const MachineBasicBlock &MBB : MF) {
52 for (const MachineInstr &MI : MBB) {
53 if (MI.getOpcode() == R600::KILLGT)
54 killPixel = true;
55 unsigned numOperands = MI.getNumOperands();
56 for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) {
57 const MachineOperand &MO = MI.getOperand(op_idx);
58 if (!MO.isReg())
59 continue;
60 unsigned HWReg = RI->getHWRegIndex(MO.getReg());
61
62 // Register with value > 127 aren't GPR
63 if (HWReg > 127)
64 continue;
65 MaxGPR = std::max(MaxGPR, HWReg);
66 }
67 }
68 }
69
70 unsigned RsrcReg;
72 // Evergreen / Northern Islands
73 switch (MF.getFunction().getCallingConv()) {
74 default: [[fallthrough]];
79 }
80 } else {
81 // R600 / R700
82 switch (MF.getFunction().getCallingConv()) {
83 default: [[fallthrough]];
84 case CallingConv::AMDGPU_GS: [[fallthrough]];
85 case CallingConv::AMDGPU_CS: [[fallthrough]];
88 }
89 }
90
91 OutStreamer->emitInt32(RsrcReg);
92 OutStreamer->emitIntValue(S_NUM_GPRS(MaxGPR + 1) |
93 S_STACK_SIZE(MFI->CFStackSize), 4);
95 OutStreamer->emitInt32(S_02880C_KILL_ENABLE(killPixel));
96
99 OutStreamer->emitIntValue(alignTo(MFI->getLDSSize(), 4) >> 2, 4);
100 }
101}
102
104
105
106 // Functions needs to be cacheline (256B) aligned.
108
110
112 MCSectionELF *ConfigSection =
113 Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0);
114 OutStreamer->switchSection(ConfigSection);
115
116 EmitProgramInfoR600(MF);
117
119
120 if (isVerbose()) {
121 MCSectionELF *CommentSection =
122 Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0);
123 OutStreamer->switchSection(CommentSection);
124
126 OutStreamer->emitRawComment(
127 Twine("SQ_PGM_RESOURCES:STACK_SIZE = " + Twine(MFI->CFStackSize)));
128 }
129
130 return false;
131}
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
R600 Assembly printer class.
#define R_0288E8_SQ_LDS_ALLOC
Definition: R600Defines.h:166
#define S_02880C_KILL_ENABLE(x)
Definition: R600Defines.h:145
#define R_028868_SQ_PGM_RESOURCES_VS
Definition: R600Defines.h:155
#define S_NUM_GPRS(x)
Definition: R600Defines.h:148
#define R_028878_SQ_PGM_RESOURCES_GS
Definition: R600Defines.h:163
#define R_02880C_DB_SHADER_CONTROL
Definition: R600Defines.h:144
#define R_028860_SQ_PGM_RESOURCES_VS
Definition: R600Defines.h:162
#define R_0288D4_SQ_PGM_RESOURCES_LS
Definition: R600Defines.h:164
#define R_028850_SQ_PGM_RESOURCES_PS
Definition: R600Defines.h:154
#define S_STACK_SIZE(x)
Definition: R600Defines.h:149
#define R_028844_SQ_PGM_RESOURCES_PS
Definition: R600Defines.h:161
Provides R600 specific target descriptions.
AMDGPU R600 specific subclass of TargetSubtarget.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:86
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:383
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:104
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
void emitFunctionBody()
This method emits the body and trailer for a function.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:101
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:257
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:281
Context object for machine code objects.
Definition: MCContext.h:83
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:551
MCContext & getContext() const
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void ensureAlignment(Align A)
ensureAlignment - Make sure the function is at least A bytes aligned.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
R600AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
const R600RegisterInfo * getRegisterInfo() const override
Definition: R600Subtarget.h:60
Generation getGeneration() const
Definition: R600Subtarget.h:75
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool isCompute(CallingConv::ID cc)
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:197
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
Definition: CallingConv.h:188
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:191
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:194
@ SHT_PROGBITS
Definition: ELF.h:1089
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AsmPrinter * createR600AsmPrinterPass(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39