mlir: Avoid SmallVector::set_size in SerializeToHsacoPass::loadLibraries
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 12 Jan 2022 02:11:15 +0000 (18:11 -0800)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 13 Jan 2022 18:17:00 +0000 (10:17 -0800)
Spotted this in a final grep of projects I don't usually build before
pushing https://reviews.llvm.org/D115380, which makes
`SmallVector::set_size()` private.

Update to `truncate()`, a new-ish variant of `resize()` that asserts the
new size is not bigger and that avoids pulling in the allocation and
initialization code for growing. Doesn't really look like the perf
impact of that would matter here, but since `dirLength` is known to be a
smaller size then we might as well.

Differential Revision: https://reviews.llvm.org/D117073

mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp

index 8ffa83f..75d14d2 100644 (file)
@@ -160,7 +160,7 @@ SerializeToHsacoPass::loadLibraries(SmallVectorImpl<char> &path,
     llvm::StringRef pathRef(path.data(), path.size());
     std::unique_ptr<llvm::Module> library =
         llvm::getLazyIRFileModule(pathRef, error, context);
-    path.set_size(dirLength);
+    path.truncate(dirLength);
     if (!library) {
       getOperation().emitError() << "Failed to load library " << file
                                  << " from " << path << error.getMessage();