|
15 | 15 | #include "llvm/IR/GlobalVariable.h" |
16 | 16 | #include "llvm/IR/Value.h" |
17 | 17 | #include "llvm/Object/ELFObjectFile.h" |
18 | | -#include "llvm/ObjectYAML/ELFYAML.h" |
19 | | -#include "llvm/ObjectYAML/yaml2obj.h" |
20 | 18 | #include "llvm/Support/MemoryBufferRef.h" |
21 | 19 | #include "llvm/Transforms/Utils/ModuleUtils.h" |
22 | 20 |
|
@@ -367,87 +365,3 @@ Error llvm::offloading::amdgpu::getAMDGPUMetaDataFromImage( |
367 | 365 | } |
368 | 366 | return Error::success(); |
369 | 367 | } |
370 | | - |
371 | | -void offloading::intel::containerizeOpenMPSPIRVImage( |
372 | | - object::OffloadBinary::OffloadingImage &Img) { |
373 | | - constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] = "1.0"; |
374 | | - constexpr int NT_INTEL_ONEOMP_OFFLOAD_VERSION = 1; |
375 | | - constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT = 2; |
376 | | - constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX = 3; |
377 | | - llvm::Triple Triple(Img.StringData.lookup("triple")); |
378 | | - assert((Triple.isSPIRV() && Triple.getVendor() == llvm::Triple::Intel) && |
379 | | - "Unexpected triple"); |
380 | | - |
381 | | - // Start creating notes for the ELF container. |
382 | | - std::vector<ELFYAML::NoteEntry> Notes; |
383 | | - std::string Version = toHex(INTEL_ONEOMP_OFFLOAD_VERSION); |
384 | | - Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", |
385 | | - yaml::BinaryRef(Version), |
386 | | - NT_INTEL_ONEOMP_OFFLOAD_VERSION}); |
387 | | - |
388 | | - // The AuxInfo string will hold auxiliary information for the image. |
389 | | - // ELFYAML::NoteEntry structures will hold references to the |
390 | | - // string, so we have to make sure the string is valid. |
391 | | - std::string AuxInfo; |
392 | | - |
393 | | - // TODO: Pass compile/link opts |
394 | | - StringRef CompileOpts = ""; |
395 | | - StringRef LinkOpts = ""; |
396 | | - |
397 | | - unsigned ImageFmt = 1; // SPIR-V format |
398 | | - |
399 | | - AuxInfo = toHex((Twine(0) + Twine('\0') + Twine(ImageFmt) + Twine('\0') + |
400 | | - CompileOpts + Twine('\0') + LinkOpts) |
401 | | - .str()); |
402 | | - Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", |
403 | | - yaml::BinaryRef(AuxInfo), |
404 | | - NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX}); |
405 | | - |
406 | | - std::string ImgCount = toHex(Twine(1).str()); // always one image per ELF |
407 | | - Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", |
408 | | - yaml::BinaryRef(ImgCount), |
409 | | - NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT}); |
410 | | - |
411 | | - std::string YamlFile; |
412 | | - llvm::raw_string_ostream YamlFileStream(YamlFile); |
413 | | - |
414 | | - // Write YAML template file. |
415 | | - { |
416 | | - // We use 64-bit little-endian ELF currently. |
417 | | - ELFYAML::FileHeader Header{}; |
418 | | - Header.Class = ELF::ELFCLASS64; |
419 | | - Header.Data = ELF::ELFDATA2LSB; |
420 | | - Header.Type = ELF::ET_DYN; |
421 | | - // Use an existing Intel machine type as there is not one specifically for |
422 | | - // Intel GPUs. |
423 | | - Header.Machine = ELF::EM_IA_64; |
424 | | - |
425 | | - // Create a section with notes. |
426 | | - ELFYAML::NoteSection Section{}; |
427 | | - Section.Type = ELF::SHT_NOTE; |
428 | | - Section.AddressAlign = 0; |
429 | | - Section.Name = ".note.inteloneompoffload"; |
430 | | - Section.Notes.emplace(std::move(Notes)); |
431 | | - |
432 | | - ELFYAML::Object Object{}; |
433 | | - Object.Header = Header; |
434 | | - Object.Chunks.push_back( |
435 | | - std::make_unique<ELFYAML::NoteSection>(std::move(Section))); |
436 | | - |
437 | | - // Create the section that will hold the image |
438 | | - ELFYAML::RawContentSection ImageSection{}; |
439 | | - ImageSection.Type = ELF::SHT_PROGBITS; |
440 | | - ImageSection.AddressAlign = 0; |
441 | | - std::string Name = "__openmp_offload_spirv_0"; |
442 | | - ImageSection.Name = Name; |
443 | | - ImageSection.Content = |
444 | | - llvm::yaml::BinaryRef(arrayRefFromStringRef(Img.Image->getBuffer())); |
445 | | - Object.Chunks.push_back( |
446 | | - std::make_unique<ELFYAML::RawContentSection>(std::move(ImageSection))); |
447 | | - |
448 | | - llvm::yaml::yaml2elf( |
449 | | - Object, YamlFileStream, |
450 | | - [](const Twine &Msg) { llvm::report_fatal_error(Msg); }, UINT64_MAX); |
451 | | - } |
452 | | - Img.Image = MemoryBuffer::getMemBufferCopy(YamlFile); |
453 | | -} |
0 commit comments