[llvm-dev] LLVMBuildPhi() circular dependency problem

Toshiyasu Morita via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 15 17:38:45 PST 2017


I wrote earlier:

>I'm having a circular dependency problem with LLVMBuildPhi.
>
>The short explanation:
>
>The compiler is complaining when I build the LLVMValueRef array for
> LLVMAddIncoming that one of the values is undefined, because it's
actually assigned
> later in the basic block.

I think I just realized the correct solution: move LLVMAddIncoming() to
the  end of basic block?

Toshi



On Wed, Feb 15, 2017 at 5:08 PM, Toshiyasu Morita <toshi at tensyr.com> wrote:

> I'm having a circular dependency problem with LLVMBuildPhi.
>
> The short explanation:
>
> The compiler is complaining when I build the LLVMValueRef array for
> LLVMAddIncoming that one of the values is undefined, because it's actually
> assigned later in the basic block.
>
> The long explanation:
>
> I have a loop init basic block which contains:
>
> // Initialize loop counter
>         counter_init = LLVMConstInt(LLVMInt64Type(), count, 0);
> ..
> The loop body basic block contains:
>
> // Set the counter
>         sprintf(tmp_name, "tmp%d", *tmp_num++);
>         counter = LLVMBuildPhi(builder, LLVMInt64Type(), tmp_name);
>         phi_values[0] = counter_init;
>         phi_values[1] = counter_next;
>         phi_basic_blocks[0] = loop_init;
>         phi_basic_blocks[1] = loop_body;
>         LLVMAddIncoming(data3_pntr, phi_values, phi_basic_blocks, 2);
>
> // Decrement the counter
>         sprintf(tmp_name, "tmp%d", *tmp_num++);
>         counter_next = LLVMBuildAdd(builder, counter,
> LLVMConstInt(LLVMInt64Type(), -1, 1), tmp_name);
>
> When this code is compiled, a warning is issued:
>
> capi_test.c:1520:16: error: ‘counter_next’ is used uninitialized in this
> function [-Werror=uninitialized]
>   phi_values[1] = counter_next;
>
> What is the correct way to break this circular dependency?
>
> Toshi
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170215/d38f6eae/attachment.html>


More information about the llvm-dev mailing list