1 //===- ConstantHandling.cpp - Implement ConstantHandling.h ----------------===//
3 // This file implements the various intrinsic operations, on constant values.
5 //===----------------------------------------------------------------------===//
7 #include "llvm/ConstantHandling.h"
8 #include "llvm/iPHINode.h"
9 #include "llvm/InstrTypes.h"
10 #include "llvm/DerivedTypes.h"
13 AnnotationID ConstRules::AID(AnnotationManager::getID("opt::ConstRules",
16 // ConstantFoldInstruction - Attempt to constant fold the specified instruction.
17 // If successful, the constant result is returned, if not, null is returned.
19 Constant *ConstantFoldInstruction(Instruction *I) {
20 if (PHINode *PN = dyn_cast<PHINode>(I)) {
21 if (PN->getNumIncomingValues() == 0)
22 return Constant::getNullValue(PN->getType());
24 Constant *Result = dyn_cast<Constant>(PN->getIncomingValue(0));
25 if (Result == 0) return 0;
27 // Handle PHI nodes specially here...
28 for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i)
29 if (PN->getIncomingValue(i) != Result)
30 return 0; // Not all the same incoming constants...
32 // If we reach here, all incoming values are the same constant.
39 if (I->getNumOperands() != 0) { // Get first operand if it's a constant...
40 Op0 = dyn_cast<Constant>(I->getOperand(0));
41 if (Op0 == 0) return 0; // Not a constant?, can't fold
43 if (I->getNumOperands() != 1) { // Get second operand if it's a constant...
44 Op1 = dyn_cast<Constant>(I->getOperand(1));
45 if (Op1 == 0) return 0; // Not a constant?, can't fold
49 if (isa<BinaryOperator>(I))
50 return ConstantExpr::get(I->getOpcode(), Op0, Op1);
52 switch (I->getOpcode()) {
53 case Instruction::Cast:
54 return ConstantExpr::getCast(Op0, I->getType());
55 case Instruction::Shl:
56 case Instruction::Shr:
57 return ConstantExpr::getShift(I->getOpcode(), Op0, Op1);
58 case Instruction::GetElementPtr: {
59 std::vector<Constant*> IdxList;
60 IdxList.reserve(I->getNumOperands()-1);
61 if (Op1) IdxList.push_back(Op1);
62 for (unsigned i = 2, e = I->getNumOperands(); i != e; ++i)
63 if (Constant *C = dyn_cast<Constant>(I->getOperand(i)))
66 return 0; // Non-constant operand
67 return ConstantExpr::getGetElementPtr(Op0, IdxList);
74 static unsigned getSize(const Type *Ty) {
75 unsigned S = Ty->getPrimitiveSize();
76 return S ? S : 8; // Treat pointers at 8 bytes
79 Constant *ConstantFoldCastInstruction(const Constant *V, const Type *DestTy) {
80 if (V->getType() == DestTy) return (Constant*)V;
82 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
83 if (CE->getOpcode() == Instruction::Cast) {
84 Constant *Op = const_cast<Constant*>(CE->getOperand(0));
85 // Try to not produce a cast of a cast, which is almost always redundant.
86 if (!Op->getType()->isFloatingPoint() &&
87 !CE->getType()->isFloatingPoint() &&
88 !DestTy->getType()->isFloatingPoint()) {
89 unsigned S1 = getSize(Op->getType()), S2 = getSize(CE->getType());
90 unsigned S3 = getSize(DestTy);
91 if (Op->getType() == DestTy && S3 >= S2)
93 if (S1 >= S2 && S2 >= S3)
94 return ConstantExpr::getCast(Op, DestTy);
95 if (S1 <= S2 && S2 >= S3 && S1 <= S3)
96 return ConstantExpr::getCast(Op, DestTy);
100 return ConstRules::get(*V, *V)->castTo(V, DestTy);
103 Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
104 const Constant *V2) {
106 case Instruction::Add: return *V1 + *V2;
107 case Instruction::Sub: return *V1 - *V2;
108 case Instruction::Mul: return *V1 * *V2;
109 case Instruction::Div: return *V1 / *V2;
110 case Instruction::Rem: return *V1 % *V2;
111 case Instruction::And: return *V1 & *V2;
112 case Instruction::Or: return *V1 | *V2;
113 case Instruction::Xor: return *V1 ^ *V2;
115 case Instruction::SetEQ: return *V1 == *V2;
116 case Instruction::SetNE: return *V1 != *V2;
117 case Instruction::SetLE: return *V1 <= *V2;
118 case Instruction::SetGE: return *V1 >= *V2;
119 case Instruction::SetLT: return *V1 < *V2;
120 case Instruction::SetGT: return *V1 > *V2;
125 Constant *ConstantFoldShiftInstruction(unsigned Opcode, const Constant *V1,
126 const Constant *V2) {
128 case Instruction::Shl: return *V1 << *V2;
129 case Instruction::Shr: return *V1 >> *V2;
134 Constant *ConstantFoldGetElementPtr(const Constant *C,
135 const std::vector<Constant*> &IdxList) {
136 if (IdxList.size() == 0 ||
137 (IdxList.size() == 1 && IdxList[0]->isNullValue()))
138 return const_cast<Constant*>(C);
140 // If C is null and all idx's are null, return null of the right type.
142 // FIXME: Implement folding of GEP constant exprs the same as instcombine does
144 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
145 // Implement folding of:
146 // void ()** getelementptr (%struct..TorRec* getelementptr
147 // ([N x %struct..TorRec]* %llvm.global_dtors, long 0, long 0),
150 // %struct..TorRec* getelementptr ([N x %struct..TorRec]*
151 // %llvm.global_dtors, long 0, long 0, ubyte 1)
153 if (CE->getOpcode() == Instruction::GetElementPtr)
154 if (IdxList[0] == Constant::getNullValue(Type::LongTy)) {
155 std::vector<Constant*> NewIndices;
156 NewIndices.reserve(IdxList.size() + CE->getNumOperands());
157 for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
158 NewIndices.push_back(cast<Constant>(CE->getOperand(i)));
159 NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());
160 return ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices);
163 // Implement folding of:
164 // int* getelementptr ([2 x int]* cast ([3 x int]* %X to [2 x int]*),
166 // To: int* getelementptr ([3 x int]* %X, long 0, long 0)
168 if (CE->getOpcode() == Instruction::Cast && IdxList.size() > 1 &&
169 IdxList[0]->isNullValue())
170 if (const PointerType *SPT =
171 dyn_cast<PointerType>(CE->getOperand(0)->getType()))
172 if (const ArrayType *SAT = dyn_cast<ArrayType>(SPT->getElementType()))
173 if (const ArrayType *CAT =
174 dyn_cast<ArrayType>(cast<PointerType>(C->getType())->getElementType()))
175 if (CAT->getElementType() == SAT->getElementType())
176 return ConstantExpr::getGetElementPtr(
177 (Constant*)CE->getOperand(0), IdxList);
183 //===----------------------------------------------------------------------===//
184 // TemplateRules Class
185 //===----------------------------------------------------------------------===//
187 // TemplateRules - Implement a subclass of ConstRules that provides all
188 // operations as noops. All other rules classes inherit from this class so
189 // that if functionality is needed in the future, it can simply be added here
190 // and to ConstRules without changing anything else...
192 // This class also provides subclasses with typesafe implementations of methods
193 // so that don't have to do type casting.
195 template<class ArgType, class SubClassName>
196 class TemplateRules : public ConstRules {
198 //===--------------------------------------------------------------------===//
199 // Redirecting functions that cast to the appropriate types
200 //===--------------------------------------------------------------------===//
202 virtual Constant *add(const Constant *V1, const Constant *V2) const {
203 return SubClassName::Add((const ArgType *)V1, (const ArgType *)V2);
205 virtual Constant *sub(const Constant *V1, const Constant *V2) const {
206 return SubClassName::Sub((const ArgType *)V1, (const ArgType *)V2);
208 virtual Constant *mul(const Constant *V1, const Constant *V2) const {
209 return SubClassName::Mul((const ArgType *)V1, (const ArgType *)V2);
211 virtual Constant *div(const Constant *V1, const Constant *V2) const {
212 return SubClassName::Div((const ArgType *)V1, (const ArgType *)V2);
214 virtual Constant *rem(const Constant *V1, const Constant *V2) const {
215 return SubClassName::Rem((const ArgType *)V1, (const ArgType *)V2);
217 virtual Constant *op_and(const Constant *V1, const Constant *V2) const {
218 return SubClassName::And((const ArgType *)V1, (const ArgType *)V2);
220 virtual Constant *op_or(const Constant *V1, const Constant *V2) const {
221 return SubClassName::Or((const ArgType *)V1, (const ArgType *)V2);
223 virtual Constant *op_xor(const Constant *V1, const Constant *V2) const {
224 return SubClassName::Xor((const ArgType *)V1, (const ArgType *)V2);
226 virtual Constant *shl(const Constant *V1, const Constant *V2) const {
227 return SubClassName::Shl((const ArgType *)V1, (const ArgType *)V2);
229 virtual Constant *shr(const Constant *V1, const Constant *V2) const {
230 return SubClassName::Shr((const ArgType *)V1, (const ArgType *)V2);
233 virtual ConstantBool *lessthan(const Constant *V1,
234 const Constant *V2) const {
235 return SubClassName::LessThan((const ArgType *)V1, (const ArgType *)V2);
238 // Casting operators. ick
239 virtual ConstantBool *castToBool(const Constant *V) const {
240 return SubClassName::CastToBool((const ArgType*)V);
242 virtual ConstantSInt *castToSByte(const Constant *V) const {
243 return SubClassName::CastToSByte((const ArgType*)V);
245 virtual ConstantUInt *castToUByte(const Constant *V) const {
246 return SubClassName::CastToUByte((const ArgType*)V);
248 virtual ConstantSInt *castToShort(const Constant *V) const {
249 return SubClassName::CastToShort((const ArgType*)V);
251 virtual ConstantUInt *castToUShort(const Constant *V) const {
252 return SubClassName::CastToUShort((const ArgType*)V);
254 virtual ConstantSInt *castToInt(const Constant *V) const {
255 return SubClassName::CastToInt((const ArgType*)V);
257 virtual ConstantUInt *castToUInt(const Constant *V) const {
258 return SubClassName::CastToUInt((const ArgType*)V);
260 virtual ConstantSInt *castToLong(const Constant *V) const {
261 return SubClassName::CastToLong((const ArgType*)V);
263 virtual ConstantUInt *castToULong(const Constant *V) const {
264 return SubClassName::CastToULong((const ArgType*)V);
266 virtual ConstantFP *castToFloat(const Constant *V) const {
267 return SubClassName::CastToFloat((const ArgType*)V);
269 virtual ConstantFP *castToDouble(const Constant *V) const {
270 return SubClassName::CastToDouble((const ArgType*)V);
272 virtual Constant *castToPointer(const Constant *V,
273 const PointerType *Ty) const {
274 return SubClassName::CastToPointer((const ArgType*)V, Ty);
277 //===--------------------------------------------------------------------===//
278 // Default "noop" implementations
279 //===--------------------------------------------------------------------===//
281 static Constant *Add(const ArgType *V1, const ArgType *V2) { return 0; }
282 static Constant *Sub(const ArgType *V1, const ArgType *V2) { return 0; }
283 static Constant *Mul(const ArgType *V1, const ArgType *V2) { return 0; }
284 static Constant *Div(const ArgType *V1, const ArgType *V2) { return 0; }
285 static Constant *Rem(const ArgType *V1, const ArgType *V2) { return 0; }
286 static Constant *And(const ArgType *V1, const ArgType *V2) { return 0; }
287 static Constant *Or (const ArgType *V1, const ArgType *V2) { return 0; }
288 static Constant *Xor(const ArgType *V1, const ArgType *V2) { return 0; }
289 static Constant *Shl(const ArgType *V1, const ArgType *V2) { return 0; }
290 static Constant *Shr(const ArgType *V1, const ArgType *V2) { return 0; }
291 static ConstantBool *LessThan(const ArgType *V1, const ArgType *V2) {
295 // Casting operators. ick
296 static ConstantBool *CastToBool (const Constant *V) { return 0; }
297 static ConstantSInt *CastToSByte (const Constant *V) { return 0; }
298 static ConstantUInt *CastToUByte (const Constant *V) { return 0; }
299 static ConstantSInt *CastToShort (const Constant *V) { return 0; }
300 static ConstantUInt *CastToUShort(const Constant *V) { return 0; }
301 static ConstantSInt *CastToInt (const Constant *V) { return 0; }
302 static ConstantUInt *CastToUInt (const Constant *V) { return 0; }
303 static ConstantSInt *CastToLong (const Constant *V) { return 0; }
304 static ConstantUInt *CastToULong (const Constant *V) { return 0; }
305 static ConstantFP *CastToFloat (const Constant *V) { return 0; }
306 static ConstantFP *CastToDouble(const Constant *V) { return 0; }
307 static Constant *CastToPointer(const Constant *,
308 const PointerType *) {return 0;}
313 //===----------------------------------------------------------------------===//
315 //===----------------------------------------------------------------------===//
317 // EmptyRules provides a concrete base class of ConstRules that does nothing
319 struct EmptyRules : public TemplateRules<Constant, EmptyRules> {
324 //===----------------------------------------------------------------------===//
326 //===----------------------------------------------------------------------===//
328 // BoolRules provides a concrete base class of ConstRules for the 'bool' type.
330 struct BoolRules : public TemplateRules<ConstantBool, BoolRules> {
332 static ConstantBool *LessThan(const ConstantBool *V1, const ConstantBool *V2){
333 return ConstantBool::get(V1->getValue() < V2->getValue());
336 static Constant *And(const ConstantBool *V1, const ConstantBool *V2) {
337 return ConstantBool::get(V1->getValue() & V2->getValue());
340 static Constant *Or(const ConstantBool *V1, const ConstantBool *V2) {
341 return ConstantBool::get(V1->getValue() | V2->getValue());
344 static Constant *Xor(const ConstantBool *V1, const ConstantBool *V2) {
345 return ConstantBool::get(V1->getValue() ^ V2->getValue());
350 //===----------------------------------------------------------------------===//
351 // PointerRules Class
352 //===----------------------------------------------------------------------===//
354 // PointerRules provides a concrete base class of ConstRules for pointer types
356 struct PointerRules : public TemplateRules<ConstantPointer, PointerRules> {
357 static ConstantBool *CastToBool (const Constant *V) {
358 if (V->isNullValue()) return ConstantBool::False;
359 return 0; // Can't const prop other types of pointers
361 static ConstantSInt *CastToSByte (const Constant *V) {
362 if (V->isNullValue()) return ConstantSInt::get(Type::SByteTy, 0);
363 return 0; // Can't const prop other types of pointers
365 static ConstantUInt *CastToUByte (const Constant *V) {
366 if (V->isNullValue()) return ConstantUInt::get(Type::UByteTy, 0);
367 return 0; // Can't const prop other types of pointers
369 static ConstantSInt *CastToShort (const Constant *V) {
370 if (V->isNullValue()) return ConstantSInt::get(Type::ShortTy, 0);
371 return 0; // Can't const prop other types of pointers
373 static ConstantUInt *CastToUShort(const Constant *V) {
374 if (V->isNullValue()) return ConstantUInt::get(Type::UShortTy, 0);
375 return 0; // Can't const prop other types of pointers
377 static ConstantSInt *CastToInt (const Constant *V) {
378 if (V->isNullValue()) return ConstantSInt::get(Type::IntTy, 0);
379 return 0; // Can't const prop other types of pointers
381 static ConstantUInt *CastToUInt (const Constant *V) {
382 if (V->isNullValue()) return ConstantUInt::get(Type::UIntTy, 0);
383 return 0; // Can't const prop other types of pointers
385 static ConstantSInt *CastToLong (const Constant *V) {
386 if (V->isNullValue()) return ConstantSInt::get(Type::LongTy, 0);
387 return 0; // Can't const prop other types of pointers
389 static ConstantUInt *CastToULong (const Constant *V) {
390 if (V->isNullValue()) return ConstantUInt::get(Type::ULongTy, 0);
391 return 0; // Can't const prop other types of pointers
393 static ConstantFP *CastToFloat (const Constant *V) {
394 if (V->isNullValue()) return ConstantFP::get(Type::FloatTy, 0);
395 return 0; // Can't const prop other types of pointers
397 static ConstantFP *CastToDouble(const Constant *V) {
398 if (V->isNullValue()) return ConstantFP::get(Type::DoubleTy, 0);
399 return 0; // Can't const prop other types of pointers
402 static Constant *CastToPointer(const ConstantPointer *V,
403 const PointerType *PTy) {
404 if (V->getType() == PTy)
405 return const_cast<ConstantPointer*>(V); // Allow cast %PTy %ptr to %PTy
406 if (V->isNullValue())
407 return ConstantPointerNull::get(PTy);
408 return 0; // Can't const prop other types of pointers
413 //===----------------------------------------------------------------------===//
415 //===----------------------------------------------------------------------===//
417 // DirectRules provides a concrete base classes of ConstRules for a variety of
418 // different types. This allows the C++ compiler to automatically generate our
419 // constant handling operations in a typesafe and accurate manner.
421 template<class ConstantClass, class BuiltinType, Type **Ty, class SuperClass>
422 struct DirectRules : public TemplateRules<ConstantClass, SuperClass> {
423 static Constant *Add(const ConstantClass *V1, const ConstantClass *V2) {
424 BuiltinType R = (BuiltinType)V1->getValue() + (BuiltinType)V2->getValue();
425 return ConstantClass::get(*Ty, R);
428 static Constant *Sub(const ConstantClass *V1, const ConstantClass *V2) {
429 BuiltinType R = (BuiltinType)V1->getValue() - (BuiltinType)V2->getValue();
430 return ConstantClass::get(*Ty, R);
433 static Constant *Mul(const ConstantClass *V1, const ConstantClass *V2) {
434 BuiltinType R = (BuiltinType)V1->getValue() * (BuiltinType)V2->getValue();
435 return ConstantClass::get(*Ty, R);
438 static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
439 if (V2->isNullValue()) return 0;
440 BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
441 return ConstantClass::get(*Ty, R);
444 static ConstantBool *LessThan(const ConstantClass *V1,
445 const ConstantClass *V2) {
446 bool R = (BuiltinType)V1->getValue() < (BuiltinType)V2->getValue();
447 return ConstantBool::get(R);
450 static Constant *CastToPointer(const ConstantClass *V,
451 const PointerType *PTy) {
452 if (V->isNullValue()) // Is it a FP or Integral null value?
453 return ConstantPointerNull::get(PTy);
454 return 0; // Can't const prop other types of pointers
457 // Casting operators. ick
458 #define DEF_CAST(TYPE, CLASS, CTYPE) \
459 static CLASS *CastTo##TYPE (const ConstantClass *V) { \
460 return CLASS::get(Type::TYPE##Ty, (CTYPE)(BuiltinType)V->getValue()); \
463 DEF_CAST(Bool , ConstantBool, bool)
464 DEF_CAST(SByte , ConstantSInt, signed char)
465 DEF_CAST(UByte , ConstantUInt, unsigned char)
466 DEF_CAST(Short , ConstantSInt, signed short)
467 DEF_CAST(UShort, ConstantUInt, unsigned short)
468 DEF_CAST(Int , ConstantSInt, signed int)
469 DEF_CAST(UInt , ConstantUInt, unsigned int)
470 DEF_CAST(Long , ConstantSInt, int64_t)
471 DEF_CAST(ULong , ConstantUInt, uint64_t)
472 DEF_CAST(Float , ConstantFP , float)
473 DEF_CAST(Double, ConstantFP , double)
478 //===----------------------------------------------------------------------===//
479 // DirectIntRules Class
480 //===----------------------------------------------------------------------===//
482 // DirectIntRules provides implementations of functions that are valid on
483 // integer types, but not all types in general.
485 template <class ConstantClass, class BuiltinType, Type **Ty>
486 struct DirectIntRules
487 : public DirectRules<ConstantClass, BuiltinType, Ty,
488 DirectIntRules<ConstantClass, BuiltinType, Ty> > {
490 static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
491 if (V2->isNullValue()) return 0;
492 if (V2->isAllOnesValue() && // MIN_INT / -1
493 (BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
495 BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
496 return ConstantClass::get(*Ty, R);
499 static Constant *Rem(const ConstantClass *V1,
500 const ConstantClass *V2) {
501 if (V2->isNullValue()) return 0; // X / 0
502 if (V2->isAllOnesValue() && // MIN_INT / -1
503 (BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
505 BuiltinType R = (BuiltinType)V1->getValue() % (BuiltinType)V2->getValue();
506 return ConstantClass::get(*Ty, R);
509 static Constant *And(const ConstantClass *V1, const ConstantClass *V2) {
510 BuiltinType R = (BuiltinType)V1->getValue() & (BuiltinType)V2->getValue();
511 return ConstantClass::get(*Ty, R);
513 static Constant *Or(const ConstantClass *V1, const ConstantClass *V2) {
514 BuiltinType R = (BuiltinType)V1->getValue() | (BuiltinType)V2->getValue();
515 return ConstantClass::get(*Ty, R);
517 static Constant *Xor(const ConstantClass *V1, const ConstantClass *V2) {
518 BuiltinType R = (BuiltinType)V1->getValue() ^ (BuiltinType)V2->getValue();
519 return ConstantClass::get(*Ty, R);
522 static Constant *Shl(const ConstantClass *V1, const ConstantClass *V2) {
523 BuiltinType R = (BuiltinType)V1->getValue() << (BuiltinType)V2->getValue();
524 return ConstantClass::get(*Ty, R);
527 static Constant *Shr(const ConstantClass *V1, const ConstantClass *V2) {
528 BuiltinType R = (BuiltinType)V1->getValue() >> (BuiltinType)V2->getValue();
529 return ConstantClass::get(*Ty, R);
534 //===----------------------------------------------------------------------===//
535 // DirectFPRules Class
536 //===----------------------------------------------------------------------===//
538 // DirectFPRules provides implementations of functions that are valid on
539 // floating point types, but not all types in general.
541 template <class ConstantClass, class BuiltinType, Type **Ty>
543 : public DirectRules<ConstantClass, BuiltinType, Ty,
544 DirectFPRules<ConstantClass, BuiltinType, Ty> > {
545 static Constant *Rem(const ConstantClass *V1, const ConstantClass *V2) {
546 if (V2->isNullValue()) return 0;
547 BuiltinType Result = std::fmod((BuiltinType)V1->getValue(),
548 (BuiltinType)V2->getValue());
549 return ConstantClass::get(*Ty, Result);
553 //===----------------------------------------------------------------------===//
554 // DirectRules Subclasses
555 //===----------------------------------------------------------------------===//
557 // Given the DirectRules class we can now implement lots of types with little
558 // code. Thank goodness C++ compilers are great at stomping out layers of
559 // templates... can you imagine having to do this all by hand? (/me is lazy :)
562 // ConstRules::find - Return the constant rules that take care of the specified
565 Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) {
566 assert(AID == ConstRules::AID && "Bad annotation for factory!");
567 const Type *Ty = cast<Type>((const Value*)TyA);
569 switch (Ty->getPrimitiveID()) {
570 case Type::BoolTyID: return new BoolRules();
571 case Type::PointerTyID: return new PointerRules();
572 case Type::SByteTyID:
573 return new DirectIntRules<ConstantSInt, signed char , &Type::SByteTy>();
574 case Type::UByteTyID:
575 return new DirectIntRules<ConstantUInt, unsigned char , &Type::UByteTy>();
576 case Type::ShortTyID:
577 return new DirectIntRules<ConstantSInt, signed short, &Type::ShortTy>();
578 case Type::UShortTyID:
579 return new DirectIntRules<ConstantUInt, unsigned short, &Type::UShortTy>();
581 return new DirectIntRules<ConstantSInt, signed int , &Type::IntTy>();
583 return new DirectIntRules<ConstantUInt, unsigned int , &Type::UIntTy>();
585 return new DirectIntRules<ConstantSInt, int64_t , &Type::LongTy>();
586 case Type::ULongTyID:
587 return new DirectIntRules<ConstantUInt, uint64_t , &Type::ULongTy>();
588 case Type::FloatTyID:
589 return new DirectFPRules<ConstantFP , float , &Type::FloatTy>();
590 case Type::DoubleTyID:
591 return new DirectFPRules<ConstantFP , double , &Type::DoubleTy>();
593 return new EmptyRules();
597 ConstRules *ConstRules::getConstantExprRules() {
598 static EmptyRules CERules;