[PATCH] D47467: [IR] Begin removal of TerminatorInst by removing successor manipulation.

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 03:30:03 PDT 2018


chandlerc created this revision.
chandlerc added a reviewer: rnk.
Herald added subscribers: hiraditya, mcrosier, sanjoy.

The core get and set routines move to the `Instruction` class. These
routines are only valid to call on instructions which are terminators.

The iterator and *generic* range based access move to `CFG.h` where all
the other generic successor and predecessor access lives. While moving
the iterator here, simplify it using the iterator utilities LLVM
provides and updates coding style as much as reasonable. The APIs remain
pointer-heavy when they could better use references, and retain the odd
behavior of `operator*` and `operator->` that is common in LLVM
iterators. Adjusting this API, if desired, should be a follow-up step.

Non-generic range iteration is added for the two instructions where
there is an especially easy mechanism and where there was code
attempting to use the range accessor from a specific subclass:
`indirectbr` and `br`. In both cases, the successors are contiguous
operands and can be easily iterated via the operand list.

This is the first major patch in removing the `TerminatorInst` type from
the IR's instruction type hierarchy. The steps that I have planned out
(although there are likely to be some minor ones) look like the
following:

- Remove the few remaining APIs of `TerminatorInst`, replacing them with existing predicates in `Instruction` or adding new ones if needed.
- Replacing `isa<TerminatorInst>` and `dyn_cast<TerminatorInst>` with appropriate uses of `isTerminator`.
- Replacing `TerminatorInst` in parameter APIs with just `Instruction` and potentially an assert on `isTerminator`.
- Replacing `TerminatorInst` in the return of the remaining APIs (not updated above) with `Instruction`. Most notably, the `getTerminator` method.
- Removing `TerminotarInst` type completely.
- Making `InvokeInst` and `CallInst` derive from a common base class w/ most of the logic currently in `CallInst`.
- Replacing uses of `CallSite` everywhere with the common base class.

These are likely to be quite mechanical, and I suspect are probably best done
with post-commit review. Please lete me know if there are specific
patches in this series you'd like to do pre-commit review on and I'll
happily break them out. Naturally, if any end up with significant
questions in them, I'll post a review for that.


Repository:
  rL LLVM

https://reviews.llvm.org/D47467

Files:
  llvm/include/llvm/IR/CFG.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Instruction.h
  llvm/include/llvm/IR/Instructions.h
  llvm/lib/Analysis/LoopInfo.cpp
  llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
  llvm/lib/IR/BasicBlock.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Scalar/GVNHoist.cpp
  llvm/lib/Transforms/Scalar/LoopInterchange.cpp
  llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
  llvm/lib/Transforms/Utils/CloneFunction.cpp
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47467.148871.patch
Type: text/x-patch
Size: 30268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180529/ac9edba5/attachment.bin>


More information about the llvm-commits mailing list