This is an archive of the discontinued LLVM Phabricator instance.

[X86][NFC] Move table from getRelaxedOpcodeArith into its own class
ClosedPublic

Authored by Amir on Mar 10 2022, 12:16 PM.

Details

Summary

Move out the table and prepare the code to reuse it for the reverse mapping.
Follows the example of memory folding/unfolding tables in X86InstrFoldTables.cpp

Preparation step to unify llvm::X86::getRelaxedOpcodeArith and
getShortArithOpcode in BOLT X86MCPlusBuilder.cpp.

Addresses https://lists.llvm.org/pipermail/llvm-dev/2022-January/154526.html

Diff Detail

Event Timeline

Amir created this revision.Mar 10 2022, 12:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2022, 12:16 PM
Amir published this revision for review.Mar 10 2022, 12:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2022, 12:38 PM
skan accepted this revision.Mar 11 2022, 7:06 PM

Thanks for making this change! LGTM!

This revision is now accepted and ready to land.Mar 11 2022, 7:06 PM
MaskRay added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.cpp
127

SmallVector<X, 0> usually compiles to less code and is more efficient

133

Drop the comment. The code is self-explanatory

134

You may just use llvm::sort which calls array_pod_sort if applicable

137

is_sorted

169
if (const X86InstrRelaxTableEntry *I = lookupRelaxTable(ShortOp))
  return I->DstOp;
return ShortOp;
Amir updated this revision to Diff 414806.Mar 11 2022, 10:02 PM

Address feedback; rebase

Amir marked 5 inline comments as done.

@skan, @MaskRay

Thank you for a review!

MaskRay accepted this revision.Mar 11 2022, 10:05 PM
MaskRay added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.cpp
133

llvm::sort(Table)

136

llvm::is_sorted if an LLVM STLExtras util may conflict with std:: of the same name

craig.topper added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.cpp
17

Don't vector since you switched to SmallVector

133

Does sort(Table) work?

craig.topper added inline comments.Mar 11 2022, 10:10 PM
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.h
22

They -> The

craig.topper added inline comments.Mar 11 2022, 10:13 PM
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.cpp
139

Does this method provide much value versus calling push_back directly in the loop?

Amir updated this revision to Diff 414807.Mar 11 2022, 10:13 PM

llvm:: namespace

Amir updated this revision to Diff 414810.Mar 11 2022, 10:32 PM

Address feedback

Amir marked 6 inline comments as done.
craig.topper added inline comments.Mar 11 2022, 10:35 PM
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.h
39

Does this need an extra slash to be a valid doxygen comment?

42

Same

skan added inline comments.Mar 11 2022, 10:41 PM
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.cpp
135

Where did you check the unique after the change??

139

https://llvm.org/doxygen/classllvm_1_1ManagedStatic.html I think the ShortTable is seldom used, AFAIK, it is used only bolt. So we avoid the construction at most of the time.

craig.topper added inline comments.Mar 11 2022, 10:42 PM
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.cpp
139

That comment was directed at the AddTableEntry method from previous patch.

MaskRay added inline comments.Mar 11 2022, 10:44 PM
llvm/lib/Target/X86/MCTargetDesc/X86InstrRelaxTables.cpp
133

llvm::sort is preferred to avoid pitfalls related to argument-dependent lookup, since std::sort exists.

135

oh, should use adjacent_find. My bad

skan added a comment.Mar 11 2022, 10:47 PM

Oh, I was in the wrong channel..

Amir updated this revision to Diff 414812.Mar 11 2022, 10:55 PM

Address feedback

Amir marked 7 inline comments as done.Mar 11 2022, 10:56 PM
This revision was landed with ongoing or failed builds.Mar 12 2022, 9:06 AM
This revision was automatically updated to reflect the committed changes.