Skip to content

[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

Merged
merged 8 commits into from
Jul 31, 2024
Merged

Conversation

Sterling-Augustine
Copy link
Contributor

This patch implements sandboxir::PHINode which mirrors llvm::PHINode.

Based almost entirely on work by vporpo.

This patch implements sandboxir::PHINode which mirrors llvm::PHINode.

Based almost entirely on work by vporpo.
Copy link
Contributor

@vporpo vporpo left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SBPHINode -> PHINode

Copy link
Contributor Author

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)));
Copy link
Contributor

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)))); ?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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(); }

Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link

github-actions bot commented Jul 30, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@Sterling-Augustine Sterling-Augustine merged commit 3403b59 into llvm:main Jul 31, 2024
7 checks passed
@Sterling-Augustine Sterling-Augustine deleted the sandboxir branch September 4, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants