This required to add binding to Instruction::removeFromParent so that instruction can be forward declared and then moved at the right place.
Details
Diff Detail
Event Timeline
tools/llvm-c-test/echo.cpp | ||
---|---|---|
208–209 | Why this addition? (the comment talk about function argument) The code path seems funky, it seem that the body should always be executed right now or you hit the error. | |
235 | s/somethign/something/ To be sure I understand correctly, in case of a loop you'll generate some instruction (only PHI?) "at the wrong place" and then when you see them again you move them where they should be? |
tools/llvm-c-test/echo.cpp | ||
---|---|---|
208–209 | As to not run CloneInstruction at all if the instruction already was generated. Argument should be already generated, instruction may or may not be already generated. | |
235 | If an instruction use as argument another instruction from a basic block that isn't generated yet, the instruction can't be generated at the right place (this place do not exists yet). So, if we end up there and have a match, it means we are trying to generate an instruction that already where generated as a dependency. We don't need to regenerate the instruction, but we need to make sure it is at the right place. |
tools/llvm-c-test/echo.cpp | ||
---|---|---|
208–209 | What I mean is that I don't see how removing the "if" entirely would change anything (inline the then body in the parent) here. | |
235 | Sure but you could (I am not saying you should) use a placeholder with value tracking instead of generating the instruction at the wrong place the first time you see it. |
tools/llvm-c-test/echo.cpp | ||
---|---|---|
216–222 | Ok here is what I think the semantic is: assert((LLVMIsAArgument(Src) || LLVMIsAInstruction(Src)) && "unexpected"); // Function argument should always be in the map already. auto i = VMap.find(Src); if (i != VMap.end()) return i->second; // Instruction only are possible at this point assert(LLVMIsAInstruction(Src) && "unexpected"); auto Builder = LLVMCreateBuilderInContext(Ctx); auto BB = DeclareBB(LLVMGetInstructionParent(Src)); LLVMPositionBuilderAtEnd(Builder, BB); auto Dst = CloneInstruction(Src, Builder); LLVMDisposeBuilder(Builder); return Dst; } |
Why this addition? (the comment talk about function argument)
The code path seems funky, it seem that the body should always be executed right now or you hit the error.