Changeset View
Changeset View
Standalone View
Standalone View
lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | void AMDGPUTargetAsmStreamer::EmitAMDGPUHsaModuleScopeGlobal( | ||||
OS << "\t.amdgpu_hsa_module_global " << GlobalName << '\n'; | OS << "\t.amdgpu_hsa_module_global " << GlobalName << '\n'; | ||||
} | } | ||||
void AMDGPUTargetAsmStreamer::EmitAMDGPUHsaProgramScopeGlobal( | void AMDGPUTargetAsmStreamer::EmitAMDGPUHsaProgramScopeGlobal( | ||||
StringRef GlobalName) { | StringRef GlobalName) { | ||||
OS << "\t.amdgpu_hsa_program_global " << GlobalName << '\n'; | OS << "\t.amdgpu_hsa_program_global " << GlobalName << '\n'; | ||||
} | } | ||||
void AMDGPUTargetAsmStreamer::emitRuntimeMetadata(Module &M) { | |||||
OS << "\t.amdgpu_runtime_metadata\n"; | |||||
OS << getRuntimeMDYAMLString(M); | |||||
OS << "\n\t.end_amdgpu_runtime_metadata\n"; | |||||
} | |||||
void AMDGPUTargetAsmStreamer::EmitRuntimeMetadata(StringRef Metadata) { | |||||
OS << "\t.amdgpu_runtime_metadata "; | |||||
OS << Metadata; | |||||
OS << "\t.end_amdgpu_runtime_metadata\n"; | |||||
} | |||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// AMDGPUTargetELFStreamer | // AMDGPUTargetELFStreamer | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
AMDGPUTargetELFStreamer::AMDGPUTargetELFStreamer(MCStreamer &S) | AMDGPUTargetELFStreamer::AMDGPUTargetELFStreamer(MCStreamer &S) | ||||
: AMDGPUTargetStreamer(S), Streamer(S) {} | : AMDGPUTargetStreamer(S), Streamer(S) {} | ||||
MCELFStreamer &AMDGPUTargetELFStreamer::getStreamer() { | MCELFStreamer &AMDGPUTargetELFStreamer::getStreamer() { | ||||
return static_cast<MCELFStreamer &>(Streamer); | return static_cast<MCELFStreamer &>(Streamer); | ||||
} | } | ||||
void | void | ||||
AMDGPUTargetELFStreamer::EmitAMDGPUNote(const MCExpr* DescSZ, | |||||
PT_NOTE::NoteType Type, | |||||
std::function<void(MCELFStreamer &)> EmitDesc) { | |||||
auto &S = getStreamer(); | |||||
auto &Context = S.getContext(); | |||||
auto NameSZ = sizeof(PT_NOTE::NoteName); | |||||
S.PushSection(); | |||||
S.SwitchSection(Context.getELFSection( | |||||
PT_NOTE::SectionName, ELF::SHT_NOTE, ELF::SHF_ALLOC)); | |||||
S.EmitIntValue(NameSZ, 4); // namesz | |||||
S.EmitValue(DescSZ, 4); // descz | |||||
S.EmitIntValue(Type, 4); // type | |||||
S.EmitBytes(StringRef(PT_NOTE::NoteName, NameSZ)); // name | |||||
S.EmitValueToAlignment(4, 0, 1, 0); // padding 0 | |||||
EmitDesc(S); // desc | |||||
S.EmitValueToAlignment(4, 0, 1, 0); // padding 0 | |||||
S.PopSection(); | |||||
} | |||||
void | |||||
AMDGPUTargetELFStreamer::EmitDirectiveHSACodeObjectVersion(uint32_t Major, | AMDGPUTargetELFStreamer::EmitDirectiveHSACodeObjectVersion(uint32_t Major, | ||||
uint32_t Minor) { | uint32_t Minor) { | ||||
MCStreamer &OS = getStreamer(); | |||||
MCSectionELF *Note = | |||||
OS.getContext().getELFSection(PT_NOTE::SectionName, ELF::SHT_NOTE, | |||||
ELF::SHF_ALLOC); | |||||
auto NameSZ = sizeof(PT_NOTE::NoteName); | EmitAMDGPUNote( | ||||
OS.PushSection(); | MCConstantExpr::create(8, getContext()), | ||||
OS.SwitchSection(Note); | PT_NOTE::NT_AMDGPU_HSA_CODE_OBJECT_VERSION, | ||||
OS.EmitIntValue(NameSZ, 4); // namesz | [&](MCELFStreamer &OS){ | ||||
OS.EmitIntValue(8, 4); // descz | OS.EmitIntValue(Major, 4); | ||||
OS.EmitIntValue(PT_NOTE::NT_AMDGPU_HSA_CODE_OBJECT_VERSION, 4); // type | |||||
OS.EmitBytes(StringRef(PT_NOTE::NoteName, NameSZ)); // name | |||||
OS.EmitValueToAlignment(4); | |||||
OS.EmitIntValue(Major, 4); // desc | |||||
OS.EmitIntValue(Minor, 4); | OS.EmitIntValue(Minor, 4); | ||||
OS.EmitValueToAlignment(4); | } | ||||
OS.PopSection(); | ); | ||||
} | } | ||||
void | void | ||||
AMDGPUTargetELFStreamer::EmitDirectiveHSACodeObjectISA(uint32_t Major, | AMDGPUTargetELFStreamer::EmitDirectiveHSACodeObjectISA(uint32_t Major, | ||||
uint32_t Minor, | uint32_t Minor, | ||||
uint32_t Stepping, | uint32_t Stepping, | ||||
StringRef VendorName, | StringRef VendorName, | ||||
StringRef ArchName) { | StringRef ArchName) { | ||||
MCStreamer &OS = getStreamer(); | |||||
MCSectionELF *Note = | |||||
OS.getContext().getELFSection(PT_NOTE::SectionName, ELF::SHT_NOTE, | |||||
ELF::SHF_ALLOC); | |||||
uint16_t VendorNameSize = VendorName.size() + 1; | uint16_t VendorNameSize = VendorName.size() + 1; | ||||
uint16_t ArchNameSize = ArchName.size() + 1; | uint16_t ArchNameSize = ArchName.size() + 1; | ||||
unsigned DescSZ = sizeof(VendorNameSize) + sizeof(ArchNameSize) + | unsigned DescSZ = sizeof(VendorNameSize) + sizeof(ArchNameSize) + | ||||
sizeof(Major) + sizeof(Minor) + sizeof(Stepping) + | sizeof(Major) + sizeof(Minor) + sizeof(Stepping) + | ||||
VendorNameSize + ArchNameSize; | VendorNameSize + ArchNameSize; | ||||
OS.PushSection(); | EmitAMDGPUNote( | ||||
OS.SwitchSection(Note); | MCConstantExpr::create(DescSZ, getContext()), | ||||
auto NameSZ = sizeof(PT_NOTE::NoteName); | PT_NOTE::NT_AMDGPU_HSA_ISA, | ||||
OS.EmitIntValue(NameSZ, 4); // namesz | [&](MCELFStreamer &OS) { | ||||
OS.EmitIntValue(DescSZ, 4); // descsz | OS.EmitIntValue(VendorNameSize, 2); | ||||
OS.EmitIntValue(PT_NOTE::NT_AMDGPU_HSA_ISA, 4); // type | |||||
OS.EmitBytes(StringRef(PT_NOTE::NoteName, NameSZ)); // name | |||||
OS.EmitValueToAlignment(4); | |||||
OS.EmitIntValue(VendorNameSize, 2); // desc | |||||
OS.EmitIntValue(ArchNameSize, 2); | OS.EmitIntValue(ArchNameSize, 2); | ||||
OS.EmitIntValue(Major, 4); | OS.EmitIntValue(Major, 4); | ||||
OS.EmitIntValue(Minor, 4); | OS.EmitIntValue(Minor, 4); | ||||
OS.EmitIntValue(Stepping, 4); | OS.EmitIntValue(Stepping, 4); | ||||
OS.EmitBytes(VendorName); | OS.EmitBytes(VendorName); | ||||
OS.EmitIntValue(0, 1); // NULL terminate VendorName | OS.EmitIntValue(0, 1); // NULL terminate VendorName | ||||
OS.EmitBytes(ArchName); | OS.EmitBytes(ArchName); | ||||
OS.EmitIntValue(0, 1); // NULL terminte ArchName | OS.EmitIntValue(0, 1); // NULL terminte ArchName | ||||
OS.EmitValueToAlignment(4); | } | ||||
OS.PopSection(); | ); | ||||
} | } | ||||
void | void | ||||
AMDGPUTargetELFStreamer::EmitAMDKernelCodeT(const amd_kernel_code_t &Header) { | AMDGPUTargetELFStreamer::EmitAMDKernelCodeT(const amd_kernel_code_t &Header) { | ||||
MCStreamer &OS = getStreamer(); | MCStreamer &OS = getStreamer(); | ||||
OS.PushSection(); | OS.PushSection(); | ||||
OS.EmitBytes(StringRef((const char*)&Header, sizeof(Header))); | OS.EmitBytes(StringRef((const char*)&Header, sizeof(Header))); | ||||
Show All 20 Lines | void AMDGPUTargetELFStreamer::EmitAMDGPUHsaProgramScopeGlobal( | ||||
StringRef GlobalName) { | StringRef GlobalName) { | ||||
MCSymbolELF *Symbol = cast<MCSymbolELF>( | MCSymbolELF *Symbol = cast<MCSymbolELF>( | ||||
getStreamer().getContext().getOrCreateSymbol(GlobalName)); | getStreamer().getContext().getOrCreateSymbol(GlobalName)); | ||||
Symbol->setType(ELF::STT_OBJECT); | Symbol->setType(ELF::STT_OBJECT); | ||||
Symbol->setBinding(ELF::STB_GLOBAL); | Symbol->setBinding(ELF::STB_GLOBAL); | ||||
} | } | ||||
void AMDGPUTargetELFStreamer::emitRuntimeMetadata(Module &M) { | void AMDGPUTargetELFStreamer::EmitRuntimeMetadata(StringRef Metadata) { | ||||
auto &S = getStreamer(); | // Create two labels to mark the beginning and end of the desc field | ||||
auto &Context = S.getContext(); | // and a MCExpr to calculate the size of the desc field. | ||||
auto &Context = getContext(); | |||||
auto NameSZ = sizeof(PT_NOTE::NoteName); // Size of note name including trailing null. | auto *DescBegin = Context.createTempSymbol(); | ||||
auto *DescEnd = Context.createTempSymbol(); | |||||
auto *DescSZ = MCBinaryExpr::createSub( | |||||
MCSymbolRefExpr::create(DescEnd, Context), | |||||
MCSymbolRefExpr::create(DescBegin, Context), Context); | |||||
S.PushSection(); | EmitAMDGPUNote( | ||||
S.SwitchSection(Context.getELFSection( | DescSZ, | ||||
PT_NOTE::SectionName, ELF::SHT_NOTE, ELF::SHF_ALLOC)); | PT_NOTE::NT_AMDGPU_HSA_RUNTIME_METADATA, | ||||
[&](MCELFStreamer &OS) { | |||||
OS.EmitLabel(DescBegin); | |||||
OS.EmitBytes(Metadata); | |||||
OS.EmitLabel(DescEnd); | |||||
} | |||||
); | |||||
} | |||||
void AMDGPUTargetELFStreamer::emitRuntimeMetadata(Module &M) { | |||||
// Create two labels to mark the beginning and end of the desc field | // Create two labels to mark the beginning and end of the desc field | ||||
// and a MCExpr to calculate the size of the desc field. | // and a MCExpr to calculate the size of the desc field. | ||||
auto &Context = getContext(); | |||||
auto *DescBegin = Context.createTempSymbol(); | auto *DescBegin = Context.createTempSymbol(); | ||||
auto *DescEnd = Context.createTempSymbol(); | auto *DescEnd = Context.createTempSymbol(); | ||||
auto *DescSZ = MCBinaryExpr::createSub( | auto *DescSZ = MCBinaryExpr::createSub( | ||||
MCSymbolRefExpr::create(DescEnd, Context), | MCSymbolRefExpr::create(DescEnd, Context), | ||||
MCSymbolRefExpr::create(DescBegin, Context), Context); | MCSymbolRefExpr::create(DescBegin, Context), Context); | ||||
// Emit the note element for runtime metadata. | EmitAMDGPUNote( | ||||
// Name and desc should be padded to 4 byte boundary but size of name and | DescSZ, | ||||
// desc should not include padding 0's. | PT_NOTE::NT_AMDGPU_HSA_RUNTIME_METADATA, | ||||
S.EmitIntValue(NameSZ, 4); // namesz | [&](MCELFStreamer &OS) { | ||||
S.EmitValue(DescSZ, 4); // descz | OS.EmitLabel(DescBegin); | ||||
S.EmitIntValue(PT_NOTE::NT_AMDGPU_HSA_RUNTIME_METADATA, 4); // type | OS.EmitBytes(getRuntimeMDYAMLString(M)); | ||||
S.EmitBytes(StringRef(PT_NOTE::NoteName, NameSZ)); // name | OS.EmitLabel(DescEnd); | ||||
S.EmitValueToAlignment(4, 0, 1, 0); // padding 0 | } | ||||
S.EmitLabel(DescBegin); | ); | ||||
yaxunl: This function and the above function are similar. Is it possible to unify them? | |||||
S.EmitBytes(getRuntimeMDYAMLString(M)); // desc | |||||
S.EmitLabel(DescEnd); | |||||
S.EmitValueToAlignment(4, 0, 1, 0); // padding 0 | |||||
S.PopSection(); | |||||
} | } |
This function and the above function are similar. Is it possible to unify them?