summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-06-27 23:31:34 +0000
committerChris Lattner <sabre@nondot.org>2001-06-27 23:31:34 +0000
commit6bb09d96a05f9cfab4b0ef4a2b834d6ff4e6caa5 (patch)
tree5298e29549e5be67a5e2aca1f8145c7df2ed98d8 /lib
parent3596366bed2ec5e492d994f88ea76829a0e3d657 (diff)
downloadllvm-6bb09d96a05f9cfab4b0ef4a2b834d6ff4e6caa5.tar.gz
llvm-6bb09d96a05f9cfab4b0ef4a2b834d6ff4e6caa5.tar.bz2
llvm-6bb09d96a05f9cfab4b0ef4a2b834d6ff4e6caa5.tar.xz
Add instructions to fold unary and binary instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@87 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/ConstantFold.h32
-rw-r--r--lib/VMCore/ConstantFolding.h32
2 files changed, 64 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.h b/lib/VMCore/ConstantFold.h
index 3227e3995f..4facdc38e1 100644
--- a/lib/VMCore/ConstantFold.h
+++ b/lib/VMCore/ConstantFold.h
@@ -36,6 +36,7 @@
#define LLVM_OPT_CONSTANTHANDLING_H
#include "llvm/ConstPoolVals.h"
+#include "llvm/Instruction.h"
#include "llvm/Type.h"
//===----------------------------------------------------------------------===//
@@ -142,4 +143,35 @@ inline ConstPoolBool *operator<=(const ConstPoolVal &V1,
return Result; // !(V1 > V2)
}
+
+//===----------------------------------------------------------------------===//
+// Implement higher level instruction folding type instructions
+//===----------------------------------------------------------------------===//
+
+inline ConstPoolVal *ConstantFoldUnaryInstruction(unsigned Opcode,
+ ConstPoolVal *V) {
+ switch (Opcode) {
+ case Instruction::Not: return !*V;
+ case Instruction::Neg: return -*V;
+ }
+ return 0;
+}
+
+inline ConstPoolVal *ConstantFoldBinaryInstruction(unsigned Opcode,
+ ConstPoolVal *V1,
+ ConstPoolVal *V2) {
+ switch (Opcode) {
+ case Instruction::Add: return *V1 + *V2;
+ case Instruction::Sub: return *V1 - *V2;
+
+ case Instruction::SetEQ: return *V1 == *V2;
+ case Instruction::SetNE: return *V1 != *V2;
+ case Instruction::SetLE: return *V1 <= *V2;
+ case Instruction::SetGE: return *V1 >= *V2;
+ case Instruction::SetLT: return *V1 < *V2;
+ case Instruction::SetGT: return *V1 > *V2;
+ }
+ return 0;
+}
+
#endif
diff --git a/lib/VMCore/ConstantFolding.h b/lib/VMCore/ConstantFolding.h
index 3227e3995f..4facdc38e1 100644
--- a/lib/VMCore/ConstantFolding.h
+++ b/lib/VMCore/ConstantFolding.h
@@ -36,6 +36,7 @@
#define LLVM_OPT_CONSTANTHANDLING_H
#include "llvm/ConstPoolVals.h"
+#include "llvm/Instruction.h"
#include "llvm/Type.h"
//===----------------------------------------------------------------------===//
@@ -142,4 +143,35 @@ inline ConstPoolBool *operator<=(const ConstPoolVal &V1,
return Result; // !(V1 > V2)
}
+
+//===----------------------------------------------------------------------===//
+// Implement higher level instruction folding type instructions
+//===----------------------------------------------------------------------===//
+
+inline ConstPoolVal *ConstantFoldUnaryInstruction(unsigned Opcode,
+ ConstPoolVal *V) {
+ switch (Opcode) {
+ case Instruction::Not: return !*V;
+ case Instruction::Neg: return -*V;
+ }
+ return 0;
+}
+
+inline ConstPoolVal *ConstantFoldBinaryInstruction(unsigned Opcode,
+ ConstPoolVal *V1,
+ ConstPoolVal *V2) {
+ switch (Opcode) {
+ case Instruction::Add: return *V1 + *V2;
+ case Instruction::Sub: return *V1 - *V2;
+
+ case Instruction::SetEQ: return *V1 == *V2;
+ case Instruction::SetNE: return *V1 != *V2;
+ case Instruction::SetLE: return *V1 <= *V2;
+ case Instruction::SetGE: return *V1 >= *V2;
+ case Instruction::SetLT: return *V1 < *V2;
+ case Instruction::SetGT: return *V1 > *V2;
+ }
+ return 0;
+}
+
#endif