Skip to content

Commit

Permalink
修正分支指令的 Use 更新 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Turmoil authored Oct 12, 2024
1 parent 9188181 commit 055c99a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
6 changes: 5 additions & 1 deletion libs/llvm/src/ir/value/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ ValuePtr User::RemoveUse(ValuePtr use) {
ValuePtr User::ReplaceUse(ValuePtr oldValue, ValuePtr newValue) {
for (auto it = _useList.begin(); it != _useList.end(); ++it) {
if ((*it)->GetValue() == oldValue) {
*it = Use::New(this, newValue);
if (newValue) {
*it = Use::New(this, newValue);
} else {
_useList.erase(it);
}
return oldValue;
}
}
Expand Down
33 changes: 20 additions & 13 deletions libs/llvm/src/ir/value/inst/Instructions.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "llvm/ir/value/inst/Instructions.h"
#include "llvm/utils.h"
#include "llvm/ir/LlvmContext.h"
#include "llvm/ir/Type.h"
#include "llvm/ir/value/BasicBlock.h"
#include "llvm/ir/value/Function.h"
#include "llvm/utils.h"

#pragma region AllocaInst

Expand Down Expand Up @@ -73,27 +73,31 @@ BranchInstPtr BranchInst::New(ValuePtr condition, BasicBlockPtr trueBlock,
}

BasicBlockPtr BranchInst::SetTrueBlock(BasicBlockPtr block) {
BasicBlockPtr old = _trueBlock;

if (_trueBlock) {
ReplaceOperand(_trueBlock, block);
return _trueBlock;
}

_trueBlock = block;
AddOperand(_trueBlock);
if (_trueBlock) {
AddOperand(_trueBlock);
}

return nullptr;
return old;
}

BasicBlockPtr BranchInst::SetFalseBlock(BasicBlockPtr block) {
BasicBlockPtr old = _falseBlock;

if (_falseBlock) {
ReplaceOperand(_falseBlock, block);
return _falseBlock;
}

_falseBlock = block;
AddOperand(_falseBlock);
if (_falseBlock) {
AddOperand(_falseBlock);
}

return nullptr;
return old;
}

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

BasicBlockPtr JumpInst::SetTarget(BasicBlockPtr block) {
BasicBlockPtr old = _target;

if (_target) {
ReplaceOperand(_target, block);
return _target;
}

_target = block;
AddOperand(_target);
return nullptr;
if (_target) {
AddOperand(_target);
}

return old;
}

#pragma endregion
Expand Down

0 comments on commit 055c99a

Please sign in to comment.