1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[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.

llvm-svn: 350835
This commit is contained in:
James Y Knight 2019-01-10 16:07:20 +00:00
parent 841e3b1050
commit 8a32a5595a
13 changed files with 49 additions and 61 deletions

View File

@ -3720,16 +3720,16 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
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 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
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())

View File

@ -7915,19 +7915,19 @@ void SelectionDAGBuilder::visitInlineAsm(ImmutableCallSite CS) {
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++) {

View File

@ -1778,17 +1778,14 @@ void Interpreter::visitExtractElementInst(ExtractElementInst &I) {
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::visitInsertElementInst(InsertElementInst &I) {
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 @@ void Interpreter::visitShuffleVectorInst(ShuffleVectorInst &I){
// 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();

View File

@ -103,8 +103,9 @@ static ExFunc lookupFunction(const Function *F) {
// 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);

View File

@ -1999,9 +1999,8 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
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))

View File

@ -257,7 +257,7 @@ static bool containsGCPtrType(Type *Ty) {
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;
}

View File

@ -163,7 +163,7 @@ bool AMDGPURewriteOutArguments::checkArgumentUses(Value &Arg) const {
// 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 @@ bool AMDGPURewriteOutArguments::runOnFunction(Function &F) {
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) !=

View File

@ -1775,11 +1775,8 @@ bool HexagonTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info,
// 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

View File

@ -74,16 +74,18 @@ static FPReturnVariant whichFPReturnVariant(Type *T) {
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;
}

View File

@ -386,27 +386,22 @@ const char* Mips16TargetLowering::
}
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 "";

View File

@ -3230,8 +3230,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
}
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);
}

View File

@ -347,7 +347,7 @@ static bool containsGCPtrType(Type *Ty) {
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;
}

View File

@ -356,8 +356,8 @@ struct StoreModifier: public Modifier {
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