mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
NVPTX: Use RAUW instead of reinventing the wheel
This code had a homemade RAUW that was incorrect when a user was a constant: instead of calling `replaceUsersWithOnConstant()` it would incorrectly update the operand in-place, invalidating `LLVMContextImpl::ExprConstants`. RAUW does the job better. The ValueHandle that `GVMap` is holding onto needs to be removed first, so this commit also removes each variable from the map on-the-fly. Since deletions from `ExprConstants` use a linear search that compares directly on the pointer value (instead of using the key), there isn't an obvious way to expose this with a testcase. llvm-svn: 215953
This commit is contained in:
parent
bb7967e614
commit
4847822e30
@ -140,20 +140,23 @@ bool GenericToNVVM::runOnModule(Module &M) {
|
|||||||
for (GVMapTy::iterator I = GVMap.begin(), E = GVMap.end(); I != E;) {
|
for (GVMapTy::iterator I = GVMap.begin(), E = GVMap.end(); I != E;) {
|
||||||
GlobalVariable *GV = I->first;
|
GlobalVariable *GV = I->first;
|
||||||
GlobalVariable *NewGV = I->second;
|
GlobalVariable *NewGV = I->second;
|
||||||
++I;
|
|
||||||
|
// Remove GV from the map so that it can be RAUWed. Note that
|
||||||
|
// DenseMap::erase() won't invalidate any iterators but this one.
|
||||||
|
auto Next = std::next(I);
|
||||||
|
GVMap.erase(I);
|
||||||
|
I = Next;
|
||||||
|
|
||||||
Constant *BitCastNewGV = ConstantExpr::getPointerCast(NewGV, GV->getType());
|
Constant *BitCastNewGV = ConstantExpr::getPointerCast(NewGV, GV->getType());
|
||||||
// At this point, the remaining uses of GV should be found only in global
|
// At this point, the remaining uses of GV should be found only in global
|
||||||
// variable initializers, as other uses have been already been removed
|
// variable initializers, as other uses have been already been removed
|
||||||
// while walking through the instructions in function definitions.
|
// while walking through the instructions in function definitions.
|
||||||
for (Value::use_iterator UI = GV->use_begin(), UE = GV->use_end();
|
GV->replaceAllUsesWith(BitCastNewGV);
|
||||||
UI != UE;)
|
|
||||||
(UI++)->set(BitCastNewGV);
|
|
||||||
std::string Name = GV->getName();
|
std::string Name = GV->getName();
|
||||||
GV->removeDeadConstantUsers();
|
|
||||||
GV->eraseFromParent();
|
GV->eraseFromParent();
|
||||||
NewGV->setName(Name);
|
NewGV->setName(Name);
|
||||||
}
|
}
|
||||||
GVMap.clear();
|
assert(GVMap.empty() && "Expected it to be empty by now");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user