This is an archive of the discontinued LLVM Phabricator instance.

[MC] Store implicit ops immediately after the TargetInsts table. NFC.
ClosedPublic

Authored by foad on Jan 20 2023, 7:15 AM.

Details

Summary

This shrinks MCInstrDesc (and hence the whole TargetInsts table) because
we can store a 16-bit offset value to access the implicit operands,
instead of a pointer. This also reduces the number of relocs that need
to be applied when LLVM is compiled as position-independent code.

Diff Detail

Event Timeline

foad created this revision.Jan 20 2023, 7:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2023, 7:15 AM
foad requested review of this revision.Jan 20 2023, 7:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2023, 7:15 AM
arsenm added a subscriber: arsenm.Jan 20 2023, 7:46 AM
arsenm added inline comments.
llvm/include/llvm/MC/MCInstrDesc.h
579–580

This looks a bit undefined to me. Is ubsan and asan happy with this?

foad added inline comments.Jan 20 2023, 10:54 AM
llvm/include/llvm/MC/MCInstrDesc.h
579–580

Yes. I ran check-llvm with LLVM_USE_SANITIZER='Address;Undefined' and it is clean.

barannikov88 accepted this revision.Jan 23 2023, 1:49 PM
barannikov88 added a subscriber: barannikov88.

LGTM with a couple of nits.
This change is significant, I think you need more votes to proceed.

llvm/utils/TableGen/InstrInfoEmitter.cpp
910

Could Descs be a better name? So that you don't access it as Insts.Insts below.

949

Please make sure auto is qualified correctly if you prefer using it.
This auto & is really Record *&, while it should be const Record * (const non-reference).
Or just don't use it at all :) (as the coding style suggests).

This revision is now accepted and ready to land.Jan 23 2023, 1:49 PM
foad updated this revision to Diff 492038.Jan 25 2023, 2:16 AM

Rebase.

foad added inline comments.Feb 9 2023, 2:34 AM
llvm/utils/TableGen/InstrInfoEmitter.cpp
910

Maybe. It's actually e.g. AMDGPUInsts.Insts, but I guess your point still applies.

foad updated this revision to Diff 508083.Mar 24 2023, 7:18 AM

Rebase. Rename TargetInsts.Insts to TargetDescs.Insts.

foad marked an inline comment as done.Mar 24 2023, 7:18 AM
llvm/include/llvm/MC/MCInstrDesc.h
214

Could we give OpInfo the same treatment?

llvm/utils/TableGen/InstrInfoEmitter.cpp
1070

I'm dreaming of getting rid of these extern auxiliary tables. Perhaps we can start by packing all of these addresses in a struct that can serve as an interface class? We can then make them static and only export that struct. In the future, that structure will then be the only thing that needs to be relocated.
Hiding the current names would expose the current users.

llvm/utils/TableGen/InstrInfoEmitter.cpp
922

In some private table gen backend that also used these offset tables, we went away from the one raw out stream. Instead, there's an array abstraction that builds the body of the array in a stringstream and methods to generate the reference string (pointer to some element, or its index or offset) for e.g. the last added entry, or a given offset from a local base. It allows you to build all tables in one intuitive sweep, and then emit the accumulated bodies in some order to the output stream. If there's interest, I could probably share that table abstraction to add as common facility to tablegen.

foad added inline comments.Mar 27 2023, 2:10 AM
llvm/include/llvm/MC/MCInstrDesc.h
214

Yes! D142219!

llvm/utils/TableGen/InstrInfoEmitter.cpp
922

Sounds nice!

1070

Sounds reasonable. The only rogue user of TargetInsts/TargetDescs that I'm aware of is the ARM AsmParser that I had to update in this patch. There was some discussion about how to fix that in D142217 but I didn't have the ARM expertise to do it myself.

llvm/include/llvm/MC/MCInstrDesc.h
214

Ah, many small steps make a great leap.

llvm/utils/TableGen/InstrInfoEmitter.cpp
922

I'll start digging and removing the rust.

1070

Right. I don't grasp the details right away, but I think it is a perfect example of methods that could be added to the interface class, or in a local class derived from it.

This revision was landed with ongoing or failed builds.Mar 27 2023, 3:40 AM
This revision was automatically updated to reflect the committed changes.

@foad MSVC builds seem to be breaking due to this:
https://lab.llvm.org/buildbot/#/builders/86/builds/53509

LLVMARMAsmParser.lib(ARMAsmParser.cpp.obj) : error LNK2001: unresolved external symbol "class llvm::MCInstrDesc const * const llvm::ARMDescs" (?ARMDescs@llvm@@3QBVMCInstrDesc@1@B)
bin\llc.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
foad added a comment.Mar 27 2023, 5:34 AM

@foad MSVC builds seem to be breaking due to this:
https://lab.llvm.org/buildbot/#/builders/86/builds/53509

LLVMARMAsmParser.lib(ARMAsmParser.cpp.obj) : error LNK2001: unresolved external symbol "class llvm::MCInstrDesc const * const llvm::ARMDescs" (?ARMDescs@llvm@@3QBVMCInstrDesc@1@B)
bin\llc.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.

Thanks - I just noticed that too. I have a quick fix but can't push it now due to some partial github outage.

foad added a comment.Mar 27 2023, 6:30 AM

@foad MSVC builds seem to be breaking due to this:
https://lab.llvm.org/buildbot/#/builders/86/builds/53509

LLVMARMAsmParser.lib(ARMAsmParser.cpp.obj) : error LNK2001: unresolved external symbol "class llvm::MCInstrDesc const * const llvm::ARMDescs" (?ARMDescs@llvm@@3QBVMCInstrDesc@1@B)
bin\llc.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.

Thanks - I just noticed that too. I have a quick fix but can't push it now due to some partial github outage.

Pushed ffab44bd960c6392a0ed1f945cc145a2a2643c8c