aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine/Interpreter
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-11-08 06:47:33 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-11-08 06:47:33 +0000
commit3822ff5c71478c7c90a50ca57045fb676fcb5005 (patch)
tree44d109d0052024ecdbcfceb248446b56a7bfce0f /lib/ExecutionEngine/Interpreter
parent73fb07566b24d43bb116c2ade0297d90ec72490d (diff)
downloadexternal_llvm-3822ff5c71478c7c90a50ca57045fb676fcb5005.zip
external_llvm-3822ff5c71478c7c90a50ca57045fb676fcb5005.tar.gz
external_llvm-3822ff5c71478c7c90a50ca57045fb676fcb5005.tar.bz2
For 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31542 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/Interpreter')
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp69
-rw-r--r--lib/ExecutionEngine/Interpreter/Interpreter.h3
2 files changed, 52 insertions, 20 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index cf41abd..da1fe54 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -72,8 +72,10 @@ static GenericValue executeSetGEInst(GenericValue Src1, GenericValue Src2,
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 @@ GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
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 @@ void Interpreter::visitCallSite(CallSite CS) {
#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 @@ static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2,
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_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(>>, UByte, SByte);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, UShort, Short);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, UInt, Int);
+ IMPLEMENT_SIGNLESS_SHIFT(>>, ULong, Long);
default:
- std::cout << "Unhandled type for Shr instruction: " << *Ty << "\n";
+ 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_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 AShr instruction: " << *Ty << "\n";
abort();
}
return Dest;
@@ -990,13 +1011,23 @@ void Interpreter::visitShl(ShiftInst &I) {
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);
}
diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h
index 1c169b5..ced624f 100644
--- a/lib/ExecutionEngine/Interpreter/Interpreter.h
+++ b/lib/ExecutionEngine/Interpreter/Interpreter.h
@@ -154,7 +154,8 @@ public:
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;