forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.7 KiB
49 lines
1.7 KiB
# 模拟帧槽分配
|
|
|
|
num_params = 390
|
|
num_reg_params = 8
|
|
|
|
# 模拟 LowerFunctionParams 中的帧槽分配
|
|
frame_slots = []
|
|
for param_idx in range(num_params):
|
|
# 创建参数帧槽
|
|
param_slot = len(frame_slots)
|
|
frame_slots.append({"type": "param", "param_idx": param_idx, "is_stack_arg": False})
|
|
|
|
# 如果参数在栈上,创建 callee_stack_arg 帧槽
|
|
if param_idx >= num_reg_params:
|
|
frame_slots.append({"type": "callee_stack_arg", "param_idx": param_idx, "is_stack_arg": True})
|
|
|
|
# 模拟 alloca 指令处理中的帧槽分配
|
|
# 假设有 390 个 alloca 指令
|
|
num_alloca = 390
|
|
for alloca_idx in range(num_alloca):
|
|
frame_slots.append({"type": "alloca", "alloca_idx": alloca_idx, "is_stack_arg": False})
|
|
|
|
print(f"总帧槽数量: {len(frame_slots)}")
|
|
|
|
# 计算 FrameLowering 中的偏移
|
|
local_cursor = 0
|
|
stack_arg_cursor = 0
|
|
for i, slot in enumerate(frame_slots):
|
|
if slot["is_stack_arg"]:
|
|
slot["offset"] = stack_arg_cursor
|
|
stack_arg_cursor += 8
|
|
else:
|
|
local_cursor += 4
|
|
slot["offset"] = -local_cursor
|
|
|
|
# 找到第 221 和 222 个参数的帧槽
|
|
for i, slot in enumerate(frame_slots):
|
|
if slot["type"] == "param" and slot["param_idx"] in [220, 221]:
|
|
print(f"\n参数索引 {slot['param_idx']} (第 {slot['param_idx']+1} 个参数):")
|
|
print(f" 帧槽索引: {i}")
|
|
print(f" 帧槽偏移: {slot['offset']}")
|
|
|
|
# 找到第 221 和 222 个 alloca 的帧槽
|
|
for i, slot in enumerate(frame_slots):
|
|
if slot["type"] == "alloca" and slot["alloca_idx"] in [220, 221]:
|
|
print(f"\nAlloca 索引 {slot['alloca_idx']} (第 {slot['alloca_idx']+1} 个 alloca):")
|
|
print(f" 帧槽索引: {i}")
|
|
print(f" 帧槽偏移: {slot['offset']}")
|