mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Add LLVMContext::emitWarning methods and use them. <rdar://problem/12867368>
When the backend is used from clang, it should produce proper diagnostics instead of just printing messages to errs(). Other clients may also want to register their own error handlers with the LLVMContext, and the same handler should work for warnings in the same way as the existing emitError methods. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171041 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -89,6 +89,12 @@ public:
|
|||||||
void emitError(const Instruction *I, const Twine &ErrorStr);
|
void emitError(const Instruction *I, const Twine &ErrorStr);
|
||||||
void emitError(const Twine &ErrorStr);
|
void emitError(const Twine &ErrorStr);
|
||||||
|
|
||||||
|
/// emitWarning - This is similar to emitError but it emits a warning instead
|
||||||
|
/// of an error.
|
||||||
|
void emitWarning(unsigned LocCookie, const Twine &ErrorStr);
|
||||||
|
void emitWarning(const Instruction *I, const Twine &ErrorStr);
|
||||||
|
void emitWarning(const Twine &ErrorStr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
|
LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
|
||||||
void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;
|
void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;
|
||||||
|
@@ -177,8 +177,8 @@ bool ProfileMetadataLoaderPass::runOnModule(Module &M) {
|
|||||||
unsigned ReadCount = matchEdges(M, PB, Counters);
|
unsigned ReadCount = matchEdges(M, PB, Counters);
|
||||||
|
|
||||||
if (ReadCount != Counters.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
M.getContext().emitWarning("profile information is inconsistent "
|
||||||
<< "the current program!\n";
|
"with the current program");
|
||||||
}
|
}
|
||||||
NumEdgesRead = ReadCount;
|
NumEdgesRead = ReadCount;
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "llvm/Analysis/ProfileInfoLoader.h"
|
#include "llvm/Analysis/ProfileInfoLoader.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/InstrTypes.h"
|
#include "llvm/InstrTypes.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
@@ -170,8 +171,8 @@ bool LoaderPass::runOnModule(Module &M) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ReadCount != Counters.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
M.getContext().emitWarning("profile information is inconsistent "
|
||||||
<< "the current program!\n";
|
"with the current program");
|
||||||
}
|
}
|
||||||
NumEdgesRead = ReadCount;
|
NumEdgesRead = ReadCount;
|
||||||
}
|
}
|
||||||
@@ -218,8 +219,8 @@ bool LoaderPass::runOnModule(Module &M) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ReadCount != Counters.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
M.getContext().emitWarning("profile information is inconsistent "
|
||||||
<< "the current program!\n";
|
"with the current program");
|
||||||
}
|
}
|
||||||
NumEdgesRead = ReadCount;
|
NumEdgesRead = ReadCount;
|
||||||
}
|
}
|
||||||
@@ -239,8 +240,8 @@ bool LoaderPass::runOnModule(Module &M) {
|
|||||||
BlockInformation[F][BB] = (double)Counters[ReadCount++];
|
BlockInformation[F][BB] = (double)Counters[ReadCount++];
|
||||||
}
|
}
|
||||||
if (ReadCount != Counters.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
M.getContext().emitWarning("profile information is inconsistent "
|
||||||
<< "the current program!\n";
|
"with the current program");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,8 +259,8 @@ bool LoaderPass::runOnModule(Module &M) {
|
|||||||
FunctionInformation[F] = (double)Counters[ReadCount++];
|
FunctionInformation[F] = (double)Counters[ReadCount++];
|
||||||
}
|
}
|
||||||
if (ReadCount != Counters.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
M.getContext().emitWarning("profile information is inconsistent "
|
||||||
<< "the current program!\n";
|
"with the current program");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -413,22 +413,30 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Intrinsic::stacksave:
|
case Intrinsic::stacksave:
|
||||||
case Intrinsic::stackrestore: {
|
|
||||||
if (!Warned)
|
if (!Warned)
|
||||||
errs() << "WARNING: this target does not support the llvm.stack"
|
Context.emitWarning("this target does not support the "
|
||||||
<< (Callee->getIntrinsicID() == Intrinsic::stacksave ?
|
"llvm.stacksave intrinsic");
|
||||||
"save" : "restore") << " intrinsic.\n";
|
Warned = true;
|
||||||
|
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Intrinsic::stackrestore:
|
||||||
|
if (!Warned)
|
||||||
|
Context.emitWarning("this target does not support the "
|
||||||
|
"llvm.stackrestore intrinsic");
|
||||||
Warned = true;
|
Warned = true;
|
||||||
if (Callee->getIntrinsicID() == Intrinsic::stacksave)
|
|
||||||
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case Intrinsic::returnaddress:
|
case Intrinsic::returnaddress:
|
||||||
|
Context.emitWarning("this target does not support the "
|
||||||
|
"llvm.returnaddress intrinsic");
|
||||||
|
CI->replaceAllUsesWith(ConstantPointerNull::get(
|
||||||
|
cast<PointerType>(CI->getType())));
|
||||||
|
break;
|
||||||
|
|
||||||
case Intrinsic::frameaddress:
|
case Intrinsic::frameaddress:
|
||||||
errs() << "WARNING: this target does not support the llvm."
|
Context.emitWarning("this target does not support the "
|
||||||
<< (Callee->getIntrinsicID() == Intrinsic::returnaddress ?
|
"llvm.frameaddress intrinsic");
|
||||||
"return" : "frame") << "address intrinsic.\n";
|
|
||||||
CI->replaceAllUsesWith(ConstantPointerNull::get(
|
CI->replaceAllUsesWith(ConstantPointerNull::get(
|
||||||
cast<PointerType>(CI->getType())));
|
cast<PointerType>(CI->getType())));
|
||||||
break;
|
break;
|
||||||
@@ -438,12 +446,12 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
|||||||
|
|
||||||
case Intrinsic::pcmarker:
|
case Intrinsic::pcmarker:
|
||||||
break; // Simply strip out pcmarker on unsupported architectures
|
break; // Simply strip out pcmarker on unsupported architectures
|
||||||
case Intrinsic::readcyclecounter: {
|
case Intrinsic::readcyclecounter:
|
||||||
errs() << "WARNING: this target does not support the llvm.readcyclecoun"
|
Context.emitWarning("this target does not support the "
|
||||||
<< "ter intrinsic. It is being lowered to a constant 0\n";
|
"llvm.readcyclecounter intrinsic; "
|
||||||
|
"it is being lowered to a constant 0");
|
||||||
CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0));
|
CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case Intrinsic::dbg_declare:
|
case Intrinsic::dbg_declare:
|
||||||
break; // Simply strip out debugging intrinsics
|
break; // Simply strip out debugging intrinsics
|
||||||
|
@@ -1154,8 +1154,9 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
|
|||||||
// If we are removing arguments to the function, emit an obnoxious warning.
|
// If we are removing arguments to the function, emit an obnoxious warning.
|
||||||
if (FT->getNumParams() < NumActualArgs) {
|
if (FT->getNumParams() < NumActualArgs) {
|
||||||
if (!FT->isVarArg()) {
|
if (!FT->isVarArg()) {
|
||||||
errs() << "WARNING: While resolving call to function '"
|
FT->getContext().emitWarning("while resolving call to function '" +
|
||||||
<< Callee->getName() << "' arguments were dropped!\n";
|
Callee->getName() +
|
||||||
|
"' arguments were dropped");
|
||||||
} else {
|
} else {
|
||||||
// Add all of the arguments in their promoted form to the arg list.
|
// Add all of the arguments in their promoted form to the arg list.
|
||||||
for (unsigned i = FT->getNumParams(); i != NumActualArgs; ++i, ++AI) {
|
for (unsigned i = FT->getNumParams(); i != NumActualArgs; ++i, ++AI) {
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include "llvm/Transforms/Instrumentation.h"
|
#include "llvm/Transforms/Instrumentation.h"
|
||||||
#include "ProfilingUtils.h"
|
#include "ProfilingUtils.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
@@ -54,8 +55,8 @@ ModulePass *llvm::createEdgeProfilerPass() { return new EdgeProfiler(); }
|
|||||||
bool EdgeProfiler::runOnModule(Module &M) {
|
bool EdgeProfiler::runOnModule(Module &M) {
|
||||||
Function *Main = M.getFunction("main");
|
Function *Main = M.getFunction("main");
|
||||||
if (Main == 0) {
|
if (Main == 0) {
|
||||||
errs() << "WARNING: cannot insert edge profiling into a module"
|
M.getContext().emitWarning("cannot insert edge profiling into a module"
|
||||||
<< " with no main function!\n";
|
" with no main function");
|
||||||
return false; // No main, no instrumentation!
|
return false; // No main, no instrumentation!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "llvm/Analysis/ProfileInfo.h"
|
#include "llvm/Analysis/ProfileInfo.h"
|
||||||
#include "llvm/Analysis/ProfileInfoLoader.h"
|
#include "llvm/Analysis/ProfileInfoLoader.h"
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
@@ -75,8 +76,8 @@ inline static void printEdgeCounter(ProfileInfo::Edge e,
|
|||||||
bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
||||||
Function *Main = M.getFunction("main");
|
Function *Main = M.getFunction("main");
|
||||||
if (Main == 0) {
|
if (Main == 0) {
|
||||||
errs() << "WARNING: cannot insert edge profiling into a module"
|
M.getContext().emitWarning("cannot insert edge profiling into a module"
|
||||||
<< " with no main function!\n";
|
" with no main function");
|
||||||
return false; // No main, no instrumentation!
|
return false; // No main, no instrumentation!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1345,8 +1345,8 @@ bool PathProfiler::runOnModule(Module &M) {
|
|||||||
Main = M.getFunction("MAIN__");
|
Main = M.getFunction("MAIN__");
|
||||||
|
|
||||||
if (!Main) {
|
if (!Main) {
|
||||||
errs() << "WARNING: cannot insert path profiling into a module"
|
Context->emitWarning("cannot insert edge profiling into a module"
|
||||||
<< " with no main function!\n";
|
" with no main function");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -97,16 +97,30 @@ void LLVMContext::emitError(const Twine &ErrorStr) {
|
|||||||
emitError(0U, ErrorStr);
|
emitError(0U, ErrorStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
|
void LLVMContext::emitWarning(const Twine &ErrorStr) {
|
||||||
|
emitWarning(0U, ErrorStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned getSrcLocation(const Instruction *I) {
|
||||||
unsigned LocCookie = 0;
|
unsigned LocCookie = 0;
|
||||||
if (const MDNode *SrcLoc = I->getMetadata("srcloc")) {
|
if (const MDNode *SrcLoc = I->getMetadata("srcloc")) {
|
||||||
if (SrcLoc->getNumOperands() != 0)
|
if (SrcLoc->getNumOperands() != 0)
|
||||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(SrcLoc->getOperand(0)))
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(SrcLoc->getOperand(0)))
|
||||||
LocCookie = CI->getZExtValue();
|
LocCookie = CI->getZExtValue();
|
||||||
}
|
}
|
||||||
|
return LocCookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
|
||||||
|
unsigned LocCookie = getSrcLocation(I);
|
||||||
return emitError(LocCookie, ErrorStr);
|
return emitError(LocCookie, ErrorStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLVMContext::emitWarning(const Instruction *I, const Twine &ErrorStr) {
|
||||||
|
unsigned LocCookie = getSrcLocation(I);
|
||||||
|
return emitWarning(LocCookie, ErrorStr);
|
||||||
|
}
|
||||||
|
|
||||||
void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
|
void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
|
||||||
// If there is no error handler installed, just print the error and exit.
|
// If there is no error handler installed, just print the error and exit.
|
||||||
if (pImpl->InlineAsmDiagHandler == 0) {
|
if (pImpl->InlineAsmDiagHandler == 0) {
|
||||||
@@ -120,6 +134,19 @@ void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
|
|||||||
pImpl->InlineAsmDiagHandler(Diag, pImpl->InlineAsmDiagContext, LocCookie);
|
pImpl->InlineAsmDiagHandler(Diag, pImpl->InlineAsmDiagContext, LocCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLVMContext::emitWarning(unsigned LocCookie, const Twine &ErrorStr) {
|
||||||
|
// If there is no handler installed, just print the warning.
|
||||||
|
if (pImpl->InlineAsmDiagHandler == 0) {
|
||||||
|
errs() << "warning: " << ErrorStr << "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we do have a handler, we can report the warning.
|
||||||
|
SMDiagnostic Diag("", SourceMgr::DK_Warning, ErrorStr.str());
|
||||||
|
|
||||||
|
pImpl->InlineAsmDiagHandler(Diag, pImpl->InlineAsmDiagContext, LocCookie);
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Metadata Kind Uniquing
|
// Metadata Kind Uniquing
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Reference in New Issue
Block a user