aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-05-15 19:50:34 +0000
committerDan Gohman <gohman@apple.com>2008-05-15 19:50:34 +0000
commit8055f7781b0430973392a8ddf54142afb9bcdd3d (patch)
treebb8e3b74ffb3950147e74e621ffa5e8f14040cd2 /lib/VMCore/Instructions.cpp
parent7fcd440412730ab1a380d723a418856e4226d9e8 (diff)
downloadexternal_llvm-8055f7781b0430973392a8ddf54142afb9bcdd3d.zip
external_llvm-8055f7781b0430973392a8ddf54142afb9bcdd3d.tar.gz
external_llvm-8055f7781b0430973392a8ddf54142afb9bcdd3d.tar.bz2
IR support for extractvalue and insertvalue instructions. Also, begin
moving toward making structs and arrays first-class types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51157 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r--lib/VMCore/Instructions.cpp69
1 files changed, 37 insertions, 32 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 473e9fa..c54815a 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -1038,41 +1038,16 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
//
const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
Value* const *Idxs,
- unsigned NumIdx,
- bool AllowCompositeLeaf) {
- if (!isa<PointerType>(Ptr)) return 0; // Type isn't a pointer type!
+ unsigned NumIdx) {
+ const PointerType *PTy = dyn_cast<PointerType>(Ptr);
+ if (!PTy) return 0; // Type isn't a pointer type!
+ const Type *Agg = PTy->getElementType();
// Handle the special case of the empty set index set...
- if (NumIdx == 0) {
- if (AllowCompositeLeaf ||
- cast<PointerType>(Ptr)->getElementType()->isFirstClassType())
- return cast<PointerType>(Ptr)->getElementType();
- else
- return 0;
- }
-
- unsigned CurIdx = 0;
- while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
- if (NumIdx == CurIdx) {
- if (AllowCompositeLeaf || CT->isFirstClassType()) return Ptr;
- return 0; // Can't load a whole structure or array!?!?
- }
+ if (NumIdx == 0)
+ return Agg;
- Value *Index = Idxs[CurIdx++];
- if (isa<PointerType>(CT) && CurIdx != 1)
- return 0; // Can only index into pointer types at the first index!
- if (!CT->indexValid(Index)) return 0;
- Ptr = CT->getTypeAtIndex(Index);
-
- // If the new type forwards to another type, then it is in the middle
- // of being refined to another type (and hence, may have dropped all
- // references to what it was using before). So, use the new forwarded
- // type.
- if (const Type * Ty = Ptr->getForwardedType()) {
- Ptr = Ty;
- }
- }
- return CurIdx == NumIdx ? Ptr : 0;
+ return ExtractValueInst::getIndexedType(Agg, Idxs+1, Idxs+NumIdx);
}
const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
@@ -1345,6 +1320,36 @@ int ShuffleVectorInst::getMaskValue(unsigned i) const {
return cast<ConstantInt>(MaskCV->getOperand(i))->getZExtValue();
}
+//===----------------------------------------------------------------------===//
+// ExtractValueInst Class
+//===----------------------------------------------------------------------===//
+
+// getIndexedType - Returns the type of the element that would be extracted
+// with an extractvalue instruction with the specified parameters.
+//
+// A null type is returned if the indices are invalid for the specified
+// pointer type.
+//
+const Type* ExtractValueInst::getIndexedType(const Type *Agg,
+ Value* const *Idxs,
+ unsigned NumIdx) {
+ unsigned CurIdx = 0;
+ for (; CurIdx != NumIdx; ++CurIdx) {
+ const CompositeType *CT = dyn_cast<CompositeType>(Agg);
+ if (!CT) return 0;
+ Value *Index = Idxs[CurIdx];
+ if (!CT->indexValid(Index)) return 0;
+ Agg = CT->getTypeAtIndex(Index);
+
+ // If the new type forwards to another type, then it is in the middle
+ // of being refined to another type (and hence, may have dropped all
+ // references to what it was using before). So, use the new forwarded
+ // type.
+ if (const Type *Ty = Agg->getForwardedType())
+ Agg = Ty;
+ }
+ return CurIdx == NumIdx ? Agg : 0;
+}
//===----------------------------------------------------------------------===//
// BinaryOperator Class