Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1 | //===-- Execution.cpp - Implement code to simulate the program ------------===// |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 10 | // This file contains the actual instruction interpreter. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "interpreter" |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 15 | #include "Interpreter.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/APInt.h" |
| 17 | #include "llvm/ADT/Statistic.h" |
| 18 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Constants.h" |
| 20 | #include "llvm/IR/DerivedTypes.h" |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 21 | #include "llvm/IR/GetElementPtrTypeIterator.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Instructions.h" |
Chris Lattner | 663ceeb | 2008-07-08 17:25:49 +0000 | [diff] [blame] | 23 | #include "llvm/Support/CommandLine.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Debug.h" |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MathExtras.h" |
Gabor Greif | 724441e | 2007-10-11 19:40:35 +0000 | [diff] [blame] | 27 | #include <algorithm> |
Anton Korobeynikov | ae9f3a3 | 2008-02-20 11:08:44 +0000 | [diff] [blame] | 28 | #include <cmath> |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 29 | using namespace llvm; |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 30 | |
Chris Lattner | cecf56b | 2006-12-19 22:56:53 +0000 | [diff] [blame] | 31 | STATISTIC(NumDynamicInsts, "Number of dynamic instructions executed"); |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 663ceeb | 2008-07-08 17:25:49 +0000 | [diff] [blame] | 33 | static cl::opt<bool> PrintVolatile("interpreter-print-volatile", cl::Hidden, |
| 34 | cl::desc("make the interpreter print every volatile load and store")); |
| 35 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 37 | // Various Helper Functions |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 38 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 40 | static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) { |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 41 | SF.Values[V] = Val; |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Chris Lattner | 2adcd83 | 2002-05-03 19:52:30 +0000 | [diff] [blame] | 44 | //===----------------------------------------------------------------------===// |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 45 | // Binary Instruction Implementations |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | |
| 48 | #define IMPLEMENT_BINARY_OPERATOR(OP, TY) \ |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 49 | case Type::TY##TyID: \ |
| 50 | Dest.TY##Val = Src1.TY##Val OP Src2.TY##Val; \ |
| 51 | break |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 52 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 53 | static void executeFAddInst(GenericValue &Dest, GenericValue Src1, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 54 | GenericValue Src2, Type *Ty) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 55 | switch (Ty->getTypeID()) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 56 | IMPLEMENT_BINARY_OPERATOR(+, Float); |
| 57 | IMPLEMENT_BINARY_OPERATOR(+, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 58 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 59 | dbgs() << "Unhandled type for FAdd instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 60 | llvm_unreachable(0); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 61 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 64 | static void executeFSubInst(GenericValue &Dest, GenericValue Src1, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 65 | GenericValue Src2, Type *Ty) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 66 | switch (Ty->getTypeID()) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 67 | IMPLEMENT_BINARY_OPERATOR(-, Float); |
| 68 | IMPLEMENT_BINARY_OPERATOR(-, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 69 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 70 | dbgs() << "Unhandled type for FSub instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 71 | llvm_unreachable(0); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 72 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 75 | static void executeFMulInst(GenericValue &Dest, GenericValue Src1, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 76 | GenericValue Src2, Type *Ty) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 77 | switch (Ty->getTypeID()) { |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 78 | IMPLEMENT_BINARY_OPERATOR(*, Float); |
| 79 | IMPLEMENT_BINARY_OPERATOR(*, Double); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 80 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 81 | dbgs() << "Unhandled type for FMul instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 82 | llvm_unreachable(0); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 83 | } |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 86 | static void executeFDivInst(GenericValue &Dest, GenericValue Src1, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 87 | GenericValue Src2, Type *Ty) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 88 | switch (Ty->getTypeID()) { |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 89 | IMPLEMENT_BINARY_OPERATOR(/, Float); |
| 90 | IMPLEMENT_BINARY_OPERATOR(/, Double); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 91 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 92 | dbgs() << "Unhandled type for FDiv instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 93 | llvm_unreachable(0); |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 94 | } |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 97 | static void executeFRemInst(GenericValue &Dest, GenericValue Src1, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 98 | GenericValue Src2, Type *Ty) { |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 99 | switch (Ty->getTypeID()) { |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 100 | case Type::FloatTyID: |
| 101 | Dest.FloatVal = fmod(Src1.FloatVal, Src2.FloatVal); |
| 102 | break; |
| 103 | case Type::DoubleTyID: |
| 104 | Dest.DoubleVal = fmod(Src1.DoubleVal, Src2.DoubleVal); |
| 105 | break; |
| 106 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 107 | dbgs() << "Unhandled type for Rem instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 108 | llvm_unreachable(0); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 109 | } |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 112 | #define IMPLEMENT_INTEGER_ICMP(OP, TY) \ |
| 113 | case Type::IntegerTyID: \ |
| 114 | Dest.IntVal = APInt(1,Src1.IntVal.OP(Src2.IntVal)); \ |
| 115 | break; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 116 | |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 117 | #define IMPLEMENT_VECTOR_INTEGER_ICMP(OP, TY) \ |
| 118 | case Type::VectorTyID: { \ |
| 119 | assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); \ |
| 120 | Dest.AggregateVal.resize( Src1.AggregateVal.size() ); \ |
| 121 | for( uint32_t _i=0;_i<Src1.AggregateVal.size();_i++) \ |
| 122 | Dest.AggregateVal[_i].IntVal = APInt(1, \ |
| 123 | Src1.AggregateVal[_i].IntVal.OP(Src2.AggregateVal[_i].IntVal));\ |
| 124 | } break; |
| 125 | |
Chris Lattner | fd506f5 | 2003-04-23 19:55:35 +0000 | [diff] [blame] | 126 | // Handle pointers specially because they must be compared with only as much |
| 127 | // width as the host has. We _do not_ want to be comparing 64 bit values when |
| 128 | // running on a 32-bit target, otherwise the upper 32 bits might mess up |
| 129 | // comparisons if they contain garbage. |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 130 | #define IMPLEMENT_POINTER_ICMP(OP) \ |
Chris Lattner | fd506f5 | 2003-04-23 19:55:35 +0000 | [diff] [blame] | 131 | case Type::PointerTyID: \ |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 132 | Dest.IntVal = APInt(1,(void*)(intptr_t)Src1.PointerVal OP \ |
| 133 | (void*)(intptr_t)Src2.PointerVal); \ |
| 134 | break; |
Chris Lattner | fd506f5 | 2003-04-23 19:55:35 +0000 | [diff] [blame] | 135 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 136 | static GenericValue executeICMP_EQ(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 137 | Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 138 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 139 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 140 | IMPLEMENT_INTEGER_ICMP(eq,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 141 | IMPLEMENT_VECTOR_INTEGER_ICMP(eq,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 142 | IMPLEMENT_POINTER_ICMP(==); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 143 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 144 | dbgs() << "Unhandled type for ICMP_EQ predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 145 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 146 | } |
| 147 | return Dest; |
| 148 | } |
| 149 | |
| 150 | static GenericValue executeICMP_NE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 151 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 152 | GenericValue Dest; |
| 153 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 154 | IMPLEMENT_INTEGER_ICMP(ne,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 155 | IMPLEMENT_VECTOR_INTEGER_ICMP(ne,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 156 | IMPLEMENT_POINTER_ICMP(!=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 157 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 158 | dbgs() << "Unhandled type for ICMP_NE predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 159 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 160 | } |
| 161 | return Dest; |
| 162 | } |
| 163 | |
| 164 | static GenericValue executeICMP_ULT(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 165 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 166 | GenericValue Dest; |
| 167 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 168 | IMPLEMENT_INTEGER_ICMP(ult,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 169 | IMPLEMENT_VECTOR_INTEGER_ICMP(ult,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 170 | IMPLEMENT_POINTER_ICMP(<); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 171 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 172 | dbgs() << "Unhandled type for ICMP_ULT predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 173 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 174 | } |
| 175 | return Dest; |
| 176 | } |
| 177 | |
| 178 | static GenericValue executeICMP_SLT(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 179 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 180 | GenericValue Dest; |
| 181 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 182 | IMPLEMENT_INTEGER_ICMP(slt,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 183 | IMPLEMENT_VECTOR_INTEGER_ICMP(slt,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 184 | IMPLEMENT_POINTER_ICMP(<); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 185 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 186 | dbgs() << "Unhandled type for ICMP_SLT predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 187 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 188 | } |
| 189 | return Dest; |
| 190 | } |
| 191 | |
| 192 | static GenericValue executeICMP_UGT(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 193 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 194 | GenericValue Dest; |
| 195 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 196 | IMPLEMENT_INTEGER_ICMP(ugt,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 197 | IMPLEMENT_VECTOR_INTEGER_ICMP(ugt,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 198 | IMPLEMENT_POINTER_ICMP(>); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 199 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 200 | dbgs() << "Unhandled type for ICMP_UGT predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 201 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 202 | } |
| 203 | return Dest; |
| 204 | } |
| 205 | |
| 206 | static GenericValue executeICMP_SGT(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 207 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 208 | GenericValue Dest; |
| 209 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 210 | IMPLEMENT_INTEGER_ICMP(sgt,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 211 | IMPLEMENT_VECTOR_INTEGER_ICMP(sgt,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 212 | IMPLEMENT_POINTER_ICMP(>); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 213 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 214 | dbgs() << "Unhandled type for ICMP_SGT predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 215 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 216 | } |
| 217 | return Dest; |
| 218 | } |
| 219 | |
| 220 | static GenericValue executeICMP_ULE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 221 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 222 | GenericValue Dest; |
| 223 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 224 | IMPLEMENT_INTEGER_ICMP(ule,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 225 | IMPLEMENT_VECTOR_INTEGER_ICMP(ule,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 226 | IMPLEMENT_POINTER_ICMP(<=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 227 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 228 | dbgs() << "Unhandled type for ICMP_ULE predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 229 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 230 | } |
| 231 | return Dest; |
| 232 | } |
| 233 | |
| 234 | static GenericValue executeICMP_SLE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 235 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 236 | GenericValue Dest; |
| 237 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 238 | IMPLEMENT_INTEGER_ICMP(sle,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 239 | IMPLEMENT_VECTOR_INTEGER_ICMP(sle,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 240 | IMPLEMENT_POINTER_ICMP(<=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 241 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 242 | dbgs() << "Unhandled type for ICMP_SLE predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 243 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 244 | } |
| 245 | return Dest; |
| 246 | } |
| 247 | |
| 248 | static GenericValue executeICMP_UGE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 249 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 250 | GenericValue Dest; |
| 251 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 252 | IMPLEMENT_INTEGER_ICMP(uge,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 253 | IMPLEMENT_VECTOR_INTEGER_ICMP(uge,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 254 | IMPLEMENT_POINTER_ICMP(>=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 255 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 256 | dbgs() << "Unhandled type for ICMP_UGE predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 257 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 258 | } |
| 259 | return Dest; |
| 260 | } |
| 261 | |
| 262 | static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 263 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 264 | GenericValue Dest; |
| 265 | switch (Ty->getTypeID()) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 266 | IMPLEMENT_INTEGER_ICMP(sge,Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 267 | IMPLEMENT_VECTOR_INTEGER_ICMP(sge,Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 268 | IMPLEMENT_POINTER_ICMP(>=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 269 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 270 | dbgs() << "Unhandled type for ICMP_SGE predicate: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 271 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 272 | } |
| 273 | return Dest; |
| 274 | } |
| 275 | |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 276 | void Interpreter::visitICmpInst(ICmpInst &I) { |
| 277 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 278 | Type *Ty = I.getOperand(0)->getType(); |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 279 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 280 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 281 | GenericValue R; // Result |
| 282 | |
| 283 | switch (I.getPredicate()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 284 | case ICmpInst::ICMP_EQ: R = executeICMP_EQ(Src1, Src2, Ty); break; |
| 285 | case ICmpInst::ICMP_NE: R = executeICMP_NE(Src1, Src2, Ty); break; |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 286 | case ICmpInst::ICMP_ULT: R = executeICMP_ULT(Src1, Src2, Ty); break; |
| 287 | case ICmpInst::ICMP_SLT: R = executeICMP_SLT(Src1, Src2, Ty); break; |
| 288 | case ICmpInst::ICMP_UGT: R = executeICMP_UGT(Src1, Src2, Ty); break; |
| 289 | case ICmpInst::ICMP_SGT: R = executeICMP_SGT(Src1, Src2, Ty); break; |
| 290 | case ICmpInst::ICMP_ULE: R = executeICMP_ULE(Src1, Src2, Ty); break; |
| 291 | case ICmpInst::ICMP_SLE: R = executeICMP_SLE(Src1, Src2, Ty); break; |
| 292 | case ICmpInst::ICMP_UGE: R = executeICMP_UGE(Src1, Src2, Ty); break; |
| 293 | case ICmpInst::ICMP_SGE: R = executeICMP_SGE(Src1, Src2, Ty); break; |
| 294 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 295 | dbgs() << "Don't know how to handle this ICmp predicate!\n-->" << I; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 296 | llvm_unreachable(0); |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | SetValue(&I, R, SF); |
| 300 | } |
| 301 | |
| 302 | #define IMPLEMENT_FCMP(OP, TY) \ |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 303 | case Type::TY##TyID: \ |
| 304 | Dest.IntVal = APInt(1,Src1.TY##Val OP Src2.TY##Val); \ |
| 305 | break |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 306 | |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 307 | #define IMPLEMENT_VECTOR_FCMP_T(OP, TY) \ |
| 308 | assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); \ |
| 309 | Dest.AggregateVal.resize( Src1.AggregateVal.size() ); \ |
| 310 | for( uint32_t _i=0;_i<Src1.AggregateVal.size();_i++) \ |
| 311 | Dest.AggregateVal[_i].IntVal = APInt(1, \ |
| 312 | Src1.AggregateVal[_i].TY##Val OP Src2.AggregateVal[_i].TY##Val);\ |
| 313 | break; |
| 314 | |
| 315 | #define IMPLEMENT_VECTOR_FCMP(OP) \ |
| 316 | case Type::VectorTyID: \ |
| 317 | if(dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) { \ |
| 318 | IMPLEMENT_VECTOR_FCMP_T(OP, Float); \ |
| 319 | } else { \ |
| 320 | IMPLEMENT_VECTOR_FCMP_T(OP, Double); \ |
| 321 | } |
| 322 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 323 | static GenericValue executeFCMP_OEQ(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 324 | Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 325 | GenericValue Dest; |
| 326 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 327 | IMPLEMENT_FCMP(==, Float); |
| 328 | IMPLEMENT_FCMP(==, Double); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 329 | IMPLEMENT_VECTOR_FCMP(==); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 330 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 331 | dbgs() << "Unhandled type for FCmp EQ instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 332 | llvm_unreachable(0); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 333 | } |
| 334 | return Dest; |
| 335 | } |
| 336 | |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 337 | #define IMPLEMENT_SCALAR_NANS(TY, X,Y) \ |
| 338 | if (TY->isFloatTy()) { \ |
| 339 | if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \ |
| 340 | Dest.IntVal = APInt(1,false); \ |
| 341 | return Dest; \ |
| 342 | } \ |
| 343 | } else { \ |
| 344 | if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \ |
| 345 | Dest.IntVal = APInt(1,false); \ |
| 346 | return Dest; \ |
| 347 | } \ |
| 348 | } |
| 349 | |
| 350 | #define MASK_VECTOR_NANS_T(X,Y, TZ, FLAG) \ |
| 351 | assert(X.AggregateVal.size() == Y.AggregateVal.size()); \ |
| 352 | Dest.AggregateVal.resize( X.AggregateVal.size() ); \ |
| 353 | for( uint32_t _i=0;_i<X.AggregateVal.size();_i++) { \ |
| 354 | if (X.AggregateVal[_i].TZ##Val != X.AggregateVal[_i].TZ##Val || \ |
| 355 | Y.AggregateVal[_i].TZ##Val != Y.AggregateVal[_i].TZ##Val) \ |
| 356 | Dest.AggregateVal[_i].IntVal = APInt(1,FLAG); \ |
| 357 | else { \ |
| 358 | Dest.AggregateVal[_i].IntVal = APInt(1,!FLAG); \ |
| 359 | } \ |
| 360 | } |
| 361 | |
| 362 | #define MASK_VECTOR_NANS(TY, X,Y, FLAG) \ |
| 363 | if (TY->isVectorTy()) { \ |
| 364 | if (dyn_cast<VectorType>(TY)->getElementType()->isFloatTy()) { \ |
| 365 | MASK_VECTOR_NANS_T(X, Y, Float, FLAG) \ |
| 366 | } else { \ |
| 367 | MASK_VECTOR_NANS_T(X, Y, Double, FLAG) \ |
| 368 | } \ |
| 369 | } \ |
| 370 | |
| 371 | |
| 372 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 373 | static GenericValue executeFCMP_ONE(GenericValue Src1, GenericValue Src2, |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 374 | Type *Ty) |
| 375 | { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 376 | GenericValue Dest; |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 377 | // if input is scalar value and Src1 or Src2 is NaN return false |
| 378 | IMPLEMENT_SCALAR_NANS(Ty, Src1, Src2) |
| 379 | // if vector input detect NaNs and fill mask |
| 380 | MASK_VECTOR_NANS(Ty, Src1, Src2, false) |
| 381 | GenericValue DestMask = Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 382 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 383 | IMPLEMENT_FCMP(!=, Float); |
| 384 | IMPLEMENT_FCMP(!=, Double); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 385 | IMPLEMENT_VECTOR_FCMP(!=); |
| 386 | default: |
| 387 | dbgs() << "Unhandled type for FCmp NE instruction: " << *Ty << "\n"; |
| 388 | llvm_unreachable(0); |
Nadav Rotem | 0fda0f3 | 2013-04-12 22:02:26 +0000 | [diff] [blame] | 389 | } |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 390 | // in vector case mask out NaN elements |
| 391 | if (Ty->isVectorTy()) |
| 392 | for( size_t _i=0; _i<Src1.AggregateVal.size(); _i++) |
| 393 | if (DestMask.AggregateVal[_i].IntVal == false) |
| 394 | Dest.AggregateVal[_i].IntVal = APInt(1,false); |
| 395 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 396 | return Dest; |
| 397 | } |
| 398 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 399 | static GenericValue executeFCMP_OLE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 400 | Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 401 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 402 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 403 | IMPLEMENT_FCMP(<=, Float); |
| 404 | IMPLEMENT_FCMP(<=, Double); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 405 | IMPLEMENT_VECTOR_FCMP(<=); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 406 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 407 | dbgs() << "Unhandled type for FCmp LE instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 408 | llvm_unreachable(0); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 409 | } |
| 410 | return Dest; |
| 411 | } |
| 412 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 413 | static GenericValue executeFCMP_OGE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 414 | Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 415 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 416 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 417 | IMPLEMENT_FCMP(>=, Float); |
| 418 | IMPLEMENT_FCMP(>=, Double); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 419 | IMPLEMENT_VECTOR_FCMP(>=); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 420 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 421 | dbgs() << "Unhandled type for FCmp GE instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 422 | llvm_unreachable(0); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 423 | } |
| 424 | return Dest; |
| 425 | } |
| 426 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 427 | static GenericValue executeFCMP_OLT(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 428 | Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 429 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 430 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 431 | IMPLEMENT_FCMP(<, Float); |
| 432 | IMPLEMENT_FCMP(<, Double); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 433 | IMPLEMENT_VECTOR_FCMP(<); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 434 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 435 | dbgs() << "Unhandled type for FCmp LT instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 436 | llvm_unreachable(0); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 437 | } |
| 438 | return Dest; |
| 439 | } |
| 440 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 441 | static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 442 | Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 443 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 444 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 445 | IMPLEMENT_FCMP(>, Float); |
| 446 | IMPLEMENT_FCMP(>, Double); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 447 | IMPLEMENT_VECTOR_FCMP(>); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 448 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 449 | dbgs() << "Unhandled type for FCmp GT instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 450 | llvm_unreachable(0); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 451 | } |
| 452 | return Dest; |
| 453 | } |
| 454 | |
Anton Korobeynikov | 4c71dfe | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 455 | #define IMPLEMENT_UNORDERED(TY, X,Y) \ |
Chris Lattner | cf0fe8d | 2009-10-05 05:54:46 +0000 | [diff] [blame] | 456 | if (TY->isFloatTy()) { \ |
Anton Korobeynikov | 4c71dfe | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 457 | if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \ |
| 458 | Dest.IntVal = APInt(1,true); \ |
| 459 | return Dest; \ |
| 460 | } \ |
| 461 | } else if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \ |
| 462 | Dest.IntVal = APInt(1,true); \ |
| 463 | return Dest; \ |
| 464 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 465 | |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 466 | #define IMPLEMENT_VECTOR_UNORDERED(TY, X,Y, _FUNC) \ |
| 467 | if (TY->isVectorTy()) { \ |
| 468 | GenericValue DestMask = Dest; \ |
| 469 | Dest = _FUNC(Src1, Src2, Ty); \ |
| 470 | for( size_t _i=0; _i<Src1.AggregateVal.size(); _i++) \ |
| 471 | if (DestMask.AggregateVal[_i].IntVal == true) \ |
| 472 | Dest.AggregateVal[_i].IntVal = APInt(1,true); \ |
| 473 | return Dest; \ |
| 474 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 475 | |
| 476 | static GenericValue executeFCMP_UEQ(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 477 | Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 478 | GenericValue Dest; |
| 479 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 480 | MASK_VECTOR_NANS(Ty, Src1, Src2, true) |
| 481 | IMPLEMENT_VECTOR_UNORDERED(Ty, Src1, Src2, executeFCMP_OEQ) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 482 | return executeFCMP_OEQ(Src1, Src2, Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 483 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static GenericValue executeFCMP_UNE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 487 | Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 488 | GenericValue Dest; |
| 489 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 490 | MASK_VECTOR_NANS(Ty, Src1, Src2, true) |
| 491 | IMPLEMENT_VECTOR_UNORDERED(Ty, Src1, Src2, executeFCMP_ONE) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 492 | return executeFCMP_ONE(Src1, Src2, Ty); |
| 493 | } |
| 494 | |
| 495 | static GenericValue executeFCMP_ULE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 496 | Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 497 | GenericValue Dest; |
| 498 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 499 | MASK_VECTOR_NANS(Ty, Src1, Src2, true) |
| 500 | IMPLEMENT_VECTOR_UNORDERED(Ty, Src1, Src2, executeFCMP_OLE) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 501 | return executeFCMP_OLE(Src1, Src2, Ty); |
| 502 | } |
| 503 | |
| 504 | static GenericValue executeFCMP_UGE(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 505 | Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 506 | GenericValue Dest; |
| 507 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 508 | MASK_VECTOR_NANS(Ty, Src1, Src2, true) |
| 509 | IMPLEMENT_VECTOR_UNORDERED(Ty, Src1, Src2, executeFCMP_OGE) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 510 | return executeFCMP_OGE(Src1, Src2, Ty); |
| 511 | } |
| 512 | |
| 513 | static GenericValue executeFCMP_ULT(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 514 | Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 515 | GenericValue Dest; |
| 516 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 517 | MASK_VECTOR_NANS(Ty, Src1, Src2, true) |
| 518 | IMPLEMENT_VECTOR_UNORDERED(Ty, Src1, Src2, executeFCMP_OLT) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 519 | return executeFCMP_OLT(Src1, Src2, Ty); |
| 520 | } |
| 521 | |
| 522 | static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 523 | Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 524 | GenericValue Dest; |
| 525 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 526 | MASK_VECTOR_NANS(Ty, Src1, Src2, true) |
| 527 | IMPLEMENT_VECTOR_UNORDERED(Ty, Src1, Src2, executeFCMP_OGT) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 528 | return executeFCMP_OGT(Src1, Src2, Ty); |
| 529 | } |
| 530 | |
| 531 | static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 532 | Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 533 | GenericValue Dest; |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 534 | if(Ty->isVectorTy()) { |
| 535 | assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); |
| 536 | Dest.AggregateVal.resize( Src1.AggregateVal.size() ); |
| 537 | if(dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) { |
| 538 | for( size_t _i=0;_i<Src1.AggregateVal.size();_i++) |
| 539 | Dest.AggregateVal[_i].IntVal = APInt(1, |
| 540 | ( (Src1.AggregateVal[_i].FloatVal == |
| 541 | Src1.AggregateVal[_i].FloatVal) && |
| 542 | (Src2.AggregateVal[_i].FloatVal == |
| 543 | Src2.AggregateVal[_i].FloatVal))); |
| 544 | } else { |
| 545 | for( size_t _i=0;_i<Src1.AggregateVal.size();_i++) |
| 546 | Dest.AggregateVal[_i].IntVal = APInt(1, |
| 547 | ( (Src1.AggregateVal[_i].DoubleVal == |
| 548 | Src1.AggregateVal[_i].DoubleVal) && |
| 549 | (Src2.AggregateVal[_i].DoubleVal == |
| 550 | Src2.AggregateVal[_i].DoubleVal))); |
| 551 | } |
| 552 | } else if (Ty->isFloatTy()) |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 553 | Dest.IntVal = APInt(1,(Src1.FloatVal == Src1.FloatVal && |
| 554 | Src2.FloatVal == Src2.FloatVal)); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 555 | else { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 556 | Dest.IntVal = APInt(1,(Src1.DoubleVal == Src1.DoubleVal && |
| 557 | Src2.DoubleVal == Src2.DoubleVal)); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 558 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 559 | return Dest; |
| 560 | } |
| 561 | |
| 562 | static GenericValue executeFCMP_UNO(GenericValue Src1, GenericValue Src2, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 563 | Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 564 | GenericValue Dest; |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 565 | if(Ty->isVectorTy()) { |
| 566 | assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); |
| 567 | Dest.AggregateVal.resize( Src1.AggregateVal.size() ); |
| 568 | if(dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) { |
| 569 | for( size_t _i=0;_i<Src1.AggregateVal.size();_i++) |
| 570 | Dest.AggregateVal[_i].IntVal = APInt(1, |
| 571 | ( (Src1.AggregateVal[_i].FloatVal != |
| 572 | Src1.AggregateVal[_i].FloatVal) || |
| 573 | (Src2.AggregateVal[_i].FloatVal != |
| 574 | Src2.AggregateVal[_i].FloatVal))); |
| 575 | } else { |
| 576 | for( size_t _i=0;_i<Src1.AggregateVal.size();_i++) |
| 577 | Dest.AggregateVal[_i].IntVal = APInt(1, |
| 578 | ( (Src1.AggregateVal[_i].DoubleVal != |
| 579 | Src1.AggregateVal[_i].DoubleVal) || |
| 580 | (Src2.AggregateVal[_i].DoubleVal != |
| 581 | Src2.AggregateVal[_i].DoubleVal))); |
| 582 | } |
| 583 | } else if (Ty->isFloatTy()) |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 584 | Dest.IntVal = APInt(1,(Src1.FloatVal != Src1.FloatVal || |
| 585 | Src2.FloatVal != Src2.FloatVal)); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 586 | else { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 587 | Dest.IntVal = APInt(1,(Src1.DoubleVal != Src1.DoubleVal || |
| 588 | Src2.DoubleVal != Src2.DoubleVal)); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 589 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 590 | return Dest; |
| 591 | } |
| 592 | |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 593 | static GenericValue executeFCMP_BOOL(GenericValue Src1, GenericValue Src2, |
| 594 | const Type *Ty, const bool val) { |
| 595 | GenericValue Dest; |
| 596 | if(Ty->isVectorTy()) { |
| 597 | assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); |
| 598 | Dest.AggregateVal.resize( Src1.AggregateVal.size() ); |
| 599 | for( size_t _i=0; _i<Src1.AggregateVal.size(); _i++) |
| 600 | Dest.AggregateVal[_i].IntVal = APInt(1,val); |
| 601 | } else { |
| 602 | Dest.IntVal = APInt(1, val); |
| 603 | } |
| 604 | |
| 605 | return Dest; |
| 606 | } |
| 607 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 608 | void Interpreter::visitFCmpInst(FCmpInst &I) { |
| 609 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 610 | Type *Ty = I.getOperand(0)->getType(); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 611 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 612 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 613 | GenericValue R; // Result |
| 614 | |
| 615 | switch (I.getPredicate()) { |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 616 | default: |
| 617 | dbgs() << "Don't know how to handle this FCmp predicate!\n-->" << I; |
| 618 | llvm_unreachable(0); |
| 619 | break; |
| 620 | case FCmpInst::FCMP_FALSE: R = executeFCMP_BOOL(Src1, Src2, Ty, false); |
| 621 | break; |
| 622 | case FCmpInst::FCMP_TRUE: R = executeFCMP_BOOL(Src1, Src2, Ty, true); |
| 623 | break; |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 624 | case FCmpInst::FCMP_ORD: R = executeFCMP_ORD(Src1, Src2, Ty); break; |
| 625 | case FCmpInst::FCMP_UNO: R = executeFCMP_UNO(Src1, Src2, Ty); break; |
| 626 | case FCmpInst::FCMP_UEQ: R = executeFCMP_UEQ(Src1, Src2, Ty); break; |
| 627 | case FCmpInst::FCMP_OEQ: R = executeFCMP_OEQ(Src1, Src2, Ty); break; |
| 628 | case FCmpInst::FCMP_UNE: R = executeFCMP_UNE(Src1, Src2, Ty); break; |
| 629 | case FCmpInst::FCMP_ONE: R = executeFCMP_ONE(Src1, Src2, Ty); break; |
| 630 | case FCmpInst::FCMP_ULT: R = executeFCMP_ULT(Src1, Src2, Ty); break; |
| 631 | case FCmpInst::FCMP_OLT: R = executeFCMP_OLT(Src1, Src2, Ty); break; |
| 632 | case FCmpInst::FCMP_UGT: R = executeFCMP_UGT(Src1, Src2, Ty); break; |
| 633 | case FCmpInst::FCMP_OGT: R = executeFCMP_OGT(Src1, Src2, Ty); break; |
| 634 | case FCmpInst::FCMP_ULE: R = executeFCMP_ULE(Src1, Src2, Ty); break; |
| 635 | case FCmpInst::FCMP_OLE: R = executeFCMP_OLE(Src1, Src2, Ty); break; |
| 636 | case FCmpInst::FCMP_UGE: R = executeFCMP_UGE(Src1, Src2, Ty); break; |
| 637 | case FCmpInst::FCMP_OGE: R = executeFCMP_OGE(Src1, Src2, Ty); break; |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | SetValue(&I, R, SF); |
| 641 | } |
| 642 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 643 | static GenericValue executeCmpInst(unsigned predicate, GenericValue Src1, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 644 | GenericValue Src2, Type *Ty) { |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 645 | GenericValue Result; |
| 646 | switch (predicate) { |
| 647 | case ICmpInst::ICMP_EQ: return executeICMP_EQ(Src1, Src2, Ty); |
| 648 | case ICmpInst::ICMP_NE: return executeICMP_NE(Src1, Src2, Ty); |
| 649 | case ICmpInst::ICMP_UGT: return executeICMP_UGT(Src1, Src2, Ty); |
| 650 | case ICmpInst::ICMP_SGT: return executeICMP_SGT(Src1, Src2, Ty); |
| 651 | case ICmpInst::ICMP_ULT: return executeICMP_ULT(Src1, Src2, Ty); |
| 652 | case ICmpInst::ICMP_SLT: return executeICMP_SLT(Src1, Src2, Ty); |
| 653 | case ICmpInst::ICMP_UGE: return executeICMP_UGE(Src1, Src2, Ty); |
| 654 | case ICmpInst::ICMP_SGE: return executeICMP_SGE(Src1, Src2, Ty); |
| 655 | case ICmpInst::ICMP_ULE: return executeICMP_ULE(Src1, Src2, Ty); |
| 656 | case ICmpInst::ICMP_SLE: return executeICMP_SLE(Src1, Src2, Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 657 | case FCmpInst::FCMP_ORD: return executeFCMP_ORD(Src1, Src2, Ty); |
| 658 | case FCmpInst::FCMP_UNO: return executeFCMP_UNO(Src1, Src2, Ty); |
| 659 | case FCmpInst::FCMP_OEQ: return executeFCMP_OEQ(Src1, Src2, Ty); |
| 660 | case FCmpInst::FCMP_UEQ: return executeFCMP_UEQ(Src1, Src2, Ty); |
| 661 | case FCmpInst::FCMP_ONE: return executeFCMP_ONE(Src1, Src2, Ty); |
| 662 | case FCmpInst::FCMP_UNE: return executeFCMP_UNE(Src1, Src2, Ty); |
| 663 | case FCmpInst::FCMP_OLT: return executeFCMP_OLT(Src1, Src2, Ty); |
| 664 | case FCmpInst::FCMP_ULT: return executeFCMP_ULT(Src1, Src2, Ty); |
| 665 | case FCmpInst::FCMP_OGT: return executeFCMP_OGT(Src1, Src2, Ty); |
| 666 | case FCmpInst::FCMP_UGT: return executeFCMP_UGT(Src1, Src2, Ty); |
| 667 | case FCmpInst::FCMP_OLE: return executeFCMP_OLE(Src1, Src2, Ty); |
| 668 | case FCmpInst::FCMP_ULE: return executeFCMP_ULE(Src1, Src2, Ty); |
| 669 | case FCmpInst::FCMP_OGE: return executeFCMP_OGE(Src1, Src2, Ty); |
| 670 | case FCmpInst::FCMP_UGE: return executeFCMP_UGE(Src1, Src2, Ty); |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 671 | case FCmpInst::FCMP_FALSE: return executeFCMP_BOOL(Src1, Src2, Ty, false); |
| 672 | case FCmpInst::FCMP_TRUE: return executeFCMP_BOOL(Src1, Src2, Ty, true); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 673 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 674 | dbgs() << "Unhandled Cmp predicate\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 675 | llvm_unreachable(0); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 679 | void Interpreter::visitBinaryOperator(BinaryOperator &I) { |
| 680 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 681 | Type *Ty = I.getOperand(0)->getType(); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 682 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 683 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 684 | GenericValue R; // Result |
| 685 | |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 686 | // First process vector operation |
| 687 | if (Ty->isVectorTy()) { |
| 688 | assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); |
| 689 | R.AggregateVal.resize(Src1.AggregateVal.size()); |
Nadav Rotem | 0fda0f3 | 2013-04-12 22:02:26 +0000 | [diff] [blame] | 690 | |
Nadav Rotem | 0d840bb | 2013-04-26 20:19:41 +0000 | [diff] [blame] | 691 | // Macros to execute binary operation 'OP' over integer vectors |
| 692 | #define INTEGER_VECTOR_OPERATION(OP) \ |
| 693 | for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \ |
| 694 | R.AggregateVal[i].IntVal = \ |
| 695 | Src1.AggregateVal[i].IntVal OP Src2.AggregateVal[i].IntVal; |
| 696 | |
| 697 | // Additional macros to execute binary operations udiv/sdiv/urem/srem since |
| 698 | // they have different notation. |
| 699 | #define INTEGER_VECTOR_FUNCTION(OP) \ |
| 700 | for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \ |
| 701 | R.AggregateVal[i].IntVal = \ |
| 702 | Src1.AggregateVal[i].IntVal.OP(Src2.AggregateVal[i].IntVal); |
| 703 | |
| 704 | // Macros to execute binary operation 'OP' over floating point type TY |
| 705 | // (float or double) vectors |
| 706 | #define FLOAT_VECTOR_FUNCTION(OP, TY) \ |
| 707 | for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \ |
| 708 | R.AggregateVal[i].TY = \ |
| 709 | Src1.AggregateVal[i].TY OP Src2.AggregateVal[i].TY; |
| 710 | |
| 711 | // Macros to choose appropriate TY: float or double and run operation |
| 712 | // execution |
| 713 | #define FLOAT_VECTOR_OP(OP) { \ |
| 714 | if (dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) \ |
| 715 | FLOAT_VECTOR_FUNCTION(OP, FloatVal) \ |
| 716 | else { \ |
| 717 | if (dyn_cast<VectorType>(Ty)->getElementType()->isDoubleTy()) \ |
| 718 | FLOAT_VECTOR_FUNCTION(OP, DoubleVal) \ |
| 719 | else { \ |
| 720 | dbgs() << "Unhandled type for OP instruction: " << *Ty << "\n"; \ |
| 721 | llvm_unreachable(0); \ |
| 722 | } \ |
| 723 | } \ |
| 724 | } |
| 725 | |
| 726 | switch(I.getOpcode()){ |
| 727 | default: |
| 728 | dbgs() << "Don't know how to handle this binary operator!\n-->" << I; |
| 729 | llvm_unreachable(0); |
| 730 | break; |
| 731 | case Instruction::Add: INTEGER_VECTOR_OPERATION(+) break; |
| 732 | case Instruction::Sub: INTEGER_VECTOR_OPERATION(-) break; |
| 733 | case Instruction::Mul: INTEGER_VECTOR_OPERATION(*) break; |
| 734 | case Instruction::UDiv: INTEGER_VECTOR_FUNCTION(udiv) break; |
| 735 | case Instruction::SDiv: INTEGER_VECTOR_FUNCTION(sdiv) break; |
| 736 | case Instruction::URem: INTEGER_VECTOR_FUNCTION(urem) break; |
| 737 | case Instruction::SRem: INTEGER_VECTOR_FUNCTION(srem) break; |
| 738 | case Instruction::And: INTEGER_VECTOR_OPERATION(&) break; |
| 739 | case Instruction::Or: INTEGER_VECTOR_OPERATION(|) break; |
| 740 | case Instruction::Xor: INTEGER_VECTOR_OPERATION(^) break; |
| 741 | case Instruction::FAdd: FLOAT_VECTOR_OP(+) break; |
| 742 | case Instruction::FSub: FLOAT_VECTOR_OP(-) break; |
| 743 | case Instruction::FMul: FLOAT_VECTOR_OP(*) break; |
| 744 | case Instruction::FDiv: FLOAT_VECTOR_OP(/) break; |
| 745 | case Instruction::FRem: |
| 746 | if (dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) |
| 747 | for (unsigned i = 0; i < R.AggregateVal.size(); ++i) |
| 748 | R.AggregateVal[i].FloatVal = |
| 749 | fmod(Src1.AggregateVal[i].FloatVal, Src2.AggregateVal[i].FloatVal); |
| 750 | else { |
| 751 | if (dyn_cast<VectorType>(Ty)->getElementType()->isDoubleTy()) |
| 752 | for (unsigned i = 0; i < R.AggregateVal.size(); ++i) |
| 753 | R.AggregateVal[i].DoubleVal = |
| 754 | fmod(Src1.AggregateVal[i].DoubleVal, Src2.AggregateVal[i].DoubleVal); |
| 755 | else { |
| 756 | dbgs() << "Unhandled type for Rem instruction: " << *Ty << "\n"; |
| 757 | llvm_unreachable(0); |
| 758 | } |
| 759 | } |
| 760 | break; |
| 761 | } |
| 762 | } else { |
| 763 | switch (I.getOpcode()) { |
| 764 | default: |
| 765 | dbgs() << "Don't know how to handle this binary operator!\n-->" << I; |
| 766 | llvm_unreachable(0); |
| 767 | break; |
| 768 | case Instruction::Add: R.IntVal = Src1.IntVal + Src2.IntVal; break; |
| 769 | case Instruction::Sub: R.IntVal = Src1.IntVal - Src2.IntVal; break; |
| 770 | case Instruction::Mul: R.IntVal = Src1.IntVal * Src2.IntVal; break; |
| 771 | case Instruction::FAdd: executeFAddInst(R, Src1, Src2, Ty); break; |
| 772 | case Instruction::FSub: executeFSubInst(R, Src1, Src2, Ty); break; |
| 773 | case Instruction::FMul: executeFMulInst(R, Src1, Src2, Ty); break; |
| 774 | case Instruction::FDiv: executeFDivInst(R, Src1, Src2, Ty); break; |
| 775 | case Instruction::FRem: executeFRemInst(R, Src1, Src2, Ty); break; |
| 776 | case Instruction::UDiv: R.IntVal = Src1.IntVal.udiv(Src2.IntVal); break; |
| 777 | case Instruction::SDiv: R.IntVal = Src1.IntVal.sdiv(Src2.IntVal); break; |
| 778 | case Instruction::URem: R.IntVal = Src1.IntVal.urem(Src2.IntVal); break; |
| 779 | case Instruction::SRem: R.IntVal = Src1.IntVal.srem(Src2.IntVal); break; |
| 780 | case Instruction::And: R.IntVal = Src1.IntVal & Src2.IntVal; break; |
| 781 | case Instruction::Or: R.IntVal = Src1.IntVal | Src2.IntVal; break; |
| 782 | case Instruction::Xor: R.IntVal = Src1.IntVal ^ Src2.IntVal; break; |
| 783 | } |
| 784 | } |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 785 | SetValue(&I, R, SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 788 | static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, |
Elena Demikhovsky | 4ca0ce2 | 2013-09-02 06:40:09 +0000 | [diff] [blame] | 789 | GenericValue Src3, const Type *Ty) { |
| 790 | GenericValue Dest; |
| 791 | if(Ty->isVectorTy()) { |
| 792 | assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); |
| 793 | assert(Src2.AggregateVal.size() == Src3.AggregateVal.size()); |
| 794 | Dest.AggregateVal.resize( Src1.AggregateVal.size() ); |
| 795 | for (size_t i = 0; i < Src1.AggregateVal.size(); ++i) |
| 796 | Dest.AggregateVal[i] = (Src1.AggregateVal[i].IntVal == 0) ? |
| 797 | Src3.AggregateVal[i] : Src2.AggregateVal[i]; |
| 798 | } else { |
| 799 | Dest = (Src1.IntVal == 0) ? Src3 : Src2; |
| 800 | } |
| 801 | return Dest; |
Chris Lattner | 759d34f | 2004-04-20 16:43:21 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void Interpreter::visitSelectInst(SelectInst &I) { |
| 805 | ExecutionContext &SF = ECStack.back(); |
Elena Demikhovsky | 4ca0ce2 | 2013-09-02 06:40:09 +0000 | [diff] [blame] | 806 | const Type * Ty = I.getOperand(0)->getType(); |
Chris Lattner | 759d34f | 2004-04-20 16:43:21 +0000 | [diff] [blame] | 807 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 808 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 809 | GenericValue Src3 = getOperandValue(I.getOperand(2), SF); |
Elena Demikhovsky | 4ca0ce2 | 2013-09-02 06:40:09 +0000 | [diff] [blame] | 810 | GenericValue R = executeSelectInst(Src1, Src2, Src3, Ty); |
Chris Lattner | 759d34f | 2004-04-20 16:43:21 +0000 | [diff] [blame] | 811 | SetValue(&I, R, SF); |
| 812 | } |
| 813 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 814 | //===----------------------------------------------------------------------===// |
| 815 | // Terminator Instruction Implementations |
| 816 | //===----------------------------------------------------------------------===// |
| 817 | |
Chris Lattner | e43db88 | 2001-10-27 04:15:57 +0000 | [diff] [blame] | 818 | void Interpreter::exitCalled(GenericValue GV) { |
Brian Gaeke | d8400d8 | 2004-02-13 05:48:00 +0000 | [diff] [blame] | 819 | // runAtExitHandlers() assumes there are no stack frames, but |
| 820 | // if exit() was called, then it had a stack frame. Blow away |
| 821 | // the stack before interpreting atexit handlers. |
Chris Lattner | f32a6a3 | 2009-10-29 05:26:09 +0000 | [diff] [blame] | 822 | ECStack.clear(); |
| 823 | runAtExitHandlers(); |
| 824 | exit(GV.IntVal.zextOrTrunc(32).getZExtValue()); |
Chris Lattner | e43db88 | 2001-10-27 04:15:57 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 827 | /// Pop the last stack frame off of ECStack and then copy the result |
| 828 | /// back into the result variable if we are not returning void. The |
Jeff Cohen | 8c9191c | 2006-02-07 05:29:44 +0000 | [diff] [blame] | 829 | /// result variable may be the ExitValue, or the Value of the calling |
Brian Gaeke | dbde1ae | 2003-11-07 20:44:58 +0000 | [diff] [blame] | 830 | /// CallInst if there was a previous stack frame. This method may |
| 831 | /// invalidate any ECStack iterators you have. This method also takes |
| 832 | /// care of switching to the normal destination BB, if we are returning |
| 833 | /// from an invoke. |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 834 | /// |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 835 | void Interpreter::popStackAndReturnValueToCaller(Type *RetTy, |
Chris Lattner | f32a6a3 | 2009-10-29 05:26:09 +0000 | [diff] [blame] | 836 | GenericValue Result) { |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 837 | // Pop the current stack frame. |
| 838 | ECStack.pop_back(); |
| 839 | |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 840 | if (ECStack.empty()) { // Finished main. Put result into exit code... |
Dan Gohman | 9634331 | 2010-06-18 02:01:10 +0000 | [diff] [blame] | 841 | if (RetTy && !RetTy->isVoidTy()) { // Nonvoid return type? |
Jeff Cohen | 8c9191c | 2006-02-07 05:29:44 +0000 | [diff] [blame] | 842 | ExitValue = Result; // Capture the exit value of the program |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 843 | } else { |
Reid Spencer | e770787 | 2007-06-01 22:23:29 +0000 | [diff] [blame] | 844 | memset(&ExitValue.Untyped, 0, sizeof(ExitValue.Untyped)); |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 845 | } |
| 846 | } else { |
| 847 | // If we have a previous stack frame, and we have a previous call, |
| 848 | // fill in the return value... |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 849 | ExecutionContext &CallingSF = ECStack.back(); |
Brian Gaeke | dbde1ae | 2003-11-07 20:44:58 +0000 | [diff] [blame] | 850 | if (Instruction *I = CallingSF.Caller.getInstruction()) { |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 851 | // Save result... |
Benjamin Kramer | f012705 | 2010-01-05 13:12:22 +0000 | [diff] [blame] | 852 | if (!CallingSF.Caller.getType()->isVoidTy()) |
Brian Gaeke | dbde1ae | 2003-11-07 20:44:58 +0000 | [diff] [blame] | 853 | SetValue(I, Result, CallingSF); |
| 854 | if (InvokeInst *II = dyn_cast<InvokeInst> (I)) |
| 855 | SwitchToNewBasicBlock (II->getNormalDest (), CallingSF); |
Brian Gaeke | 2cb474c | 2003-11-07 19:26:23 +0000 | [diff] [blame] | 856 | CallingSF.Caller = CallSite(); // We returned from the call... |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 861 | void Interpreter::visitReturnInst(ReturnInst &I) { |
| 862 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 863 | Type *RetTy = Type::getVoidTy(I.getContext()); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 864 | GenericValue Result; |
| 865 | |
| 866 | // Save away the return value... (if we are not 'ret void') |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 867 | if (I.getNumOperands()) { |
| 868 | RetTy = I.getReturnValue()->getType(); |
| 869 | Result = getOperandValue(I.getReturnValue(), SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 870 | } |
| 871 | |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 872 | popStackAndReturnValueToCaller(RetTy, Result); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Chris Lattner | ec7c1ab | 2004-10-16 18:21:33 +0000 | [diff] [blame] | 875 | void Interpreter::visitUnreachableInst(UnreachableInst &I) { |
Chris Lattner | 75361b6 | 2010-04-07 22:58:41 +0000 | [diff] [blame] | 876 | report_fatal_error("Program executed an 'unreachable' instruction!"); |
Chris Lattner | ec7c1ab | 2004-10-16 18:21:33 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 879 | void Interpreter::visitBranchInst(BranchInst &I) { |
| 880 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 881 | BasicBlock *Dest; |
| 882 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 883 | Dest = I.getSuccessor(0); // Uncond branches have a fixed dest... |
| 884 | if (!I.isUnconditional()) { |
| 885 | Value *Cond = I.getCondition(); |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 886 | if (getOperandValue(Cond, SF).IntVal == 0) // If false cond... |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 887 | Dest = I.getSuccessor(1); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 888 | } |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 889 | SwitchToNewBasicBlock(Dest, SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 890 | } |
| 891 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 892 | void Interpreter::visitSwitchInst(SwitchInst &I) { |
| 893 | ExecutionContext &SF = ECStack.back(); |
Eli Friedman | bb5a744 | 2011-09-29 20:21:17 +0000 | [diff] [blame] | 894 | Value* Cond = I.getCondition(); |
| 895 | Type *ElTy = Cond->getType(); |
| 896 | GenericValue CondVal = getOperandValue(Cond, SF); |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 897 | |
| 898 | // Check to see if any of the cases match... |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 899 | BasicBlock *Dest = 0; |
Stepan Dyatkovskiy | 3d3abe0 | 2012-03-11 06:09:17 +0000 | [diff] [blame] | 900 | for (SwitchInst::CaseIt i = I.case_begin(), e = I.case_end(); i != e; ++i) { |
Bob Wilson | db3a9e6 | 2013-09-09 19:14:35 +0000 | [diff] [blame] | 901 | GenericValue CaseVal = getOperandValue(i.getCaseValue(), SF); |
| 902 | if (executeICMP_EQ(CondVal, CaseVal, ElTy).IntVal != 0) { |
| 903 | Dest = cast<BasicBlock>(i.getCaseSuccessor()); |
| 904 | break; |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 905 | } |
Eli Friedman | bb5a744 | 2011-09-29 20:21:17 +0000 | [diff] [blame] | 906 | } |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 907 | if (!Dest) Dest = I.getDefaultDest(); // No cases matched: use default |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 908 | SwitchToNewBasicBlock(Dest, SF); |
| 909 | } |
| 910 | |
Chris Lattner | f32a6a3 | 2009-10-29 05:26:09 +0000 | [diff] [blame] | 911 | void Interpreter::visitIndirectBrInst(IndirectBrInst &I) { |
| 912 | ExecutionContext &SF = ECStack.back(); |
| 913 | void *Dest = GVTOP(getOperandValue(I.getAddress(), SF)); |
| 914 | SwitchToNewBasicBlock((BasicBlock*)Dest, SF); |
| 915 | } |
| 916 | |
| 917 | |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 918 | // SwitchToNewBasicBlock - This method is used to jump to a new basic block. |
| 919 | // This function handles the actual updating of block and instruction iterators |
| 920 | // as well as execution of all of the PHI nodes in the destination block. |
| 921 | // |
| 922 | // This method does this because all of the PHI nodes must be executed |
| 923 | // atomically, reading their inputs before any of the results are updated. Not |
| 924 | // doing this can cause problems if the PHI nodes depend on other PHI nodes for |
| 925 | // their inputs. If the input PHI node is updated before it is read, incorrect |
| 926 | // results can happen. Thus we use a two phase approach. |
| 927 | // |
| 928 | void Interpreter::SwitchToNewBasicBlock(BasicBlock *Dest, ExecutionContext &SF){ |
| 929 | BasicBlock *PrevBB = SF.CurBB; // Remember where we came from... |
| 930 | SF.CurBB = Dest; // Update CurBB to branch destination |
| 931 | SF.CurInst = SF.CurBB->begin(); // Update new instruction ptr... |
| 932 | |
| 933 | if (!isa<PHINode>(SF.CurInst)) return; // Nothing fancy to do |
| 934 | |
| 935 | // Loop over all of the PHI nodes in the current block, reading their inputs. |
| 936 | std::vector<GenericValue> ResultValues; |
| 937 | |
| 938 | for (; PHINode *PN = dyn_cast<PHINode>(SF.CurInst); ++SF.CurInst) { |
| 939 | // Search for the value corresponding to this previous bb... |
| 940 | int i = PN->getBasicBlockIndex(PrevBB); |
| 941 | assert(i != -1 && "PHINode doesn't contain entry for predecessor??"); |
| 942 | Value *IncomingValue = PN->getIncomingValue(i); |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 943 | |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 944 | // Save the incoming value for this PHI node... |
| 945 | ResultValues.push_back(getOperandValue(IncomingValue, SF)); |
| 946 | } |
| 947 | |
| 948 | // Now loop over all of the PHI nodes setting their values... |
| 949 | SF.CurInst = SF.CurBB->begin(); |
Reid Spencer | 2da5c3d | 2004-09-15 17:06:42 +0000 | [diff] [blame] | 950 | for (unsigned i = 0; isa<PHINode>(SF.CurInst); ++SF.CurInst, ++i) { |
| 951 | PHINode *PN = cast<PHINode>(SF.CurInst); |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 952 | SetValue(PN, ResultValues[i], SF); |
Reid Spencer | 2da5c3d | 2004-09-15 17:06:42 +0000 | [diff] [blame] | 953 | } |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 956 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 957 | // Memory Instruction Implementations |
| 958 | //===----------------------------------------------------------------------===// |
| 959 | |
Victor Hernandez | 7b929da | 2009-10-23 21:09:37 +0000 | [diff] [blame] | 960 | void Interpreter::visitAllocaInst(AllocaInst &I) { |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 961 | ExecutionContext &SF = ECStack.back(); |
| 962 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 963 | Type *Ty = I.getType()->getElementType(); // Type to be allocated |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 964 | |
Chris Lattner | cc82cc1 | 2002-04-28 21:57:33 +0000 | [diff] [blame] | 965 | // Get the number of elements being allocated by the array... |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 966 | unsigned NumElements = |
| 967 | getOperandValue(I.getOperand(0), SF).IntVal.getZExtValue(); |
| 968 | |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 969 | unsigned TypeSize = (size_t)TD.getTypeAllocSize(Ty); |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 970 | |
Gabor Greif | 724441e | 2007-10-11 19:40:35 +0000 | [diff] [blame] | 971 | // Avoid malloc-ing zero bytes, use max()... |
| 972 | unsigned MemToAlloc = std::max(1U, NumElements * TypeSize); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 973 | |
| 974 | // Allocate enough memory to hold the type... |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 975 | void *Memory = malloc(MemToAlloc); |
| 976 | |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 977 | DEBUG(dbgs() << "Allocated Type: " << *Ty << " (" << TypeSize << " bytes) x " |
Chris Lattner | 79c5d3f | 2009-08-23 04:52:46 +0000 | [diff] [blame] | 978 | << NumElements << " (Total: " << MemToAlloc << ") at " |
| 979 | << uintptr_t(Memory) << '\n'); |
Chris Lattner | 9bffa73 | 2002-02-19 18:50:09 +0000 | [diff] [blame] | 980 | |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 981 | GenericValue Result = PTOGV(Memory); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 982 | assert(Result.PointerVal != 0 && "Null pointer returned by malloc!"); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 983 | SetValue(&I, Result, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 984 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 985 | if (I.getOpcode() == Instruction::Alloca) |
Chris Lattner | 9bffa73 | 2002-02-19 18:50:09 +0000 | [diff] [blame] | 986 | ECStack.back().Allocas.add(Memory); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 987 | } |
| 988 | |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 989 | // getElementOffset - The workhorse for getelementptr. |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 990 | // |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 991 | GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I, |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 992 | gep_type_iterator E, |
| 993 | ExecutionContext &SF) { |
Duncan Sands | 1df9859 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 994 | assert(Ptr->getType()->isPointerTy() && |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 995 | "Cannot getElementOffset of a nonpointer type!"); |
| 996 | |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 997 | uint64_t Total = 0; |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 998 | |
| 999 | for (; I != E; ++I) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1000 | if (StructType *STy = dyn_cast<StructType>(*I)) { |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 1001 | const StructLayout *SLO = TD.getStructLayout(STy); |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1002 | |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 1003 | const ConstantInt *CPU = cast<ConstantInt>(I.getOperand()); |
| 1004 | unsigned Index = unsigned(CPU->getZExtValue()); |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1005 | |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 1006 | Total += SLO->getElementOffset(Index); |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 1007 | } else { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1008 | SequentialType *ST = cast<SequentialType>(*I); |
Chris Lattner | 006a4a5 | 2003-02-25 21:14:59 +0000 | [diff] [blame] | 1009 | // Get the index number for the array... which must be long type... |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 1010 | GenericValue IdxGV = getOperandValue(I.getOperand(), SF); |
| 1011 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1012 | int64_t Idx; |
| 1013 | unsigned BitWidth = |
| 1014 | cast<IntegerType>(I.getOperand()->getType())->getBitWidth(); |
Reid Spencer | 23e2883 | 2007-01-18 01:25:42 +0000 | [diff] [blame] | 1015 | if (BitWidth == 32) |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 1016 | Idx = (int64_t)(int32_t)IdxGV.IntVal.getZExtValue(); |
Chris Lattner | aee7f21 | 2008-04-06 21:50:58 +0000 | [diff] [blame] | 1017 | else { |
| 1018 | assert(BitWidth == 64 && "Invalid index type for getelementptr"); |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 1019 | Idx = (int64_t)IdxGV.IntVal.getZExtValue(); |
Chris Lattner | aee7f21 | 2008-04-06 21:50:58 +0000 | [diff] [blame] | 1020 | } |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 1021 | Total += TD.getTypeAllocSize(ST->getElementType())*Idx; |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 1022 | } |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1025 | GenericValue Result; |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 1026 | Result.PointerVal = ((char*)getOperandValue(Ptr, SF).PointerVal) + Total; |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 1027 | DEBUG(dbgs() << "GEP Index " << Total << " bytes.\n"); |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1028 | return Result; |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 1031 | void Interpreter::visitGetElementPtrInst(GetElementPtrInst &I) { |
| 1032 | ExecutionContext &SF = ECStack.back(); |
Owen Anderson | fdca74c | 2009-06-26 16:46:15 +0000 | [diff] [blame] | 1033 | SetValue(&I, executeGEPOperation(I.getPointerOperand(), |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 1034 | gep_type_begin(I), gep_type_end(I), SF), SF); |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 1037 | void Interpreter::visitLoadInst(LoadInst &I) { |
| 1038 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1039 | GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 1040 | GenericValue *Ptr = (GenericValue*)GVTOP(SRC); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1041 | GenericValue Result; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1042 | LoadValueFromMemory(Result, Ptr, I.getType()); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1043 | SetValue(&I, Result, SF); |
Chris Lattner | 663ceeb | 2008-07-08 17:25:49 +0000 | [diff] [blame] | 1044 | if (I.isVolatile() && PrintVolatile) |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 1045 | dbgs() << "Volatile load " << I; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 1048 | void Interpreter::visitStoreInst(StoreInst &I) { |
| 1049 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | fddc755 | 2002-10-15 20:34:05 +0000 | [diff] [blame] | 1050 | GenericValue Val = getOperandValue(I.getOperand(0), SF); |
| 1051 | GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 1052 | StoreValueToMemory(Val, (GenericValue *)GVTOP(SRC), |
Chris Lattner | 683d5da9 | 2002-10-26 01:57:15 +0000 | [diff] [blame] | 1053 | I.getOperand(0)->getType()); |
Chris Lattner | 663ceeb | 2008-07-08 17:25:49 +0000 | [diff] [blame] | 1054 | if (I.isVolatile() && PrintVolatile) |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 1055 | dbgs() << "Volatile store: " << I; |
Chris Lattner | fddc755 | 2002-10-15 20:34:05 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1058 | //===----------------------------------------------------------------------===// |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1059 | // Miscellaneous Instruction Implementations |
| 1060 | //===----------------------------------------------------------------------===// |
| 1061 | |
Brian Gaeke | fea483d | 2003-11-07 20:04:22 +0000 | [diff] [blame] | 1062 | void Interpreter::visitCallSite(CallSite CS) { |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 1063 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1064 | |
| 1065 | // Check to see if this is an intrinsic function call... |
Reid Spencer | 4ccf462 | 2007-04-16 21:50:40 +0000 | [diff] [blame] | 1066 | Function *F = CS.getCalledFunction(); |
Chris Lattner | f32a6a3 | 2009-10-29 05:26:09 +0000 | [diff] [blame] | 1067 | if (F && F->isDeclaration()) |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1068 | switch (F->getIntrinsicID()) { |
Brian Gaeke | 34562ba | 2004-01-14 06:02:53 +0000 | [diff] [blame] | 1069 | case Intrinsic::not_intrinsic: |
| 1070 | break; |
Chris Lattner | 317201d | 2004-03-13 00:24:00 +0000 | [diff] [blame] | 1071 | case Intrinsic::vastart: { // va_start |
Brian Gaeke | 9d20b71 | 2004-02-25 23:01:48 +0000 | [diff] [blame] | 1072 | GenericValue ArgIndex; |
| 1073 | ArgIndex.UIntPairVal.first = ECStack.size() - 1; |
| 1074 | ArgIndex.UIntPairVal.second = 0; |
| 1075 | SetValue(CS.getInstruction(), ArgIndex, SF); |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1076 | return; |
Brian Gaeke | 9d20b71 | 2004-02-25 23:01:48 +0000 | [diff] [blame] | 1077 | } |
Chris Lattner | 317201d | 2004-03-13 00:24:00 +0000 | [diff] [blame] | 1078 | case Intrinsic::vaend: // va_end is a noop for the interpreter |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1079 | return; |
Chris Lattner | 317201d | 2004-03-13 00:24:00 +0000 | [diff] [blame] | 1080 | case Intrinsic::vacopy: // va_copy: dest = src |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1081 | SetValue(CS.getInstruction(), getOperandValue(*CS.arg_begin(), SF), SF); |
| 1082 | return; |
| 1083 | default: |
Brian Gaeke | 34562ba | 2004-01-14 06:02:53 +0000 | [diff] [blame] | 1084 | // If it is an unknown intrinsic function, use the intrinsic lowering |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1085 | // class to transform it into hopefully tasty LLVM code. |
| 1086 | // |
Chris Lattner | b8e237b | 2007-04-17 17:38:28 +0000 | [diff] [blame] | 1087 | BasicBlock::iterator me(CS.getInstruction()); |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1088 | BasicBlock *Parent = CS.getInstruction()->getParent(); |
Chris Lattner | b8e237b | 2007-04-17 17:38:28 +0000 | [diff] [blame] | 1089 | bool atBegin(Parent->begin() == me); |
| 1090 | if (!atBegin) |
| 1091 | --me; |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1092 | IL->LowerIntrinsicCall(cast<CallInst>(CS.getInstruction())); |
| 1093 | |
| 1094 | // Restore the CurInst pointer to the first instruction newly inserted, if |
| 1095 | // any. |
Chris Lattner | b8e237b | 2007-04-17 17:38:28 +0000 | [diff] [blame] | 1096 | if (atBegin) { |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1097 | SF.CurInst = Parent->begin(); |
| 1098 | } else { |
Chris Lattner | b8e237b | 2007-04-17 17:38:28 +0000 | [diff] [blame] | 1099 | SF.CurInst = me; |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1100 | ++SF.CurInst; |
| 1101 | } |
Brian Gaeke | b440dea | 2004-04-23 18:05:28 +0000 | [diff] [blame] | 1102 | return; |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
Reid Spencer | 4ccf462 | 2007-04-16 21:50:40 +0000 | [diff] [blame] | 1105 | |
Brian Gaeke | fea483d | 2003-11-07 20:04:22 +0000 | [diff] [blame] | 1106 | SF.Caller = CS; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 1107 | std::vector<GenericValue> ArgVals; |
Brian Gaeke | ae2495a | 2003-11-07 19:59:08 +0000 | [diff] [blame] | 1108 | const unsigned NumArgs = SF.Caller.arg_size(); |
| 1109 | ArgVals.reserve(NumArgs); |
Reid Spencer | 4ccf462 | 2007-04-16 21:50:40 +0000 | [diff] [blame] | 1110 | uint16_t pNum = 1; |
Brian Gaeke | ae2495a | 2003-11-07 19:59:08 +0000 | [diff] [blame] | 1111 | for (CallSite::arg_iterator i = SF.Caller.arg_begin(), |
Reid Spencer | 4ccf462 | 2007-04-16 21:50:40 +0000 | [diff] [blame] | 1112 | e = SF.Caller.arg_end(); i != e; ++i, ++pNum) { |
Brian Gaeke | ae2495a | 2003-11-07 19:59:08 +0000 | [diff] [blame] | 1113 | Value *V = *i; |
| 1114 | ArgVals.push_back(getOperandValue(V, SF)); |
Chris Lattner | 9378013 | 2003-01-13 00:58:52 +0000 | [diff] [blame] | 1115 | } |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 1116 | |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1117 | // To handle indirect calls, we must get the pointer value from the argument |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1118 | // and treat it as a function pointer. |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1119 | GenericValue SRC = getOperandValue(SF.Caller.getCalledValue(), SF); |
Chris Lattner | da82ed5 | 2003-05-08 16:18:31 +0000 | [diff] [blame] | 1120 | callFunction((Function*)GVTOP(SRC), ArgVals); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 1123 | // auxiliary function for shift operations |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1124 | static unsigned getShiftAmount(uint64_t orgShiftAmount, |
| 1125 | llvm::APInt valueToShift) { |
| 1126 | unsigned valueWidth = valueToShift.getBitWidth(); |
| 1127 | if (orgShiftAmount < (uint64_t)valueWidth) |
| 1128 | return orgShiftAmount; |
| 1129 | // according to the llvm documentation, if orgShiftAmount > valueWidth, |
| 1130 | // the result is undfeined. but we do shift by this rule: |
| 1131 | return (NextPowerOf2(valueWidth-1) - 1) & orgShiftAmount; |
| 1132 | } |
| 1133 | |
| 1134 | |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 1135 | void Interpreter::visitShl(BinaryOperator &I) { |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1136 | ExecutionContext &SF = ECStack.back(); |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1137 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1138 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1139 | GenericValue Dest; |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1140 | const Type *Ty = I.getType(); |
| 1141 | |
| 1142 | if (Ty->isVectorTy()) { |
| 1143 | uint32_t src1Size = uint32_t(Src1.AggregateVal.size()); |
| 1144 | assert(src1Size == Src2.AggregateVal.size()); |
| 1145 | for (unsigned i = 0; i < src1Size; i++) { |
| 1146 | GenericValue Result; |
| 1147 | uint64_t shiftAmount = Src2.AggregateVal[i].IntVal.getZExtValue(); |
| 1148 | llvm::APInt valueToShift = Src1.AggregateVal[i].IntVal; |
| 1149 | Result.IntVal = valueToShift.shl(getShiftAmount(shiftAmount, valueToShift)); |
| 1150 | Dest.AggregateVal.push_back(Result); |
| 1151 | } |
| 1152 | } else { |
| 1153 | // scalar |
| 1154 | uint64_t shiftAmount = Src2.IntVal.getZExtValue(); |
| 1155 | llvm::APInt valueToShift = Src1.IntVal; |
| 1156 | Dest.IntVal = valueToShift.shl(getShiftAmount(shiftAmount, valueToShift)); |
| 1157 | } |
| 1158 | |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1159 | SetValue(&I, Dest, SF); |
| 1160 | } |
| 1161 | |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 1162 | void Interpreter::visitLShr(BinaryOperator &I) { |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1163 | ExecutionContext &SF = ECStack.back(); |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1164 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1165 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1166 | GenericValue Dest; |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1167 | const Type *Ty = I.getType(); |
| 1168 | |
| 1169 | if (Ty->isVectorTy()) { |
| 1170 | uint32_t src1Size = uint32_t(Src1.AggregateVal.size()); |
| 1171 | assert(src1Size == Src2.AggregateVal.size()); |
| 1172 | for (unsigned i = 0; i < src1Size; i++) { |
| 1173 | GenericValue Result; |
| 1174 | uint64_t shiftAmount = Src2.AggregateVal[i].IntVal.getZExtValue(); |
| 1175 | llvm::APInt valueToShift = Src1.AggregateVal[i].IntVal; |
| 1176 | Result.IntVal = valueToShift.lshr(getShiftAmount(shiftAmount, valueToShift)); |
| 1177 | Dest.AggregateVal.push_back(Result); |
| 1178 | } |
| 1179 | } else { |
| 1180 | // scalar |
| 1181 | uint64_t shiftAmount = Src2.IntVal.getZExtValue(); |
| 1182 | llvm::APInt valueToShift = Src1.IntVal; |
| 1183 | Dest.IntVal = valueToShift.lshr(getShiftAmount(shiftAmount, valueToShift)); |
| 1184 | } |
| 1185 | |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 1186 | SetValue(&I, Dest, SF); |
| 1187 | } |
| 1188 | |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 1189 | void Interpreter::visitAShr(BinaryOperator &I) { |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 1190 | ExecutionContext &SF = ECStack.back(); |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 1191 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1192 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
Chris Lattner | 9029cb8 | 2009-01-16 20:17:02 +0000 | [diff] [blame] | 1193 | GenericValue Dest; |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1194 | const Type *Ty = I.getType(); |
| 1195 | |
| 1196 | if (Ty->isVectorTy()) { |
| 1197 | size_t src1Size = Src1.AggregateVal.size(); |
| 1198 | assert(src1Size == Src2.AggregateVal.size()); |
| 1199 | for (unsigned i = 0; i < src1Size; i++) { |
| 1200 | GenericValue Result; |
| 1201 | uint64_t shiftAmount = Src2.AggregateVal[i].IntVal.getZExtValue(); |
| 1202 | llvm::APInt valueToShift = Src1.AggregateVal[i].IntVal; |
| 1203 | Result.IntVal = valueToShift.ashr(getShiftAmount(shiftAmount, valueToShift)); |
| 1204 | Dest.AggregateVal.push_back(Result); |
| 1205 | } |
| 1206 | } else { |
| 1207 | // scalar |
| 1208 | uint64_t shiftAmount = Src2.IntVal.getZExtValue(); |
| 1209 | llvm::APInt valueToShift = Src1.IntVal; |
| 1210 | Dest.IntVal = valueToShift.ashr(getShiftAmount(shiftAmount, valueToShift)); |
| 1211 | } |
| 1212 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1213 | SetValue(&I, Dest, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1216 | GenericValue Interpreter::executeTruncInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1217 | ExecutionContext &SF) { |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1218 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1219 | Type *SrcTy = SrcVal->getType(); |
| 1220 | if (SrcTy->isVectorTy()) { |
| 1221 | Type *DstVecTy = DstTy->getScalarType(); |
| 1222 | unsigned DBitWidth = cast<IntegerType>(DstVecTy)->getBitWidth(); |
| 1223 | unsigned NumElts = Src.AggregateVal.size(); |
| 1224 | // the sizes of src and dst vectors must be equal |
| 1225 | Dest.AggregateVal.resize(NumElts); |
| 1226 | for (unsigned i = 0; i < NumElts; i++) |
| 1227 | Dest.AggregateVal[i].IntVal = Src.AggregateVal[i].IntVal.trunc(DBitWidth); |
| 1228 | } else { |
| 1229 | IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1230 | unsigned DBitWidth = DITy->getBitWidth(); |
| 1231 | Dest.IntVal = Src.IntVal.trunc(DBitWidth); |
| 1232 | } |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1233 | return Dest; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1234 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1235 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1236 | GenericValue Interpreter::executeSExtInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1237 | ExecutionContext &SF) { |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1238 | const Type *SrcTy = SrcVal->getType(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1239 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1240 | if (SrcTy->isVectorTy()) { |
| 1241 | const Type *DstVecTy = DstTy->getScalarType(); |
| 1242 | unsigned DBitWidth = cast<IntegerType>(DstVecTy)->getBitWidth(); |
| 1243 | unsigned size = Src.AggregateVal.size(); |
| 1244 | // the sizes of src and dst vectors must be equal. |
| 1245 | Dest.AggregateVal.resize(size); |
| 1246 | for (unsigned i = 0; i < size; i++) |
| 1247 | Dest.AggregateVal[i].IntVal = Src.AggregateVal[i].IntVal.sext(DBitWidth); |
| 1248 | } else { |
| 1249 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1250 | unsigned DBitWidth = DITy->getBitWidth(); |
| 1251 | Dest.IntVal = Src.IntVal.sext(DBitWidth); |
| 1252 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1253 | return Dest; |
| 1254 | } |
| 1255 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1256 | GenericValue Interpreter::executeZExtInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1257 | ExecutionContext &SF) { |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1258 | const Type *SrcTy = SrcVal->getType(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1259 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1260 | if (SrcTy->isVectorTy()) { |
| 1261 | const Type *DstVecTy = DstTy->getScalarType(); |
| 1262 | unsigned DBitWidth = cast<IntegerType>(DstVecTy)->getBitWidth(); |
| 1263 | |
| 1264 | unsigned size = Src.AggregateVal.size(); |
| 1265 | // the sizes of src and dst vectors must be equal. |
| 1266 | Dest.AggregateVal.resize(size); |
| 1267 | for (unsigned i = 0; i < size; i++) |
| 1268 | Dest.AggregateVal[i].IntVal = Src.AggregateVal[i].IntVal.zext(DBitWidth); |
| 1269 | } else { |
| 1270 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1271 | unsigned DBitWidth = DITy->getBitWidth(); |
| 1272 | Dest.IntVal = Src.IntVal.zext(DBitWidth); |
| 1273 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1274 | return Dest; |
| 1275 | } |
| 1276 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1277 | GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1278 | ExecutionContext &SF) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1279 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1280 | |
| 1281 | if (SrcVal->getType()->getTypeID() == Type::VectorTyID) { |
| 1282 | assert(SrcVal->getType()->getScalarType()->isDoubleTy() && |
| 1283 | DstTy->getScalarType()->isFloatTy() && |
| 1284 | "Invalid FPTrunc instruction"); |
| 1285 | |
| 1286 | unsigned size = Src.AggregateVal.size(); |
| 1287 | // the sizes of src and dst vectors must be equal. |
| 1288 | Dest.AggregateVal.resize(size); |
| 1289 | for (unsigned i = 0; i < size; i++) |
| 1290 | Dest.AggregateVal[i].FloatVal = (float)Src.AggregateVal[i].DoubleVal; |
| 1291 | } else { |
| 1292 | assert(SrcVal->getType()->isDoubleTy() && DstTy->isFloatTy() && |
| 1293 | "Invalid FPTrunc instruction"); |
| 1294 | Dest.FloatVal = (float)Src.DoubleVal; |
| 1295 | } |
| 1296 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1297 | return Dest; |
| 1298 | } |
| 1299 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1300 | GenericValue Interpreter::executeFPExtInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1301 | ExecutionContext &SF) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1302 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1303 | |
| 1304 | if (SrcVal->getType()->getTypeID() == Type::VectorTyID) { |
| 1305 | assert(SrcVal->getType()->getScalarType()->isFloatTy() && |
| 1306 | DstTy->getScalarType()->isDoubleTy() && "Invalid FPExt instruction"); |
| 1307 | |
| 1308 | unsigned size = Src.AggregateVal.size(); |
| 1309 | // the sizes of src and dst vectors must be equal. |
| 1310 | Dest.AggregateVal.resize(size); |
| 1311 | for (unsigned i = 0; i < size; i++) |
| 1312 | Dest.AggregateVal[i].DoubleVal = (double)Src.AggregateVal[i].FloatVal; |
| 1313 | } else { |
| 1314 | assert(SrcVal->getType()->isFloatTy() && DstTy->isDoubleTy() && |
| 1315 | "Invalid FPExt instruction"); |
| 1316 | Dest.DoubleVal = (double)Src.FloatVal; |
| 1317 | } |
| 1318 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1319 | return Dest; |
| 1320 | } |
| 1321 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1322 | GenericValue Interpreter::executeFPToUIInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1323 | ExecutionContext &SF) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1324 | Type *SrcTy = SrcVal->getType(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1325 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1326 | |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1327 | if (SrcTy->getTypeID() == Type::VectorTyID) { |
| 1328 | const Type *DstVecTy = DstTy->getScalarType(); |
| 1329 | const Type *SrcVecTy = SrcTy->getScalarType(); |
| 1330 | uint32_t DBitWidth = cast<IntegerType>(DstVecTy)->getBitWidth(); |
| 1331 | unsigned size = Src.AggregateVal.size(); |
| 1332 | // the sizes of src and dst vectors must be equal. |
| 1333 | Dest.AggregateVal.resize(size); |
| 1334 | |
| 1335 | if (SrcVecTy->getTypeID() == Type::FloatTyID) { |
| 1336 | assert(SrcVecTy->isFloatingPointTy() && "Invalid FPToUI instruction"); |
| 1337 | for (unsigned i = 0; i < size; i++) |
| 1338 | Dest.AggregateVal[i].IntVal = APIntOps::RoundFloatToAPInt( |
| 1339 | Src.AggregateVal[i].FloatVal, DBitWidth); |
| 1340 | } else { |
| 1341 | for (unsigned i = 0; i < size; i++) |
| 1342 | Dest.AggregateVal[i].IntVal = APIntOps::RoundDoubleToAPInt( |
| 1343 | Src.AggregateVal[i].DoubleVal, DBitWidth); |
| 1344 | } |
| 1345 | } else { |
| 1346 | // scalar |
| 1347 | uint32_t DBitWidth = cast<IntegerType>(DstTy)->getBitWidth(); |
| 1348 | assert(SrcTy->isFloatingPointTy() && "Invalid FPToUI instruction"); |
| 1349 | |
| 1350 | if (SrcTy->getTypeID() == Type::FloatTyID) |
| 1351 | Dest.IntVal = APIntOps::RoundFloatToAPInt(Src.FloatVal, DBitWidth); |
| 1352 | else { |
| 1353 | Dest.IntVal = APIntOps::RoundDoubleToAPInt(Src.DoubleVal, DBitWidth); |
| 1354 | } |
| 1355 | } |
| 1356 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1357 | return Dest; |
| 1358 | } |
| 1359 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1360 | GenericValue Interpreter::executeFPToSIInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1361 | ExecutionContext &SF) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1362 | Type *SrcTy = SrcVal->getType(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1363 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1364 | |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1365 | if (SrcTy->getTypeID() == Type::VectorTyID) { |
| 1366 | const Type *DstVecTy = DstTy->getScalarType(); |
| 1367 | const Type *SrcVecTy = SrcTy->getScalarType(); |
| 1368 | uint32_t DBitWidth = cast<IntegerType>(DstVecTy)->getBitWidth(); |
| 1369 | unsigned size = Src.AggregateVal.size(); |
| 1370 | // the sizes of src and dst vectors must be equal |
| 1371 | Dest.AggregateVal.resize(size); |
| 1372 | |
| 1373 | if (SrcVecTy->getTypeID() == Type::FloatTyID) { |
| 1374 | assert(SrcVecTy->isFloatingPointTy() && "Invalid FPToSI instruction"); |
| 1375 | for (unsigned i = 0; i < size; i++) |
| 1376 | Dest.AggregateVal[i].IntVal = APIntOps::RoundFloatToAPInt( |
| 1377 | Src.AggregateVal[i].FloatVal, DBitWidth); |
| 1378 | } else { |
| 1379 | for (unsigned i = 0; i < size; i++) |
| 1380 | Dest.AggregateVal[i].IntVal = APIntOps::RoundDoubleToAPInt( |
| 1381 | Src.AggregateVal[i].DoubleVal, DBitWidth); |
| 1382 | } |
| 1383 | } else { |
| 1384 | // scalar |
| 1385 | unsigned DBitWidth = cast<IntegerType>(DstTy)->getBitWidth(); |
| 1386 | assert(SrcTy->isFloatingPointTy() && "Invalid FPToSI instruction"); |
| 1387 | |
| 1388 | if (SrcTy->getTypeID() == Type::FloatTyID) |
| 1389 | Dest.IntVal = APIntOps::RoundFloatToAPInt(Src.FloatVal, DBitWidth); |
| 1390 | else { |
| 1391 | Dest.IntVal = APIntOps::RoundDoubleToAPInt(Src.DoubleVal, DBitWidth); |
| 1392 | } |
| 1393 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1394 | return Dest; |
| 1395 | } |
| 1396 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1397 | GenericValue Interpreter::executeUIToFPInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1398 | ExecutionContext &SF) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1399 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1400 | |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1401 | if (SrcVal->getType()->getTypeID() == Type::VectorTyID) { |
| 1402 | const Type *DstVecTy = DstTy->getScalarType(); |
| 1403 | unsigned size = Src.AggregateVal.size(); |
| 1404 | // the sizes of src and dst vectors must be equal |
| 1405 | Dest.AggregateVal.resize(size); |
| 1406 | |
| 1407 | if (DstVecTy->getTypeID() == Type::FloatTyID) { |
| 1408 | assert(DstVecTy->isFloatingPointTy() && "Invalid UIToFP instruction"); |
| 1409 | for (unsigned i = 0; i < size; i++) |
| 1410 | Dest.AggregateVal[i].FloatVal = |
| 1411 | APIntOps::RoundAPIntToFloat(Src.AggregateVal[i].IntVal); |
| 1412 | } else { |
| 1413 | for (unsigned i = 0; i < size; i++) |
| 1414 | Dest.AggregateVal[i].DoubleVal = |
| 1415 | APIntOps::RoundAPIntToDouble(Src.AggregateVal[i].IntVal); |
| 1416 | } |
| 1417 | } else { |
| 1418 | // scalar |
| 1419 | assert(DstTy->isFloatingPointTy() && "Invalid UIToFP instruction"); |
| 1420 | if (DstTy->getTypeID() == Type::FloatTyID) |
| 1421 | Dest.FloatVal = APIntOps::RoundAPIntToFloat(Src.IntVal); |
| 1422 | else { |
| 1423 | Dest.DoubleVal = APIntOps::RoundAPIntToDouble(Src.IntVal); |
| 1424 | } |
| 1425 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1426 | return Dest; |
| 1427 | } |
| 1428 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1429 | GenericValue Interpreter::executeSIToFPInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1430 | ExecutionContext &SF) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1431 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1432 | |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1433 | if (SrcVal->getType()->getTypeID() == Type::VectorTyID) { |
| 1434 | const Type *DstVecTy = DstTy->getScalarType(); |
| 1435 | unsigned size = Src.AggregateVal.size(); |
| 1436 | // the sizes of src and dst vectors must be equal |
| 1437 | Dest.AggregateVal.resize(size); |
| 1438 | |
| 1439 | if (DstVecTy->getTypeID() == Type::FloatTyID) { |
| 1440 | assert(DstVecTy->isFloatingPointTy() && "Invalid SIToFP instruction"); |
| 1441 | for (unsigned i = 0; i < size; i++) |
| 1442 | Dest.AggregateVal[i].FloatVal = |
| 1443 | APIntOps::RoundSignedAPIntToFloat(Src.AggregateVal[i].IntVal); |
| 1444 | } else { |
| 1445 | for (unsigned i = 0; i < size; i++) |
| 1446 | Dest.AggregateVal[i].DoubleVal = |
| 1447 | APIntOps::RoundSignedAPIntToDouble(Src.AggregateVal[i].IntVal); |
| 1448 | } |
| 1449 | } else { |
| 1450 | // scalar |
| 1451 | assert(DstTy->isFloatingPointTy() && "Invalid SIToFP instruction"); |
| 1452 | |
| 1453 | if (DstTy->getTypeID() == Type::FloatTyID) |
| 1454 | Dest.FloatVal = APIntOps::RoundSignedAPIntToFloat(Src.IntVal); |
| 1455 | else { |
| 1456 | Dest.DoubleVal = APIntOps::RoundSignedAPIntToDouble(Src.IntVal); |
| 1457 | } |
| 1458 | } |
| 1459 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1460 | return Dest; |
| 1461 | } |
| 1462 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1463 | GenericValue Interpreter::executePtrToIntInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1464 | ExecutionContext &SF) { |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 1465 | uint32_t DBitWidth = cast<IntegerType>(DstTy)->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1466 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Duncan Sands | 1df9859 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 1467 | assert(SrcVal->getType()->isPointerTy() && "Invalid PtrToInt instruction"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1468 | |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 1469 | Dest.IntVal = APInt(DBitWidth, (intptr_t) Src.PointerVal); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1470 | return Dest; |
| 1471 | } |
| 1472 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1473 | GenericValue Interpreter::executeIntToPtrInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1474 | ExecutionContext &SF) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1475 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Duncan Sands | 1df9859 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 1476 | assert(DstTy->isPointerTy() && "Invalid PtrToInt instruction"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1477 | |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 1478 | uint32_t PtrSize = TD.getPointerSizeInBits(); |
Reid Spencer | 7553c34 | 2007-03-06 03:41:50 +0000 | [diff] [blame] | 1479 | if (PtrSize != Src.IntVal.getBitWidth()) |
Reid Spencer | 5763105 | 2007-03-06 03:46:41 +0000 | [diff] [blame] | 1480 | Src.IntVal = Src.IntVal.zextOrTrunc(PtrSize); |
Reid Spencer | 7553c34 | 2007-03-06 03:41:50 +0000 | [diff] [blame] | 1481 | |
Reid Spencer | 6bc6333 | 2007-04-26 18:19:35 +0000 | [diff] [blame] | 1482 | Dest.PointerVal = PointerTy(intptr_t(Src.IntVal.getZExtValue())); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1483 | return Dest; |
| 1484 | } |
| 1485 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1486 | GenericValue Interpreter::executeBitCastInst(Value *SrcVal, Type *DstTy, |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1487 | ExecutionContext &SF) { |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1488 | |
| 1489 | // This instruction supports bitwise conversion of vectors to integers and |
| 1490 | // to vectors of other types (as long as they have the same size) |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1491 | Type *SrcTy = SrcVal->getType(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1492 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1493 | |
| 1494 | if ((SrcTy->getTypeID() == Type::VectorTyID) || |
| 1495 | (DstTy->getTypeID() == Type::VectorTyID)) { |
| 1496 | // vector src bitcast to vector dst or vector src bitcast to scalar dst or |
| 1497 | // scalar src bitcast to vector dst |
| 1498 | bool isLittleEndian = TD.isLittleEndian(); |
| 1499 | GenericValue TempDst, TempSrc, SrcVec; |
| 1500 | const Type *SrcElemTy; |
| 1501 | const Type *DstElemTy; |
| 1502 | unsigned SrcBitSize; |
| 1503 | unsigned DstBitSize; |
| 1504 | unsigned SrcNum; |
| 1505 | unsigned DstNum; |
| 1506 | |
| 1507 | if (SrcTy->getTypeID() == Type::VectorTyID) { |
| 1508 | SrcElemTy = SrcTy->getScalarType(); |
| 1509 | SrcBitSize = SrcTy->getScalarSizeInBits(); |
| 1510 | SrcNum = Src.AggregateVal.size(); |
| 1511 | SrcVec = Src; |
| 1512 | } else { |
| 1513 | // if src is scalar value, make it vector <1 x type> |
| 1514 | SrcElemTy = SrcTy; |
| 1515 | SrcBitSize = SrcTy->getPrimitiveSizeInBits(); |
| 1516 | SrcNum = 1; |
| 1517 | SrcVec.AggregateVal.push_back(Src); |
| 1518 | } |
| 1519 | |
| 1520 | if (DstTy->getTypeID() == Type::VectorTyID) { |
| 1521 | DstElemTy = DstTy->getScalarType(); |
| 1522 | DstBitSize = DstTy->getScalarSizeInBits(); |
| 1523 | DstNum = (SrcNum * SrcBitSize) / DstBitSize; |
| 1524 | } else { |
| 1525 | DstElemTy = DstTy; |
| 1526 | DstBitSize = DstTy->getPrimitiveSizeInBits(); |
| 1527 | DstNum = 1; |
| 1528 | } |
| 1529 | |
| 1530 | if (SrcNum * SrcBitSize != DstNum * DstBitSize) |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1531 | llvm_unreachable("Invalid BitCast"); |
Elena Demikhovsky | cf21d15 | 2013-08-05 12:17:06 +0000 | [diff] [blame] | 1532 | |
| 1533 | // If src is floating point, cast to integer first. |
| 1534 | TempSrc.AggregateVal.resize(SrcNum); |
| 1535 | if (SrcElemTy->isFloatTy()) { |
| 1536 | for (unsigned i = 0; i < SrcNum; i++) |
| 1537 | TempSrc.AggregateVal[i].IntVal = |
| 1538 | APInt::floatToBits(SrcVec.AggregateVal[i].FloatVal); |
| 1539 | |
| 1540 | } else if (SrcElemTy->isDoubleTy()) { |
| 1541 | for (unsigned i = 0; i < SrcNum; i++) |
| 1542 | TempSrc.AggregateVal[i].IntVal = |
| 1543 | APInt::doubleToBits(SrcVec.AggregateVal[i].DoubleVal); |
| 1544 | } else if (SrcElemTy->isIntegerTy()) { |
| 1545 | for (unsigned i = 0; i < SrcNum; i++) |
| 1546 | TempSrc.AggregateVal[i].IntVal = SrcVec.AggregateVal[i].IntVal; |
| 1547 | } else { |
| 1548 | // Pointers are not allowed as the element type of vector. |
| 1549 | llvm_unreachable("Invalid Bitcast"); |
| 1550 | } |
| 1551 | |
| 1552 | // now TempSrc is integer type vector |
| 1553 | if (DstNum < SrcNum) { |
| 1554 | // Example: bitcast <4 x i32> <i32 0, i32 1, i32 2, i32 3> to <2 x i64> |
| 1555 | unsigned Ratio = SrcNum / DstNum; |
| 1556 | unsigned SrcElt = 0; |
| 1557 | for (unsigned i = 0; i < DstNum; i++) { |
| 1558 | GenericValue Elt; |
| 1559 | Elt.IntVal = 0; |
| 1560 | Elt.IntVal = Elt.IntVal.zext(DstBitSize); |
| 1561 | unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize * (Ratio - 1); |
| 1562 | for (unsigned j = 0; j < Ratio; j++) { |
| 1563 | APInt Tmp; |
| 1564 | Tmp = Tmp.zext(SrcBitSize); |
| 1565 | Tmp = TempSrc.AggregateVal[SrcElt++].IntVal; |
| 1566 | Tmp = Tmp.zext(DstBitSize); |
| 1567 | Tmp = Tmp.shl(ShiftAmt); |
| 1568 | ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize; |
| 1569 | Elt.IntVal |= Tmp; |
| 1570 | } |
| 1571 | TempDst.AggregateVal.push_back(Elt); |
| 1572 | } |
| 1573 | } else { |
| 1574 | // Example: bitcast <2 x i64> <i64 0, i64 1> to <4 x i32> |
| 1575 | unsigned Ratio = DstNum / SrcNum; |
| 1576 | for (unsigned i = 0; i < SrcNum; i++) { |
| 1577 | unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize * (Ratio - 1); |
| 1578 | for (unsigned j = 0; j < Ratio; j++) { |
| 1579 | GenericValue Elt; |
| 1580 | Elt.IntVal = Elt.IntVal.zext(SrcBitSize); |
| 1581 | Elt.IntVal = TempSrc.AggregateVal[i].IntVal; |
| 1582 | Elt.IntVal = Elt.IntVal.lshr(ShiftAmt); |
| 1583 | // it could be DstBitSize == SrcBitSize, so check it |
| 1584 | if (DstBitSize < SrcBitSize) |
| 1585 | Elt.IntVal = Elt.IntVal.trunc(DstBitSize); |
| 1586 | ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize; |
| 1587 | TempDst.AggregateVal.push_back(Elt); |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | // convert result from integer to specified type |
| 1593 | if (DstTy->getTypeID() == Type::VectorTyID) { |
| 1594 | if (DstElemTy->isDoubleTy()) { |
| 1595 | Dest.AggregateVal.resize(DstNum); |
| 1596 | for (unsigned i = 0; i < DstNum; i++) |
| 1597 | Dest.AggregateVal[i].DoubleVal = |
| 1598 | TempDst.AggregateVal[i].IntVal.bitsToDouble(); |
| 1599 | } else if (DstElemTy->isFloatTy()) { |
| 1600 | Dest.AggregateVal.resize(DstNum); |
| 1601 | for (unsigned i = 0; i < DstNum; i++) |
| 1602 | Dest.AggregateVal[i].FloatVal = |
| 1603 | TempDst.AggregateVal[i].IntVal.bitsToFloat(); |
| 1604 | } else { |
| 1605 | Dest = TempDst; |
| 1606 | } |
| 1607 | } else { |
| 1608 | if (DstElemTy->isDoubleTy()) |
| 1609 | Dest.DoubleVal = TempDst.AggregateVal[0].IntVal.bitsToDouble(); |
| 1610 | else if (DstElemTy->isFloatTy()) { |
| 1611 | Dest.FloatVal = TempDst.AggregateVal[0].IntVal.bitsToFloat(); |
| 1612 | } else { |
| 1613 | Dest.IntVal = TempDst.AggregateVal[0].IntVal; |
| 1614 | } |
| 1615 | } |
| 1616 | } else { // if ((SrcTy->getTypeID() == Type::VectorTyID) || |
| 1617 | // (DstTy->getTypeID() == Type::VectorTyID)) |
| 1618 | |
| 1619 | // scalar src bitcast to scalar dst |
| 1620 | if (DstTy->isPointerTy()) { |
| 1621 | assert(SrcTy->isPointerTy() && "Invalid BitCast"); |
| 1622 | Dest.PointerVal = Src.PointerVal; |
| 1623 | } else if (DstTy->isIntegerTy()) { |
| 1624 | if (SrcTy->isFloatTy()) |
| 1625 | Dest.IntVal = APInt::floatToBits(Src.FloatVal); |
| 1626 | else if (SrcTy->isDoubleTy()) { |
| 1627 | Dest.IntVal = APInt::doubleToBits(Src.DoubleVal); |
| 1628 | } else if (SrcTy->isIntegerTy()) { |
| 1629 | Dest.IntVal = Src.IntVal; |
| 1630 | } else { |
| 1631 | llvm_unreachable("Invalid BitCast"); |
| 1632 | } |
| 1633 | } else if (DstTy->isFloatTy()) { |
| 1634 | if (SrcTy->isIntegerTy()) |
| 1635 | Dest.FloatVal = Src.IntVal.bitsToFloat(); |
| 1636 | else { |
| 1637 | Dest.FloatVal = Src.FloatVal; |
| 1638 | } |
| 1639 | } else if (DstTy->isDoubleTy()) { |
| 1640 | if (SrcTy->isIntegerTy()) |
| 1641 | Dest.DoubleVal = Src.IntVal.bitsToDouble(); |
| 1642 | else { |
| 1643 | Dest.DoubleVal = Src.DoubleVal; |
| 1644 | } |
| 1645 | } else { |
| 1646 | llvm_unreachable("Invalid Bitcast"); |
| 1647 | } |
| 1648 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1649 | |
| 1650 | return Dest; |
| 1651 | } |
| 1652 | |
| 1653 | void Interpreter::visitTruncInst(TruncInst &I) { |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 1654 | ExecutionContext &SF = ECStack.back(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1655 | SetValue(&I, executeTruncInst(I.getOperand(0), I.getType(), SF), SF); |
| 1656 | } |
| 1657 | |
| 1658 | void Interpreter::visitSExtInst(SExtInst &I) { |
| 1659 | ExecutionContext &SF = ECStack.back(); |
| 1660 | SetValue(&I, executeSExtInst(I.getOperand(0), I.getType(), SF), SF); |
| 1661 | } |
| 1662 | |
| 1663 | void Interpreter::visitZExtInst(ZExtInst &I) { |
| 1664 | ExecutionContext &SF = ECStack.back(); |
| 1665 | SetValue(&I, executeZExtInst(I.getOperand(0), I.getType(), SF), SF); |
| 1666 | } |
| 1667 | |
| 1668 | void Interpreter::visitFPTruncInst(FPTruncInst &I) { |
| 1669 | ExecutionContext &SF = ECStack.back(); |
| 1670 | SetValue(&I, executeFPTruncInst(I.getOperand(0), I.getType(), SF), SF); |
| 1671 | } |
| 1672 | |
| 1673 | void Interpreter::visitFPExtInst(FPExtInst &I) { |
| 1674 | ExecutionContext &SF = ECStack.back(); |
| 1675 | SetValue(&I, executeFPExtInst(I.getOperand(0), I.getType(), SF), SF); |
| 1676 | } |
| 1677 | |
| 1678 | void Interpreter::visitUIToFPInst(UIToFPInst &I) { |
| 1679 | ExecutionContext &SF = ECStack.back(); |
| 1680 | SetValue(&I, executeUIToFPInst(I.getOperand(0), I.getType(), SF), SF); |
| 1681 | } |
| 1682 | |
| 1683 | void Interpreter::visitSIToFPInst(SIToFPInst &I) { |
| 1684 | ExecutionContext &SF = ECStack.back(); |
| 1685 | SetValue(&I, executeSIToFPInst(I.getOperand(0), I.getType(), SF), SF); |
| 1686 | } |
| 1687 | |
| 1688 | void Interpreter::visitFPToUIInst(FPToUIInst &I) { |
| 1689 | ExecutionContext &SF = ECStack.back(); |
| 1690 | SetValue(&I, executeFPToUIInst(I.getOperand(0), I.getType(), SF), SF); |
| 1691 | } |
| 1692 | |
| 1693 | void Interpreter::visitFPToSIInst(FPToSIInst &I) { |
| 1694 | ExecutionContext &SF = ECStack.back(); |
| 1695 | SetValue(&I, executeFPToSIInst(I.getOperand(0), I.getType(), SF), SF); |
| 1696 | } |
| 1697 | |
| 1698 | void Interpreter::visitPtrToIntInst(PtrToIntInst &I) { |
| 1699 | ExecutionContext &SF = ECStack.back(); |
| 1700 | SetValue(&I, executePtrToIntInst(I.getOperand(0), I.getType(), SF), SF); |
| 1701 | } |
| 1702 | |
| 1703 | void Interpreter::visitIntToPtrInst(IntToPtrInst &I) { |
| 1704 | ExecutionContext &SF = ECStack.back(); |
| 1705 | SetValue(&I, executeIntToPtrInst(I.getOperand(0), I.getType(), SF), SF); |
| 1706 | } |
| 1707 | |
| 1708 | void Interpreter::visitBitCastInst(BitCastInst &I) { |
| 1709 | ExecutionContext &SF = ECStack.back(); |
| 1710 | SetValue(&I, executeBitCastInst(I.getOperand(0), I.getType(), SF), SF); |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1711 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1712 | |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1713 | #define IMPLEMENT_VAARG(TY) \ |
| 1714 | case Type::TY##TyID: Dest.TY##Val = Src.TY##Val; break |
| 1715 | |
| 1716 | void Interpreter::visitVAArgInst(VAArgInst &I) { |
| 1717 | ExecutionContext &SF = ECStack.back(); |
| 1718 | |
Brian Gaeke | 9d20b71 | 2004-02-25 23:01:48 +0000 | [diff] [blame] | 1719 | // Get the incoming valist parameter. LLI treats the valist as a |
| 1720 | // (ec-stack-depth var-arg-index) pair. |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1721 | GenericValue VAList = getOperandValue(I.getOperand(0), SF); |
Brian Gaeke | 9d20b71 | 2004-02-25 23:01:48 +0000 | [diff] [blame] | 1722 | GenericValue Dest; |
| 1723 | GenericValue Src = ECStack[VAList.UIntPairVal.first] |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 1724 | .VarArgs[VAList.UIntPairVal.second]; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1725 | Type *Ty = I.getType(); |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 1726 | switch (Ty->getTypeID()) { |
Jim Grosbach | cce07c9 | 2013-01-31 19:46:59 +0000 | [diff] [blame] | 1727 | case Type::IntegerTyID: |
| 1728 | Dest.IntVal = Src.IntVal; |
Jim Grosbach | cce07c9 | 2013-01-31 19:46:59 +0000 | [diff] [blame] | 1729 | break; |
Jim Grosbach | 9f285c6 | 2013-02-01 18:57:06 +0000 | [diff] [blame] | 1730 | IMPLEMENT_VAARG(Pointer); |
| 1731 | IMPLEMENT_VAARG(Float); |
| 1732 | IMPLEMENT_VAARG(Double); |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1733 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 1734 | dbgs() << "Unhandled dest type for vaarg instruction: " << *Ty << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1735 | llvm_unreachable(0); |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1736 | } |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1737 | |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1738 | // Set the Value of this Instruction. |
| 1739 | SetValue(&I, Dest, SF); |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 1740 | |
| 1741 | // Move the pointer to the next vararg. |
| 1742 | ++VAList.UIntPairVal.second; |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
Nadav Rotem | 953783e | 2013-04-01 15:53:30 +0000 | [diff] [blame] | 1745 | void Interpreter::visitExtractElementInst(ExtractElementInst &I) { |
| 1746 | ExecutionContext &SF = ECStack.back(); |
| 1747 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1748 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1749 | GenericValue Dest; |
| 1750 | |
| 1751 | Type *Ty = I.getType(); |
| 1752 | const unsigned indx = unsigned(Src2.IntVal.getZExtValue()); |
| 1753 | |
| 1754 | if(Src1.AggregateVal.size() > indx) { |
| 1755 | switch (Ty->getTypeID()) { |
| 1756 | default: |
| 1757 | dbgs() << "Unhandled destination type for extractelement instruction: " |
| 1758 | << *Ty << "\n"; |
| 1759 | llvm_unreachable(0); |
| 1760 | break; |
| 1761 | case Type::IntegerTyID: |
| 1762 | Dest.IntVal = Src1.AggregateVal[indx].IntVal; |
| 1763 | break; |
| 1764 | case Type::FloatTyID: |
| 1765 | Dest.FloatVal = Src1.AggregateVal[indx].FloatVal; |
| 1766 | break; |
| 1767 | case Type::DoubleTyID: |
| 1768 | Dest.DoubleVal = Src1.AggregateVal[indx].DoubleVal; |
| 1769 | break; |
| 1770 | } |
| 1771 | } else { |
| 1772 | dbgs() << "Invalid index in extractelement instruction\n"; |
| 1773 | } |
| 1774 | |
| 1775 | SetValue(&I, Dest, SF); |
| 1776 | } |
| 1777 | |
Elena Demikhovsky | 4ca0ce2 | 2013-09-02 06:40:09 +0000 | [diff] [blame] | 1778 | void Interpreter::visitInsertElementInst(InsertElementInst &I) { |
| 1779 | ExecutionContext &SF = ECStack.back(); |
| 1780 | Type *Ty = I.getType(); |
| 1781 | |
| 1782 | if(!(Ty->isVectorTy()) ) |
| 1783 | llvm_unreachable("Unhandled dest type for insertelement instruction"); |
| 1784 | |
| 1785 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1786 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1787 | GenericValue Src3 = getOperandValue(I.getOperand(2), SF); |
| 1788 | GenericValue Dest; |
| 1789 | |
| 1790 | Type *TyContained = Ty->getContainedType(0); |
| 1791 | |
| 1792 | const unsigned indx = unsigned(Src3.IntVal.getZExtValue()); |
| 1793 | Dest.AggregateVal = Src1.AggregateVal; |
| 1794 | |
| 1795 | if(Src1.AggregateVal.size() <= indx) |
| 1796 | llvm_unreachable("Invalid index in insertelement instruction"); |
| 1797 | switch (TyContained->getTypeID()) { |
| 1798 | default: |
| 1799 | llvm_unreachable("Unhandled dest type for insertelement instruction"); |
| 1800 | case Type::IntegerTyID: |
| 1801 | Dest.AggregateVal[indx].IntVal = Src2.IntVal; |
| 1802 | break; |
| 1803 | case Type::FloatTyID: |
| 1804 | Dest.AggregateVal[indx].FloatVal = Src2.FloatVal; |
| 1805 | break; |
| 1806 | case Type::DoubleTyID: |
| 1807 | Dest.AggregateVal[indx].DoubleVal = Src2.DoubleVal; |
| 1808 | break; |
| 1809 | } |
| 1810 | SetValue(&I, Dest, SF); |
| 1811 | } |
| 1812 | |
| 1813 | void Interpreter::visitShuffleVectorInst(ShuffleVectorInst &I){ |
| 1814 | ExecutionContext &SF = ECStack.back(); |
| 1815 | |
| 1816 | Type *Ty = I.getType(); |
| 1817 | if(!(Ty->isVectorTy())) |
| 1818 | llvm_unreachable("Unhandled dest type for shufflevector instruction"); |
| 1819 | |
| 1820 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1821 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1822 | GenericValue Src3 = getOperandValue(I.getOperand(2), SF); |
| 1823 | GenericValue Dest; |
| 1824 | |
| 1825 | // There is no need to check types of src1 and src2, because the compiled |
| 1826 | // bytecode can't contain different types for src1 and src2 for a |
| 1827 | // shufflevector instruction. |
| 1828 | |
| 1829 | Type *TyContained = Ty->getContainedType(0); |
| 1830 | unsigned src1Size = (unsigned)Src1.AggregateVal.size(); |
| 1831 | unsigned src2Size = (unsigned)Src2.AggregateVal.size(); |
| 1832 | unsigned src3Size = (unsigned)Src3.AggregateVal.size(); |
| 1833 | |
| 1834 | Dest.AggregateVal.resize(src3Size); |
| 1835 | |
| 1836 | switch (TyContained->getTypeID()) { |
| 1837 | default: |
| 1838 | llvm_unreachable("Unhandled dest type for insertelement instruction"); |
| 1839 | break; |
| 1840 | case Type::IntegerTyID: |
| 1841 | for( unsigned i=0; i<src3Size; i++) { |
| 1842 | unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue(); |
| 1843 | if(j < src1Size) |
| 1844 | Dest.AggregateVal[i].IntVal = Src1.AggregateVal[j].IntVal; |
| 1845 | else if(j < src1Size + src2Size) |
| 1846 | Dest.AggregateVal[i].IntVal = Src2.AggregateVal[j-src1Size].IntVal; |
| 1847 | else |
| 1848 | // The selector may not be greater than sum of lengths of first and |
| 1849 | // second operands and llasm should not allow situation like |
| 1850 | // %tmp = shufflevector <2 x i32> <i32 3, i32 4>, <2 x i32> undef, |
| 1851 | // <2 x i32> < i32 0, i32 5 >, |
| 1852 | // where i32 5 is invalid, but let it be additional check here: |
| 1853 | llvm_unreachable("Invalid mask in shufflevector instruction"); |
| 1854 | } |
| 1855 | break; |
| 1856 | case Type::FloatTyID: |
| 1857 | for( unsigned i=0; i<src3Size; i++) { |
| 1858 | unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue(); |
| 1859 | if(j < src1Size) |
| 1860 | Dest.AggregateVal[i].FloatVal = Src1.AggregateVal[j].FloatVal; |
| 1861 | else if(j < src1Size + src2Size) |
| 1862 | Dest.AggregateVal[i].FloatVal = Src2.AggregateVal[j-src1Size].FloatVal; |
| 1863 | else |
| 1864 | llvm_unreachable("Invalid mask in shufflevector instruction"); |
| 1865 | } |
| 1866 | break; |
| 1867 | case Type::DoubleTyID: |
| 1868 | for( unsigned i=0; i<src3Size; i++) { |
| 1869 | unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue(); |
| 1870 | if(j < src1Size) |
| 1871 | Dest.AggregateVal[i].DoubleVal = Src1.AggregateVal[j].DoubleVal; |
| 1872 | else if(j < src1Size + src2Size) |
| 1873 | Dest.AggregateVal[i].DoubleVal = |
| 1874 | Src2.AggregateVal[j-src1Size].DoubleVal; |
| 1875 | else |
| 1876 | llvm_unreachable("Invalid mask in shufflevector instruction"); |
| 1877 | } |
| 1878 | break; |
| 1879 | } |
| 1880 | SetValue(&I, Dest, SF); |
| 1881 | } |
| 1882 | |
Elena Demikhovsky | 3c5ce29 | 2013-09-12 10:48:23 +0000 | [diff] [blame] | 1883 | void Interpreter::visitExtractValueInst(ExtractValueInst &I) { |
| 1884 | ExecutionContext &SF = ECStack.back(); |
| 1885 | Value *Agg = I.getAggregateOperand(); |
| 1886 | GenericValue Dest; |
| 1887 | GenericValue Src = getOperandValue(Agg, SF); |
| 1888 | |
| 1889 | ExtractValueInst::idx_iterator IdxBegin = I.idx_begin(); |
| 1890 | unsigned Num = I.getNumIndices(); |
| 1891 | GenericValue *pSrc = &Src; |
| 1892 | |
| 1893 | for (unsigned i = 0 ; i < Num; ++i) { |
| 1894 | pSrc = &pSrc->AggregateVal[*IdxBegin]; |
| 1895 | ++IdxBegin; |
| 1896 | } |
| 1897 | |
| 1898 | Type *IndexedType = ExtractValueInst::getIndexedType(Agg->getType(), I.getIndices()); |
| 1899 | switch (IndexedType->getTypeID()) { |
| 1900 | default: |
| 1901 | llvm_unreachable("Unhandled dest type for extractelement instruction"); |
| 1902 | break; |
| 1903 | case Type::IntegerTyID: |
| 1904 | Dest.IntVal = pSrc->IntVal; |
| 1905 | break; |
| 1906 | case Type::FloatTyID: |
| 1907 | Dest.FloatVal = pSrc->FloatVal; |
| 1908 | break; |
| 1909 | case Type::DoubleTyID: |
| 1910 | Dest.DoubleVal = pSrc->DoubleVal; |
| 1911 | break; |
| 1912 | case Type::ArrayTyID: |
| 1913 | case Type::StructTyID: |
| 1914 | case Type::VectorTyID: |
| 1915 | Dest.AggregateVal = pSrc->AggregateVal; |
| 1916 | break; |
| 1917 | case Type::PointerTyID: |
| 1918 | Dest.PointerVal = pSrc->PointerVal; |
| 1919 | break; |
| 1920 | } |
| 1921 | |
| 1922 | SetValue(&I, Dest, SF); |
| 1923 | } |
| 1924 | |
| 1925 | void Interpreter::visitInsertValueInst(InsertValueInst &I) { |
| 1926 | |
| 1927 | ExecutionContext &SF = ECStack.back(); |
| 1928 | Value *Agg = I.getAggregateOperand(); |
| 1929 | |
| 1930 | GenericValue Src1 = getOperandValue(Agg, SF); |
| 1931 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1932 | GenericValue Dest = Src1; // Dest is a slightly changed Src1 |
| 1933 | |
| 1934 | ExtractValueInst::idx_iterator IdxBegin = I.idx_begin(); |
| 1935 | unsigned Num = I.getNumIndices(); |
| 1936 | |
| 1937 | GenericValue *pDest = &Dest; |
| 1938 | for (unsigned i = 0 ; i < Num; ++i) { |
| 1939 | pDest = &pDest->AggregateVal[*IdxBegin]; |
| 1940 | ++IdxBegin; |
| 1941 | } |
| 1942 | // pDest points to the target value in the Dest now |
| 1943 | |
| 1944 | Type *IndexedType = ExtractValueInst::getIndexedType(Agg->getType(), I.getIndices()); |
| 1945 | |
| 1946 | switch (IndexedType->getTypeID()) { |
| 1947 | default: |
| 1948 | llvm_unreachable("Unhandled dest type for insertelement instruction"); |
| 1949 | break; |
| 1950 | case Type::IntegerTyID: |
| 1951 | pDest->IntVal = Src2.IntVal; |
| 1952 | break; |
| 1953 | case Type::FloatTyID: |
| 1954 | pDest->FloatVal = Src2.FloatVal; |
| 1955 | break; |
| 1956 | case Type::DoubleTyID: |
| 1957 | pDest->DoubleVal = Src2.DoubleVal; |
| 1958 | break; |
| 1959 | case Type::ArrayTyID: |
| 1960 | case Type::StructTyID: |
| 1961 | case Type::VectorTyID: |
| 1962 | pDest->AggregateVal = Src2.AggregateVal; |
| 1963 | break; |
| 1964 | case Type::PointerTyID: |
| 1965 | pDest->PointerVal = Src2.PointerVal; |
| 1966 | break; |
| 1967 | } |
| 1968 | |
| 1969 | SetValue(&I, Dest, SF); |
| 1970 | } |
| 1971 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1972 | GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE, |
| 1973 | ExecutionContext &SF) { |
| 1974 | switch (CE->getOpcode()) { |
Elena Demikhovsky | 4ca0ce2 | 2013-09-02 06:40:09 +0000 | [diff] [blame] | 1975 | case Instruction::Trunc: |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1976 | return executeTruncInst(CE->getOperand(0), CE->getType(), SF); |
| 1977 | case Instruction::ZExt: |
| 1978 | return executeZExtInst(CE->getOperand(0), CE->getType(), SF); |
| 1979 | case Instruction::SExt: |
| 1980 | return executeSExtInst(CE->getOperand(0), CE->getType(), SF); |
| 1981 | case Instruction::FPTrunc: |
| 1982 | return executeFPTruncInst(CE->getOperand(0), CE->getType(), SF); |
| 1983 | case Instruction::FPExt: |
| 1984 | return executeFPExtInst(CE->getOperand(0), CE->getType(), SF); |
| 1985 | case Instruction::UIToFP: |
| 1986 | return executeUIToFPInst(CE->getOperand(0), CE->getType(), SF); |
| 1987 | case Instruction::SIToFP: |
| 1988 | return executeSIToFPInst(CE->getOperand(0), CE->getType(), SF); |
| 1989 | case Instruction::FPToUI: |
| 1990 | return executeFPToUIInst(CE->getOperand(0), CE->getType(), SF); |
| 1991 | case Instruction::FPToSI: |
| 1992 | return executeFPToSIInst(CE->getOperand(0), CE->getType(), SF); |
| 1993 | case Instruction::PtrToInt: |
| 1994 | return executePtrToIntInst(CE->getOperand(0), CE->getType(), SF); |
| 1995 | case Instruction::IntToPtr: |
| 1996 | return executeIntToPtrInst(CE->getOperand(0), CE->getType(), SF); |
| 1997 | case Instruction::BitCast: |
| 1998 | return executeBitCastInst(CE->getOperand(0), CE->getType(), SF); |
| 1999 | case Instruction::GetElementPtr: |
| 2000 | return executeGEPOperation(CE->getOperand(0), gep_type_begin(CE), |
| 2001 | gep_type_end(CE), SF); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 2002 | case Instruction::FCmp: |
| 2003 | case Instruction::ICmp: |
| 2004 | return executeCmpInst(CE->getPredicate(), |
| 2005 | getOperandValue(CE->getOperand(0), SF), |
| 2006 | getOperandValue(CE->getOperand(1), SF), |
| 2007 | CE->getOperand(0)->getType()); |
| 2008 | case Instruction::Select: |
| 2009 | return executeSelectInst(getOperandValue(CE->getOperand(0), SF), |
| 2010 | getOperandValue(CE->getOperand(1), SF), |
Elena Demikhovsky | 4ca0ce2 | 2013-09-02 06:40:09 +0000 | [diff] [blame] | 2011 | getOperandValue(CE->getOperand(2), SF), |
| 2012 | CE->getOperand(0)->getType()); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 2013 | default : |
| 2014 | break; |
| 2015 | } |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 2016 | |
| 2017 | // The cases below here require a GenericValue parameter for the result |
| 2018 | // so we initialize one, compute it and then return it. |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 2019 | GenericValue Op0 = getOperandValue(CE->getOperand(0), SF); |
| 2020 | GenericValue Op1 = getOperandValue(CE->getOperand(1), SF); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 2021 | GenericValue Dest; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2022 | Type * Ty = CE->getOperand(0)->getType(); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 2023 | switch (CE->getOpcode()) { |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2024 | case Instruction::Add: Dest.IntVal = Op0.IntVal + Op1.IntVal; break; |
| 2025 | case Instruction::Sub: Dest.IntVal = Op0.IntVal - Op1.IntVal; break; |
| 2026 | case Instruction::Mul: Dest.IntVal = Op0.IntVal * Op1.IntVal; break; |
| 2027 | case Instruction::FAdd: executeFAddInst(Dest, Op0, Op1, Ty); break; |
| 2028 | case Instruction::FSub: executeFSubInst(Dest, Op0, Op1, Ty); break; |
| 2029 | case Instruction::FMul: executeFMulInst(Dest, Op0, Op1, Ty); break; |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 2030 | case Instruction::FDiv: executeFDivInst(Dest, Op0, Op1, Ty); break; |
| 2031 | case Instruction::FRem: executeFRemInst(Dest, Op0, Op1, Ty); break; |
| 2032 | case Instruction::SDiv: Dest.IntVal = Op0.IntVal.sdiv(Op1.IntVal); break; |
| 2033 | case Instruction::UDiv: Dest.IntVal = Op0.IntVal.udiv(Op1.IntVal); break; |
| 2034 | case Instruction::URem: Dest.IntVal = Op0.IntVal.urem(Op1.IntVal); break; |
| 2035 | case Instruction::SRem: Dest.IntVal = Op0.IntVal.srem(Op1.IntVal); break; |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2036 | case Instruction::And: Dest.IntVal = Op0.IntVal & Op1.IntVal; break; |
| 2037 | case Instruction::Or: Dest.IntVal = Op0.IntVal | Op1.IntVal; break; |
| 2038 | case Instruction::Xor: Dest.IntVal = Op0.IntVal ^ Op1.IntVal; break; |
Reid Spencer | f953633 | 2007-03-06 03:09:31 +0000 | [diff] [blame] | 2039 | case Instruction::Shl: |
| 2040 | Dest.IntVal = Op0.IntVal.shl(Op1.IntVal.getZExtValue()); |
| 2041 | break; |
| 2042 | case Instruction::LShr: |
| 2043 | Dest.IntVal = Op0.IntVal.lshr(Op1.IntVal.getZExtValue()); |
| 2044 | break; |
| 2045 | case Instruction::AShr: |
| 2046 | Dest.IntVal = Op0.IntVal.ashr(Op1.IntVal.getZExtValue()); |
| 2047 | break; |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 2048 | default: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 2049 | dbgs() << "Unhandled ConstantExpr: " << *CE << "\n"; |
Ahmed Charles | b0934ab | 2012-02-19 11:37:01 +0000 | [diff] [blame] | 2050 | llvm_unreachable("Unhandled ConstantExpr"); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 2051 | } |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 2052 | return Dest; |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | GenericValue Interpreter::getOperandValue(Value *V, ExecutionContext &SF) { |
| 2056 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
| 2057 | return getConstantExprValue(CE, SF); |
| 2058 | } else if (Constant *CPV = dyn_cast<Constant>(V)) { |
| 2059 | return getConstantValue(CPV); |
| 2060 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) { |
| 2061 | return PTOGV(getPointerToGlobal(GV)); |
| 2062 | } else { |
| 2063 | return SF.Values[V]; |
| 2064 | } |
| 2065 | } |
| 2066 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2067 | //===----------------------------------------------------------------------===// |
| 2068 | // Dispatch and Execution Code |
| 2069 | //===----------------------------------------------------------------------===// |
| 2070 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2071 | //===----------------------------------------------------------------------===// |
Chris Lattner | da82ed5 | 2003-05-08 16:18:31 +0000 | [diff] [blame] | 2072 | // callFunction - Execute the specified function... |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2073 | // |
Chris Lattner | da82ed5 | 2003-05-08 16:18:31 +0000 | [diff] [blame] | 2074 | void Interpreter::callFunction(Function *F, |
| 2075 | const std::vector<GenericValue> &ArgVals) { |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 2076 | assert((ECStack.empty() || ECStack.back().Caller.getInstruction() == 0 || |
| 2077 | ECStack.back().Caller.arg_size() == ArgVals.size()) && |
| 2078 | "Incorrect number of arguments passed into function call!"); |
Chris Lattner | 63bd613 | 2003-09-17 17:26:22 +0000 | [diff] [blame] | 2079 | // Make a new stack frame... and fill it in. |
| 2080 | ECStack.push_back(ExecutionContext()); |
| 2081 | ExecutionContext &StackFrame = ECStack.back(); |
Chris Lattner | da82ed5 | 2003-05-08 16:18:31 +0000 | [diff] [blame] | 2082 | StackFrame.CurFunction = F; |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 2083 | |
| 2084 | // Special handling for external functions. |
Reid Spencer | 5cbf985 | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 2085 | if (F->isDeclaration()) { |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 2086 | GenericValue Result = callExternalFunction (F, ArgVals); |
| 2087 | // Simulate a 'ret' instruction of the appropriate type. |
| 2088 | popStackAndReturnValueToCaller (F->getReturnType (), Result); |
| 2089 | return; |
| 2090 | } |
| 2091 | |
| 2092 | // Get pointers to first LLVM BB & Instruction in function. |
Chris Lattner | cdf5178 | 2003-05-08 16:06:52 +0000 | [diff] [blame] | 2093 | StackFrame.CurBB = F->begin(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2094 | StackFrame.CurInst = StackFrame.CurBB->begin(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2095 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 2096 | // Run through the function arguments and initialize their values... |
Chris Lattner | e4d5c44 | 2005-03-15 04:54:21 +0000 | [diff] [blame] | 2097 | assert((ArgVals.size() == F->arg_size() || |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 2098 | (ArgVals.size() > F->arg_size() && F->getFunctionType()->isVarArg()))&& |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 2099 | "Invalid number of values passed to function invocation!"); |
Chris Lattner | cdf5178 | 2003-05-08 16:06:52 +0000 | [diff] [blame] | 2100 | |
| 2101 | // Handle non-varargs arguments... |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 2102 | unsigned i = 0; |
Reid Spencer | 4ccf462 | 2007-04-16 21:50:40 +0000 | [diff] [blame] | 2103 | for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); |
| 2104 | AI != E; ++AI, ++i) |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 2105 | SetValue(AI, ArgVals[i], StackFrame); |
Chris Lattner | cdf5178 | 2003-05-08 16:06:52 +0000 | [diff] [blame] | 2106 | |
| 2107 | // Handle varargs arguments... |
| 2108 | StackFrame.VarArgs.assign(ArgVals.begin()+i, ArgVals.end()); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
Reid Spencer | 951418b | 2007-05-16 02:05:13 +0000 | [diff] [blame] | 2111 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2112 | void Interpreter::run() { |
Brian Gaeke | 9ad671d | 2003-09-04 23:15:40 +0000 | [diff] [blame] | 2113 | while (!ECStack.empty()) { |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 2114 | // Interpret a single instruction & increment the "PC". |
| 2115 | ExecutionContext &SF = ECStack.back(); // Current stack frame |
| 2116 | Instruction &I = *SF.CurInst++; // Increment before execute |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 2117 | |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 2118 | // Track the number of dynamic instructions executed. |
| 2119 | ++NumDynamicInsts; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2120 | |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 2121 | DEBUG(dbgs() << "About to interpret: " << I); |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 2122 | visit(I); // Dispatch to one of the visit* methods... |
Chris Lattner | 27725bf | 2007-09-21 18:30:39 +0000 | [diff] [blame] | 2123 | #if 0 |
| 2124 | // This is not safe, as visiting the instruction could lower it and free I. |
Chris Lattner | bdff548 | 2009-08-23 04:37:46 +0000 | [diff] [blame] | 2125 | DEBUG( |
Reid Spencer | 951418b | 2007-05-16 02:05:13 +0000 | [diff] [blame] | 2126 | if (!isa<CallInst>(I) && !isa<InvokeInst>(I) && |
| 2127 | I.getType() != Type::VoidTy) { |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 2128 | dbgs() << " --> "; |
Chris Lattner | 27725bf | 2007-09-21 18:30:39 +0000 | [diff] [blame] | 2129 | const GenericValue &Val = SF.Values[&I]; |
| 2130 | switch (I.getType()->getTypeID()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2131 | default: llvm_unreachable("Invalid GenericValue Type"); |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 2132 | case Type::VoidTyID: dbgs() << "void"; break; |
| 2133 | case Type::FloatTyID: dbgs() << "float " << Val.FloatVal; break; |
| 2134 | case Type::DoubleTyID: dbgs() << "double " << Val.DoubleVal; break; |
| 2135 | case Type::PointerTyID: dbgs() << "void* " << intptr_t(Val.PointerVal); |
Chris Lattner | 27725bf | 2007-09-21 18:30:39 +0000 | [diff] [blame] | 2136 | break; |
| 2137 | case Type::IntegerTyID: |
David Greene | ef573a3 | 2010-01-05 01:27:23 +0000 | [diff] [blame] | 2138 | dbgs() << "i" << Val.IntVal.getBitWidth() << " " |
Chris Lattner | bdff548 | 2009-08-23 04:37:46 +0000 | [diff] [blame] | 2139 | << Val.IntVal.toStringUnsigned(10) |
| 2140 | << " (0x" << Val.IntVal.toStringUnsigned(16) << ")\n"; |
Chris Lattner | 27725bf | 2007-09-21 18:30:39 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | } |
Chris Lattner | bdff548 | 2009-08-23 04:37:46 +0000 | [diff] [blame] | 2143 | }); |
Chris Lattner | 27725bf | 2007-09-21 18:30:39 +0000 | [diff] [blame] | 2144 | #endif |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 2145 | } |
| 2146 | } |