This is an archive of the discontinued LLVM Phabricator instance.

llvm-tblgen: Let each emitter self-contained
ClosedPublic

Authored by chapuni on Feb 19 2023, 7:01 AM.

Details

Summary

llvm-tblgen: Introduce llvm::TableGen::Emitter to register backends

Opt(flag, func, desc, default) registers an option into Action.

OptClass<EmitterC> is also available if EmitterC(RK).run(OS) is capable.

Action is defined as ManagedStatic<cl::opt> to guarantee to be created
when each registration of emitter is invoked.

FIXME: This may be move to llvm/include/llvm/TableGen/Main.h

llvm-tblgen: Cleanup for each EmitterClass to be invoked by uniform signature.

llvm-tblgen: Rewrite emitters to use TableGen::Emitter

Each emitter became self-contained since it has the registration of option.

Diff Detail

Event Timeline

chapuni created this revision.Feb 19 2023, 7:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 19 2023, 7:01 AM
chapuni requested review of this revision.Feb 19 2023, 7:01 AM
lkail added a subscriber: lkail.Feb 19 2023, 7:17 AM
craig.topper added inline comments.
llvm/utils/TableGen/AsmMatcherEmitter.cpp
4006–4007

I believe LLVM coding standards say to prefer static over anonymous namespaces. https://llvm.org/docs/CodingStandards.html#anonymous-namespaces. "make anonymous namespaces as small as possible, and only use them for class declarations."

chapuni added inline comments.
llvm/utils/TableGen/AsmMatcherEmitter.cpp
4006–4007

I have misunderstood usage of anonymous namespace. I will rework later.

I committed also c45e90cf152decb1a3dcd208273ca025e14f1b4f as a trivial change but I have noticed I did wrong thing. I will rework as well.

chapuni updated this revision to Diff 498828.Feb 20 2023, 6:31 AM
  • Avoid easy use of anonymous namespace
  • Move decl of EmitDecoder()to TableGenBackends.h
  • llvm::TableGen::Emitter::Opt(): Add 4th arg, isDefault
  • LLVMTableGenMain() assumes TableGen::Emitter::Action is not null.
  • Move decl of EmitDecoder()to TableGenBackends.h

maybe a dumb question: why?

llvm/utils/TableGen/TableGenBackends.h
80

nit: I believe function argument names should be camel case starting with upper case letter.

chapuni updated this revision to Diff 498949.Feb 20 2023, 1:46 PM
chapuni edited the summary of this revision. (Show Details)
  • Fixup namings
chapuni marked an inline comment as done.Feb 20 2023, 2:00 PM
  • Move decl of EmitDecoder()to TableGenBackends.h

maybe a dumb question: why?

DisassemblerEmitter.cpp declares it as ad-hoc decl extern. Since I touched around it, I have moved it to other header.
I have taken TableGenBackends.h since I thought excessive to introduce a new header like DecoderEmitter.h.

llvm/utils/TableGen/TableGenBackends.h
80

I have followed CommandLine.h.

myhsu added a comment.Feb 23 2023, 4:47 PM

I think this patch generally LGTM. But I would love to know if plugin support or third-party extension in general is part of your roadmap, if that's the case...

FIXME: This may be move to llvm/include/llvm/TableGen/Main.h

then yeah, moving it to public header might be a good idea.

then yeah, moving it to public header might be a good idea.

I'm afraid if it would affect other *-tblgen. It was in public in my prototype.
I'd be happy to move it to public step-by-step.

When we could implement tblgen plugin, I wonder;

  • If we took -load foo-pluigin.so, how it could be activated. I guess we should enhance TableGen::Emitter::Opt to activate myself. In my current implementation, TableGen::Emitter::Opt just registers an option.
  • Or, could we enforce users to name their plugin as libtblgen-foo-option.so?
chapuni updated this revision to Diff 506289.Mar 18 2023, 5:39 AM
  • Move llvm::TableGen::Emitter to llvm/TableGen/TableGenBackend.h
  • TableGen/BackGuide.rst: Modify using llvm::TableGen::Emitter`

@myhsu I have exposed llvm::TableGen::Emitter into llvm/TableGen/TableGenBackend.h.

myhsu accepted this revision.EditedMar 19 2023, 9:33 PM

LGTM Cheers

then yeah, moving it to public header might be a good idea.

I'm afraid if it would affect other *-tblgen. It was in public in my prototype.
I'd be happy to move it to public step-by-step.

When we could implement tblgen plugin, I wonder;

  • If we took -load foo-pluigin.so, how it could be activated. I guess we should enhance TableGen::Emitter::Opt to activate myself. In my current implementation, TableGen::Emitter::Opt just registers an option.

IMHO activation upon the plugin is loaded makes more sense, because unlike using opt with legacy PassManager, there won't be multiple TG actions in a single invocation.

This revision is now accepted and ready to land.Mar 19 2023, 9:33 PM