This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Add `push_back` to `llvm::Function`
Needs ReviewPublic

Authored by etcwilde on Jul 16 2023, 5:01 PM.

Details

Reviewers
compnerd
vporpo
Summary

Appending a basic block to a function is a fairly common operation. The basic block list is private now, so pushing back is currently done by myFunction->insert(myFunction->getEnd(), bb);, which feels a bit redundant. This patch adds a push_back convenience function to llvm::Function to make appending basic blocks a bit easier again.

+  /// append \p BB to the end of the function
+  void push_back(BasicBlock *BB) {
+    return BasicBlocks.push_back(BB);
+  }

I've also gone through and migrated the usage in kaleidoscope, the getting started docs, and in clang where I saw it.
I'm open to leaving that part of the change off, but it makes it a little bit clearer what the intended goal is.

I was going back and forth a little regarding the naming. appendBasicBlock is clearest, push_back is most consistent though.

Diff Detail

Event Timeline

etcwilde created this revision.Jul 16 2023, 5:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2023, 5:01 PM
etcwilde requested review of this revision.Jul 16 2023, 5:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2023, 5:01 PM
etcwilde updated this revision to Diff 540850.Jul 16 2023, 8:16 PM

Fixing push_back formatting.

Failure was a formatting issue in clang/lib/Analysis/UnsafeBufferUsage.cpp.
I just fixed that in d7b45945fbb7c4ac27c456dd7c2ff8bb40fcf8f8.
I don't know how to re-trigger the tests though.