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 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source 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" |
Chris Lattner | 31bcdb8 | 2002-04-28 19:55:58 +0000 | [diff] [blame] | 16 | #include "llvm/Constants.h" |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/Instructions.h" |
Chris Lattner | 3048373 | 2004-06-20 07:49:54 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 20 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/APInt.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Statistic.h" |
| 23 | #include "llvm/Support/Debug.h" |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 24 | #include "llvm/Support/MathExtras.h" |
Jeff Cohen | 97af751 | 2006-12-02 02:22:01 +0000 | [diff] [blame] | 25 | #include <cmath> |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 26 | using namespace llvm; |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 27 | |
Chris Lattner | cecf56b | 2006-12-19 22:56:53 +0000 | [diff] [blame] | 28 | STATISTIC(NumDynamicInsts, "Number of dynamic instructions executed"); |
| 29 | static Interpreter *TheEE = 0; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 30 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 31 | //===----------------------------------------------------------------------===// |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 32 | // Various Helper Functions |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 34 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 35 | inline void initializeAPInt(GenericValue &GV, const Type* Ty, |
| 36 | ExecutionContext &SF) { |
| 37 | if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) |
| 38 | GV.APIntVal = SF.getAPInt(ITy->getBitWidth()); |
| 39 | } |
Chris Lattner | 759d34f | 2004-04-20 16:43:21 +0000 | [diff] [blame] | 40 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 41 | static inline uint64_t doSignExtension(uint64_t Val, const IntegerType* ITy) { |
Reid Spencer | a42c7fd | 2007-01-20 20:12:29 +0000 | [diff] [blame] | 42 | // Determine if the value is signed or not |
| 43 | bool isSigned = (Val & (1 << (ITy->getBitWidth()-1))) != 0; |
| 44 | // If its signed, extend the sign bits |
| 45 | if (isSigned) |
| 46 | Val |= ~ITy->getBitMask(); |
| 47 | return Val; |
| 48 | } |
| 49 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 50 | static inline void maskToBitWidth(GenericValue& GV, unsigned BitWidth) { |
| 51 | uint64_t BitMask = ~(uint64_t)(0ull) >> (64-BitWidth); |
| 52 | if (BitWidth <= 8) |
| 53 | GV.Int8Val &= BitMask; |
| 54 | else if (BitWidth <= 16) |
| 55 | GV.Int16Val &= BitMask; |
| 56 | else if (BitWidth <= 32) |
| 57 | GV.Int32Val &= BitMask; |
| 58 | else if (BitWidth <= 64) |
| 59 | GV.Int64Val &= BitMask; |
| 60 | else { |
| 61 | assert(GV.APIntVal && "Unallocated GV.APIntVal"); |
| 62 | *(GV.APIntVal) &= APInt::getAllOnesValue(BitWidth); |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 66 | static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) { |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 67 | SF.Values[V] = Val; |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 70 | void Interpreter::initializeExecutionEngine() { |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 71 | TheEE = this; |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Chris Lattner | 2adcd83 | 2002-05-03 19:52:30 +0000 | [diff] [blame] | 74 | //===----------------------------------------------------------------------===// |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 75 | // Binary Instruction Implementations |
| 76 | //===----------------------------------------------------------------------===// |
| 77 | |
| 78 | #define IMPLEMENT_BINARY_OPERATOR(OP, TY) \ |
| 79 | case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.TY##Val; break |
| 80 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 81 | #define IMPLEMENT_INTEGER_BINOP(OP, TY) \ |
| 82 | case Type::IntegerTyID: { \ |
| 83 | unsigned BitWidth = cast<IntegerType>(TY)->getBitWidth(); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 84 | if (BitWidth == 1) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 85 | Dest.Int1Val = Src1.Int1Val OP Src2.Int1Val; \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 86 | maskToBitWidth(Dest, BitWidth); \ |
| 87 | } else if (BitWidth <= 8) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 88 | Dest.Int8Val = Src1.Int8Val OP Src2.Int8Val; \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 89 | maskToBitWidth(Dest, BitWidth); \ |
| 90 | } else if (BitWidth <= 16) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 91 | Dest.Int16Val = Src1.Int16Val OP Src2.Int16Val; \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 92 | maskToBitWidth(Dest, BitWidth); \ |
| 93 | } else if (BitWidth <= 32) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 94 | Dest.Int32Val = Src1.Int32Val OP Src2.Int32Val; \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 95 | maskToBitWidth(Dest, BitWidth); \ |
| 96 | } else if (BitWidth <= 64) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 97 | Dest.Int64Val = Src1.Int64Val OP Src2.Int64Val; \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 98 | maskToBitWidth(Dest, BitWidth); \ |
| 99 | } else \ |
| 100 | *(Dest.APIntVal) = *(Src1.APIntVal) OP *(Src2.APIntVal); \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 101 | break; \ |
| 102 | } |
| 103 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 104 | #define IMPLEMENT_SIGNED_BINOP(OP, TY, APOP) \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 105 | if (const IntegerType *ITy = dyn_cast<IntegerType>(TY)) { \ |
| 106 | unsigned BitWidth = ITy->getBitWidth(); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 107 | if (BitWidth <= 8) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 108 | Dest.Int8Val = ((int8_t)Src1.Int8Val) OP ((int8_t)Src2.Int8Val); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 109 | maskToBitWidth(Dest, BitWidth); \ |
| 110 | } else if (BitWidth <= 16) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 111 | Dest.Int16Val = ((int16_t)Src1.Int16Val) OP ((int16_t)Src2.Int16Val); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 112 | maskToBitWidth(Dest, BitWidth); \ |
| 113 | } else if (BitWidth <= 32) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 114 | Dest.Int32Val = ((int32_t)Src1.Int32Val) OP ((int32_t)Src2.Int32Val); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 115 | maskToBitWidth(Dest, BitWidth); \ |
| 116 | } else if (BitWidth <= 64) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 117 | Dest.Int64Val = ((int64_t)Src1.Int64Val) OP ((int64_t)Src2.Int64Val); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 118 | maskToBitWidth(Dest, BitWidth); \ |
| 119 | } else \ |
| 120 | *(Dest.APIntVal) = Src1.APIntVal->APOP(*(Src2.APIntVal)); \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 121 | } else { \ |
| 122 | cerr << "Unhandled type for " #OP " operator: " << *Ty << "\n"; \ |
| 123 | abort(); \ |
| 124 | } |
| 125 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 126 | #define IMPLEMENT_UNSIGNED_BINOP(OP, TY, APOP) \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 127 | if (const IntegerType *ITy = dyn_cast<IntegerType>(TY)) { \ |
| 128 | unsigned BitWidth = ITy->getBitWidth(); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 129 | if (BitWidth <= 8) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 130 | Dest.Int8Val = ((uint8_t)Src1.Int8Val) OP ((uint8_t)Src2.Int8Val); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 131 | maskToBitWidth(Dest, BitWidth); \ |
| 132 | } else if (BitWidth <= 16) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 133 | Dest.Int16Val = ((uint16_t)Src1.Int16Val) OP ((uint16_t)Src2.Int16Val); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 134 | maskToBitWidth(Dest, BitWidth); \ |
| 135 | } else if (BitWidth <= 32) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 136 | Dest.Int32Val = ((uint32_t)Src1.Int32Val) OP ((uint32_t)Src2.Int32Val); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 137 | maskToBitWidth(Dest, BitWidth); \ |
| 138 | } else if (BitWidth <= 64) {\ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 139 | Dest.Int64Val = ((uint64_t)Src1.Int64Val) OP ((uint64_t)Src2.Int64Val); \ |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 140 | maskToBitWidth(Dest, BitWidth); \ |
| 141 | } else \ |
| 142 | *(Dest.APIntVal) = Src1.APIntVal->APOP(*(Src2.APIntVal)); \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 143 | } else { \ |
| 144 | cerr << "Unhandled type for " #OP " operator: " << *Ty << "\n"; \ |
| 145 | abort(); \ |
| 146 | } |
| 147 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 148 | static void executeAddInst(GenericValue &Dest, GenericValue Src1, |
| 149 | GenericValue Src2, const Type *Ty) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 150 | switch (Ty->getTypeID()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 151 | IMPLEMENT_INTEGER_BINOP(+, Ty); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 152 | IMPLEMENT_BINARY_OPERATOR(+, Float); |
| 153 | IMPLEMENT_BINARY_OPERATOR(+, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 154 | default: |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 155 | cerr << "Unhandled type for Add instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 156 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 157 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 160 | static void executeSubInst(GenericValue &Dest, GenericValue Src1, |
| 161 | GenericValue Src2, const Type *Ty) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 162 | switch (Ty->getTypeID()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 163 | IMPLEMENT_INTEGER_BINOP(-, Ty); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 164 | IMPLEMENT_BINARY_OPERATOR(-, Float); |
| 165 | IMPLEMENT_BINARY_OPERATOR(-, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 166 | default: |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 167 | cerr << "Unhandled type for Sub instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 168 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 169 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 172 | static void executeMulInst(GenericValue &Dest, GenericValue Src1, |
| 173 | GenericValue Src2, const Type *Ty) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 174 | switch (Ty->getTypeID()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 175 | IMPLEMENT_INTEGER_BINOP(*, Ty); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 176 | IMPLEMENT_BINARY_OPERATOR(*, Float); |
| 177 | IMPLEMENT_BINARY_OPERATOR(*, Double); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 178 | default: |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 179 | cerr << "Unhandled type for Mul instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 180 | abort(); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 181 | } |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 184 | static void executeUDivInst(GenericValue &Dest, GenericValue Src1, |
| 185 | GenericValue Src2, const Type *Ty) { |
| 186 | IMPLEMENT_UNSIGNED_BINOP(/,Ty,udiv) |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 189 | static void executeSDivInst(GenericValue &Dest, GenericValue Src1, |
| 190 | GenericValue Src2, const Type *Ty) { |
| 191 | IMPLEMENT_SIGNED_BINOP(/,Ty,sdiv) |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 194 | static void executeFDivInst(GenericValue &Dest, GenericValue Src1, |
| 195 | GenericValue Src2, const Type *Ty) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 196 | switch (Ty->getTypeID()) { |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 197 | IMPLEMENT_BINARY_OPERATOR(/, Float); |
| 198 | IMPLEMENT_BINARY_OPERATOR(/, Double); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 199 | default: |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 200 | cerr << "Unhandled type for FDiv instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 201 | abort(); |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 202 | } |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 205 | static void executeURemInst(GenericValue &Dest, GenericValue Src1, |
| 206 | GenericValue Src2, const Type *Ty) { |
| 207 | IMPLEMENT_UNSIGNED_BINOP(%,Ty,urem) |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 210 | static void executeSRemInst(GenericValue &Dest, GenericValue Src1, |
| 211 | GenericValue Src2, const Type *Ty) { |
| 212 | IMPLEMENT_SIGNED_BINOP(%,Ty,srem) |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 215 | static void executeFRemInst(GenericValue &Dest, GenericValue Src1, |
| 216 | GenericValue Src2, const Type *Ty) { |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 217 | switch (Ty->getTypeID()) { |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 218 | case Type::FloatTyID: |
| 219 | Dest.FloatVal = fmod(Src1.FloatVal, Src2.FloatVal); |
| 220 | break; |
| 221 | case Type::DoubleTyID: |
| 222 | Dest.DoubleVal = fmod(Src1.DoubleVal, Src2.DoubleVal); |
| 223 | break; |
| 224 | default: |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 225 | cerr << "Unhandled type for Rem instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 226 | abort(); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 227 | } |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 230 | static void executeAndInst(GenericValue &Dest, GenericValue Src1, |
| 231 | GenericValue Src2, const Type *Ty) { |
| 232 | IMPLEMENT_UNSIGNED_BINOP(&,Ty,And) |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 235 | static void executeOrInst(GenericValue &Dest, GenericValue Src1, |
| 236 | GenericValue Src2, const Type *Ty) { |
| 237 | IMPLEMENT_UNSIGNED_BINOP(|,Ty,Or) |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 240 | static void executeXorInst(GenericValue &Dest, GenericValue Src1, |
| 241 | GenericValue Src2, const Type *Ty) { |
| 242 | IMPLEMENT_UNSIGNED_BINOP(^,Ty,Xor) |
Chris Lattner | 4d0e1f9 | 2001-10-30 20:54:36 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 245 | #define IMPLEMENT_SIGNED_ICMP(OP, TY, APOP) \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 246 | case Type::IntegerTyID: { \ |
Reid Spencer | a42c7fd | 2007-01-20 20:12:29 +0000 | [diff] [blame] | 247 | const IntegerType* ITy = cast<IntegerType>(TY); \ |
| 248 | unsigned BitWidth = ITy->getBitWidth(); \ |
| 249 | int64_t LHS = 0, RHS = 0; \ |
| 250 | if (BitWidth <= 8) { \ |
| 251 | LHS = int64_t(doSignExtension(uint64_t(Src1.Int8Val), ITy)); \ |
| 252 | RHS = int64_t(doSignExtension(uint64_t(Src2.Int8Val), ITy)); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 253 | Dest.Int1Val = LHS OP RHS; \ |
Reid Spencer | a42c7fd | 2007-01-20 20:12:29 +0000 | [diff] [blame] | 254 | } else if (BitWidth <= 16) { \ |
| 255 | LHS = int64_t(doSignExtension(uint64_t(Src1.Int16Val), ITy)); \ |
| 256 | RHS = int64_t(doSignExtension(uint64_t(Src2.Int16Val), ITy)); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 257 | Dest.Int1Val = LHS OP RHS; \ |
Reid Spencer | a42c7fd | 2007-01-20 20:12:29 +0000 | [diff] [blame] | 258 | } else if (BitWidth <= 32) { \ |
| 259 | LHS = int64_t(doSignExtension(uint64_t(Src1.Int32Val), ITy)); \ |
| 260 | RHS = int64_t(doSignExtension(uint64_t(Src2.Int32Val), ITy)); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 261 | Dest.Int1Val = LHS OP RHS; \ |
Reid Spencer | a42c7fd | 2007-01-20 20:12:29 +0000 | [diff] [blame] | 262 | } else if (BitWidth <= 64) { \ |
| 263 | LHS = int64_t(doSignExtension(uint64_t(Src1.Int64Val), ITy)); \ |
| 264 | RHS = int64_t(doSignExtension(uint64_t(Src2.Int64Val), ITy)); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 265 | Dest.Int1Val = LHS OP RHS; \ |
Reid Spencer | a42c7fd | 2007-01-20 20:12:29 +0000 | [diff] [blame] | 266 | } else { \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 267 | Dest.Int1Val = Src1.APIntVal->APOP(*(Src2.APIntVal)); \ |
| 268 | } \ |
| 269 | break; \ |
| 270 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 271 | |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 272 | #define IMPLEMENT_UNSIGNED_ICMP(OP, TY, APOP) \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 273 | case Type::IntegerTyID: { \ |
| 274 | unsigned BitWidth = cast<IntegerType>(TY)->getBitWidth(); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 275 | if (BitWidth == 1) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 276 | Dest.Int1Val = ((uint8_t)Src1.Int1Val) OP ((uint8_t)Src2.Int1Val); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 277 | maskToBitWidth(Dest, BitWidth); \ |
| 278 | } else if (BitWidth <= 8) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 279 | Dest.Int1Val = ((uint8_t)Src1.Int8Val) OP ((uint8_t)Src2.Int8Val); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 280 | maskToBitWidth(Dest, BitWidth); \ |
| 281 | } else if (BitWidth <= 16) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 282 | Dest.Int1Val = ((uint16_t)Src1.Int16Val) OP ((uint16_t)Src2.Int16Val); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 283 | maskToBitWidth(Dest, BitWidth); \ |
| 284 | } else if (BitWidth <= 32) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 285 | Dest.Int1Val = ((uint32_t)Src1.Int32Val) OP ((uint32_t)Src2.Int32Val); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 286 | maskToBitWidth(Dest, BitWidth); \ |
| 287 | } else if (BitWidth <= 64) { \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 288 | Dest.Int1Val = ((uint64_t)Src1.Int64Val) OP ((uint64_t)Src2.Int64Val); \ |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 289 | maskToBitWidth(Dest, BitWidth); \ |
| 290 | } else { \ |
| 291 | Dest.Int1Val = Src1.APIntVal->APOP(*(Src2.APIntVal)); \ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 292 | } \ |
| 293 | break; \ |
| 294 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 295 | |
Chris Lattner | fd506f5 | 2003-04-23 19:55:35 +0000 | [diff] [blame] | 296 | // Handle pointers specially because they must be compared with only as much |
| 297 | // width as the host has. We _do not_ want to be comparing 64 bit values when |
| 298 | // running on a 32-bit target, otherwise the upper 32 bits might mess up |
| 299 | // comparisons if they contain garbage. |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 300 | #define IMPLEMENT_POINTER_ICMP(OP) \ |
Chris Lattner | fd506f5 | 2003-04-23 19:55:35 +0000 | [diff] [blame] | 301 | case Type::PointerTyID: \ |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 302 | Dest.Int1Val = (void*)(intptr_t)Src1.PointerVal OP \ |
Chris Lattner | fd506f5 | 2003-04-23 19:55:35 +0000 | [diff] [blame] | 303 | (void*)(intptr_t)Src2.PointerVal; break |
| 304 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 305 | static GenericValue executeICMP_EQ(GenericValue Src1, GenericValue Src2, |
| 306 | const Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 307 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 308 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 309 | IMPLEMENT_UNSIGNED_ICMP(==, Ty, eq); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 310 | IMPLEMENT_POINTER_ICMP(==); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 311 | default: |
| 312 | cerr << "Unhandled type for ICMP_EQ predicate: " << *Ty << "\n"; |
| 313 | abort(); |
| 314 | } |
| 315 | return Dest; |
| 316 | } |
| 317 | |
| 318 | static GenericValue executeICMP_NE(GenericValue Src1, GenericValue Src2, |
| 319 | const Type *Ty) { |
| 320 | GenericValue Dest; |
| 321 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 322 | IMPLEMENT_UNSIGNED_ICMP(!=, Ty, ne); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 323 | IMPLEMENT_POINTER_ICMP(!=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 324 | default: |
| 325 | cerr << "Unhandled type for ICMP_NE predicate: " << *Ty << "\n"; |
| 326 | abort(); |
| 327 | } |
| 328 | return Dest; |
| 329 | } |
| 330 | |
| 331 | static GenericValue executeICMP_ULT(GenericValue Src1, GenericValue Src2, |
| 332 | const Type *Ty) { |
| 333 | GenericValue Dest; |
| 334 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 335 | IMPLEMENT_UNSIGNED_ICMP(<, Ty, ult); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 336 | IMPLEMENT_POINTER_ICMP(<); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 337 | default: |
| 338 | cerr << "Unhandled type for ICMP_ULT predicate: " << *Ty << "\n"; |
| 339 | abort(); |
| 340 | } |
| 341 | return Dest; |
| 342 | } |
| 343 | |
| 344 | static GenericValue executeICMP_SLT(GenericValue Src1, GenericValue Src2, |
| 345 | const Type *Ty) { |
| 346 | GenericValue Dest; |
| 347 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 348 | IMPLEMENT_SIGNED_ICMP(<, Ty, slt); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 349 | IMPLEMENT_POINTER_ICMP(<); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 350 | default: |
| 351 | cerr << "Unhandled type for ICMP_SLT predicate: " << *Ty << "\n"; |
| 352 | abort(); |
| 353 | } |
| 354 | return Dest; |
| 355 | } |
| 356 | |
| 357 | static GenericValue executeICMP_UGT(GenericValue Src1, GenericValue Src2, |
| 358 | const Type *Ty) { |
| 359 | GenericValue Dest; |
| 360 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 361 | IMPLEMENT_UNSIGNED_ICMP(>, Ty, ugt); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 362 | IMPLEMENT_POINTER_ICMP(>); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 363 | default: |
| 364 | cerr << "Unhandled type for ICMP_UGT predicate: " << *Ty << "\n"; |
| 365 | abort(); |
| 366 | } |
| 367 | return Dest; |
| 368 | } |
| 369 | |
| 370 | static GenericValue executeICMP_SGT(GenericValue Src1, GenericValue Src2, |
| 371 | const Type *Ty) { |
| 372 | GenericValue Dest; |
| 373 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 374 | IMPLEMENT_SIGNED_ICMP(>, Ty, sgt); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 375 | IMPLEMENT_POINTER_ICMP(>); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 376 | default: |
| 377 | cerr << "Unhandled type for ICMP_SGT predicate: " << *Ty << "\n"; |
| 378 | abort(); |
| 379 | } |
| 380 | return Dest; |
| 381 | } |
| 382 | |
| 383 | static GenericValue executeICMP_ULE(GenericValue Src1, GenericValue Src2, |
| 384 | const Type *Ty) { |
| 385 | GenericValue Dest; |
| 386 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 387 | IMPLEMENT_UNSIGNED_ICMP(<=, Ty, ule); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 388 | IMPLEMENT_POINTER_ICMP(<=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 389 | default: |
| 390 | cerr << "Unhandled type for ICMP_ULE predicate: " << *Ty << "\n"; |
| 391 | abort(); |
| 392 | } |
| 393 | return Dest; |
| 394 | } |
| 395 | |
| 396 | static GenericValue executeICMP_SLE(GenericValue Src1, GenericValue Src2, |
| 397 | const Type *Ty) { |
| 398 | GenericValue Dest; |
| 399 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 400 | IMPLEMENT_SIGNED_ICMP(<=, Ty, sle); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 401 | IMPLEMENT_POINTER_ICMP(<=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 402 | default: |
| 403 | cerr << "Unhandled type for ICMP_SLE predicate: " << *Ty << "\n"; |
| 404 | abort(); |
| 405 | } |
| 406 | return Dest; |
| 407 | } |
| 408 | |
| 409 | static GenericValue executeICMP_UGE(GenericValue Src1, GenericValue Src2, |
| 410 | const Type *Ty) { |
| 411 | GenericValue Dest; |
| 412 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 413 | IMPLEMENT_UNSIGNED_ICMP(>=, Ty, uge); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 414 | IMPLEMENT_POINTER_ICMP(>=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 415 | default: |
| 416 | cerr << "Unhandled type for ICMP_UGE predicate: " << *Ty << "\n"; |
| 417 | abort(); |
| 418 | } |
| 419 | return Dest; |
| 420 | } |
| 421 | |
| 422 | static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2, |
| 423 | const Type *Ty) { |
| 424 | GenericValue Dest; |
| 425 | switch (Ty->getTypeID()) { |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 426 | IMPLEMENT_SIGNED_ICMP(>=, Ty, sge); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 427 | IMPLEMENT_POINTER_ICMP(>=); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 428 | default: |
| 429 | cerr << "Unhandled type for ICMP_SGE predicate: " << *Ty << "\n"; |
| 430 | abort(); |
| 431 | } |
| 432 | return Dest; |
| 433 | } |
| 434 | |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 435 | void Interpreter::visitICmpInst(ICmpInst &I) { |
| 436 | ExecutionContext &SF = ECStack.back(); |
| 437 | const Type *Ty = I.getOperand(0)->getType(); |
| 438 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 439 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 440 | GenericValue R; // Result |
| 441 | |
| 442 | switch (I.getPredicate()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 443 | case ICmpInst::ICMP_EQ: R = executeICMP_EQ(Src1, Src2, Ty); break; |
| 444 | case ICmpInst::ICMP_NE: R = executeICMP_NE(Src1, Src2, Ty); break; |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 445 | case ICmpInst::ICMP_ULT: R = executeICMP_ULT(Src1, Src2, Ty); break; |
| 446 | case ICmpInst::ICMP_SLT: R = executeICMP_SLT(Src1, Src2, Ty); break; |
| 447 | case ICmpInst::ICMP_UGT: R = executeICMP_UGT(Src1, Src2, Ty); break; |
| 448 | case ICmpInst::ICMP_SGT: R = executeICMP_SGT(Src1, Src2, Ty); break; |
| 449 | case ICmpInst::ICMP_ULE: R = executeICMP_ULE(Src1, Src2, Ty); break; |
| 450 | case ICmpInst::ICMP_SLE: R = executeICMP_SLE(Src1, Src2, Ty); break; |
| 451 | case ICmpInst::ICMP_UGE: R = executeICMP_UGE(Src1, Src2, Ty); break; |
| 452 | case ICmpInst::ICMP_SGE: R = executeICMP_SGE(Src1, Src2, Ty); break; |
| 453 | default: |
| 454 | cerr << "Don't know how to handle this ICmp predicate!\n-->" << I; |
| 455 | abort(); |
| 456 | } |
| 457 | |
| 458 | SetValue(&I, R, SF); |
| 459 | } |
| 460 | |
| 461 | #define IMPLEMENT_FCMP(OP, TY) \ |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 462 | case Type::TY##TyID: Dest.Int1Val = Src1.TY##Val OP Src2.TY##Val; break |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 463 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 464 | static GenericValue executeFCMP_OEQ(GenericValue Src1, GenericValue Src2, |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 465 | const Type *Ty) { |
| 466 | GenericValue Dest; |
| 467 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 468 | IMPLEMENT_FCMP(==, Float); |
| 469 | IMPLEMENT_FCMP(==, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 470 | default: |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 471 | cerr << "Unhandled type for FCmp EQ instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 472 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 473 | } |
| 474 | return Dest; |
| 475 | } |
| 476 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 477 | static GenericValue executeFCMP_ONE(GenericValue Src1, GenericValue Src2, |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 478 | const Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 479 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 480 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 481 | IMPLEMENT_FCMP(!=, Float); |
| 482 | IMPLEMENT_FCMP(!=, Double); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 483 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 484 | default: |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 485 | cerr << "Unhandled type for FCmp NE instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 486 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 487 | } |
| 488 | return Dest; |
| 489 | } |
| 490 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 491 | static GenericValue executeFCMP_OLE(GenericValue Src1, GenericValue Src2, |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 492 | const Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 493 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 494 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 495 | IMPLEMENT_FCMP(<=, Float); |
| 496 | IMPLEMENT_FCMP(<=, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 497 | default: |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 498 | cerr << "Unhandled type for FCmp LE instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 499 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 500 | } |
| 501 | return Dest; |
| 502 | } |
| 503 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 504 | static GenericValue executeFCMP_OGE(GenericValue Src1, GenericValue Src2, |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 505 | const Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 506 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 507 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 508 | IMPLEMENT_FCMP(>=, Float); |
| 509 | IMPLEMENT_FCMP(>=, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 510 | default: |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 511 | cerr << "Unhandled type for FCmp GE instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 512 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 513 | } |
| 514 | return Dest; |
| 515 | } |
| 516 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 517 | static GenericValue executeFCMP_OLT(GenericValue Src1, GenericValue Src2, |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 518 | const Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 519 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 520 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 521 | IMPLEMENT_FCMP(<, Float); |
| 522 | IMPLEMENT_FCMP(<, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 523 | default: |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 524 | cerr << "Unhandled type for FCmp LT instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 525 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 526 | } |
| 527 | return Dest; |
| 528 | } |
| 529 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 530 | static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2, |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 531 | const Type *Ty) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 532 | GenericValue Dest; |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 533 | switch (Ty->getTypeID()) { |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 534 | IMPLEMENT_FCMP(>, Float); |
| 535 | IMPLEMENT_FCMP(>, Double); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 536 | default: |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 537 | cerr << "Unhandled type for FCmp GT instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 538 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 539 | } |
| 540 | return Dest; |
| 541 | } |
| 542 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 543 | #define IMPLEMENT_UNORDERED(TY, X,Y) \ |
| 544 | if (TY == Type::FloatTy) \ |
| 545 | if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \ |
| 546 | Dest.Int1Val = true; \ |
| 547 | return Dest; \ |
| 548 | } \ |
| 549 | else if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \ |
| 550 | Dest.Int1Val = true; \ |
| 551 | return Dest; \ |
| 552 | } |
| 553 | |
| 554 | |
| 555 | static GenericValue executeFCMP_UEQ(GenericValue Src1, GenericValue Src2, |
| 556 | const Type *Ty) { |
| 557 | GenericValue Dest; |
| 558 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
| 559 | return executeFCMP_OEQ(Src1, Src2, Ty); |
| 560 | } |
| 561 | |
| 562 | static GenericValue executeFCMP_UNE(GenericValue Src1, GenericValue Src2, |
| 563 | const Type *Ty) { |
| 564 | GenericValue Dest; |
| 565 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
| 566 | return executeFCMP_ONE(Src1, Src2, Ty); |
| 567 | } |
| 568 | |
| 569 | static GenericValue executeFCMP_ULE(GenericValue Src1, GenericValue Src2, |
| 570 | const Type *Ty) { |
| 571 | GenericValue Dest; |
| 572 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
| 573 | return executeFCMP_OLE(Src1, Src2, Ty); |
| 574 | } |
| 575 | |
| 576 | static GenericValue executeFCMP_UGE(GenericValue Src1, GenericValue Src2, |
| 577 | const Type *Ty) { |
| 578 | GenericValue Dest; |
| 579 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
| 580 | return executeFCMP_OGE(Src1, Src2, Ty); |
| 581 | } |
| 582 | |
| 583 | static GenericValue executeFCMP_ULT(GenericValue Src1, GenericValue Src2, |
| 584 | const Type *Ty) { |
| 585 | GenericValue Dest; |
| 586 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
| 587 | return executeFCMP_OLT(Src1, Src2, Ty); |
| 588 | } |
| 589 | |
| 590 | static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2, |
| 591 | const Type *Ty) { |
| 592 | GenericValue Dest; |
| 593 | IMPLEMENT_UNORDERED(Ty, Src1, Src2) |
| 594 | return executeFCMP_OGT(Src1, Src2, Ty); |
| 595 | } |
| 596 | |
| 597 | static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, |
| 598 | const Type *Ty) { |
| 599 | GenericValue Dest; |
| 600 | if (Ty == Type::FloatTy) |
| 601 | Dest.Int1Val = (Src1.FloatVal == Src1.FloatVal && |
| 602 | Src2.FloatVal == Src2.FloatVal); |
| 603 | else |
| 604 | Dest.Int1Val = (Src1.DoubleVal == Src1.DoubleVal && |
| 605 | Src2.DoubleVal == Src2.DoubleVal); |
| 606 | return Dest; |
| 607 | } |
| 608 | |
| 609 | static GenericValue executeFCMP_UNO(GenericValue Src1, GenericValue Src2, |
| 610 | const Type *Ty) { |
| 611 | GenericValue Dest; |
| 612 | if (Ty == Type::FloatTy) |
| 613 | Dest.Int1Val = (Src1.FloatVal != Src1.FloatVal || |
| 614 | Src2.FloatVal != Src2.FloatVal); |
| 615 | else |
| 616 | Dest.Int1Val = (Src1.DoubleVal != Src1.DoubleVal || |
| 617 | Src2.DoubleVal != Src2.DoubleVal); |
| 618 | return Dest; |
| 619 | } |
| 620 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 621 | void Interpreter::visitFCmpInst(FCmpInst &I) { |
| 622 | ExecutionContext &SF = ECStack.back(); |
| 623 | const Type *Ty = I.getOperand(0)->getType(); |
| 624 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 625 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 626 | GenericValue R; // Result |
| 627 | |
| 628 | switch (I.getPredicate()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 629 | case FCmpInst::FCMP_FALSE: R.Int1Val = false; break; |
| 630 | case FCmpInst::FCMP_TRUE: R.Int1Val = true; break; |
| 631 | case FCmpInst::FCMP_ORD: R = executeFCMP_ORD(Src1, Src2, Ty); break; |
| 632 | case FCmpInst::FCMP_UNO: R = executeFCMP_UNO(Src1, Src2, Ty); break; |
| 633 | case FCmpInst::FCMP_UEQ: R = executeFCMP_UEQ(Src1, Src2, Ty); break; |
| 634 | case FCmpInst::FCMP_OEQ: R = executeFCMP_OEQ(Src1, Src2, Ty); break; |
| 635 | case FCmpInst::FCMP_UNE: R = executeFCMP_UNE(Src1, Src2, Ty); break; |
| 636 | case FCmpInst::FCMP_ONE: R = executeFCMP_ONE(Src1, Src2, Ty); break; |
| 637 | case FCmpInst::FCMP_ULT: R = executeFCMP_ULT(Src1, Src2, Ty); break; |
| 638 | case FCmpInst::FCMP_OLT: R = executeFCMP_OLT(Src1, Src2, Ty); break; |
| 639 | case FCmpInst::FCMP_UGT: R = executeFCMP_UGT(Src1, Src2, Ty); break; |
| 640 | case FCmpInst::FCMP_OGT: R = executeFCMP_OGT(Src1, Src2, Ty); break; |
| 641 | case FCmpInst::FCMP_ULE: R = executeFCMP_ULE(Src1, Src2, Ty); break; |
| 642 | case FCmpInst::FCMP_OLE: R = executeFCMP_OLE(Src1, Src2, Ty); break; |
| 643 | case FCmpInst::FCMP_UGE: R = executeFCMP_UGE(Src1, Src2, Ty); break; |
| 644 | case FCmpInst::FCMP_OGE: R = executeFCMP_OGE(Src1, Src2, Ty); break; |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 645 | default: |
| 646 | cerr << "Don't know how to handle this FCmp predicate!\n-->" << I; |
| 647 | abort(); |
| 648 | } |
| 649 | |
| 650 | SetValue(&I, R, SF); |
| 651 | } |
| 652 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 653 | static GenericValue executeCmpInst(unsigned predicate, GenericValue Src1, |
| 654 | GenericValue Src2, const Type *Ty) { |
| 655 | GenericValue Result; |
| 656 | switch (predicate) { |
| 657 | case ICmpInst::ICMP_EQ: return executeICMP_EQ(Src1, Src2, Ty); |
| 658 | case ICmpInst::ICMP_NE: return executeICMP_NE(Src1, Src2, Ty); |
| 659 | case ICmpInst::ICMP_UGT: return executeICMP_UGT(Src1, Src2, Ty); |
| 660 | case ICmpInst::ICMP_SGT: return executeICMP_SGT(Src1, Src2, Ty); |
| 661 | case ICmpInst::ICMP_ULT: return executeICMP_ULT(Src1, Src2, Ty); |
| 662 | case ICmpInst::ICMP_SLT: return executeICMP_SLT(Src1, Src2, Ty); |
| 663 | case ICmpInst::ICMP_UGE: return executeICMP_UGE(Src1, Src2, Ty); |
| 664 | case ICmpInst::ICMP_SGE: return executeICMP_SGE(Src1, Src2, Ty); |
| 665 | case ICmpInst::ICMP_ULE: return executeICMP_ULE(Src1, Src2, Ty); |
| 666 | case ICmpInst::ICMP_SLE: return executeICMP_SLE(Src1, Src2, Ty); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 667 | case FCmpInst::FCMP_ORD: return executeFCMP_ORD(Src1, Src2, Ty); |
| 668 | case FCmpInst::FCMP_UNO: return executeFCMP_UNO(Src1, Src2, Ty); |
| 669 | case FCmpInst::FCMP_OEQ: return executeFCMP_OEQ(Src1, Src2, Ty); |
| 670 | case FCmpInst::FCMP_UEQ: return executeFCMP_UEQ(Src1, Src2, Ty); |
| 671 | case FCmpInst::FCMP_ONE: return executeFCMP_ONE(Src1, Src2, Ty); |
| 672 | case FCmpInst::FCMP_UNE: return executeFCMP_UNE(Src1, Src2, Ty); |
| 673 | case FCmpInst::FCMP_OLT: return executeFCMP_OLT(Src1, Src2, Ty); |
| 674 | case FCmpInst::FCMP_ULT: return executeFCMP_ULT(Src1, Src2, Ty); |
| 675 | case FCmpInst::FCMP_OGT: return executeFCMP_OGT(Src1, Src2, Ty); |
| 676 | case FCmpInst::FCMP_UGT: return executeFCMP_UGT(Src1, Src2, Ty); |
| 677 | case FCmpInst::FCMP_OLE: return executeFCMP_OLE(Src1, Src2, Ty); |
| 678 | case FCmpInst::FCMP_ULE: return executeFCMP_ULE(Src1, Src2, Ty); |
| 679 | case FCmpInst::FCMP_OGE: return executeFCMP_OGE(Src1, Src2, Ty); |
| 680 | case FCmpInst::FCMP_UGE: return executeFCMP_UGE(Src1, Src2, Ty); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 681 | case FCmpInst::FCMP_FALSE: { |
| 682 | GenericValue Result; |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 683 | Result.Int1Val = false; |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 684 | return Result; |
| 685 | } |
| 686 | case FCmpInst::FCMP_TRUE: { |
| 687 | GenericValue Result; |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 688 | Result.Int1Val = true; |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 689 | return Result; |
| 690 | } |
| 691 | default: |
| 692 | cerr << "Unhandled Cmp predicate\n"; |
| 693 | abort(); |
| 694 | } |
| 695 | } |
| 696 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 697 | void Interpreter::visitBinaryOperator(BinaryOperator &I) { |
| 698 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 699 | const Type *Ty = I.getOperand(0)->getType(); |
| 700 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 701 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 702 | GenericValue R; // Result |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 703 | initializeAPInt(R, Ty, SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 704 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 705 | switch (I.getOpcode()) { |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 706 | case Instruction::Add: executeAddInst (R, Src1, Src2, Ty); break; |
| 707 | case Instruction::Sub: executeSubInst (R, Src1, Src2, Ty); break; |
| 708 | case Instruction::Mul: executeMulInst (R, Src1, Src2, Ty); break; |
| 709 | case Instruction::UDiv: executeUDivInst (R, Src1, Src2, Ty); break; |
| 710 | case Instruction::SDiv: executeSDivInst (R, Src1, Src2, Ty); break; |
| 711 | case Instruction::FDiv: executeFDivInst (R, Src1, Src2, Ty); break; |
| 712 | case Instruction::URem: executeURemInst (R, Src1, Src2, Ty); break; |
| 713 | case Instruction::SRem: executeSRemInst (R, Src1, Src2, Ty); break; |
| 714 | case Instruction::FRem: executeFRemInst (R, Src1, Src2, Ty); break; |
| 715 | case Instruction::And: executeAndInst (R, Src1, Src2, Ty); break; |
| 716 | case Instruction::Or: executeOrInst (R, Src1, Src2, Ty); break; |
| 717 | case Instruction::Xor: executeXorInst (R, Src1, Src2, Ty); break; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 718 | default: |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 719 | cerr << "Don't know how to handle this binary operator!\n-->" << I; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 720 | abort(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 723 | SetValue(&I, R, SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 726 | static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, |
Chris Lattner | 759d34f | 2004-04-20 16:43:21 +0000 | [diff] [blame] | 727 | GenericValue Src3) { |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 728 | return Src1.Int1Val ? Src2 : Src3; |
Chris Lattner | 759d34f | 2004-04-20 16:43:21 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | void Interpreter::visitSelectInst(SelectInst &I) { |
| 732 | ExecutionContext &SF = ECStack.back(); |
| 733 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 734 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 735 | GenericValue Src3 = getOperandValue(I.getOperand(2), SF); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 736 | GenericValue R; |
| 737 | initializeAPInt(R, I.getOperand(1)->getType(), SF); |
| 738 | R = executeSelectInst(Src1, Src2, Src3); |
Chris Lattner | 759d34f | 2004-04-20 16:43:21 +0000 | [diff] [blame] | 739 | SetValue(&I, R, SF); |
| 740 | } |
| 741 | |
| 742 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 743 | //===----------------------------------------------------------------------===// |
| 744 | // Terminator Instruction Implementations |
| 745 | //===----------------------------------------------------------------------===// |
| 746 | |
Chris Lattner | e43db88 | 2001-10-27 04:15:57 +0000 | [diff] [blame] | 747 | void Interpreter::exitCalled(GenericValue GV) { |
Brian Gaeke | d8400d8 | 2004-02-13 05:48:00 +0000 | [diff] [blame] | 748 | // runAtExitHandlers() assumes there are no stack frames, but |
| 749 | // if exit() was called, then it had a stack frame. Blow away |
| 750 | // the stack before interpreting atexit handlers. |
| 751 | ECStack.clear (); |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 752 | runAtExitHandlers (); |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 753 | exit (GV.Int32Val); |
Chris Lattner | e43db88 | 2001-10-27 04:15:57 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 756 | /// Pop the last stack frame off of ECStack and then copy the result |
| 757 | /// back into the result variable if we are not returning void. The |
Jeff Cohen | 8c9191c | 2006-02-07 05:29:44 +0000 | [diff] [blame] | 758 | /// result variable may be the ExitValue, or the Value of the calling |
Brian Gaeke | dbde1ae | 2003-11-07 20:44:58 +0000 | [diff] [blame] | 759 | /// CallInst if there was a previous stack frame. This method may |
| 760 | /// invalidate any ECStack iterators you have. This method also takes |
| 761 | /// care of switching to the normal destination BB, if we are returning |
| 762 | /// from an invoke. |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 763 | /// |
| 764 | void Interpreter::popStackAndReturnValueToCaller (const Type *RetTy, |
| 765 | GenericValue Result) { |
| 766 | // Pop the current stack frame. |
| 767 | ECStack.pop_back(); |
| 768 | |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 769 | if (ECStack.empty()) { // Finished main. Put result into exit code... |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 770 | if (RetTy && RetTy->isInteger()) { // Nonvoid return type? |
Jeff Cohen | 8c9191c | 2006-02-07 05:29:44 +0000 | [diff] [blame] | 771 | ExitValue = Result; // Capture the exit value of the program |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 772 | } else { |
Jeff Cohen | 8c9191c | 2006-02-07 05:29:44 +0000 | [diff] [blame] | 773 | memset(&ExitValue, 0, sizeof(ExitValue)); |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 774 | } |
| 775 | } else { |
| 776 | // If we have a previous stack frame, and we have a previous call, |
| 777 | // fill in the return value... |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 778 | ExecutionContext &CallingSF = ECStack.back(); |
Brian Gaeke | dbde1ae | 2003-11-07 20:44:58 +0000 | [diff] [blame] | 779 | if (Instruction *I = CallingSF.Caller.getInstruction()) { |
Brian Gaeke | 2cb474c | 2003-11-07 19:26:23 +0000 | [diff] [blame] | 780 | if (CallingSF.Caller.getType() != Type::VoidTy) // Save result... |
Brian Gaeke | dbde1ae | 2003-11-07 20:44:58 +0000 | [diff] [blame] | 781 | SetValue(I, Result, CallingSF); |
| 782 | if (InvokeInst *II = dyn_cast<InvokeInst> (I)) |
| 783 | SwitchToNewBasicBlock (II->getNormalDest (), CallingSF); |
Brian Gaeke | 2cb474c | 2003-11-07 19:26:23 +0000 | [diff] [blame] | 784 | CallingSF.Caller = CallSite(); // We returned from the call... |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 789 | void Interpreter::visitReturnInst(ReturnInst &I) { |
| 790 | ExecutionContext &SF = ECStack.back(); |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 791 | const Type *RetTy = Type::VoidTy; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 792 | GenericValue Result; |
| 793 | |
| 794 | // Save away the return value... (if we are not 'ret void') |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 795 | if (I.getNumOperands()) { |
| 796 | RetTy = I.getReturnValue()->getType(); |
| 797 | Result = getOperandValue(I.getReturnValue(), SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 800 | popStackAndReturnValueToCaller(RetTy, Result); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Brian Gaeke | 9bf06b1 | 2003-11-07 20:07:06 +0000 | [diff] [blame] | 803 | void Interpreter::visitUnwindInst(UnwindInst &I) { |
Brian Gaeke | dbde1ae | 2003-11-07 20:44:58 +0000 | [diff] [blame] | 804 | // Unwind stack |
| 805 | Instruction *Inst; |
| 806 | do { |
| 807 | ECStack.pop_back (); |
| 808 | if (ECStack.empty ()) |
| 809 | abort (); |
| 810 | Inst = ECStack.back ().Caller.getInstruction (); |
| 811 | } while (!(Inst && isa<InvokeInst> (Inst))); |
| 812 | |
| 813 | // Return from invoke |
| 814 | ExecutionContext &InvokingSF = ECStack.back (); |
| 815 | InvokingSF.Caller = CallSite (); |
| 816 | |
| 817 | // Go to exceptional destination BB of invoke instruction |
Chris Lattner | aeb2a1d | 2004-02-08 21:44:31 +0000 | [diff] [blame] | 818 | SwitchToNewBasicBlock(cast<InvokeInst>(Inst)->getUnwindDest(), InvokingSF); |
Brian Gaeke | 9bf06b1 | 2003-11-07 20:07:06 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Chris Lattner | ec7c1ab | 2004-10-16 18:21:33 +0000 | [diff] [blame] | 821 | void Interpreter::visitUnreachableInst(UnreachableInst &I) { |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 822 | cerr << "ERROR: Program executed an 'unreachable' instruction!\n"; |
Chris Lattner | ec7c1ab | 2004-10-16 18:21:33 +0000 | [diff] [blame] | 823 | abort(); |
| 824 | } |
| 825 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 826 | void Interpreter::visitBranchInst(BranchInst &I) { |
| 827 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 828 | BasicBlock *Dest; |
| 829 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 830 | Dest = I.getSuccessor(0); // Uncond branches have a fixed dest... |
| 831 | if (!I.isUnconditional()) { |
| 832 | Value *Cond = I.getCondition(); |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 833 | if (getOperandValue(Cond, SF).Int1Val == 0) // If false cond... |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 834 | Dest = I.getSuccessor(1); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 835 | } |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 836 | SwitchToNewBasicBlock(Dest, SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 839 | void Interpreter::visitSwitchInst(SwitchInst &I) { |
| 840 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 841 | GenericValue CondVal = getOperandValue(I.getOperand(0), SF); |
| 842 | const Type *ElTy = I.getOperand(0)->getType(); |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 843 | |
| 844 | // Check to see if any of the cases match... |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 845 | BasicBlock *Dest = 0; |
| 846 | for (unsigned i = 2, e = I.getNumOperands(); i != e; i += 2) |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 847 | if (executeICMP_EQ(CondVal, |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 848 | getOperandValue(I.getOperand(i), SF), ElTy).Int1Val) { |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 849 | Dest = cast<BasicBlock>(I.getOperand(i+1)); |
| 850 | break; |
| 851 | } |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 852 | |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 853 | if (!Dest) Dest = I.getDefaultDest(); // No cases matched: use default |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 854 | SwitchToNewBasicBlock(Dest, SF); |
| 855 | } |
| 856 | |
| 857 | // SwitchToNewBasicBlock - This method is used to jump to a new basic block. |
| 858 | // This function handles the actual updating of block and instruction iterators |
| 859 | // as well as execution of all of the PHI nodes in the destination block. |
| 860 | // |
| 861 | // This method does this because all of the PHI nodes must be executed |
| 862 | // atomically, reading their inputs before any of the results are updated. Not |
| 863 | // doing this can cause problems if the PHI nodes depend on other PHI nodes for |
| 864 | // their inputs. If the input PHI node is updated before it is read, incorrect |
| 865 | // results can happen. Thus we use a two phase approach. |
| 866 | // |
| 867 | void Interpreter::SwitchToNewBasicBlock(BasicBlock *Dest, ExecutionContext &SF){ |
| 868 | BasicBlock *PrevBB = SF.CurBB; // Remember where we came from... |
| 869 | SF.CurBB = Dest; // Update CurBB to branch destination |
| 870 | SF.CurInst = SF.CurBB->begin(); // Update new instruction ptr... |
| 871 | |
| 872 | if (!isa<PHINode>(SF.CurInst)) return; // Nothing fancy to do |
| 873 | |
| 874 | // Loop over all of the PHI nodes in the current block, reading their inputs. |
| 875 | std::vector<GenericValue> ResultValues; |
| 876 | |
| 877 | for (; PHINode *PN = dyn_cast<PHINode>(SF.CurInst); ++SF.CurInst) { |
| 878 | // Search for the value corresponding to this previous bb... |
| 879 | int i = PN->getBasicBlockIndex(PrevBB); |
| 880 | assert(i != -1 && "PHINode doesn't contain entry for predecessor??"); |
| 881 | Value *IncomingValue = PN->getIncomingValue(i); |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 882 | |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 883 | // Save the incoming value for this PHI node... |
| 884 | ResultValues.push_back(getOperandValue(IncomingValue, SF)); |
| 885 | } |
| 886 | |
| 887 | // Now loop over all of the PHI nodes setting their values... |
| 888 | SF.CurInst = SF.CurBB->begin(); |
Reid Spencer | 2da5c3d | 2004-09-15 17:06:42 +0000 | [diff] [blame] | 889 | for (unsigned i = 0; isa<PHINode>(SF.CurInst); ++SF.CurInst, ++i) { |
| 890 | PHINode *PN = cast<PHINode>(SF.CurInst); |
Chris Lattner | 77113b6 | 2003-05-10 20:21:16 +0000 | [diff] [blame] | 891 | SetValue(PN, ResultValues[i], SF); |
Reid Spencer | 2da5c3d | 2004-09-15 17:06:42 +0000 | [diff] [blame] | 892 | } |
Chris Lattner | 09e9392 | 2003-04-22 20:34:47 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 895 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 896 | // Memory Instruction Implementations |
| 897 | //===----------------------------------------------------------------------===// |
| 898 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 899 | void Interpreter::visitAllocationInst(AllocationInst &I) { |
| 900 | ExecutionContext &SF = ECStack.back(); |
| 901 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 902 | const Type *Ty = I.getType()->getElementType(); // Type to be allocated |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 903 | |
Chris Lattner | cc82cc1 | 2002-04-28 21:57:33 +0000 | [diff] [blame] | 904 | // Get the number of elements being allocated by the array... |
Reid Spencer | e49661b | 2006-12-31 05:51:36 +0000 | [diff] [blame] | 905 | unsigned NumElements = getOperandValue(I.getOperand(0), SF).Int32Val; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 906 | |
| 907 | // Allocate enough memory to hold the type... |
Chris Lattner | d564496 | 2005-01-08 20:05:34 +0000 | [diff] [blame] | 908 | void *Memory = malloc(NumElements * (size_t)TD.getTypeSize(Ty)); |
Chris Lattner | 9bffa73 | 2002-02-19 18:50:09 +0000 | [diff] [blame] | 909 | |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 910 | GenericValue Result = PTOGV(Memory); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 911 | assert(Result.PointerVal != 0 && "Null pointer returned by malloc!"); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 912 | SetValue(&I, Result, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 913 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 914 | if (I.getOpcode() == Instruction::Alloca) |
Chris Lattner | 9bffa73 | 2002-02-19 18:50:09 +0000 | [diff] [blame] | 915 | ECStack.back().Allocas.add(Memory); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 918 | void Interpreter::visitFreeInst(FreeInst &I) { |
| 919 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 920 | assert(isa<PointerType>(I.getOperand(0)->getType()) && "Freeing nonptr?"); |
| 921 | GenericValue Value = getOperandValue(I.getOperand(0), SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 922 | // TODO: Check to make sure memory is allocated |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 923 | free(GVTOP(Value)); // Free memory |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 926 | // getElementOffset - The workhorse for getelementptr. |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 927 | // |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 928 | GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I, |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 929 | gep_type_iterator E, |
| 930 | ExecutionContext &SF) { |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 931 | assert(isa<PointerType>(Ptr->getType()) && |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 932 | "Cannot getElementOffset of a nonpointer type!"); |
| 933 | |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 934 | PointerTy Total = 0; |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 935 | |
| 936 | for (; I != E; ++I) { |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 937 | if (const StructType *STy = dyn_cast<StructType>(*I)) { |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 938 | const StructLayout *SLO = TD.getStructLayout(STy); |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 939 | |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 940 | const ConstantInt *CPU = cast<ConstantInt>(I.getOperand()); |
| 941 | unsigned Index = unsigned(CPU->getZExtValue()); |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 942 | |
Chris Lattner | b1919e2 | 2007-02-10 19:55:17 +0000 | [diff] [blame] | 943 | Total += (PointerTy)SLO->getElementOffset(Index); |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 944 | } else { |
| 945 | const SequentialType *ST = cast<SequentialType>(*I); |
Chris Lattner | 006a4a5 | 2003-02-25 21:14:59 +0000 | [diff] [blame] | 946 | // Get the index number for the array... which must be long type... |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 947 | GenericValue IdxGV = getOperandValue(I.getOperand(), SF); |
| 948 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 949 | int64_t Idx; |
| 950 | unsigned BitWidth = |
| 951 | cast<IntegerType>(I.getOperand()->getType())->getBitWidth(); |
Reid Spencer | 23e2883 | 2007-01-18 01:25:42 +0000 | [diff] [blame] | 952 | if (BitWidth == 32) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 953 | Idx = (int64_t)(int32_t)IdxGV.Int32Val; |
Reid Spencer | 23e2883 | 2007-01-18 01:25:42 +0000 | [diff] [blame] | 954 | else if (BitWidth == 64) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 955 | Idx = (int64_t)IdxGV.Int64Val; |
| 956 | else |
Reid Spencer | 23e2883 | 2007-01-18 01:25:42 +0000 | [diff] [blame] | 957 | assert(0 && "Invalid index type for getelementptr"); |
Chris Lattner | d564496 | 2005-01-08 20:05:34 +0000 | [diff] [blame] | 958 | Total += PointerTy(TD.getTypeSize(ST->getElementType())*Idx); |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 959 | } |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 962 | GenericValue Result; |
| 963 | Result.PointerVal = getOperandValue(Ptr, SF).PointerVal + Total; |
| 964 | return Result; |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 967 | void Interpreter::visitGetElementPtrInst(GetElementPtrInst &I) { |
| 968 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 969 | SetValue(&I, TheEE->executeGEPOperation(I.getPointerOperand(), |
Chris Lattner | 4af6de8 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 970 | gep_type_begin(I), gep_type_end(I), SF), SF); |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 973 | void Interpreter::visitLoadInst(LoadInst &I) { |
| 974 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 975 | GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 976 | GenericValue *Ptr = (GenericValue*)GVTOP(SRC); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 977 | GenericValue Result; |
| 978 | initializeAPInt(Result, I.getType(), SF); |
| 979 | LoadValueFromMemory(Result, Ptr, I.getType()); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 980 | SetValue(&I, Result, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 983 | void Interpreter::visitStoreInst(StoreInst &I) { |
| 984 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | fddc755 | 2002-10-15 20:34:05 +0000 | [diff] [blame] | 985 | GenericValue Val = getOperandValue(I.getOperand(0), SF); |
| 986 | GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); |
Chris Lattner | fe11a97 | 2002-12-23 23:59:41 +0000 | [diff] [blame] | 987 | StoreValueToMemory(Val, (GenericValue *)GVTOP(SRC), |
Chris Lattner | 683d5da9 | 2002-10-26 01:57:15 +0000 | [diff] [blame] | 988 | I.getOperand(0)->getType()); |
Chris Lattner | fddc755 | 2002-10-15 20:34:05 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 991 | //===----------------------------------------------------------------------===// |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 992 | // Miscellaneous Instruction Implementations |
| 993 | //===----------------------------------------------------------------------===// |
| 994 | |
Brian Gaeke | fea483d | 2003-11-07 20:04:22 +0000 | [diff] [blame] | 995 | void Interpreter::visitCallSite(CallSite CS) { |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 996 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 997 | |
| 998 | // Check to see if this is an intrinsic function call... |
| 999 | if (Function *F = CS.getCalledFunction()) |
Reid Spencer | 5cbf985 | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 1000 | if (F->isDeclaration ()) |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1001 | switch (F->getIntrinsicID()) { |
Brian Gaeke | 34562ba | 2004-01-14 06:02:53 +0000 | [diff] [blame] | 1002 | case Intrinsic::not_intrinsic: |
| 1003 | break; |
Chris Lattner | 317201d | 2004-03-13 00:24:00 +0000 | [diff] [blame] | 1004 | case Intrinsic::vastart: { // va_start |
Brian Gaeke | 9d20b71 | 2004-02-25 23:01:48 +0000 | [diff] [blame] | 1005 | GenericValue ArgIndex; |
| 1006 | ArgIndex.UIntPairVal.first = ECStack.size() - 1; |
| 1007 | ArgIndex.UIntPairVal.second = 0; |
| 1008 | SetValue(CS.getInstruction(), ArgIndex, SF); |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1009 | return; |
Brian Gaeke | 9d20b71 | 2004-02-25 23:01:48 +0000 | [diff] [blame] | 1010 | } |
Chris Lattner | 317201d | 2004-03-13 00:24:00 +0000 | [diff] [blame] | 1011 | case Intrinsic::vaend: // va_end is a noop for the interpreter |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1012 | return; |
Chris Lattner | 317201d | 2004-03-13 00:24:00 +0000 | [diff] [blame] | 1013 | case Intrinsic::vacopy: // va_copy: dest = src |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1014 | SetValue(CS.getInstruction(), getOperandValue(*CS.arg_begin(), SF), SF); |
| 1015 | return; |
| 1016 | default: |
Brian Gaeke | 34562ba | 2004-01-14 06:02:53 +0000 | [diff] [blame] | 1017 | // If it is an unknown intrinsic function, use the intrinsic lowering |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1018 | // class to transform it into hopefully tasty LLVM code. |
| 1019 | // |
| 1020 | Instruction *Prev = CS.getInstruction()->getPrev(); |
| 1021 | BasicBlock *Parent = CS.getInstruction()->getParent(); |
| 1022 | IL->LowerIntrinsicCall(cast<CallInst>(CS.getInstruction())); |
| 1023 | |
| 1024 | // Restore the CurInst pointer to the first instruction newly inserted, if |
| 1025 | // any. |
| 1026 | if (!Prev) { |
| 1027 | SF.CurInst = Parent->begin(); |
| 1028 | } else { |
| 1029 | SF.CurInst = Prev; |
| 1030 | ++SF.CurInst; |
| 1031 | } |
Brian Gaeke | b440dea | 2004-04-23 18:05:28 +0000 | [diff] [blame] | 1032 | return; |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Brian Gaeke | fea483d | 2003-11-07 20:04:22 +0000 | [diff] [blame] | 1035 | SF.Caller = CS; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 1036 | std::vector<GenericValue> ArgVals; |
Brian Gaeke | ae2495a | 2003-11-07 19:59:08 +0000 | [diff] [blame] | 1037 | const unsigned NumArgs = SF.Caller.arg_size(); |
| 1038 | ArgVals.reserve(NumArgs); |
| 1039 | for (CallSite::arg_iterator i = SF.Caller.arg_begin(), |
| 1040 | e = SF.Caller.arg_end(); i != e; ++i) { |
| 1041 | Value *V = *i; |
| 1042 | ArgVals.push_back(getOperandValue(V, SF)); |
Chris Lattner | 9378013 | 2003-01-13 00:58:52 +0000 | [diff] [blame] | 1043 | // Promote all integral types whose size is < sizeof(int) into ints. We do |
| 1044 | // this by zero or sign extending the value as appropriate according to the |
| 1045 | // source type. |
Brian Gaeke | ae2495a | 2003-11-07 19:59:08 +0000 | [diff] [blame] | 1046 | const Type *Ty = V->getType(); |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1047 | if (Ty->isInteger()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1048 | if (Ty->getPrimitiveSizeInBits() == 1) |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 1049 | ArgVals.back().Int32Val = ArgVals.back().Int1Val; |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1050 | else if (Ty->getPrimitiveSizeInBits() <= 8) |
| 1051 | ArgVals.back().Int32Val = ArgVals.back().Int8Val; |
| 1052 | else if (Ty->getPrimitiveSizeInBits() <= 16) |
| 1053 | ArgVals.back().Int32Val = ArgVals.back().Int16Val; |
Chris Lattner | 9378013 | 2003-01-13 00:58:52 +0000 | [diff] [blame] | 1054 | } |
| 1055 | } |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 1056 | |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1057 | // 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] | 1058 | // and treat it as a function pointer. |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1059 | GenericValue SRC = getOperandValue(SF.Caller.getCalledValue(), SF); |
Chris Lattner | da82ed5 | 2003-05-08 16:18:31 +0000 | [diff] [blame] | 1060 | callFunction((Function*)GVTOP(SRC), ArgVals); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1063 | static void executeShlInst(GenericValue &Dest, GenericValue Src1, |
| 1064 | GenericValue Src2, const Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1065 | if (const IntegerType *ITy = cast<IntegerType>(Ty)) { |
| 1066 | unsigned BitWidth = ITy->getBitWidth(); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1067 | if (BitWidth <= 8) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1068 | Dest.Int8Val = ((uint8_t)Src1.Int8Val) << ((uint32_t)Src2.Int8Val); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1069 | maskToBitWidth(Dest, BitWidth); |
| 1070 | } else if (BitWidth <= 16) { |
| 1071 | Dest.Int16Val = ((uint16_t)Src1.Int16Val) << ((uint32_t)Src2.Int16Val); |
| 1072 | maskToBitWidth(Dest, BitWidth); |
| 1073 | } else if (BitWidth <= 32) { |
| 1074 | Dest.Int32Val = ((uint32_t)Src1.Int32Val) << ((uint32_t)Src2.Int32Val); |
| 1075 | maskToBitWidth(Dest, BitWidth); |
| 1076 | } else if (BitWidth <= 64) { |
| 1077 | Dest.Int64Val = ((uint64_t)Src1.Int64Val) << ((uint32_t)Src2.Int64Val); |
| 1078 | maskToBitWidth(Dest, BitWidth); |
| 1079 | } else { |
| 1080 | *(Dest.APIntVal) = Src1.APIntVal->shl(Src2.APIntVal->getZExtValue()); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1081 | } |
| 1082 | } else { |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 1083 | cerr << "Unhandled type for Shl instruction: " << *Ty << "\n"; |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1084 | abort(); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1085 | } |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1088 | static void executeLShrInst(GenericValue &Dest, GenericValue Src1, |
| 1089 | GenericValue Src2, const Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1090 | if (const IntegerType *ITy = cast<IntegerType>(Ty)) { |
| 1091 | unsigned BitWidth = ITy->getBitWidth(); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1092 | if (BitWidth <= 8) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1093 | Dest.Int8Val = ((uint8_t)Src1.Int8Val) >> ((uint32_t)Src2.Int8Val); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1094 | maskToBitWidth(Dest, BitWidth); |
| 1095 | } else if (BitWidth <= 16) { |
| 1096 | Dest.Int16Val = ((uint16_t)Src1.Int16Val) >> ((uint32_t)Src2.Int16Val); |
| 1097 | maskToBitWidth(Dest, BitWidth); |
| 1098 | } else if (BitWidth <= 32) { |
| 1099 | Dest.Int32Val = ((uint32_t)Src1.Int32Val) >> ((uint32_t)Src2.Int32Val); |
| 1100 | maskToBitWidth(Dest, BitWidth); |
| 1101 | } else if (BitWidth <= 64) { |
| 1102 | Dest.Int64Val = ((uint64_t)Src1.Int64Val) >> ((uint32_t)Src2.Int64Val); |
| 1103 | maskToBitWidth(Dest, BitWidth); |
| 1104 | } else { |
| 1105 | *(Dest.APIntVal) = Src1.APIntVal->lshr(Src2.APIntVal->getZExtValue()); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } else { |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 1108 | cerr << "Unhandled type for LShr instruction: " << *Ty << "\n"; |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 1109 | abort(); |
| 1110 | } |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1113 | static void executeAShrInst(GenericValue &Dest, GenericValue Src1, |
| 1114 | GenericValue Src2, const Type *Ty) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1115 | if (const IntegerType *ITy = cast<IntegerType>(Ty)) { |
| 1116 | unsigned BitWidth = ITy->getBitWidth(); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1117 | if (BitWidth <= 8) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1118 | Dest.Int8Val = ((int8_t)Src1.Int8Val) >> ((int32_t)Src2.Int8Val); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1119 | maskToBitWidth(Dest, BitWidth); |
| 1120 | } else if (BitWidth <= 16) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1121 | Dest.Int16Val = ((int16_t)Src1.Int16Val) >> ((int32_t)Src2.Int8Val); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1122 | maskToBitWidth(Dest, BitWidth); |
| 1123 | } else if (BitWidth <= 32) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1124 | Dest.Int32Val = ((int32_t)Src1.Int32Val) >> ((int32_t)Src2.Int8Val); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1125 | maskToBitWidth(Dest, BitWidth); |
| 1126 | } else if (BitWidth <= 64) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1127 | Dest.Int64Val = ((int64_t)Src1.Int64Val) >> ((int32_t)Src2.Int8Val); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1128 | maskToBitWidth(Dest, BitWidth); |
| 1129 | } else { |
| 1130 | *(Dest.APIntVal) = Src1.APIntVal->ashr(Src2.APIntVal->getZExtValue()); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1131 | } |
| 1132 | } else { |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 1133 | cerr << "Unhandled type for AShr instruction: " << *Ty << "\n"; |
Chris Lattner | 0286835 | 2003-04-22 21:22:33 +0000 | [diff] [blame] | 1134 | abort(); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1135 | } |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 1138 | void Interpreter::visitShl(BinaryOperator &I) { |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1139 | ExecutionContext &SF = ECStack.back(); |
| 1140 | const Type *Ty = I.getOperand(0)->getType(); |
| 1141 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1142 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1143 | GenericValue Dest; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1144 | initializeAPInt(Dest, Ty, SF); |
| 1145 | executeShlInst (Dest, Src1, Src2, Ty); |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1146 | SetValue(&I, Dest, SF); |
| 1147 | } |
| 1148 | |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 1149 | void Interpreter::visitLShr(BinaryOperator &I) { |
Brian Gaeke | 63438cc | 2003-12-11 00:22:59 +0000 | [diff] [blame] | 1150 | ExecutionContext &SF = ECStack.back(); |
| 1151 | const Type *Ty = I.getOperand(0)->getType(); |
| 1152 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1153 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1154 | GenericValue Dest; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1155 | initializeAPInt(Dest, Ty, SF); |
| 1156 | executeLShrInst (Dest, Src1, Src2, Ty); |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 1157 | SetValue(&I, Dest, SF); |
| 1158 | } |
| 1159 | |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 1160 | void Interpreter::visitAShr(BinaryOperator &I) { |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 1161 | ExecutionContext &SF = ECStack.back(); |
| 1162 | const Type *Ty = I.getOperand(0)->getType(); |
| 1163 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 1164 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
| 1165 | GenericValue Dest; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1166 | initializeAPInt(Dest, Ty, SF); |
| 1167 | executeAShrInst (Dest, Src1, Src2, Ty); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1168 | SetValue(&I, Dest, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Reid Spencer | 23e2883 | 2007-01-18 01:25:42 +0000 | [diff] [blame] | 1171 | #define INTEGER_ASSIGN(DEST, BITWIDTH, VAL) \ |
| 1172 | { \ |
Reid Spencer | 23cbb1c | 2007-02-08 00:29:31 +0000 | [diff] [blame] | 1173 | uint64_t Mask = ~(uint64_t)(0ull) >> (64-BITWIDTH); \ |
Reid Spencer | 23e2883 | 2007-01-18 01:25:42 +0000 | [diff] [blame] | 1174 | if (BITWIDTH == 1) { \ |
| 1175 | Dest.Int1Val = (bool) (VAL & Mask); \ |
| 1176 | } else if (BITWIDTH <= 8) { \ |
| 1177 | Dest.Int8Val = (uint8_t) (VAL & Mask); \ |
| 1178 | } else if (BITWIDTH <= 16) { \ |
| 1179 | Dest.Int16Val = (uint16_t) (VAL & Mask); \ |
| 1180 | } else if (BITWIDTH <= 32) { \ |
| 1181 | Dest.Int32Val = (uint32_t) (VAL & Mask); \ |
| 1182 | } else \ |
| 1183 | Dest.Int64Val = (uint64_t) (VAL & Mask); \ |
| 1184 | } |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1185 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1186 | GenericValue Interpreter::executeTruncInst(Value *SrcVal, const Type *DstTy, |
| 1187 | ExecutionContext &SF) { |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1188 | const Type *SrcTy = SrcVal->getType(); |
| 1189 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1190 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1191 | const IntegerType *SITy = cast<IntegerType>(SrcTy); |
| 1192 | unsigned DBitWidth = DITy->getBitWidth(); |
| 1193 | unsigned SBitWidth = SITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1194 | assert(SBitWidth > DBitWidth && "Invalid truncate"); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1195 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1196 | if (DBitWidth > 64) { |
| 1197 | // Both values are APInt, just use the APInt trunc |
| 1198 | initializeAPInt(Dest, DstTy, SF); |
| 1199 | *(Dest.APIntVal) = Src.APIntVal->trunc(DBitWidth); |
| 1200 | return Dest; |
| 1201 | } |
| 1202 | |
| 1203 | uint64_t MaskedVal = 0; |
| 1204 | uint64_t Mask = (1ULL << DBitWidth) - 1; |
| 1205 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1206 | // Mask the source value to its actual bit width. This ensures that any |
| 1207 | // high order bits are cleared. |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1208 | if (SBitWidth <= 8) |
| 1209 | MaskedVal = Src.Int8Val & Mask; |
| 1210 | else if (SBitWidth <= 16) |
| 1211 | MaskedVal = Src.Int16Val & Mask; |
| 1212 | else if (SBitWidth <= 32) |
| 1213 | MaskedVal = Src.Int32Val & Mask; |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1214 | else if (SBitWidth <= 64) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1215 | MaskedVal = Src.Int64Val & Mask; |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1216 | else |
| 1217 | MaskedVal = Src.APIntVal->trunc(DBitWidth).getZExtValue(); |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1218 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1219 | INTEGER_ASSIGN(Dest, DBitWidth, MaskedVal); |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1220 | return Dest; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1221 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1222 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1223 | GenericValue Interpreter::executeSExtInst(Value *SrcVal, const Type *DstTy, |
| 1224 | ExecutionContext &SF) { |
| 1225 | const Type *SrcTy = SrcVal->getType(); |
| 1226 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1227 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1228 | const IntegerType *SITy = cast<IntegerType>(SrcTy); |
| 1229 | unsigned DBitWidth = DITy->getBitWidth(); |
| 1230 | unsigned SBitWidth = SITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1231 | assert(SBitWidth < DBitWidth && "Invalid sign extend"); |
Reid Spencer | c00a430 | 2007-01-20 08:32:52 +0000 | [diff] [blame] | 1232 | |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1233 | if (SBitWidth > 64) { |
| 1234 | // Both values are APInt, just use the APInt::sext method; |
| 1235 | initializeAPInt(Dest, DstTy, SF); |
| 1236 | *(Dest.APIntVal) = Src.APIntVal->sext(DBitWidth); |
| 1237 | return Dest; |
| 1238 | } |
| 1239 | |
Reid Spencer | c00a430 | 2007-01-20 08:32:52 +0000 | [diff] [blame] | 1240 | // Normalize to a 64-bit value. |
| 1241 | uint64_t Normalized = 0; |
| 1242 | if (SBitWidth <= 8) |
| 1243 | Normalized = Src.Int8Val; |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1244 | else if (SBitWidth <= 16) |
Reid Spencer | c00a430 | 2007-01-20 08:32:52 +0000 | [diff] [blame] | 1245 | Normalized = Src.Int16Val; |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1246 | else if (SBitWidth <= 32) |
Reid Spencer | c00a430 | 2007-01-20 08:32:52 +0000 | [diff] [blame] | 1247 | Normalized = Src.Int32Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1248 | else |
Reid Spencer | c00a430 | 2007-01-20 08:32:52 +0000 | [diff] [blame] | 1249 | Normalized = Src.Int64Val; |
| 1250 | |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1251 | if (DBitWidth > 64) { |
| 1252 | // Destination is an APint, construct it and return |
| 1253 | initializeAPInt(Dest, DstTy, SF); |
| 1254 | *(Dest.APIntVal) = APInt(SBitWidth, Normalized).sext(DBitWidth); |
| 1255 | return Dest; |
| 1256 | } |
| 1257 | |
Reid Spencer | a42c7fd | 2007-01-20 20:12:29 +0000 | [diff] [blame] | 1258 | Normalized = doSignExtension(Normalized, SITy); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1259 | |
| 1260 | // Now that we have a sign extended value, assign it to the destination |
Reid Spencer | c00a430 | 2007-01-20 08:32:52 +0000 | [diff] [blame] | 1261 | INTEGER_ASSIGN(Dest, DBitWidth, Normalized); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1262 | return Dest; |
| 1263 | } |
| 1264 | |
| 1265 | GenericValue Interpreter::executeZExtInst(Value *SrcVal, const Type *DstTy, |
| 1266 | ExecutionContext &SF) { |
| 1267 | const Type *SrcTy = SrcVal->getType(); |
| 1268 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1269 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1270 | const IntegerType *SITy = cast<IntegerType>(SrcTy); |
| 1271 | unsigned DBitWidth = DITy->getBitWidth(); |
| 1272 | unsigned SBitWidth = SITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1273 | assert(SBitWidth < DBitWidth && "Invalid sign extend"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1274 | |
| 1275 | if (SBitWidth > 64) { |
| 1276 | // Both values are APInt, just use the APInt::sext method; |
| 1277 | initializeAPInt(Dest, DstTy, SF); |
| 1278 | *(Dest.APIntVal) = Src.APIntVal->zext(DBitWidth); |
| 1279 | return Dest; |
| 1280 | } |
| 1281 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1282 | uint64_t Extended = 0; |
| 1283 | if (SBitWidth == 1) |
| 1284 | // For sign extension from bool, we must extend the source bits. |
| 1285 | Extended = (uint64_t) (Src.Int1Val & 1); |
| 1286 | else if (SBitWidth <= 8) |
| 1287 | Extended = (uint64_t) (uint8_t)Src.Int8Val; |
| 1288 | else if (SBitWidth <= 16) |
| 1289 | Extended = (uint64_t) (uint16_t)Src.Int16Val; |
| 1290 | else if (SBitWidth <= 32) |
| 1291 | Extended = (uint64_t) (uint32_t)Src.Int32Val; |
| 1292 | else |
| 1293 | Extended = (uint64_t) Src.Int64Val; |
| 1294 | |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1295 | if (DBitWidth > 64) { |
| 1296 | // Destination is an APint, construct it and return |
| 1297 | initializeAPInt(Dest, DstTy, SF); |
| 1298 | *(Dest.APIntVal) = APInt(SBitWidth, Extended).zext(DBitWidth); |
| 1299 | return Dest; |
| 1300 | } |
| 1301 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1302 | // Now that we have a sign extended value, assign it to the destination |
| 1303 | INTEGER_ASSIGN(Dest, DBitWidth, Extended); |
| 1304 | return Dest; |
| 1305 | } |
| 1306 | |
| 1307 | GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy, |
| 1308 | ExecutionContext &SF) { |
| 1309 | const Type *SrcTy = SrcVal->getType(); |
| 1310 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1311 | assert(SrcTy == Type::DoubleTy && DstTy == Type::FloatTy && |
| 1312 | "Invalid FPTrunc instruction"); |
| 1313 | Dest.FloatVal = (float) Src.DoubleVal; |
| 1314 | return Dest; |
| 1315 | } |
| 1316 | |
| 1317 | GenericValue Interpreter::executeFPExtInst(Value *SrcVal, const Type *DstTy, |
| 1318 | ExecutionContext &SF) { |
| 1319 | const Type *SrcTy = SrcVal->getType(); |
| 1320 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1321 | assert(SrcTy == Type::FloatTy && DstTy == Type::DoubleTy && |
| 1322 | "Invalid FPTrunc instruction"); |
| 1323 | Dest.DoubleVal = (double) Src.FloatVal; |
| 1324 | return Dest; |
| 1325 | } |
| 1326 | |
| 1327 | GenericValue Interpreter::executeFPToUIInst(Value *SrcVal, const Type *DstTy, |
| 1328 | ExecutionContext &SF) { |
| 1329 | const Type *SrcTy = SrcVal->getType(); |
| 1330 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1331 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1332 | unsigned DBitWidth = DITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1333 | assert(SrcTy->isFloatingPoint() && "Invalid FPToUI instruction"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1334 | |
| 1335 | if (DBitWidth > 64) { |
| 1336 | initializeAPInt(Dest, DITy, SF); |
| 1337 | if (SrcTy->getTypeID() == Type::FloatTyID) |
| 1338 | *(Dest.APIntVal) = APIntOps::RoundFloatToAPInt(Src.FloatVal, DBitWidth); |
| 1339 | else |
| 1340 | *(Dest.APIntVal) = APIntOps::RoundDoubleToAPInt(Src.DoubleVal, DBitWidth); |
| 1341 | return Dest; |
| 1342 | } |
| 1343 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1344 | uint64_t Converted = 0; |
| 1345 | if (SrcTy->getTypeID() == Type::FloatTyID) |
| 1346 | Converted = (uint64_t) Src.FloatVal; |
| 1347 | else |
| 1348 | Converted = (uint64_t) Src.DoubleVal; |
| 1349 | |
| 1350 | INTEGER_ASSIGN(Dest, DBitWidth, Converted); |
| 1351 | return Dest; |
| 1352 | } |
| 1353 | |
| 1354 | GenericValue Interpreter::executeFPToSIInst(Value *SrcVal, const Type *DstTy, |
| 1355 | ExecutionContext &SF) { |
| 1356 | const Type *SrcTy = SrcVal->getType(); |
| 1357 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1358 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1359 | unsigned DBitWidth = DITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1360 | assert(SrcTy->isFloatingPoint() && "Invalid FPToSI instruction"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1361 | |
| 1362 | if (DBitWidth > 64) { |
| 1363 | initializeAPInt(Dest, DITy, SF); |
| 1364 | if (SrcTy->getTypeID() == Type::FloatTyID) |
| 1365 | *(Dest.APIntVal) = APIntOps::RoundFloatToAPInt(Src.FloatVal, DBitWidth); |
| 1366 | else |
| 1367 | *(Dest.APIntVal) = APIntOps::RoundDoubleToAPInt(Src.DoubleVal, DBitWidth); |
| 1368 | return Dest; |
| 1369 | } |
| 1370 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1371 | int64_t Converted = 0; |
| 1372 | if (SrcTy->getTypeID() == Type::FloatTyID) |
| 1373 | Converted = (int64_t) Src.FloatVal; |
| 1374 | else |
| 1375 | Converted = (int64_t) Src.DoubleVal; |
| 1376 | |
| 1377 | INTEGER_ASSIGN(Dest, DBitWidth, Converted); |
| 1378 | return Dest; |
| 1379 | } |
| 1380 | |
| 1381 | GenericValue Interpreter::executeUIToFPInst(Value *SrcVal, const Type *DstTy, |
| 1382 | ExecutionContext &SF) { |
| 1383 | const Type *SrcTy = SrcVal->getType(); |
| 1384 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1385 | const IntegerType *SITy = cast<IntegerType>(SrcTy); |
| 1386 | unsigned SBitWidth = SITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1387 | assert(DstTy->isFloatingPoint() && "Invalid UIToFP instruction"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1388 | |
| 1389 | if (SBitWidth > 64) { |
| 1390 | if (DstTy->getTypeID() == Type::FloatTyID) |
| 1391 | Dest.FloatVal = APIntOps::RoundAPIntToFloat(*(Src.APIntVal)); |
| 1392 | else |
| 1393 | Dest.DoubleVal = APIntOps::RoundAPIntToDouble(*(Src.APIntVal)); |
| 1394 | return Dest; |
| 1395 | } |
| 1396 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1397 | uint64_t Converted = 0; |
| 1398 | if (SBitWidth == 1) |
| 1399 | Converted = (uint64_t) Src.Int1Val; |
| 1400 | else if (SBitWidth <= 8) |
| 1401 | Converted = (uint64_t) Src.Int8Val; |
| 1402 | else if (SBitWidth <= 16) |
| 1403 | Converted = (uint64_t) Src.Int16Val; |
| 1404 | else if (SBitWidth <= 32) |
| 1405 | Converted = (uint64_t) Src.Int32Val; |
| 1406 | else |
| 1407 | Converted = (uint64_t) Src.Int64Val; |
| 1408 | |
| 1409 | if (DstTy->getTypeID() == Type::FloatTyID) |
| 1410 | Dest.FloatVal = (float) Converted; |
| 1411 | else |
| 1412 | Dest.DoubleVal = (double) Converted; |
| 1413 | return Dest; |
| 1414 | } |
| 1415 | |
| 1416 | GenericValue Interpreter::executeSIToFPInst(Value *SrcVal, const Type *DstTy, |
| 1417 | ExecutionContext &SF) { |
| 1418 | const Type *SrcTy = SrcVal->getType(); |
| 1419 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1420 | const IntegerType *SITy = cast<IntegerType>(SrcTy); |
| 1421 | unsigned SBitWidth = SITy->getBitWidth(); |
Reid Spencer | 24d6da5 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 1422 | assert(DstTy->isFloatingPoint() && "Invalid SIToFP instruction"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1423 | |
| 1424 | if (SBitWidth > 64) { |
| 1425 | if (DstTy->getTypeID() == Type::FloatTyID) |
| 1426 | Dest.FloatVal = APIntOps::RoundSignedAPIntToFloat(*(Src.APIntVal)); |
| 1427 | else |
| 1428 | Dest.DoubleVal = APIntOps::RoundSignedAPIntToDouble(*(Src.APIntVal)); |
| 1429 | return Dest; |
| 1430 | } |
| 1431 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1432 | int64_t Converted = 0; |
| 1433 | if (SBitWidth == 1) |
| 1434 | Converted = 0LL - Src.Int1Val; |
| 1435 | else if (SBitWidth <= 8) |
| 1436 | Converted = (int64_t) (int8_t)Src.Int8Val; |
| 1437 | else if (SBitWidth <= 16) |
| 1438 | Converted = (int64_t) (int16_t)Src.Int16Val; |
| 1439 | else if (SBitWidth <= 32) |
| 1440 | Converted = (int64_t) (int32_t)Src.Int32Val; |
| 1441 | else |
| 1442 | Converted = (int64_t) Src.Int64Val; |
| 1443 | |
| 1444 | if (DstTy->getTypeID() == Type::FloatTyID) |
| 1445 | Dest.FloatVal = (float) Converted; |
| 1446 | else |
| 1447 | Dest.DoubleVal = (double) Converted; |
| 1448 | return Dest; |
| 1449 | } |
| 1450 | |
| 1451 | GenericValue Interpreter::executePtrToIntInst(Value *SrcVal, const Type *DstTy, |
| 1452 | ExecutionContext &SF) { |
| 1453 | const Type *SrcTy = SrcVal->getType(); |
| 1454 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1455 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1456 | unsigned DBitWidth = DITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1457 | assert(isa<PointerType>(SrcTy) && "Invalid PtrToInt instruction"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1458 | |
| 1459 | if (DBitWidth > 64) { |
| 1460 | initializeAPInt(Dest, DstTy, SF); |
| 1461 | *(Dest.APIntVal) = (intptr_t) Src.PointerVal; |
| 1462 | } |
| 1463 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1464 | INTEGER_ASSIGN(Dest, DBitWidth, (intptr_t) Src.PointerVal); |
| 1465 | return Dest; |
| 1466 | } |
| 1467 | |
| 1468 | GenericValue Interpreter::executeIntToPtrInst(Value *SrcVal, const Type *DstTy, |
| 1469 | ExecutionContext &SF) { |
| 1470 | const Type *SrcTy = SrcVal->getType(); |
| 1471 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1472 | const IntegerType *SITy = cast<IntegerType>(SrcTy); |
| 1473 | unsigned SBitWidth = SITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1474 | assert(isa<PointerType>(DstTy) && "Invalid PtrToInt instruction"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1475 | |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1476 | uint64_t Converted = 0; |
| 1477 | if (SBitWidth == 1) |
| 1478 | Converted = (uint64_t) Src.Int1Val; |
| 1479 | else if (SBitWidth <= 8) |
| 1480 | Converted = (uint64_t) Src.Int8Val; |
| 1481 | else if (SBitWidth <= 16) |
| 1482 | Converted = (uint64_t) Src.Int16Val; |
| 1483 | else if (SBitWidth <= 32) |
| 1484 | Converted = (uint64_t) Src.Int32Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1485 | else if (SBitWidth <= 64) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1486 | Converted = (uint64_t) Src.Int64Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1487 | else |
| 1488 | Converted = (uint64_t) Src.APIntVal->trunc(64).getZExtValue(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1489 | |
| 1490 | Dest.PointerVal = (PointerTy) Converted; |
| 1491 | return Dest; |
| 1492 | } |
| 1493 | |
| 1494 | GenericValue Interpreter::executeBitCastInst(Value *SrcVal, const Type *DstTy, |
| 1495 | ExecutionContext &SF) { |
| 1496 | |
| 1497 | const Type *SrcTy = SrcVal->getType(); |
| 1498 | GenericValue Dest, Src = getOperandValue(SrcVal, SF); |
| 1499 | if (isa<PointerType>(DstTy)) { |
| 1500 | assert(isa<PointerType>(SrcTy) && "Invalid BitCast"); |
| 1501 | Dest.PointerVal = Src.PointerVal; |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1502 | } else if (DstTy->isInteger()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1503 | const IntegerType *DITy = cast<IntegerType>(DstTy); |
| 1504 | unsigned DBitWidth = DITy->getBitWidth(); |
| 1505 | if (SrcTy == Type::FloatTy) { |
| 1506 | Dest.Int32Val = FloatToBits(Src.FloatVal); |
| 1507 | } else if (SrcTy == Type::DoubleTy) { |
| 1508 | Dest.Int64Val = DoubleToBits(Src.DoubleVal); |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1509 | } else if (SrcTy->isInteger()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1510 | const IntegerType *SITy = cast<IntegerType>(SrcTy); |
| 1511 | unsigned SBitWidth = SITy->getBitWidth(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1512 | assert(SBitWidth == DBitWidth && "Invalid BitCast"); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1513 | if (SBitWidth == 1) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1514 | Dest.Int1Val = Src.Int1Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1515 | maskToBitWidth(Dest, DBitWidth); |
| 1516 | } else if (SBitWidth <= 8) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1517 | Dest.Int8Val = Src.Int8Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1518 | maskToBitWidth(Dest, DBitWidth); |
| 1519 | } else if (SBitWidth <= 16) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1520 | Dest.Int16Val = Src.Int16Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1521 | maskToBitWidth(Dest, DBitWidth); |
| 1522 | } else if (SBitWidth <= 32) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1523 | Dest.Int32Val = Src.Int32Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1524 | maskToBitWidth(Dest, DBitWidth); |
| 1525 | } else if (SBitWidth <= 64) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1526 | Dest.Int64Val = Src.Int64Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1527 | maskToBitWidth(Dest, DBitWidth); |
| 1528 | } else { |
| 1529 | *(Dest.APIntVal) = *(Src.APIntVal); |
| 1530 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1531 | } else |
| 1532 | assert(0 && "Invalid BitCast"); |
| 1533 | } else if (DstTy == Type::FloatTy) { |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1534 | if (SrcTy->isInteger()) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1535 | Dest.FloatVal = BitsToFloat(Src.Int32Val); |
| 1536 | else |
| 1537 | Dest.FloatVal = Src.FloatVal; |
| 1538 | } else if (DstTy == Type::DoubleTy) { |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1539 | if (SrcTy->isInteger()) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1540 | Dest.DoubleVal = BitsToDouble(Src.Int64Val); |
| 1541 | else |
| 1542 | Dest.DoubleVal = Src.DoubleVal; |
| 1543 | } else |
| 1544 | assert(0 && "Invalid Bitcast"); |
| 1545 | |
| 1546 | return Dest; |
| 1547 | } |
| 1548 | |
| 1549 | void Interpreter::visitTruncInst(TruncInst &I) { |
Chris Lattner | d7916e9 | 2003-05-10 21:22:39 +0000 | [diff] [blame] | 1550 | ExecutionContext &SF = ECStack.back(); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1551 | SetValue(&I, executeTruncInst(I.getOperand(0), I.getType(), SF), SF); |
| 1552 | } |
| 1553 | |
| 1554 | void Interpreter::visitSExtInst(SExtInst &I) { |
| 1555 | ExecutionContext &SF = ECStack.back(); |
| 1556 | SetValue(&I, executeSExtInst(I.getOperand(0), I.getType(), SF), SF); |
| 1557 | } |
| 1558 | |
| 1559 | void Interpreter::visitZExtInst(ZExtInst &I) { |
| 1560 | ExecutionContext &SF = ECStack.back(); |
| 1561 | SetValue(&I, executeZExtInst(I.getOperand(0), I.getType(), SF), SF); |
| 1562 | } |
| 1563 | |
| 1564 | void Interpreter::visitFPTruncInst(FPTruncInst &I) { |
| 1565 | ExecutionContext &SF = ECStack.back(); |
| 1566 | SetValue(&I, executeFPTruncInst(I.getOperand(0), I.getType(), SF), SF); |
| 1567 | } |
| 1568 | |
| 1569 | void Interpreter::visitFPExtInst(FPExtInst &I) { |
| 1570 | ExecutionContext &SF = ECStack.back(); |
| 1571 | SetValue(&I, executeFPExtInst(I.getOperand(0), I.getType(), SF), SF); |
| 1572 | } |
| 1573 | |
| 1574 | void Interpreter::visitUIToFPInst(UIToFPInst &I) { |
| 1575 | ExecutionContext &SF = ECStack.back(); |
| 1576 | SetValue(&I, executeUIToFPInst(I.getOperand(0), I.getType(), SF), SF); |
| 1577 | } |
| 1578 | |
| 1579 | void Interpreter::visitSIToFPInst(SIToFPInst &I) { |
| 1580 | ExecutionContext &SF = ECStack.back(); |
| 1581 | SetValue(&I, executeSIToFPInst(I.getOperand(0), I.getType(), SF), SF); |
| 1582 | } |
| 1583 | |
| 1584 | void Interpreter::visitFPToUIInst(FPToUIInst &I) { |
| 1585 | ExecutionContext &SF = ECStack.back(); |
| 1586 | SetValue(&I, executeFPToUIInst(I.getOperand(0), I.getType(), SF), SF); |
| 1587 | } |
| 1588 | |
| 1589 | void Interpreter::visitFPToSIInst(FPToSIInst &I) { |
| 1590 | ExecutionContext &SF = ECStack.back(); |
| 1591 | SetValue(&I, executeFPToSIInst(I.getOperand(0), I.getType(), SF), SF); |
| 1592 | } |
| 1593 | |
| 1594 | void Interpreter::visitPtrToIntInst(PtrToIntInst &I) { |
| 1595 | ExecutionContext &SF = ECStack.back(); |
| 1596 | SetValue(&I, executePtrToIntInst(I.getOperand(0), I.getType(), SF), SF); |
| 1597 | } |
| 1598 | |
| 1599 | void Interpreter::visitIntToPtrInst(IntToPtrInst &I) { |
| 1600 | ExecutionContext &SF = ECStack.back(); |
| 1601 | SetValue(&I, executeIntToPtrInst(I.getOperand(0), I.getType(), SF), SF); |
| 1602 | } |
| 1603 | |
| 1604 | void Interpreter::visitBitCastInst(BitCastInst &I) { |
| 1605 | ExecutionContext &SF = ECStack.back(); |
| 1606 | SetValue(&I, executeBitCastInst(I.getOperand(0), I.getType(), SF), SF); |
Chris Lattner | a34c568 | 2002-08-27 22:33:45 +0000 | [diff] [blame] | 1607 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1608 | |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1609 | #define IMPLEMENT_VAARG(TY) \ |
| 1610 | case Type::TY##TyID: Dest.TY##Val = Src.TY##Val; break |
| 1611 | |
| 1612 | void Interpreter::visitVAArgInst(VAArgInst &I) { |
| 1613 | ExecutionContext &SF = ECStack.back(); |
| 1614 | |
Brian Gaeke | 9d20b71 | 2004-02-25 23:01:48 +0000 | [diff] [blame] | 1615 | // Get the incoming valist parameter. LLI treats the valist as a |
| 1616 | // (ec-stack-depth var-arg-index) pair. |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1617 | GenericValue VAList = getOperandValue(I.getOperand(0), SF); |
Brian Gaeke | 9d20b71 | 2004-02-25 23:01:48 +0000 | [diff] [blame] | 1618 | GenericValue Dest; |
| 1619 | GenericValue Src = ECStack[VAList.UIntPairVal.first] |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1620 | .VarArgs[VAList.UIntPairVal.second]; |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1621 | const Type *Ty = I.getType(); |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 1622 | switch (Ty->getTypeID()) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1623 | case Type::IntegerTyID: { |
| 1624 | unsigned BitWidth = cast<IntegerType>(Ty)->getBitWidth(); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1625 | if (BitWidth == 1) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1626 | Dest.Int1Val = Src.Int1Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1627 | maskToBitWidth(Dest, BitWidth); |
| 1628 | } else if (BitWidth <= 8) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1629 | Dest.Int8Val = Src.Int8Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1630 | maskToBitWidth(Dest, BitWidth); |
| 1631 | } else if (BitWidth <= 16) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1632 | Dest.Int16Val = Src.Int16Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1633 | maskToBitWidth(Dest, BitWidth); |
| 1634 | } else if (BitWidth <= 32) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1635 | Dest.Int32Val = Src.Int32Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1636 | maskToBitWidth(Dest, BitWidth); |
| 1637 | } else if (BitWidth <= 64) { |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1638 | Dest.Int64Val = Src.Int64Val; |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1639 | maskToBitWidth(Dest, BitWidth); |
| 1640 | } else { |
| 1641 | *(Dest.APIntVal) = *(Src.APIntVal); |
| 1642 | } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1643 | } |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1644 | IMPLEMENT_VAARG(Pointer); |
| 1645 | IMPLEMENT_VAARG(Float); |
| 1646 | IMPLEMENT_VAARG(Double); |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1647 | default: |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 1648 | cerr << "Unhandled dest type for vaarg instruction: " << *Ty << "\n"; |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1649 | abort(); |
| 1650 | } |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1651 | |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1652 | // Set the Value of this Instruction. |
| 1653 | SetValue(&I, Dest, SF); |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 1654 | |
| 1655 | // Move the pointer to the next vararg. |
| 1656 | ++VAList.UIntPairVal.second; |
Brian Gaeke | c1a2be1 | 2003-11-07 21:20:47 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1659 | GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE, |
| 1660 | ExecutionContext &SF) { |
| 1661 | switch (CE->getOpcode()) { |
| 1662 | case Instruction::Trunc: |
| 1663 | return executeTruncInst(CE->getOperand(0), CE->getType(), SF); |
| 1664 | case Instruction::ZExt: |
| 1665 | return executeZExtInst(CE->getOperand(0), CE->getType(), SF); |
| 1666 | case Instruction::SExt: |
| 1667 | return executeSExtInst(CE->getOperand(0), CE->getType(), SF); |
| 1668 | case Instruction::FPTrunc: |
| 1669 | return executeFPTruncInst(CE->getOperand(0), CE->getType(), SF); |
| 1670 | case Instruction::FPExt: |
| 1671 | return executeFPExtInst(CE->getOperand(0), CE->getType(), SF); |
| 1672 | case Instruction::UIToFP: |
| 1673 | return executeUIToFPInst(CE->getOperand(0), CE->getType(), SF); |
| 1674 | case Instruction::SIToFP: |
| 1675 | return executeSIToFPInst(CE->getOperand(0), CE->getType(), SF); |
| 1676 | case Instruction::FPToUI: |
| 1677 | return executeFPToUIInst(CE->getOperand(0), CE->getType(), SF); |
| 1678 | case Instruction::FPToSI: |
| 1679 | return executeFPToSIInst(CE->getOperand(0), CE->getType(), SF); |
| 1680 | case Instruction::PtrToInt: |
| 1681 | return executePtrToIntInst(CE->getOperand(0), CE->getType(), SF); |
| 1682 | case Instruction::IntToPtr: |
| 1683 | return executeIntToPtrInst(CE->getOperand(0), CE->getType(), SF); |
| 1684 | case Instruction::BitCast: |
| 1685 | return executeBitCastInst(CE->getOperand(0), CE->getType(), SF); |
| 1686 | case Instruction::GetElementPtr: |
| 1687 | return executeGEPOperation(CE->getOperand(0), gep_type_begin(CE), |
| 1688 | gep_type_end(CE), SF); |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1689 | case Instruction::FCmp: |
| 1690 | case Instruction::ICmp: |
| 1691 | return executeCmpInst(CE->getPredicate(), |
| 1692 | getOperandValue(CE->getOperand(0), SF), |
| 1693 | getOperandValue(CE->getOperand(1), SF), |
| 1694 | CE->getOperand(0)->getType()); |
| 1695 | case Instruction::Select: |
| 1696 | return executeSelectInst(getOperandValue(CE->getOperand(0), SF), |
| 1697 | getOperandValue(CE->getOperand(1), SF), |
| 1698 | getOperandValue(CE->getOperand(2), SF)); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1699 | default : |
| 1700 | break; |
| 1701 | } |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1702 | |
| 1703 | // The cases below here require a GenericValue parameter for the result |
| 1704 | // so we initialize one, compute it and then return it. |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1705 | GenericValue Dest; |
| 1706 | initializeAPInt(Dest, CE->getType(), SF); |
| 1707 | switch (CE->getOpcode()) { |
| 1708 | case Instruction::Add: |
| 1709 | executeAddInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1710 | getOperandValue(CE->getOperand(1), SF), |
| 1711 | CE->getOperand(0)->getType()); |
| 1712 | case Instruction::Sub: |
| 1713 | executeSubInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1714 | getOperandValue(CE->getOperand(1), SF), |
| 1715 | CE->getOperand(0)->getType()); |
| 1716 | case Instruction::Mul: |
| 1717 | executeMulInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1718 | getOperandValue(CE->getOperand(1), SF), |
| 1719 | CE->getOperand(0)->getType()); |
| 1720 | case Instruction::SDiv: |
| 1721 | executeSDivInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1722 | getOperandValue(CE->getOperand(1), SF), |
| 1723 | CE->getOperand(0)->getType()); |
| 1724 | case Instruction::UDiv: |
| 1725 | executeUDivInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1726 | getOperandValue(CE->getOperand(1), SF), |
| 1727 | CE->getOperand(0)->getType()); |
| 1728 | case Instruction::FDiv: |
| 1729 | executeFDivInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1730 | getOperandValue(CE->getOperand(1), SF), |
| 1731 | CE->getOperand(0)->getType()); |
| 1732 | case Instruction::URem: |
| 1733 | executeURemInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1734 | getOperandValue(CE->getOperand(1), SF), |
| 1735 | CE->getOperand(0)->getType()); |
| 1736 | case Instruction::SRem: |
| 1737 | executeSRemInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1738 | getOperandValue(CE->getOperand(1), SF), |
| 1739 | CE->getOperand(0)->getType()); |
| 1740 | case Instruction::FRem: |
| 1741 | executeFRemInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1742 | getOperandValue(CE->getOperand(1), SF), |
| 1743 | CE->getOperand(0)->getType()); |
| 1744 | case Instruction::And: |
| 1745 | executeAndInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1746 | getOperandValue(CE->getOperand(1), SF), |
| 1747 | CE->getOperand(0)->getType()); |
| 1748 | case Instruction::Or: |
| 1749 | executeOrInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1750 | getOperandValue(CE->getOperand(1), SF), |
| 1751 | CE->getOperand(0)->getType()); |
| 1752 | case Instruction::Xor: |
| 1753 | executeXorInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1754 | getOperandValue(CE->getOperand(1), SF), |
| 1755 | CE->getOperand(0)->getType()); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1756 | case Instruction::Shl: |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1757 | executeShlInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1758 | getOperandValue(CE->getOperand(1), SF), |
| 1759 | CE->getOperand(0)->getType()); |
| 1760 | case Instruction::LShr: |
| 1761 | executeLShrInst(Dest, getOperandValue(CE->getOperand(0), SF), |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1762 | getOperandValue(CE->getOperand(1), SF), |
| 1763 | CE->getOperand(0)->getType()); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1764 | case Instruction::AShr: |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1765 | executeAShrInst(Dest, getOperandValue(CE->getOperand(0), SF), |
| 1766 | getOperandValue(CE->getOperand(1), SF), |
| 1767 | CE->getOperand(0)->getType()); |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1768 | default: |
| 1769 | cerr << "Unhandled ConstantExpr: " << *CE << "\n"; |
| 1770 | abort(); |
| 1771 | return GenericValue(); |
| 1772 | } |
Reid Spencer | e092936 | 2007-03-03 08:38:04 +0000 | [diff] [blame] | 1773 | return Dest; |
Reid Spencer | e1aa066 | 2007-03-03 06:22:22 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | GenericValue Interpreter::getOperandValue(Value *V, ExecutionContext &SF) { |
| 1777 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
| 1778 | return getConstantExprValue(CE, SF); |
| 1779 | } else if (Constant *CPV = dyn_cast<Constant>(V)) { |
| 1780 | return getConstantValue(CPV); |
| 1781 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) { |
| 1782 | return PTOGV(getPointerToGlobal(GV)); |
| 1783 | } else { |
| 1784 | return SF.Values[V]; |
| 1785 | } |
| 1786 | } |
| 1787 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1788 | //===----------------------------------------------------------------------===// |
| 1789 | // Dispatch and Execution Code |
| 1790 | //===----------------------------------------------------------------------===// |
| 1791 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1792 | //===----------------------------------------------------------------------===// |
Chris Lattner | da82ed5 | 2003-05-08 16:18:31 +0000 | [diff] [blame] | 1793 | // callFunction - Execute the specified function... |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1794 | // |
Chris Lattner | da82ed5 | 2003-05-08 16:18:31 +0000 | [diff] [blame] | 1795 | void Interpreter::callFunction(Function *F, |
| 1796 | const std::vector<GenericValue> &ArgVals) { |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1797 | assert((ECStack.empty() || ECStack.back().Caller.getInstruction() == 0 || |
| 1798 | ECStack.back().Caller.arg_size() == ArgVals.size()) && |
| 1799 | "Incorrect number of arguments passed into function call!"); |
Chris Lattner | 63bd613 | 2003-09-17 17:26:22 +0000 | [diff] [blame] | 1800 | // Make a new stack frame... and fill it in. |
| 1801 | ECStack.push_back(ExecutionContext()); |
| 1802 | ExecutionContext &StackFrame = ECStack.back(); |
Chris Lattner | da82ed5 | 2003-05-08 16:18:31 +0000 | [diff] [blame] | 1803 | StackFrame.CurFunction = F; |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 1804 | |
| 1805 | // Special handling for external functions. |
Reid Spencer | 5cbf985 | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 1806 | if (F->isDeclaration()) { |
Brian Gaeke | af955ba | 2003-11-07 05:22:49 +0000 | [diff] [blame] | 1807 | GenericValue Result = callExternalFunction (F, ArgVals); |
| 1808 | // Simulate a 'ret' instruction of the appropriate type. |
| 1809 | popStackAndReturnValueToCaller (F->getReturnType (), Result); |
| 1810 | return; |
| 1811 | } |
| 1812 | |
| 1813 | // Get pointers to first LLVM BB & Instruction in function. |
Chris Lattner | cdf5178 | 2003-05-08 16:06:52 +0000 | [diff] [blame] | 1814 | StackFrame.CurBB = F->begin(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1815 | StackFrame.CurInst = StackFrame.CurBB->begin(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1816 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1817 | // Run through the function arguments and initialize their values... |
Chris Lattner | e4d5c44 | 2005-03-15 04:54:21 +0000 | [diff] [blame] | 1818 | assert((ArgVals.size() == F->arg_size() || |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1819 | (ArgVals.size() > F->arg_size() && F->getFunctionType()->isVarArg()))&& |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1820 | "Invalid number of values passed to function invocation!"); |
Chris Lattner | cdf5178 | 2003-05-08 16:06:52 +0000 | [diff] [blame] | 1821 | |
| 1822 | // Handle non-varargs arguments... |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 1823 | unsigned i = 0; |
Chris Lattner | e4d5c44 | 2005-03-15 04:54:21 +0000 | [diff] [blame] | 1824 | for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); AI != E; ++AI, ++i) |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1825 | SetValue(AI, ArgVals[i], StackFrame); |
Chris Lattner | cdf5178 | 2003-05-08 16:06:52 +0000 | [diff] [blame] | 1826 | |
| 1827 | // Handle varargs arguments... |
| 1828 | StackFrame.VarArgs.assign(ArgVals.begin()+i, ArgVals.end()); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1831 | void Interpreter::run() { |
Brian Gaeke | 9ad671d | 2003-09-04 23:15:40 +0000 | [diff] [blame] | 1832 | while (!ECStack.empty()) { |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 1833 | // Interpret a single instruction & increment the "PC". |
| 1834 | ExecutionContext &SF = ECStack.back(); // Current stack frame |
| 1835 | Instruction &I = *SF.CurInst++; // Increment before execute |
Misha Brukman | d1c881a | 2005-04-21 22:43:08 +0000 | [diff] [blame] | 1836 | |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 1837 | // Track the number of dynamic instructions executed. |
| 1838 | ++NumDynamicInsts; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1839 | |
Bill Wendling | 480f093 | 2006-11-27 23:54:50 +0000 | [diff] [blame] | 1840 | DOUT << "About to interpret: " << I; |
Brian Gaeke | 03e43dc | 2003-10-24 19:59:01 +0000 | [diff] [blame] | 1841 | visit(I); // Dispatch to one of the visit* methods... |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1842 | } |
| 1843 | } |