Skip to content

Commit

Permalink
[BOLT][NFC] Remove redundant dependent template type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aaupov committed Jan 14, 2022
1 parent c34adaa commit 29fe14c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
18 changes: 8 additions & 10 deletions bolt/include/bolt/Rewrite/RewriteInstance.h
Expand Up @@ -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 <typename ELFT,
typename ELFShdrTy = typename object::ELFObjectFile<ELFT>::Elf_Shdr>
std::vector<ELFShdrTy>
template <typename ELFT>
std::vector<typename object::ELFObjectFile<ELFT>::Elf_Shdr>
getOutputSections(object::ELFObjectFile<ELFT> *File,
std::vector<uint32_t> &NewSectionIndex);

Expand All @@ -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 <typename ELFT,
typename ELFShdrTy = typename object::ELFObjectFile<ELFT>::Elf_Shdr,
typename WriteFuncTy, typename StrTabFuncTy>
void updateELFSymbolTable(object::ELFObjectFile<ELFT> *File, bool IsDynSym,
const ELFShdrTy &SymTabSection,
const std::vector<uint32_t> &NewSectionIndex,
WriteFuncTy Write, StrTabFuncTy AddToStrTab);
template <typename ELFT, typename WriteFuncTy, typename StrTabFuncTy>
void updateELFSymbolTable(
object::ELFObjectFile<ELFT> *File, bool IsDynSym,
const typename object::ELFObjectFile<ELFT>::Elf_Shdr &SymTabSection,
const std::vector<uint32_t> &NewSectionIndex, WriteFuncTy Write,
StrTabFuncTy AddToStrTab);

/// Add a notes section containing the BOLT revision and command line options.
void addBoltInfoSection();
Expand Down
16 changes: 7 additions & 9 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Expand Up @@ -4019,10 +4019,11 @@ bool RewriteInstance::shouldStrip(const ELFShdrTy &Section,
return false;
}

template <typename ELFT, typename ELFShdrTy>
std::vector<ELFShdrTy>
template <typename ELFT>
std::vector<typename object::ELFObjectFile<ELFT>::Elf_Shdr>
RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
std::vector<uint32_t> &NewSectionIndex) {
using ELFShdrTy = typename ELFObjectFile<ELFT>::Elf_Shdr;
const ELFFile<ELFT> &Obj = File->getELFFile();
typename ELFT::ShdrRange Sections = cantFail(Obj.sections());

Expand Down Expand Up @@ -4255,14 +4256,11 @@ void RewriteInstance::patchELFSectionHeaderTable(ELFObjectFile<ELFT> *File) {
OS.pwrite(reinterpret_cast<const char *>(&NewEhdr), sizeof(NewEhdr), 0);
}

template <typename ELFT, typename ELFShdrTy, typename WriteFuncTy,
typename StrTabFuncTy>
template <typename ELFT, typename WriteFuncTy, typename StrTabFuncTy>
void RewriteInstance::updateELFSymbolTable(
ELFObjectFile<ELFT> *File,
bool IsDynSym,
const ELFShdrTy &SymTabSection,
const std::vector<uint32_t> &NewSectionIndex,
WriteFuncTy Write,
ELFObjectFile<ELFT> *File, bool IsDynSym,
const typename object::ELFObjectFile<ELFT>::Elf_Shdr &SymTabSection,
const std::vector<uint32_t> &NewSectionIndex, WriteFuncTy Write,
StrTabFuncTy AddToStrTab) {
const ELFFile<ELFT> &Obj = File->getELFFile();
using ELFSymTy = typename ELFObjectFile<ELFT>::Elf_Sym;
Expand Down

0 comments on commit 29fe14c

Please sign in to comment.