@@ -6637,17 +6637,14 @@ bool llvm::isGEPBasedOnPointerToString(const GEPOperator *GEP,
66376637}
66386638
66396639// If V refers to an initialized global constant, set Slice either to
6640- // its initializer if the size of its elements equals ElementSize, or ,
6641- // for ElementSize == 8 , to its representation as an array of unsiged
6642- // char. Return true on success.
6643- // Offset is in the unit "nr of ElementSize sized elements".
6640+ // its initializer if the bit width of its elements equals ElementBitWidth ,
6641+ // or, for ElementBitWidth == CHAR_BIT , to its representation as an array
6642+ // of unsigned char. Return true on success.
6643+ // Offset is in the unit "nr of ElementBitWidth sized elements".
66446644bool llvm::getConstantDataArrayInfo (const Value *V,
66456645 ConstantDataArraySlice &Slice,
6646- unsigned ElementSize , uint64_t Offset) {
6646+ unsigned ElementBitWidth , uint64_t Offset) {
66476647 assert (V && " V should not be null." );
6648- assert ((ElementSize % 8 ) == 0 &&
6649- " ElementSize expected to be a multiple of the size of a byte." );
6650- unsigned ElementSizeInBytes = ElementSize / 8 ;
66516648
66526649 // Drill down into the pointer expression V, ignoring any intervening
66536650 // casts, and determine the identity of the object it references along
@@ -6659,6 +6656,11 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
66596656 return false ;
66606657
66616658 const DataLayout &DL = GV->getDataLayout ();
6659+ unsigned ByteWidth = DL.getByteWidth ();
6660+ assert ((ElementBitWidth % ByteWidth) == 0 &&
6661+ " ElementBitWidth is expected to be a multiple of the byte width" );
6662+ unsigned ElementSizeInBytes = ElementBitWidth / ByteWidth;
6663+
66626664 APInt Off (DL.getIndexTypeSizeInBits (V->getType ()), 0 );
66636665
66646666 if (GV != V->stripAndAccumulateConstantOffsets (DL, Off,
@@ -6698,7 +6700,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
66986700 auto *Init = const_cast <Constant *>(GV->getInitializer ());
66996701 if (auto *ArrayInit = dyn_cast<ConstantDataArray>(Init)) {
67006702 Type *InitElTy = ArrayInit->getElementType ();
6701- if (InitElTy->isIntegerTy (ElementSize )) {
6703+ if (InitElTy->isIntegerTy (ElementBitWidth )) {
67026704 // If Init is an initializer for an array of the expected type
67036705 // and size, use it as is.
67046706 Array = ArrayInit;
@@ -6707,7 +6709,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
67076709 }
67086710
67096711 if (!Array) {
6710- if (ElementSize != 8 )
6712+ if (ElementBitWidth != CHAR_BIT )
67116713 // TODO: Handle conversions to larger integral types.
67126714 return false ;
67136715
@@ -6785,9 +6787,9 @@ bool llvm::getConstantStringInfo(const Value *V, StringRef &Str,
67856787
67866788// / If we can compute the length of the string pointed to by
67876789// / the specified pointer, return 'len+1'. If we can't, return 0.
6788- static uint64_t GetStringLengthH (const Value *V,
6789- SmallPtrSetImpl<const PHINode*> &PHIs,
6790- unsigned CharSize ) {
6790+ static uint64_t getStringLength (const Value *V,
6791+ SmallPtrSetImpl<const PHINode *> &PHIs,
6792+ unsigned CharWidth ) {
67916793 // Look through noop bitcast instructions.
67926794 V = V->stripPointerCasts ();
67936795
@@ -6800,7 +6802,7 @@ static uint64_t GetStringLengthH(const Value *V,
68006802 // If it was new, see if all the input strings are the same length.
68016803 uint64_t LenSoFar = ~0ULL ;
68026804 for (Value *IncValue : PN->incoming_values ()) {
6803- uint64_t Len = GetStringLengthH (IncValue, PHIs, CharSize );
6805+ uint64_t Len = getStringLength (IncValue, PHIs, CharWidth );
68046806 if (Len == 0 ) return 0 ; // Unknown length -> unknown.
68056807
68066808 if (Len == ~0ULL ) continue ;
@@ -6816,9 +6818,9 @@ static uint64_t GetStringLengthH(const Value *V,
68166818
68176819 // strlen(select(c,x,y)) -> strlen(x) ^ strlen(y)
68186820 if (const SelectInst *SI = dyn_cast<SelectInst>(V)) {
6819- uint64_t Len1 = GetStringLengthH (SI->getTrueValue (), PHIs, CharSize );
6821+ uint64_t Len1 = getStringLength (SI->getTrueValue (), PHIs, CharWidth );
68206822 if (Len1 == 0 ) return 0 ;
6821- uint64_t Len2 = GetStringLengthH (SI->getFalseValue (), PHIs, CharSize );
6823+ uint64_t Len2 = getStringLength (SI->getFalseValue (), PHIs, CharWidth );
68226824 if (Len2 == 0 ) return 0 ;
68236825 if (Len1 == ~0ULL ) return Len2;
68246826 if (Len2 == ~0ULL ) return Len1;
@@ -6828,7 +6830,7 @@ static uint64_t GetStringLengthH(const Value *V,
68286830
68296831 // Otherwise, see if we can read the string.
68306832 ConstantDataArraySlice Slice;
6831- if (!getConstantDataArrayInfo (V, Slice, CharSize ))
6833+ if (!getConstantDataArrayInfo (V, Slice, CharWidth ))
68326834 return 0 ;
68336835
68346836 if (Slice.Array == nullptr )
@@ -6850,12 +6852,12 @@ static uint64_t GetStringLengthH(const Value *V,
68506852
68516853// / If we can compute the length of the string pointed to by
68526854// / the specified pointer, return 'len+1'. If we can't, return 0.
6853- uint64_t llvm::GetStringLength (const Value *V, unsigned CharSize ) {
6855+ uint64_t llvm::getStringLength (const Value *V, unsigned CharWidth ) {
68546856 if (!V->getType ()->isPointerTy ())
68556857 return 0 ;
68566858
68576859 SmallPtrSet<const PHINode*, 32 > PHIs;
6858- uint64_t Len = GetStringLengthH (V, PHIs, CharSize );
6860+ uint64_t Len = :: getStringLength (V, PHIs, CharWidth );
68596861 // If Len is ~0ULL, we had an infinite phi cycle: this is dead code, so return
68606862 // an empty string as a length.
68616863 return Len == ~0ULL ? 1 : Len;
0 commit comments