[llvm-commits] CVS: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp Interpreter.h
Reid Spencer
reid at x10sys.com
Tue Nov 7 22:48:13 PST 2006
Changes in directory llvm/lib/ExecutionEngine/Interpreter:
Execution.cpp updated: 1.145 -> 1.146
Interpreter.h updated: 1.75 -> 1.76
---
Log message:
For PR950: http://llvm.org/PR950 :
This patch converts the old SHR instruction into two instructions,
AShr (Arithmetic) and LShr (Logical). The Shr instructions now are not
dependent on the sign of their operands.
---
Diffs of the changes: (+52 -20)
Execution.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++----------------
Interpreter.h | 3 +-
2 files changed, 52 insertions(+), 20 deletions(-)
Index: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
diff -u llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.145 llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.146
--- llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.145 Thu Nov 2 02:12:02 2006
+++ llvm/lib/ExecutionEngine/Interpreter/Execution.cpp Wed Nov 8 00:47:33 2006
@@ -72,8 +72,10 @@
const Type *Ty);
static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
-static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2,
- const Type *Ty);
+static GenericValue executeLShrInst(GenericValue Src1, GenericValue Src2,
+ const Type *Ty);
+static GenericValue executeAShrInst(GenericValue Src1, GenericValue Src2,
+ const Type *Ty);
static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2,
GenericValue Src3);
@@ -161,10 +163,14 @@
return executeShlInst(getOperandValue(CE->getOperand(0), SF),
getOperandValue(CE->getOperand(1), SF),
CE->getOperand(0)->getType());
- case Instruction::Shr:
- return executeShrInst(getOperandValue(CE->getOperand(0), SF),
- getOperandValue(CE->getOperand(1), SF),
- CE->getOperand(0)->getType());
+ case Instruction::LShr:
+ return executeLShrInst(getOperandValue(CE->getOperand(0), SF),
+ getOperandValue(CE->getOperand(1), SF),
+ CE->getOperand(0)->getType());
+ case Instruction::AShr:
+ return executeAShrInst(getOperandValue(CE->getOperand(0), SF),
+ getOperandValue(CE->getOperand(1), SF),
+ CE->getOperand(0)->getType());
case Instruction::Select:
return executeSelectInst(getOperandValue(CE->getOperand(0), SF),
getOperandValue(CE->getOperand(1), SF),
@@ -943,6 +949,10 @@
#define IMPLEMENT_SHIFT(OP, TY) \
case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.UByteVal; break
+#define IMPLEMENT_SIGNLESS_SHIFT(OP, TY1, TY2) \
+ case Type::TY2##TyID: \
+ IMPLEMENT_SHIFT(OP, TY1)
+
static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2,
const Type *Ty) {
GenericValue Dest;
@@ -961,20 +971,31 @@
return Dest;
}
-static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2,
- const Type *Ty) {
+static GenericValue executeLShrInst(GenericValue Src1, GenericValue Src2,
+ const Type *Ty) {
+ GenericValue Dest;
+ switch (Ty->getTypeID()) {
+ IMPLEMENT_SIGNLESS_SHIFT(>>, UByte, SByte);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, UShort, Short);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, UInt, Int);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, ULong, Long);
+ default:
+ std::cout << "Unhandled type for LShr instruction: " << *Ty << "\n";
+ abort();
+ }
+ return Dest;
+}
+
+static GenericValue executeAShrInst(GenericValue Src1, GenericValue Src2,
+ const Type *Ty) {
GenericValue Dest;
switch (Ty->getTypeID()) {
- IMPLEMENT_SHIFT(>>, UByte);
- IMPLEMENT_SHIFT(>>, SByte);
- IMPLEMENT_SHIFT(>>, UShort);
- IMPLEMENT_SHIFT(>>, Short);
- IMPLEMENT_SHIFT(>>, UInt);
- IMPLEMENT_SHIFT(>>, Int);
- IMPLEMENT_SHIFT(>>, ULong);
- IMPLEMENT_SHIFT(>>, Long);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, SByte, UByte);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, Short, UShort);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, Int, UInt);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, Long, ULong);
default:
- std::cout << "Unhandled type for Shr instruction: " << *Ty << "\n";
+ std::cout << "Unhandled type for AShr instruction: " << *Ty << "\n";
abort();
}
return Dest;
@@ -990,13 +1011,23 @@
SetValue(&I, Dest, SF);
}
-void Interpreter::visitShr(ShiftInst &I) {
+void Interpreter::visitLShr(ShiftInst &I) {
+ ExecutionContext &SF = ECStack.back();
+ const Type *Ty = I.getOperand(0)->getType();
+ GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
+ GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
+ GenericValue Dest;
+ Dest = executeLShrInst (Src1, Src2, Ty);
+ SetValue(&I, Dest, SF);
+}
+
+void Interpreter::visitAShr(ShiftInst &I) {
ExecutionContext &SF = ECStack.back();
const Type *Ty = I.getOperand(0)->getType();
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
GenericValue Dest;
- Dest = executeShrInst (Src1, Src2, Ty);
+ Dest = executeAShrInst (Src1, Src2, Ty);
SetValue(&I, Dest, SF);
}
Index: llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
diff -u llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.75 llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.76
--- llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.75 Fri Jun 16 13:08:38 2006
+++ llvm/lib/ExecutionEngine/Interpreter/Interpreter.h Wed Nov 8 00:47:33 2006
@@ -154,7 +154,8 @@
void visitUnreachableInst(UnreachableInst &I);
void visitShl(ShiftInst &I);
- void visitShr(ShiftInst &I);
+ void visitLShr(ShiftInst &I);
+ void visitAShr(ShiftInst &I);
void visitVAArgInst(VAArgInst &I);
void visitInstruction(Instruction &I) {
std::cerr << I;
More information about the llvm-commits
mailing list