Skip to content

Commit 4629893

Browse files
committed
修正分支指令的 Use 更新
1 parent 9188181 commit 4629893

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

libs/llvm/src/ir/value/User.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ ValuePtr User::RemoveUse(ValuePtr use) {
4646
ValuePtr User::ReplaceUse(ValuePtr oldValue, ValuePtr newValue) {
4747
for (auto it = _useList.begin(); it != _useList.end(); ++it) {
4848
if ((*it)->GetValue() == oldValue) {
49-
*it = Use::New(this, newValue);
49+
if (newValue) {
50+
*it = Use::New(this, newValue);
51+
} else {
52+
_useList.erase(it);
53+
}
5054
return oldValue;
5155
}
5256
}

libs/llvm/src/ir/value/inst/Instructions.cpp

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "llvm/ir/value/inst/Instructions.h"
2-
#include "llvm/utils.h"
32
#include "llvm/ir/LlvmContext.h"
43
#include "llvm/ir/Type.h"
54
#include "llvm/ir/value/BasicBlock.h"
65
#include "llvm/ir/value/Function.h"
6+
#include "llvm/utils.h"
77

88
#pragma region AllocaInst
99

@@ -73,27 +73,31 @@ BranchInstPtr BranchInst::New(ValuePtr condition, BasicBlockPtr trueBlock,
7373
}
7474

7575
BasicBlockPtr BranchInst::SetTrueBlock(BasicBlockPtr block) {
76+
BasicBlockPtr old = _trueBlock;
77+
7678
if (_trueBlock) {
7779
ReplaceOperand(_trueBlock, block);
78-
return _trueBlock;
7980
}
80-
8181
_trueBlock = block;
82-
AddOperand(_trueBlock);
82+
if (_trueBlock) {
83+
AddOperand(_trueBlock);
84+
}
8385

84-
return nullptr;
86+
return old;
8587
}
8688

8789
BasicBlockPtr BranchInst::SetFalseBlock(BasicBlockPtr block) {
90+
BasicBlockPtr old = _falseBlock;
91+
8892
if (_falseBlock) {
8993
ReplaceOperand(_falseBlock, block);
90-
return _falseBlock;
9194
}
92-
9395
_falseBlock = block;
94-
AddOperand(_falseBlock);
96+
if (_falseBlock) {
97+
AddOperand(_falseBlock);
98+
}
9599

96-
return nullptr;
100+
return old;
97101
}
98102

99103
#pragma endregion
@@ -119,14 +123,17 @@ JumpInstPtr JumpInst::New(LlvmContextPtr context) {
119123
}
120124

121125
BasicBlockPtr JumpInst::SetTarget(BasicBlockPtr block) {
126+
BasicBlockPtr old = _target;
127+
122128
if (_target) {
123129
ReplaceOperand(_target, block);
124-
return _target;
125130
}
126-
127131
_target = block;
128-
AddOperand(_target);
129-
return nullptr;
132+
if (_target) {
133+
AddOperand(_target);
134+
}
135+
136+
return old;
130137
}
131138

132139
#pragma endregion

0 commit comments

Comments
 (0)