Skip to content

Commit 72c3943

Browse files
committed
[NFC][Comgr] Cleanup of AMDGPUCompiler::unbundle
1 parent aa68ef2 commit 72c3943

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

amd/comgr/src/comgr-compiler.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
12571257
// Collect bitcode memory buffers from bitcodes, bundles, and archives
12581258
for (auto *Input : InSet->DataObjects) {
12591259

1260-
std::string FileExtension;
1260+
const char *FileExtension;
12611261
amd_comgr_data_kind_t UnbundledDataKind;
12621262
switch (Input->DataKind) {
12631263
case AMD_COMGR_DATA_KIND_BC_BUNDLE:
@@ -1288,22 +1288,22 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
12881288
const size_t BufSize = sizeof(char) * 30;
12891289
char *Buf = (char *)malloc(BufSize);
12901290
snprintf(Buf, BufSize, "comgr-bundle-%d.%s", std::rand() % 10000,
1291-
FileExtension.c_str());
1291+
FileExtension);
12921292
Input->Name = Buf;
12931293
}
12941294

12951295
// Write input file system so that OffloadBundler API can process
12961296
// TODO: Switch write to VFS
1297-
std::string InputFilePath = getFilePath(Input, InputDir).str().str();
1297+
SmallString<128> InputFilePath = getFilePath(Input, InputDir);
12981298
if (auto Status = outputToFile(Input, InputFilePath)) {
12991299
return Status;
13001300
}
13011301

13021302
// Bundler input name
1303-
BundlerConfig.InputFileNames.push_back(InputFilePath);
1303+
BundlerConfig.InputFileNames.emplace_back(InputFilePath);
13041304

13051305
// Generate prefix for output files
1306-
std::string OutputPrefix = std::string(Input->Name);
1306+
StringRef OutputPrefix = Input->Name;
13071307
size_t Index = OutputPrefix.find_last_of(".");
13081308
OutputPrefix = OutputPrefix.substr(0, Index);
13091309

@@ -1314,22 +1314,18 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13141314
<< " Unbundled Files Extension: ." << FileExtension << "\n";
13151315
}
13161316

1317-
for (size_t I = 0; I < ActionInfo->BundleEntryIDs.size(); I++) {
1318-
auto Entry = ActionInfo->BundleEntryIDs[I];
1319-
BundlerConfig.TargetNames.push_back(Entry);
1320-
1317+
for (StringRef Entry : ActionInfo->BundleEntryIDs) {
13211318
// Add an output file for each target
1322-
std::string OutputFileName =
1323-
OutputPrefix + '-' + Entry + "." + FileExtension;
1319+
SmallString<128> OutputFilePath = OutputDir;
1320+
sys::path::append(OutputFilePath,
1321+
OutputPrefix + "-" + Entry + "." + FileExtension);
13241322

1325-
// TODO: Switch this to LLVM path APIs
1326-
std::string OutputFilePath = OutputDir.str().str() + "/" + OutputFileName;
1327-
BundlerConfig.OutputFileNames.push_back(OutputFilePath);
1323+
BundlerConfig.TargetNames.emplace_back(Entry);
1324+
BundlerConfig.OutputFileNames.emplace_back(OutputFilePath);
13281325

13291326
if (env::shouldEmitVerboseLogs()) {
1330-
LogS << "\tBundle Entry ID: " << BundlerConfig.TargetNames[I] << "\n"
1331-
<< "\tOutput Filename: " << BundlerConfig.OutputFileNames[I]
1332-
<< "\n";
1327+
LogS << "\tBundle Entry ID: " << Entry << "\n"
1328+
<< "\tOutput Filename: " << OutputFilePath << "\n";
13331329
LogS.flush();
13341330
}
13351331
}
@@ -1360,7 +1356,7 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13601356
}
13611357

13621358
// Add new bitcodes to OutSetT
1363-
for (auto OutputFilePath : BundlerConfig.OutputFileNames) {
1359+
for (StringRef OutputFilePath : BundlerConfig.OutputFileNames) {
13641360

13651361
amd_comgr_data_t ResultT;
13661362

@@ -1371,11 +1367,10 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13711367
ScopedDataObjectReleaser SDOR(ResultT);
13721368

13731369
DataObject *Result = DataObject::convert(ResultT);
1374-
if (auto Status = inputFromFile(Result, StringRef(OutputFilePath)))
1370+
if (auto Status = inputFromFile(Result, OutputFilePath))
13751371
return Status;
13761372

1377-
StringRef OutputFileName =
1378-
llvm::sys::path::filename(StringRef(OutputFilePath));
1373+
StringRef OutputFileName = sys::path::filename(OutputFilePath);
13791374
Result->setName(OutputFileName);
13801375

13811376
if (auto Status = amd_comgr_data_set_add(OutSetT, ResultT)) {

0 commit comments

Comments
 (0)