[llvm] r174748 - Revert "Add LLVMContext::emitWarning methods and use them. <rdar://problem/12867368>"

Bob Wilson bob.wilson at apple.com
Fri Feb 8 13:48:30 PST 2013


Author: bwilson
Date: Fri Feb  8 15:48:29 2013
New Revision: 174748

URL: http://llvm.org/viewvc/llvm-project?rev=174748&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/IR/LLVMContext.h
    llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp
    llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp
    llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp
    llvm/trunk/lib/IR/LLVMContext.cpp
    llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp
    llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp
    llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp

Modified: llvm/trunk/include/llvm/IR/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/LLVMContext.h?rev=174748&r1=174747&r2=174748&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/IR/LLVMContext.h Fri Feb  8 15:48:29 2013
@@ -101,12 +101,6 @@ public:
   void emitError(const Instruction *I, 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:
   LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
   void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;

Modified: llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp?rev=174748&r1=174747&r2=174748&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp Fri Feb  8 15:48:29 2013
@@ -177,8 +177,8 @@ bool ProfileMetadataLoaderPass::runOnMod
   unsigned ReadCount = matchEdges(M, PB, Counters);
 
   if (ReadCount != Counters.size()) {
-    M.getContext().emitWarning("profile information is inconsistent "
-                               "with the current program");
+    errs() << "WARNING: profile information is inconsistent with "
+           << "the current program!\n";
   }
   NumEdgesRead = ReadCount;
 

Modified: llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp?rev=174748&r1=174747&r2=174748&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp Fri Feb  8 15:48:29 2013
@@ -19,7 +19,6 @@
 #include "llvm/Analysis/ProfileInfoLoader.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/InstrTypes.h"
-#include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CFG.h"
@@ -171,8 +170,8 @@ bool LoaderPass::runOnModule(Module &M)
       }
     }
     if (ReadCount != Counters.size()) {
-      M.getContext().emitWarning("profile information is inconsistent "
-                                 "with the current program");
+      errs() << "WARNING: profile information is inconsistent with "
+             << "the current program!\n";
     }
     NumEdgesRead = ReadCount;
   }
@@ -219,8 +218,8 @@ bool LoaderPass::runOnModule(Module &M)
       }
     }
     if (ReadCount != Counters.size()) {
-      M.getContext().emitWarning("profile information is inconsistent "
-                                 "with the current program");
+      errs() << "WARNING: profile information is inconsistent with "
+             << "the current program!\n";
     }
     NumEdgesRead = ReadCount;
   }
@@ -240,8 +239,8 @@ bool LoaderPass::runOnModule(Module &M)
           BlockInformation[F][BB] = (double)Counters[ReadCount++];
     }
     if (ReadCount != Counters.size()) {
-      M.getContext().emitWarning("profile information is inconsistent "
-                                 "with the current program");
+      errs() << "WARNING: profile information is inconsistent with "
+             << "the current program!\n";
     }
   }
 
@@ -259,8 +258,8 @@ bool LoaderPass::runOnModule(Module &M)
         FunctionInformation[F] = (double)Counters[ReadCount++];
     }
     if (ReadCount != Counters.size()) {
-      M.getContext().emitWarning("profile information is inconsistent "
-                                 "with the current program");
+      errs() << "WARNING: profile information is inconsistent with "
+             << "the current program!\n";
     }
   }
 

Modified: llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp?rev=174748&r1=174747&r2=174748&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp Fri Feb  8 15:48:29 2013
@@ -413,30 +413,22 @@ void IntrinsicLowering::LowerIntrinsicCa
   }
 
   case Intrinsic::stacksave:
+  case Intrinsic::stackrestore: {
     if (!Warned)
-      Context.emitWarning("this target does not support the "
-                          "llvm.stacksave intrinsic");
-    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");
+      errs() << "WARNING: this target does not support the llvm.stack"
+             << (Callee->getIntrinsicID() == Intrinsic::stacksave ?
+               "save" : "restore") << " intrinsic.\n";
     Warned = true;
+    if (Callee->getIntrinsicID() == Intrinsic::stacksave)
+      CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
     break;
+  }
     
   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:
-    Context.emitWarning("this target does not support the "
-                        "llvm.frameaddress intrinsic");
+    errs() << "WARNING: this target does not support the llvm."
+           << (Callee->getIntrinsicID() == Intrinsic::returnaddress ?
+             "return" : "frame") << "address intrinsic.\n";
     CI->replaceAllUsesWith(ConstantPointerNull::get(
                                             cast<PointerType>(CI->getType())));
     break;
