Skip to content

Commit df8598d

Browse files
committed
This reverts r313381
llvm-svn: 313387
1 parent 8b0bbc6 commit df8598d

23 files changed

+248
-417
lines changed

llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ class OptimizationRemarkEmitter {
7878
/// use the extra analysis (1) to filter trivial false positives or (2) to
7979
/// provide more context so that non-trivial false positives can be quickly
8080
/// detected by the user.
81-
bool allowExtraAnalysis(StringRef PassName) const {
82-
return (F->getContext().getDiagnosticsOutputFile() ||
83-
F->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
81+
bool allowExtraAnalysis() const {
82+
// For now, only allow this with -fsave-optimization-record since the -Rpass
83+
// options are handled in the front-end.
84+
return F->getContext().getDiagnosticsOutputFile();
8485
}
8586

8687
private:

llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ class MachineOptimizationRemark : public DiagnosticInfoMIROptimization {
7373

7474
/// \see DiagnosticInfoOptimizationBase::isEnabled.
7575
bool isEnabled() const override {
76-
const Function &Fn = getFunction();
77-
LLVMContext &Ctx = Fn.getContext();
78-
return Ctx.getDiagHandlerPtr()->isPassedOptRemarkEnabled(getPassName());
76+
return OptimizationRemark::isEnabled(getPassName());
7977
}
8078
};
8179

@@ -99,9 +97,7 @@ class MachineOptimizationRemarkMissed : public DiagnosticInfoMIROptimization {
9997

10098
/// \see DiagnosticInfoOptimizationBase::isEnabled.
10199
bool isEnabled() const override {
102-
const Function &Fn = getFunction();
103-
LLVMContext &Ctx = Fn.getContext();
104-
return Ctx.getDiagHandlerPtr()->isMissedOptRemarkEnabled(getPassName());
100+
return OptimizationRemarkMissed::isEnabled(getPassName());
105101
}
106102
};
107103

@@ -125,9 +121,7 @@ class MachineOptimizationRemarkAnalysis : public DiagnosticInfoMIROptimization {
125121

126122
/// \see DiagnosticInfoOptimizationBase::isEnabled.
127123
bool isEnabled() const override {
128-
const Function &Fn = getFunction();
129-
LLVMContext &Ctx = Fn.getContext();
130-
return Ctx.getDiagHandlerPtr()->isAnalysisRemarkEnabled(getPassName());
124+
return OptimizationRemarkAnalysis::isEnabled(getPassName());
131125
}
132126
};
133127

@@ -158,10 +152,10 @@ class MachineOptimizationRemarkEmitter {
158152
/// that are normally too noisy. In this mode, we can use the extra analysis
159153
/// (1) to filter trivial false positives or (2) to provide more context so
160154
/// that non-trivial false positives can be quickly detected by the user.
161-
bool allowExtraAnalysis(StringRef PassName) const {
162-
return (MF.getFunction()->getContext().getDiagnosticsOutputFile() ||
163-
MF.getFunction()->getContext()
164-
.getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
155+
bool allowExtraAnalysis() const {
156+
// For now, only allow this with -fsave-optimization-record since the -Rpass
157+
// options are handled in the front-end.
158+
return MF.getFunction()->getContext().getDiagnosticsOutputFile();
165159
}
166160

167161
private:

llvm/include/llvm/IR/DiagnosticHandler.h

Lines changed: 0 additions & 67 deletions
This file was deleted.

llvm/include/llvm/IR/DiagnosticInfo.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,10 @@ class OptimizationRemark : public DiagnosticInfoIROptimization {
604604
return DI->getKind() == DK_OptimizationRemark;
605605
}
606606

607+
static bool isEnabled(StringRef PassName);
608+
607609
/// \see DiagnosticInfoOptimizationBase::isEnabled.
608-
bool isEnabled() const override;
610+
bool isEnabled() const override { return isEnabled(getPassName()); }
609611

610612
private:
611613
/// This is deprecated now and only used by the function API below.
@@ -645,8 +647,10 @@ class OptimizationRemarkMissed : public DiagnosticInfoIROptimization {
645647
return DI->getKind() == DK_OptimizationRemarkMissed;
646648
}
647649

650+
static bool isEnabled(StringRef PassName);
651+
648652
/// \see DiagnosticInfoOptimizationBase::isEnabled.
649-
bool isEnabled() const override;
653+
bool isEnabled() const override { return isEnabled(getPassName()); }
650654

651655
private:
652656
/// This is deprecated now and only used by the function API below.
@@ -697,8 +701,12 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
697701
return DI->getKind() == DK_OptimizationRemarkAnalysis;
698702
}
699703

704+
static bool isEnabled(StringRef PassName);
705+
700706
/// \see DiagnosticInfoOptimizationBase::isEnabled.
701-
bool isEnabled() const override;
707+
bool isEnabled() const override {
708+
return shouldAlwaysPrint() || isEnabled(getPassName());
709+
}
702710

703711
static const char *AlwaysPrint;
704712

llvm/include/llvm/IR/LLVMContext.h

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define LLVM_IR_LLVMCONTEXT_H
1717

1818
#include "llvm-c/Types.h"
19-
#include "llvm/IR/DiagnosticHandler.h"
2019
#include "llvm/Support/CBindingWrapping.h"
2120
#include "llvm/Support/Options.h"
2221
#include <cstdint>
@@ -168,6 +167,11 @@ class LLVMContext {
168167
using InlineAsmDiagHandlerTy = void (*)(const SMDiagnostic&, void *Context,
169168
unsigned LocCookie);
170169

170+
/// Defines the type of a diagnostic handler.
171+
/// \see LLVMContext::setDiagnosticHandler.
172+
/// \see LLVMContext::diagnose.
173+
using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
174+
171175
/// Defines the type of a yield callback.
172176
/// \see LLVMContext::setYieldCallback.
173177
using YieldCallbackTy = void (*)(LLVMContext *Context, void *OpaqueHandle);
@@ -190,43 +194,26 @@ class LLVMContext {
190194
/// setInlineAsmDiagnosticHandler.
191195
void *getInlineAsmDiagnosticContext() const;
192196

193-
/// setDiagnosticHandlerCallBack - This method sets a handler call back
194-
/// that is invoked when the backend needs to report anything to the user.
195-
/// The first argument is a function pointer and the second is a context pointer
196-
/// that gets passed into the DiagHandler. The third argument should be set to
197+
/// setDiagnosticHandler - This method sets a handler that is invoked
198+
/// when the backend needs to report anything to the user. The first
199+
/// argument is a function pointer and the second is a context pointer that
200+
/// gets passed into the DiagHandler. The third argument should be set to
197201
/// true if the handler only expects enabled diagnostics.
198202
///
199203
/// LLVMContext doesn't take ownership or interpret either of these
200204
/// pointers.
201-
void setDiagnosticHandlerCallBack(
202-
DiagnosticHandler::DiagnosticHandlerTy DiagHandler,
203-
void *DiagContext = nullptr, bool RespectFilters = false);
204-
205-
/// setDiagnosticHandler - This method sets unique_ptr to object of DiagnosticHandler
206-
/// to provide custom diagnostic handling. The first argument is unique_ptr of object
207-
/// of type DiagnosticHandler or a derived of that. The third argument should be
208-
/// set to true if the handler only expects enabled diagnostics.
209-
///
210-
/// Ownership of this pointer is moved to LLVMContextImpl.
211-
void setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH,
205+
void setDiagnosticHandler(DiagnosticHandlerTy DiagHandler,
206+
void *DiagContext = nullptr,
212207
bool RespectFilters = false);
213208

214-
/// getDiagnosticHandlerCallBack - Return the diagnostic handler call back set by
215-
/// setDiagnosticHandlerCallBack.
216-
DiagnosticHandler::DiagnosticHandlerTy getDiagnosticHandlerCallBack() const;
209+
/// getDiagnosticHandler - Return the diagnostic handler set by
210+
/// setDiagnosticHandler.
211+
DiagnosticHandlerTy getDiagnosticHandler() const;
217212

218213
/// getDiagnosticContext - Return the diagnostic context set by
219214
/// setDiagnosticContext.
220215
void *getDiagnosticContext() const;
221216

222-
/// getDiagHandlerPtr - Returns const raw pointer of DiagnosticHandler set by
223-
/// setDiagnosticHandler.
224-
const DiagnosticHandler *getDiagHandlerPtr() const;
225-
226-
/// getDiagnosticHandler - transfers owenership of DiagnosticHandler unique_ptr
227-
/// to caller.
228-
std::unique_ptr<DiagnosticHandler> getDiagnosticHandler();
229-
230217
/// \brief Return if a code hotness metric should be included in optimization
231218
/// diagnostics.
232219
bool getDiagnosticsHotnessRequested() const;

llvm/include/llvm/LTO/Config.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,27 +171,20 @@ struct Config {
171171
bool UseInputModulePath = false);
172172
};
173173

174-
struct LTOLLVMDiagnosticHandler : public DiagnosticHandler {
175-
DiagnosticHandlerFunction *Fn;
176-
LTOLLVMDiagnosticHandler(DiagnosticHandlerFunction *DiagHandlerFn)
177-
: Fn(DiagHandlerFn) {}
178-
bool handleDiagnostics(const DiagnosticInfo &DI) override {
179-
(*Fn)(DI);
180-
return true;
181-
}
182-
};
183174
/// A derived class of LLVMContext that initializes itself according to a given
184175
/// Config object. The purpose of this class is to tie ownership of the
185176
/// diagnostic handler to the context, as opposed to the Config object (which
186177
/// may be ephemeral).
187-
// FIXME: This should not be required as diagnostic handler is not callback.
188178
struct LTOLLVMContext : LLVMContext {
179+
static void funcDiagHandler(const DiagnosticInfo &DI, void *Context) {
180+
auto *Fn = static_cast<DiagnosticHandlerFunction *>(Context);
181+
(*Fn)(DI);
182+
}
189183

190184
LTOLLVMContext(const Config &C) : DiagHandler(C.DiagHandler) {
191185
setDiscardValueNames(C.ShouldDiscardValueNames);
192186
enableDebugTypeODRUniquing();
193-
setDiagnosticHandler(
194-
llvm::make_unique<LTOLLVMDiagnosticHandler>(&DiagHandler), true);
187+
setDiagnosticHandler(funcDiagHandler, &DiagHandler, true);
195188
}
196189
DiagnosticHandlerFunction DiagHandler;
197190
};

llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ struct LTOCodeGenerator {
184184
LLVMContext &getContext() { return Context; }
185185

186186
void resetMergedModule() { MergedModule.reset(); }
187-
void DiagnosticHandler(const DiagnosticInfo &DI);
188187

189188
private:
190189
void initializeLTOPasses();
@@ -205,6 +204,10 @@ struct LTOCodeGenerator {
205204
bool determineTarget();
206205
std::unique_ptr<TargetMachine> createTargetMachine();
207206

207+
static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context);
208+
209+
void DiagnosticHandler2(const DiagnosticInfo &DI);
210+
208211
void emitError(const std::string &ErrMsg);
209212
void emitWarning(const std::string &ErrMsg);
210213

llvm/lib/IR/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ add_llvm_library(LLVMCore
1717
DebugInfo.cpp
1818
DebugInfoMetadata.cpp
1919
DebugLoc.cpp
20-
DiagnosticHandler.cpp
2120
DiagnosticInfo.cpp
2221
DiagnosticPrinter.cpp
2322
Dominators.cpp

llvm/lib/IR/Core.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ LLVMContextRef LLVMGetGlobalContext() { return wrap(&*GlobalContext); }
8585
void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
8686
LLVMDiagnosticHandler Handler,
8787
void *DiagnosticContext) {
88-
unwrap(C)->setDiagnosticHandlerCallBack(
89-
LLVM_EXTENSION reinterpret_cast<DiagnosticHandler::DiagnosticHandlerTy>(
88+
unwrap(C)->setDiagnosticHandler(
89+
LLVM_EXTENSION reinterpret_cast<LLVMContext::DiagnosticHandlerTy>(
9090
Handler),
9191
DiagnosticContext);
9292
}
9393

9494
LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C) {
9595
return LLVM_EXTENSION reinterpret_cast<LLVMDiagnosticHandler>(
96-
unwrap(C)->getDiagnosticHandlerCallBack());
96+
unwrap(C)->getDiagnosticHandler());
9797
}
9898

9999
void *LLVMContextGetDiagnosticContext(LLVMContextRef C) {

0 commit comments

Comments
 (0)