[llvm-commits] [llvm] r95086 - in /llvm/trunk: include/llvm/Constants.h include/llvm/InstrTypes.h include/llvm/Support/ConstantFolder.h include/llvm/Support/IRBuilder.h include/llvm/Support/NoFolder.h include/llvm/Support/TargetFolder.h lib/VMCore/Constants.cpp lib/VMCore/Instructions.cpp

Duncan Sands baldrick at free.fr
Tue Feb 2 04:53:04 PST 2010


Author: baldrick
Date: Tue Feb  2 06:53:04 2010
New Revision: 95086

URL: http://llvm.org/viewvc/llvm-project?rev=95086&view=rev
Log:
Adding missing methods for creating Add, Mul, Neg and Sub with NUW.

Modified:
    llvm/trunk/include/llvm/Constants.h
    llvm/trunk/include/llvm/InstrTypes.h
    llvm/trunk/include/llvm/Support/ConstantFolder.h
    llvm/trunk/include/llvm/Support/IRBuilder.h
    llvm/trunk/include/llvm/Support/NoFolder.h
    llvm/trunk/include/llvm/Support/TargetFolder.h
    llvm/trunk/lib/VMCore/Constants.cpp
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=95086&r1=95085&r2=95086&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Tue Feb  2 06:53:04 2010
@@ -697,10 +697,13 @@
   static Constant *getBitCast (Constant *C, const Type *Ty);
 
   static Constant *getNSWNeg(Constant *C);
+  static Constant *getNUWNeg(Constant *C);
   static Constant *getNSWAdd(Constant *C1, Constant *C2);
+  static Constant *getNUWAdd(Constant *C1, Constant *C2);
   static Constant *getNSWSub(Constant *C1, Constant *C2);
-  static Constant *getNUWMul(Constant *C1, Constant *C2);
+  static Constant *getNUWSub(Constant *C1, Constant *C2);
   static Constant *getNSWMul(Constant *C1, Constant *C2);
+  static Constant *getNUWMul(Constant *C1, Constant *C2);
   static Constant *getExactSDiv(Constant *C1, Constant *C2);
 
   /// Transparently provide more efficient getOperand methods.

Modified: llvm/trunk/include/llvm/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InstrTypes.h?rev=95086&r1=95085&r2=95086&view=diff

==============================================================================
--- llvm/trunk/include/llvm/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/InstrTypes.h Tue Feb  2 06:53:04 2010
@@ -299,6 +299,27 @@
     return BO;
   }
 
+  /// CreateNUWMul - Create a Mul operator with the NUW flag set.
+  ///
+  static BinaryOperator *CreateNUWMul(Value *V1, Value *V2,
+                                      const Twine &Name = "") {
+    BinaryOperator *BO = CreateMul(V1, V2, Name);
+    BO->setHasNoUnsignedWrap(true);
+    return BO;
+  }
+  static BinaryOperator *CreateNUWMul(Value *V1, Value *V2,
+                                      const Twine &Name, BasicBlock *BB) {
+    BinaryOperator *BO = CreateMul(V1, V2, Name, BB);
+    BO->setHasNoUnsignedWrap(true);
+    return BO;
+  }
+  static BinaryOperator *CreateNUWMul(Value *V1, Value *V2,
+                                      const Twine &Name, Instruction *I) {
+    BinaryOperator *BO = CreateMul(V1, V2, Name, I);
+    BO->setHasNoUnsignedWrap(true);
+    return BO;
+  }
+
   /// CreateExactSDiv - Create an SDiv operator with the exact flag set.
   ///
   static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
@@ -334,6 +355,10 @@
                                       Instruction *InsertBefore = 0);
   static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
                                       BasicBlock *InsertAtEnd);
+  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name = "",
+                                      Instruction *InsertBefore = 0);
+  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
+                                      BasicBlock *InsertAtEnd);
   static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name = "",
                                     Instruction *InsertBefore = 0);
   static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name,

