[cfe-commits] r150615 - in /cfe/trunk: lib/Basic/DiagnosticIDs.cpp utils/TableGen/ClangDiagnosticsEmitter.cpp
Benjamin Kramer
benny.kra at googlemail.com
Wed Feb 15 12:57:04 PST 2012
Author: d0k
Date: Wed Feb 15 14:57:03 2012
New Revision: 150615
URL: http://llvm.org/viewvc/llvm-project?rev=150615&view=rev
Log:
Store the warning option corresponding to a diagnostics as an index into the option table instead of storing the name.
Another 8 bytes + relocation removed from every diagnostic on x86_64.
Modified:
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=150615&r1=150614&r2=150615&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Wed Feb 15 14:57:03 2012
@@ -52,16 +52,13 @@
unsigned WarnShowInSystemHeader : 1;
unsigned Category : 5;
- uint8_t OptionGroupLen;
+ uint16_t OptionGroupIndex;
uint16_t DescriptionLen;
-
- const char *OptionGroupStr;
-
const char *DescriptionStr;
- StringRef getOptionGroup() const {
- return StringRef(OptionGroupStr, OptionGroupLen);
+ unsigned getOptionGroupIndex() const {
+ return OptionGroupIndex;
}
StringRef getDescription() const {
@@ -89,10 +86,8 @@
SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER, \
CATEGORY) \
{ diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, ACCESS, \
- NOWERROR, SHOWINSYSHEADER, CATEGORY, \
- STR_SIZE(GROUP, uint8_t), \
- STR_SIZE(DESC, uint16_t), \
- GROUP, DESC },
+ NOWERROR, SHOWINSYSHEADER, CATEGORY, GROUP, \
+ STR_SIZE(DESC, uint16_t), DESC },
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
@@ -103,7 +98,7 @@
#include "clang/Basic/DiagnosticSemaKinds.inc"
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
#undef DIAG
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
static const unsigned StaticDiagInfoSize =
@@ -130,7 +125,7 @@
// Search the diagnostic table with a binary search.
StaticDiagInfoRec Find = { static_cast<unsigned short>(DiagID),
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const StaticDiagInfoRec *Found =
std::lower_bound(StaticDiagInfo, StaticDiagInfo + StaticDiagInfoSize, Find);
@@ -164,15 +159,6 @@
return Info;
}
-/// getWarningOptionForDiag - Return the lowest-level warning option that
-/// enables the specified diagnostic. If there is no -Wfoo flag that controls
-/// the diagnostic, this returns null.
-StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
- if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
- return Info->getOptionGroup();
- return StringRef();
-}
-
/// getCategoryNumberForDiag - Return the category number that a specified
/// DiagID belongs to, or 0 if no category.
unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) {
@@ -531,6 +517,15 @@
return LHS.getName() < RHS.getName();
}
+/// getWarningOptionForDiag - Return the lowest-level warning option that
+/// enables the specified diagnostic. If there is no -Wfoo flag that controls
+/// the diagnostic, this returns null.
+StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
+ if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
+ return OptionTable[Info->getOptionGroupIndex()].getName();
+ return StringRef();
+}
+
void DiagnosticIDs::getDiagnosticsInGroup(
const WarningOption *Group,
llvm::SmallVectorImpl<diag::kind> &Diags) const
Modified: cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp?rev=150615&r1=150614&r2=150615&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp Wed Feb 15 14:57:03 2012
@@ -21,6 +21,7 @@
#include <map>
#include <algorithm>
#include <functional>
+#include <set>
using namespace llvm;
//===----------------------------------------------------------------------===//
@@ -138,7 +139,21 @@
const std::vector<Record*> &Diags =
Records.getAllDerivedDefinitions("Diagnostic");
-
+
+ // Make a sorted set of all warning opts so we can get the index.
+ std::set<std::string> WarningOpts;
+ for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
+ const Record *R = Diags[i];
+ DefInit *DI = dynamic_cast<DefInit*>(R->getValueInit("Group"));
+ if (DI)
+ WarningOpts.insert(DI->getDef()->getValueAsString("GroupName"));
+ }
+
+ std::vector<Record*> DiagGroups
+ = Records.getAllDerivedDefinitions("DiagGroup");
+ for (unsigned i = 0, e = DiagGroups.size(); i != e; ++i)
+ WarningOpts.insert(DiagGroups[i]->getValueAsString("GroupName"));
+
DiagCategoryIDMap CategoryIDs(Records);
DiagGroupParentMap DGParentMap(Records);
@@ -156,12 +171,15 @@
OS << ", \"";
OS.write_escaped(R.getValueAsString("Text")) << '"';
- // Warning associated with the diagnostic.
+ // Warning associated with the diagnostic. This is stored as an index into
+ // the alphabetically sorted warning table.
if (DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group"))) {
- OS << ", \"";
- OS.write_escaped(DI->getDef()->getValueAsString("GroupName")) << '"';
+ std::set<std::string>::iterator I =
+ WarningOpts.find(DI->getDef()->getValueAsString("GroupName"));
+ assert(I != WarningOpts.end());
+ OS << ", " << std::distance(WarningOpts.begin(), I);
} else {
- OS << ", \"\"";
+ OS << ", 0";
}
// SFINAE bit
More information about the cfe-commits
mailing list