blob: b31639046975b45d8e723d02a33ff67abc5894f5 [file] [log] [blame]
Chris Lattnercf3056d2003-10-13 03:32:08 +00001//===- Expressions.cpp - Expression Analysis Utilities --------------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
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.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner369bbeb2001-07-20 19:17:55 +00009//
10// This file defines a package of expression analysis utilties:
11//
12// ClassifyExpression: Analyze an expression to determine the complexity of the
13// expression, and which other variables it depends on.
14//
15//===----------------------------------------------------------------------===//
16
17#include "llvm/Analysis/Expressions.h"
Chris Lattner968ddc92002-04-08 20:18:09 +000018#include "llvm/ConstantHandling.h"
Chris Lattnere590ff22002-03-26 17:55:33 +000019#include "llvm/Function.h"
Chris Lattner19f31f22001-07-21 19:07:19 +000020
Brian Gaeked0fde302003-11-11 22:41:34 +000021namespace llvm {
22
Chris Lattner69f8ce02001-09-11 04:27:34 +000023ExprType::ExprType(Value *Val) {
Chris Lattner1d87bcf2001-10-01 20:11:19 +000024 if (Val)
Chris Lattnere9bb2df2001-12-03 22:26:30 +000025 if (ConstantInt *CPI = dyn_cast<ConstantInt>(Val)) {
Chris Lattner1d87bcf2001-10-01 20:11:19 +000026 Offset = CPI;
27 Var = 0;
28 ExprTy = Constant;
29 Scale = 0;
30 return;
31 }
32
33 Var = Val; Offset = 0;
34 ExprTy = Var ? Linear : Constant;
Chris Lattner69f8ce02001-09-11 04:27:34 +000035 Scale = 0;
36}
37
Chris Lattnere9bb2df2001-12-03 22:26:30 +000038ExprType::ExprType(const ConstantInt *scale, Value *var,
39 const ConstantInt *offset) {
Chris Lattner50020222001-11-26 18:53:07 +000040 Scale = var ? scale : 0; Var = var; Offset = offset;
Chris Lattner69f8ce02001-09-11 04:27:34 +000041 ExprTy = Scale ? ScaledLinear : (Var ? Linear : Constant);
Chris Lattnerce8a1492002-09-03 01:05:48 +000042 if (Scale && Scale->isNullValue()) { // Simplify 0*Var + const
Chris Lattner69f8ce02001-09-11 04:27:34 +000043 Scale = 0; Var = 0;
44 ExprTy = Constant;
45 }
46}
47
48
49const Type *ExprType::getExprType(const Type *Default) const {
50 if (Offset) return Offset->getType();
51 if (Scale) return Scale->getType();
52 return Var ? Var->getType() : Default;
53}
54
55
56
Chris Lattner19f31f22001-07-21 19:07:19 +000057class DefVal {
Chris Lattnere9bb2df2001-12-03 22:26:30 +000058 const ConstantInt * const Val;
Chris Lattner19f31f22001-07-21 19:07:19 +000059 const Type * const Ty;
60protected:
Chris Lattnere9bb2df2001-12-03 22:26:30 +000061 inline DefVal(const ConstantInt *val, const Type *ty) : Val(val), Ty(ty) {}
Chris Lattner19f31f22001-07-21 19:07:19 +000062public:
63 inline const Type *getType() const { return Ty; }
Chris Lattnere9bb2df2001-12-03 22:26:30 +000064 inline const ConstantInt *getVal() const { return Val; }
65 inline operator const ConstantInt * () const { return Val; }
66 inline const ConstantInt *operator->() const { return Val; }
Chris Lattner19f31f22001-07-21 19:07:19 +000067};
68
69struct DefZero : public DefVal {
Chris Lattnere9bb2df2001-12-03 22:26:30 +000070 inline DefZero(const ConstantInt *val, const Type *ty) : DefVal(val, ty) {}
71 inline DefZero(const ConstantInt *val) : DefVal(val, val->getType()) {}
Chris Lattner19f31f22001-07-21 19:07:19 +000072};
73
74struct DefOne : public DefVal {
Chris Lattnere9bb2df2001-12-03 22:26:30 +000075 inline DefOne(const ConstantInt *val, const Type *ty) : DefVal(val, ty) {}
Chris Lattner19f31f22001-07-21 19:07:19 +000076};
77
Chris Lattner369bbeb2001-07-20 19:17:55 +000078
Chris Lattner9b534262002-03-14 22:35:50 +000079// getUnsignedConstant - Return a constant value of the specified type. If the
80// constant value is not valid for the specified type, return null. This cannot
81// happen for values in the range of 0 to 127.
82//
Chris Lattnere9bb2df2001-12-03 22:26:30 +000083static ConstantInt *getUnsignedConstant(uint64_t V, const Type *Ty) {
Chris Lattner9b625032002-05-06 16:15:30 +000084 if (isa<PointerType>(Ty)) Ty = Type::ULongTy;
Chris Lattner9b534262002-03-14 22:35:50 +000085 if (Ty->isSigned()) {
86 // If this value is not a valid unsigned value for this type, return null!
87 if (V > 127 && ((int64_t)V < 0 ||
88 !ConstantSInt::isValueValidForType(Ty, (int64_t)V)))
89 return 0;
90 return ConstantSInt::get(Ty, V);
91 } else {
92 // If this value is not a valid unsigned value for this type, return null!
93 if (V > 255 && !ConstantUInt::isValueValidForType(Ty, V))
94 return 0;
95 return ConstantUInt::get(Ty, V);
96 }
Chris Lattner369bbeb2001-07-20 19:17:55 +000097}
98
Chris Lattner369bbeb2001-07-20 19:17:55 +000099// Add - Helper function to make later code simpler. Basically it just adds
100// the two constants together, inserts the result into the constant pool, and
101// returns it. Of course life is not simple, and this is no exception. Factors
102// that complicate matters:
103// 1. Either argument may be null. If this is the case, the null argument is
104// treated as either 0 (if DefOne = false) or 1 (if DefOne = true)
105// 2. Types get in the way. We want to do arithmetic operations without
106// regard for the underlying types. It is assumed that the constants are
107// integral constants. The new value takes the type of the left argument.
108// 3. If DefOne is true, a null return value indicates a value of 1, if DefOne
109// is false, a null return value indicates a value of 0.
110//
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000111static const ConstantInt *Add(const ConstantInt *Arg1,
112 const ConstantInt *Arg2, bool DefOne) {
Chris Lattner369bbeb2001-07-20 19:17:55 +0000113 assert(Arg1 && Arg2 && "No null arguments should exist now!");
Chris Lattner19f31f22001-07-21 19:07:19 +0000114 assert(Arg1->getType() == Arg2->getType() && "Types must be compatible!");
Chris Lattner369bbeb2001-07-20 19:17:55 +0000115
116 // Actually perform the computation now!
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000117 Constant *Result = *Arg1 + *Arg2;
Chris Lattner19f31f22001-07-21 19:07:19 +0000118 assert(Result && Result->getType() == Arg1->getType() &&
119 "Couldn't perform addition!");
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000120 ConstantInt *ResultI = cast<ConstantInt>(Result);
Chris Lattner369bbeb2001-07-20 19:17:55 +0000121
122 // Check to see if the result is one of the special cases that we want to
123 // recognize...
Chris Lattner69f8ce02001-09-11 04:27:34 +0000124 if (ResultI->equalsInt(DefOne ? 1 : 0))
125 return 0; // Yes it is, simply return null.
Chris Lattner369bbeb2001-07-20 19:17:55 +0000126
Chris Lattner369bbeb2001-07-20 19:17:55 +0000127 return ResultI;
128}
129
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000130inline const ConstantInt *operator+(const DefZero &L, const DefZero &R) {
Chris Lattner19f31f22001-07-21 19:07:19 +0000131 if (L == 0) return R;
132 if (R == 0) return L;
Chris Lattner8e195e02001-09-07 16:31:04 +0000133 return Add(L, R, false);
Chris Lattner19f31f22001-07-21 19:07:19 +0000134}
Chris Lattner369bbeb2001-07-20 19:17:55 +0000135
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000136inline const ConstantInt *operator+(const DefOne &L, const DefOne &R) {
Chris Lattner19f31f22001-07-21 19:07:19 +0000137 if (L == 0) {
138 if (R == 0)
Chris Lattner69f8ce02001-09-11 04:27:34 +0000139 return getUnsignedConstant(2, L.getType());
Chris Lattner19f31f22001-07-21 19:07:19 +0000140 else
Chris Lattner69f8ce02001-09-11 04:27:34 +0000141 return Add(getUnsignedConstant(1, L.getType()), R, true);
Chris Lattner19f31f22001-07-21 19:07:19 +0000142 } else if (R == 0) {
Chris Lattner69f8ce02001-09-11 04:27:34 +0000143 return Add(L, getUnsignedConstant(1, L.getType()), true);
Chris Lattner19f31f22001-07-21 19:07:19 +0000144 }
Chris Lattner8e195e02001-09-07 16:31:04 +0000145 return Add(L, R, true);
Chris Lattner369bbeb2001-07-20 19:17:55 +0000146}
147
148
Chris Lattner19f31f22001-07-21 19:07:19 +0000149// Mul - Helper function to make later code simpler. Basically it just
Chris Lattner369bbeb2001-07-20 19:17:55 +0000150// multiplies the two constants together, inserts the result into the constant
151// pool, and returns it. Of course life is not simple, and this is no
152// exception. Factors that complicate matters:
153// 1. Either argument may be null. If this is the case, the null argument is
154// treated as either 0 (if DefOne = false) or 1 (if DefOne = true)
155// 2. Types get in the way. We want to do arithmetic operations without
156// regard for the underlying types. It is assumed that the constants are
157// integral constants.
158// 3. If DefOne is true, a null return value indicates a value of 1, if DefOne
159// is false, a null return value indicates a value of 0.
160//
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000161inline const ConstantInt *Mul(const ConstantInt *Arg1,
162 const ConstantInt *Arg2, bool DefOne) {
Chris Lattner369bbeb2001-07-20 19:17:55 +0000163 assert(Arg1 && Arg2 && "No null arguments should exist now!");
Chris Lattner19f31f22001-07-21 19:07:19 +0000164 assert(Arg1->getType() == Arg2->getType() && "Types must be compatible!");
Chris Lattner369bbeb2001-07-20 19:17:55 +0000165
166 // Actually perform the computation now!
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000167 Constant *Result = *Arg1 * *Arg2;
Chris Lattner19f31f22001-07-21 19:07:19 +0000168 assert(Result && Result->getType() == Arg1->getType() &&
Chris Lattner50020222001-11-26 18:53:07 +0000169 "Couldn't perform multiplication!");
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000170 ConstantInt *ResultI = cast<ConstantInt>(Result);
Chris Lattner369bbeb2001-07-20 19:17:55 +0000171
172 // Check to see if the result is one of the special cases that we want to
173 // recognize...
Chris Lattner69f8ce02001-09-11 04:27:34 +0000174 if (ResultI->equalsInt(DefOne ? 1 : 0))
175 return 0; // Yes it is, simply return null.
Chris Lattner369bbeb2001-07-20 19:17:55 +0000176
Chris Lattner369bbeb2001-07-20 19:17:55 +0000177 return ResultI;
178}
179
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000180inline const ConstantInt *operator*(const DefZero &L, const DefZero &R) {
Chris Lattner19f31f22001-07-21 19:07:19 +0000181 if (L == 0 || R == 0) return 0;
Chris Lattner8e195e02001-09-07 16:31:04 +0000182 return Mul(L, R, false);
Chris Lattner19f31f22001-07-21 19:07:19 +0000183}
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000184inline const ConstantInt *operator*(const DefOne &L, const DefZero &R) {
Chris Lattner69f8ce02001-09-11 04:27:34 +0000185 if (R == 0) return getUnsignedConstant(0, L.getType());
Chris Lattner19f31f22001-07-21 19:07:19 +0000186 if (L == 0) return R->equalsInt(1) ? 0 : R.getVal();
Chris Lattner50020222001-11-26 18:53:07 +0000187 return Mul(L, R, true);
Chris Lattner19f31f22001-07-21 19:07:19 +0000188}
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000189inline const ConstantInt *operator*(const DefZero &L, const DefOne &R) {
Chris Lattner50020222001-11-26 18:53:07 +0000190 if (L == 0 || R == 0) return L.getVal();
191 return Mul(R, L, false);
Chris Lattner19f31f22001-07-21 19:07:19 +0000192}
193
Chris Lattner69f8ce02001-09-11 04:27:34 +0000194// handleAddition - Add two expressions together, creating a new expression that
195// represents the composite of the two...
196//
197static ExprType handleAddition(ExprType Left, ExprType Right, Value *V) {
198 const Type *Ty = V->getType();
199 if (Left.ExprTy > Right.ExprTy)
Chris Lattner697954c2002-01-20 22:54:45 +0000200 std::swap(Left, Right); // Make left be simpler than right
Chris Lattner69f8ce02001-09-11 04:27:34 +0000201
202 switch (Left.ExprTy) {
203 case ExprType::Constant:
Chris Lattner50020222001-11-26 18:53:07 +0000204 return ExprType(Right.Scale, Right.Var,
205 DefZero(Right.Offset, Ty) + DefZero(Left.Offset, Ty));
Chris Lattner69f8ce02001-09-11 04:27:34 +0000206 case ExprType::Linear: // RHS side must be linear or scaled
207 case ExprType::ScaledLinear: // RHS must be scaled
208 if (Left.Var != Right.Var) // Are they the same variables?
Chris Lattner50020222001-11-26 18:53:07 +0000209 return V; // if not, we don't know anything!
Chris Lattner69f8ce02001-09-11 04:27:34 +0000210
211 return ExprType(DefOne(Left.Scale , Ty) + DefOne(Right.Scale , Ty),
Chris Lattner50020222001-11-26 18:53:07 +0000212 Right.Var,
Chris Lattner69f8ce02001-09-11 04:27:34 +0000213 DefZero(Left.Offset, Ty) + DefZero(Right.Offset, Ty));
214 default:
215 assert(0 && "Dont' know how to handle this case!");
216 return ExprType();
217 }
218}
219
220// negate - Negate the value of the specified expression...
221//
222static inline ExprType negate(const ExprType &E, Value *V) {
223 const Type *Ty = V->getType();
Chris Lattnercb05e782002-03-11 20:50:24 +0000224 ConstantInt *Zero = getUnsignedConstant(0, Ty);
225 ConstantInt *One = getUnsignedConstant(1, Ty);
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000226 ConstantInt *NegOne = cast<ConstantInt>(*Zero - *One);
Chris Lattner69f8ce02001-09-11 04:27:34 +0000227 if (NegOne == 0) return V; // Couldn't subtract values...
228
229 return ExprType(DefOne (E.Scale , Ty) * NegOne, E.Var,
230 DefZero(E.Offset, Ty) * NegOne);
231}
Chris Lattner19f31f22001-07-21 19:07:19 +0000232
Chris Lattner369bbeb2001-07-20 19:17:55 +0000233
234// ClassifyExpression: Analyze an expression to determine the complexity of the
235// expression, and which other values it depends on.
236//
237// Note that this analysis cannot get into infinite loops because it treats PHI
238// nodes as being an unknown linear expression.
239//
Chris Lattnerc74cb862002-08-30 22:53:53 +0000240ExprType ClassifyExpression(Value *Expr) {
Chris Lattner369bbeb2001-07-20 19:17:55 +0000241 assert(Expr != 0 && "Can't classify a null expression!");
Chris Lattner0da29c82001-12-05 19:38:29 +0000242 if (Expr->getType() == Type::FloatTy || Expr->getType() == Type::DoubleTy)
243 return Expr; // FIXME: Can't handle FP expressions
244
Chris Lattner369bbeb2001-07-20 19:17:55 +0000245 switch (Expr->getValueType()) {
246 case Value::InstructionVal: break; // Instruction... hmmm... investigate.
247 case Value::TypeVal: case Value::BasicBlockVal:
Chris Lattner96d0f302002-04-28 04:50:00 +0000248 case Value::FunctionVal: default:
Chris Lattner481fafe2001-12-13 00:45:06 +0000249 //assert(0 && "Unexpected expression type to classify!");
Chris Lattner697954c2002-01-20 22:54:45 +0000250 std::cerr << "Bizarre thing to expr classify: " << Expr << "\n";
Chris Lattner481fafe2001-12-13 00:45:06 +0000251 return Expr;
Chris Lattnere590ff22002-03-26 17:55:33 +0000252 case Value::GlobalVariableVal: // Global Variable & Function argument:
Chris Lattner73e21422002-04-09 19:48:49 +0000253 case Value::ArgumentVal: // nothing known, return variable itself
Chris Lattner369bbeb2001-07-20 19:17:55 +0000254 return Expr;
255 case Value::ConstantVal: // Constant value, just return constant
Chris Lattnerac7ad682003-04-16 22:50:19 +0000256 if (ConstantInt *CPI = dyn_cast<ConstantInt>(cast<Constant>(Expr)))
257 // It's an integral constant!
Chris Lattnerce8a1492002-09-03 01:05:48 +0000258 return ExprType(CPI->isNullValue() ? 0 : CPI);
Chris Lattner369bbeb2001-07-20 19:17:55 +0000259 return Expr;
260 }
261
Chris Lattner9636a912001-10-01 16:18:37 +0000262 Instruction *I = cast<Instruction>(Expr);
Chris Lattner19f31f22001-07-21 19:07:19 +0000263 const Type *Ty = I->getType();
Chris Lattner369bbeb2001-07-20 19:17:55 +0000264
Misha Brukman1ba31382003-07-14 17:26:34 +0000265 switch (I->getOpcode()) { // Handle each instruction type separately
Chris Lattner369bbeb2001-07-20 19:17:55 +0000266 case Instruction::Add: {
Chris Lattner19f31f22001-07-21 19:07:19 +0000267 ExprType Left (ClassifyExpression(I->getOperand(0)));
268 ExprType Right(ClassifyExpression(I->getOperand(1)));
Chris Lattner69f8ce02001-09-11 04:27:34 +0000269 return handleAddition(Left, Right, I);
Chris Lattner369bbeb2001-07-20 19:17:55 +0000270 } // end case Instruction::Add
271
Chris Lattner69f8ce02001-09-11 04:27:34 +0000272 case Instruction::Sub: {
273 ExprType Left (ClassifyExpression(I->getOperand(0)));
274 ExprType Right(ClassifyExpression(I->getOperand(1)));
Chris Lattner50020222001-11-26 18:53:07 +0000275 ExprType RightNeg = negate(Right, I);
276 if (RightNeg.Var == I && !RightNeg.Offset && !RightNeg.Scale)
277 return I; // Could not negate value...
278 return handleAddition(Left, RightNeg, I);
Chris Lattner69f8ce02001-09-11 04:27:34 +0000279 } // end case Instruction::Sub
280
Chris Lattner369bbeb2001-07-20 19:17:55 +0000281 case Instruction::Shl: {
Chris Lattner19f31f22001-07-21 19:07:19 +0000282 ExprType Right(ClassifyExpression(I->getOperand(1)));
283 if (Right.ExprTy != ExprType::Constant) break;
284 ExprType Left(ClassifyExpression(I->getOperand(0)));
285 if (Right.Offset == 0) return Left; // shl x, 0 = x
286 assert(Right.Offset->getType() == Type::UByteTy &&
Chris Lattner369bbeb2001-07-20 19:17:55 +0000287 "Shift amount must always be a unsigned byte!");
Chris Lattner28a128e2003-07-23 15:16:40 +0000288 uint64_t ShiftAmount = cast<ConstantUInt>(Right.Offset)->getValue();
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000289 ConstantInt *Multiplier = getUnsignedConstant(1ULL << ShiftAmount, Ty);
Chris Lattner9b534262002-03-14 22:35:50 +0000290
291 // We don't know how to classify it if they are shifting by more than what
292 // is reasonable. In most cases, the result will be zero, but there is one
293 // class of cases where it is not, so we cannot optimize without checking
294 // for it. The case is when you are shifting a signed value by 1 less than
295 // the number of bits in the value. For example:
296 // %X = shl sbyte %Y, ubyte 7
297 // will try to form an sbyte multiplier of 128, which will give a null
298 // multiplier, even though the result is not 0. Until we can check for this
299 // case, be conservative. TODO.
300 //
301 if (Multiplier == 0)
302 return Expr;
303
Chris Lattner8e195e02001-09-07 16:31:04 +0000304 return ExprType(DefOne(Left.Scale, Ty) * Multiplier, Left.Var,
305 DefZero(Left.Offset, Ty) * Multiplier);
Chris Lattner369bbeb2001-07-20 19:17:55 +0000306 } // end case Instruction::Shl
307
Chris Lattner19f31f22001-07-21 19:07:19 +0000308 case Instruction::Mul: {
309 ExprType Left (ClassifyExpression(I->getOperand(0)));
310 ExprType Right(ClassifyExpression(I->getOperand(1)));
311 if (Left.ExprTy > Right.ExprTy)
Chris Lattner697954c2002-01-20 22:54:45 +0000312 std::swap(Left, Right); // Make left be simpler than right
Chris Lattner19f31f22001-07-21 19:07:19 +0000313
314 if (Left.ExprTy != ExprType::Constant) // RHS must be > constant
315 return I; // Quadratic eqn! :(
316
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000317 const ConstantInt *Offs = Left.Offset;
Chris Lattner19f31f22001-07-21 19:07:19 +0000318 if (Offs == 0) return ExprType();
Chris Lattner8e195e02001-09-07 16:31:04 +0000319 return ExprType( DefOne(Right.Scale , Ty) * Offs, Right.Var,
320 DefZero(Right.Offset, Ty) * Offs);
Chris Lattner19f31f22001-07-21 19:07:19 +0000321 } // end case Instruction::Mul
322
323 case Instruction::Cast: {
324 ExprType Src(ClassifyExpression(I->getOperand(0)));
Chris Lattner69f8ce02001-09-11 04:27:34 +0000325 const Type *DestTy = I->getType();
Chris Lattner9b625032002-05-06 16:15:30 +0000326 if (isa<PointerType>(DestTy))
Chris Lattner69f8ce02001-09-11 04:27:34 +0000327 DestTy = Type::ULongTy; // Pointer types are represented as ulong
Chris Lattner19f31f22001-07-21 19:07:19 +0000328
Chris Lattner5fd60912003-07-01 21:08:52 +0000329 const Type *SrcValTy = Src.getExprType(0);
330 if (!SrcValTy) return I;
331 if (!SrcValTy->isLosslesslyConvertibleTo(DestTy)) {
Chris Lattner882572a2001-11-26 16:53:50 +0000332 if (Src.ExprTy != ExprType::Constant)
333 return I; // Converting cast, and not a constant value...
334 }
Chris Lattner19f31f22001-07-21 19:07:19 +0000335
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000336 const ConstantInt *Offset = Src.Offset;
337 const ConstantInt *Scale = Src.Scale;
Chris Lattner882572a2001-11-26 16:53:50 +0000338 if (Offset) {
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000339 const Constant *CPV = ConstantFoldCastInstruction(Offset, DestTy);
Chris Lattner882572a2001-11-26 16:53:50 +0000340 if (!CPV) return I;
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000341 Offset = cast<ConstantInt>(CPV);
Chris Lattner882572a2001-11-26 16:53:50 +0000342 }
343 if (Scale) {
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000344 const Constant *CPV = ConstantFoldCastInstruction(Scale, DestTy);
Chris Lattner882572a2001-11-26 16:53:50 +0000345 if (!CPV) return I;
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000346 Scale = cast<ConstantInt>(CPV);
Chris Lattner882572a2001-11-26 16:53:50 +0000347 }
348 return ExprType(Scale, Src.Var, Offset);
Chris Lattner19f31f22001-07-21 19:07:19 +0000349 } // end case Instruction::Cast
Chris Lattner793d6782001-07-25 22:47:32 +0000350 // TODO: Handle SUB, SHR?
Chris Lattner369bbeb2001-07-20 19:17:55 +0000351
352 } // end switch
353
354 // Otherwise, I don't know anything about this value!
Chris Lattner19f31f22001-07-21 19:07:19 +0000355 return I;
Chris Lattner369bbeb2001-07-20 19:17:55 +0000356}
Brian Gaeked0fde302003-11-11 22:41:34 +0000357
358} // End llvm namespace