[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 7 14:20:48 PDT 2022


rjmccall added inline comments.


================
Comment at: clang/lib/CodeGen/CodeGenModule.h:1482
+
+  struct KeepLazyEmiitedSymRAII {
+    std::unique_ptr<CodeGenModule> OldBuilder;
----------------
rjmccall wrote:
> junaire wrote:
> > rjmccall wrote:
> > > I think a RAII object is an odd way to express this API; there's not really a natural reason you would scope this.  It would be better to just have a method on `CodeGenModule` that steals the internal lazy-emission state from a different instance.
> > I don't have a better way to do this in mind, We need to restore the states after resetting the `Builder` right? So I guess RAII should be fine? Can you please provide some hints about how to do this more elegantly? Thx!
> I don't know what you mean.  You're not restoring any old state, you're moving state into the new CGM.  The whole thing is an imperative operation, it's just being done in a destructor for no particular reason.
> 
> ```
> std::unique_ptr<CodeGenModule> newBuilder(new CodeGenModule(...));
> Builder->moveLazyEmissionStateInto(newBuilder.get());
> Builder = newBuilder;
> ```
I liked all the assertions you had here.  It was good to validate that we weren't overwriting useful state in the new builder.


================
Comment at: clang/lib/CodeGen/ModuleBuilder.cpp:163
 
       for (auto &&Lib : CodeGenOpts.DependentLibraries)
         Builder->AddDependentLib(Lib);
----------------
junaire wrote:
> I left I may doing something wrong here, after invoking `Initialize` we set `Builder = std::move(NewBuilder);`, so these lines are useless now? I'm quite confused though... @rjmccall 
Ah, I see.  Probably the most reasonable thing would be to do something like this in `StartModule`:

```
  auto OldBuilder = std::move(Builder);
  Initialize(Ctx);
  if (OldBuilder) {
    OldBuilder->moveLazyEmissionStateInto(*Builder);
  }
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126781/new/

https://reviews.llvm.org/D126781



More information about the cfe-commits mailing list