LLVM  10.0.0svn
R600AsmPrinter.cpp
Go to the documentation of this file.
1 //===-- R600AsmPrinter.cpp - R600 Assebly 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"
18 #include "AMDGPUSubtarget.h"
19 #include "R600Defines.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;
47  const R600Subtarget &STM = MF.getSubtarget<R600Subtarget>();
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->EmitIntValue(RsrcReg, 4);
92  OutStreamer->EmitIntValue(S_NUM_GPRS(MaxGPR + 1) |
93  S_STACK_SIZE(MFI->CFStackSize), 4);
94  OutStreamer->EmitIntValue(R_02880C_DB_SHADER_CONTROL, 4);
95  OutStreamer->EmitIntValue(S_02880C_KILL_ENABLE(killPixel), 4);
96 
97  if (AMDGPU::isCompute(MF.getFunction().getCallingConv())) {
98  OutStreamer->EmitIntValue(R_0288E8_SQ_LDS_ALLOC, 4);
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 }
132 
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:216
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
LLVMContext & Context
AMDGPU specific subclass of TargetSubtarget.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:199
#define R_028850_SQ_PGM_RESOURCES_PS
Definition: R600Defines.h:156
#define R_028860_SQ_PGM_RESOURCES_VS
Definition: R600Defines.h:164
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
#define R_028878_SQ_PGM_RESOURCES_GS
Definition: R600Defines.h:165
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
Generation getGeneration() const
AsmPrinter * createR600AsmPrinterPass(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer)
#define S_NUM_GPRS(x)
Definition: R600Defines.h:150
Definition: BitVector.h:937
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Definition: CallingConv.h:193
Context object for machine code objects.
Definition: MCContext.h:65
void EmitFunctionBody()
This method emits the body and trailer for a function.
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:196
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:203
bool isCompute(CallingConv::ID cc)
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.
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
#define R_0288D4_SQ_PGM_RESOURCES_LS
Definition: R600Defines.h:166
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
#define R_02880C_DB_SHADER_CONTROL
Definition: R600Defines.h:146
const R600RegisterInfo * getRegisterInfo() const override
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
R600 Assembly printer class.
MachineOperand class - Representation of each machine instruction operand.
#define S_STACK_SIZE(x)
Definition: R600Defines.h:151
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:202
#define R_028868_SQ_PGM_RESOURCES_VS
Definition: R600Defines.h:157
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
Definition: MachineInstr.h:63
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:163
#define S_02880C_KILL_ENABLE(x)
Definition: R600Defines.h:147
R600AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:424
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:273
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Register getReg() const
getReg - Returns the register number.
#define R_0288E8_SQ_LDS_ALLOC
Definition: R600Defines.h:168
#define R_028844_SQ_PGM_RESOURCES_PS
Definition: R600Defines.h:163