Skip to content

Commit

Permalink
Merge pull request #215 from vext01/jump-thread-ctrlp
Browse files Browse the repository at this point in the history
Prevent JumpThreadingPass from messing with control points.
  • Loading branch information
ltratt authored Nov 18, 2024
2 parents ce98289 + 49693e4 commit c73f96f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/Support/Yk.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ void initYkOptions(void);
// of us randomly introducing `extern bool`s all over the place.
extern bool YkOptNoneAfterIRPasses;
extern bool YkDontOptFuncABI;
extern bool YkPatchCtrlPoint;

#endif
5 changes: 1 addition & 4 deletions llvm/lib/CodeGen/TargetPassConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "llvm/Support/Threading.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/Yk.h"
#include "llvm/Target/CGPassBuilderOption.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Scalar.h"
Expand Down Expand Up @@ -270,10 +271,6 @@ static cl::opt<bool>
YkBlockDisambiguate("yk-block-disambiguate", cl::init(false), cl::NotHidden,
cl::desc("Disambiguate blocks for yk"));

static cl::opt<bool> YkPatchCtrlPoint("yk-patch-control-point", cl::init(false),
cl::NotHidden,
cl::desc("Patch yk_mt_control_point()"));

static cl::opt<bool> YkLinkage("yk-linkage", cl::init(false),
cl::NotHidden,
cl::desc("Change functions with internal linkage to have external linkage"));
Expand Down
15 changes: 15 additions & 0 deletions llvm/lib/Support/Yk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ struct CreateYkDontOptFuncABIParser {
} // namespace
static ManagedStatic<cl::opt<bool, true>, CreateYkDontOptFuncABIParser> YkDontOptFuncABIParser;

bool YkPatchCtrlPoint;
namespace {
struct CreateYkPatchCtrlPointParser {
static void *call() {
return new cl::opt<bool, true>(
"yk-patch-control-point",
cl::desc("Patch yk control points"),
cl::NotHidden, cl::location(YkPatchCtrlPoint));
}
};
} // namespace
static ManagedStatic<cl::opt<bool, true>, CreateYkPatchCtrlPointParser> YkPatchCtrlPointParser;


void llvm::initYkOptions() {
*YkExtendedLLVMBBAddrMapSectionParser;
*YkStackMapOffsetFixParser;
Expand All @@ -118,4 +132,5 @@ void llvm::initYkOptions() {
*YkOptNoneAfterIRPassesParser;
*YkEmbedIRParser;
*YkDontOptFuncABIParser;
*YkPatchCtrlPointParser;
}
15 changes: 15 additions & 0 deletions llvm/lib/Transforms/Scalar/JumpThreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Yk.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include "llvm/Transforms/Yk/ControlPoint.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
Expand Down Expand Up @@ -963,6 +965,19 @@ static bool hasAddressTakenAndUsed(BasicBlock *BB) {
/// processBlock - If there are any predecessors whose control can be threaded
/// through to a successor, transform them now.
bool JumpThreadingPass::processBlock(BasicBlock *BB) {
// We mustn't duplicate yk JIT control points.
if (YkPatchCtrlPoint) {
for (Instruction &I: *BB) {
if (CallInst *CI = dyn_cast<CallInst>(&I)) {
Function *CF = CI->getCalledFunction();
// The control point hasn't been patched yet, so we look for the
// pre-patched name.
if ((CF != nullptr) && (CF->getName() == YK_DUMMY_CONTROL_POINT)) {
return false;
}
}
}
}
// If the block is trivially dead, just return and let the caller nuke it.
// This simplifies other transformations.
if (DTU->isBBPendingDeletion(BB) ||
Expand Down

0 comments on commit c73f96f

Please sign in to comment.