llvm.org GIT mirror llvm / 2314c6c
[ExecutionEngine] Add UnaryOperator visitor to the interpreter This is to support the unary FNeg instruction. Differential Revision: https://reviews.llvm.org/D62881 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362941 91177308-0d34-0410-b5e6-96231b3b80d8 Cameron McInally 1 year, 5 months ago
3 changed file(s) with 55 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3939
4040 static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) {
4141 SF.Values[V] = Val;
42 }
43
44 //===----------------------------------------------------------------------===//
45 // Unary Instruction Implementations
46 //===----------------------------------------------------------------------===//
47
48 static void executeFNegInst(GenericValue &Dest, GenericValue Src, Type *Ty) {
49 switch (Ty->getTypeID()) {
50 case Type::FloatTyID:
51 Dest.FloatVal = -Src.FloatVal;
52 case Type::DoubleTyID:
53 Dest.DoubleVal = -Src.DoubleVal;
54 default:
55 llvm_unreachable("Unhandled type for FNeg instruction");
56 }
57 }
58
59 void Interpreter::visitUnaryOperator(UnaryOperator &I) {
60 ExecutionContext &SF = ECStack.back();
61 Type *Ty = I.getOperand(0)->getType();
62 GenericValue Src = getOperandValue(I.getOperand(0), SF);
63 GenericValue R; // Result
64
65 // First process vector operation
66 if (Ty->isVectorTy()) {
67 R.AggregateVal.resize(Src.AggregateVal.size());
68
69 switch(I.getOpcode()) {
70 default:
71 llvm_unreachable("Don't know how to handle this unary operator");
72 break;
73 case Instruction::FNeg:
74 if (cast(Ty)->getElementType()->isFloatTy()) {
75 for (unsigned i = 0; i < R.AggregateVal.size(); ++i)
76 R.AggregateVal[i].FloatVal = -Src.AggregateVal[i].FloatVal;
77 } else if (cast(Ty)->getElementType()->isDoubleTy()) {
78 for (unsigned i = 0; i < R.AggregateVal.size(); ++i)
79 R.AggregateVal[i].DoubleVal = -Src.AggregateVal[i].DoubleVal;
80 } else {
81 llvm_unreachable("Unhandled type for FNeg instruction");
82 }
83 break;
84 }
85 } else {
86 switch (I.getOpcode()) {
87 default:
88 llvm_unreachable("Don't know how to handle this unary operator");
89 break;
90 case Instruction::FNeg: executeFNegInst(R, Src, Ty); break;
91 }
92 }
93 SetValue(&I, R, SF);
4294 }
4395
4496 //===----------------------------------------------------------------------===//
123123 void visitSwitchInst(SwitchInst &I);
124124 void visitIndirectBrInst(IndirectBrInst &I);
125125
126 void visitUnaryOperator(UnaryOperator &I);
126127 void visitBinaryOperator(BinaryOperator &I);
127128 void visitICmpInst(ICmpInst &I);
128129 void visitFCmpInst(FCmpInst &I);
77 %C_float = fmul <4 x float> %B_float, %B_float
88 %D_float = fdiv <4 x float> %C_float, %B_float
99 %E_float = frem <4 x float> %D_float, %A_float
10 %F_float = fneg <4 x float> %E_float
1011
1112
1213 %A_double = fadd <3 x double> ,
1415 %C_double = fmul <3 x double> %B_double, %B_double
1516 %D_double = fdiv <3 x double> %C_double, %B_double
1617 %E_double = frem <3 x double> %D_double, %A_double
18 %F_double = fneg <3 x double> %E_double
1719
1820 ret i32 0
1921 }