[PATCH] D113352: [clang] Run LLVM Verifier in modes without CodeGen too
Itay Bookstein via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 6 15:11:08 PDT 2021
ibookstein created this revision.
ibookstein added reviewers: dblaikie, rjmccall.
Herald added a subscriber: ormris.
ibookstein requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Previously, the Backend_Emit{Nothing,BC,LL} modes did
not run the LLVM verifier since it is usually added via
the TargetMachine::addPassesToEmitFile method according
to the DisableVerify parameter. This is called from
EmitAssemblyHelper::AddEmitPasses, which is only relevant
for BackendAction-s that require CodeGen.
Note:
- In these particular situations the verifier is added to the optimization pipeline rather than the codegen pipeline so that it runs prior to the BC/LL emission pass.
- This change applies to both the old and the new PMs.
- Because the clang tests use -emit-llvm ubiquitously, this change will enable the verifier for them.
Signed-off-by: Itay Bookstein <ibookstein at gmail.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113352
Files:
clang/lib/CodeGen/BackendUtil.cpp
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -487,6 +487,12 @@
}
}
+static bool actionRequiresCodeGen(BackendAction Action) {
+ return Action != Backend_EmitNothing &&
+ Action != Backend_EmitBC &&
+ Action != Backend_EmitLL;
+}
+
static bool initTargetOptions(DiagnosticsEngine &Diags,
llvm::TargetOptions &Options,
const CodeGenOptions &CodeGenOpts,
@@ -977,9 +983,7 @@
setCommandLineOpts(CodeGenOpts);
- bool UsesCodeGen = (Action != Backend_EmitNothing &&
- Action != Backend_EmitBC &&
- Action != Backend_EmitLL);
+ bool UsesCodeGen = actionRequiresCodeGen(Action);
CreateTargetMachine(UsesCodeGen);
if (UsesCodeGen && !TM)
@@ -1006,6 +1010,10 @@
CreatePasses(PerModulePasses, PerFunctionPasses);
+ if (!UsesCodeGen && CodeGenOpts.VerifyModule)
+ // Add it here so that it runs prior to the BC/LL emission pass
+ PerModulePasses.add(createVerifierPass());
+
legacy::PassManager CodeGenPasses;
CodeGenPasses.add(
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
@@ -1425,6 +1433,11 @@
MPM.addPass(ModuleMemProfilerPass());
}
}
+
+ if (!actionRequiresCodeGen(Action) && CodeGenOpts.VerifyModule)
+ // Add it here so that it runs prior to the BC/LL emission pass
+ MPM.addPass(VerifierPass());
+
switch (Action) {
case Backend_EmitBC:
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
@@ -1514,8 +1527,7 @@
TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime : nullptr);
setCommandLineOpts(CodeGenOpts);
- bool RequiresCodeGen = (Action != Backend_EmitNothing &&
- Action != Backend_EmitBC && Action != Backend_EmitLL);
+ bool RequiresCodeGen = actionRequiresCodeGen(Action);
CreateTargetMachine(RequiresCodeGen);
if (RequiresCodeGen && !TM)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113352.385296.patch
Type: text/x-patch
Size: 2080 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211106/2348032e/attachment.bin>
More information about the cfe-commits
mailing list