Modified: llvm/trunk/include/llvm/Support/ConstantFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ConstantFolder.h?rev=95086&r1=95085&r2=95086&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/ConstantFolder.h (original)
+++ llvm/trunk/include/llvm/Support/ConstantFolder.h Tue Feb  2 06:53:04 2010
@@ -39,6 +39,9 @@
   Constant *CreateNSWAdd(Constant *LHS, Constant *RHS) const {
     return ConstantExpr::getNSWAdd(LHS, RHS);
   }
+  Constant *CreateNUWAdd(Constant *LHS, Constant *RHS) const {
+    return ConstantExpr::getNUWAdd(LHS, RHS);
+  }
   Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {
     return ConstantExpr::getFAdd(LHS, RHS);
   }
@@ -48,6 +51,9 @@
   Constant *CreateNSWSub(Constant *LHS, Constant *RHS) const {
     return ConstantExpr::getNSWSub(LHS, RHS);
   }
+  Constant *CreateNUWSub(Constant *LHS, Constant *RHS) const {
+    return ConstantExpr::getNUWSub(LHS, RHS);
+  }
   Constant *CreateFSub(Constant *LHS, Constant *RHS) const {
     return ConstantExpr::getFSub(LHS, RHS);
   }
@@ -57,6 +63,9 @@
   Constant *CreateNSWMul(Constant *LHS, Constant *RHS) const {
     return ConstantExpr::getNSWMul(LHS, RHS);
   }
+  Constant *CreateNUWMul(Constant *LHS, Constant *RHS) const {
+    return ConstantExpr::getNUWMul(LHS, RHS);
+  }
   Constant *CreateFMul(Constant *LHS, Constant *RHS) const {
     return ConstantExpr::getFMul(LHS, RHS);
   }
@@ -115,6 +124,9 @@
   Constant *CreateNSWNeg(Constant *C) const {
     return ConstantExpr::getNSWNeg(C);
   }
+  Constant *CreateNUWNeg(Constant *C) const {
+    return ConstantExpr::getNUWNeg(C);
+  }
   Constant *CreateFNeg(Constant *C) const {
     return ConstantExpr::getFNeg(C);
   }

Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=95086&r1=95085&r2=95086&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Tue Feb  2 06:53:04 2010
@@ -318,6 +318,12 @@
         return Folder.CreateNSWAdd(LC, RC);
     return Insert(BinaryOperator::CreateNSWAdd(LHS, RHS), Name);
   }
+  Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
+    if (Constant *LC = dyn_cast<Constant>(LHS))
+      if (Constant *RC = dyn_cast<Constant>(RHS))
+        return Folder.CreateNUWAdd(LC, RC);
+    return Insert(BinaryOperator::CreateNUWAdd(LHS, RHS), Name);
+  }
   Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
     if (Constant *LC = dyn_cast<Constant>(LHS))
       if (Constant *RC = dyn_cast<Constant>(RHS))
@@ -336,6 +342,12 @@
         return Folder.CreateNSWSub(LC, RC);
     return Insert(BinaryOperator::CreateNSWSub(LHS, RHS), Name);
   }
+  Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
+    if (Constant *LC = dyn_cast<Constant>(LHS))
+      if (Constant *RC = dyn_cast<Constant>(RHS))
+        return Folder.CreateNUWSub(LC, RC);
+    return Insert(BinaryOperator::CreateNUWSub(LHS, RHS), Name);
+  }
   Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "") {
     if (Constant *LC = dyn_cast<Constant>(LHS))
       if (Constant *RC = dyn_cast<Constant>(RHS))
@@ -354,6 +366,12 @@
         return Folder.CreateNSWMul(LC, RC);
     return Insert(BinaryOperator::CreateNSWMul(LHS, RHS), Name);
   }
+  Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
+    if (Constant *LC = dyn_cast<Constant>(LHS))
+      if (Constant *RC = dyn_cast<Constant>(RHS))
+        return Folder.CreateNUWMul(LC, RC);
+    return Insert(BinaryOperator::CreateNUWMul(LHS, RHS), Name);
+  }
   Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "") {
     if (Constant *LC = dyn_cast<Constant>(LHS))
       if (Constant *RC = dyn_cast<Constant>(RHS))
@@ -484,6 +502,11 @@
       return Folder.CreateNSWNeg(VC);
     return Insert(BinaryOperator::CreateNSWNeg(V), Name);
   }
+  Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
+    if (Constant *VC = dyn_cast<Constant>(V))
+      return Folder.CreateNUWNeg(VC);
+    return Insert(BinaryOperator::CreateNUWNeg(V), Name);
+  }
   Value *CreateFNeg(Value *V, const Twine &Name = "") {
     if (Constant *VC = dyn_cast<Constant>(V))
       return Folder.CreateFNeg(VC);

Modified: llvm/trunk/include/llvm/Support/NoFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/NoFolder.h?rev=95086&r1=95085&r2=95086&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/NoFolder.h (original)
+++ llvm/trunk/include/llvm/Support/NoFolder.h Tue Feb  2 06:53:04 2010
@@ -45,6 +45,9 @@
   Value *CreateNSWAdd(Constant *LHS, Constant *RHS) const {
     return BinaryOperator::CreateNSWAdd(LHS, RHS);
   }
+  Value *CreateNUWAdd(Constant *LHS, Constant *RHS) const {
+    return BinaryOperator::CreateNUWAdd(LHS, RHS);
+  }
   Value *CreateFAdd(Constant *LHS, Constant *RHS) const {
     return BinaryOperator::CreateFAdd(LHS, RHS);
   }
@@ -54,6 +57,9 @@
   Value *CreateNSWSub(Constant *LHS, Constant *RHS) const {
     return BinaryOperator::CreateNSWSub(LHS, RHS);
   }
+  Value *CreateNUWSub(Constant *LHS, Constant *RHS) const {
+    return BinaryOperator::CreateNUWSub(LHS, RHS);
+  }
   Value *CreateFSub(Constant *LHS, Constant *RHS) const {
     return BinaryOperator::CreateFSub(LHS, RHS);
   }
@@ -63,6 +69,9 @@
   Value *CreateNSWMul(Constant *LHS, Constant *RHS) const {
     return BinaryOperator::CreateNSWMul(LHS, RHS);
   }
+  Value *CreateNUWMul(Constant *LHS, Constant *RHS) const {
+    return BinaryOperator::CreateNUWMul(LHS, RHS);
+  }
   Value *CreateFMul(Constant *LHS, Constant *RHS) const {
     return BinaryOperator::CreateFMul(LHS, RHS);
   }
@@ -121,6 +130,9 @@
   Value *CreateNSWNeg(Constant *C) const {
     return BinaryOperator::CreateNSWNeg(C);
   }
+  Value *CreateNUWNeg(Constant *C) const {
+    return BinaryOperator::CreateNUWNeg(C);
+  }
   Value *CreateNot(Constant *C) const {
     return BinaryOperator::CreateNot(C);
   }

Modified: llvm/trunk/include/llvm/Support/TargetFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetFolder.h?rev=95086&r1=95085&r2=95086&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/TargetFolder.h (original)
+++ llvm/trunk/include/llvm/Support/TargetFolder.h Tue Feb  2 06:53:04 2010
@@ -52,6 +52,9 @@
   Constant *CreateNSWAdd(Constant *LHS, Constant *RHS) const {
     return Fold(ConstantExpr::getNSWAdd(LHS, RHS));
   }
+  Constant *CreateNUWAdd(Constant *LHS, Constant *RHS) const {
+    return Fold(ConstantExpr::getNUWAdd(LHS, RHS));
+  }
   Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {
     return Fold(ConstantExpr::getFAdd(LHS, RHS));
   }
@@ -61,6 +64,9 @@
   Constant *CreateNSWSub(Constant *LHS, Constant *RHS) const {
     return Fold(ConstantExpr::getNSWSub(LHS, RHS));
   }
+  Constant *CreateNUWSub(Constant *LHS, Constant *RHS) const {
+    return Fold(ConstantExpr::getNUWSub(LHS, RHS));
+  }
   Constant *CreateFSub(Constant *LHS, Constant *RHS) const {
     return Fold(ConstantExpr::getFSub(LHS, RHS));
   }
@@ -70,6 +76,9 @@
   Constant *CreateNSWMul(Constant *LHS, Constant *RHS) const {
     return Fold(ConstantExpr::getNSWMul(LHS, RHS));
   }
+  Constant *CreateNUWMul(Constant *LHS, Constant *RHS) const {
+    return Fold(ConstantExpr::getNUWMul(LHS, RHS));
+  }
   Constant *CreateFMul(Constant *LHS, Constant *RHS) const {
     return Fold(ConstantExpr::getFMul(LHS, RHS));
   }
@@ -128,6 +137,9 @@
   Constant *CreateNSWNeg(Constant *C) const {
     return Fold(ConstantExpr::getNSWNeg(C));
   }
+  Constant *CreateNUWNeg(Constant *C) const {
+    return Fold(ConstantExpr::getNUWNeg(C));
+  }
   Constant *CreateFNeg(Constant *C) const {
     return Fold(ConstantExpr::getFNeg(C));
   }

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=95086&r1=95085&r2=95086&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Tue Feb  2 06:53:04 2010
@@ -645,18 +645,29 @@
   return getNSWSub(ConstantFP::getZeroValueForNegation(C->getType()), C);
 }
 
