From e61875890886c61a701e46ed390eb707a6f25b33 Mon Sep 17 00:00:00 2001 From: Edd Barrett Date: Wed, 30 Mar 2022 10:43:25 +0100 Subject: [PATCH] Force emission of a branch in FastISel. This is similar to #29, but for FastISel. The change ensures that a LLVM `br` always codegens a branch, even if fallthrough is possible. We re-use --yk-no-fallthrough for this. To do so we move its definition into a more generic location. With this, the Lua interpreter runs until stop-gapping with the yk JIT. --- llvm/lib/CodeGen/CodeGen.cpp | 7 +++++++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 4 +++- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 6 +----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp index e0e2db9f472568..36d10a57926be2 100644 --- a/llvm/lib/CodeGen/CodeGen.cpp +++ b/llvm/lib/CodeGen/CodeGen.cpp @@ -14,9 +14,16 @@ #include "llvm-c/Initialization.h" #include "llvm/InitializePasses.h" #include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" using namespace llvm; +llvm::cl::opt YkNoFallThrough( + "yk-no-fallthrough", cl::Hidden, cl::init(false), + cl::desc("Always emit a branch even if fallthrough is possible. This " + "is required for the yk JIT, so that the machine IR has the " + "same block structure as the high-level IR")); + /// initializeCodeGen - Initialize all passes linked into the CodeGen library. void llvm::initializeCodeGen(PassRegistry &Registry) { initializeAtomicExpandPass(Registry); diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp index 4ca731cfdf6225..4ea6d197fe37c7 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -111,6 +111,8 @@ using namespace llvm; using namespace PatternMatch; +extern cl::opt YkNoFallThrough; + #define DEBUG_TYPE "isel" STATISTIC(NumFastIselSuccessIndependent, "Number of insts selected by " @@ -1576,7 +1578,7 @@ bool FastISel::selectInstruction(const Instruction *I) { /// (fall-through) successor, and update the CFG. void FastISel::fastEmitBranch(MachineBasicBlock *MSucc, const DebugLoc &DbgLoc) { - if (FuncInfo.MBB->getBasicBlock()->sizeWithoutDebug() > 1 && + if ((!YkNoFallThrough) && (FuncInfo.MBB->getBasicBlock()->sizeWithoutDebug() > 1) && FuncInfo.MBB->isLayoutSuccessor(MSucc)) { // For more accurate line information if this is the only non-debug // instruction in the block then emit it, otherwise we have the diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 69ec0678f0ad58..19b3fb199b4d11 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -135,11 +135,7 @@ static cl::opt SwitchPeelThreshold( "switch statement. A value greater than 100 will void this " "optimization")); -static cl::opt YkNoFallThrough( - "yk-no-fallthrough", cl::Hidden, cl::init(false), - cl::desc("Always emit a branch even if fallthrough is possible. This " - "is required for the yk JIT, so that the machine IR has the " - "same block structure as the high-level IR")); +extern cl::opt YkNoFallThrough; // Limit the width of DAG chains. This is important in general to prevent // DAG-based analysis from blowing up. For example, alias analysis and