[llvm-dev] PHI nodes for atomic variables

Qiuping Yi via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 7 20:07:08 PST 2018


Hi everyone,

I want to track the def-use chain for atomic variables.
However, it seems that LLVM will not generate PHI nodes for atomic
variables.

I present the generated LLVM bytecode for the next code snippet as follow.
I found that it only generated PHI node (*%8 = phi i32 [ %4, %3 ], [ %6, %5
]*) for non-atomic variable 'data2' but not for atomic variable x? Why?
With PHI node "*%8 = phi i32 [ %4, %3 ], [ %6, %5 ]*", we can easily know
that *data3* dependents on *data4.*
However, if no such PHI node can be generated, how to catch the information
that *data1* dependents on *data4*?

Thank you all in advance.


int data1, data2, data3, data4;
std::atomic<int> x;

void f1()
{
    if (data1 > 0) {
         x = data4;
        data2 = data4;
    }

    data3 = data2;
    data1 = x;
}


; Function Attrs: uwtable
define void @_Z2f1v() #3 personality i32 (...)* @__gxx_personality_v0 {
  tail call void @checker_thread_begin(i8* getelementptr inbounds ([3 x
i8], [3 x i8]* @.str, i64 0, i64 0))
  %1 = load i32, i32* @data1, align 4, !tbaa !1
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %5, label %3

; <label>:3:                                      ; preds = %0
  %4 = load i32, i32* @data2, align 4, !tbaa !1
  br label %7

; <label>:5:                                      ; preds = %0
  %6 = load i32, i32* @data4, align 4, !tbaa !1
  store atomic i32 %6, i32* getelementptr inbounds (%"struct.std::atomic",
%"struct.std::atomic"* @x, i64 0, i32 0, i32 0) seq_cst, align 4
  store i32 %6, i32* @data2, align 4, !tbaa !1
  br label %7

; <label>:7:                                      ; preds = %3, %5
*  %8 = phi i32 [ %4, %3 ], [ %6, %5 ]*
  store i32 %8, i32* @data3, align 4, !tbaa !1
  %9 = load atomic i32, i32* getelementptr inbounds (%"struct.std::atomic",
%"struct.std::atomic"* @x, i64 0, i32 0, i32 0) seq_cst, align 4
  store i32 %9, i32* @data1, align 4, !tbaa !1
  tail call void @checker_thread_end()
  ret void
}


Best regards,

Qiuping Yi
Institute Of Software
Chinese Academy of Sciences
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180207/a26ce3ad/attachment.html>


More information about the llvm-dev mailing list