[PATCH] D41029: [JumpTables][PowerPC] Let targets decide which switch instructions are suitable for jump tables

Nemanja Ivanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 13:45:51 PST 2017


nemanjai added inline comments.


================
Comment at: lib/Target/PowerPC/PPCISelLowering.cpp:1178
+                                               uint64_t Range) const {
+  static std::set<const SwitchInst*> KnownNoJTSwitches;
+  if (!TargetLoweringBase::isSuitableForJumpTable(SI, NumCases, Range))
----------------
efriedma wrote:
> Not thread-safe.  (We support using multiple LLVMContexts at the same time in a process.)
Ah, OK. I'll make it a data member of the class.


================
Comment at: lib/Target/PowerPC/PPCISelLowering.cpp:1204
+    }
+    if (mightUseCTR(It.getCaseSuccessor())) {
+      NumSwitchesNotSuitableForJT++;
----------------
efriedma wrote:
> This is worst-case quadratic (N switches times M instructions in the successor); you might need to cache the mightUseCTR computation.
Well, this is linear in the sum of instructions in successors of all the cases in the switch. This is since no block is visited twice. If a CTR use is found in a block, we return so definitely won't re-vist it. If no CTR use is found in a block, it is not visited again because we skip it in the `if` block above.

I don't think I can make it any faster than that since I have to check each instruction for using the CTR.

Or did you have something else in mind? Perhaps you mean across multiple invocations of `isSuitableForJumpTable()` on the same `SwitchInst`?


Repository:
  rL LLVM

https://reviews.llvm.org/D41029





More information about the llvm-commits mailing list