llvm.org GIT mirror llvm / 2bc065b
Refactor code to make it useful outside of Constants.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8205 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
2 changed file(s) with 24 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
465465 //===----------------------------------------------------------------------===//
466466 // Factory Function Implementation
467467
468 // ReplaceUsesOfWith - This is exactly the same as Value::replaceAllUsesWith,
469 // except that it doesn't have all of the asserts. The asserts fail because we
470 // are half-way done resolving types, which causes some types to exist as two
471 // different Type*'s at the same time. This is a sledgehammer to work around
472 // this problem.
473 //
474 static void ReplaceUsesOfWith(Value *Old, Value *New) {
475 while (!Old->use_empty()) {
476 User *Use = Old->use_back();
477 // Must handle Constants specially, we cannot call replaceUsesOfWith on a
478 // constant!
479 if (Constant *C = dyn_cast(Use)) {
480 C->replaceUsesOfWithOnConstant(Old, New);
481 } else {
482 Use->replaceUsesOfWith(Old, New);
483 }
484 }
485 }
486
487
488468 // ConstantCreator - A class that is used to create constants by
489469 // ValueMap*. This class should be partially specialized if there is
490470 // something strange that needs to be done to interface to the ctor for the
595575 C.push_back(cast(getOperand(i)));
596576 Constant *New = ConstantArray::get(cast(NewTy), C);
597577 if (New != this) {
598 ReplaceUsesOfWith(this, New);
578 uncheckedReplaceAllUsesWith(New);
599579 destroyConstant(); // This constant is now dead, destroy it.
600580 }
601581 }
664644 C.push_back(cast(getOperand(i)));
665645 Constant *New = ConstantStruct::get(cast(NewTy), C);
666646 if (New != this) {
667 ReplaceUsesOfWith(this, New);
647 uncheckedReplaceAllUsesWith(New);
668648 destroyConstant(); // This constant is now dead, destroy it.
669649 }
670650 }
705685 // Make everyone now use a constant of the new type...
706686 Constant *New = ConstantPointerNull::get(cast(NewTy));
707687 if (New != this) {
708 ReplaceUsesOfWith(this, New);
688 uncheckedReplaceAllUsesWith(New);
709689
710690 // This constant is now dead, destroy it.
711691 destroyConstant();
858838 New = ConstantExpr::getGetElementPtr(getOperand(0), C);
859839 }
860840 if (New != this) {
861 ReplaceUsesOfWith(this, New);
841 uncheckedReplaceAllUsesWith(New);
862842 destroyConstant(); // This constant is now dead, destroy it.
863843 }
864844 }
6565 }
6666 }
6767
68 // uncheckedReplaceAllUsesWith - This is exactly the same as replaceAllUsesWith,
69 // except that it doesn't have all of the asserts. The asserts fail because we
70 // are half-way done resolving types, which causes some types to exist as two
71 // different Type*'s at the same time. This is a sledgehammer to work around
72 // this problem.
73 //
74 void Value::uncheckedReplaceAllUsesWith(Value *New) {
75 while (!Uses.empty()) {
76 User *Use = Uses.back();
77 // Must handle Constants specially, we cannot call replaceUsesOfWith on a
78 // constant!
79 if (Constant *C = dyn_cast(Use)) {
80 C->replaceUsesOfWithOnConstant(this, New);
81 } else {
82 Use->replaceUsesOfWith(this, New);
83 }
84 }
85 }
86
87
6888 // refineAbstractType - This function is implemented because we use
6989 // potentially abstract types, and these types may be resolved to more
7090 // concrete types after we are constructed. For the value class, we simply