[llvm-dev] Creating/Deleting a new instruction from LLVM IR

Ansar K.A. via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 25 19:05:47 PST 2015


Hi,

I was trying to create a new  *Store* instruction and inserting it to LLVM
IR (.ll) file. I found the following constructor in LLVM Manual:

StoreInst::StoreInst
<http://llvm.org/docs/doxygen/html/classllvm_1_1StoreInst.html#aa2a72f9a51b317f5b4ab8695adf59025>
(Value <http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html> * Val,
Value <http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html> * Ptr,
Instruction
<http://llvm.org/docs/doxygen/html/classllvm_1_1Instruction.html> *
InsertBefore )

I thought of using this. I don't know the meaning of the constructors
arguments. What all values should be passed for creating a new *Store
*Instruction
(with an *example) *?

How to insert this to LLVM IR? ( I saw the code snippet in LLVM Programming
manual, I couldn't understand it. Any examples on doing the same? )

I tried to delete an instruction using:

                        i->eraseFromParent();

But it throws the following error/exception:

*opt -load /home/mtech2/Documents/llvm/build/Debug+Asserts/lib/CSE.so -CSE
<test.ll> /dev/null*
*opt: /home/mtech2/Documents/llvm/llvm/include/llvm/Support/Casting.h:81:
static bool llvm::isa_impl_cl<To, From*>::doit(const From*) [with To =
llvm::Instruction; From = llvm::Instruction]: Assertion `Val && "isa<> used
on a null pointer"' failed.*
*#0 0x29635a5 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/mtech2/Documents/llvm/llvm/lib/Support/Unix/Signals.inc:405:0*
*#1 0x29638ba PrintStackTraceSignalHandler(void*)
/home/mtech2/Documents/llvm/llvm/lib/Support/Unix/Signals.inc:463:0*
*#2 0x2961eb9 llvm::sys::RunSignalHandlers()
/home/mtech2/Documents/llvm/llvm/lib/Support/Signals.cpp:34:0*
*#3 0x29623b1 SignalHandler(int)
/home/mtech2/Documents/llvm/llvm/lib/Support/Unix/Signals.inc:211:0*
*#4 0x7f190977a340 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)*
*#5 0x7f1908715cc9 gsignal
/build/buildd/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0*
*#6 0x7f19087190d8 abort /build/buildd/eglibc-2.19/stdlib/abort.c:91:0*
*#7 0x7f190870eb86 __assert_fail_base
/build/buildd/eglibc-2.19/assert/assert.c:92:0*
*#8 0x7f190870ec32 (/lib/x86_64-linux-gnu/libc.so.6+0x2fc32)*
*#9 0x7f19084d9970 llvm::isa_impl_cl<llvm::Instruction,
llvm::Instruction*>::doit(llvm::Instruction const*)
/home/mtech2/Documents/llvm/llvm/include/llvm/Support/Casting.h:82:0*
*#10 0x7f19084d9450 llvm::isa_impl_wrap<llvm::Instruction,
llvm::Instruction*, llvm::Instruction*>::doit(llvm::Instruction* const&)
/home/mtech2/Documents/llvm/llvm/include/llvm/Support/Casting.h:123:0*
*#11 0x7f19084d89e2 llvm::isa_impl_wrap<llvm::Instruction,
llvm::ilist_iterator<llvm::Instruction> const,
llvm::Instruction*>::doit(llvm::ilist_iterator<llvm::Instruction> const&)
/home/mtech2/Documents/llvm/llvm/include/llvm/Support/Casting.h:115:0*
*#12 0x7f19084d8371 bool llvm::isa<llvm::Instruction,
llvm::ilist_iterator<llvm::Instruction>
>(llvm::ilist_iterator<llvm::Instruction> const&)
/home/mtech2/Documents/llvm/llvm/include/llvm/Support/Casting.h:135:0*
*#13 0x7f19084d7ba1 llvm::cast_retty<llvm::Instruction,
llvm::ilist_iterator<llvm::Instruction> >::ret_type
llvm::cast<llvm::Instruction, llvm::ilist_iterator<llvm::Instruction>
>(llvm::ilist_iterator<llvm::Instruction>&)
/home/mtech2/Documents/llvm/llvm/include/llvm/Support/Casting.h:230:0*
*#14 0x7f19084d73fd (anonymous
namespace)::CSE::runOnFunction(llvm::Function&)
/home/mtech2/Documents/llvm/llvm/lib/Transforms/CSE/CSE.cpp:48:0*
*#15 0x288fd1c llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/mtech2/Documents/llvm/llvm/lib/IR/LegacyPassManager.cpp:1528:0*
*#16 0x288feaf llvm::FPPassManager::runOnModule(llvm::Module&)
/home/mtech2/Documents/llvm/llvm/lib/IR/LegacyPassManager.cpp:1549:0*
*#17 0x289024a (anonymous
namespace)::MPPassManager::runOnModule(llvm::Module&)
/home/mtech2/Documents/llvm/llvm/lib/IR/LegacyPassManager.cpp:1605:0*
*#18 0x28909bb llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/mtech2/Documents/llvm/llvm/lib/IR/LegacyPassManager.cpp:1708:0*
*#19 0x2890bfb llvm::legacy::PassManager::run(llvm::Module&)
/home/mtech2/Documents/llvm/llvm/lib/IR/LegacyPassManager.cpp:1740:0*
*#20 0xee3bd2 main /home/mtech2/Documents/llvm/llvm/tools/opt/opt.cpp:602:0*
*#21 0x7f1908700ec5 __libc_start_main
/build/buildd/eglibc-2.19/csu/libc-start.c:321:0*
*#22 0xec1739 _start
(/home/mtech2/Documents/llvm/build/Debug+Asserts/bin/opt+0xec1739)*
*Stack dump:*
*0. Program arguments: opt -load
/home/mtech2/Documents/llvm/build/Debug+Asserts/lib/CSE.so -CSE *
*1. Running pass 'Function Pass Manager' on module '<stdin>'.*
*2. Running pass 'Print Instructions' on function '@main'*
*Aborted (core dumped)*

Any help will be appreciated.


- Ansar K.A.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151126/b4eac8e7/attachment.html>


More information about the llvm-dev mailing list