1 //===-- Constants.cpp - Implement Constant nodes --------------------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Constant* classes...
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Constants.h"
15 #include "ConstantFolding.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/GlobalValue.h"
18 #include "llvm/Instructions.h"
19 #include "llvm/SymbolTable.h"
20 #include "llvm/Module.h"
21 #include "llvm/ADT/StringExtras.h"
26 ConstantBool *ConstantBool::True = new ConstantBool(true);
27 ConstantBool *ConstantBool::False = new ConstantBool(false);
30 //===----------------------------------------------------------------------===//
32 //===----------------------------------------------------------------------===//
34 // Specialize setName to take care of symbol table majik
35 void Constant::setName(const std::string &Name, SymbolTable *ST) {
36 assert(ST && "Type::setName - Must provide symbol table argument!");
38 if (Name.size()) ST->insert(Name, this);
41 void Constant::destroyConstantImpl() {
42 // When a Constant is destroyed, there may be lingering
43 // references to the constant by other constants in the constant pool. These
44 // constants are implicitly dependent on the module that is being deleted,
45 // but they don't know that. Because we only find out when the CPV is
46 // deleted, we must now notify all of our users (that should only be
47 // Constants) that they are, in fact, invalid now and should be deleted.
49 while (!use_empty()) {
50 Value *V = use_back();
51 #ifndef NDEBUG // Only in -g mode...
52 if (!isa<Constant>(V))
53 std::cerr << "While deleting: " << *this
54 << "\n\nUse still stuck around after Def is destroyed: "
57 assert(isa<Constant>(V) && "References remain to Constant being destroyed");
58 Constant *CV = cast<Constant>(V);
59 CV->destroyConstant();
61 // The constant should remove itself from our use list...
62 assert((use_empty() || use_back() != V) && "Constant not removed!");
65 // Value has no outstanding references it is safe to delete it now...
69 // Static constructor to create a '0' constant of arbitrary type...
70 Constant *Constant::getNullValue(const Type *Ty) {
71 switch (Ty->getTypeID()) {
72 case Type::BoolTyID: {
73 static Constant *NullBool = ConstantBool::get(false);
76 case Type::SByteTyID: {
77 static Constant *NullSByte = ConstantSInt::get(Type::SByteTy, 0);
80 case Type::UByteTyID: {
81 static Constant *NullUByte = ConstantUInt::get(Type::UByteTy, 0);
84 case Type::ShortTyID: {
85 static Constant *NullShort = ConstantSInt::get(Type::ShortTy, 0);
88 case Type::UShortTyID: {
89 static Constant *NullUShort = ConstantUInt::get(Type::UShortTy, 0);
93 static Constant *NullInt = ConstantSInt::get(Type::IntTy, 0);
96 case Type::UIntTyID: {
97 static Constant *NullUInt = ConstantUInt::get(Type::UIntTy, 0);
100 case Type::LongTyID: {
101 static Constant *NullLong = ConstantSInt::get(Type::LongTy, 0);
104 case Type::ULongTyID: {
105 static Constant *NullULong = ConstantUInt::get(Type::ULongTy, 0);
109 case Type::FloatTyID: {
110 static Constant *NullFloat = ConstantFP::get(Type::FloatTy, 0);
113 case Type::DoubleTyID: {
114 static Constant *NullDouble = ConstantFP::get(Type::DoubleTy, 0);
118 case Type::PointerTyID:
119 return ConstantPointerNull::get(cast<PointerType>(Ty));
121 case Type::StructTyID:
122 case Type::ArrayTyID:
123 case Type::PackedTyID:
124 return ConstantAggregateZero::get(Ty);
126 // Function, Label, or Opaque type?
127 assert(!"Cannot create a null constant of that type!");
132 // Static constructor to create the maximum constant of an integral type...
133 ConstantIntegral *ConstantIntegral::getMaxValue(const Type *Ty) {
134 switch (Ty->getTypeID()) {
135 case Type::BoolTyID: return ConstantBool::True;
136 case Type::SByteTyID:
137 case Type::ShortTyID:
139 case Type::LongTyID: {
140 // Calculate 011111111111111...
141 unsigned TypeBits = Ty->getPrimitiveSize()*8;
142 int64_t Val = INT64_MAX; // All ones
143 Val >>= 64-TypeBits; // Shift out unwanted 1 bits...
144 return ConstantSInt::get(Ty, Val);
147 case Type::UByteTyID:
148 case Type::UShortTyID:
150 case Type::ULongTyID: return getAllOnesValue(Ty);
156 // Static constructor to create the minimum constant for an integral type...
157 ConstantIntegral *ConstantIntegral::getMinValue(const Type *Ty) {
158 switch (Ty->getTypeID()) {
159 case Type::BoolTyID: return ConstantBool::False;
160 case Type::SByteTyID:
161 case Type::ShortTyID:
163 case Type::LongTyID: {
164 // Calculate 1111111111000000000000
165 unsigned TypeBits = Ty->getPrimitiveSize()*8;
166 int64_t Val = -1; // All ones
167 Val <<= TypeBits-1; // Shift over to the right spot
168 return ConstantSInt::get(Ty, Val);
171 case Type::UByteTyID:
172 case Type::UShortTyID:
174 case Type::ULongTyID: return ConstantUInt::get(Ty, 0);
180 // Static constructor to create an integral constant with all bits set
181 ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) {
182 switch (Ty->getTypeID()) {
183 case Type::BoolTyID: return ConstantBool::True;
184 case Type::SByteTyID:
185 case Type::ShortTyID:
187 case Type::LongTyID: return ConstantSInt::get(Ty, -1);
189 case Type::UByteTyID:
190 case Type::UShortTyID:
192 case Type::ULongTyID: {
193 // Calculate ~0 of the right type...
194 unsigned TypeBits = Ty->getPrimitiveSize()*8;
195 uint64_t Val = ~0ULL; // All ones
196 Val >>= 64-TypeBits; // Shift out unwanted 1 bits...
197 return ConstantUInt::get(Ty, Val);
203 bool ConstantUInt::isAllOnesValue() const {
204 unsigned TypeBits = getType()->getPrimitiveSize()*8;
205 uint64_t Val = ~0ULL; // All ones
206 Val >>= 64-TypeBits; // Shift out inappropriate bits
207 return getValue() == Val;
211 //===----------------------------------------------------------------------===//
212 // ConstantXXX Classes
213 //===----------------------------------------------------------------------===//
215 //===----------------------------------------------------------------------===//
216 // Normal Constructors
218 ConstantIntegral::ConstantIntegral(const Type *Ty, uint64_t V)
223 ConstantBool::ConstantBool(bool V) : ConstantIntegral(Type::BoolTy, V) {
226 ConstantInt::ConstantInt(const Type *Ty, uint64_t V) : ConstantIntegral(Ty, V) {
229 ConstantSInt::ConstantSInt(const Type *Ty, int64_t V) : ConstantInt(Ty, V) {
230 assert(Ty->isInteger() && Ty->isSigned() &&
231 "Illegal type for unsigned integer constant!");
232 assert(isValueValidForType(Ty, V) && "Value too large for type!");
235 ConstantUInt::ConstantUInt(const Type *Ty, uint64_t V) : ConstantInt(Ty, V) {
236 assert(Ty->isInteger() && Ty->isUnsigned() &&
237 "Illegal type for unsigned integer constant!");
238 assert(isValueValidForType(Ty, V) && "Value too large for type!");
241 ConstantFP::ConstantFP(const Type *Ty, double V) : Constant(Ty) {
242 assert(isValueValidForType(Ty, V) && "Value too large for type!");
246 ConstantArray::ConstantArray(const ArrayType *T,
247 const std::vector<Constant*> &V) : Constant(T) {
248 assert(V.size() == T->getNumElements() &&
249 "Invalid initializer vector for constant array");
250 Operands.reserve(V.size());
251 for (unsigned i = 0, e = V.size(); i != e; ++i) {
252 assert((V[i]->getType() == T->getElementType() ||
254 V[i]->getType()->getTypeID() == T->getElementType()->getTypeID())) &&
255 "Initializer for array element doesn't match array element type!");
256 Operands.push_back(Use(V[i], this));
260 ConstantStruct::ConstantStruct(const StructType *T,
261 const std::vector<Constant*> &V) : Constant(T) {
262 assert(V.size() == T->getNumElements() &&
263 "Invalid initializer vector for constant structure");
264 Operands.reserve(V.size());
265 for (unsigned i = 0, e = V.size(); i != e; ++i) {
266 assert((V[i]->getType() == T->getElementType(i) ||
267 ((T->getElementType(i)->isAbstract() ||
268 V[i]->getType()->isAbstract()) &&
269 T->getElementType(i)->getTypeID() == V[i]->getType()->getTypeID())) &&
270 "Initializer for struct element doesn't match struct element type!");
271 Operands.push_back(Use(V[i], this));
275 ConstantPacked::ConstantPacked(const PackedType *T,
276 const std::vector<Constant*> &V) : Constant(T) {
277 Operands.reserve(V.size());
278 for (unsigned i = 0, e = V.size(); i != e; ++i) {
279 assert((V[i]->getType() == T->getElementType() ||
281 V[i]->getType()->getTypeID() == T->getElementType()->getTypeID())) &&
282 "Initializer for packed element doesn't match packed element type!");
283 Operands.push_back(Use(V[i], this));
287 ConstantExpr::ConstantExpr(unsigned Opcode, Constant *C, const Type *Ty)
288 : Constant(Ty, ConstantExprVal), iType(Opcode) {
290 Operands.push_back(Use(C, this));
293 // Select instruction creation ctor
294 ConstantExpr::ConstantExpr(Constant *C, Constant *V1, Constant *V2)
295 : Constant(V1->getType(), ConstantExprVal), iType(Instruction::Select) {
297 Operands.push_back(Use(C, this));
298 Operands.push_back(Use(V1, this));
299 Operands.push_back(Use(V2, this));
303 static bool isSetCC(unsigned Opcode) {
304 return Opcode == Instruction::SetEQ || Opcode == Instruction::SetNE ||
305 Opcode == Instruction::SetLT || Opcode == Instruction::SetGT ||
306 Opcode == Instruction::SetLE || Opcode == Instruction::SetGE;
309 ConstantExpr::ConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
310 : Constant(isSetCC(Opcode) ? Type::BoolTy : C1->getType(), ConstantExprVal),
313 Operands.push_back(Use(C1, this));
314 Operands.push_back(Use(C2, this));
317 ConstantExpr::ConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
319 : Constant(DestTy, ConstantExprVal), iType(Instruction::GetElementPtr) {
320 Operands.reserve(1+IdxList.size());
321 Operands.push_back(Use(C, this));
322 for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
323 Operands.push_back(Use(IdxList[i], this));
326 /// ConstantExpr::get* - Return some common constants without having to
327 /// specify the full Instruction::OPCODE identifier.
329 Constant *ConstantExpr::getNeg(Constant *C) {
330 if (!C->getType()->isFloatingPoint())
331 return get(Instruction::Sub, getNullValue(C->getType()), C);
333 return get(Instruction::Sub, ConstantFP::get(C->getType(), -0.0), C);
335 Constant *ConstantExpr::getNot(Constant *C) {
336 assert(isa<ConstantIntegral>(C) && "Cannot NOT a nonintegral type!");
337 return get(Instruction::Xor, C,
338 ConstantIntegral::getAllOnesValue(C->getType()));
340 Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2) {
341 return get(Instruction::Add, C1, C2);
343 Constant *ConstantExpr::getSub(Constant *C1, Constant *C2) {
344 return get(Instruction::Sub, C1, C2);
346 Constant *ConstantExpr::getMul(Constant *C1, Constant *C2) {
347 return get(Instruction::Mul, C1, C2);
349 Constant *ConstantExpr::getDiv(Constant *C1, Constant *C2) {
350 return get(Instruction::Div, C1, C2);
352 Constant *ConstantExpr::getRem(Constant *C1, Constant *C2) {
353 return get(Instruction::Rem, C1, C2);
355 Constant *ConstantExpr::getAnd(Constant *C1, Constant *C2) {
356 return get(Instruction::And, C1, C2);
358 Constant *ConstantExpr::getOr(Constant *C1, Constant *C2) {
359 return get(Instruction::Or, C1, C2);
361 Constant *ConstantExpr::getXor(Constant *C1, Constant *C2) {
362 return get(Instruction::Xor, C1, C2);
364 Constant *ConstantExpr::getSetEQ(Constant *C1, Constant *C2) {
365 return get(Instruction::SetEQ, C1, C2);
367 Constant *ConstantExpr::getSetNE(Constant *C1, Constant *C2) {
368 return get(Instruction::SetNE, C1, C2);
370 Constant *ConstantExpr::getSetLT(Constant *C1, Constant *C2) {
371 return get(Instruction::SetLT, C1, C2);
373 Constant *ConstantExpr::getSetGT(Constant *C1, Constant *C2) {
374 return get(Instruction::SetGT, C1, C2);
376 Constant *ConstantExpr::getSetLE(Constant *C1, Constant *C2) {
377 return get(Instruction::SetLE, C1, C2);
379 Constant *ConstantExpr::getSetGE(Constant *C1, Constant *C2) {
380 return get(Instruction::SetGE, C1, C2);
382 Constant *ConstantExpr::getShl(Constant *C1, Constant *C2) {
383 return get(Instruction::Shl, C1, C2);
385 Constant *ConstantExpr::getShr(Constant *C1, Constant *C2) {
386 return get(Instruction::Shr, C1, C2);
389 Constant *ConstantExpr::getUShr(Constant *C1, Constant *C2) {
390 if (C1->getType()->isUnsigned()) return getShr(C1, C2);
391 return getCast(getShr(getCast(C1,
392 C1->getType()->getUnsignedVersion()), C2), C1->getType());
395 Constant *ConstantExpr::getSShr(Constant *C1, Constant *C2) {
396 if (C1->getType()->isSigned()) return getShr(C1, C2);
397 return getCast(getShr(getCast(C1,
398 C1->getType()->getSignedVersion()), C2), C1->getType());
402 //===----------------------------------------------------------------------===//
403 // isValueValidForType implementations
405 bool ConstantSInt::isValueValidForType(const Type *Ty, int64_t Val) {
406 switch (Ty->getTypeID()) {
408 return false; // These can't be represented as integers!!!
410 case Type::SByteTyID:
411 return (Val <= INT8_MAX && Val >= INT8_MIN);
412 case Type::ShortTyID:
413 return (Val <= INT16_MAX && Val >= INT16_MIN);
415 return (Val <= int(INT32_MAX) && Val >= int(INT32_MIN));
417 return true; // This is the largest type...
421 bool ConstantUInt::isValueValidForType(const Type *Ty, uint64_t Val) {
422 switch (Ty->getTypeID()) {
424 return false; // These can't be represented as integers!!!
427 case Type::UByteTyID:
428 return (Val <= UINT8_MAX);
429 case Type::UShortTyID:
430 return (Val <= UINT16_MAX);
432 return (Val <= UINT32_MAX);
433 case Type::ULongTyID:
434 return true; // This is the largest type...
438 bool ConstantFP::isValueValidForType(const Type *Ty, double Val) {
439 switch (Ty->getTypeID()) {
441 return false; // These can't be represented as floating point!
443 // TODO: Figure out how to test if a double can be cast to a float!
444 case Type::FloatTyID:
445 case Type::DoubleTyID:
446 return true; // This is the largest type...
450 //===----------------------------------------------------------------------===//
451 // replaceUsesOfWithOnConstant implementations
453 void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
454 bool DisableChecking) {
455 assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
457 std::vector<Constant*> Values;
458 Values.reserve(getNumOperands()); // Build replacement array...
459 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
460 Constant *Val = getOperand(i);
461 if (Val == From) Val = cast<Constant>(To);
462 Values.push_back(Val);
465 Constant *Replacement = ConstantArray::get(getType(), Values);
466 assert(Replacement != this && "I didn't contain From!");
468 // Everyone using this now uses the replacement...
470 uncheckedReplaceAllUsesWith(Replacement);
472 replaceAllUsesWith(Replacement);
474 // Delete the old constant!
478 void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
479 bool DisableChecking) {
480 assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
482 std::vector<Constant*> Values;
483 Values.reserve(getNumOperands()); // Build replacement array...
484 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
485 Constant *Val = getOperand(i);
486 if (Val == From) Val = cast<Constant>(To);
487 Values.push_back(Val);
490 Constant *Replacement = ConstantStruct::get(getType(), Values);
491 assert(Replacement != this && "I didn't contain From!");
493 // Everyone using this now uses the replacement...
495 uncheckedReplaceAllUsesWith(Replacement);
497 replaceAllUsesWith(Replacement);
499 // Delete the old constant!
503 void ConstantPacked::replaceUsesOfWithOnConstant(Value *From, Value *To,
504 bool DisableChecking) {
505 assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
507 std::vector<Constant*> Values;
508 Values.reserve(getNumOperands()); // Build replacement array...
509 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
510 Constant *Val = getOperand(i);
511 if (Val == From) Val = cast<Constant>(To);
512 Values.push_back(Val);
515 Constant *Replacement = ConstantPacked::get(getType(), Values);
516 assert(Replacement != this && "I didn't contain From!");
518 // Everyone using this now uses the replacement...
520 uncheckedReplaceAllUsesWith(Replacement);
522 replaceAllUsesWith(Replacement);
524 // Delete the old constant!
528 void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV,
529 bool DisableChecking) {
530 assert(isa<Constant>(ToV) && "Cannot make Constant refer to non-constant!");
531 Constant *To = cast<Constant>(ToV);
533 Constant *Replacement = 0;
534 if (getOpcode() == Instruction::GetElementPtr) {
535 std::vector<Constant*> Indices;
536 Constant *Pointer = getOperand(0);
537 Indices.reserve(getNumOperands()-1);
538 if (Pointer == From) Pointer = To;
540 for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
541 Constant *Val = getOperand(i);
542 if (Val == From) Val = To;
543 Indices.push_back(Val);
545 Replacement = ConstantExpr::getGetElementPtr(Pointer, Indices);
546 } else if (getOpcode() == Instruction::Cast) {
547 assert(getOperand(0) == From && "Cast only has one use!");
548 Replacement = ConstantExpr::getCast(To, getType());
549 } else if (getOpcode() == Instruction::Select) {
550 Constant *C1 = getOperand(0);
551 Constant *C2 = getOperand(1);
552 Constant *C3 = getOperand(2);
553 if (C1 == From) C1 = To;
554 if (C2 == From) C2 = To;
555 if (C3 == From) C3 = To;
556 Replacement = ConstantExpr::getSelect(C1, C2, C3);
557 } else if (getNumOperands() == 2) {
558 Constant *C1 = getOperand(0);
559 Constant *C2 = getOperand(1);
560 if (C1 == From) C1 = To;
561 if (C2 == From) C2 = To;
562 Replacement = ConstantExpr::get(getOpcode(), C1, C2);
564 assert(0 && "Unknown ConstantExpr type!");
568 assert(Replacement != this && "I didn't contain From!");
570 // Everyone using this now uses the replacement...
572 uncheckedReplaceAllUsesWith(Replacement);
574 replaceAllUsesWith(Replacement);
576 // Delete the old constant!
580 //===----------------------------------------------------------------------===//
581 // Factory Function Implementation
583 // ConstantCreator - A class that is used to create constants by
584 // ValueMap*. This class should be partially specialized if there is
585 // something strange that needs to be done to interface to the ctor for the
589 template<class ConstantClass, class TypeClass, class ValType>
590 struct ConstantCreator {
591 static ConstantClass *create(const TypeClass *Ty, const ValType &V) {
592 return new ConstantClass(Ty, V);
596 template<class ConstantClass, class TypeClass>
597 struct ConvertConstantType {
598 static void convert(ConstantClass *OldC, const TypeClass *NewTy) {
599 assert(0 && "This type cannot be converted!\n");
606 template<class ValType, class TypeClass, class ConstantClass>
607 class ValueMap : public AbstractTypeUser {
608 typedef std::pair<const TypeClass*, ValType> MapKey;
609 typedef std::map<MapKey, ConstantClass *> MapTy;
610 typedef typename MapTy::iterator MapIterator;
613 typedef std::map<const TypeClass*, MapIterator> AbstractTypeMapTy;
614 AbstractTypeMapTy AbstractTypeMap;
616 // getOrCreate - Return the specified constant from the map, creating it if
618 ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
619 MapKey Lookup(Ty, V);
620 MapIterator I = Map.lower_bound(Lookup);
621 if (I != Map.end() && I->first == Lookup)
622 return I->second; // Is it in the map?
624 // If no preexisting value, create one now...
625 ConstantClass *Result =
626 ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
629 /// FIXME: why does this assert fail when loading 176.gcc?
630 //assert(Result->getType() == Ty && "Type specified is not correct!");
631 I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
633 // If the type of the constant is abstract, make sure that an entry exists
634 // for it in the AbstractTypeMap.
635 if (Ty->isAbstract()) {
636 typename AbstractTypeMapTy::iterator TI =
637 AbstractTypeMap.lower_bound(Ty);
639 if (TI == AbstractTypeMap.end() || TI->first != Ty) {
640 // Add ourselves to the ATU list of the type.
641 cast<DerivedType>(Ty)->addAbstractTypeUser(this);
643 AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
649 void remove(ConstantClass *CP) {
650 MapIterator I = Map.find(MapKey((TypeClass*)CP->getRawType(),
652 if (I == Map.end() || I->second != CP) {
653 // FIXME: This should not use a linear scan. If this gets to be a
654 // performance problem, someone should look at this.
655 for (I = Map.begin(); I != Map.end() && I->second != CP; ++I)
659 assert(I != Map.end() && "Constant not found in constant table!");
660 assert(I->second == CP && "Didn't find correct element?");
662 // Now that we found the entry, make sure this isn't the entry that
663 // the AbstractTypeMap points to.
664 const TypeClass *Ty = I->first.first;
665 if (Ty->isAbstract()) {
666 assert(AbstractTypeMap.count(Ty) &&
667 "Abstract type not in AbstractTypeMap?");
668 MapIterator &ATMEntryIt = AbstractTypeMap[Ty];
669 if (ATMEntryIt == I) {
670 // Yes, we are removing the representative entry for this type.
671 // See if there are any other entries of the same type.
672 MapIterator TmpIt = ATMEntryIt;
674 // First check the entry before this one...
675 if (TmpIt != Map.begin()) {
677 if (TmpIt->first.first != Ty) // Not the same type, move back...
681 // If we didn't find the same type, try to move forward...
682 if (TmpIt == ATMEntryIt) {
684 if (TmpIt == Map.end() || TmpIt->first.first != Ty)
685 --TmpIt; // No entry afterwards with the same type
688 // If there is another entry in the map of the same abstract type,
689 // update the AbstractTypeMap entry now.
690 if (TmpIt != ATMEntryIt) {
693 // Otherwise, we are removing the last instance of this type
694 // from the table. Remove from the ATM, and from user list.
695 cast<DerivedType>(Ty)->removeAbstractTypeUser(this);
696 AbstractTypeMap.erase(Ty);
704 void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
705 typename AbstractTypeMapTy::iterator I =
706 AbstractTypeMap.find(cast<TypeClass>(OldTy));
708 assert(I != AbstractTypeMap.end() &&
709 "Abstract type not in AbstractTypeMap?");
711 // Convert a constant at a time until the last one is gone. The last one
712 // leaving will remove() itself, causing the AbstractTypeMapEntry to be
713 // eliminated eventually.
715 ConvertConstantType<ConstantClass,
716 TypeClass>::convert(I->second->second,
717 cast<TypeClass>(NewTy));
719 I = AbstractTypeMap.find(cast<TypeClass>(OldTy));
720 } while (I != AbstractTypeMap.end());
723 // If the type became concrete without being refined to any other existing
724 // type, we just remove ourselves from the ATU list.
725 void typeBecameConcrete(const DerivedType *AbsTy) {
726 AbsTy->removeAbstractTypeUser(this);
730 std::cerr << "Constant.cpp: ValueMap\n";
735 //---- ConstantUInt::get() and ConstantSInt::get() implementations...
737 static ValueMap< int64_t, Type, ConstantSInt> SIntConstants;
738 static ValueMap<uint64_t, Type, ConstantUInt> UIntConstants;
740 ConstantSInt *ConstantSInt::get(const Type *Ty, int64_t V) {
741 return SIntConstants.getOrCreate(Ty, V);
744 ConstantUInt *ConstantUInt::get(const Type *Ty, uint64_t V) {
745 return UIntConstants.getOrCreate(Ty, V);
748 ConstantInt *ConstantInt::get(const Type *Ty, unsigned char V) {
749 assert(V <= 127 && "Can only be used with very small positive constants!");
750 if (Ty->isSigned()) return ConstantSInt::get(Ty, V);
751 return ConstantUInt::get(Ty, V);
754 //---- ConstantFP::get() implementation...
758 struct ConstantCreator<ConstantFP, Type, uint64_t> {
759 static ConstantFP *create(const Type *Ty, uint64_t V) {
760 assert(Ty == Type::DoubleTy);
766 return new ConstantFP(Ty, T.F);
770 struct ConstantCreator<ConstantFP, Type, uint32_t> {
771 static ConstantFP *create(const Type *Ty, uint32_t V) {
772 assert(Ty == Type::FloatTy);
778 return new ConstantFP(Ty, T.F);
783 static ValueMap<uint64_t, Type, ConstantFP> DoubleConstants;
784 static ValueMap<uint32_t, Type, ConstantFP> FloatConstants;
786 ConstantFP *ConstantFP::get(const Type *Ty, double V) {
787 if (Ty == Type::FloatTy) {
788 // Force the value through memory to normalize it.
794 return FloatConstants.getOrCreate(Ty, T.I);
796 assert(Ty == Type::DoubleTy);
802 return DoubleConstants.getOrCreate(Ty, T.I);
806 //---- ConstantAggregateZero::get() implementation...
809 // ConstantAggregateZero does not take extra "value" argument...
810 template<class ValType>
811 struct ConstantCreator<ConstantAggregateZero, Type, ValType> {
812 static ConstantAggregateZero *create(const Type *Ty, const ValType &V){
813 return new ConstantAggregateZero(Ty);
818 struct ConvertConstantType<ConstantAggregateZero, Type> {
819 static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
820 // Make everyone now use a constant of the new type...
821 Constant *New = ConstantAggregateZero::get(NewTy);
822 assert(New != OldC && "Didn't replace constant??");
823 OldC->uncheckedReplaceAllUsesWith(New);
824 OldC->destroyConstant(); // This constant is now dead, destroy it.
829 static ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
831 static char getValType(ConstantAggregateZero *CPZ) { return 0; }
833 Constant *ConstantAggregateZero::get(const Type *Ty) {
834 return AggZeroConstants.getOrCreate(Ty, 0);
837 // destroyConstant - Remove the constant from the constant table...
839 void ConstantAggregateZero::destroyConstant() {
840 AggZeroConstants.remove(this);
841 destroyConstantImpl();
844 void ConstantAggregateZero::replaceUsesOfWithOnConstant(Value *From, Value *To,
845 bool DisableChecking) {
846 assert(0 && "No uses!");
852 //---- ConstantArray::get() implementation...
856 struct ConvertConstantType<ConstantArray, ArrayType> {
857 static void convert(ConstantArray *OldC, const ArrayType *NewTy) {
858 // Make everyone now use a constant of the new type...
859 std::vector<Constant*> C;
860 for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
861 C.push_back(cast<Constant>(OldC->getOperand(i)));
862 Constant *New = ConstantArray::get(NewTy, C);
863 assert(New != OldC && "Didn't replace constant??");
864 OldC->uncheckedReplaceAllUsesWith(New);
865 OldC->destroyConstant(); // This constant is now dead, destroy it.
870 static std::vector<Constant*> getValType(ConstantArray *CA) {
871 std::vector<Constant*> Elements;
872 Elements.reserve(CA->getNumOperands());
873 for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
874 Elements.push_back(cast<Constant>(CA->getOperand(i)));
878 static ValueMap<std::vector<Constant*>, ArrayType,
879 ConstantArray> ArrayConstants;
881 Constant *ConstantArray::get(const ArrayType *Ty,
882 const std::vector<Constant*> &V) {
883 // If this is an all-zero array, return a ConstantAggregateZero object
886 if (!C->isNullValue())
887 return ArrayConstants.getOrCreate(Ty, V);
888 for (unsigned i = 1, e = V.size(); i != e; ++i)
890 return ArrayConstants.getOrCreate(Ty, V);
892 return ConstantAggregateZero::get(Ty);
895 // destroyConstant - Remove the constant from the constant table...
897 void ConstantArray::destroyConstant() {
898 ArrayConstants.remove(this);
899 destroyConstantImpl();
902 // ConstantArray::get(const string&) - Return an array that is initialized to
903 // contain the specified string. A null terminator is added to the specified
904 // string so that it may be used in a natural way...
906 Constant *ConstantArray::get(const std::string &Str) {
907 std::vector<Constant*> ElementVals;
909 for (unsigned i = 0; i < Str.length(); ++i)
910 ElementVals.push_back(ConstantSInt::get(Type::SByteTy, Str[i]));
912 // Add a null terminator to the string...
913 ElementVals.push_back(ConstantSInt::get(Type::SByteTy, 0));
915 ArrayType *ATy = ArrayType::get(Type::SByteTy, Str.length()+1);
916 return ConstantArray::get(ATy, ElementVals);
919 /// isString - This method returns true if the array is an array of sbyte or
920 /// ubyte, and if the elements of the array are all ConstantInt's.
921 bool ConstantArray::isString() const {
922 // Check the element type for sbyte or ubyte...
923 if (getType()->getElementType() != Type::UByteTy &&
924 getType()->getElementType() != Type::SByteTy)
926 // Check the elements to make sure they are all integers, not constant
928 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
929 if (!isa<ConstantInt>(getOperand(i)))
934 // getAsString - If the sub-element type of this array is either sbyte or ubyte,
935 // then this method converts the array to an std::string and returns it.
936 // Otherwise, it asserts out.
938 std::string ConstantArray::getAsString() const {
939 assert(isString() && "Not a string!");
941 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
942 Result += (char)cast<ConstantInt>(getOperand(i))->getRawValue();
947 //---- ConstantStruct::get() implementation...
952 struct ConvertConstantType<ConstantStruct, StructType> {
953 static void convert(ConstantStruct *OldC, const StructType *NewTy) {
954 // Make everyone now use a constant of the new type...
955 std::vector<Constant*> C;
956 for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
957 C.push_back(cast<Constant>(OldC->getOperand(i)));
958 Constant *New = ConstantStruct::get(NewTy, C);
959 assert(New != OldC && "Didn't replace constant??");
961 OldC->uncheckedReplaceAllUsesWith(New);
962 OldC->destroyConstant(); // This constant is now dead, destroy it.
967 static ValueMap<std::vector<Constant*>, StructType,
968 ConstantStruct> StructConstants;
970 static std::vector<Constant*> getValType(ConstantStruct *CS) {
971 std::vector<Constant*> Elements;
972 Elements.reserve(CS->getNumOperands());
973 for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i)
974 Elements.push_back(cast<Constant>(CS->getOperand(i)));
978 Constant *ConstantStruct::get(const StructType *Ty,
979 const std::vector<Constant*> &V) {
980 // Create a ConstantAggregateZero value if all elements are zeros...
981 for (unsigned i = 0, e = V.size(); i != e; ++i)
982 if (!V[i]->isNullValue())
983 return StructConstants.getOrCreate(Ty, V);
985 return ConstantAggregateZero::get(Ty);
988 Constant *ConstantStruct::get(const std::vector<Constant*> &V) {
989 std::vector<const Type*> StructEls;
990 StructEls.reserve(V.size());
991 for (unsigned i = 0, e = V.size(); i != e; ++i)
992 StructEls.push_back(V[i]->getType());
993 return get(StructType::get(StructEls), V);
996 // destroyConstant - Remove the constant from the constant table...
998 void ConstantStruct::destroyConstant() {
999 StructConstants.remove(this);
1000 destroyConstantImpl();
1003 //---- ConstantPacked::get() implementation...
1007 struct ConvertConstantType<ConstantPacked, PackedType> {
1008 static void convert(ConstantPacked *OldC, const PackedType *NewTy) {
1009 // Make everyone now use a constant of the new type...
1010 std::vector<Constant*> C;
1011 for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
1012 C.push_back(cast<Constant>(OldC->getOperand(i)));
1013 Constant *New = ConstantPacked::get(NewTy, C);
1014 assert(New != OldC && "Didn't replace constant??");
1015 OldC->uncheckedReplaceAllUsesWith(New);
1016 OldC->destroyConstant(); // This constant is now dead, destroy it.
1021 static std::vector<Constant*> getValType(ConstantPacked *CP) {
1022 std::vector<Constant*> Elements;
1023 Elements.reserve(CP->getNumOperands());
1024 for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
1025 Elements.push_back(CP->getOperand(i));
1029 static ValueMap<std::vector<Constant*>, PackedType,
1030 ConstantPacked> PackedConstants;
1032 Constant *ConstantPacked::get(const PackedType *Ty,
1033 const std::vector<Constant*> &V) {
1034 // If this is an all-zero packed, return a ConstantAggregateZero object
1037 if (!C->isNullValue())
1038 return PackedConstants.getOrCreate(Ty, V);
1039 for (unsigned i = 1, e = V.size(); i != e; ++i)
1041 return PackedConstants.getOrCreate(Ty, V);
1043 return ConstantAggregateZero::get(Ty);
1046 Constant *ConstantPacked::get(const std::vector<Constant*> &V) {
1047 assert(!V.empty() && "Cannot infer type if V is empty");
1048 return get(PackedType::get(V.front()->getType(),V.size()), V);
1051 // destroyConstant - Remove the constant from the constant table...
1053 void ConstantPacked::destroyConstant() {
1054 PackedConstants.remove(this);
1055 destroyConstantImpl();
1058 //---- ConstantPointerNull::get() implementation...
1062 // ConstantPointerNull does not take extra "value" argument...
1063 template<class ValType>
1064 struct ConstantCreator<ConstantPointerNull, PointerType, ValType> {
1065 static ConstantPointerNull *create(const PointerType *Ty, const ValType &V){
1066 return new ConstantPointerNull(Ty);
1071 struct ConvertConstantType<ConstantPointerNull, PointerType> {
1072 static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) {
1073 // Make everyone now use a constant of the new type...
1074 Constant *New = ConstantPointerNull::get(NewTy);
1075 assert(New != OldC && "Didn't replace constant??");
1076 OldC->uncheckedReplaceAllUsesWith(New);
1077 OldC->destroyConstant(); // This constant is now dead, destroy it.
1082 static ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
1084 static char getValType(ConstantPointerNull *) {
1089 ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) {
1090 return NullPtrConstants.getOrCreate(Ty, 0);
1093 // destroyConstant - Remove the constant from the constant table...
1095 void ConstantPointerNull::destroyConstant() {
1096 NullPtrConstants.remove(this);
1097 destroyConstantImpl();
1101 //---- UndefValue::get() implementation...
1105 // UndefValue does not take extra "value" argument...
1106 template<class ValType>
1107 struct ConstantCreator<UndefValue, Type, ValType> {
1108 static UndefValue *create(const Type *Ty, const ValType &V) {
1109 return new UndefValue(Ty);
1114 struct ConvertConstantType<UndefValue, Type> {
1115 static void convert(UndefValue *OldC, const Type *NewTy) {
1116 // Make everyone now use a constant of the new type.
1117 Constant *New = UndefValue::get(NewTy);
1118 assert(New != OldC && "Didn't replace constant??");
1119 OldC->uncheckedReplaceAllUsesWith(New);
1120 OldC->destroyConstant(); // This constant is now dead, destroy it.
1125 static ValueMap<char, Type, UndefValue> UndefValueConstants;
1127 static char getValType(UndefValue *) {
1132 UndefValue *UndefValue::get(const Type *Ty) {
1133 return UndefValueConstants.getOrCreate(Ty, 0);
1136 // destroyConstant - Remove the constant from the constant table.
1138 void UndefValue::destroyConstant() {
1139 UndefValueConstants.remove(this);
1140 destroyConstantImpl();
1146 //---- ConstantExpr::get() implementations...
1148 typedef std::pair<unsigned, std::vector<Constant*> > ExprMapKeyType;
1152 struct ConstantCreator<ConstantExpr, Type, ExprMapKeyType> {
1153 static ConstantExpr *create(const Type *Ty, const ExprMapKeyType &V) {
1154 if (V.first == Instruction::Cast)
1155 return new ConstantExpr(Instruction::Cast, V.second[0], Ty);
1156 if ((V.first >= Instruction::BinaryOpsBegin &&
1157 V.first < Instruction::BinaryOpsEnd) ||
1158 V.first == Instruction::Shl || V.first == Instruction::Shr)
1159 return new ConstantExpr(V.first, V.second[0], V.second[1]);
1160 if (V.first == Instruction::Select)
1161 return new ConstantExpr(V.second[0], V.second[1], V.second[2]);
1163 assert(V.first == Instruction::GetElementPtr && "Invalid ConstantExpr!");
1165 std::vector<Constant*> IdxList(V.second.begin()+1, V.second.end());
1166 return new ConstantExpr(V.second[0], IdxList, Ty);
1171 struct ConvertConstantType<ConstantExpr, Type> {
1172 static void convert(ConstantExpr *OldC, const Type *NewTy) {
1174 switch (OldC->getOpcode()) {
1175 case Instruction::Cast:
1176 New = ConstantExpr::getCast(OldC->getOperand(0), NewTy);
1178 case Instruction::Select:
1179 New = ConstantExpr::getSelectTy(NewTy, OldC->getOperand(0),
1180 OldC->getOperand(1),
1181 OldC->getOperand(2));
1183 case Instruction::Shl:
1184 case Instruction::Shr:
1185 New = ConstantExpr::getShiftTy(NewTy, OldC->getOpcode(),
1186 OldC->getOperand(0), OldC->getOperand(1));
1189 assert(OldC->getOpcode() >= Instruction::BinaryOpsBegin &&
1190 OldC->getOpcode() < Instruction::BinaryOpsEnd);
1191 New = ConstantExpr::getTy(NewTy, OldC->getOpcode(), OldC->getOperand(0),
1192 OldC->getOperand(1));
1194 case Instruction::GetElementPtr:
1195 // Make everyone now use a constant of the new type...
1196 std::vector<Value*> Idx(OldC->op_begin()+1, OldC->op_end());
1197 New = ConstantExpr::getGetElementPtrTy(NewTy, OldC->getOperand(0), Idx);
1201 assert(New != OldC && "Didn't replace constant??");
1202 OldC->uncheckedReplaceAllUsesWith(New);
1203 OldC->destroyConstant(); // This constant is now dead, destroy it.
1206 } // end namespace llvm
1209 static ExprMapKeyType getValType(ConstantExpr *CE) {
1210 std::vector<Constant*> Operands;
1211 Operands.reserve(CE->getNumOperands());
1212 for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
1213 Operands.push_back(cast<Constant>(CE->getOperand(i)));
1214 return ExprMapKeyType(CE->getOpcode(), Operands);
1217 static ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants;
1219 Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) {
1220 assert(Ty->isFirstClassType() && "Cannot cast to an aggregate type!");
1222 if (Constant *FC = ConstantFoldCastInstruction(C, Ty))
1223 return FC; // Fold a few common cases...
1225 // Look up the constant in the table first to ensure uniqueness
1226 std::vector<Constant*> argVec(1, C);
1227 ExprMapKeyType Key = std::make_pair(Instruction::Cast, argVec);
1228 return ExprConstants.getOrCreate(Ty, Key);
1231 Constant *ConstantExpr::getSignExtend(Constant *C, const Type *Ty) {
1232 assert(C->getType()->isInteger() && Ty->isInteger() &&
1233 C->getType()->getPrimitiveSize() <= Ty->getPrimitiveSize() &&
1234 "This is an illegal sign extension!");
1235 C = ConstantExpr::getCast(C, C->getType()->getSignedVersion());
1236 return ConstantExpr::getCast(C, Ty);
1239 Constant *ConstantExpr::getZeroExtend(Constant *C, const Type *Ty) {
1240 assert(C->getType()->isInteger() && Ty->isInteger() &&
1241 C->getType()->getPrimitiveSize() <= Ty->getPrimitiveSize() &&
1242 "This is an illegal zero extension!");
1243 C = ConstantExpr::getCast(C, C->getType()->getUnsignedVersion());
1244 return ConstantExpr::getCast(C, Ty);
1247 Constant *ConstantExpr::getSizeOf(const Type *Ty) {
1248 // sizeof is implemented as: (unsigned) gep (Ty)null, 1
1252 std::vector<Constant*>(1, ConstantInt::get(Type::UByteTy, 1))),
1256 Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
1257 Constant *C1, Constant *C2) {
1258 if (Opcode == Instruction::Shl || Opcode == Instruction::Shr)
1259 return getShiftTy(ReqTy, Opcode, C1, C2);
1260 // Check the operands for consistency first
1261 assert((Opcode >= Instruction::BinaryOpsBegin &&
1262 Opcode < Instruction::BinaryOpsEnd) &&
1263 "Invalid opcode in binary constant expression");
1264 assert(C1->getType() == C2->getType() &&
1265 "Operand types in binary constant expression should match");
1267 if (ReqTy == C1->getType() || (Instruction::isRelational(Opcode) &&
1268 ReqTy == Type::BoolTy))
1269 if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
1270 return FC; // Fold a few common cases...
1272 std::vector<Constant*> argVec(1, C1); argVec.push_back(C2);
1273 ExprMapKeyType Key = std::make_pair(Opcode, argVec);
1274 return ExprConstants.getOrCreate(ReqTy, Key);
1277 Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
1280 case Instruction::Add: case Instruction::Sub:
1281 case Instruction::Mul: case Instruction::Div:
1282 case Instruction::Rem:
1283 assert(C1->getType() == C2->getType() && "Op types should be identical!");
1284 assert((C1->getType()->isInteger() || C1->getType()->isFloatingPoint()) &&
1285 "Tried to create an arithmetic operation on a non-arithmetic type!");
1287 case Instruction::And:
1288 case Instruction::Or:
1289 case Instruction::Xor:
1290 assert(C1->getType() == C2->getType() && "Op types should be identical!");
1291 assert(C1->getType()->isIntegral() &&
1292 "Tried to create an logical operation on a non-integral type!");
1294 case Instruction::SetLT: case Instruction::SetGT: case Instruction::SetLE:
1295 case Instruction::SetGE: case Instruction::SetEQ: case Instruction::SetNE:
1296 assert(C1->getType() == C2->getType() && "Op types should be identical!");
1298 case Instruction::Shl:
1299 case Instruction::Shr:
1300 assert(C2->getType() == Type::UByteTy && "Shift should be by ubyte!");
1301 assert(C1->getType()->isInteger() &&
1302 "Tried to create a shift operation on a non-integer type!");
1309 if (Instruction::isRelational(Opcode))
1310 return getTy(Type::BoolTy, Opcode, C1, C2);
1312 return getTy(C1->getType(), Opcode, C1, C2);
1315 Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
1316 Constant *V1, Constant *V2) {
1317 assert(C->getType() == Type::BoolTy && "Select condition must be bool!");
1318 assert(V1->getType() == V2->getType() && "Select value types must match!");
1319 assert(V1->getType()->isFirstClassType() && "Cannot select aggregate type!");
1321 if (ReqTy == V1->getType())
1322 if (Constant *SC = ConstantFoldSelectInstruction(C, V1, V2))
1323 return SC; // Fold common cases
1325 std::vector<Constant*> argVec(3, C);
1328 ExprMapKeyType Key = std::make_pair(Instruction::Select, argVec);
1329 return ExprConstants.getOrCreate(ReqTy, Key);
1332 /// getShiftTy - Return a shift left or shift right constant expr
1333 Constant *ConstantExpr::getShiftTy(const Type *ReqTy, unsigned Opcode,
1334 Constant *C1, Constant *C2) {
1335 // Check the operands for consistency first
1336 assert((Opcode == Instruction::Shl ||
1337 Opcode == Instruction::Shr) &&
1338 "Invalid opcode in binary constant expression");
1339 assert(C1->getType()->isIntegral() && C2->getType() == Type::UByteTy &&
1340 "Invalid operand types for Shift constant expr!");
1342 if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
1343 return FC; // Fold a few common cases...
1345 // Look up the constant in the table first to ensure uniqueness
1346 std::vector<Constant*> argVec(1, C1); argVec.push_back(C2);
1347 ExprMapKeyType Key = std::make_pair(Opcode, argVec);
1348 return ExprConstants.getOrCreate(ReqTy, Key);
1352 Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
1353 const std::vector<Value*> &IdxList) {
1354 assert(GetElementPtrInst::getIndexedType(C->getType(), IdxList, true) &&
1355 "GEP indices invalid!");
1357 if (Constant *FC = ConstantFoldGetElementPtr(C, IdxList))
1358 return FC; // Fold a few common cases...
1360 assert(isa<PointerType>(C->getType()) &&
1361 "Non-pointer type for constant GetElementPtr expression");
1362 // Look up the constant in the table first to ensure uniqueness
1363 std::vector<Constant*> ArgVec;
1364 ArgVec.reserve(IdxList.size()+1);
1365 ArgVec.push_back(C);
1366 for (unsigned i = 0, e = IdxList.size(); i != e; ++i)
1367 ArgVec.push_back(cast<Constant>(IdxList[i]));
1368 const ExprMapKeyType &Key = std::make_pair(Instruction::GetElementPtr,ArgVec);
1369 return ExprConstants.getOrCreate(ReqTy, Key);
1372 Constant *ConstantExpr::getGetElementPtr(Constant *C,
1373 const std::vector<Constant*> &IdxList){
1374 // Get the result type of the getelementptr!
1375 std::vector<Value*> VIdxList(IdxList.begin(), IdxList.end());
1377 const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), VIdxList,
1379 assert(Ty && "GEP indices invalid!");
1380 return getGetElementPtrTy(PointerType::get(Ty), C, VIdxList);
1383 Constant *ConstantExpr::getGetElementPtr(Constant *C,
1384 const std::vector<Value*> &IdxList) {
1385 // Get the result type of the getelementptr!
1386 const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), IdxList,
1388 assert(Ty && "GEP indices invalid!");
1389 return getGetElementPtrTy(PointerType::get(Ty), C, IdxList);
1393 // destroyConstant - Remove the constant from the constant table...
1395 void ConstantExpr::destroyConstant() {
1396 ExprConstants.remove(this);
1397 destroyConstantImpl();
1400 const char *ConstantExpr::getOpcodeName() const {
1401 return Instruction::getOpcodeName(getOpcode());