mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-12 14:17:59 +00:00
AMDGPU: Minor cleanups for AMDGPUPromoteAlloca
Mostly convert to use range loops. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259550 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9c1744ae4d
commit
ed9c1ce27a
@ -106,10 +106,10 @@ bool AMDGPUPromoteAlloca::runOnFunction(Function &F) {
|
|||||||
// If the function has any arguments in the local address space, then it's
|
// If the function has any arguments in the local address space, then it's
|
||||||
// possible these arguments require the entire local memory space, so
|
// possible these arguments require the entire local memory space, so
|
||||||
// we cannot use local memory in the pass.
|
// we cannot use local memory in the pass.
|
||||||
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
|
for (Type *ParamTy : FTy->params()) {
|
||||||
Type *ParamTy = FTy->getParamType(i);
|
PointerType *PtrTy = dyn_cast<PointerType>(ParamTy);
|
||||||
if (ParamTy->isPointerTy() &&
|
if (PtrTy && PtrTy->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS) {
|
||||||
ParamTy->getPointerAddressSpace() == AMDGPUAS::LOCAL_ADDRESS) {
|
LocalMemAvailable = 0;
|
||||||
DEBUG(dbgs() << "Function has local memory argument. Promoting to "
|
DEBUG(dbgs() << "Function has local memory argument. Promoting to "
|
||||||
"local memory disabled.\n");
|
"local memory disabled.\n");
|
||||||
return false;
|
return false;
|
||||||
@ -121,26 +121,24 @@ bool AMDGPUPromoteAlloca::runOnFunction(Function &F) {
|
|||||||
if (LocalMemAvailable == 0)
|
if (LocalMemAvailable == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
// Check how much local memory is being used by global objects
|
// Check how much local memory is being used by global objects
|
||||||
for (Module::global_iterator I = Mod->global_begin(),
|
for (GlobalVariable &GV : Mod->globals()) {
|
||||||
E = Mod->global_end(); I != E; ++I) {
|
if (GV.getType()->getAddressSpace() != AMDGPUAS::LOCAL_ADDRESS)
|
||||||
GlobalVariable *GV = &*I;
|
|
||||||
if (GV->getType()->getAddressSpace() != AMDGPUAS::LOCAL_ADDRESS)
|
|
||||||
continue;
|
continue;
|
||||||
for (Value::use_iterator U = GV->use_begin(),
|
|
||||||
UE = GV->use_end(); U != UE; ++U) {
|
for (Use &U : GV.uses()) {
|
||||||
Instruction *Use = dyn_cast<Instruction>(*U);
|
Instruction *Use = dyn_cast<Instruction>(U);
|
||||||
if (!Use)
|
if (!Use)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Use->getParent()->getParent() == &F)
|
if (Use->getParent()->getParent() == &F)
|
||||||
LocalMemAvailable -=
|
LocalMemAvailable -=
|
||||||
Mod->getDataLayout().getTypeAllocSize(GV->getValueType());
|
Mod->getDataLayout().getTypeAllocSize(GV.getValueType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalMemAvailable = std::max(0, LocalMemAvailable);
|
LocalMemAvailable = std::max(0, LocalMemAvailable);
|
||||||
DEBUG(dbgs() << LocalMemAvailable << "bytes free in local memory.\n");
|
DEBUG(dbgs() << LocalMemAvailable << " bytes free in local memory.\n");
|
||||||
|
|
||||||
visit(F);
|
visit(F);
|
||||||
|
|
||||||
@ -310,17 +308,16 @@ static bool canVectorizeInst(Instruction *Inst, User *User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool tryPromoteAllocaToVector(AllocaInst *Alloca) {
|
static bool tryPromoteAllocaToVector(AllocaInst *Alloca) {
|
||||||
Type *AllocaTy = Alloca->getAllocatedType();
|
ArrayType *AllocaTy = dyn_cast<ArrayType>(Alloca->getAllocatedType());
|
||||||
|
|
||||||
DEBUG(dbgs() << "Alloca Candidate for vectorization \n");
|
DEBUG(dbgs() << "Alloca candidate for vectorization\n");
|
||||||
|
|
||||||
// FIXME: There is no reason why we can't support larger arrays, we
|
// FIXME: There is no reason why we can't support larger arrays, we
|
||||||
// are just being conservative for now.
|
// are just being conservative for now.
|
||||||
if (!AllocaTy->isArrayTy() ||
|
if (!AllocaTy ||
|
||||||
AllocaTy->getArrayElementType()->isVectorTy() ||
|
AllocaTy->getElementType()->isVectorTy() ||
|
||||||
AllocaTy->getArrayNumElements() > 4) {
|
AllocaTy->getNumElements() > 4) {
|
||||||
|
DEBUG(dbgs() << " Cannot convert type to vector\n");
|
||||||
DEBUG(dbgs() << " Cannot convert type to vector");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,9 +356,8 @@ static bool tryPromoteAllocaToVector(AllocaInst *Alloca) {
|
|||||||
DEBUG(dbgs() << " Converting alloca to vector "
|
DEBUG(dbgs() << " Converting alloca to vector "
|
||||||
<< *AllocaTy << " -> " << *VectorTy << '\n');
|
<< *AllocaTy << " -> " << *VectorTy << '\n');
|
||||||
|
|
||||||
for (std::vector<Value*>::iterator I = WorkList.begin(),
|
for (Value *V : WorkList) {
|
||||||
E = WorkList.end(); I != E; ++I) {
|
Instruction *Inst = cast<Instruction>(V);
|
||||||
Instruction *Inst = cast<Instruction>(*I);
|
|
||||||
IRBuilder<> Builder(Inst);
|
IRBuilder<> Builder(Inst);
|
||||||
switch (Inst->getOpcode()) {
|
switch (Inst->getOpcode()) {
|
||||||
case Instruction::Load: {
|
case Instruction::Load: {
|
||||||
@ -523,9 +519,7 @@ void AMDGPUPromoteAlloca::visitAlloca(AllocaInst &I) {
|
|||||||
I.replaceAllUsesWith(Offset);
|
I.replaceAllUsesWith(Offset);
|
||||||
I.eraseFromParent();
|
I.eraseFromParent();
|
||||||
|
|
||||||
for (std::vector<Value*>::iterator i = WorkList.begin(),
|
for (Value *V : WorkList) {
|
||||||
e = WorkList.end(); i != e; ++i) {
|
|
||||||
Value *V = *i;
|
|
||||||
CallInst *Call = dyn_cast<CallInst>(V);
|
CallInst *Call = dyn_cast<CallInst>(V);
|
||||||
if (!Call) {
|
if (!Call) {
|
||||||
Type *EltTy = V->getType()->getPointerElementType();
|
Type *EltTy = V->getType()->getPointerElementType();
|
||||||
|
Loading…
Reference in New Issue
Block a user