Skip to content

Commit 34271d1

Browse files
jmmartinezkzhuravl
authored andcommitted
[NFC][Comgr] Cleanup of AMDGPUCompiler::unbundle
1 parent 307113e commit 34271d1

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

amd/comgr/src/comgr-compiler.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
12471247
// Collect bitcode memory buffers from bitcodes, bundles, and archives
12481248
for (auto *Input : InSet->DataObjects) {
12491249

1250-
std::string FileExtension;
1250+
const char *FileExtension;
12511251
amd_comgr_data_kind_t UnbundledDataKind;
12521252
switch (Input->DataKind) {
12531253
case AMD_COMGR_DATA_KIND_BC_BUNDLE:
@@ -1278,36 +1278,33 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
12781278
const size_t BufSize = sizeof(char) * 30;
12791279
char *Buf = (char *)malloc(BufSize);
12801280
snprintf(Buf, BufSize, "comgr-bundle-%d.%s", std::rand() % 10000,
1281-
FileExtension.c_str());
1281+
FileExtension);
12821282
Input->Name = Buf;
12831283
}
12841284

12851285
// Write input file system so that OffloadBundler API can process
12861286
// TODO: Switch write to VFS
1287-
std::string InputFilePath = getFilePath(Input, InputDir).str().str();
1287+
SmallString<128> InputFilePath = getFilePath(Input, InputDir);
12881288
if (auto Status = outputToFile(Input, InputFilePath)) {
12891289
return Status;
12901290
}
12911291

12921292
// Bundler input name
1293-
BundlerConfig.InputFileNames.push_back(InputFilePath);
1293+
BundlerConfig.InputFileNames.emplace_back(InputFilePath);
12941294

12951295
// Generate prefix for output files
1296-
std::string OutputPrefix = std::string(Input->Name);
1296+
StringRef OutputPrefix = Input->Name;
12971297
size_t Index = OutputPrefix.find_last_of(".");
12981298
OutputPrefix = OutputPrefix.substr(0, Index);
12991299

13001300
// Bundler target and output names
1301-
for (auto Entry : ActionInfo->BundleEntryIDs) {
1302-
BundlerConfig.TargetNames.push_back(Entry);
1301+
for (StringRef Entry : ActionInfo->BundleEntryIDs) {
1302+
BundlerConfig.TargetNames.emplace_back(Entry);
13031303

1304-
// Add an output file for each target
1305-
std::string OutputFileName =
1306-
OutputPrefix + '-' + Entry + "." + FileExtension;
1307-
1308-
// TODO: Switch this to LLVM path APIs
1309-
std::string OutputFilePath = OutputDir.str().str() + "/" + OutputFileName;
1310-
BundlerConfig.OutputFileNames.push_back(OutputFilePath);
1304+
SmallString<128> OutputFilePath = OutputDir;
1305+
sys::path::append(OutputFilePath,
1306+
OutputPrefix + "-" + Entry + "." + FileExtension);
1307+
BundlerConfig.OutputFileNames.emplace_back(OutputFilePath);
13111308
}
13121309

13131310
OffloadBundler Bundler(BundlerConfig);
@@ -1318,8 +1315,10 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13181315
<< "\t Unbundled Files Extension: ." << FileExtension << "\n"
13191316
<< "\t Bundle Entry ID: " << BundlerConfig.TargetNames[0] << "\n"
13201317
<< "\t Input Filename: " << BundlerConfig.InputFileNames[0] << "\n"
1321-
<< "\t Output Filename: " << BundlerConfig.OutputFileNames[0]
1322-
<< "\n";
1318+
<< "\t Output Filenames: ";
1319+
for (StringRef OutputFileName : BundlerConfig.OutputFileNames)
1320+
LogS << OutputFileName << " ";
1321+
LogS << "\n";
13231322
LogS.flush();
13241323
}
13251324

@@ -1347,7 +1346,7 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13471346
}
13481347

13491348
// Add new bitcodes to OutSetT
1350-
for (auto OutputFilePath : BundlerConfig.OutputFileNames) {
1349+
for (StringRef OutputFilePath : BundlerConfig.OutputFileNames) {
13511350

13521351
amd_comgr_data_t ResultT;
13531352

@@ -1358,11 +1357,10 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13581357
ScopedDataObjectReleaser SDOR(ResultT);
13591358

13601359
DataObject *Result = DataObject::convert(ResultT);
1361-
if (auto Status = inputFromFile(Result, StringRef(OutputFilePath)))
1360+
if (auto Status = inputFromFile(Result, OutputFilePath))
13621361
return Status;
13631362

1364-
StringRef OutputFileName =
1365-
llvm::sys::path::filename(StringRef(OutputFilePath));
1363+
StringRef OutputFileName = sys::path::filename(OutputFilePath);
13661364
Result->setName(OutputFileName);
13671365

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

0 commit comments

Comments
 (0)