1- // ===- OffloadBundle.cpp - Utilities for handling offloading code -*- C++
2- // -*-===//
1+ // ===- OffloadBundle.cpp - Utilities for offload bundles---*- C++ -*-===//
32//
43// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54// See https://llvm.org/LICENSE.txt for license information.
65// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
76//
8- // ===---------------------------------------------------------------------- ===//
7+ // ===----------------------------------------------------------------===//
98
109#include " llvm/Object/OffloadBundle.h"
1110#include " llvm/ADT/StringSwitch.h"
@@ -79,9 +78,8 @@ Error OffloadBundleFatBin::readEntries(StringRef Buffer,
7978
8079 // Read the Magic String first.
8180 StringRef Magic;
82- if (auto EC = Reader.readFixedString (Magic, 24 )) {
81+ if (auto EC = Reader.readFixedString (Magic, 24 ))
8382 return errorCodeToError (object_error::parse_failed);
84- }
8583
8684 // Read the number of Code Objects (Entries) in the current Bundle.
8785 if (auto EC = Reader.readInteger (NumOfEntries))
@@ -108,8 +106,10 @@ Error OffloadBundleFatBin::readEntries(StringRef Buffer,
108106 if (auto EC = Reader.readFixedString (EntryID, EntryIDSize))
109107 return errorCodeToError (object_error::parse_failed);
110108
111- // create a Bundle Entry object:
112- auto Entry = new OffloadBundleEntry (EntryOffset + SectionOffset, EntrySize,
109+ // Create a Bundle Entry object:
110+ // auto Entry = new OffloadBundleEntry(EntryOffset + SectionOffset, EntrySize,
111+ // EntryIDSize, EntryID);
112+ auto Entry = std::make_unique<OffloadBundleEntry>(EntryOffset + SectionOffset, EntrySize,
113113 EntryIDSize, EntryID);
114114
115115 Entries.push_back (*Entry);
@@ -142,15 +142,16 @@ Error OffloadBundleFatBin::extractBundle(const ObjectFile &Source) {
142142 // This will extract all entries in the Bundle
143143 for (OffloadBundleEntry &Entry : Entries) {
144144
145- if (Entry.Size > 0 ) {
146- // create output file name. Which should be
147- // <fileName>-offset<Offset>-size<Size>.co"
148- std::string Str = getFileName ().str () + " -offset" + itostr (Entry.Offset ) +
149- " -size" + itostr (Entry.Size ) + " .co" ;
150- if (Error Err = object::extractCodeObject (Source, Entry.Offset ,
151- Entry.Size , StringRef (Str)))
152- return Err;
153- }
145+ if (Entry.Size == 0 )
146+ continue ;
147+
148+ // create output file name. Which should be
149+ // <fileName>-offset<Offset>-size<Size>.co"
150+ std::string Str = getFileName ().str () + " -offset" + itostr (Entry.Offset ) +
151+ " -size" + itostr (Entry.Size ) + " .co" ;
152+ if (Error Err = object::extractCodeObject (Source, Entry.Offset , Entry.Size ,
153+ StringRef (Str)))
154+ return Err;
154155 }
155156
156157 return Error::success ();
@@ -160,7 +161,7 @@ Error object::extractOffloadBundleFatBinary(
160161 const ObjectFile &Obj, SmallVectorImpl<OffloadBundleFatBin> &Bundles) {
161162 assert ((Obj.isELF () || Obj.isCOFF ()) && " Invalid file type" );
162163
163- // iterate through Sections until we find an offload_bundle section.
164+ // Iterate through Sections until we find an offload_bundle section.
164165 for (SectionRef Sec : Obj.sections ()) {
165166 Expected<StringRef> Buffer = Sec.getContents ();
166167 if (!Buffer)
@@ -175,9 +176,8 @@ Error object::extractOffloadBundleFatBinary(
175176 if (Obj.isELF ()) {
176177 SectionOffset = ELFSectionRef (Sec).getOffset ();
177178 } else if (Obj.isCOFF ()) {
178- if (const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(&Obj)) {
179+ if (const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(&Obj))
179180 const coff_section *CoffSection = COFFObj->getCOFFSection (Sec);
180- }
181181 }
182182
183183 MemoryBufferRef Contents (*Buffer, Obj.getFileName ());
@@ -341,7 +341,7 @@ CompressedOffloadBundle::decompress(llvm::MemoryBufferRef &Input,
341341 double DecompressionTimeSeconds =
342342 DecompressTimer.getTotalTime ().getWallTime ();
343343
344- // Recalculate MD5 hash for integrity check
344+ // Recalculate MD5 hash for integrity check.
345345 llvm::Timer HashRecalcTimer (" Hash Recalculation Timer" ,
346346 " Hash recalculation time" ,
347347 OffloadBundlerTimerGroup);
0 commit comments