This is an archive of the discontinued LLVM Phabricator instance.

Add support for phi nodes in the LLVM C API test
ClosedPublic

Authored by deadalnix on Feb 9 2016, 4:22 PM.

Details

Summary

This required to add binding to Instruction::removeFromParent so that instruction can be forward declared and then moved at the right place.

Diff Detail

Event Timeline

deadalnix updated this revision to Diff 47396.Feb 9 2016, 4:22 PM
deadalnix retitled this revision from to Add support for phi nodes in the LLVM C API test.
deadalnix updated this object.
deadalnix added a subscriber: llvm-commits.
mehdi_amini added inline comments.Feb 9 2016, 4:42 PM
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?

deadalnix added inline comments.Feb 9 2016, 6:05 PM
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.

mehdi_amini added inline comments.Feb 9 2016, 6:11 PM
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.

deadalnix added inline comments.Feb 10 2016, 3:29 PM
tools/llvm-c-test/echo.cpp
208–209

No because now, the instruction would be moved around.

235

What do you suggest as a placeholder ? Many things are uniqued so replaceAllUsesWith tends to fail horribly.

mehdi_amini added inline comments.Feb 10 2016, 4:27 PM
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;
}
deadalnix updated this revision to Diff 47561.Feb 10 2016, 4:42 PM

Simplify CloneValue ending

mehdi_amini accepted this revision.Feb 10 2016, 4:44 PM
mehdi_amini edited edge metadata.

LGTM

This revision is now accepted and ready to land.Feb 10 2016, 4:44 PM
This revision was automatically updated to reflect the committed changes.