shchenz added a comment.

Thanks for doing this. I am not familiar with the frontend, so I may be 
wrong/stupid in the follow comments : )
Hope other experts like @hubert.reinterpretcast can give more meaningful 
comments.

I tested on AIX, seems for static variable `static int x = foo();` in global 
scope, even compile with `-bcdtors:csect`, the init function also will not be 
eliminated. Could you please give an example to show why we need the new 
associated metadata for this case? Thanks.

And we may need to update the docs for `associated` metadata too in 
`docs/LangRef.rst`



================
Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:542
+  if (getTriple().isOSAIX())
+    VFInitTermAssoc.push_back(std::make_pair(D, Fn));
+
----------------
Should we use `addVarTermAssoc`?


================
Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:688
+        updateAssociatedFunc(VFInitTermAssoc, LocalCXXGlobalInits, GetElem, 
Fn);
+        updateAssociatedFunc(FFDtorTermAssoc, LocalCXXGlobalInits, GetElem, 
Fn);
+      }
----------------
`FFDtorTermAssoc` should store the mapping between dtor and term functions? So 
why we need to update this container when we generate wrapper function for init 
function? I think in the init function there should only be ctors related 
functions?

And why we don't need to update for `VarsWithInitTerm`, in that container there 
should be some static variables reply on the wrapper init function?


================
Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4799
+    if (getTriple().isOSAIX())
+      addVarWithInitTerm(D, GV);
+  }
----------------
Why do we need to add mapping between a variable and its address? We already 
map the global and its init function in above `EmitCXXGlobalVarDeclInitFunc`?


================
Comment at: clang/lib/CodeGen/CodeGenModule.h:465
+  /// between dtor and term functions.
+  llvm::SmallVector<std::pair<const Decl *, llvm::Constant *>, 8>
+      VFInitTermAssoc;
----------------
Is there any reason why we need `vector` here instead of `map`? Can you give an 
example that shows one global variable will be connected with more than one 
init functions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125095

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to