<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Mehdi,<div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">What about keeping track of “visited” global in a side structure (hash map…) and skip these?</div><div class=""><br class=""></div><div class="">Note also that only GlobalValue can create cycles, so you’d need only to track these, not all constant.</div></blockquote><div class=""><br class=""></div>Thanks for the proposition, I will try that.</div><div class=""><br class=""></div><div class="">Greetings,</div><div class=""><br class=""></div><div class="">Johan<br class="">
<br class=""><div><blockquote type="cite" class=""><div class="">On 28 Sep 2016, at 18:50, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Sep 28, 2016, at 9:35 AM, Johan Wehrli via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi,<div class=""><br class=""></div><div class="">I have implemented a recursive loop to go through all the user of a global variable but I have one issue left.</div><div class=""><br class=""></div><div class="">Depending the code, the global variable is using itself: </div><div class=""><br class=""></div><div class=""><i class="">@sSelectedAccount = internal constant %struct.KVObserver { %0* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_.744 to %0*), i8* bitcast (%struct.KVObserver* @sSelectedAccount to i8*), i32 3 }, align 4</i></div><div class=""><br class=""></div><div class="">With the IR code above, I am stuck in an infinite loop:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">       </span>1) The global<span class="Apple-converted-space"> </span><i class="">sSelectedAccount</i><span class="Apple-converted-space"> </span>has the following user: "<i class="">i8* bitcast (%struct.KVObserver* @sSelectedAccount to i8*)</i>"</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">   </span>2) The bit cast has the following user: "<i class="">%struct.KVObserver { %"type 0x7ff164027360"* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_.744 to %"type 0x7ff164027360"*), i8* bitcast (%struct.KVObserver* @sSelectedAccount to i8*), i32 3 }</i>"</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">    </span>3) The previous has the user<span class="Apple-converted-space"> </span><i class="">sSelectedAccount</i><span class="Apple-converted-space"> </span>-> so this create the infinite loop.</div><div class=""><br class=""></div><div class="">I was looking for a way to detect the loop and I think there is two possibilities:</div><div class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>- from the global value, iterate through all the element and find the loop, but this need a lot of cast and another recursive loop (need to handle ConstantStruct, ConstantExpr, ConstantArray, etc.) Does anyone know if there is an easier way to do this?</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">    </span>-during the recursive loop, can I find the “main” global value? e.g: when I am on "<i class="">i8* bitcast (%struct.KVObserver* @sSelectedAccount to i8*)</i>”, how can I get the global variable <i class="">sSelectedAccount<span class="Apple-converted-space"> </span></i>?</div></div></div></blockquote><div class=""><br class=""></div></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">What about keeping track of “visited” global in a side structure (hash map…) and skip these?</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Note also that only GlobalValue can create cycles, so you’d need only to track these, not all constant.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">— </div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Mehdi</div></div></blockquote></div><br class=""></div></body></html>