1- I need the first example. 2- I set the Address uninitialized according to the documentation " Setting the name on the Value automatically updates the module's symbol table" from Value.h source code 3- I'm not sure about "select" instruction, you mean that the address is the new destination (basic block)that will be added Thanks On 23 July 2013 16:38, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Rasha, > > > I need to addDestination to some basic blocks > > Just to make sure there's no confusion here: you really are trying to > create code like: > > define i32 @foo(i1 %tst) { > %Address = select i1 %tst, i8* blockaddress(@foo, %true), i8* > blockaddress(@foo, %false) > indirectbr i8* %Address, [label %true, label %false] ; This is what > you're creating > true: > ret i32 42 > false: > ret i32 0 > } > > and not: > > define i32 @bar(i1 %tst) { > br i1 %tst, label %true, label %false ; You're not trying to create this > true: > ret i32 42 > false: > ret i32 0 > } > > If that's incorrect, you're going about it entirely the wrong way. We > can help with either, but it's best not to go too far on a > misunderstanding. > > > Value* Address; > > IndirectBrInst *IBI = IndirectBrInst::Create(Address, > Result.size(),i->getTerminator() ); > > > > IBI->addDestination(i); > > The problem seems to be that "Address" is uninitialised but it needs > to be set to some valid pointer value before creating your IndirectBr. > To replicate my first example it would be set to the "select" > instruction, for example; whatever produces your testination > blockaddress. > > Cheers. > > Tim. >-- *Rasha Salah Omar Msc Student at E-JUST Demonestrator at Faculty of Computers and Informatics Benha University * -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130724/ed7aa4a8/attachment.html>
Hi Rasha, On Wed, Jul 24, 2013 at 12:28 AM, Rasha Omar <rasha.sala7 at gmail.com> wrote:> 1- I need the first example.Oh good.> 2- I set the Address uninitialized according to the documentation > " Setting the name on the Value automatically updates the module's symbol > table" from Value.h source codeThat's referring to a string name, and is only really important for clarity and debugging the IR being produced. It means you could start out with something like [...] %1 = add i32 %lhs, %rhs ret i32 %1 [...] (where the %1 is just an automatically incrementing label provided by LLVM) then call MyAddInst.setName("theSum") and LLVM would automatically convert this to: %theSum = add i32 %lhs, %rhs ret i32 %theSum You still have to have an initialised, valid Value pointer to be able to do this.> 3- I'm not sure about "select" instruction, you mean that the address is the > new destination (basic block)that will be addedThe address will be, directly or indirectly, the result of a "BlockAddress::get(...)" call. Perhaps directly (though that would be rather useless since then you'd just as well create a direct branch to that block, perhaps via a "select" as in my code, or via load/store. Perhaps even passed into the function as a parameter in a rather bizarre set of circumstances. Do you know about the Cpp backend, by the way? It can be very useful for working out just what you have to write to emit certain LLVM IR. What you do is write your own .ll file by hand, having the features you want, then run $ llc -march=cpp example_file.ll -o - LLVM will produce some C++ code that generates the module you wrote. It's not necessarily in the best of styles, but shows you roughly which calls you should be making. Cheers. Tim.
Hi 1- for(rit=Result.begin();rit!=Result.end();++rit) { Value* Address= BlockAddress::get (*rit); IndirectBrInst *IBI = IndirectBrInst::Create(Address, Result.size(),i->getTerminator() ); IBI->addDestination((*rit)); } I tried this code , but the needed destination wasn't added. 2- About LLVM backend $ llc -march=cpp example_file.ll -o I think it will be so helpful for my work Thanks On 24 July 2013 08:37, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Rasha, > > On Wed, Jul 24, 2013 at 12:28 AM, Rasha Omar <rasha.sala7 at gmail.com> > wrote: > > 1- I need the first example. > > Oh good. > > 2- I set the Address uninitialized according to the documentation > > " Setting the name on the Value automatically updates the module's symbol > > table" from Value.h source code > > That's referring to a string name, and is only really important for > clarity and debugging the IR being produced. It means you could start > out with something like > > [...] > %1 = add i32 %lhs, %rhs > ret i32 %1 > [...] > > (where the %1 is just an automatically incrementing label provided by > LLVM) then call MyAddInst.setName("theSum") and LLVM would > automatically convert this to: > > %theSum = add i32 %lhs, %rhs > ret i32 %theSum > > You still have to have an initialised, valid Value pointer to be able > to do this. > > > 3- I'm not sure about "select" instruction, you mean that the address is > the > > new destination (basic block)that will be added > > The address will be, directly or indirectly, the result of a > "BlockAddress::get(...)" call. Perhaps directly (though that would be > rather useless since then you'd just as well create a direct branch to > that block, perhaps via a "select" as in my code, or via load/store. > Perhaps even passed into the function as a parameter in a rather > bizarre set of circumstances. > > Do you know about the Cpp backend, by the way? It can be very useful > for working out just what you have to write to emit certain LLVM IR. > > What you do is write your own .ll file by hand, having the features > you want, then run > > $ llc -march=cpp example_file.ll -o - > > LLVM will produce some C++ code that generates the module you wrote. > It's not necessarily in the best of styles, but shows you roughly > which calls you should be making. > > Cheers. > > Tim. >-- *Rasha Salah Omar Msc Student at E-JUST Demonestrator at Faculty of Computers and Informatics Benha University * -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130725/5ab74181/attachment.html>