[opaque pointer types] Remove some calls to generic Type subtype accessors.
That is, remove many of the calls to Type::getNumContainedTypes(),
Type::subtypes(), and Type::getContainedType(N).
I'm not intending to remove these accessors -- they are
useful/necessary in some cases. However, removing the pointee type
from pointers would potentially break some uses, and reducing the
number of calls makes it easier to audit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350835 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 846ce3a..2f3d2f3 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3720,16 +3720,16 @@
return error("EXTRACTVAL: Invalid type");
if ((unsigned)Index != Index)
return error("Invalid value");
- if (IsStruct && Index >= CurTy->subtypes().size())
+ if (IsStruct && Index >= CurTy->getStructNumElements())
return error("EXTRACTVAL: Invalid struct index");
if (IsArray && Index >= CurTy->getArrayNumElements())
return error("EXTRACTVAL: Invalid array index");
EXTRACTVALIdx.push_back((unsigned)Index);
if (IsStruct)
- CurTy = CurTy->subtypes()[Index];
+ CurTy = CurTy->getStructElementType(Index);
else
- CurTy = CurTy->subtypes()[0];
+ CurTy = CurTy->getArrayElementType();
}
I = ExtractValueInst::Create(Agg, EXTRACTVALIdx);
@@ -3762,16 +3762,16 @@
return error("INSERTVAL: Invalid type");
if ((unsigned)Index != Index)
return error("Invalid value");
- if (IsStruct && Index >= CurTy->subtypes().size())
+ if (IsStruct && Index >= CurTy->getStructNumElements())
return error("INSERTVAL: Invalid struct index");
if (IsArray && Index >= CurTy->getArrayNumElements())
return error("INSERTVAL: Invalid array index");
INSERTVALIdx.push_back((unsigned)Index);
if (IsStruct)
- CurTy = CurTy->subtypes()[Index];
+ CurTy = CurTy->getStructElementType(Index);
else
- CurTy = CurTy->subtypes()[0];
+ CurTy = CurTy->getArrayElementType();
}
if (CurTy != Val->getType())
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index d64b96b..9350084 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -7915,19 +7915,19 @@
unsigned numRet;
ArrayRef<Type *> ResultTypes;
SmallVector<SDValue, 1> ResultValues(1);
- if (CSResultType->isSingleValueType()) {
- numRet = 1;
- ResultValues[0] = Val;
- ResultTypes = makeArrayRef(CSResultType);
- } else {
- numRet = CSResultType->getNumContainedTypes();
+ if (StructType *StructResult = dyn_cast<StructType>(CSResultType)) {
+ numRet = StructResult->getNumElements();
assert(Val->getNumOperands() == numRet &&
"Mismatch in number of output operands in asm result");
- ResultTypes = CSResultType->subtypes();
+ ResultTypes = StructResult->elements();
ArrayRef<SDUse> ValueUses = Val->ops();
ResultValues.resize(numRet);
std::transform(ValueUses.begin(), ValueUses.end(), ResultValues.begin(),
[](const SDUse &u) -> SDValue { return u.get(); });
+ } else {
+ numRet = 1;
+ ResultValues[0] = Val;
+ ResultTypes = makeArrayRef(CSResultType);
}
SmallVector<EVT, 1> ResultVTs(numRet);
for (unsigned i = 0; i < numRet; i++) {
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index 39cf6d4..98dca11 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -1778,17 +1778,14 @@
void Interpreter::visitInsertElementInst(InsertElementInst &I) {
ExecutionContext &SF = ECStack.back();
- Type *Ty = I.getType();
-
- if(!(Ty->isVectorTy()) )
- llvm_unreachable("Unhandled dest type for insertelement instruction");
+ VectorType *Ty = cast<VectorType>(I.getType());
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
GenericValue Src3 = getOperandValue(I.getOperand(2), SF);
GenericValue Dest;
- Type *TyContained = Ty->getContainedType(0);
+ Type *TyContained = Ty->getElementType();
const unsigned indx = unsigned(Src3.IntVal.getZExtValue());
Dest.AggregateVal = Src1.AggregateVal;
@@ -1814,9 +1811,7 @@
void Interpreter::visitShuffleVectorInst(ShuffleVectorInst &I){
ExecutionContext &SF = ECStack.back();
- Type *Ty = I.getType();
- if(!(Ty->isVectorTy()))
- llvm_unreachable("Unhandled dest type for shufflevector instruction");
+ VectorType *Ty = cast<VectorType>(I.getType());
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
@@ -1827,7 +1822,7 @@
// bytecode can't contain different types for src1 and src2 for a
// shufflevector instruction.
- Type *TyContained = Ty->getContainedType(0);
+ Type *TyContained = Ty->getElementType();
unsigned src1Size = (unsigned)Src1.AggregateVal.size();
unsigned src2Size = (unsigned)Src2.AggregateVal.size();
unsigned src3Size = (unsigned)Src3.AggregateVal.size();
diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 044d9b7..334fcac 100644
--- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -103,8 +103,9 @@
// composite function name should be.
std::string ExtName = "lle_";
FunctionType *FT = F->getFunctionType();
- for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i)
- ExtName += getTypeID(FT->getContainedType(i));
+ ExtName += getTypeID(FT->getReturnType());
+ for (Type *T : FT->params())
+ ExtName += getTypeID(T);
ExtName += ("_" + F->getName()).str();
sys::ScopedLock Writer(*FunctionsLock);
diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp
index df09d13..d36967f 100644
--- a/lib/IR/Constants.cpp
+++ b/lib/IR/Constants.cpp
@@ -1999,9 +1999,8 @@
if (!Ty)
Ty = cast<PointerType>(C->getType()->getScalarType())->getElementType();
else
- assert(
- Ty ==
- cast<PointerType>(C->getType()->getScalarType())->getContainedType(0u));
+ assert(Ty ==
+ cast<PointerType>(C->getType()->getScalarType())->getElementType());
if (Constant *FC =
ConstantFoldGetElementPtr(Ty, C, InBounds, InRangeIndex, Idxs))
diff --git a/lib/IR/SafepointIRVerifier.cpp b/lib/IR/SafepointIRVerifier.cpp
index 3596b31..12ada13 100644
--- a/lib/IR/SafepointIRVerifier.cpp
+++ b/lib/IR/SafepointIRVerifier.cpp
@@ -257,7 +257,7 @@
if (ArrayType *AT = dyn_cast<ArrayType>(Ty))
return containsGCPtrType(AT->getElementType());
if (StructType *ST = dyn_cast<StructType>(Ty))
- return llvm::any_of(ST->subtypes(), containsGCPtrType);
+ return llvm::any_of(ST->elements(), containsGCPtrType);
return false;
}
diff --git a/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp b/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
index a861762..efe501c 100644
--- a/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
+++ b/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
@@ -163,7 +163,7 @@
// some casts between structs and non-structs, but we can't bitcast
// directly between them. directly bitcast between them. Blender uses
// some casts that look like { <3 x float> }* to <4 x float>*
- if ((SrcEltTy->isStructTy() && (SrcEltTy->getNumContainedTypes() != 1)))
+ if ((SrcEltTy->isStructTy() && (SrcEltTy->getStructNumElements() != 1)))
return false;
// Clang emits OpenCL 3-vector type accesses with a bitcast to the
@@ -401,8 +401,8 @@
if (Val->getType() != EltTy) {
Type *EffectiveEltTy = EltTy;
if (StructType *CT = dyn_cast<StructType>(EltTy)) {
- assert(CT->getNumContainedTypes() == 1);
- EffectiveEltTy = CT->getContainedType(0);
+ assert(CT->getNumElements() == 1);
+ EffectiveEltTy = CT->getElementType(0);
}
if (DL->getTypeSizeInBits(EffectiveEltTy) !=
diff --git a/lib/Target/Hexagon/HexagonISelLowering.cpp b/lib/Target/Hexagon/HexagonISelLowering.cpp
index fffacff..1edf3e4 100644
--- a/lib/Target/Hexagon/HexagonISelLowering.cpp
+++ b/lib/Target/Hexagon/HexagonISelLowering.cpp
@@ -1775,11 +1775,8 @@
// The intrinsic function call is of the form { ElTy, i8* }
// @llvm.hexagon.L2.loadXX.pbr(i8*, i32). The pointer and memory access type
// should be derived from ElTy.
- PointerType *PtrTy = I.getCalledFunction()
- ->getReturnType()
- ->getContainedType(0)
- ->getPointerTo();
- Info.memVT = MVT::getVT(PtrTy->getElementType());
+ Type *ElTy = I.getCalledFunction()->getReturnType()->getStructElementType(0);
+ Info.memVT = MVT::getVT(ElTy);
llvm::Value *BasePtrVal = I.getOperand(0);
Info.ptrVal = getUnderLyingObjectForBrevLdIntr(BasePtrVal);
// The offset value comes through Modifier register. For now, assume the
diff --git a/lib/Target/Mips/Mips16HardFloat.cpp b/lib/Target/Mips/Mips16HardFloat.cpp
index c310d94..f237bb6 100644
--- a/lib/Target/Mips/Mips16HardFloat.cpp
+++ b/lib/Target/Mips/Mips16HardFloat.cpp
@@ -74,16 +74,18 @@
return FRet;
case Type::DoubleTyID:
return DRet;
- case Type::StructTyID:
- if (T->getStructNumElements() != 2)
+ case Type::StructTyID: {
+ StructType *ST = cast<StructType>(T);
+ if (ST->getNumElements() != 2)
break;
- if ((T->getContainedType(0)->isFloatTy()) &&
- (T->getContainedType(1)->isFloatTy()))
+ if ((ST->getElementType(0)->isFloatTy()) &&
+ (ST->getElementType(1)->isFloatTy()))
return CFRet;
- if ((T->getContainedType(0)->isDoubleTy()) &&
- (T->getContainedType(1)->isDoubleTy()))
+ if ((ST->getElementType(0)->isDoubleTy()) &&
+ (ST->getElementType(1)->isDoubleTy()))
return CDRet;
break;
+ }
default:
break;
}
diff --git a/lib/Target/Mips/Mips16ISelLowering.cpp b/lib/Target/Mips/Mips16ISelLowering.cpp
index 8ce47e3..79df622 100644
--- a/lib/Target/Mips/Mips16ISelLowering.cpp
+++ b/lib/Target/Mips/Mips16ISelLowering.cpp
@@ -386,27 +386,22 @@
}
else if (RetTy ->isDoubleTy()) {
result = dfMips16Helper[stubNum];
- }
- else if (RetTy->isStructTy()) {
+ } else if (StructType *SRetTy = dyn_cast<StructType>(RetTy)) {
// check if it's complex
- if (RetTy->getNumContainedTypes() == 2) {
- if ((RetTy->getContainedType(0)->isFloatTy()) &&
- (RetTy->getContainedType(1)->isFloatTy())) {
+ if (SRetTy->getNumElements() == 2) {
+ if ((SRetTy->getElementType(0)->isFloatTy()) &&
+ (SRetTy->getElementType(1)->isFloatTy())) {
result = scMips16Helper[stubNum];
- }
- else if ((RetTy->getContainedType(0)->isDoubleTy()) &&
- (RetTy->getContainedType(1)->isDoubleTy())) {
+ } else if ((SRetTy->getElementType(0)->isDoubleTy()) &&
+ (SRetTy->getElementType(1)->isDoubleTy())) {
result = dcMips16Helper[stubNum];
- }
- else {
+ } else {
llvm_unreachable("Uncovered condition");
}
- }
- else {
+ } else {
llvm_unreachable("Uncovered condition");
}
- }
- else {
+ } else {
if (stubNum == 0) {
needHelper = false;
return "";
diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 493d22a..e6573af 100644
--- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -3230,8 +3230,7 @@
}
LLVM_DEBUG(dbgs() << " done with call args\n");
- FunctionType *FT =
- cast<FunctionType>(CS.getCalledValue()->getType()->getContainedType(0));
+ FunctionType *FT = CS.getFunctionType();
if (FT->isVarArg()) {
VAHelper->visitCallSite(CS, IRB);
}
diff --git a/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index cf2ce03..42d7ed5 100644
--- a/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -347,7 +347,7 @@
if (ArrayType *AT = dyn_cast<ArrayType>(Ty))
return containsGCPtrType(AT->getElementType());
if (StructType *ST = dyn_cast<StructType>(Ty))
- return llvm::any_of(ST->subtypes(), containsGCPtrType);
+ return llvm::any_of(ST->elements(), containsGCPtrType);
return false;
}
diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp
index d8ec112..f7aff19 100644
--- a/tools/llvm-stress/llvm-stress.cpp
+++ b/tools/llvm-stress/llvm-stress.cpp
@@ -356,8 +356,8 @@
void Act() override {
// Try to use predefined pointers. If non-exist, use undef pointer value;
Value *Ptr = getRandomPointerValue();
- Type *Tp = Ptr->getType();
- Value *Val = getRandomValue(Tp->getContainedType(0));
+ PointerType *Tp = Ptr->getType();
+ Value *Val = getRandomValue(Tp->getElementType());
Type *ValTy = Val->getType();
// Do not store vectors of i1s because they are unsupported