It might well be a bug in my code, I'm pretty sure it clones unecessary units so part of the fault is mine for sure. My point is more a general thought about such workarounds.<br><br clear="all">Amaury Pouly<br>
<br><br><div class="gmail_quote">2010/8/8 Eugene Toder <span dir="ltr"><<a href="mailto:eltoder@gmail.com">eltoder@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Right, later in the same file we have:<br>
<br>
// Reserve entries in the vector for each of the SUnits we are creating. This<br>
// ensure that reallocation of the vector won't happen, so SUnit*'s won't get<br>
// invalidated.<br>
// FIXME: Multiply by 2 because we may clone nodes during scheduling.<br>
// This is a temporary workaround.<br>
SUnits.reserve(NumNodes * 2);<br>
<br>
So for some reason *2 is not enough in your case. I guess the right<br>
thing here is to either have a way to reliably estimate the number of<br>
SUnits (if it's at all possible) or use a container that doesn't<br>
reallocate on insert.<br>
<font color="#888888"><br>
Eugene<br>
</font><div><div></div><div class="h5"><br>
On Sun, Aug 8, 2010 at 3:11 PM, Amaury Pouly <<a href="mailto:amaury.pouly@gmail.com">amaury.pouly@gmail.com</a>> wrote:<br>
> Oh yes you're right, I missed that :) But the point still hold.<br>
><br>
> Amaury Pouly<br>
><br>
><br>
> 2010/8/8 Eugene Toder <<a href="mailto:eltoder@gmail.com">eltoder@gmail.com</a>><br>
>><br>
>> > Not only this code does not compile with NDEBUG set<br>
>><br>
>> I may be missing something, but why does it not compile with -DNDEBUG?<br>
>> assert() macro expands to noop when NDEBUG is set.<br>
>><br>
>> Eugene<br>
>><br>
>> On Sun, Aug 8, 2010 at 2:19 PM, Amaury Pouly <<a href="mailto:amaury.pouly@gmail.com">amaury.pouly@gmail.com</a>><br>
>> wrote:<br>
>> > Hello,<br>
>> > I was trying to interface a custom backend instruction scheduler with<br>
>> > llvm<br>
>> > code when I realize something terrible. The scheduling code builds a<br>
>> > graph<br>
>> > made up of SUnit * nodes (see ScheduleDAG*.{cpp,h}). These SUnits nodes<br>
>> > are<br>
>> > allocated via a std::vector< SUnit >.<br>
>> > This isn't a problem as long as the pointers are taken after the vector<br>
>> > is<br>
>> > fully filled and the vector never changes its size. But the problem is<br>
>> > that<br>
>> > is can happen !<br>
>> > Indeed, in some rare cases, the scheduler needs to duplicate a SUnit and<br>
>> > thus allocate a new one. This gives code this:<br>
>> ><br>
>> > ScheduleDAGSNodes.cpp:<br>
>> ><br>
>> > #ifndef NDEBUG<br>
>> > const SUnit *Addr = 0;<br>
>> > if (!SUnits.empty())<br>
>> > Addr = &SUnits[0];<br>
>> > #endif<br>
>> > SUnits.push_back(SUnit(N, (unsigned)SUnits.size()));<br>
>> > assert((Addr == 0 || Addr == &SUnits[0]) &&<br>
>> ><br>
>> > Not only this code does not compile with NDEBUG set but it could trigger<br>
>> > an<br>
>> > extermely reliable assertion failure in some cases. One could think that<br>
>> > this is too rare to happen but it does happen with my scheduler and I'm<br>
>> > not<br>
>> > quite embarassed because I can't do anything apart from hacking llvm<br>
>> > source<br>
>> > code. I feel that triggering an assertion failure just because the user<br>
>> > made<br>
>> > the mistake of having not luck is not great for such a big framework as<br>
>> > LLVM<br>
>> > :)<br>
>> ><br>
>> > Shouldn't LLVM use a custom vector implementation for such cases, an<br>
>> > implementation that does not invalidate pointers when growing ?<br>
>> > I have such an implementation at hand that I'm willing to provide if<br>
>> > needed.<br>
>> ><br>
>> > Regards<br>
>> ><br>
>> ><br>
>> > Amaury Pouly<br>
>> ><br>
>> > _______________________________________________<br>
>> > LLVM Developers mailing list<br>
>> > <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>