Hello, Does there exist something like a "dummy" instruction that is not removed by the optimizers, even if it seems to be dead code? I want to use such instructions to carry metadata information, but they should have a minimal impact on the code generation and optimization. I used an add instruction: %0 = add i8 1, 2, !pragma_instrument_mem_add !0 ; <i8> [#uses=0] which should not carry any dependencies, if inserted inside a loop for instance. But the problem is that it is removed when I use the optimization level -O2. Is there a way to prevent this? I would like to attach metadata to instructions rather than using intrinsics that reference metadata. Thank you, Alexandra -- View this message in context: http://old.nabble.com/Prevent-instruction-elimination-tp30046067p30046067.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On 10/25/10 4:13 AM, Xinfinity wrote:> Hello, > > Does there exist something like a "dummy" instruction that is not removed by > the optimizers, even if it seems to be dead code? > I want to use such instructions to carry metadata information, but they > should have a minimal impact on the code generation and optimization. I used > an add instruction:You may want to use LLVM Metadata features. Search for MDNode in the doxygen docs for some information on how to create metadata. Alternatively, you can use calls to external functions. These are seldomly optimized since optimizations assume that external functions can have undetermined side effects. -- John T.> %0 = add i8 1, 2, !pragma_instrument_mem_add !0 ;<i8> [#uses=0] > > which should not carry any dependencies, if inserted inside a loop for > instance. But the problem is that it is removed when I use the optimization > level -O2. Is there a way to prevent this? > I would like to attach metadata to instructions rather than using intrinsics > that reference metadata. > > > Thank you, > Alexandra
Hi, John Criswell-4 wrote:> > > You may want to use LLVM Metadata features. Search for MDNode in the > doxygen docs for some information on how to create metadata. > >I use metadata information in this way: unsigned mk = Context.getMDKindID(mdtype); Value *V = MDString::get(Context,StringRef(str)); MDNode* n = MDNode::get(Context, &V, 1); inst->setMetadata(mk, n); Maybe it is a deprecated way of handling metadata, as I started with this code from LLVM 2.6. But what I need is a dummy instruction ("inst" in the above example), that has a minimal impact. I want the code to be optimized (almost) as this instruction would not exist. John Criswell-4 wrote:> > > Alternatively, you can use calls to external functions. These are > seldomly optimized since optimizations assume that external functions > can have undetermined side effects. > > -- John T. > >I should avoid calls to some functions, as they would be considered a dependence if they are inserted in the body of a loop, and would definitely affect the optimization step. I also thought about inserting an inline assembly that only contains a comment and carries metadata info. But this is also a call, so it influences the optimizers. Alexandra -- View this message in context: http://old.nabble.com/Prevent-instruction-elimination-tp30046067p30048639.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Oct 25, 2010, at 2:13 AM, Xinfinity wrote:> > Hello, > > Does there exist something like a "dummy" instruction that is not removed by > the optimizers, even if it seems to be dead code? > I want to use such instructions to carry metadata information, but they > should have a minimal impact on the code generation and optimization.Use of metadata will not prevent optimizer from removing an instruction. Actually, that is the corner stone of LLVM metadata design. I am curious, what information you want to carry and until what point ? - Devang
Devang Patel wrote:> > > Use of metadata will not prevent optimizer from removing an instruction. > Actually, that is the corner stone of LLVM metadata design. > > I am curious, what information you want to carry and until what point ? > - > Devang > >I want to handle new pragma inserted in the C/C++ source code and to adapt clang to transform them in metadata information. I want to keep this information until I run some passes on the *.bc files and manipulate the code. Then, I delete those "dummy" instructions. I want to transform this: #pragma my_pragma { C/C++ code C/C++ code } into LLVM_dummy_inst1 , !metadata_info !0 optimized LLVM code optimized LLVM code LLVM_dummy_inst2, !metadata_info !1 but if I run this with clang -O2 or with opt -O2, my dummy_inst are removed, so I cannot find the pragmas in the LLVM IR. I know that metadata will not prevent the elimination, but I am asking if there is any way to prevent this, or what kind of instructions I could use to have a minimal influence on the optimizers. Alexandra -- View this message in context: http://old.nabble.com/Prevent-instruction-elimination-tp30046067p30049711.html Sent from the LLVM - Dev mailing list archive at Nabble.com.