Marcello Maggioni
2013-Sep-17 23:47 UTC
[LLVMdev] Is it safe to insert instructions in batches into BBs?
Hi, I'm getting a very strange behaviour while adding already created instructions in batches into basicblocks instead of creating and inserting them immediately. Because I need to insert instructions in a certain specific order inside multiple different BBs I found it easy to use the IRBuilder to create instructions without inserting them into a BB, storing them somewhere (vector, map ... etc) and later on inserting all of them in one go into their positions in the BBs. What I do is similar to this: IRBuilder<> IB(Context); Vector.push_back(IB.CreateXXX()); Vector.push_back(IB.CreateXXX()); Vector.push_back(IB.CreateXXX()); ... // Other stuff for (SmallVectorImpl<Instruction*>::iterator I = Vector.begin(), E = Vector.end(); I != E; ++I) { SomeBB->getInstList().insert(SomeInstruction, *I); } If I add the instructions like this I get strange results. It's like if llvm gets corrupted or something similar, because in the backend strange things happen, like MCRegisterInfo returning wrong register aliasing information in a random fashion (sometimes happens and sometimes doesn't) . If I create and add the instructions on the fly like this: IB.SetInsertionPoint(SomeInstruction); for () { IB.CreateXXX(); } Everything is fine. So , in the end, is it safe to add instructions like in the first method I mentioned or actually the only safe way is to use the second way? In case it should be safe, what could be the cause of the random breakages? Cheers, Marcello PS = Some of the instructions I'm adding are using one the output value of the other.
Óscar Fuentes
2013-Sep-18 02:40 UTC
[LLVMdev] Is it safe to insert instructions in batches into BBs?
Marcello Maggioni <marcello at codeplay.com> writes:> I'm getting a very strange behaviour while adding already created > instructions in batches into basicblocks instead of creating and > inserting them immediately. > > Because I need to insert instructions in a certain specific order > inside multiple different BBs I found it easy to use the IRBuilder to > create instructions without inserting them into a BB, storing them > somewhere (vector, map ... etc) and later on inserting all of them in > one go into their positions in the BBs.[snip]> So , in the end, is it safe to add instructions like in the first > method I mentioned or actually the only safe way is to use the second > way? In case it should be safe, what could be the cause of the random > breakages? > > Cheers, > Marcello > > PS = Some of the instructions I'm adding are using one the output > value of the other.Does your module pass the verifier? (llvm::verifyModule)
Caldarale, Charles R
2013-Sep-18 03:04 UTC
[LLVMdev] Is it safe to insert instructions in batches into BBs?
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of Marcello Maggioni > Subject: [LLVMdev] Is it safe to insert instructions in batches into BBs?> Because I need to insert instructions in a certain specific order inside > multiple different BBs I found it easy to use the IRBuilder to create > instructions without inserting them into a BB, storing them somewhere > (vector, map ... etc) and later on inserting all of them in one go into > their positions in the BBs.You cannot insert the same instruction object into more than one basic block. You might be able to clone instructions and add the clones to the other blocks. - Chuck
Marcello Maggioni
2013-Sep-18 08:16 UTC
[LLVMdev] Is it safe to insert instructions in batches into BBs?
Il 18/09/2013 03:40, Óscar Fuentes ha scritto:> Marcello Maggioni <marcello at codeplay.com> writes: > >> I'm getting a very strange behaviour while adding already created >> instructions in batches into basicblocks instead of creating and >> inserting them immediately. >> >> Because I need to insert instructions in a certain specific order >> inside multiple different BBs I found it easy to use the IRBuilder to >> create instructions without inserting them into a BB, storing them >> somewhere (vector, map ... etc) and later on inserting all of them in >> one go into their positions in the BBs. > [snip] >> So , in the end, is it safe to add instructions like in the first >> method I mentioned or actually the only safe way is to use the second >> way? In case it should be safe, what could be the cause of the random >> breakages? >> >> Cheers, >> Marcello >> >> PS = Some of the instructions I'm adding are using one the output >> value of the other. > Does your module pass the verifier? (llvm::verifyModule) > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdevYes, it does. I get no complaints by the module verifier, and the CFG at the IR level looks fine. If I try to print the CFG at Machine level though in some occasions the graph is not shown (probably another one of the strange breakages I get together with the RegisterInfo one) Marcello
Marcello Maggioni
2013-Sep-18 08:19 UTC
[LLVMdev] Is it safe to insert instructions in batches into BBs?
Il 18/09/2013 04:04, Caldarale, Charles R ha scritto:>> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] >> On Behalf Of Marcello Maggioni >> Subject: [LLVMdev] Is it safe to insert instructions in batches into BBs? >> Because I need to insert instructions in a certain specific order inside >> multiple different BBs I found it easy to use the IRBuilder to create >> instructions without inserting them into a BB, storing them somewhere >> (vector, map ... etc) and later on inserting all of them in one go into >> their positions in the BBs. > You cannot insert the same instruction object into more than one basic block. You might be able to clone instructions and add the clones to the other blocks. > > - ChuckI'm not doing that, I only insert an instruction in a single basicblock. I'm using that method of insertion because it makes the code clearer to insert the instructions like that instead of inserting them immediately where they are created (the actual code is more complex than the example I shown , but is conceptually the same) Marcello
Maybe Matching Threads
- [LLVMdev] Is it safe to insert instructions in batches into BBs?
- [LLVMdev] Is it safe to insert instructions in batches into BBs?
- [LLVMdev] Inserting a custom switch instruction implementation in backend
- [LLVMdev] Predication on SIMD architectures and LLVM
- [LLVMdev] Predication on SIMD architectures and LLVM