aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-03-29 02:37:53 +0000
committerChris Lattner <sabre@nondot.org>2004-03-29 02:37:53 +0000
commit4dcb5401e4f6248eb546e4da444ba8e8cf306666 (patch)
tree9c04b07b0b04cb4edcb71387bd7b4371400d42fb
parent944cfafe76c9567cab806e8a6f7ad67686dfe717 (diff)
downloadexternal_llvm-4dcb5401e4f6248eb546e4da444ba8e8cf306666.zip
external_llvm-4dcb5401e4f6248eb546e4da444ba8e8cf306666.tar.gz
external_llvm-4dcb5401e4f6248eb546e4da444ba8e8cf306666.tar.bz2
Add a bunch of methods that should have been added a long time ago.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12526 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Constants.h22
-rw-r--r--lib/VMCore/Constants.cpp61
2 files changed, 83 insertions, 0 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 1d4892f..2e471cb 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -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,
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index fdde9d9..21f19b9 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -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);
+}
+
+
//===----------------------------------------------------------------------===//