[PATCH] D153468: [clang][LTO] Add flag to run verifier after every pass
Arthur Eubanks via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 21 14:16:36 PDT 2023
aeubanks created this revision.
aeubanks added a reviewer: tejohnson.
Herald added subscribers: ormris, steven_wu, hiraditya, inglorion.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.
Helps with debugging issues caught by the verifier.
Plumbed through both normal clang compile and ThinLTO.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153468
Files:
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/verify-each.c
llvm/include/llvm/LTO/Config.h
llvm/lib/LTO/LTOBackend.cpp
Index: llvm/lib/LTO/LTOBackend.cpp
===================================================================
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -259,7 +259,8 @@
ModuleAnalysisManager MAM;
PassInstrumentationCallbacks PIC;
- StandardInstrumentations SI(Mod.getContext(), Conf.DebugPassManager);
+ StandardInstrumentations SI(Mod.getContext(), Conf.DebugPassManager,
+ Conf.VerifyEach);
SI.registerCallbacks(PIC, &MAM);
PassBuilder PB(TM, Conf.PTO, PGOOpt, &PIC);
Index: llvm/include/llvm/LTO/Config.h
===================================================================
--- llvm/include/llvm/LTO/Config.h
+++ llvm/include/llvm/LTO/Config.h
@@ -57,6 +57,7 @@
CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
CodeGenFileType CGFileType = CGFT_ObjectFile;
unsigned OptLevel = 2;
+ bool VerifyEach = false;
bool DisableVerify = false;
/// Use the standard optimization pipeline.
Index: clang/test/CodeGen/verify-each.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/verify-each.c
@@ -0,0 +1,17 @@
+// Test to ensure -llvm-verify-each works.
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -O2 -o /dev/null -triple x86_64-unknown-linux-gnu -emit-llvm-bc %s -fdebug-pass-manager 2>&1 | FileCheck %s --check-prefix=NO
+// NO-NOT: Verifying
+
+// RUN: %clang_cc1 -O2 -o /dev/null -triple x86_64-unknown-linux-gnu -emit-llvm-bc %s -fdebug-pass-manager -llvm-verify-each 2>&1 | FileCheck %s
+
+// RUN: %clang_cc1 -O2 -o %t.o -flto=thin -triple x86_64-unknown-linux-gnu -emit-llvm-bc %s -fdebug-pass-manager -llvm-verify-each 2>&1 | FileCheck %s
+// RUN: llvm-lto -thinlto -o %t %t.o
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o /dev/null -x ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager -llvm-verify-each 2>&1 | FileCheck %s
+
+// CHECK: Verifying
+
+void foo(void) {
+}
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -839,7 +839,7 @@
StandardInstrumentations SI(
TheModule->getContext(),
(CodeGenOpts.DebugPassManager || DebugPassStructure),
- /*VerifyEach*/ false, PrintPassOpts);
+ CodeGenOpts.VerifyEach, PrintPassOpts);
SI.registerCallbacks(PIC, &MAM);
PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
@@ -1192,6 +1192,7 @@
Conf.ProfileRemapping = std::move(ProfileRemapping);
Conf.DebugPassManager = CGOpts.DebugPassManager;
+ Conf.VerifyEach = CGOpts.VerifyEach;
Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
Conf.RemarksFilename = CGOpts.OptRecordFile;
Conf.RemarksPasses = CGOpts.OptRecordPasses;
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5737,6 +5737,9 @@
let Flags = [CC1Option, NoDriverOption] in {
+def llvm_verify_each : Flag<["-"], "llvm-verify-each">,
+ HelpText<"Run the LLVM verifier after every LLVM pass">,
+ MarshallingInfoFlag<CodeGenOpts<"VerifyEach">>;
def disable_llvm_verifier : Flag<["-"], "disable-llvm-verifier">,
HelpText<"Don't run the LLVM IR verifier pass">,
MarshallingInfoNegativeFlag<CodeGenOpts<"VerifyModule">>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -322,6 +322,8 @@
CODEGENOPT(VerifyModule , 1, 1) ///< Control whether the module should be run
///< through the LLVM Verifier.
+CODEGENOPT(VerifyEach , 1, 1) ///< Control whether the LLVM verifier
+ ///< should run after every pass.
CODEGENOPT(StackRealignment , 1, 0) ///< Control whether to force stack
///< realignment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153468.533395.patch
Type: text/x-patch
Size: 4089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230621/5f04d59d/attachment-0001.bin>
More information about the cfe-commits
mailing list