[PATCH] D40808: [RISCV] Implement branch analysis

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 19:05:05 PST 2017


reames requested changes to this revision.
reames added a comment.
This revision now requires changes to proceed.

Adding a machine pass which just called analyzeBranch on each BB and printed the result would be straight-forward if you wanted to cleanup the testing.



================
Comment at: lib/Target/RISCV/RISCVInstrInfo.cpp:152
+
+  // Get the last instruction in the block.
+  MachineInstr *LastInst = &*I;
----------------
Okay, this code structure is horrible.  I get that you just copied the structure, but there's no reason to keep this.  Suggested alternate structure:
if (!ends with predicated terminator) // i.e. fallthrough
  return
scan back to first unconditional branch or indirect branch
if (allowmodify) {
  // remove everything after that point
}
handle conditional branch case starting from last unconditional branch
handle unconditional branch case starting from last unconditional branch

Beyond this, there's a general invariant question.  How do we end up with multiple unconditional branches?  When we insert one, shouldn't we truncate the block at that point?


https://reviews.llvm.org/D40808





More information about the llvm-commits mailing list