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,9 +106,12 @@ 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,
113- EntryIDSize, EntryID);
109+ // Create a Bundle Entry object:
110+ // auto Entry = new OffloadBundleEntry(EntryOffset + SectionOffset,
111+ // EntrySize,
112+ // EntryIDSize, EntryID);
113+ auto Entry = std::make_unique<OffloadBundleEntry>(
114+ EntryOffset + SectionOffset, EntrySize, EntryIDSize, EntryID);
114115
115116 Entries.push_back (*Entry);
116117 }
@@ -142,15 +143,16 @@ Error OffloadBundleFatBin::extractBundle(const ObjectFile &Source) {
142143 // This will extract all entries in the Bundle
143144 for (OffloadBundleEntry &Entry : Entries) {
144145
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- }
146+ if (Entry.Size == 0 )
147+ continue ;
148+
149+ // create output file name. Which should be
150+ // <fileName>-offset<Offset>-size<Size>.co"
151+ std::string Str = getFileName ().str () + " -offset" + itostr (Entry.Offset ) +
152+ " -size" + itostr (Entry.Size ) + " .co" ;
153+ if (Error Err = object::extractCodeObject (Source, Entry.Offset , Entry.Size ,
154+ StringRef (Str)))
155+ return Err;
154156 }
155157
156158 return Error::success ();
@@ -160,7 +162,7 @@ Error object::extractOffloadBundleFatBinary(
160162 const ObjectFile &Obj, SmallVectorImpl<OffloadBundleFatBin> &Bundles) {
161163 assert ((Obj.isELF () || Obj.isCOFF ()) && " Invalid file type" );
162164
163- // iterate through Sections until we find an offload_bundle section.
165+ // Iterate through Sections until we find an offload_bundle section.
164166 for (SectionRef Sec : Obj.sections ()) {
165167 Expected<StringRef> Buffer = Sec.getContents ();
166168 if (!Buffer)
@@ -175,9 +177,8 @@ Error object::extractOffloadBundleFatBinary(
175177 if (Obj.isELF ()) {
176178 SectionOffset = ELFSectionRef (Sec).getOffset ();
177179 } else if (Obj.isCOFF ()) {
178- if (const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(&Obj)) {
180+ if (const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(&Obj))
179181 const coff_section *CoffSection = COFFObj->getCOFFSection (Sec);
180- }
181182 }
182183
183184 MemoryBufferRef Contents (*Buffer, Obj.getFileName ());
@@ -341,7 +342,7 @@ CompressedOffloadBundle::decompress(llvm::MemoryBufferRef &Input,
341342 double DecompressionTimeSeconds =
342343 DecompressTimer.getTotalTime ().getWallTime ();
343344
344- // Recalculate MD5 hash for integrity check
345+ // Recalculate MD5 hash for integrity check.
345346 llvm::Timer HashRecalcTimer (" Hash Recalculation Timer" ,
346347 " Hash recalculation time" ,
347348 OffloadBundlerTimerGroup);
0 commit comments