1 //===-- AMDILAsmPrinter7XX.cpp - TODO: Add brief description -------===//
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 //==-----------------------------------------------------------------------===//
9 #include "AMDIL7XXAsmPrinter.h"
11 #include "AMDILAlgorithms.tpp"
12 #include "AMDIL7XXAsmPrinter.h"
13 #include "AMDILDevices.h"
14 #include "AMDILGlobalManager.h"
15 #include "AMDILKernelManager.h"
16 #include "AMDILMachineFunctionInfo.h"
17 #include "AMDILUtilityFunctions.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/ADT/Statistic.h"
20 #include "llvm/ADT/StringExtras.h"
21 #include "llvm/Analysis/DebugInfo.h"
22 #include "llvm/CodeGen/MachineConstantPool.h"
23 #include "llvm/CodeGen/MachineModuleInfo.h"
24 #include "llvm/CodeGen/MachineRegisterInfo.h"
25 #include "llvm/Constants.h"
26 #include "llvm/MC/MCAsmInfo.h"
27 #include "llvm/MC/MCStreamer.h"
28 #include "llvm/MC/MCSymbol.h"
29 #include "llvm/Metadata.h"
30 #include "llvm/Support/Debug.h"
31 #include "llvm/Support/DebugLoc.h"
32 #include "llvm/Support/InstIterator.h"
33 #include "llvm/Support/TargetRegistry.h"
34 #include "llvm/Type.h"
38 // TODO: Add support for verbose.
39 AMDIL7XXAsmPrinter::AMDIL7XXAsmPrinter(TargetMachine& TM, MCStreamer &Streamer)
40 : AMDILAsmPrinter(TM, Streamer)
44 AMDIL7XXAsmPrinter::~AMDIL7XXAsmPrinter()
49 /// @brief strips KERNEL_PREFIX and KERNEL_SUFFIX from the name
50 /// and returns that name if both of the tokens are present.
53 std::string Strip(const std::string &name)
55 size_t start = name.find("__OpenCL_");
56 size_t end = name.find("_kernel");
57 if (start == std::string::npos
58 || end == std::string::npos
62 return name.substr(9, name.length()-16);
66 AMDIL7XXAsmPrinter::emitMacroFunc(const MachineInstr *MI,
69 const AMDILSubtarget *curTarget = mTM->getSubtargetImpl();
70 const char *name = "unknown";
71 llvm::StringRef nameRef;
72 if (MI->getOperand(0).isGlobal()) {
73 nameRef = MI->getOperand(0).getGlobal()->getName();
74 name = nameRef.data();
75 if (curTarget->device()->usesHardware(
76 AMDILDeviceInfo::DoubleOps)
77 && !::strncmp(name, "__sqrt_f64", 10) ) {
78 name = "__sqrt_f64_7xx";
81 emitMCallInst(MI, O, name);
85 AMDIL7XXAsmPrinter::runOnMachineFunction(MachineFunction &lMF)
89 mMFI = lMF.getInfo<AMDILMachineFunctionInfo>();
90 SetupMachineFunction(lMF);
91 std::string kernelName = MF->getFunction()->getName();
92 mName = Strip(kernelName);
94 mKernelName = kernelName;
101 AMDIL7XXAsmPrinter::EmitInstruction(const MachineInstr *II)
104 raw_string_ostream OFunStr(FunStr);
105 formatted_raw_ostream O(OFunStr);
106 const AMDILSubtarget *curTarget = mTM->getSubtargetImpl();
111 if (isMacroFunc(II)) {
112 emitMacroFunc(II, O);
114 OutStreamer.EmitRawText(StringRef(FunStr));
117 if (isMacroCall(II)) {
119 name = mTM->getInstrInfo()->getName(II->getOpcode()) + 5;
120 int macronum = amd::MacroDBFindMacro(name);
121 O << "\t;"<< name<<"\n";
122 O << "\tmcall("<<macronum<<")";
123 if (curTarget->device()->isSupported(
124 AMDILDeviceInfo::MacroDB)) {
125 mMacroIDs.insert(macronum);
127 mMFI->addCalledIntr(macronum);
131 // Print the assembly for the instruction.
132 // We want to make sure that we do HW constants
133 // before we do arena segment
134 if (mMeta->useCompilerWrite(II)) {
135 // TODO: This is a hack to get around some
136 // conformance failures.
137 O << "\tif_logicalz cb0[0].x\n";
138 O << "\tuav_raw_store_id("
139 << curTarget->device()->getResourceID(AMDILDevice::RAW_UAV_ID)
141 O << "mem0.x___, cb0[3].x, r0.0\n";
143 mMFI->addMetadata(";memory:compilerwrite");
145 printInstruction(II, O);
148 OutStreamer.EmitRawText(StringRef(FunStr));