1 //===-- AMDGPUAsmPrinter.cpp - AMDGPU Assebly printer --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // The AMDGPUAsmPrinter is used to print both assembly string and also binary
11 // code. When passed an MCAsmStreamer it prints assembly and when passed
12 // an MCObjectStreamer it outputs binary code.
14 //===----------------------------------------------------------------------===//
18 #include "AMDGPUAsmPrinter.h"
20 #include "SIMachineFunctionInfo.h"
21 #include "SIRegisterInfo.h"
22 #include "llvm/MC/MCStreamer.h"
23 #include "llvm/Target/TargetLoweringObjectFile.h"
24 #include "llvm/Support/TargetRegistry.h"
29 static AsmPrinter
*createAMDGPUAsmPrinterPass(TargetMachine
&tm
,
30 MCStreamer
&Streamer
) {
31 return new AMDGPUAsmPrinter(tm
, Streamer
);
34 extern "C" void LLVMInitializeAMDGPUAsmPrinter() {
35 TargetRegistry::RegisterAsmPrinter(TheAMDGPUTarget
, createAMDGPUAsmPrinterPass
);
38 /// runOnMachineFunction - We need to override this function so we can avoid
39 /// the call to EmitFunctionHeader(), which the MCPureStreamer can't handle.
40 bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction
&MF
) {
41 const AMDGPUSubtarget
&STM
= TM
.getSubtarget
<AMDGPUSubtarget
>();
45 SetupMachineFunction(MF
);
46 if (STM
.device()->getGeneration() > AMDGPUDeviceInfo::HD6XXX
) {
49 OutStreamer
.SwitchSection(getObjFileLowering().getTextSection());
54 void AMDGPUAsmPrinter::EmitProgramInfo(MachineFunction
&MF
) {
58 const SIRegisterInfo
* RI
=
59 static_cast<const SIRegisterInfo
*>(TM
.getRegisterInfo());
61 for (MachineFunction::iterator BB
= MF
.begin(), BB_E
= MF
.end();
63 MachineBasicBlock
&MBB
= *BB
;
64 for (MachineBasicBlock::iterator I
= MBB
.begin(), E
= MBB
.end();
66 MachineInstr
&MI
= *I
;
68 unsigned numOperands
= MI
.getNumOperands();
69 for (unsigned op_idx
= 0; op_idx
< numOperands
; op_idx
++) {
70 MachineOperand
& MO
= MI
.getOperand(op_idx
);
80 if (reg
== AMDGPU::VCC
) {
87 case AMDGPU::SI_LITERAL_CONSTANT
:
88 case AMDGPU::SREG_LIT_0
:
93 if (AMDGPU::SReg_32RegClass
.contains(reg
)) {
96 } else if (AMDGPU::VReg_32RegClass
.contains(reg
)) {
99 } else if (AMDGPU::SReg_64RegClass
.contains(reg
)) {
102 } else if (AMDGPU::VReg_64RegClass
.contains(reg
)) {
105 } else if (AMDGPU::SReg_128RegClass
.contains(reg
)) {
108 } else if (AMDGPU::VReg_128RegClass
.contains(reg
)) {
111 } else if (AMDGPU::SReg_256RegClass
.contains(reg
)) {
115 assert(!"Unknown register class");
117 hwReg
= RI
->getHWRegNum(reg
);
118 maxUsed
= hwReg
+ width
- 1;
120 MaxSGPR
= maxUsed
> MaxSGPR
? maxUsed
: MaxSGPR
;
122 MaxVGPR
= maxUsed
> MaxVGPR
? maxUsed
: MaxVGPR
;
130 SIMachineFunctionInfo
* MFI
= MF
.getInfo
<SIMachineFunctionInfo
>();
131 OutStreamer
.EmitIntValue(MaxSGPR
+ 1, 4);
132 OutStreamer
.EmitIntValue(MaxVGPR
+ 1, 4);
133 OutStreamer
.EmitIntValue(MFI
->SPIPSInputAddr
, 4);