summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/Interpreter
diff options
context:
space:
mode:
authorCameron McInally <cameron.mcinally@nyu.edu>2019-06-10 14:38:48 +0000
committerCameron McInally <cameron.mcinally@nyu.edu>2019-06-10 14:38:48 +0000
commitce49e2231bb6096f2a859b939243efdec85c1ca1 (patch)
tree5328daa6ec1cd85efdce4fa0f415beac359de44f /llvm/lib/ExecutionEngine/Interpreter
parent286a47116a8be983aacceefa91259d258429638b (diff)
downloadbcm5719-llvm-ce49e2231bb6096f2a859b939243efdec85c1ca1.tar.gz
bcm5719-llvm-ce49e2231bb6096f2a859b939243efdec85c1ca1.zip
[ExecutionEngine] Add UnaryOperator visitor to the interpreter
This is to support the unary FNeg instruction. Differential Revision: https://reviews.llvm.org/D62881 llvm-svn: 362941
Diffstat (limited to 'llvm/lib/ExecutionEngine/Interpreter')
-rw-r--r--llvm/lib/ExecutionEngine/Interpreter/Execution.cpp52
-rw-r--r--llvm/lib/ExecutionEngine/Interpreter/Interpreter.h1
2 files changed, 53 insertions, 0 deletions
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
index 170f0155e5b..67180f2c21f 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -43,6 +43,58 @@ static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) {
}
//===----------------------------------------------------------------------===//
+// Unary Instruction Implementations
+//===----------------------------------------------------------------------===//
+
+static void executeFNegInst(GenericValue &Dest, GenericValue Src, Type *Ty) {
+ switch (Ty->getTypeID()) {
+ case Type::FloatTyID:
+ Dest.FloatVal = -Src.FloatVal;
+ case Type::DoubleTyID:
+ Dest.DoubleVal = -Src.DoubleVal;
+ default:
+ llvm_unreachable("Unhandled type for FNeg instruction");
+ }
+}
+
+void Interpreter::visitUnaryOperator(UnaryOperator &I) {
+ ExecutionContext &SF = ECStack.back();
+ Type *Ty = I.getOperand(0)->getType();
+ GenericValue Src = getOperandValue(I.getOperand(0), SF);
+ GenericValue R; // Result
+
+ // First process vector operation
+ if (Ty->isVectorTy()) {
+ R.AggregateVal.resize(Src.AggregateVal.size());
+
+ switch(I.getOpcode()) {
+ default:
+ llvm_unreachable("Don't know how to handle this unary operator");
+ break;
+ case Instruction::FNeg:
+ if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) {
+ for (unsigned i = 0; i < R.AggregateVal.size(); ++i)
+ R.AggregateVal[i].FloatVal = -Src.AggregateVal[i].FloatVal;
+ } else if (cast<VectorType>(Ty)->getElementType()->isDoubleTy()) {
+ for (unsigned i = 0; i < R.AggregateVal.size(); ++i)
+ R.AggregateVal[i].DoubleVal = -Src.AggregateVal[i].DoubleVal;
+ } else {
+ llvm_unreachable("Unhandled type for FNeg instruction");
+ }
+ break;
+ }
+ } else {
+ switch (I.getOpcode()) {
+ default:
+ llvm_unreachable("Don't know how to handle this unary operator");
+ break;
+ case Instruction::FNeg: executeFNegInst(R, Src, Ty); break;
+ }
+ }
+ SetValue(&I, R, SF);
+}
+
+//===----------------------------------------------------------------------===//
// Binary Instruction Implementations
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
index 898f1d34ec1..e72d778317d 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
+++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
@@ -124,6 +124,7 @@ public:
void visitSwitchInst(SwitchInst &I);
void visitIndirectBrInst(IndirectBrInst &I);
+ void visitUnaryOperator(UnaryOperator &I);
void visitBinaryOperator(BinaryOperator &I);
void visitICmpInst(ICmpInst &I);
void visitFCmpInst(FCmpInst &I);
OpenPOWER on IntegriCloud