LLVM  14.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"
22 #include "llvm/BinaryFormat/ELF.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCSectionELF.h"
25 #include "llvm/MC/MCStreamer.h"
27 
28 using namespace llvm;
29 
30 AsmPrinter *
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 
44 void 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: LLVM_FALLTHROUGH;
79  }
80  } else {
81  // R600 / R700
82  switch (MF.getFunction().getCallingConv()) {
83  default: LLVM_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.
107  MF.ensureAlignment(Align(256));
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 }
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
R_028850_SQ_PGM_RESOURCES_PS
#define R_028850_SQ_PGM_RESOURCES_PS
Definition: R600Defines.h:154
R_028844_SQ_PGM_RESOURCES_PS
#define R_028844_SQ_PGM_RESOURCES_PS
Definition: R600Defines.h:161
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
R_02880C_DB_SHADER_CONTROL
#define R_02880C_DB_SHADER_CONTROL
Definition: R600Defines.h:144
MCSectionELF.h
llvm::CallingConv::AMDGPU_CS
@ AMDGPU_CS
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:213
llvm::MachineFunction::ensureAlignment
void ensureAlignment(Align A)
ensureAlignment - Make sure the function is at least A bytes aligned.
Definition: MachineFunction.h:680
llvm::AMDGPUMachineFunction::getLDSSize
unsigned getLDSSize() const
Definition: AMDGPUMachineFunction.h:70
llvm::MCSectionELF
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
llvm::MCObjectFileInfo::getContext
MCContext & getContext() const
Definition: MCObjectFileInfo.h:235
llvm::R600MachineFunctionInfo
Definition: R600MachineFunctionInfo.h:19
R_0288D4_SQ_PGM_RESOURCES_LS
#define R_0288D4_SQ_PGM_RESOURCES_LS
Definition: R600Defines.h:164
R_0288E8_SQ_LDS_ALLOC
#define R_0288E8_SQ_LDS_ALLOC
Definition: R600Defines.h:166
llvm::R600RegisterInfo
Definition: R600RegisterInfo.h:22
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:910
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
R600AsmPrinter.h
ELF.h
S_STACK_SIZE
#define S_STACK_SIZE(x)
Definition: R600Defines.h:149
R_028860_SQ_PGM_RESOURCES_VS
#define R_028860_SQ_PGM_RESOURCES_VS
Definition: R600Defines.h:162
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition: MachineFunction.h:724
llvm::R600AsmPrinter
Definition: R600AsmPrinter.h:21
llvm::R600AsmPrinter::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: R600AsmPrinter.cpp:103
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:97
MCContext.h
llvm::AsmPrinter::SetupMachineFunction
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
Definition: AsmPrinter.cpp:1962
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
S_02880C_KILL_ENABLE
#define S_02880C_KILL_ENABLE(x)
Definition: R600Defines.h:145
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::CallingConv::AMDGPU_GS
@ AMDGPU_GS
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:207
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::R600AsmPrinter::R600AsmPrinter
R600AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Definition: R600AsmPrinter.cpp:36
R600MachineFunctionInfo.h
R600MCTargetDesc.h
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:626
llvm::R600Subtarget
Definition: R600Subtarget.h:35
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition: MachineOperand.h:321
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:239
llvm::CallingConv::AMDGPU_VS
@ AMDGPU_VS
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Definition: CallingConv.h:204
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::R600Subtarget::getGeneration
Generation getGeneration() const
Definition: R600Subtarget.h:81
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
llvm::move
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:1605
S_NUM_GPRS
#define S_NUM_GPRS(x)
Definition: R600Defines.h:148
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:100
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AMDGPU::isCompute
bool isCompute(CallingConv::ID cc)
Definition: AMDGPUBaseInfo.cpp:1377
TargetLoweringObjectFile.h
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:273
R_028878_SQ_PGM_RESOURCES_GS
#define R_028878_SQ_PGM_RESOURCES_GS
Definition: R600Defines.h:163
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
std
Definition: BitVector.h:838
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:592
llvm::createR600AsmPrinterPass
AsmPrinter * createR600AsmPrinterPass(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer)
Definition: R600AsmPrinter.cpp:31
llvm::R600Subtarget::getRegisterInfo
const R600RegisterInfo * getRegisterInfo() const override
Definition: R600Subtarget.h:66
R600Subtarget.h
R_028868_SQ_PGM_RESOURCES_VS
#define R_028868_SQ_PGM_RESOURCES_VS
Definition: R600Defines.h:155
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
llvm::R600AsmPrinter::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: R600AsmPrinter.cpp:40
llvm::R600MachineFunctionInfo::CFStackSize
unsigned CFStackSize
Definition: R600MachineFunctionInfo.h:22
R600Defines.h
llvm::AsmPrinter::getObjFileLowering
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:224
MCStreamer.h
llvm::AsmPrinter::emitFunctionBody
void emitFunctionBody()
This method emits the body and trailer for a function.
Definition: AsmPrinter.cpp:1242
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::AsmPrinter::isVerbose
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:238
llvm::CallingConv::AMDGPU_PS
@ AMDGPU_PS
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:210
llvm::AMDGPUSubtarget::EVERGREEN
@ EVERGREEN
Definition: AMDGPUSubtarget.h:35