Skip to content

Commit 0aedf8d

Browse files
jmmartinezDavid Salinas
authored andcommitted
[NFC][Comgr] Cleanup of AMDGPUCompiler::unbundle
1 parent 06600ac commit 0aedf8d

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
@@ -1229,7 +1229,7 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
12291229
// Collect bitcode memory buffers from bitcodes, bundles, and archives
12301230
for (auto *Input : InSet->DataObjects) {
12311231

1232-
std::string FileExtension;
1232+
const char *FileExtension;
12331233
amd_comgr_data_kind_t UnbundledDataKind;
12341234
switch (Input->DataKind) {
12351235
case AMD_COMGR_DATA_KIND_BC_BUNDLE:
@@ -1260,36 +1260,33 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
12601260
const size_t BufSize = sizeof(char) * 30;
12611261
char *Buf = (char *)malloc(BufSize);
12621262
snprintf(Buf, BufSize, "comgr-bundle-%d.%s", std::rand() % 10000,
1263-
FileExtension.c_str());
1263+
FileExtension);
12641264
Input->Name = Buf;
12651265
}
12661266

12671267
// Write input file system so that OffloadBundler API can process
12681268
// TODO: Switch write to VFS
1269-
std::string InputFilePath = getFilePath(Input, InputDir).str().str();
1269+
SmallString<128> InputFilePath = getFilePath(Input, InputDir);
12701270
if (auto Status = outputToFile(Input, InputFilePath)) {
12711271
return Status;
12721272
}
12731273

12741274
// Bundler input name
1275-
BundlerConfig.InputFileNames.push_back(InputFilePath);
1275+
BundlerConfig.InputFileNames.emplace_back(InputFilePath);
12761276

12771277
// Generate prefix for output files
1278-
std::string OutputPrefix = std::string(Input->Name);
1278+
StringRef OutputPrefix = Input->Name;
12791279
size_t Index = OutputPrefix.find_last_of(".");
12801280
OutputPrefix = OutputPrefix.substr(0, Index);
12811281

12821282
// Bundler target and output names
1283-
for (auto Entry : ActionInfo->BundleEntryIDs) {
1284-
BundlerConfig.TargetNames.push_back(Entry);
1283+
for (StringRef Entry : ActionInfo->BundleEntryIDs) {
1284+
BundlerConfig.TargetNames.emplace_back(Entry);
12851285

1286-
// Add an output file for each target
1287-
std::string OutputFileName =
1288-
OutputPrefix + '-' + Entry + "." + FileExtension;
1289-
1290-
// TODO: Switch this to LLVM path APIs
1291-
std::string OutputFilePath = OutputDir.str().str() + "/" + OutputFileName;
1292-
BundlerConfig.OutputFileNames.push_back(OutputFilePath);
1286+
SmallString<128> OutputFilePath = OutputDir;
1287+
sys::path::append(OutputFilePath,
1288+
OutputPrefix + "-" + Entry + "." + FileExtension);
1289+
BundlerConfig.OutputFileNames.emplace_back(OutputFilePath);
12931290
}
12941291

12951292
OffloadBundler Bundler(BundlerConfig);
@@ -1300,8 +1297,10 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13001297
<< "\t Unbundled Files Extension: ." << FileExtension << "\n"
13011298
<< "\t Bundle Entry ID: " << BundlerConfig.TargetNames[0] << "\n"
13021299
<< "\t Input Filename: " << BundlerConfig.InputFileNames[0] << "\n"
1303-
<< "\t Output Filename: " << BundlerConfig.OutputFileNames[0]
1304-
<< "\n";
1300+
<< "\t Output Filenames: ";
1301+
for (StringRef OutputFileName : BundlerConfig.OutputFileNames)
1302+
LogS << OutputFileName << " ";
1303+
LogS << "\n";
13051304
LogS.flush();
13061305
}
13071306

@@ -1329,7 +1328,7 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13291328
}
13301329

13311330
// Add new bitcodes to OutSetT
1332-
for (auto OutputFilePath : BundlerConfig.OutputFileNames) {
1331+
for (StringRef OutputFilePath : BundlerConfig.OutputFileNames) {
13331332

13341333
amd_comgr_data_t ResultT;
13351334

@@ -1340,11 +1339,10 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
13401339
ScopedDataObjectReleaser SDOR(ResultT);
13411340

13421341
DataObject *Result = DataObject::convert(ResultT);
1343-
if (auto Status = inputFromFile(Result, StringRef(OutputFilePath)))
1342+
if (auto Status = inputFromFile(Result, OutputFilePath))
13441343
return Status;
13451344

1346-
StringRef OutputFileName =
1347-
llvm::sys::path::filename(StringRef(OutputFilePath));
1345+
StringRef OutputFileName = sys::path::filename(OutputFilePath);
13481346
Result->setName(OutputFileName);
13491347

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

0 commit comments

Comments
 (0)