[llvm] [DirectX] Simplify and correct the flattening of GEPs in DXILFlattenArrays (PR #146173)
Farzon Lotfi via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 06:10:01 PDT 2025
================
@@ -78,35 +80,20 @@ class DXILFlattenArraysVisitor
private:
SmallVector<WeakTrackingVH> PotentiallyDeadInstrs;
- DenseMap<GetElementPtrInst *, GEPData> GEPChainMap;
+ DenseMap<GEPOperator *, GEPInfo> GEPChainInfoMap;
+ DenseMap<GlobalVariable *, GlobalVariable *> &GlobalMap;
bool finish();
ConstantInt *genConstFlattenIndices(ArrayRef<Value *> Indices,
ArrayRef<uint64_t> Dims,
IRBuilder<> &Builder);
Value *genInstructionFlattenIndices(ArrayRef<Value *> Indices,
ArrayRef<uint64_t> Dims,
IRBuilder<> &Builder);
-
- // Helper function to collect indices and dimensions from a GEP instruction
- void collectIndicesAndDimsFromGEP(GetElementPtrInst &GEP,
- SmallVectorImpl<Value *> &Indices,
- SmallVectorImpl<uint64_t> &Dims,
- bool &AllIndicesAreConstInt);
-
- void
- recursivelyCollectGEPs(GetElementPtrInst &CurrGEP,
- ArrayType *FlattenedArrayType, Value *PtrOperand,
- unsigned &GEPChainUseCount,
- SmallVector<Value *> Indices = SmallVector<Value *>(),
- SmallVector<uint64_t> Dims = SmallVector<uint64_t>(),
- bool AllIndicesAreConstInt = true);
- bool visitGetElementPtrInstInGEPChain(GetElementPtrInst &GEP);
- bool visitGetElementPtrInstInGEPChainBase(GEPData &GEPInfo,
- GetElementPtrInst &GEP);
};
} // namespace
bool DXILFlattenArraysVisitor::finish() {
+ GEPChainInfoMap.clear();
----------------
farzonl wrote:
This is fine. not sure if its necessary though. The `GEPChainInfoMap` will ger recreated on every construction of th `DXILFlattenArraysVisitor` which should be the same as clearing it. That said the idea makes sense, there are going to be many invalid gep chains the longer we don't clear because we are flattening as we walk the chains. So I think it makes sense, but we should probably be clearing the `GEPChainInfoMap` after each function, while I think this clears it after each module.
https://github.com/llvm/llvm-project/pull/146173
More information about the llvm-commits
mailing list