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 //===----------------------------------------------------------------------===//
12 /// The AMDGPUAsmPrinter 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.
16 //===----------------------------------------------------------------------===//
20 #include "AMDGPUAsmPrinter.h"
22 #include "SIMachineFunctionInfo.h"
23 #include "SIRegisterInfo.h"
24 #include "llvm/MC/MCStreamer.h"
25 #include "llvm/Support/TargetRegistry.h"
26 #include "llvm/Target/TargetLoweringObjectFile.h"
31 static AsmPrinter *createAMDGPUAsmPrinterPass(TargetMachine &tm,
32 MCStreamer &Streamer) {
33 return new AMDGPUAsmPrinter(tm, Streamer);
36 extern "C" void LLVMInitializeR600AsmPrinter() {
37 TargetRegistry::RegisterAsmPrinter(TheAMDGPUTarget, createAMDGPUAsmPrinterPass);
40 /// We need to override this function so we can avoid
41 /// the call to EmitFunctionHeader(), which the MCPureStreamer can't handle.
42 bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
43 const AMDGPUSubtarget &STM = TM.getSubtarget<AMDGPUSubtarget>();
45 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
49 SetupMachineFunction(MF);
50 if (OutStreamer.hasRawTextSupport()) {
51 OutStreamer.EmitRawText("@" + MF.getName() + ":");
53 OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
54 if (STM.device()->getGeneration() > AMDGPUDeviceInfo::HD6XXX) {
61 void AMDGPUAsmPrinter::EmitProgramInfo(MachineFunction &MF) {
65 const SIRegisterInfo * RI =
66 static_cast<const SIRegisterInfo*>(TM.getRegisterInfo());
68 for (MachineFunction::iterator BB = MF.begin(), BB_E = MF.end();
70 MachineBasicBlock &MBB = *BB;
71 for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
73 MachineInstr &MI = *I;
75 unsigned numOperands = MI.getNumOperands();
76 for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) {
77 MachineOperand & MO = MI.getOperand(op_idx);
87 if (reg == AMDGPU::VCC) {
98 if (AMDGPU::SReg_32RegClass.contains(reg)) {
101 } else if (AMDGPU::VReg_32RegClass.contains(reg)) {
104 } else if (AMDGPU::SReg_64RegClass.contains(reg)) {
107 } else if (AMDGPU::VReg_64RegClass.contains(reg)) {
110 } else if (AMDGPU::SReg_128RegClass.contains(reg)) {
113 } else if (AMDGPU::VReg_128RegClass.contains(reg)) {
116 } else if (AMDGPU::SReg_256RegClass.contains(reg)) {
119 } else if (AMDGPU::VReg_256RegClass.contains(reg)) {
122 } else if (AMDGPU::VReg_512RegClass.contains(reg)) {
126 assert(!"Unknown register class");
128 hwReg = RI->getEncodingValue(reg) & 0xff;
129 maxUsed = hwReg + width - 1;
131 MaxSGPR = maxUsed > MaxSGPR ? maxUsed : MaxSGPR;
133 MaxVGPR = maxUsed > MaxVGPR ? maxUsed : MaxVGPR;
141 SIMachineFunctionInfo * MFI = MF.getInfo<SIMachineFunctionInfo>();
142 OutStreamer.EmitIntValue(MaxSGPR + 1, 4);
143 OutStreamer.EmitIntValue(MaxVGPR + 1, 4);
144 OutStreamer.EmitIntValue(MFI->PSInputAddr, 4);