-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[aarch64] handle stack frames that are larger than 4096 bytes
- Loading branch information
1 parent
3645f5a
commit 44f7eb2
Showing
6 changed files
with
113 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/banjo/target/aarch64/aarch64_stack_offset_fixup_pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "aarch64_stack_offset_fixup_pass.hpp" | ||
|
||
#include "banjo/mcode/instruction.hpp" | ||
#include "banjo/target/aarch64/aarch64_opcode.hpp" | ||
#include "banjo/utils/utils.hpp" | ||
|
||
namespace banjo { | ||
namespace target { | ||
|
||
void AArch64StackOffsetFixupPass::run(mcode::Module &module_) { | ||
for (mcode::Function *func : module_.get_functions()) { | ||
for (mcode::BasicBlock &block : *func) { | ||
run(block); | ||
} | ||
} | ||
} | ||
|
||
void AArch64StackOffsetFixupPass::run(mcode::BasicBlock &block) { | ||
mcode::StackFrame &frame = block.get_func()->get_stack_frame(); | ||
|
||
for (mcode::InstrIter iter = block.begin(); iter != block.end(); ++iter) { | ||
mcode::Instruction &instr = *iter; | ||
mcode::Opcode opcode = instr.get_opcode(); | ||
|
||
if (!Utils::is_one_of<mcode::Opcode>(opcode, {AArch64Opcode::ADD, AArch64Opcode::SUB})) { | ||
continue; | ||
} | ||
|
||
mcode::Operand &operand = instr.get_operand(2); | ||
if (!operand.is_stack_slot_offset() || instr.get_operands().get_size() == 4) { | ||
continue; | ||
} | ||
|
||
mcode::Operand::StackSlotOffset offset = operand.get_stack_slot_offset(); | ||
mcode::StackSlot &stack_slot = frame.get_stack_slot(offset.slot_index); | ||
unsigned total_offset = stack_slot.get_offset() + offset.additional_offset; | ||
|
||
if (total_offset < 4096) { | ||
continue; | ||
} | ||
|
||
ASSERT(total_offset < 4096 * 4096); | ||
|
||
operand = mcode::Operand::from_int_immediate(total_offset >> 12, operand.get_size()); | ||
instr.get_operands().append(mcode::Operand::from_aarch64_left_shift(12)); | ||
|
||
mcode::Operand m_imm_remainder = mcode::Operand::from_int_immediate(total_offset & 0xFFF); | ||
block.insert_after( | ||
iter, | ||
mcode::Instruction(opcode, {instr.get_operand(0), instr.get_operand(0), m_imm_remainder}) | ||
); | ||
} | ||
} | ||
|
||
} // namespace target | ||
} // namespace banjo |
21 changes: 21 additions & 0 deletions
21
src/banjo/target/aarch64/aarch64_stack_offset_fixup_pass.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef BANJO_TARGET_AARCH64_AARCH64_STACK_OFFSET_FIXUP_PASS_H | ||
#define BANJO_TARGET_AARCH64_AARCH64_STACK_OFFSET_FIXUP_PASS_H | ||
|
||
#include "banjo/codegen/machine_pass.hpp" | ||
|
||
namespace banjo { | ||
namespace target { | ||
|
||
class AArch64StackOffsetFixupPass final : public codegen::MachinePass { | ||
|
||
public: | ||
void run(mcode::Module &module_); | ||
|
||
private: | ||
void run(mcode::BasicBlock &block); | ||
}; | ||
|
||
} // namespace target | ||
} // namespace banjo | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters