diff options
author | Krzysztof Drewniak <Krzysztof.Drewniak@amd.com> | 2023-11-08 13:57:41 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-08 13:57:41 -0600 |
commit | 05fa923a9bbb657fc47f3c238c8f6b48f0a892a9 (patch) | |
tree | 19643e0a6775eade106bb842bd0cf9994b9da5eb | |
parent | 955dd8800b4745784bf6da948ec7992d5b75b4d7 (diff) |
Fix SmallVector usage in SerailzeToHsaco (#71702)
Enable merging #71439 by removing a definitely-wrong usage of
std::unique_ptr<SmallVectorImpl<char>> as a return value with passing in
a SmallVectorImpl<char>&
Also change the following function to take ArrayRef<char> instead of
const SmalVectorImpl<char>& .
-rw-r--r-- | mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp index 5c288e977ad0..f0c294c22695 100644 --- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp @@ -95,9 +95,9 @@ private: std::unique_ptr<std::vector<char>> serializeISA(const std::string &isa) override; - std::unique_ptr<SmallVectorImpl<char>> assembleIsa(const std::string &isa); - std::unique_ptr<std::vector<char>> - createHsaco(const SmallVectorImpl<char> &isaBinary); + LogicalResult assembleIsa(const std::string &isa, + SmallVectorImpl<char> &result); + std::unique_ptr<std::vector<char>> createHsaco(ArrayRef<char> isaBinary); std::string getRocmPath(); }; @@ -318,21 +318,18 @@ SerializeToHsacoPass::translateToLLVMIR(llvm::LLVMContext &llvmContext) { return ret; } -std::unique_ptr<SmallVectorImpl<char>> -SerializeToHsacoPass::assembleIsa(const std::string &isa) { +LogicalResult SerializeToHsacoPass::assembleIsa(const std::string &isa, + SmallVectorImpl<char> &result) { auto loc = getOperation().getLoc(); - SmallVector<char, 0> result; llvm::raw_svector_ostream os(result); llvm::Triple triple(llvm::Triple::normalize(this->triple)); std::string error; const llvm::Target *target = llvm::TargetRegistry::lookupTarget(triple.normalize(), error); - if (!target) { - emitError(loc, Twine("failed to lookup target: ") + error); - return {}; - } + if (!target) + return emitError(loc, Twine("failed to lookup target: ") + error); llvm::SourceMgr srcMgr; srcMgr.AddNewSourceBuffer(llvm::MemoryBuffer::getMemBuffer(isa), SMLoc()); @@ -373,19 +370,17 @@ SerializeToHsacoPass::assembleIsa(const std::string &isa) { std::unique_ptr<llvm::MCTargetAsmParser> tap( target->createMCAsmParser(*sti, *parser, *mcii, mcOptions)); - if (!tap) { - emitError(loc, "assembler initialization error"); - return {}; - } + if (!tap) + return emitError(loc, "assembler initialization error"); parser->setTargetParser(*tap); parser->Run(false); - return std::make_unique<SmallVector<char, 0>>(std::move(result)); + return success(); } std::unique_ptr<std::vector<char>> -SerializeToHsacoPass::createHsaco(const SmallVectorImpl<char> &isaBinary) { +SerializeToHsacoPass::createHsaco(ArrayRef<char> isaBinary) { auto loc = getOperation().getLoc(); // Save the ISA binary to a temp file. @@ -435,10 +430,10 @@ SerializeToHsacoPass::createHsaco(const SmallVectorImpl<char> &isaBinary) { std::unique_ptr<std::vector<char>> SerializeToHsacoPass::serializeISA(const std::string &isa) { - auto isaBinary = assembleIsa(isa); - if (!isaBinary) + SmallVector<char, 0> isaBinary; + if (failed(assembleIsa(isa, isaBinary))) return {}; - return createHsaco(*isaBinary); + return createHsaco(isaBinary); } // Register pass to serialize GPU kernel functions to a HSACO binary annotation. |