@@ -95,9 +95,9 @@ class SerializeToHsacoPass
95
95
std::unique_ptr<std::vector<char >>
96
96
serializeISA (const std::string &isa) override ;
97
97
98
- std::unique_ptr<SmallVectorImpl< char >> assembleIsa (const std::string &isa);
99
- std::unique_ptr<std::vector< char >>
100
- createHsaco (const SmallVectorImpl <char > & isaBinary);
98
+ LogicalResult assembleIsa (const std::string &isa,
99
+ SmallVectorImpl< char > &result);
100
+ std::unique_ptr<std::vector< char >> createHsaco (ArrayRef <char > isaBinary);
101
101
102
102
std::string getRocmPath ();
103
103
};
@@ -318,21 +318,18 @@ SerializeToHsacoPass::translateToLLVMIR(llvm::LLVMContext &llvmContext) {
318
318
return ret;
319
319
}
320
320
321
- std::unique_ptr<SmallVectorImpl< char >>
322
- SerializeToHsacoPass::assembleIsa ( const std::string &isa ) {
321
+ LogicalResult SerializeToHsacoPass::assembleIsa ( const std::string &isa,
322
+ SmallVectorImpl< char > &result ) {
323
323
auto loc = getOperation ().getLoc ();
324
324
325
- SmallVector<char , 0 > result;
326
325
llvm::raw_svector_ostream os (result);
327
326
328
327
llvm::Triple triple (llvm::Triple::normalize (this ->triple ));
329
328
std::string error;
330
329
const llvm::Target *target =
331
330
llvm::TargetRegistry::lookupTarget (triple.normalize (), error);
332
- if (!target) {
333
- emitError (loc, Twine (" failed to lookup target: " ) + error);
334
- return {};
335
- }
331
+ if (!target)
332
+ return emitError (loc, Twine (" failed to lookup target: " ) + error);
336
333
337
334
llvm::SourceMgr srcMgr;
338
335
srcMgr.AddNewSourceBuffer (llvm::MemoryBuffer::getMemBuffer (isa), SMLoc ());
@@ -373,19 +370,17 @@ SerializeToHsacoPass::assembleIsa(const std::string &isa) {
373
370
std::unique_ptr<llvm::MCTargetAsmParser> tap (
374
371
target->createMCAsmParser (*sti, *parser, *mcii, mcOptions));
375
372
376
- if (!tap) {
377
- emitError (loc, " assembler initialization error" );
378
- return {};
379
- }
373
+ if (!tap)
374
+ return emitError (loc, " assembler initialization error" );
380
375
381
376
parser->setTargetParser (*tap);
382
377
parser->Run (false );
383
378
384
- return std::make_unique<SmallVector< char , 0 >>( std::move (result) );
379
+ return success ( );
385
380
}
386
381
387
382
std::unique_ptr<std::vector<char >>
388
- SerializeToHsacoPass::createHsaco (const SmallVectorImpl <char > & isaBinary) {
383
+ SerializeToHsacoPass::createHsaco (ArrayRef <char > isaBinary) {
389
384
auto loc = getOperation ().getLoc ();
390
385
391
386
// Save the ISA binary to a temp file.
@@ -435,10 +430,10 @@ SerializeToHsacoPass::createHsaco(const SmallVectorImpl<char> &isaBinary) {
435
430
436
431
std::unique_ptr<std::vector<char >>
437
432
SerializeToHsacoPass::serializeISA (const std::string &isa) {
438
- auto isaBinary = assembleIsa (isa) ;
439
- if (! isaBinary)
433
+ SmallVector< char , 0 > isaBinary ;
434
+ if (failed ( assembleIsa (isa, isaBinary)) )
440
435
return {};
441
- return createHsaco (* isaBinary);
436
+ return createHsaco (isaBinary);
442
437
}
443
438
444
439
// Register pass to serialize GPU kernel functions to a HSACO binary annotation.
0 commit comments