llvm.org GIT mirror llvm / 719df2e
[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 James Y Knight 8 months ago
13 changed file(s) with 49 addition(s) and 61 deletion(s). Raw diff Collapse all Expand all
37193719 return error("EXTRACTVAL: Invalid type");
37203720 if ((unsigned)Index != Index)
37213721 return error("Invalid value");
3722 if (IsStruct && Index >= CurTy->subtypes().size())
3722 if (IsStruct && Index >= CurTy->getStructNumElements())
37233723 return error("EXTRACTVAL: Invalid struct index");
37243724 if (IsArray && Index >= CurTy->getArrayNumElements())
37253725 return error("EXTRACTVAL: Invalid array index");
37263726 EXTRACTVALIdx.push_back((unsigned)Index);
37273727
37283728 if (IsStruct)
3729 CurTy = CurTy->subtypes()[Index];
3729 CurTy = CurTy->getStructElementType(Index);
37303730 else
3731 CurTy = CurTy->subtypes()[0];
3731 CurTy = CurTy->getArrayElementType();
37323732 }
37333733
37343734 I = ExtractValueInst::Create(Agg, EXTRACTVALIdx);
37613761 return error("INSERTVAL: Invalid type");
37623762 if ((unsigned)Index != Index)
37633763 return error("Invalid value");
3764 if (IsStruct && Index >= CurTy->subtypes().size())
3764 if (IsStruct && Index >= CurTy->getStructNumElements())
37653765 return error("INSERTVAL: Invalid struct index");
37663766 if (IsArray && Index >= CurTy->getArrayNumElements())
37673767 return error("INSERTVAL: Invalid array index");
37683768
37693769 INSERTVALIdx.push_back((unsigned)Index);
37703770 if (IsStruct)
3771 CurTy = CurTy->subtypes()[Index];
3771 CurTy = CurTy->getStructElementType(Index);
37723772 else
3773 CurTy = CurTy->subtypes()[0];
3773 CurTy = CurTy->getArrayElementType();
37743774 }
37753775
37763776 if (CurTy != Val->getType())
79147914 unsigned numRet;
79157915 ArrayRef ResultTypes;
79167916 SmallVector ResultValues(1);
7917 if (CSResultType->isSingleValueType()) {
7918 numRet = 1;
7919 ResultValues[0] = Val;
7920 ResultTypes = makeArrayRef(CSResultType);
7921 } else {
7922 numRet = CSResultType->getNumContainedTypes();
7917 if (StructType *StructResult = dyn_cast(CSResultType)) {
7918 numRet = StructResult->getNumElements();
79237919 assert(Val->getNumOperands() == numRet &&
79247920 "Mismatch in number of output operands in asm result");
7925 ResultTypes = CSResultType->subtypes();
7921 ResultTypes = StructResult->elements();
79267922 ArrayRef ValueUses = Val->ops();
79277923 ResultValues.resize(numRet);
79287924 std::transform(ValueUses.begin(), ValueUses.end(), ResultValues.begin(),
79297925 [](const SDUse &u) -> SDValue { return u.get(); });
7926 } else {
7927 numRet = 1;
7928 ResultValues[0] = Val;
7929 ResultTypes = makeArrayRef(CSResultType);
79307930 }
79317931 SmallVector ResultVTs(numRet);
79327932 for (unsigned i = 0; i < numRet; i++) {
17771777
17781778 void Interpreter::visitInsertElementInst(InsertElementInst &I) {
17791779 ExecutionContext &SF = ECStack.back();
1780 Type *Ty = I.getType();
1781
1782 if(!(Ty->isVectorTy()) )
1783 llvm_unreachable("Unhandled dest type for insertelement instruction");
1780 VectorType *Ty = cast(I.getType());
17841781
17851782 GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
17861783 GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
17871784 GenericValue Src3 = getOperandValue(I.getOperand(2), SF);
17881785 GenericValue Dest;
17891786
1790 Type *TyContained = Ty->getContainedType(0);
1787 Type *TyContained = Ty->getElementType();
17911788
17921789 const unsigned indx = unsigned(Src3.IntVal.getZExtValue());
17931790 Dest.AggregateVal = Src1.AggregateVal;
18131810 void Interpreter::visitShuffleVectorInst(ShuffleVectorInst &I){
18141811 ExecutionContext &SF = ECStack.back();
18151812
1816 Type *Ty = I.getType();
1817 if(!(Ty->isVectorTy()))
1818 llvm_unreachable("Unhandled dest type for shufflevector instruction");
1813 VectorType *Ty = cast(I.getType());
18191814
18201815 GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
18211816 GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
18261821 // bytecode can't contain different types for src1 and src2 for a
18271822 // shufflevector instruction.
18281823
1829 Type *TyContained = Ty->getContainedType(0);
1824 Type *TyContained = Ty->getElementType();
18301825 unsigned src1Size = (unsigned)Src1.AggregateVal.size();
18311826 unsigned src2Size = (unsigned)Src2.AggregateVal.size();
18321827 unsigned src3Size = (unsigned)Src3.AggregateVal.size();
102102 // composite function name should be.
103103 std::string ExtName = "lle_";
104104 FunctionType *FT = F->getFunctionType();
105 for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i)
106 ExtName += getTypeID(FT->getContainedType(i));
105 ExtName += getTypeID(FT->getReturnType());
106 for (Type *T : FT->params())
107 ExtName += getTypeID(T);
107108 ExtName += ("_" + F->getName()).str();
108109
109110 sys::ScopedLock Writer(*FunctionsLock);
19981998 if (!Ty)
19991999 Ty = cast(C->getType()->getScalarType())->getElementType();
20002000 else
2001 assert(
2002 Ty ==
2003 cast(C->getType()->getScalarType())->getContainedType(0u));
2001 assert(Ty ==
2002 cast(C->getType()->getScalarType())->getElementType());
20042003
20052004 if (Constant *FC =
20062005 ConstantFoldGetElementPtr(Ty, C, InBounds, InRangeIndex, Idxs))
256256 if (ArrayType *AT = dyn_cast(Ty))
257257 return containsGCPtrType(AT->getElementType());
258258 if (StructType *ST = dyn_cast(Ty))
259 return llvm::any_of(ST->subtypes(), containsGCPtrType);
259 return llvm::any_of(ST->elements(), containsGCPtrType);
260260 return false;
261261 }
262262
162162 // some casts between structs and non-structs, but we can't bitcast
163163 // directly between them. directly bitcast between them. Blender uses
164164 // some casts that look like { <3 x float> }* to <4 x float>*
165 if ((SrcEltTy->isStructTy() && (SrcEltTy->getNumContainedTypes() != 1)))
165 if ((SrcEltTy->isStructTy() && (SrcEltTy->getStructNumElements() != 1)))
166166 return false;
167167
168168 // Clang emits OpenCL 3-vector type accesses with a bitcast to the
400400 if (Val->getType() != EltTy) {
401401 Type *EffectiveEltTy = EltTy;
402402 if (StructType *CT = dyn_cast(EltTy)) {
403 assert(CT->getNumContainedTypes() == 1);
404 EffectiveEltTy = CT->getContainedType(0);
403 assert(CT->getNumElements() == 1);
404 EffectiveEltTy = CT->getElementType(0);
405405 }
406406
407407 if (DL->getTypeSizeInBits(EffectiveEltTy) !=
17741774 // The intrinsic function call is of the form { ElTy, i8* }
17751775 // @llvm.hexagon.L2.loadXX.pbr(i8*, i32). The pointer and memory access type
17761776 // should be derived from ElTy.
1777 PointerType *PtrTy = I.getCalledFunction()
1778 ->getReturnType()
1779 ->getContainedType(0)
1780 ->getPointerTo();
1781 Info.memVT = MVT::getVT(PtrTy->getElementType());
1777 Type *ElTy = I.getCalledFunction()->getReturnType()->getStructElementType(0);
1778 Info.memVT = MVT::getVT(ElTy);
17821779 llvm::Value *BasePtrVal = I.getOperand(0);
17831780 Info.ptrVal = getUnderLyingObjectForBrevLdIntr(BasePtrVal);
17841781 // The offset value comes through Modifier register. For now, assume the
7373 return FRet;
7474 case Type::DoubleTyID:
7575 return DRet;
76 case Type::StructTyID:
77 if (T->getStructNumElements() != 2)
76 case Type::StructTyID: {
77 StructType *ST = cast(T);
78 if (ST->getNumElements() != 2)
7879 break;
79 if ((T->getContainedType(0)->isFloatTy()) &&
80 (T->getContainedType(1)->isFloatTy()))
80 if ((ST->getElementType(0)->isFloatTy()) &&
81 (ST->getElementType(1)->isFloatTy()))
8182 return CFRet;
82 if ((T->getContainedType(0)->isDoubleTy()) &&
83 (T->getContainedType(1)->isDoubleTy()))
83 if ((ST->getElementType(0)->isDoubleTy()) &&
84 (ST->getElementType(1)->isDoubleTy()))
8485 return CDRet;
8586 break;
87 }
8688 default:
8789 break;
8890 }
385385 }
386386 else if (RetTy ->isDoubleTy()) {
387387 result = dfMips16Helper[stubNum];
388 }
389 else if (RetTy->isStructTy()) {
388 } else if (StructType *SRetTy = dyn_cast(RetTy)) {
390389 // check if it's complex
391 if (RetTy->getNumContainedTypes() == 2) {
392 if ((RetTy->getContainedType(0)->isFloatTy()) &&
393 (RetTy->getContainedType(1)->isFloatTy())) {
390 if (SRetTy->getNumElements() == 2) {
391 if ((SRetTy->getElementType(0)->isFloatTy()) &&
392 (SRetTy->getElementType(1)->isFloatTy())) {
394393 result = scMips16Helper[stubNum];
395 }
396 else if ((RetTy->getContainedType(0)->isDoubleTy()) &&
397 (RetTy->getContainedType(1)->isDoubleTy())) {
394 } else if ((SRetTy->getElementType(0)->isDoubleTy()) &&
395 (SRetTy->getElementType(1)->isDoubleTy())) {
398396 result = dcMips16Helper[stubNum];
399 }
400 else {
397 } else {
401398 llvm_unreachable("Uncovered condition");
402399 }
403 }
404 else {
400 } else {
405401 llvm_unreachable("Uncovered condition");
406402 }
407 }
408 else {
403 } else {
409404 if (stubNum == 0) {
410405 needHelper = false;
411406 return "";
32293229 }
32303230 LLVM_DEBUG(dbgs() << " done with call args\n");
32313231
3232 FunctionType *FT =
3233 cast(CS.getCalledValue()->getType()->getContainedType(0));
3232 FunctionType *FT = CS.getFunctionType();
32343233 if (FT->isVarArg()) {
32353234 VAHelper->visitCallSite(CS, IRB);
32363235 }
346346 if (ArrayType *AT = dyn_cast(Ty))
347347 return containsGCPtrType(AT->getElementType());
348348 if (StructType *ST = dyn_cast(Ty))
349 return llvm::any_of(ST->subtypes(), containsGCPtrType);
349 return llvm::any_of(ST->elements(), containsGCPtrType);
350350 return false;
351351 }
352352
355355 void Act() override {
356356 // Try to use predefined pointers. If non-exist, use undef pointer value;
357357 Value *Ptr = getRandomPointerValue();
358 Type *Tp = Ptr->getType();
359 Value *Val = getRandomValue(Tp->getContainedType(0));
358 PointerType *Tp = Ptr->getType();
359 Value *Val = getRandomValue(Tp->getElementType());
360360 Type *ValTy = Val->getType();
361361
362362 // Do not store vectors of i1s because they are unsupported