llvm.org GIT mirror llvm / 5844691
Revert "Add LLVMContext::emitWarning methods and use them. <rdar://problem/12867368>" This reverts r171041. This was a nice idea that didn't work out well. Clang warnings need to be associated with warning groups so that they can be selectively disabled, promoted to errors, etc. This simplistic patch didn't allow for that. Enhancing it to provide some way for the backend to specify a front-end warning type seems like overkill for the few uses of this, at least for now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174748 91177308-0d34-0410-b5e6-96231b3b80d8 Bob Wilson 7 years ago
8 changed file(s) with 33 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
100100 void emitError(const Instruction *I, const Twine &ErrorStr);
101101 void emitError(const Twine &ErrorStr);
102102
103 /// emitWarning - This is similar to emitError but it emits a warning instead
104 /// of an error.
105 void emitWarning(unsigned LocCookie, const Twine &ErrorStr);
106 void emitWarning(const Instruction *I, const Twine &ErrorStr);
107 void emitWarning(const Twine &ErrorStr);
108
109103 private:
110104 LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
111105 void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;
176176 unsigned ReadCount = matchEdges(M, PB, Counters);
177177
178178 if (ReadCount != Counters.size()) {
179 M.getContext().emitWarning("profile information is inconsistent "
180 "with the current program");
179 errs() << "WARNING: profile information is inconsistent with "
180 << "the current program!\n";
181181 }
182182 NumEdgesRead = ReadCount;
183183
1818 #include "llvm/Analysis/ProfileInfoLoader.h"
1919 #include "llvm/IR/BasicBlock.h"
2020 #include "llvm/IR/InstrTypes.h"
21 #include "llvm/IR/LLVMContext.h"
2221 #include "llvm/IR/Module.h"
2322 #include "llvm/Pass.h"
2423 #include "llvm/Support/CFG.h"
170169 }
171170 }
172171 if (ReadCount != Counters.size()) {
173 M.getContext().emitWarning("profile information is inconsistent "
174 "with the current program");
172 errs() << "WARNING: profile information is inconsistent with "
173 << "the current program!\n";
175174 }
176175 NumEdgesRead = ReadCount;
177176 }
218217 }
219218 }
220219 if (ReadCount != Counters.size()) {
221 M.getContext().emitWarning("profile information is inconsistent "
222 "with the current program");
220 errs() << "WARNING: profile information is inconsistent with "
221 << "the current program!\n";
223222 }
224223 NumEdgesRead = ReadCount;
225224 }
239238 BlockInformation[F][BB] = (double)Counters[ReadCount++];
240239 }
241240 if (ReadCount != Counters.size()) {
242 M.getContext().emitWarning("profile information is inconsistent "
243 "with the current program");
241 errs() << "WARNING: profile information is inconsistent with "
242 << "the current program!\n";
244243 }
245244 }
246245
258257 FunctionInformation[F] = (double)Counters[ReadCount++];
259258 }
260259 if (ReadCount != Counters.size()) {
261 M.getContext().emitWarning("profile information is inconsistent "
262 "with the current program");
260 errs() << "WARNING: profile information is inconsistent with "
261 << "the current program!\n";
263262 }
264263 }
265264
412412 }
413413
414414 case Intrinsic::stacksave:
415 case Intrinsic::stackrestore: {
415416 if (!Warned)
416 Context.emitWarning("this target does not support the "
417 "llvm.stacksave intrinsic");
417 errs() << "WARNING: this target does not support the llvm.stack"
418 << (Callee->getIntrinsicID() == Intrinsic::stacksave ?
419 "save" : "restore") << " intrinsic.\n";
418420 Warned = true;
419 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
420 break;
421
422 case Intrinsic::stackrestore:
423 if (!Warned)
424 Context.emitWarning("this target does not support the "
425 "llvm.stackrestore intrinsic");
426 Warned = true;
427 break;
421 if (Callee->getIntrinsicID() == Intrinsic::stacksave)
422 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
423 break;
424 }
428425
429426 case Intrinsic::returnaddress:
430 Context.emitWarning("this target does not support the "
431 "llvm.returnaddress intrinsic");
427 case Intrinsic::frameaddress:
428 errs() << "WARNING: this target does not support the llvm."
429 << (Callee->getIntrinsicID() == Intrinsic::returnaddress ?
430 "return" : "frame") << "address intrinsic.\n";
432431 CI->replaceAllUsesWith(ConstantPointerNull::get(
433432 cast(CI->getType())));
434433 break;
435434
436 case Intrinsic::frameaddress:
437 Context.emitWarning("this target does not support the "
438 "llvm.frameaddress intrinsic");
439 CI->replaceAllUsesWith(ConstantPointerNull::get(
440 cast(CI->getType())));
441 break;
442
443435 case Intrinsic::prefetch:
444436 break; // Simply strip out prefetches on unsupported architectures
445437
446438 case Intrinsic::pcmarker:
447439 break; // Simply strip out pcmarker on unsupported architectures
448 case Intrinsic::readcyclecounter:
449 Context.emitWarning("this target does not support the "
450 "llvm.readcyclecounter intrinsic; "
451 "it is being lowered to a constant 0");
440 case Intrinsic::readcyclecounter: {
441 errs() << "WARNING: this target does not support the llvm.readcyclecoun"
442 << "ter intrinsic. It is being lowered to a constant 0\n";
452443 CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0));
453444 break;
445 }
454446
455447 case Intrinsic::dbg_declare:
456448 break; // Simply strip out debugging intrinsics
9494 emitError(0U, ErrorStr);
9595 }
9696
97 void LLVMContext::emitWarning(const Twine &ErrorStr) {
98 emitWarning(0U, ErrorStr);
99 }
100
101 static unsigned getSrcLocation(const Instruction *I) {
97 void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
10298 unsigned LocCookie = 0;
10399 if (const MDNode *SrcLoc = I->getMetadata("srcloc")) {
104100 if (SrcLoc->getNumOperands() != 0)
105101 if (const ConstantInt *CI = dyn_cast(SrcLoc->getOperand(0)))
106102 LocCookie = CI->getZExtValue();
107103 }
108 return LocCookie;
109 }
110
111 void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
112 unsigned LocCookie = getSrcLocation(I);
113104 return emitError(LocCookie, ErrorStr);
114 }
115
116 void LLVMContext::emitWarning(const Instruction *I, const Twine &ErrorStr) {
117 unsigned LocCookie = getSrcLocation(I);
118 return emitWarning(LocCookie, ErrorStr);
119105 }
120106
121107 void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
127113
128114 // If we do have an error handler, we can report the error and keep going.
129115 SMDiagnostic Diag("", SourceMgr::DK_Error, ErrorStr.str());
130
131 pImpl->DiagHandler(Diag, pImpl->DiagContext, LocCookie);
132 }
133
134 void LLVMContext::emitWarning(unsigned LocCookie, const Twine &ErrorStr) {
135 // If there is no handler installed, just print the warning.
136 if (pImpl->DiagHandler == 0) {
137 errs() << "warning: " << ErrorStr << "\n";
138 return;
139 }
140
141 // If we do have a handler, we can report the warning.
142 SMDiagnostic Diag("", SourceMgr::DK_Warning, ErrorStr.str());
143116
144117 pImpl->DiagHandler(Diag, pImpl->DiagContext, LocCookie);
145118 }
2020 #include "llvm/Transforms/Instrumentation.h"
2121 #include "ProfilingUtils.h"
2222 #include "llvm/ADT/Statistic.h"
23 #include "llvm/IR/LLVMContext.h"
2423 #include "llvm/IR/Module.h"
2524 #include "llvm/Pass.h"
2625 #include "llvm/Support/raw_ostream.h"
5453 bool EdgeProfiler::runOnModule(Module &M) {
5554 Function *Main = M.getFunction("main");
5655 if (Main == 0) {
57 M.getContext().emitWarning("cannot insert edge profiling into a module"
58 " with no main function");
56 errs() << "WARNING: cannot insert edge profiling into a module"
57 << " with no main function!\n";
5958 return false; // No main, no instrumentation!
6059 }
6160
2121 #include "llvm/Analysis/ProfileInfo.h"
2222 #include "llvm/Analysis/ProfileInfoLoader.h"
2323 #include "llvm/IR/Constants.h"
24 #include "llvm/IR/LLVMContext.h"
2524 #include "llvm/IR/Module.h"
2625 #include "llvm/Pass.h"
2726 #include "llvm/Support/Debug.h"
7574 bool OptimalEdgeProfiler::runOnModule(Module &M) {
7675 Function *Main = M.getFunction("main");
7776 if (Main == 0) {
78 M.getContext().emitWarning("cannot insert edge profiling into a module"
79 " with no main function");
77 errs() << "WARNING: cannot insert edge profiling into a module"
78 << " with no main function!\n";
8079 return false; // No main, no instrumentation!
8180 }
8281
13441344 Main = M.getFunction("MAIN__");
13451345
13461346 if (!Main) {
1347 Context->emitWarning("cannot insert edge profiling into a module"
1348 " with no main function");
1347 errs() << "WARNING: cannot insert path profiling into a module"
1348 << " with no main function!\n";
13491349 return false;
13501350 }
13511351