Instruction does not dominate all uses! <badref> ??

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Instruction does not dominate all uses! <badref> ??

edA-qa mort-ora-y
I'm having trouble figuring out what the error "Instruction does not
dominate all uses!" means. I'm trying to construct a call to a function
with two parameters. The printed IR, with error, looks like this:

define i32 @add(i32, i32) {
EntryBlock:
  %2 = add i32 %0, %1
  ret i32 %2
}

define i32 @eval_expr() {
EntryBlock:
  ret i32 <badref>
}

Instruction does not dominate all uses!
  <badref> = call i32 @add(i32 2, i32 3)
  ret i32 <badref>


And the approximate/simplified code I'm using to generate the call,
which would appear at <badref> is:

        llvm::Value * func = module->getFunction( "add" );
       
        std::vector<llvm::Value*> args;
        args.push_back( llvm::ConstantInt::get( llvm::Type::getInt32Ty(
*context ), 2 ) );
        args.push_back( llvm::ConstantInt::get( llvm::Type::getInt32Ty(
*context ), 3 ) );
       
        llvm::ArrayRef<llvm::Value*> ar_args( args );
        return llvm::CallInst::Create( func, ar_args );




--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

signature.asc (267 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Instruction does not dominate all uses! <badref> ??

Duncan Sands
Hi edA-qa mort-ora-y,

On 02/11/12 10:20, edA-qa mort-ora-y wrote:

> I'm having trouble figuring out what the error "Instruction does not
> dominate all uses!" means. I'm trying to construct a call to a function
> with two parameters. The printed IR, with error, looks like this:
>
> define i32 @add(i32, i32) {
> EntryBlock:
>    %2 = add i32 %0, %1
>    ret i32 %2
> }
>
> define i32 @eval_expr() {
> EntryBlock:
>    ret i32 <badref>
> }
>
> Instruction does not dominate all uses!
>    <badref> = call i32 @add(i32 2, i32 3)
>    ret i32 <badref>

Looks like you forgot to add the call instruction to EntryBlock.

>
>
> And the approximate/simplified code I'm using to generate the call,
> which would appear at <badref> is:
>
> llvm::Value * func = module->getFunction( "add" );
>
> std::vector<llvm::Value*> args;
> args.push_back( llvm::ConstantInt::get( llvm::Type::getInt32Ty(
> *context ), 2 ) );
> args.push_back( llvm::ConstantInt::get( llvm::Type::getInt32Ty(
> *context ), 3 ) );
>
> llvm::ArrayRef<llvm::Value*> ar_args( args );
> return llvm::CallInst::Create( func, ar_args );

^ Didn't add it to a basic block.

Ciao, Duncan.

>
>
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Instruction does not dominate all uses! <badref> ??

edA-qa mort-ora-y
On 02/11/12 11:55, Duncan Sands wrote:
> Looks like you forgot to add the call instruction to EntryBlock.
> ^ Didn't add it to a basic block.

I forget to past that part. This is how I add it to a block:

        auto f = llvm::cast<llvm::Function>( module->getOrInsertFunction(
"eval_expr",
                llvm::Type::getInt32Ty( *context ), (llvm::Type*)0 ) );
               
        auto bb = llvm::BasicBlock::Create( *context, "EntryBlock", f );
        llvm::IRBuilder<true,llvm::NoFolder> builder( bb );
       
        builder.CreateRet( expr_i_showed_before );

        return f;

Or do I have to create another block to do the calls?


--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

signature.asc (267 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Instruction does not dominate all uses! <badref> ??

Nick Lewycky
In reply to this post by edA-qa mort-ora-y
edA-qa mort-ora-y wrote:

> I'm having trouble figuring out what the error "Instruction does not
> dominate all uses!" means. I'm trying to construct a call to a function
> with two parameters. The printed IR, with error, looks like this:
>
> define i32 @add(i32, i32) {
> EntryBlock:
>    %2 = add i32 %0, %1
>    ret i32 %2
> }
>
> define i32 @eval_expr() {
> EntryBlock:
>    ret i32<badref>
> }
>
> Instruction does not dominate all uses!
>    <badref>  = call i32 @add(i32 2, i32 3)
>    ret i32<badref>

It's correct but not entirely helpful. You've got an instruction in
function @eval_expr whose operand is an instruction in an entirely
different function (or in no function at all).

> And the approximate/simplified code I'm using to generate the call,
> which would appear at<badref>  is:
>
> llvm::Value * func = module->getFunction( "add" );
>
> std::vector<llvm::Value*>  args;
> args.push_back( llvm::ConstantInt::get( llvm::Type::getInt32Ty(
> *context ), 2 ) );
> args.push_back( llvm::ConstantInt::get( llvm::Type::getInt32Ty(
> *context ), 3 ) );
>
> llvm::ArrayRef<llvm::Value*>  ar_args( args );
> return llvm::CallInst::Create( func, ar_args );

This creates a CallInst but doesn't insert it into any basic block.

Nick
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Instruction does not dominate all uses! <badref> ??

edA-qa mort-ora-y
Okay, I've think I understand now. By using a "Value" object (like a
function call) in another instruction does nothing more than use a
reference to that value. It is still my responsibility to ensure that
value/reference is actually created prior to its use in the block.

On 02/11/12 12:16, Nick Lewycky wrote:

> edA-qa mort-ora-y wrote:
>> I'm having trouble figuring out what the error "Instruction does not
>> dominate all uses!" means. I'm trying to construct a call to a function
>> with two parameters. The printed IR, with error, looks like this:
>>
>> define i32 @add(i32, i32) {
>> EntryBlock:
>>    %2 = add i32 %0, %1
>>    ret i32 %2
>> }
>>
>> define i32 @eval_expr() {
>> EntryBlock:
>>    ret i32<badref>
>> }
>>
>> Instruction does not dominate all uses!
>>    <badref>  = call i32 @add(i32 2, i32 3)
>>    ret i32<badref>
>
> It's correct but not entirely helpful. You've got an instruction in
> function @eval_expr whose operand is an instruction in an entirely
> different function (or in no function at all).
>
>> And the approximate/simplified code I'm using to generate the call,
>> which would appear at<badref>  is:
>>
>>     llvm::Value * func = module->getFunction( "add" );
>>    
>>     std::vector<llvm::Value*>  args;
>>     args.push_back( llvm::ConstantInt::get( llvm::Type::getInt32Ty(
>> *context ), 2 ) );
>>     args.push_back( llvm::ConstantInt::get( llvm::Type::getInt32Ty(
>> *context ), 3 ) );
>>    
>>     llvm::ArrayRef<llvm::Value*>  ar_args( args );
>>     return llvm::CallInst::Create( func, ar_args );
>
> This creates a CallInst but doesn't insert it into any basic block.
>
> Nick
>
>

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

signature.asc (267 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Instruction does not dominate all uses! <badref> ??

Krzysztof Parzyszek
On 11/2/2012 6:51 AM, edA-qa mort-ora-y wrote:
> Okay, I've think I understand now. By using a "Value" object (like a
> function call) in another instruction does nothing more than use a
> reference to that value. It is still my responsibility to ensure that
> value/reference is actually created prior to its use in the block.

In your case it was created, but not inserted in the instruction list.
For every value A in your program, if an instruction B uses A, then A
has to be inserted in such a place in the program where it will dominate
B.  If A is used in several places, it has to dominate all of them.

-Krzysztof

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Instruction does not dominate all uses! <badref> ??

Abhinash Jain
In reply to this post by edA-qa mort-ora-y
@edA-qa mort-ora-y,

>>It is still my responsibility to ensure that value/reference is actually created prior to its use in the block.

Can You tell me how will you ensure this thing?
 
Actually am also stuck on somewhat similar issue and facing this same error.
But since am NOVICE to llvm I couldn't able to figure it out that how to code to get this error resolved.
If you can help me from implementation perspective than it will be great.