- Added a comment warning  about using MergeGepUse while iterating.
- Changed MergeGepUse to return bool for whether anything actually changed.
- Adding GEP's user to worklist, even when GEP and GEP's source pointer GEP cannot be merged.
This commit is contained in:
Adam Yang 2022-11-10 15:34:17 -08:00 коммит произвёл GitHub
Родитель 4349c3e1f7
Коммит 0392e60dbc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -61,7 +61,13 @@ namespace dxilutil {
llvm::Type *Ty, DxilTypeSystem &typeSys);
llvm::Type *GetArrayEltTy(llvm::Type *Ty);
bool HasDynamicIndexing(llvm::Value *V);
void MergeGepUse(llvm::Value *V);
// Cleans up unnecessary chains of GEPs and bitcasts left over from certain
// optimizations. This function is NOT safe to call while iterating
// instructions either forward or backward. If V happens to be a GEP or
// bitcast, the function may delete V, instructions preceding V it, and
// instructions following V.
bool MergeGepUse(llvm::Value *V);
// Find alloca insertion point, given instruction
llvm::Instruction *FindAllocaInsertionPt(llvm::Instruction* I); // Considers entire parent function

Просмотреть файл

@ -108,7 +108,8 @@ namespace hlsl {
namespace dxilutil {
void MergeGepUse(Value *V) {
bool MergeGepUse(Value *V) {
bool changed = false;
SmallVector<Value *, 16> worklist;
auto addUsersToWorklist = [&worklist](Value *V) {
if (!V->user_empty()) {
@ -125,6 +126,7 @@ void MergeGepUse(Value *V) {
V = worklist.pop_back_val();
if (BitCastOperator *BCO = dyn_cast<BitCastOperator>(V)) {
if (Value *NewV = dxilutil::TryReplaceBaseCastWithGep(V)) {
changed = true;
worklist.push_back(NewV);
} else {
// merge any GEP users of the untranslated bitcast
@ -137,8 +139,13 @@ void MergeGepUse(Value *V) {
if (Value *newGEP = MergeGEP(prevGEP, GEP)) {
worklist.push_back(newGEP);
// delete prevGEP if no more users
if (prevGEP->user_empty() && isa<GetElementPtrInst>(prevGEP))
if (prevGEP->user_empty() && isa<GetElementPtrInst>(prevGEP)) {
cast<GetElementPtrInst>(prevGEP)->eraseFromParent();
changed = true;
}
}
else {
addUsersToWorklist(GEP);
}
} else {
// nothing to merge yet, add GEP users
@ -146,6 +153,8 @@ void MergeGepUse(Value *V) {
}
}
}
return changed;
}
std::unique_ptr<llvm::Module> LoadModuleFromBitcode(llvm::MemoryBuffer *MB,