-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Support] Do not use llvm::size
in getLoopPreheader
#94540
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
Conversation
@llvm/pr-subscribers-llvm-support Author: Ben Barham (bnbarham) Changes
Full diff: https://github.com/llvm/llvm-project/pull/94540.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
index 1e0d0ee446fc4..c9c7354937545 100644
--- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h
+++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
@@ -208,7 +208,10 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader() const {
return nullptr;
// Make sure there is only one exit out of the preheader.
- if (llvm::size(llvm::children<BlockT *>(Out)) != 1)
+ typedef GraphTraits<BlockT *> BlockTraits;
+ typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out);
+ ++SI;
+ if (SI != BlockTraits::child_end(Out))
return nullptr; // Multiple exits from the block, must not be a preheader.
// The predecessor has exactly one successor, so it is a preheader.
|
@kazutakahirata this was a NFC commit, was there an underlying reason for the change or are you happy with reverting this part of it? |
typedef GraphTraits<BlockT *> BlockTraits; | ||
typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out); | ||
++SI; | ||
if (SI != BlockTraits::child_end(Out)) |
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.
Could we do something like this?
typedef GraphTraits<BlockT *> BlockTraits; | |
typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out); | |
++SI; | |
if (SI != BlockTraits::child_end(Out)) | |
if (!llvm::hasSingleElement(GraphTraits<BlockT *>::children(Out))) |
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.
Ah nice, much better. Switched to llvm::hasSingleElement
, thanks!
`BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader()` was changed in 7243607 to use `llvm::size` rather than the checking that `child_begin() + 1 == child_end()`. `llvm::size` requires that `std::distance` be O(1) and hence that clients support random access. Use `llvm::hasSingleElement` instead.
527f574
to
3d0d614
Compare
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.
LGTM. Thanks!
`BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader()` was changed in 7243607 to use `llvm::size` rather than the checking that `child_begin() + 1 == child_end()`. `llvm::size` requires that `std::distance` be O(1) and hence that clients support random access. Use `llvm::hasSingleElement` instead. Signed-off-by: Hafidz Muzakky <[email protected]>
BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader()
was changed in7243607 to use
llvm::size
rather thanthe checking that
child_begin() + 1 == child_end()
.llvm::size
requires that
std::distance
be O(1) and hence that clients supportrandom access. Use
llvm::hasSingleElement
instead.