[llvm-commits] CVS: llvm/lib/VMCore/ConstantHandling.cpp Type.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Nov 25 15:22:01 PST 2003
Changes in directory llvm/lib/VMCore:
ConstantHandling.cpp updated: 1.41 -> 1.42
Type.cpp updated: 1.83 -> 1.84
---
Log message:
Relax constrains on GEP type indexes
---
Diffs of the changes: (+16 -10)
Index: llvm/lib/VMCore/ConstantHandling.cpp
diff -u llvm/lib/VMCore/ConstantHandling.cpp:1.41 llvm/lib/VMCore/ConstantHandling.cpp:1.42
--- llvm/lib/VMCore/ConstantHandling.cpp:1.41 Mon Nov 17 14:19:35 2003
+++ llvm/lib/VMCore/ConstantHandling.cpp Tue Nov 25 15:21:46 2003
@@ -15,6 +15,7 @@
#include "llvm/iPHINode.h"
#include "llvm/InstrTypes.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Support/GetElementPtrTypeIterator.h"
#include <cmath>
using namespace llvm;
@@ -159,22 +160,29 @@
// TODO If C is null and all idx's are null, return null of the right type.
- if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(const_cast<Constant*>(C))) {
// Combine Indices - If the source pointer to this getelementptr instruction
// is a getelementptr instruction, combine the indices of the two
// getelementptr instructions into a single instruction.
//
if (CE->getOpcode() == Instruction::GetElementPtr) {
- if (CE->getOperand(CE->getNumOperands()-1)->getType() == Type::LongTy) {
+ const Type *LastTy = 0;
+ for (gep_type_iterator I = gep_type_begin(CE), E = gep_type_end(CE);
+ I != E; ++I)
+ LastTy = *I;
+
+ if (LastTy && isa<ArrayType>(LastTy)) {
std::vector<Constant*> NewIndices;
NewIndices.reserve(IdxList.size() + CE->getNumOperands());
for (unsigned i = 1, e = CE->getNumOperands()-1; i != e; ++i)
NewIndices.push_back(cast<Constant>(CE->getOperand(i)));
// Add the last index of the source with the first index of the new GEP.
+ // Make sure to handle the case when they are actually different types.
Constant *Combined =
- ConstantExpr::get(Instruction::Add, IdxList[0],
- CE->getOperand(CE->getNumOperands()-1));
+ ConstantExpr::get(Instruction::Add,
+ ConstantExpr::getCast(IdxList[0], Type::LongTy),
+ ConstantExpr::getCast(CE->getOperand(CE->getNumOperands()-1), Type::LongTy));
NewIndices.push_back(Combined);
NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());
Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.83 llvm/lib/VMCore/Type.cpp:1.84
--- llvm/lib/VMCore/Type.cpp:1.83 Wed Nov 19 13:20:20 2003
+++ llvm/lib/VMCore/Type.cpp Tue Nov 25 15:21:46 2003
@@ -261,10 +261,10 @@
bool StructType::indexValid(const Value *V) const {
- if (!isa<Constant>(V)) return false;
- if (V->getType() != Type::UByteTy) return false;
- unsigned Idx = cast<ConstantUInt>(V)->getValue();
- return Idx < ETypes.size();
+ // Structure indexes require unsigned integer constants.
+ if (ConstantUInt *CU = dyn_cast<ConstantUInt>(V))
+ return CU->getValue() < ETypes.size();
+ return false;
}
// getTypeAtIndex - Given an index value into the type, return the type of the
@@ -272,11 +272,9 @@
//
const Type *StructType::getTypeAtIndex(const Value *V) const {
assert(isa<Constant>(V) && "Structure index must be a constant!!");
- assert(V->getType() == Type::UByteTy && "Structure index must be ubyte!");
unsigned Idx = cast<ConstantUInt>(V)->getValue();
assert(Idx < ETypes.size() && "Structure index out of range!");
assert(indexValid(V) && "Invalid structure index!"); // Duplicate check
-
return ETypes[Idx];
}
More information about the llvm-commits
mailing list