-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SandboxIR] Implement PHINodes #101111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SandboxIR] Implement PHINodes #101111
Conversation
This patch implements sandboxir::PHINode which mirrors llvm::PHINode. Based almost entirely on work by vporpo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor comments, looks good.
@@ -1290,6 +1292,97 @@ class GetElementPtrInst final : public Instruction { | |||
#endif | |||
}; | |||
|
|||
class PHINode final : public Instruction { | |||
/// Use Context::createPHINode(). Don't call the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment looks like it should fit in a single 80-column line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/// constructor directly. | ||
PHINode(llvm::PHINode *PHI, Context &Ctx) | ||
: Instruction(ClassID::PHI, Opcode::PHI, PHI, Ctx) {} | ||
friend Context; // for SBPHINode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SBPHINode -> PHINode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1301,6 +1407,11 @@ Context::createGetElementPtrInst(llvm::GetElementPtrInst *I) { | |||
return cast<GetElementPtrInst>(registerValue(std::move(NewPtr))); | |||
} | |||
|
|||
PHINode *Context::createPHINode(llvm::PHINode *I) { | |||
auto NewPtr = std::unique_ptr<PHINode>(new PHINode(I, *this)); | |||
return cast<PHINode>(registerValue(std::move(NewPtr))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Perehaps return cast<PHINode>(registerValue(std::unique_ptr<PHINode>(new PHINode(I, *this))));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That ends up being different from the others, like on the code just above this one. Should we change them all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, your call. Either is fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean we can keep it as it is too, I don't feel strongly about changing them.
return cast<llvm::PHINode>(Val)->hasConstantOrUndefValue(); | ||
} | ||
bool isComplete() const { return cast<llvm::PHINode>(Val)->isComplete(); } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some member functions have not been implemented yet, like replaceIncomingBlockWith()
, copyIncomingBlocks()
, removeIncomingValueIf()
. Could you add a TODO in the code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
✅ With the latest revision this PR passed the C/C++ code formatter. |
This patch implements sandboxir::PHINode which mirrors llvm::PHINode.
Based almost entirely on work by vporpo.