<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Hi Eric,</div><div><br class="webkit-block-placeholder"></div><div>On Sep 21, 2007, at 04:49, Eric Christopher wrote:</div><div><br class="webkit-block-placeholder"></div><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Here are a pair of patches to add an attribute to automatically gcroot things based on type. It currently works for pointers to structures only because a) that's all I need, and b) I think that's all that makes sense really. I could remove the restriction if someone can come up with a good use case for other types.</div></blockquote><div><br class="webkit-block-placeholder"></div><div>Very cool.</div><div><br></div><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Note that we're also zeroing out automatic variables as well so if we do a collection before they're initialized we don't end up following garbage.</div></blockquote><div><div><br class="webkit-block-placeholder"></div><div><div>@@ -1581,6 +1605,17 @@ void TreeToLLVM::EmitAutomaticVariableDe</div><div>   // Handle annotate attributes</div><div>   if (DECL_ATTRIBUTES(decl))</div><div>     EmitAnnotateIntrinsic(AI, decl);</div><div>+</div><div>+  // Handle gcroot attribute</div><div>+  if (POINTER_TYPE_P(TREE_TYPE (decl))</div><div>+      && TYPE_GCROOT(TREE_TYPE (decl)))</div><div>+    {</div><div>+      // We should null out local variables so that a stack crawl</div><div>+      // before initialization doesn't get garbage results to follow.</div><div>+      const Type *T = cast<PointerType>(AI->getType())->getElementType();</div><div>+      EmitTypeGcroot(AI, decl);</div><div>+      Builder.CreateStore(Constant::getNullValue(T), AI);</div><div>+    }</div><div>   </div><div>   if (TheDebugInfo) {</div><div>     if (DECL_NAME(decl)) {</div></div><div><br class="webkit-block-placeholder"></div><div>This is redundant; LLVM does it for you. See thread starting here:</div><div><br class="webkit-block-placeholder"></div><div>  <a href="http://www.mail-archive.com/llvm-commits@cs.uiuc.edu/msg23987.html">http://www.mail-archive.com/llvm-commits@cs.uiuc.edu/msg23987.html</a></div><div><br class="webkit-block-placeholder"></div><div>The upshot is that the collector knows whether it is necessary to initialize roots or not, and does so on the program's behalf iff necessary.</div><div><br class="webkit-block-placeholder"></div><div>However, if the source language requires null initialization semantics, then the front-end should emit explicit null initializers (as the variable comes into scope).</div></div></div><div><br></div><div><br></div><div>+// Emits code to do something for a type attribute</div><div><div>+void TreeToLLVM::EmitTypeGcroot(Value *V, tree decl) {</div><div>+</div><div>+  Function *gcrootFun = Intrinsic::getDeclaration(TheModule,</div><div>+<span class="Apple-tab-span" style="white-space:pre">                                              </span>  Intrinsic::gcroot);</div><div>+  </div><div>+  // The idea is that it's a pointer to type "Value"</div><div>+  // which is opaque* but the routine expects i8** and i8*.</div><div>+  const PointerType *Ty = PointerType::get(Type::Int8Ty);</div><div>+  V = Builder.CreateBitCast(V, PointerType::get(Ty), "tmp");</div><div><br></div></div><div><div>The llvm.gcroot intrinsic can be declared to take any types you care to give it in the module, so long as its eventual type is like void(<ty>**, <ty2>*).</div><div><br class="webkit-block-placeholder"></div><div>But since you don't have a parent type to use, what you've done probably makes as much sense as anything.</div><div><br></div></div><div><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; ">— Gordon<br class="Apple-interchange-newline"></span></span></span></span></span></span> </div><br></body></html>