@@ -6392,17 +6392,14 @@ bool llvm::isGEPBasedOnPointerToString(const GEPOperator *GEP,
63926392}
63936393
63946394// If V refers to an initialized global constant, set Slice either to
6395- // its initializer if the size of its elements equals ElementSize, or ,
6396- // for ElementSize == 8 , to its representation as an array of unsiged
6397- // char. Return true on success.
6398- // Offset is in the unit "nr of ElementSize sized elements".
6395+ // its initializer if the bit width of its elements equals ElementBitWidth ,
6396+ // or, for ElementBitWidth == CHAR_BIT , to its representation as an array
6397+ // of unsigned char. Return true on success.
6398+ // Offset is in the unit "nr of ElementBitWidth sized elements".
63996399bool llvm::getConstantDataArrayInfo (const Value *V,
64006400 ConstantDataArraySlice &Slice,
6401- unsigned ElementSize , uint64_t Offset) {
6401+ unsigned ElementBitWidth , uint64_t Offset) {
64026402 assert (V && " V should not be null." );
6403- assert ((ElementSize % 8 ) == 0 &&
6404- " ElementSize expected to be a multiple of the size of a byte." );
6405- unsigned ElementSizeInBytes = ElementSize / 8 ;
64066403
64076404 // Drill down into the pointer expression V, ignoring any intervening
64086405 // casts, and determine the identity of the object it references along
@@ -6414,6 +6411,11 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
64146411 return false ;
64156412
64166413 const DataLayout &DL = GV->getDataLayout ();
6414+ unsigned ByteWidth = DL.getByteWidth ();
6415+ assert ((ElementBitWidth % ByteWidth) == 0 &&
6416+ " ElementBitWidth is expected to be a multiple of the byte width" );
6417+ unsigned ElementSizeInBytes = ElementBitWidth / ByteWidth;
6418+
64176419 APInt Off (DL.getIndexTypeSizeInBits (V->getType ()), 0 );
64186420
64196421 if (GV != V->stripAndAccumulateConstantOffsets (DL, Off,
@@ -6453,7 +6455,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
64536455 auto *Init = const_cast <Constant *>(GV->getInitializer ());
64546456 if (auto *ArrayInit = dyn_cast<ConstantDataArray>(Init)) {
64556457 Type *InitElTy = ArrayInit->getElementType ();
6456- if (InitElTy->isIntegerTy (ElementSize )) {
6458+ if (InitElTy->isIntegerTy (ElementBitWidth )) {
64576459 // If Init is an initializer for an array of the expected type
64586460 // and size, use it as is.
64596461 Array = ArrayInit;
@@ -6462,7 +6464,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
64626464 }
64636465
64646466 if (!Array) {
6465- if (ElementSize != 8 )
6467+ if (ElementBitWidth != CHAR_BIT )
64666468 // TODO: Handle conversions to larger integral types.
64676469 return false ;
64686470
@@ -6540,9 +6542,9 @@ bool llvm::getConstantStringInfo(const Value *V, StringRef &Str,
65406542
65416543// / If we can compute the length of the string pointed to by
65426544// / the specified pointer, return 'len+1'. If we can't, return 0.
6543- static uint64_t GetStringLengthH (const Value *V,
6544- SmallPtrSetImpl<const PHINode*> &PHIs,
6545- unsigned CharSize ) {
6545+ static uint64_t getStringLength (const Value *V,
6546+ SmallPtrSetImpl<const PHINode *> &PHIs,
6547+ unsigned CharWidth ) {
65466548 // Look through noop bitcast instructions.
65476549 V = V->stripPointerCasts ();
65486550
@@ -6555,7 +6557,7 @@ static uint64_t GetStringLengthH(const Value *V,
65556557 // If it was new, see if all the input strings are the same length.
65566558 uint64_t LenSoFar = ~0ULL ;
65576559 for (Value *IncValue : PN->incoming_values ()) {
6558- uint64_t Len = GetStringLengthH (IncValue, PHIs, CharSize );
6560+ uint64_t Len = getStringLength (IncValue, PHIs, CharWidth );
65596561 if (Len == 0 ) return 0 ; // Unknown length -> unknown.
65606562
65616563 if (Len == ~0ULL ) continue ;
@@ -6571,9 +6573,9 @@ static uint64_t GetStringLengthH(const Value *V,
65716573
65726574 // strlen(select(c,x,y)) -> strlen(x) ^ strlen(y)
65736575 if (const SelectInst *SI = dyn_cast<SelectInst>(V)) {
6574- uint64_t Len1 = GetStringLengthH (SI->getTrueValue (), PHIs, CharSize );
6576+ uint64_t Len1 = getStringLength (SI->getTrueValue (), PHIs, CharWidth );
65756577 if (Len1 == 0 ) return 0 ;
6576- uint64_t Len2 = GetStringLengthH (SI->getFalseValue (), PHIs, CharSize );
6578+ uint64_t Len2 = getStringLength (SI->getFalseValue (), PHIs, CharWidth );
65776579 if (Len2 == 0 ) return 0 ;
65786580 if (Len1 == ~0ULL ) return Len2;
65796581 if (Len2 == ~0ULL ) return Len1;
@@ -6583,7 +6585,7 @@ static uint64_t GetStringLengthH(const Value *V,
65836585
65846586 // Otherwise, see if we can read the string.
65856587 ConstantDataArraySlice Slice;
6586- if (!getConstantDataArrayInfo (V, Slice, CharSize ))
6588+ if (!getConstantDataArrayInfo (V, Slice, CharWidth ))
65876589 return 0 ;
65886590
65896591 if (Slice.Array == nullptr )
@@ -6605,12 +6607,12 @@ static uint64_t GetStringLengthH(const Value *V,
66056607
66066608// / If we can compute the length of the string pointed to by
66076609// / the specified pointer, return 'len+1'. If we can't, return 0.
6608- uint64_t llvm::GetStringLength (const Value *V, unsigned CharSize ) {
6610+ uint64_t llvm::getStringLength (const Value *V, unsigned CharWidth ) {
66096611 if (!V->getType ()->isPointerTy ())
66106612 return 0 ;
66116613
66126614 SmallPtrSet<const PHINode*, 32 > PHIs;
6613- uint64_t Len = GetStringLengthH (V, PHIs, CharSize );
6615+ uint64_t Len = :: getStringLength (V, PHIs, CharWidth );
66146616 // If Len is ~0ULL, we had an infinite phi cycle: this is dead code, so return
66156617 // an empty string as a length.
66166618 return Len == ~0ULL ? 1 : Len;
0 commit comments