From 29fe14c78d044ef8f5ed5ae36a353b464ab787ec Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Fri, 14 Jan 2022 12:57:37 -0800 Subject: [PATCH] [BOLT][NFC] Remove redundant dependent template type Summary: Reduce code size by removing redundant dependent template type from RewriteInstance methods. Code size savings (via bloaty on llvm-bolt Debug build): ``` symbol,vmsize,filesize -> vmsize,filesize (delta vmsize,filesize) updateELFSymbolTable 57096,59600 -> 56656,59048 (440,552) updateELFSymbolTable::lambda 35957,55277 -> 35949,54485 (8,792) getOutputSections 20592,21440 -> 20372,21156 (220,284) getOutputSections::lambda 1792,5300 -> 1792,5372 (0,-72) total delta (668,1556) ``` Reviewed By: maksfb FBD33589393 --- bolt/include/bolt/Rewrite/RewriteInstance.h | 18 ++++++++---------- bolt/lib/Rewrite/RewriteInstance.cpp | 16 +++++++--------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h index 1073d78459ffd..047e33fca27c6 100644 --- a/bolt/include/bolt/Rewrite/RewriteInstance.h +++ b/bolt/include/bolt/Rewrite/RewriteInstance.h @@ -279,9 +279,8 @@ class RewriteInstance { /// Return a list of all sections to include in the output binary. /// Populate \p NewSectionIndex with a map of input to output indices. - template ::Elf_Shdr> - std::vector + template + std::vector::Elf_Shdr> getOutputSections(object::ELFObjectFile *File, std::vector &NewSectionIndex); @@ -293,13 +292,12 @@ class RewriteInstance { /// based on the input file symbol table passed in \p SymTabSection. /// \p IsDynSym is set to true for dynamic symbol table since we /// are updating it in-place with minimal modifications. - template ::Elf_Shdr, - typename WriteFuncTy, typename StrTabFuncTy> - void updateELFSymbolTable(object::ELFObjectFile *File, bool IsDynSym, - const ELFShdrTy &SymTabSection, - const std::vector &NewSectionIndex, - WriteFuncTy Write, StrTabFuncTy AddToStrTab); + template + void updateELFSymbolTable( + object::ELFObjectFile *File, bool IsDynSym, + const typename object::ELFObjectFile::Elf_Shdr &SymTabSection, + const std::vector &NewSectionIndex, WriteFuncTy Write, + StrTabFuncTy AddToStrTab); /// Add a notes section containing the BOLT revision and command line options. void addBoltInfoSection(); diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index dc75e2b51bdad..9dc7a9eac2480 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -4019,10 +4019,11 @@ bool RewriteInstance::shouldStrip(const ELFShdrTy &Section, return false; } -template -std::vector +template +std::vector::Elf_Shdr> RewriteInstance::getOutputSections(ELFObjectFile *File, std::vector &NewSectionIndex) { + using ELFShdrTy = typename ELFObjectFile::Elf_Shdr; const ELFFile &Obj = File->getELFFile(); typename ELFT::ShdrRange Sections = cantFail(Obj.sections()); @@ -4255,14 +4256,11 @@ void RewriteInstance::patchELFSectionHeaderTable(ELFObjectFile *File) { OS.pwrite(reinterpret_cast(&NewEhdr), sizeof(NewEhdr), 0); } -template +template void RewriteInstance::updateELFSymbolTable( - ELFObjectFile *File, - bool IsDynSym, - const ELFShdrTy &SymTabSection, - const std::vector &NewSectionIndex, - WriteFuncTy Write, + ELFObjectFile *File, bool IsDynSym, + const typename object::ELFObjectFile::Elf_Shdr &SymTabSection, + const std::vector &NewSectionIndex, WriteFuncTy Write, StrTabFuncTy AddToStrTab) { const ELFFile &Obj = File->getELFFile(); using ELFSymTy = typename ELFObjectFile::Elf_Sym;