[PATCH] move IR-level optimization flags into their own struct

Sanjay Patel spatel at rotateright.com
Tue Apr 28 09:21:36 PDT 2015


================
Comment at: include/llvm/CodeGen/SelectionDAGNodes.h:932-988
@@ +931,59 @@
+/// the backend.
+struct SDNodeFlags {
+private:
+  bool NoUnsignedWrap   : 1;
+  bool NoSignedWrap     : 1;
+  bool Exact            : 1;
+  bool UnsafeAlgebra    : 1;
+  bool NoNaNs           : 1;
+  bool NoInfs           : 1;
+  bool NoSignedZeros    : 1;
+  bool AllowReciprocal  : 1;
+
+public:
+  /// Default constructor turns off all optimization flags.
+  SDNodeFlags() {
+    NoUnsignedWrap  = false;
+    NoSignedWrap    = false;
+    Exact           = false;
+    UnsafeAlgebra   = false;
+    NoNaNs          = false;
+    NoInfs          = false;
+    NoSignedZeros   = false;
+    AllowReciprocal = false;
+  }
+
+  // These are mutators for each flag.
+  void setNoUnsignedWrap(bool b)   { NoUnsignedWrap = b;  }
+  void setNoSignedWrap(bool b)     { NoSignedWrap = b;    }
+  void setExact(bool b)            { Exact = b;           }
+  void setUnsafeAlgebra(bool b)    { UnsafeAlgebra = b;   }
+  void setNoNaNs(bool b)           { NoNaNs = b;          }
+  void setNoInfs(bool b)           { NoInfs = b;          }
+  void setNoSignedZeros(bool b)    { NoSignedZeros = b;   }
+  void setAllowReciprocal(bool b)  { AllowReciprocal = b; }
+
+  // These are accessors for each flag.
+  bool hasNoUnsignedWrap() const   { return NoUnsignedWrap;   }
+  bool hasNoSignedWrap() const     { return NoSignedWrap;     }
+  bool hasExact() const            { return Exact;            }
+  bool hasUnsafeAlgebra() const    { return UnsafeAlgebra;    }
+  bool hasNoNaNs()const            { return NoNaNs;           }
+  bool hasNoInfs() const           { return NoInfs;           }
+  bool hasNoSignedZeros() const    { return NoSignedZeros;    }
+  bool hasAllowReciprocal() const  { return AllowReciprocal;  }
+
+  /// Return a raw encoding of the flags.
+  /// This function should only be used to add data to the NodeID value.
+  unsigned getRawFlags() const {
+    return  (NoUnsignedWrap   << 0) |
+            (NoSignedWrap     << 1) |
+            (Exact            << 2) |
+            (UnsafeAlgebra    << 3) |
+            (NoNaNs           << 4) |
+            (NoInfs           << 5) |
+            (NoSignedZeros    << 6) |
+            (AllowReciprocal  << 7) ;
+  }
+};
+
----------------
echristo wrote:
> I know where you're going with this formatting, but I don't know that it really enhances readability any more than just clang formatting it and not worrying about it.
Ok - clang-format would just wrap at 80-cols:

  unsigned getRawFlags() const {
    return (NoUnsignedWrap << 0) | (NoSignedWrap << 1) | (Exact << 2) |
           (UnsafeAlgebra << 3) | (NoNaNs << 4) | (NoInfs << 5) |
           (NoSignedZeros << 6) | (AllowReciprocal << 7);
  }

http://reviews.llvm.org/D9325

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list