[llvm-commits] [llvm] r73076 - /llvm/trunk/utils/TableGen/Record.cpp

David Greene greened at obbligato.org
Mon Jun 8 12:16:56 PDT 2009


Author: greened
Date: Mon Jun  8 14:16:56 2009
New Revision: 73076

URL: http://llvm.org/viewvc/llvm-project?rev=73076&view=rev
Log:

Make !if short-circuit when possible.

Modified:
    llvm/trunk/utils/TableGen/Record.cpp

Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=73076&r1=73075&r2=73076&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Mon Jun  8 14:16:56 2009
@@ -965,9 +965,25 @@
 
 Init *TernOpInit::resolveReferences(Record &R, const RecordVal *RV) {
   Init *lhs = LHS->resolveReferences(R, RV);
+
+  if (Opc == IF && lhs != LHS) {
+    IntInit *Value = dynamic_cast<IntInit*>(lhs);
+    if (Value != 0) {
+      // Short-circuit
+      if (Value->getValue()) {
+        Init *mhs = MHS->resolveReferences(R, RV);
+        return (new TernOpInit(getOpcode(), lhs, mhs, RHS, getType()))->Fold(&R, 0);
+      }
+      else {
+        Init *rhs = RHS->resolveReferences(R, RV);
+        return (new TernOpInit(getOpcode(), lhs, MHS, rhs, getType()))->Fold(&R, 0);
+      }
+    }
+  }
+  
   Init *mhs = MHS->resolveReferences(R, RV);
   Init *rhs = RHS->resolveReferences(R, RV);
-  
+
   if (LHS != lhs || MHS != mhs || RHS != rhs)
     return (new TernOpInit(getOpcode(), lhs, mhs, rhs, getType()))->Fold(&R, 0);
   return Fold(&R, 0);





More information about the llvm-commits mailing list