Skip to content

Commit

Permalink
Force emission of a branch in FastISel.
Browse files Browse the repository at this point in the history
This is similar to rust-lang#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.
  • Loading branch information
vext01 committed Mar 30, 2022
1 parent c697a93 commit e618758
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions llvm/lib/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> 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);
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
using namespace llvm;
using namespace PatternMatch;

extern cl::opt<bool> YkNoFallThrough;

#define DEBUG_TYPE "isel"

STATISTIC(NumFastIselSuccessIndependent, "Number of insts selected by "
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ static cl::opt<unsigned> SwitchPeelThreshold(
"switch statement. A value greater than 100 will void this "
"optimization"));

static cl::opt<bool> 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<bool> 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
Expand Down

0 comments on commit e618758

Please sign in to comment.