LLVM  8.0.1
R600AsmPrinter.cpp
Go to the documentation of this file.
1 //===-- R600AsmPrinter.cpp - R600 Assebly printer ------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 ///
12 /// The R600AsmPrinter is used to print both assembly string and also binary
13 /// code. When passed an MCAsmStreamer it prints assembly and when passed
14 /// an MCObjectStreamer it outputs binary code.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #include "R600AsmPrinter.h"
19 #include "AMDGPUSubtarget.h"
20 #include "R600Defines.h"
23 #include "llvm/BinaryFormat/ELF.h"
24 #include "llvm/MC/MCContext.h"
25 #include "llvm/MC/MCSectionELF.h"
26 #include "llvm/MC/MCStreamer.h"
28 
29 using namespace llvm;
30 
31 AsmPrinter *
33  std::unique_ptr<MCStreamer> &&Streamer) {
34  return new R600AsmPrinter(TM, std::move(Streamer));
35 }
36 
38  std::unique_ptr<MCStreamer> Streamer)
39  : AsmPrinter(TM, std::move(Streamer)) { }
40 
42  return "R600 Assembly Printer";
43 }
44 
45 void R600AsmPrinter::EmitProgramInfoR600(const MachineFunction &MF) {
46  unsigned MaxGPR = 0;
47  bool killPixel = false;
48  const R600Subtarget &STM = MF.getSubtarget<R600Subtarget>();
49  const R600RegisterInfo *RI = STM.getRegisterInfo();
51 
52  for (const MachineBasicBlock &MBB : MF) {
53  for (const MachineInstr &MI : MBB) {
54  if (MI.getOpcode() == R600::KILLGT)
55  killPixel = true;
56  unsigned numOperands = MI.getNumOperands();
57  for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) {
58  const MachineOperand &MO = MI.getOperand(op_idx);
59  if (!MO.isReg())
60  continue;
61  unsigned HWReg = RI->getHWRegIndex(MO.getReg());
62 
63  // Register with value > 127 aren't GPR
64  if (HWReg > 127)
65  continue;
66  MaxGPR = std::max(MaxGPR, HWReg);
67  }
68  }
69  }
70 
71  unsigned RsrcReg;
73  // Evergreen / Northern Islands
74  switch (MF.getFunction().getCallingConv()) {
75  default: LLVM_FALLTHROUGH;
80  }
81  } else {
82  // R600 / R700
83  switch (MF.getFunction().getCallingConv()) {
84  default: LLVM_FALLTHROUGH;
89  }
90  }
91 
92  OutStreamer->EmitIntValue(RsrcReg, 4);
93  OutStreamer->EmitIntValue(S_NUM_GPRS(MaxGPR + 1) |
94  S_STACK_SIZE(MFI->CFStackSize), 4);
95  OutStreamer->EmitIntValue(R_02880C_DB_SHADER_CONTROL, 4);
96  OutStreamer->EmitIntValue(S_02880C_KILL_ENABLE(killPixel), 4);
97 
98  if (AMDGPU::isCompute(MF.getFunction().getCallingConv())) {
99  OutStreamer->EmitIntValue(R_0288E8_SQ_LDS_ALLOC, 4);
100  OutStreamer->EmitIntValue(alignTo(MFI->getLDSSize(), 4) >> 2, 4);
101  }
102 }
103 
105 
106 
107  // Functions needs to be cacheline (256B) aligned.
108  MF.ensureAlignment(8);
109 
111 
113  MCSectionELF *ConfigSection =
114  Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0);
115  OutStreamer->SwitchSection(ConfigSection);
116 
117  EmitProgramInfoR600(MF);
118 
120 
121  if (isVerbose()) {
122  MCSectionELF *CommentSection =
123  Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0);
124  OutStreamer->SwitchSection(CommentSection);
125 
127  OutStreamer->emitRawComment(
128  Twine("SQ_PGM_RESOURCES:STACK_SIZE = " + Twine(MFI->CFStackSize)));
129  }
130 
131  return false;
132 }
133 
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:212
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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:94
This class represents lattice values for constants.
Definition: AllocatorList.h:24
#define LLVM_FALLTHROUGH
Definition: Compiler.h:86
#define R_028850_SQ_PGM_RESOURCES_PS
Definition: R600Defines.h:157
#define R_028860_SQ_PGM_RESOURCES_VS
Definition: R600Defines.h:165
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
unsigned getReg() const
getReg - Returns the register number.
#define R_028878_SQ_PGM_RESOURCES_GS
Definition: R600Defines.h:166
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:97
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:685
Generation getGeneration() const
AsmPrinter * createR600AsmPrinterPass(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer)
#define S_NUM_GPRS(x)
Definition: R600Defines.h:151
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:192
Definition: BitVector.h:938
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:198
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Context object for machine code objects.
Definition: MCContext.h:63
void EmitFunctionBody()
This method emits the body and trailer for a function.
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:203
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Definition: CallingConv.h:189
bool isCompute(CallingConv::ID cc)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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:79
void ensureAlignment(unsigned A)
ensureAlignment - Make sure the function is at least 1 << A bytes aligned.
#define R_0288D4_SQ_PGM_RESOURCES_LS
Definition: R600Defines.h:167
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:147
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:195
const R600RegisterInfo * getRegisterInfo() const override
R600 Assembly printer class.
MachineOperand class - Representation of each machine instruction operand.
#define S_STACK_SIZE(x)
Definition: R600Defines.h:152
#define R_028868_SQ_PGM_RESOURCES_VS
Definition: R600Defines.h:158
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
Definition: MachineInstr.h:64
void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
#define S_02880C_KILL_ENABLE(x)
Definition: R600Defines.h:148
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:28
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:389
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
#define R_0288E8_SQ_LDS_ALLOC
Definition: R600Defines.h:169
#define R_028844_SQ_PGM_RESOURCES_PS
Definition: R600Defines.h:164