[midend-SCCP]删除User的析构函数,usedelete增加逻辑通知inst所使用的value移除对应的use关系(一般在这之前会替换使用inst的uses为其他值),TODO:仍然存在bug需要调试

This commit is contained in:
rain2133
2025-07-31 22:32:04 +08:00
parent c5af4f1c49
commit 0f1fcc835d
3 changed files with 125 additions and 31 deletions

View File

@@ -626,21 +626,21 @@ class User : public Value {
explicit User(Type *type, const std::string &name = "") : Value(type, name) {}
public:
~User() override {
// 当 User 对象被销毁时例如LoadInst 或 StoreInst 被删除时),
// 它必须通知它所使用的所有 Value将对应的 Use 关系从它们的 uses 列表中移除。
// 这样可以防止 Value 的 uses 列表中出现悬空的 Use 对象。
for (const auto &use_ptr : operands) {
// 确保 use_ptr 非空,并且其内部指向的 Value* 也非空
// (虽然通常情况下不会为空,但为了健壮性考虑)
if (use_ptr && use_ptr->getValue()) {
use_ptr->getValue()->removeUse(use_ptr);
}
}
// operands 向量本身是 std::vector<std::shared_ptr<Use>>
// 在此析构函数结束后operands 向量会被销毁,其内部的 shared_ptr 也会被释放,
// 如果 shared_ptr 引用计数降为0Use 对象本身也会被销毁。
}
// ~User() override {
// // 当 User 对象被销毁时例如LoadInst 或 StoreInst 被删除时),
// // 它必须通知它所使用的所有 Value将对应的 Use 关系从它们的 uses 列表中移除。
// // 这样可以防止 Value 的 uses 列表中出现悬空的 Use 对象。
// for (const auto &use_ptr : operands) {
// // 确保 use_ptr 非空,并且其内部指向的 Value* 也非空
// // (虽然通常情况下不会为空,但为了健壮性考虑)
// if (use_ptr && use_ptr->getValue()) {
// use_ptr->getValue()->removeUse(use_ptr);
// }
// }
// // operands 向量本身是 std::vector<std::shared_ptr<Use>>
// // 在此析构函数结束后operands 向量会被销毁,其内部的 shared_ptr 也会被释放,
// // 如果 shared_ptr 引用计数降为0Use 对象本身也会被销毁。
// }
unsigned getNumOperands() const { return operands.size(); } ///< 获取操作数数量
auto operand_begin() const { return operands.begin(); } ///< 返回操作数列表的开头迭代器
auto operand_end() const { return operands.end(); } ///< 返回操作数列表的结尾迭代器