This commits removes TableGens reliance on managed static global record state
by moving the RecordContext into the RecordKeeper. The RecordKeeper is now
treated similarly to a (LLVM|MLIR|etc)Context object and is passed to static
construction functions. This is an important step forward in removing TableGens
reliance on global state, and in a followup will allow for users that parse tablegen
to parse multiple tablegen files without worrying about Record lifetime.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Some context here is that I'm building language tooling for TableGen (diagnostics, go-to definition, find references, etc.) and I can't really do that effectively if TableGen relies on global record state.
llvm/include/llvm/TableGen/Record.h | ||
---|---|---|
328 | Most Inits inherit from TypedInit which has a RecTy. Is possible for the TypedInits to use the RecordKeeper from the the Type? Then only UnsetInit needs an explicit RecordKeeper? But I guess that means Init::getRecordKeeper would need to examine the Opc to determine where to find the RecordKeeper. | |
1816 | Why not make the whole Context a member of RecordKeeper? Why go through a pointer? |
llvm/include/llvm/TableGen/Record.h | ||
---|---|---|
328 | Agreed, it would be nice to use an approach like MLIR does with MLIRContext: since types have access to a MLIRContext, other things that are guaranteed to have types don't need to carry it around. Is this possible in tblgen? Ah it seems that init doesn't carry a type. :( |
llvm/include/llvm/TableGen/Record.h | ||
---|---|---|
328 | Given that all but one of the Inits are Typed, used the suggestion. I don't think it will be too bad in practice, and we can update if we ever add more inits. | |
1816 | Using pImpl helps to keep the uniquers implementation details out of the public header, and also helps to reduce the number of friends of RecordKeeper. If we move the uniquer data directly into RecordKeeper, as opposed to an external struct, we would need to add ~20 friends. Given all of that, feels much cleaner to just use pImpl here. |
llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp | ||
---|---|---|
45 | I know you didn't write, this but can the reinterpret_cast be a cast<>. reinterpret_cast looks suspicious. |
llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp | ||
---|---|---|
45 | Thanks for pointing this out! Fixed. |
Most Inits inherit from TypedInit which has a RecTy. Is possible for the TypedInits to use the RecordKeeper from the the Type? Then only UnsetInit needs an explicit RecordKeeper?
But I guess that means Init::getRecordKeeper would need to examine the Opc to determine where to find the RecordKeeper.