[PATCH] D155413: [NFC] Add `push_back` to `llvm::Function`

Evan Wilde via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 16 17:02:00 PDT 2023


etcwilde created this revision.
etcwilde added reviewers: compnerd, vporpo.
etcwilde added a project: LLVM.
Herald added a project: All.
etcwilde requested review of this revision.
Herald added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155413

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl05.rst
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
  llvm/examples/Kaleidoscope/Chapter5/toy.cpp
  llvm/examples/Kaleidoscope/Chapter6/toy.cpp
  llvm/examples/Kaleidoscope/Chapter7/toy.cpp
  llvm/examples/Kaleidoscope/Chapter8/toy.cpp
  llvm/examples/Kaleidoscope/Chapter9/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp
  llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
  llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
  llvm/include/llvm/IR/Function.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155413.540836.patch
Type: text/x-patch
Size: 14180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230717/d9e257a2/attachment.bin>


More information about the llvm-commits mailing list