[LLVMdev] Quick doubt about IR
Shivam Bhagi
shivam.bhagi at outlook.com
Wed Dec 4 21:04:54 PST 2013
Hi,
So I included this in my code:
ArrayType* b = ArrayType::get(IntegerType::get(getGlobalContext(), 8), 10);
AllocaInst* pa = new AllocaInst(b, "arr");
//Considering that I represents the instruction iterator pointing to the instruction that I want to replace (i.e. %arr = alloca [30 x i8], align 1)
I->replaceAllUsesWith(pa);
I->eraseFromParent();
I->getParent()->getInstList().insert(*I, pa);
I'm running into the following error:
Stack dump:
Return code not zero; aborting
void llvm::Value::replaceAllUsesWith(llvm::Value*): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed.
0 opt 0x08fc4996 llvm::sys::PrintStackTrace(_IO_FILE*) + 50
1 opt 0x08fc4be9
2 opt 0x08fc45f0
3 0xb77c4400 __kernel_sigreturn + 0
4 0xb77c4422 __kernel_vsyscall + 2
5 libc.so.6 0xb751f941 gsignal + 81
6 libc.so.6 0xb7522d72 abort + 386
7 libc.so.6 0xb7518b58 __assert_fail + 248
8 opt 0x08edfb85 llvm::Value::replaceAllUsesWith(llvm::Value*) + 187
9 CS6265Pass.so 0xb77bdee4
10 opt 0x08ec5317 llvm::FPPassManager::runOnFunction(llvm::Function&) + 301
11 opt 0x08ec54b8 llvm::FPPassManager::runOnModule(llvm::Module&) + 92
12 opt 0x08ec57bc llvm::MPPassManager::runOnModule(llvm::Module&) + 496
13 opt 0x08ec5d4d llvm::PassManagerImpl::run(llvm::Module&) + 229
14 opt 0x08ec5f41 llvm::PassManager::run(llvm::Module&) + 39
15 opt 0x0849c28b main + 5835
16 libc.so.6 0xb750be46 __libc_start_main + 230
17 opt 0x0848e4b1
How can I fix it?
Thanks,
Shivam
On Dec 4, 2013, at 4:57 PM, Jim Grosbach <grosbach at apple.com> wrote:
> Create a new alloca instruction, insert it into the IR right before (or after) the old one, RAUW the value, then delete the old instruction. You should be able to find a variety of examples of this sort of thing in most of the IR level optimization passes. I’d look at InstCombine in particular.
>
> -Jim
>
> On Dec 4, 2013, at 1:40 PM, Shivam Bhagi <shivam.bhagi at outlook.com> wrote:
>
>> Hi,
>>
>> While looking over the IR generated by my source code, I came across the following:
>>
>> %arr = alloca [30 x i8], align 1
>>
>> In the source code this particular line of code is represented by:
>>
>> int arr[30];
>>
>> I was wondering how I could change the capacity of arr from 30 to any other integral value via a function-pass. I know that 'alloca' can be used for reserving space on stack; further, 'store' can be used for writing to memory. I was wondering how that would work for an array though?
>>
>> Thanks,
>> Shivam
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131205/65a38d35/attachment.html>
More information about the llvm-dev
mailing list