@@ -446,12 +438,12 @@ void IntrinsicLowering::LowerIntrinsicCa
 
   case Intrinsic::pcmarker:
     break;    // Simply strip out pcmarker on unsupported architectures
-  case Intrinsic::readcyclecounter:
-    Context.emitWarning("this target does not support the "
-                        "llvm.readcyclecounter intrinsic; "
-                        "it is being lowered to a constant 0");
+  case Intrinsic::readcyclecounter: {
+    errs() << "WARNING: this target does not support the llvm.readcyclecoun"
+           << "ter intrinsic.  It is being lowered to a constant 0\n";
     CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0));
     break;
+  }
 
   case Intrinsic::dbg_declare:
     break;    // Simply strip out debugging intrinsics

Modified: llvm/trunk/lib/IR/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContext.cpp?rev=174748&r1=174747&r2=174748&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContext.cpp (original)
+++ llvm/trunk/lib/IR/LLVMContext.cpp Fri Feb  8 15:48:29 2013
@@ -95,30 +95,16 @@ void LLVMContext::emitError(const Twine
   emitError(0U, ErrorStr);
 }
 
-void LLVMContext::emitWarning(const Twine &ErrorStr) {
-  emitWarning(0U, ErrorStr);
-}
-
-static unsigned getSrcLocation(const Instruction *I) {
+void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
   unsigned LocCookie = 0;
   if (const MDNode *SrcLoc = I->getMetadata("srcloc")) {
     if (SrcLoc->getNumOperands() != 0)
       if (const ConstantInt *CI = dyn_cast<ConstantInt>(SrcLoc->getOperand(0)))
         LocCookie = CI->getZExtValue();
   }
-  return LocCookie;
-}
-
-void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) {
-  unsigned LocCookie = getSrcLocation(I);
   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) {
   // If there is no error handler installed, just print the error and exit.
   if (pImpl->DiagHandler == 0) {
@@ -131,19 +117,6 @@ void LLVMContext::emitError(unsigned Loc
 
   pImpl->DiagHandler(Diag, pImpl->DiagContext, LocCookie);
 }
-
-void LLVMContext::emitWarning(unsigned LocCookie, const Twine &ErrorStr) {
-  // If there is no handler installed, just print the warning.
-  if (pImpl->DiagHandler == 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->DiagHandler(Diag, pImpl->DiagContext, LocCookie);
-}
 
 //===----------------------------------------------------------------------===//
 // Metadata Kind Uniquing

Modified: llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp?rev=174748&r1=174747&r2=174748&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp Fri Feb  8 15:48:29 2013
@@ -21,7 +21,6 @@
 #include "llvm/Transforms/Instrumentation.h"
 #include "ProfilingUtils.h"
 #include "llvm/ADT/Statistic.h"
-#include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/raw_ostream.h"
@@ -55,8 +54,8 @@ ModulePass *llvm::createEdgeProfilerPass
 bool EdgeProfiler::runOnModule(Module &M) {
   Function *Main = M.getFunction("main");
   if (Main == 0) {
-    M.getContext().emitWarning("cannot insert edge profiling into a module"
-                               " with no main function");
+    errs() << "WARNING: cannot insert edge profiling into a module"
+           << " with no main function!\n";
     return false;  // No main, no instrumentation!
   }
 

Modified: llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp?rev=174748&r1=174747&r2=174748&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp Fri Feb  8 15:48:29 2013
@@ -22,7 +22,6 @@
 #include "llvm/Analysis/ProfileInfo.h"
 #include "llvm/Analysis/ProfileInfoLoader.h"
 #include "llvm/IR/Constants.h"
-#include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Debug.h"
@@ -76,8 +75,8 @@ inline static void printEdgeCounter(Prof
 bool OptimalEdgeProfiler::runOnModule(Module &M) {
   Function *Main = M.getFunction("main");
   if (Main == 0) {
-    M.getContext().emitWarning("cannot insert edge profiling into a module"
-                               " with no main function");
+    errs() << "WARNING: cannot insert edge profiling into a module"
+           << " with no main function!\n";
     return false;  // No main, no instrumentation!
   }
 

Modified: llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp?rev=174748&r1=174747&r2=174748&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp Fri Feb  8 15:48:29 2013
@@ -1345,8 +1345,8 @@ bool PathProfiler::runOnModule(Module &M
     Main = M.getFunction("MAIN__");
 
   if (!Main) {
-    Context->emitWarning("cannot insert edge profiling into a module"
-                         " with no main function");
+    errs() << "WARNING: cannot insert path profiling into a module"
+           << " with no main function!\n";
     return false;
   }
 





More information about the llvm-commits mailing list