This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - refactor of SymbolBody::compare()
ClosedPublic

Authored by grimar on Mar 9 2016, 11:12 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 50163.Mar 9 2016, 11:12 AM
grimar retitled this revision from to [ELF] - refactor of SymbolBody::compare() .
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
grimar added inline comments.
ELF/Symbols.cpp
119 ↗(On Diff #50163)

btw we anyways don't need that as ThisC->MaxAlignment/OtherC->MaxAlignment are of a type uint64

124 ↗(On Diff #50163)

btw, I think it requires a new name. It does not just compares bodies, but also set flags, so do not what its name says.
I dont have good suggestions about name, may be resolveBody ?

149 ↗(On Diff #50163)

And I think direct names are more readable than std::get<>

ruiu added inline comments.Mar 9 2016, 1:03 PM
ELF/Symbols.cpp
115 ↗(On Diff #50163)
DeifnedCommon* A, DefiendCommon* B

->

DeifnedCommon *A, DefiendCommon *B
117 ↗(On Diff #50163)

I understand the intention but this seems a bit tricky. It only saves one line, so I wouldn't use a recursion.

if (A->Size < B->Size) {
  B->MaxAlignment = std::max(A->MaxAlignment, B->MaxAlignment);
  return -1;
}
124 ↗(On Diff #50163)

Well, I don't have an idea of good name right now. It is indeed a bit weird that the function compare has a side effect, but I'd leave it alone for now.

149 ↗(On Diff #50163)

Agreed.

grimar updated this revision to Diff 50249.Mar 10 2016, 2:02 AM

Addressed Rui's review comments.

ELF/Symbols.cpp
115 ↗(On Diff #50163)

Done.

117 ↗(On Diff #50163)

Done.

grimar added inline comments.Mar 10 2016, 2:04 AM
ELF/Symbols.cpp
159 ↗(On Diff #50249)

Actually I don't like that part of code. There is to much attention to commons. But I dont have ideas how to improve that. Also in my opinion it is still better than was before.

rafael added inline comments.Mar 10 2016, 8:46 AM
ELF/Symbols.cpp
117 ↗(On Diff #50249)

I think you can just say

A->MaxAlingment = B->MaxAlignment = std::max(A->MaxAlignment, B->MaxAlignment);

before the if.

grimar added inline comments.Mar 10 2016, 9:00 AM
ELF/Symbols.cpp
117 ↗(On Diff #50249)

Sounds good for me.

ruiu accepted this revision.Mar 10 2016, 9:35 AM
ruiu edited edge metadata.

LGTM

ELF/Symbols.cpp
117 ↗(On Diff #50249)

Not directly related (so please don't do that in this patch), but I'd rename MaxAlignment to Align. (We can argue of the maximum alignment for a group of symbols, but for each symbol, there is only one alignment.)

This revision is now accepted and ready to land.Mar 10 2016, 9:35 AM
This revision was automatically updated to reflect the committed changes.