Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegenv2: improve multi argument generation #395

Closed

Conversation

JakeHillion
Copy link
Contributor

@JakeHillion JakeHillion commented Oct 27, 2023

Summary

Adds a new function CodeGen::codegenFromDrgns which runs multiple drgn root types through one DrgnParser. Stores the naming for the output within this function as we previously decided that when doing the actual codegen, which is too late with multiple root types.

This new function is used in OIGenerator when you have multiple OIL calls within one input object. Rather than producing separate .os with likely duplicate code for each callsite, we produce a single .o that contains both calls. For calls with types with significant overlap this should be a significant reduction in work. The downside is the calls can't have different features, but this could be solved in the future by namespacing the code based on features/config within the generated .cpp - the pros seem to outweigh the con.

This should also be used with oid in multi probe mode as it would again significantly reduce the work it has to do. I didn't do this yet as it requires changing the cache. As I've got a big cache refactor ongoing at the minute it makes sense to wait until after that's landed to make this change.

Test plan

  • CI for existing behaviour
  • D50835153 for new behaviour

@JakeHillion JakeHillion force-pushed the no-root-type branch 3 times, most recently from d84b626 to df5fd58 Compare October 30, 2023 14:58
@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2023

Codecov Report

Merging #395 (a49f0e7) into main (6e1635c) will increase coverage by 0.05%.
The diff coverage is 75.53%.

@@            Coverage Diff             @@
##             main     #395      +/-   ##
==========================================
+ Coverage   68.80%   68.86%   +0.05%     
==========================================
  Files         116      116              
  Lines       11420    11458      +38     
  Branches     1899     1903       +4     
==========================================
+ Hits         7857     7890      +33     
- Misses       2587     2590       +3     
- Partials      976      978       +2     
Files Coverage Δ
oi/OICodeGen.cpp 67.10% <100.00%> (ø)
oi/type_graph/DrgnParser.h 77.77% <ø> (ø)
oi/CodeGen.h 80.00% <50.00%> (-20.00%) ⬇️
oi/CodeGen.cpp 72.11% <84.37%> (+0.97%) ⬆️
oi/FuncGen.cpp 79.70% <53.84%> (-0.71%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@facebook-github-bot
Copy link

@JakeHillion has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link

@JakeHillion has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

JakeHillion added a commit to JakeHillion/object-introspection that referenced this pull request Oct 31, 2023
Summary:
Adds a new function `CodeGen::codegenFromDrgns` which runs multiple drgn root types through one `DrgnParser`. Stores the naming for the output within this function as we previously decided that when doing the actual codegen, which is too late with multiple root types.

This new function is used in `OIGenerator` when you have multiple OIL calls within one input object. Rather than producing separate `.o`s with likely duplicate code for each callsite, we produce a single `.o` that contains both calls. For calls with types with significant overlap this should be a significant reduction in work. The downside is the calls can't have different features, but this could be solved in the future by namespacing the code based on features/config within the generated `.cpp` - the pros seem to outweigh the con.

This should also be used with `oid` in multi probe mode as it would again significantly reduce the work it has to do. I didn't do this yet as it requires changing the cache. As I've got a big refactor cache ongoing at the minute it makes sense to wait until after that's landed to make this change.


Test Plan: Generally tested with GitHub CI. Tested the new multi call OILGen with the new example seen below. Outputs the following code with two root calls: P869569859 - note that `VectorOfStrings_0` is the only instance, whereas previously we'd have generated it in two files.

Differential Revision: D50835153

Pulled By: JakeHillion
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D50835153

@JakeHillion JakeHillion requested a review from ajor October 31, 2023 17:05
@JakeHillion JakeHillion marked this pull request as ready for review October 31, 2023 17:05
Summary:
Adds a new function `CodeGen::codegenFromDrgns` which runs multiple drgn root types through one `DrgnParser`. Stores the naming for the output within this function as we previously decided that when doing the actual codegen, which is too late with multiple root types.

This new function is used in `OIGenerator` when you have multiple OIL calls within one input object. Rather than producing separate `.o`s with likely duplicate code for each callsite, we produce a single `.o` that contains both calls. For calls with types with significant overlap this should be a significant reduction in work. The downside is the calls can't have different features, but this could be solved in the future by namespacing the code based on features/config within the generated `.cpp` - the pros seem to outweigh the con.

This should also be used with `oid` in multi probe mode as it would again significantly reduce the work it has to do. I didn't do this yet as it requires changing the cache. As I've got a big refactor cache ongoing at the minute it makes sense to wait until after that's landed to make this change.


Test Plan: Generally tested with GitHub CI. Tested the new multi call OILGen with the new example seen below. Outputs the following code with two root calls: P869569859 - note that `VectorOfStrings_0` is the only instance, whereas previously we'd have generated it in two files.

Differential Revision: D50835153

Pulled By: JakeHillion
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D50835153

@JakeHillion JakeHillion marked this pull request as draft December 5, 2023 16:42
@JakeHillion
Copy link
Contributor Author

The rebase on this is horrific - putting it on hold for now. Might wait until #421 lands as this was mostly for OILGen anyway then redo it.

@JakeHillion
Copy link
Contributor Author

Going to drop this for now. The rebase was bad enough that I'll rewrite it at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants