Add a bunch of methods that should have been added a long time ago.
authorChris Lattner <sabre@nondot.org>
Mon, 29 Mar 2004 02:37:53 +0000 (02:37 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 29 Mar 2004 02:37:53 +0000 (02:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12526 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Constants.h
lib/VMCore/Constants.cpp

index 1d4892f118e94e40355d655a9ac51d3e40e39c86..2e471cb5dd3d4523a7690183e610f6585f8b88a6 100644 (file)
@@ -559,6 +559,28 @@ public:
     return getTy(C1->getType(), Opcode, C1, C2);
   }
 
+  /// ConstantExpr::get* - Return some common constants without having to
+  /// specify the full Instruction::OPCODE identifier.
+  ///
+  static Constant *getNeg(Constant *C);
+  static Constant *getNot(Constant *C);
+  static Constant *getAdd(Constant *C1, Constant *C2);
+  static Constant *getSub(Constant *C1, Constant *C2);
+  static Constant *getMul(Constant *C1, Constant *C2);
+  static Constant *getDiv(Constant *C1, Constant *C2);
+  static Constant *getRem(Constant *C1, Constant *C2);
+  static Constant *getAnd(Constant *C1, Constant *C2);
+  static Constant *getOr(Constant *C1, Constant *C2);
+  static Constant *getXor(Constant *C1, Constant *C2);
+  static Constant *getSetEQ(Constant *C1, Constant *C2);
+  static Constant *getSetNE(Constant *C1, Constant *C2);
+  static Constant *getSetLT(Constant *C1, Constant *C2);
+  static Constant *getSetGT(Constant *C1, Constant *C2);
+  static Constant *getSetLE(Constant *C1, Constant *C2);
+  static Constant *getSetGE(Constant *C1, Constant *C2);
+  static Constant *getShl(Constant *C1, Constant *C2);
+  static Constant *getShr(Constant *C1, Constant *C2);
+
   /// Getelementptr form...
   ///
   static Constant *getGetElementPtr(Constant *C,
index fdde9d9e23473213c989587bf1b58a31d25a9a15..21f19b98b11191703f695a48b9189693017d4974 100644 (file)
@@ -309,6 +309,67 @@ ConstantExpr::ConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
     Operands.push_back(Use(IdxList[i], this));
 }
 
+/// ConstantExpr::get* - Return some common constants without having to
+/// specify the full Instruction::OPCODE identifier.
+///
+Constant *ConstantExpr::getNeg(Constant *C) {
+  return get(Instruction::Sub, getNullValue(C->getType()), C);
+}
+Constant *ConstantExpr::getNot(Constant *C) {
+  assert(isa<ConstantIntegral>(C) && "Cannot NOT a nonintegral type!");
+  return get(Instruction::Xor, C,
+             ConstantIntegral::getAllOnesValue(C->getType()));
+}
+Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2) {
+  return get(Instruction::Add, C1, C2);
+}
+Constant *ConstantExpr::getSub(Constant *C1, Constant *C2) {
+  return get(Instruction::Sub, C1, C2);
+}
+Constant *ConstantExpr::getMul(Constant *C1, Constant *C2) {
+  return get(Instruction::Mul, C1, C2);
+}
+Constant *ConstantExpr::getDiv(Constant *C1, Constant *C2) {
+  return get(Instruction::Div, C1, C2);
+}
+Constant *ConstantExpr::getRem(Constant *C1, Constant *C2) {
+  return get(Instruction::Rem, C1, C2);
+}
+Constant *ConstantExpr::getAnd(Constant *C1, Constant *C2) {
+  return get(Instruction::And, C1, C2);
+}
+Constant *ConstantExpr::getOr(Constant *C1, Constant *C2) {
+  return get(Instruction::Or, C1, C2);
+}
+Constant *ConstantExpr::getXor(Constant *C1, Constant *C2) {
+  return get(Instruction::Xor, C1, C2);
+}
+Constant *ConstantExpr::getSetEQ(Constant *C1, Constant *C2) {
+  return get(Instruction::SetEQ, C1, C2);
+}
+Constant *ConstantExpr::getSetNE(Constant *C1, Constant *C2) {
+  return get(Instruction::SetNE, C1, C2);
+}
+Constant *ConstantExpr::getSetLT(Constant *C1, Constant *C2) {
+  return get(Instruction::SetLT, C1, C2);
+}
+Constant *ConstantExpr::getSetGT(Constant *C1, Constant *C2) {
+  return get(Instruction::SetGT, C1, C2);
+}
+Constant *ConstantExpr::getSetLE(Constant *C1, Constant *C2) {
+  return get(Instruction::SetLE, C1, C2);
+}
+Constant *ConstantExpr::getSetGE(Constant *C1, Constant *C2) {
+  return get(Instruction::SetGE, C1, C2);
+}
+Constant *ConstantExpr::getShl(Constant *C1, Constant *C2) {
+  return get(Instruction::Shl, C1, C2);
+}
+Constant *ConstantExpr::getShr(Constant *C1, Constant *C2) {
+  return get(Instruction::Shr, C1, C2);
+}
+
+
 
 
 //===----------------------------------------------------------------------===//