@@ -6528,17 +6528,14 @@ llvm::FindInsertedValue(Value *V, ArrayRef<unsigned> idx_range,
65286528}
65296529
65306530// If V refers to an initialized global constant, set Slice either to
6531- // its initializer if the size of its elements equals ElementSize, or ,
6532- // for ElementSize == 8 , to its representation as an array of unsiged
6533- // char. Return true on success.
6534- // Offset is in the unit "nr of ElementSize sized elements".
6531+ // its initializer if the bit width of its elements equals ElementBitWidth ,
6532+ // or, for ElementBitWidth == CHAR_BIT , to its representation as an array
6533+ // of unsigned char. Return true on success.
6534+ // Offset is in the unit "nr of ElementBitWidth sized elements".
65356535bool llvm::getConstantDataArrayInfo (const Value *V,
65366536 ConstantDataArraySlice &Slice,
6537- unsigned ElementSize , uint64_t Offset) {
6537+ unsigned ElementBitWidth , uint64_t Offset) {
65386538 assert (V && " V should not be null." );
6539- assert ((ElementSize % 8 ) == 0 &&
6540- " ElementSize expected to be a multiple of the size of a byte." );
6541- unsigned ElementSizeInBytes = ElementSize / 8 ;
65426539
65436540 // Drill down into the pointer expression V, ignoring any intervening
65446541 // casts, and determine the identity of the object it references along
@@ -6550,6 +6547,11 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
65506547 return false ;
65516548
65526549 const DataLayout &DL = GV->getDataLayout ();
6550+ unsigned ByteWidth = DL.getByteWidth ();
6551+ assert ((ElementBitWidth % ByteWidth) == 0 &&
6552+ " ElementBitWidth is expected to be a multiple of the byte width" );
6553+ unsigned ElementSizeInBytes = ElementBitWidth / ByteWidth;
6554+
65536555 APInt Off (DL.getIndexTypeSizeInBits (V->getType ()), 0 );
65546556
65556557 if (GV != V->stripAndAccumulateConstantOffsets (DL, Off,
@@ -6589,7 +6591,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
65896591 auto *Init = const_cast <Constant *>(GV->getInitializer ());
65906592 if (auto *ArrayInit = dyn_cast<ConstantDataArray>(Init)) {
65916593 Type *InitElTy = ArrayInit->getElementType ();
6592- if (InitElTy->isIntegerTy (ElementSize )) {
6594+ if (InitElTy->isIntegerTy (ElementBitWidth )) {
65936595 // If Init is an initializer for an array of the expected type
65946596 // and size, use it as is.
65956597 Array = ArrayInit;
@@ -6598,7 +6600,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
65986600 }
65996601
66006602 if (!Array) {
6601- if (ElementSize != 8 )
6603+ if (ElementBitWidth != CHAR_BIT )
66026604 // TODO: Handle conversions to larger integral types.
66036605 return false ;
66046606
@@ -6676,9 +6678,9 @@ bool llvm::getConstantStringInfo(const Value *V, StringRef &Str,
66766678
66776679// / If we can compute the length of the string pointed to by
66786680// / the specified pointer, return 'len+1'. If we can't, return 0.
6679- static uint64_t GetStringLengthH (const Value *V,
6680- SmallPtrSetImpl<const PHINode*> &PHIs,
6681- unsigned CharSize ) {
6681+ static uint64_t getStringLength (const Value *V,
6682+ SmallPtrSetImpl<const PHINode *> &PHIs,
6683+ unsigned CharWidth ) {
66826684 // Look through noop bitcast instructions.
66836685 V = V->stripPointerCasts ();
66846686
@@ -6691,7 +6693,7 @@ static uint64_t GetStringLengthH(const Value *V,
66916693 // If it was new, see if all the input strings are the same length.
66926694 uint64_t LenSoFar = ~0ULL ;
66936695 for (Value *IncValue : PN->incoming_values ()) {
6694- uint64_t Len = GetStringLengthH (IncValue, PHIs, CharSize );
6696+ uint64_t Len = getStringLength (IncValue, PHIs, CharWidth );
66956697 if (Len == 0 ) return 0 ; // Unknown length -> unknown.
66966698
66976699 if (Len == ~0ULL ) continue ;
@@ -6707,9 +6709,9 @@ static uint64_t GetStringLengthH(const Value *V,
67076709
67086710 // strlen(select(c,x,y)) -> strlen(x) ^ strlen(y)
67096711 if (const SelectInst *SI = dyn_cast<SelectInst>(V)) {
6710- uint64_t Len1 = GetStringLengthH (SI->getTrueValue (), PHIs, CharSize );
6712+ uint64_t Len1 = getStringLength (SI->getTrueValue (), PHIs, CharWidth );
67116713 if (Len1 == 0 ) return 0 ;
6712- uint64_t Len2 = GetStringLengthH (SI->getFalseValue (), PHIs, CharSize );
6714+ uint64_t Len2 = getStringLength (SI->getFalseValue (), PHIs, CharWidth );
67136715 if (Len2 == 0 ) return 0 ;
67146716 if (Len1 == ~0ULL ) return Len2;
67156717 if (Len2 == ~0ULL ) return Len1;
@@ -6719,7 +6721,7 @@ static uint64_t GetStringLengthH(const Value *V,
67196721
67206722 // Otherwise, see if we can read the string.
67216723 ConstantDataArraySlice Slice;
6722- if (!getConstantDataArrayInfo (V, Slice, CharSize ))
6724+ if (!getConstantDataArrayInfo (V, Slice, CharWidth ))
67236725 return 0 ;
67246726
67256727 if (Slice.Array == nullptr )
@@ -6741,12 +6743,12 @@ static uint64_t GetStringLengthH(const Value *V,
67416743
67426744// / If we can compute the length of the string pointed to by
67436745// / the specified pointer, return 'len+1'. If we can't, return 0.
6744- uint64_t llvm::GetStringLength (const Value *V, unsigned CharSize ) {
6746+ uint64_t llvm::getStringLength (const Value *V, unsigned CharWidth ) {
67456747 if (!V->getType ()->isPointerTy ())
67466748 return 0 ;
67476749
67486750 SmallPtrSet<const PHINode*, 32 > PHIs;
6749- uint64_t Len = GetStringLengthH (V, PHIs, CharSize );
6751+ uint64_t Len = :: getStringLength (V, PHIs, CharWidth );
67506752 // If Len is ~0ULL, we had an infinite phi cycle: this is dead code, so return
67516753 // an empty string as a length.
67526754 return Len == ~0ULL ? 1 : Len;
0 commit comments