@@ -6357,17 +6357,14 @@ bool llvm::isGEPBasedOnPointerToString(const GEPOperator *GEP,
63576357}
63586358
63596359// If V refers to an initialized global constant, set Slice either to
6360- // its initializer if the size of its elements equals ElementSize, or ,
6361- // for ElementSize == 8 , to its representation as an array of unsiged
6362- // char. Return true on success.
6363- // Offset is in the unit "nr of ElementSize sized elements".
6360+ // its initializer if the bit width of its elements equals ElementBitWidth ,
6361+ // or, for ElementBitWidth == CHAR_BIT , to its representation as an array
6362+ // of unsigned char. Return true on success.
6363+ // Offset is in the unit "nr of ElementBitWidth sized elements".
63646364bool llvm::getConstantDataArrayInfo (const Value *V,
63656365 ConstantDataArraySlice &Slice,
6366- unsigned ElementSize , uint64_t Offset) {
6366+ unsigned ElementBitWidth , uint64_t Offset) {
63676367 assert (V && " V should not be null." );
6368- assert ((ElementSize % 8 ) == 0 &&
6369- " ElementSize expected to be a multiple of the size of a byte." );
6370- unsigned ElementSizeInBytes = ElementSize / 8 ;
63716368
63726369 // Drill down into the pointer expression V, ignoring any intervening
63736370 // casts, and determine the identity of the object it references along
@@ -6379,6 +6376,11 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
63796376 return false ;
63806377
63816378 const DataLayout &DL = GV->getDataLayout ();
6379+ unsigned ByteWidth = DL.getByteWidth ();
6380+ assert ((ElementBitWidth % ByteWidth) == 0 &&
6381+ " ElementBitWidth is expected to be a multiple of the byte width" );
6382+ unsigned ElementSizeInBytes = ElementBitWidth / ByteWidth;
6383+
63826384 APInt Off (DL.getIndexTypeSizeInBits (V->getType ()), 0 );
63836385
63846386 if (GV != V->stripAndAccumulateConstantOffsets (DL, Off,
@@ -6418,7 +6420,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
64186420 auto *Init = const_cast <Constant *>(GV->getInitializer ());
64196421 if (auto *ArrayInit = dyn_cast<ConstantDataArray>(Init)) {
64206422 Type *InitElTy = ArrayInit->getElementType ();
6421- if (InitElTy->isIntegerTy (ElementSize )) {
6423+ if (InitElTy->isIntegerTy (ElementBitWidth )) {
64226424 // If Init is an initializer for an array of the expected type
64236425 // and size, use it as is.
64246426 Array = ArrayInit;
@@ -6427,7 +6429,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
64276429 }
64286430
64296431 if (!Array) {
6430- if (ElementSize != 8 )
6432+ if (ElementBitWidth != CHAR_BIT )
64316433 // TODO: Handle conversions to larger integral types.
64326434 return false ;
64336435
@@ -6505,9 +6507,9 @@ bool llvm::getConstantStringInfo(const Value *V, StringRef &Str,
65056507
65066508// / If we can compute the length of the string pointed to by
65076509// / the specified pointer, return 'len+1'. If we can't, return 0.
6508- static uint64_t GetStringLengthH (const Value *V,
6509- SmallPtrSetImpl<const PHINode*> &PHIs,
6510- unsigned CharSize ) {
6510+ static uint64_t getStringLength (const Value *V,
6511+ SmallPtrSetImpl<const PHINode *> &PHIs,
6512+ unsigned CharWidth ) {
65116513 // Look through noop bitcast instructions.
65126514 V = V->stripPointerCasts ();
65136515
@@ -6520,7 +6522,7 @@ static uint64_t GetStringLengthH(const Value *V,
65206522 // If it was new, see if all the input strings are the same length.
65216523 uint64_t LenSoFar = ~0ULL ;
65226524 for (Value *IncValue : PN->incoming_values ()) {
6523- uint64_t Len = GetStringLengthH (IncValue, PHIs, CharSize );
6525+ uint64_t Len = getStringLength (IncValue, PHIs, CharWidth );
65246526 if (Len == 0 ) return 0 ; // Unknown length -> unknown.
65256527
65266528 if (Len == ~0ULL ) continue ;
@@ -6536,9 +6538,9 @@ static uint64_t GetStringLengthH(const Value *V,
65366538
65376539 // strlen(select(c,x,y)) -> strlen(x) ^ strlen(y)
65386540 if (const SelectInst *SI = dyn_cast<SelectInst>(V)) {
6539- uint64_t Len1 = GetStringLengthH (SI->getTrueValue (), PHIs, CharSize );
6541+ uint64_t Len1 = getStringLength (SI->getTrueValue (), PHIs, CharWidth );
65406542 if (Len1 == 0 ) return 0 ;
6541- uint64_t Len2 = GetStringLengthH (SI->getFalseValue (), PHIs, CharSize );
6543+ uint64_t Len2 = getStringLength (SI->getFalseValue (), PHIs, CharWidth );
65426544 if (Len2 == 0 ) return 0 ;
65436545 if (Len1 == ~0ULL ) return Len2;
65446546 if (Len2 == ~0ULL ) return Len1;
@@ -6548,7 +6550,7 @@ static uint64_t GetStringLengthH(const Value *V,
65486550
65496551 // Otherwise, see if we can read the string.
65506552 ConstantDataArraySlice Slice;
6551- if (!getConstantDataArrayInfo (V, Slice, CharSize ))
6553+ if (!getConstantDataArrayInfo (V, Slice, CharWidth ))
65526554 return 0 ;
65536555
65546556 if (Slice.Array == nullptr )
@@ -6570,12 +6572,12 @@ static uint64_t GetStringLengthH(const Value *V,
65706572
65716573// / If we can compute the length of the string pointed to by
65726574// / the specified pointer, return 'len+1'. If we can't, return 0.
6573- uint64_t llvm::GetStringLength (const Value *V, unsigned CharSize ) {
6575+ uint64_t llvm::getStringLength (const Value *V, unsigned CharWidth ) {
65746576 if (!V->getType ()->isPointerTy ())
65756577 return 0 ;
65766578
65776579 SmallPtrSet<const PHINode*, 32 > PHIs;
6578- uint64_t Len = GetStringLengthH (V, PHIs, CharSize );
6580+ uint64_t Len = :: getStringLength (V, PHIs, CharWidth );
65796581 // If Len is ~0ULL, we had an infinite phi cycle: this is dead code, so return
65806582 // an empty string as a length.
65816583 return Len == ~0ULL ? 1 : Len;
0 commit comments