Skip to content

Commit 1b167e8

Browse files
committed
[GlobalISel] Use ComputeValueTypes to implement computeValueLLTs (NFC)
Also add an overload returning TypeSize offsets. For now, it is only called from the other overload.
1 parent 6214dcc commit 1b167e8

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

llvm/include/llvm/CodeGen/Analysis.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty,
8888
/// with the in-memory offsets of each of the individual values.
8989
///
9090
void computeValueLLTs(const DataLayout &DL, Type &Ty,
91-
SmallVectorImpl<LLT> &ValueTys,
92-
SmallVectorImpl<uint64_t> *Offsets = nullptr,
93-
uint64_t StartingOffset = 0);
91+
SmallVectorImpl<LLT> &ValueLLTs,
92+
SmallVectorImpl<TypeSize> *Offsets = nullptr,
93+
TypeSize StartingOffset = TypeSize::getZero());
94+
void computeValueLLTs(const DataLayout &DL, Type &Ty,
95+
SmallVectorImpl<LLT> &ValueLLTs,
96+
SmallVectorImpl<uint64_t> *FixedOffsets,
97+
uint64_t FixedStartingOffset = 0);
9498

9599
/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
96100
GlobalValue *ExtractTypeInfo(Value *V);

llvm/lib/CodeGen/Analysis.cpp

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,38 +147,28 @@ void llvm::ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
147147
}
148148

149149
void llvm::computeValueLLTs(const DataLayout &DL, Type &Ty,
150-
SmallVectorImpl<LLT> &ValueTys,
151-
SmallVectorImpl<uint64_t> *Offsets,
152-
uint64_t StartingOffset) {
153-
// Given a struct type, recursively traverse the elements.
154-
if (StructType *STy = dyn_cast<StructType>(&Ty)) {
155-
// If the Offsets aren't needed, don't query the struct layout. This allows
156-
// us to support structs with scalable vectors for operations that don't
157-
// need offsets.
158-
const StructLayout *SL = Offsets ? DL.getStructLayout(STy) : nullptr;
159-
for (unsigned I = 0, E = STy->getNumElements(); I != E; ++I) {
160-
uint64_t EltOffset = SL ? SL->getElementOffset(I) : 0;
161-
computeValueLLTs(DL, *STy->getElementType(I), ValueTys, Offsets,
162-
StartingOffset + EltOffset);
163-
}
164-
return;
165-
}
166-
// Given an array type, recursively traverse the elements.
167-
if (ArrayType *ATy = dyn_cast<ArrayType>(&Ty)) {
168-
Type *EltTy = ATy->getElementType();
169-
uint64_t EltSize = DL.getTypeAllocSize(EltTy).getFixedValue();
170-
for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
171-
computeValueLLTs(DL, *EltTy, ValueTys, Offsets,
172-
StartingOffset + i * EltSize);
173-
return;
150+
SmallVectorImpl<LLT> &ValueLLTs,
151+
SmallVectorImpl<TypeSize> *Offsets,
152+
TypeSize StartingOffset) {
153+
SmallVector<Type *> ValTys;
154+
ComputeValueTypes(DL, &Ty, ValTys, Offsets, StartingOffset);
155+
for (Type *ValTy : ValTys)
156+
ValueLLTs.push_back(getLLTForType(*ValTy, DL));
157+
}
158+
159+
void llvm::computeValueLLTs(const DataLayout &DL, Type &Ty,
160+
SmallVectorImpl<LLT> &ValueLLTs,
161+
SmallVectorImpl<uint64_t> *FixedOffsets,
162+
uint64_t FixedStartingOffset) {
163+
TypeSize StartingOffset = TypeSize::getFixed(FixedStartingOffset);
164+
if (FixedOffsets) {
165+
SmallVector<TypeSize, 4> Offsets;
166+
computeValueLLTs(DL, Ty, ValueLLTs, &Offsets, StartingOffset);
167+
for (TypeSize Offset : Offsets)
168+
FixedOffsets->push_back(Offset.getFixedValue());
169+
} else {
170+
computeValueLLTs(DL, Ty, ValueLLTs, nullptr, StartingOffset);
174171
}
175-
// Interpret void as zero return values.
176-
if (Ty.isVoidTy())
177-
return;
178-
// Base case: we can get an LLT for this LLVM IR type.
179-
ValueTys.push_back(getLLTForType(Ty, DL));
180-
if (Offsets)
181-
Offsets->push_back(StartingOffset);
182172
}
183173

184174
/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.

0 commit comments

Comments
 (0)