Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame^] | 1 | //===-- AMDGPUTargetStreamer.cpp - Mips Target Streamer Methods -----------===// |
| 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 | // This file provides AMDGPU specific target streamer methods. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "AMDGPUTargetStreamer.h" |
| 15 | #include "llvm/ADT/Twine.h" |
| 16 | #include "llvm/MC/MCContext.h" |
| 17 | #include "llvm/MC/MCELFStreamer.h" |
| 18 | #include "llvm/MC/MCSectionELF.h" |
| 19 | #include "llvm/Support/ELF.h" |
| 20 | #include "llvm/Support/FormattedStream.h" |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
| 24 | AMDGPUTargetStreamer::AMDGPUTargetStreamer(MCStreamer &S) |
| 25 | : MCTargetStreamer(S) { } |
| 26 | |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | // AMDGPUTargetAsmStreamer |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | |
| 31 | AMDGPUTargetAsmStreamer::AMDGPUTargetAsmStreamer(MCStreamer &S, |
| 32 | formatted_raw_ostream &OS) |
| 33 | : AMDGPUTargetStreamer(S), OS(OS) { } |
| 34 | |
| 35 | void |
| 36 | AMDGPUTargetAsmStreamer::EmitDirectiveHSACodeObjectVersion(uint32_t Major, |
| 37 | uint32_t Minor) { |
| 38 | OS << "\t.hsa_code_object_version " << |
| 39 | Twine(Major) << "," << Twine(Minor) << '\n'; |
| 40 | } |
| 41 | |
| 42 | void |
| 43 | AMDGPUTargetAsmStreamer::EmitDirectiveHSACodeObjectISA(uint32_t Major, |
| 44 | uint32_t Minor, |
| 45 | uint32_t Stepping, |
| 46 | StringRef VendorName, |
| 47 | StringRef ArchName) { |
| 48 | OS << "\t.hsa_code_object_isa " << |
| 49 | Twine(Major) << "," << Twine(Minor) << "," << Twine(Stepping) << |
| 50 | ",\"" << VendorName << "\",\"" << ArchName << "\"\n"; |
| 51 | |
| 52 | } |
| 53 | |
| 54 | //===----------------------------------------------------------------------===// |
| 55 | // AMDGPUTargetELFStreamer |
| 56 | //===----------------------------------------------------------------------===// |
| 57 | |
| 58 | AMDGPUTargetELFStreamer::AMDGPUTargetELFStreamer(MCStreamer &S) |
| 59 | : AMDGPUTargetStreamer(S), Streamer(S) { } |
| 60 | |
| 61 | MCELFStreamer &AMDGPUTargetELFStreamer::getStreamer() { |
| 62 | return static_cast<MCELFStreamer &>(Streamer); |
| 63 | } |
| 64 | |
| 65 | void |
| 66 | AMDGPUTargetELFStreamer::EmitDirectiveHSACodeObjectVersion(uint32_t Major, |
| 67 | uint32_t Minor) { |
| 68 | MCStreamer &OS = getStreamer(); |
| 69 | MCSectionELF *Note = OS.getContext().getELFSection(".note", ELF::SHT_NOTE, 0); |
| 70 | |
| 71 | unsigned NameSZ = 4; |
| 72 | |
| 73 | OS.PushSection(); |
| 74 | OS.SwitchSection(Note); |
| 75 | OS.EmitIntValue(NameSZ, 4); // namesz |
| 76 | OS.EmitIntValue(8, 4); // descz |
| 77 | OS.EmitIntValue(NT_AMDGPU_HSA_CODE_OBJECT_VERSION, 4); // type |
| 78 | OS.EmitBytes(StringRef("AMD", NameSZ)); // name |
| 79 | OS.EmitIntValue(Major, 4); // desc |
| 80 | OS.EmitIntValue(Minor, 4); |
| 81 | OS.EmitValueToAlignment(4); |
| 82 | OS.PopSection(); |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | AMDGPUTargetELFStreamer::EmitDirectiveHSACodeObjectISA(uint32_t Major, |
| 87 | uint32_t Minor, |
| 88 | uint32_t Stepping, |
| 89 | StringRef VendorName, |
| 90 | StringRef ArchName) { |
| 91 | MCStreamer &OS = getStreamer(); |
| 92 | MCSectionELF *Note = OS.getContext().getELFSection(".note", ELF::SHT_NOTE, 0); |
| 93 | |
| 94 | unsigned NameSZ = 4; |
| 95 | uint16_t VendorNameSize = VendorName.size() + 1; |
| 96 | uint16_t ArchNameSize = ArchName.size() + 1; |
| 97 | unsigned DescSZ = sizeof(VendorNameSize) + sizeof(ArchNameSize) + |
| 98 | sizeof(Major) + sizeof(Minor) + sizeof(Stepping) + |
| 99 | VendorNameSize + ArchNameSize; |
| 100 | |
| 101 | OS.PushSection(); |
| 102 | OS.SwitchSection(Note); |
| 103 | OS.EmitIntValue(NameSZ, 4); // namesz |
| 104 | OS.EmitIntValue(DescSZ, 4); // descsz |
| 105 | OS.EmitIntValue(NT_AMDGPU_HSA_ISA, 4); // type |
| 106 | OS.EmitBytes(StringRef("AMD", 4)); // name |
| 107 | OS.EmitIntValue(VendorNameSize, 2); // desc |
| 108 | OS.EmitIntValue(ArchNameSize, 2); |
| 109 | OS.EmitIntValue(Major, 4); |
| 110 | OS.EmitIntValue(Minor, 4); |
| 111 | OS.EmitIntValue(Stepping, 4); |
| 112 | OS.EmitBytes(VendorName); |
| 113 | OS.EmitIntValue(0, 1); // NULL terminate VendorName |
| 114 | OS.EmitBytes(ArchName); |
| 115 | OS.EmitIntValue(0, 1); // NULL terminte ArchName |
| 116 | OS.EmitValueToAlignment(4); |
| 117 | OS.PopSection(); |
| 118 | } |