+Constant* ConstantExpr::getNUWNeg(Constant* C) {
+  assert(C->getType()->isIntOrIntVector() &&
+         "Cannot NEG a nonintegral value!");
+  return getNUWSub(ConstantFP::getZeroValueForNegation(C->getType()), C);
+}
+
 Constant* ConstantExpr::getNSWAdd(Constant* C1, Constant* C2) {
   return getTy(C1->getType(), Instruction::Add, C1, C2,
                OverflowingBinaryOperator::NoSignedWrap);
 }
 
+Constant* ConstantExpr::getNUWAdd(Constant* C1, Constant* C2) {
+  return getTy(C1->getType(), Instruction::Add, C1, C2,
+               OverflowingBinaryOperator::NoUnsignedWrap);
+}
+
 Constant* ConstantExpr::getNSWSub(Constant* C1, Constant* C2) {
   return getTy(C1->getType(), Instruction::Sub, C1, C2,
                OverflowingBinaryOperator::NoSignedWrap);
 }
 
-Constant* ConstantExpr::getNUWMul(Constant* C1, Constant* C2) {
-  return getTy(C1->getType(), Instruction::Mul, C1, C2,
+Constant* ConstantExpr::getNUWSub(Constant* C1, Constant* C2) {
+  return getTy(C1->getType(), Instruction::Sub, C1, C2,
                OverflowingBinaryOperator::NoUnsignedWrap);
 }
 
@@ -665,6 +676,11 @@
                OverflowingBinaryOperator::NoSignedWrap);
 }
 
+Constant* ConstantExpr::getNUWMul(Constant* C1, Constant* C2) {
+  return getTy(C1->getType(), Instruction::Mul, C1, C2,
+               OverflowingBinaryOperator::NoUnsignedWrap);
+}
+
 Constant* ConstantExpr::getExactSDiv(Constant* C1, Constant* C2) {
   return getTy(C1->getType(), Instruction::SDiv, C1, C2,
                SDivOperator::IsExact);

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=95086&r1=95085&r2=95086&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Tue Feb  2 06:53:04 2010
@@ -1786,6 +1786,18 @@
   return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertAtEnd);
 }
 
+BinaryOperator *BinaryOperator::CreateNUWNeg(Value *Op, const Twine &Name,
+                                             Instruction *InsertBefore) {
+  Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
+  return BinaryOperator::CreateNUWSub(zero, Op, Name, InsertBefore);
+}
+
+BinaryOperator *BinaryOperator::CreateNUWNeg(Value *Op, const Twine &Name,
+                                             BasicBlock *InsertAtEnd) {
+  Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
+  return BinaryOperator::CreateNUWSub(zero, Op, Name, InsertAtEnd);
+}
+
 BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name,
                                            Instruction *InsertBefore) {
   Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());





More information about the llvm-commits mailing list