mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-18 21:14:35 +03:00
Cleaned up AArch64 RAPass to not shadow variables in _rewrite() (Fixes #359)
This commit is contained in:
@@ -713,40 +713,45 @@ ASMJIT_FAVOR_SPEED Error ARMRAPass::_rewrite(BaseNode* first, BaseNode* stop) no
|
||||
mem.clearRegHome();
|
||||
mem.addOffsetLo32(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite `loadAddressOf()` construct.
|
||||
if (node->type() == NodeType::kInst) {
|
||||
InstNode* inst = node->as<InstNode>();
|
||||
if (inst->realId() == Inst::kIdAdr && inst->opCount() == 2) {
|
||||
if (inst->realId() == Inst::kIdAdr && inst->opCount() == 2 && inst->op(1).isMem()) {
|
||||
BaseMem mem = inst->op(1).as<BaseMem>();
|
||||
int64_t offset = mem.offset();
|
||||
if (!mem.hasBase()) {
|
||||
|
||||
if (!mem.hasBaseOrIndex()) {
|
||||
inst->setId(Inst::kIdMov);
|
||||
inst->setOp(1, Imm(offset));
|
||||
}
|
||||
else {
|
||||
InstId op = offset < 0 ? Inst::kIdSub : Inst::kIdAdd;
|
||||
uint64_t val = offset < 0 ? Support::neg(uint64_t(offset)) : uint64_t(offset);
|
||||
if (mem.hasIndex())
|
||||
return DebugUtils::errored(kErrorInvalidAddressIndex);
|
||||
|
||||
GpX base = GpX(mem.baseId());
|
||||
GpX dst(inst->op(0).as<Gp>().id());
|
||||
GpX base(mem.baseId());
|
||||
|
||||
inst->setId(op);
|
||||
InstId arithInstId = offset < 0 ? Inst::kIdSub : Inst::kIdAdd;
|
||||
uint64_t absOffset = offset < 0 ? Support::neg(uint64_t(offset)) : uint64_t(offset);
|
||||
|
||||
inst->setId(arithInstId);
|
||||
inst->setOpCount(3);
|
||||
inst->setOp(1, base);
|
||||
inst->setOp(2, Imm(val));
|
||||
inst->setOp(2, Imm(absOffset));
|
||||
|
||||
if (val > 0xFFFu && (val & ~uint64_t(0xFFF000u)) != 0) {
|
||||
const Operand_& dst = inst->op(0);
|
||||
// Use two operations if the stack address is greater than 4095.
|
||||
if (val <= 0xFFFFFFu) {
|
||||
// Use two operations if the offset cannot be encoded with ADD/SUB.
|
||||
if (absOffset > 0xFFFu && (absOffset & ~uint64_t(0xFFF000u)) != 0) {
|
||||
if (absOffset <= 0xFFFFFFu) {
|
||||
cc()->_setCursor(inst->prev());
|
||||
cc()->_emitI(op, dst, base, Imm(val & 0xFFFu));
|
||||
ASMJIT_PROPAGATE(cc()->emit(arithInstId, dst, base, Imm(absOffset & 0xFFFu)));
|
||||
|
||||
inst->setOp(1, dst);
|
||||
inst->setOp(2, Imm(val & 0xFFF000u));
|
||||
inst->setOp(2, Imm(absOffset & 0xFFF000u));
|
||||
}
|
||||
else {
|
||||
cc()->_setCursor(inst->prev());
|
||||
cc()->_emitI(Inst::kIdMov, inst->op(0), Imm(val));
|
||||
ASMJIT_PROPAGATE(cc()->emit(Inst::kIdMov, inst->op(0), Imm(absOffset)));
|
||||
|
||||
inst->setOp(1, base);
|
||||
inst->setOp(2, dst);
|
||||
@@ -755,9 +760,6 @@ ASMJIT_FAVOR_SPEED Error ARMRAPass::_rewrite(BaseNode* first, BaseNode* stop) no
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node = next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user