Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions llvm/include/llvm/Transforms/Utils/EmitChangedFuncDebugInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===- EmitChangedFuncDebugInfo.h - Emit Additional Debug Info -*- 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
//
//===----------------------------------------------------------------------===//
//
/// \file
/// Emit debug info for changed or new funcs.
//===----------------------------------------------------------------------===//

#ifndef LLVM_TRANSFORMS_UTILS_EMITCHANGEDFUNCDEBUGINFO_H
#define LLVM_TRANSFORMS_UTILS_EMITCHANGEDFUNCDEBUGINFO_H

#include "llvm/IR/PassManager.h"

namespace llvm {

class Module;

// Pass that emits late dwarf.
class EmitChangedFuncDebugInfoPass
: public PassInfoMixin<EmitChangedFuncDebugInfoPass> {
public:
EmitChangedFuncDebugInfoPass() = default;

PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

} // end namespace llvm

#endif // LLVM_TRANSFORMS_UTILS_EMITCHANGEDFUNCDEBUGINFO_H
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
#include "llvm/Transforms/Utils/DXILUpgrade.h"
#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/Transforms/Utils/DeclareRuntimeLibcalls.h"
#include "llvm/Transforms/Utils/EmitChangedFuncDebugInfo.h"
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
#include "llvm/Transforms/Utils/FixIrreducible.h"
#include "llvm/Transforms/Utils/HelloWorld.h"
Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
#include "llvm/Transforms/Utils/CountVisits.h"
#include "llvm/Transforms/Utils/EmitChangedFuncDebugInfo.h"
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
#include "llvm/Transforms/Utils/ExtraPassManager.h"
#include "llvm/Transforms/Utils/InjectTLIMappings.h"
Expand Down Expand Up @@ -1643,9 +1644,12 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
if (PTO.CallGraphProfile && !LTOPreLink)
MPM.addPass(CGProfilePass(isLTOPostLink(LTOPhase)));

// RelLookupTableConverterPass runs later in LTO post-link pipeline.
if (!LTOPreLink)
// RelLookupTableConverterPass and EmitChangedFuncDebugInfoPass run later in
// LTO post-link pipeline.
if (!LTOPreLink) {
MPM.addPass(RelLookupTableConverterPass());
MPM.addPass(EmitChangedFuncDebugInfoPass());
}

return MPM;
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ MODULE_PASS("dfsan", DataFlowSanitizerPass())
MODULE_PASS("dot-callgraph", CallGraphDOTPrinterPass())
MODULE_PASS("dxil-upgrade", DXILUpgradePass())
MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
MODULE_PASS("emit-changed-func-debuginfo", EmitChangedFuncDebugInfoPass())
MODULE_PASS("extract-blocks", BlockExtractorPass({}, false))
MODULE_PASS("expand-variadics",
ExpandVariadicsPass(ExpandVariadicsMode::Disable))
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
Expand Down Expand Up @@ -432,6 +433,16 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
PromoteMemToReg(Allocas, DT, &AC);
}

// If argument(s) are dead (hence removed) or promoted, probably the function
// does not follow standard calling convention anymore. Add DW_CC_nocall to
// DISubroutineType to inform debugger that it may not be safe to call this
// function.
DISubprogram *SP = NF->getSubprogram();
if (SP) {
auto Temp = SP->getType()->cloneWithCC(llvm::dwarf::DW_CC_nocall);
SP->replaceType(MDNode::replaceWithPermanent(std::move(Temp)));
}

return NF;
}

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_llvm_component_library(LLVMTransformUtils
DebugSSAUpdater.cpp
DeclareRuntimeLibcalls.cpp
DemoteRegToStack.cpp
EmitChangedFuncDebugInfo.cpp
DXILUpgrade.cpp
EntryExitInstrumenter.cpp
EscapeEnumerator.cpp
Expand Down
Loading