[llvm] [CodeGen] Port `JMCInstrumenter` to new pass manager (PR #75049)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 05:51:55 PST 2023
https://github.com/paperchalice created https://github.com/llvm/llvm-project/pull/75049
None
>From 2fd8b1dd955457590f240545ec699768c7ab2e38 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Mon, 11 Dec 2023 21:29:46 +0800
Subject: [PATCH] [CodeGen] Port `JMCInstrumenter` to new pass manager
---
.../include/llvm/CodeGen/CodeGenPassBuilder.h | 1 +
llvm/include/llvm/CodeGen/JMCInstrumenter.h | 23 +++++++++++++++++++
.../llvm/CodeGen/MachinePassRegistry.def | 1 +
llvm/lib/CodeGen/JMCInstrumenter.cpp | 13 ++++++++---
llvm/lib/Passes/PassBuilder.cpp | 1 +
llvm/lib/Passes/PassRegistry.def | 1 +
.../JustMyCode/jmc-instrument-elf.ll | 3 ++-
.../JustMyCode/jmc-instrument-x86.ll | 3 ++-
.../JustMyCode/jmc-instrument.ll | 9 +++++---
llvm/tools/opt/opt.cpp | 2 +-
10 files changed, 48 insertions(+), 9 deletions(-)
create mode 100644 llvm/include/llvm/CodeGen/JMCInstrumenter.h
diff --git a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
index bb139ef2eb351..4e704411270c5 100644
--- a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
@@ -26,6 +26,7 @@
#include "llvm/CodeGen/DwarfEHPrepare.h"
#include "llvm/CodeGen/ExpandReductions.h"
#include "llvm/CodeGen/InterleavedAccess.h"
+#include "llvm/CodeGen/JMCInstrumenter.h"
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
#include "llvm/CodeGen/ReplaceWithVeclib.h"
diff --git a/llvm/include/llvm/CodeGen/JMCInstrumenter.h b/llvm/include/llvm/CodeGen/JMCInstrumenter.h
new file mode 100644
index 0000000000000..addac1654826c
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/JMCInstrumenter.h
@@ -0,0 +1,23 @@
+//===-- llvm/CodeGen/JMCInstrumenter------------------------ ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_JMCINSTRUMENTER_H
+#define LLVM_CODEGEN_JMCINSTRUMENTER_H
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+class JMCInstrumenterPass : public PassInfoMixin<JMCInstrumenterPass> {
+public:
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_JMCINSTRUMENTER_H
diff --git a/llvm/include/llvm/CodeGen/MachinePassRegistry.def b/llvm/include/llvm/CodeGen/MachinePassRegistry.def
index e6e979a4582c7..6b720736c3e53 100644
--- a/llvm/include/llvm/CodeGen/MachinePassRegistry.def
+++ b/llvm/include/llvm/CodeGen/MachinePassRegistry.def
@@ -23,6 +23,7 @@ MODULE_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis, (PIC))
#define MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR)
#endif
MODULE_PASS("pre-isel-intrinsic-lowering", PreISelIntrinsicLoweringPass, ())
+MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass, ())
#undef MODULE_PASS
#ifndef FUNCTION_ANALYSIS
diff --git a/llvm/lib/CodeGen/JMCInstrumenter.cpp b/llvm/lib/CodeGen/JMCInstrumenter.cpp
index a1f0a50406643..62a3819188752 100644
--- a/llvm/lib/CodeGen/JMCInstrumenter.cpp
+++ b/llvm/lib/CodeGen/JMCInstrumenter.cpp
@@ -20,6 +20,7 @@
// weak symbol.
//===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/JMCInstrumenter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/CodeGen/Passes.h"
@@ -39,19 +40,25 @@
using namespace llvm;
-#define DEBUG_TYPE "jmc-instrument"
+#define DEBUG_TYPE "jmc-instrumenter"
+static bool runImpl(Module &M);
namespace {
struct JMCInstrumenter : public ModulePass {
static char ID;
JMCInstrumenter() : ModulePass(ID) {
initializeJMCInstrumenterPass(*PassRegistry::getPassRegistry());
}
- bool runOnModule(Module &M) override;
+ bool runOnModule(Module &M) override { return runImpl(M); }
};
char JMCInstrumenter::ID = 0;
} // namespace
+PreservedAnalyses JMCInstrumenterPass::run(Module &M, ModuleAnalysisManager &) {
+ bool Changed = runImpl(M);
+ return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
+}
+
INITIALIZE_PASS(
JMCInstrumenter, DEBUG_TYPE,
"Instrument function entry with call to __CheckForDebuggerJustMyCode",
@@ -143,7 +150,7 @@ Function *createDefaultCheckFunction(Module &M, bool UseX86FastCall) {
}
} // namespace
-bool JMCInstrumenter::runOnModule(Module &M) {
+bool runImpl(Module &M) {
bool Changed = false;
LLVMContext &Ctx = M.getContext();
Triple ModuleTriple(M.getTargetTriple());
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index f26450e941870..0608e1b2201ba 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -78,6 +78,7 @@
#include "llvm/CodeGen/ExpandLargeFpConvert.h"
#include "llvm/CodeGen/HardwareLoops.h"
#include "llvm/CodeGen/InterleavedAccess.h"
+#include "llvm/CodeGen/JMCInstrumenter.h"
#include "llvm/CodeGen/SafeStack.h"
#include "llvm/CodeGen/TypePromotion.h"
#include "llvm/CodeGen/WasmEHPrepare.h"
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 56449906eb656..d49e35db87222 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -81,6 +81,7 @@ MODULE_PASS("instrprof", InstrProfilingLoweringPass())
MODULE_PASS("internalize", InternalizePass())
MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
MODULE_PASS("iroutliner", IROutlinerPass())
+MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
MODULE_PASS("lower-global-dtors", LowerGlobalDtorsPass())
MODULE_PASS("lower-ifunc", LowerIFuncPass())
MODULE_PASS("lowertypetests", LowerTypeTestsPass())
diff --git a/llvm/test/Instrumentation/JustMyCode/jmc-instrument-elf.ll b/llvm/test/Instrumentation/JustMyCode/jmc-instrument-elf.ll
index 12ca42703732e..f2889db2b56d1 100644
--- a/llvm/test/Instrumentation/JustMyCode/jmc-instrument-elf.ll
+++ b/llvm/test/Instrumentation/JustMyCode/jmc-instrument-elf.ll
@@ -1,4 +1,5 @@
-; RUN: opt -jmc-instrument -mtriple=x86_64-unknown-linux-gnu -S < %s | FileCheck %s
+; RUN: opt -jmc-instrumenter -mtriple=x86_64-unknown-linux-gnu -S < %s | FileCheck %s
+; RUN: opt -passes=jmc-instrumenter -mtriple=x86_64-unknown-linux-gnu -S < %s | FileCheck %s
; CHECK: @"__7DF23CF5_x at c" = internal unnamed_addr global i8 1, section ".data.just.my.code", align 1, !dbg !0
; CHECK: @"__A8764FDD_x at c" = internal unnamed_addr global i8 1, section ".data.just.my.code", align 1, !dbg !5
diff --git a/llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll b/llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
index c884395bea49b..8a2318eee5e55 100644
--- a/llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
+++ b/llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
@@ -1,4 +1,5 @@
-; RUN: opt -jmc-instrument -S < %s | FileCheck %s
+; RUN: opt -jmc-instrumenter -S < %s | FileCheck %s
+; RUN: opt -passes=jmc-instrumenter -S < %s | FileCheck %s
; CHECK: $_JustMyCode_Default = comdat any
diff --git a/llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll b/llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll
index 098ff1b2a958a..acbcc2917ae9e 100644
--- a/llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll
+++ b/llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll
@@ -1,6 +1,9 @@
-; RUN: opt -jmc-instrument -mtriple=x86_64-pc-windows-msvc -S < %s | FileCheck %s
-; RUN: opt -jmc-instrument -mtriple=aarch64-pc-windows-msvc -S < %s | FileCheck %s
-; RUN: opt -jmc-instrument -mtriple=arm-pc-windows-msvc -S < %s | FileCheck %s
+; RUN: opt -jmc-instrumenter -mtriple=x86_64-pc-windows-msvc -S < %s | FileCheck %s
+; RUN: opt -jmc-instrumenter -mtriple=aarch64-pc-windows-msvc -S < %s | FileCheck %s
+; RUN: opt -jmc-instrumenter -mtriple=arm-pc-windows-msvc -S < %s | FileCheck %s
+; RUN: opt -passes=jmc-instrumenter -mtriple=x86_64-pc-windows-msvc -S < %s | FileCheck %s
+; RUN: opt -passes=jmc-instrumenter -mtriple=aarch64-pc-windows-msvc -S < %s | FileCheck %s
+; RUN: opt -passes=jmc-instrumenter -mtriple=arm-pc-windows-msvc -S < %s | FileCheck %s
; CHECK: $__JustMyCode_Default = comdat any
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index 50b36dc742677..8d26580d8f381 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -364,7 +364,7 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) {
"polyhedral-info",
"print-polyhedral-info",
"replace-with-veclib",
- "jmc-instrument",
+ "jmc-instrumenter",
"dot-regions",
"dot-regions-only",
"view-regions",
More information about the llvm-commits
mailing list