<div dir="ltr"><div><div><div>Hi everyone,</div><div><br></div><div>I want to track the def-use chain for atomic variables. </div><div>However, it seems that LLVM will not generate PHI nodes for atomic variables.</div><div><br></div><div>I present the generated LLVM bytecode for the next code snippet as follow. </div><div>I found that it only generated PHI node (<b style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">%8 = phi i32 [ %4, %3 ], [ %6, %5 ]</b>) for non-atomic variable 'data2' but not for atomic variable x? Why?</div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">With PHI node "</span><b style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)">%8 = phi i32 [ %4, %3 ], [ %6, %5 ]</b><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">", we can easily know that<span> </span></span><b style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">data3</b><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>dependents on </span><b style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)">data4.</b><br></div><div>However, if no such PHI node can be generated, how to catch the information that <b>data1</b> dependents on <b>data4</b>?</div><div><br></div><div>Thank you all in advance.</div><div><br></div><div><br></div><div>int data1, data2, data3, data4;</div><div>std::atomic<int> x;<br></div><div><br></div><div>void f1()</div><div>{</div><div> if (data1 > 0) {<br></div><div> x = data4;</div><div> data2 = data4;</div><div> }</div><div><br></div><div> data3 = data2;</div><div> data1 = x;</div><div>}</div></div><div><br></div><div><br></div><div><div>; Function Attrs: uwtable</div><div>define void @_Z2f1v() #3 personality i32 (...)* @__gxx_personality_v0 {</div><div> tail call void @checker_thread_begin(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))</div><div> %1 = load i32, i32* @data1, align 4, !tbaa !1</div><div> %2 = icmp sgt i32 %1, 0</div><div> br i1 %2, label %5, label %3</div><div><br></div><div>; <label>:3: ; preds = %0</div><div> %4 = load i32, i32* @data2, align 4, !tbaa !1</div><div> br label %7</div><div><br></div><div>; <label>:5: ; preds = %0</div><div> %6 = load i32, i32* @data4, align 4, !tbaa !1</div><div> store atomic i32 %6, i32* getelementptr inbounds (%"struct.std::atomic", %"struct.std::atomic"* @x, i64 0, i32 0, i32 0) seq_cst, align 4</div><div> store i32 %6, i32* @data2, align 4, !tbaa !1</div><div> br label %7</div><div><br></div><div>; <label>:7: ; preds = %3, %5</div><div><b> %8 = phi i32 [ %4, %3 ], [ %6, %5 ]</b></div><div> store i32 %8, i32* @data3, align 4, !tbaa !1</div><div> %9 = load atomic i32, i32* getelementptr inbounds (%"struct.std::atomic", %"struct.std::atomic"* @x, i64 0, i32 0, i32 0) seq_cst, align 4</div><div> store i32 %9, i32* @data1, align 4, !tbaa !1</div><div> tail call void @checker_thread_end()</div><div> ret void</div><div>}</div></div></div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div><div>Best regards,</div><div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Qiuping Yi</div><div style="font-size:12.8px"><span style="font-size:12.8px">Institute Of Software</span><br style="font-size:12.8px"><span style="font-size:12.8px">Chinese Academy of Sciences</span><br></div></div></div></div></div></div></div></div></div></div>
</div>