Author: Itay Bookstein Date: 2021-11-09T23:57:13+02:00 New Revision: 9efce0baee4bdda9d824716668ac3d3027bfa318
URL: https://github.com/llvm/llvm-project/commit/9efce0baee4bdda9d824716668ac3d3027bfa318 DIFF: https://github.com/llvm/llvm-project/commit/9efce0baee4bdda9d824716668ac3d3027bfa318.diff LOG: [clang] Run LLVM Verifier in modes without CodeGen too 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. * A small bug is fixed in emitIFuncDefinition so that the clang/test/CodeGen/ifunc.c test would pass: the emitIFuncDefinition incorrectly passed the GlobalDecl of the IFunc itself to the call to GetOrCreateLLVMFunction for creating the resolver. Signed-off-by: Itay Bookstein <ibookst...@gmail.com> Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D113352 Added: Modified: clang/lib/CodeGen/BackendUtil.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/test/CodeGen/lto-newpm-pipeline.c Removed: ################################################################################ diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 2d467e8dea81..1f583e639c57 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -487,6 +487,11 @@ static CodeGenFileType getCodeGenFileType(BackendAction Action) { } } +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 +982,7 @@ void EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager( setCommandLineOpts(CodeGenOpts); - bool UsesCodeGen = (Action != Backend_EmitNothing && - Action != Backend_EmitBC && - Action != Backend_EmitLL); + bool UsesCodeGen = actionRequiresCodeGen(Action); CreateTargetMachine(UsesCodeGen); if (UsesCodeGen && !TM) @@ -1006,6 +1009,12 @@ void EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager( CreatePasses(PerModulePasses, PerFunctionPasses); + // Add a verifier pass if requested. We don't have to do this if the action + // requires code generation because there will already be a verifier pass in + // the code-generation pipeline. + if (!UsesCodeGen && CodeGenOpts.VerifyModule) + PerModulePasses.add(createVerifierPass()); + legacy::PassManager CodeGenPasses; CodeGenPasses.add( createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); @@ -1425,6 +1434,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline( MPM.addPass(ModuleMemProfilerPass()); } } + + // Add a verifier pass if requested. We don't have to do this if the action + // requires code generation because there will already be a verifier pass in + // the code-generation pipeline. + if (!actionRequiresCodeGen(Action) && CodeGenOpts.VerifyModule) + MPM.addPass(VerifierPass()); + switch (Action) { case Backend_EmitBC: if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) { @@ -1514,8 +1530,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, 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) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8e4d9dc751dd..d36cff82f9dd 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5034,7 +5034,7 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) { llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType()); llvm::Type *ResolverTy = llvm::GlobalIFunc::getResolverFunctionType(DeclTy); llvm::Constant *Resolver = - GetOrCreateLLVMFunction(IFA->getResolver(), ResolverTy, GD, + GetOrCreateLLVMFunction(IFA->getResolver(), ResolverTy, {}, /*ForVTable=*/false); llvm::GlobalIFunc *GIF = llvm::GlobalIFunc::create(DeclTy, 0, llvm::Function::ExternalLinkage, diff --git a/clang/test/CodeGen/lto-newpm-pipeline.c b/clang/test/CodeGen/lto-newpm-pipeline.c index c2cd3a4720cc..8119c79425ef 100644 --- a/clang/test/CodeGen/lto-newpm-pipeline.c +++ b/clang/test/CodeGen/lto-newpm-pipeline.c @@ -32,6 +32,8 @@ // CHECK-FULL-O0-NEXT: Running pass: CoroCleanupPass // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass // CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass +// CHECK-FULL-O0-NEXT: Running pass: VerifierPass +// CHECK-FULL-O0-NEXT: Running analysis: VerifierAnalysis // CHECK-FULL-O0-NEXT: Running pass: BitcodeWriterPass // CHECK-THIN-O0: Running pass: AlwaysInlinerPass @@ -40,6 +42,8 @@ // CHECK-THIN-O0: Running pass: CoroCleanupPass // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass +// CHECK-THIN-O0-NEXT: Running pass: VerifierPass +// CHECK-THIN-O0-NEXT: Running analysis: VerifierAnalysis // CHECK-THIN-O0-NEXT: Running pass: ThinLTOBitcodeWriterPass // TODO: The LTO pre-link pipeline currently invokes _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits