[Basic] Change DiagnosticBuilder to use a separate status variable to track whether the builder is active.

- This may seem superflous, but actually this allows the optimizer to more
   easily eliminate the isActive() checks needed by the SemaDiagnosticBuilder
   and DiagnosticBuilder dtors. And by more easily, I mean the current LLVM is
   actually able to do one and not the other. :)

This is good for another 20k code size reduction.

llvm-svn: 152709
This commit is contained in:
Daniel Dunbar
2012-03-14 09:49:36 +00:00
parent d671ab94fe
commit 7be12296fe

View File

@@ -772,10 +772,17 @@ class DiagnosticBuilder {
mutable DiagnosticsEngine *DiagObj;
mutable unsigned NumArgs, NumRanges, NumFixits;
/// \brief Status variable indicating if this diagnostic is still active.
///
// NOTE: This field is redundant with DiagObj (IsActive iff (DiagObj == 0)),
// but LLVM is not currently smart enough to eliminate the null check that
// Emit() would end up with if we used that as our status variable.
mutable bool IsActive;
void operator=(const DiagnosticBuilder&); // DO NOT IMPLEMENT
friend class DiagnosticsEngine;
explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
: DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0) {
: DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0), IsActive(true) {
assert(diagObj && "DiagnosticBuilder requires a valid DiagnosticsEngine!");
}
@@ -789,10 +796,13 @@ protected:
}
/// \brief Clear out the current diagnostic.
void Clear() { DiagObj = 0; }
void Clear() const {
DiagObj = 0;
IsActive = false;
}
/// isActive - Determine whether this diagnostic is still active.
bool isActive() const { return DiagObj != 0; }
bool isActive() const { return IsActive; }
/// \brief Force the diagnostic builder to emit the diagnostic now.
///
@@ -802,9 +812,9 @@ protected:
/// \returns true if a diagnostic was emitted, false if the
/// diagnostic was suppressed.
bool Emit() {
// If DiagObj is null, then its soul was stolen by the copy ctor
// or the user called Emit().
if (DiagObj == 0) return false;
// If this diagnostic is inactive, then its soul was stolen by the copy ctor
// (or by a subclass, as in SemaDiagnosticBuilder).
if (!isActive()) return false;
// When emitting diagnostics, we set the final argument count into
// the DiagnosticsEngine object.
@@ -814,7 +824,7 @@ protected:
bool Result = DiagObj->EmitCurrentDiagnostic();
// This diagnostic is dead.
DiagObj = 0;
Clear();
return Result;
}
@@ -824,7 +834,8 @@ public:
/// input and neuters it.
DiagnosticBuilder(const DiagnosticBuilder &D) {
DiagObj = D.DiagObj;
D.DiagObj = 0;
IsActive = D.IsActive;
D.Clear();
NumArgs = D.NumArgs;
NumRanges = D.NumRanges;
NumFixits = D.NumFixits;