refactor(backend): 单端 MLIR —— 发射器全树改名 mlirlite 并删除 --backend 开关
- App/Test 的 .vp 中 llvmlite 全部改名为 mlirlite(import、限定名、类型注解、注释) - 删除后端开关:Config.set_backend/is_mlir_backend/alias_module_name、BackendTarget/BackendIsMlir、CLI --backend、options.backend/options.target 读取,以及 IncludesScanner/StubMergerIR 的模块别名调用 - BuildPipeline 的 mlir-opt -> mlir-translate 降级管线去掉开关门,改为恒执行 - backend_dir_suffix 改名 mlir_dir_suffix 并恒返回 _mlir:TempDir/OutputDir/includes 缓存继续落在 *_mlir,避免复用旧 LLVM 后端的 .ll/obj - project.vpj 删除已失效的 options.target
This commit is contained in:
1 parent
1dcd29db9c
commit
7b3e814524
70 files changed
+5670
-5746
No files matched your search
@@ -53,7 +53,7 @@ _phase2_cmd_path: str = None
|
||||
# bat 文件是否已写入 header(@echo off),首次写入时置 1
|
||||
_phase2_bat_init: int = 0
|
||||
|
||||
# MLIR 后端(Config.is_mlir_backend())降级步骤:mlirlite 发射的是 MLIR 文本,
|
||||
# MLIR 降级步骤(单端固定,无后端开关):mlirlite 发射的是 MLIR 文本,
|
||||
# 而 opt/llc 只接受 LLVM IR,故在两者之前插入:
|
||||
# mlir-opt <in> -o <in>.mlir.opt (语法/语义校验)
|
||||
# mlir-translate --mlir-to-llvmir <in>.mlir.opt -o <in>.ll.local (降级回 LLVM IR)
|
||||
@@ -270,8 +270,8 @@ def TranslateFileGetTrans(mb: memhub.MemBuddy*, file_path: str,
|
||||
return None
|
||||
# --traceback: when this file is includes/traceback.vp, inject the startup
|
||||
# Install() ctor into its IR (before the caller dumps stub/text.ll). The
|
||||
# injector lives in the Gen layer, which already depends on llvmlite, so
|
||||
# BuildPipeline gains no cross-module llvmlite symbol dependency.
|
||||
# injector lives in the Gen layer, which already depends on mlirlite, so
|
||||
# BuildPipeline gains no cross-module mlirlite symbol dependency.
|
||||
if _traceback_mode != 0 and _tb_basename_is_traceback(file_path) != 0:
|
||||
HandlesTranslator.InjectTracebackInstallCtor(tr)
|
||||
return tr
|
||||
@@ -426,37 +426,36 @@ def compile_ll_to_obj(ir_path: str, output_dir: str, module_name: str, cc_cmd: s
|
||||
# 用直接地址寻址,ASan 全局 redzone 重定位后引用错位会读到垃圾指针。
|
||||
compile_input: str = ir_path
|
||||
|
||||
# ---- MLIR 后端降级:mlir-opt(校验)→ mlir-translate(降级回 LLVM IR)----
|
||||
# ---- MLIR 降级(单端固定,无开关):mlir-opt(校验)→ mlir-translate ----
|
||||
# 必须在 ASan opt 与 llc 之前,并把 compile_input 替换为 <...>.ll.local。
|
||||
if Config.is_mlir_backend() != 0:
|
||||
ll_local_path: str = _ir_sibling_path(ir_path, ".ll.local")
|
||||
mlir_opt_out: str = _ir_sibling_path(ir_path, ".mlir.opt")
|
||||
if ll_local_path is None or mlir_opt_out is None:
|
||||
ll_local_path: str = _ir_sibling_path(ir_path, ".ll.local")
|
||||
mlir_opt_out: str = _ir_sibling_path(ir_path, ".mlir.opt")
|
||||
if ll_local_path is None or mlir_opt_out is None:
|
||||
return 1
|
||||
mo_len: sizet = len(MLIR_OPT_CMD) + len(ir_path) + len(mlir_opt_out) + 16
|
||||
cmd_mo: str = _mbuddy.alloc(mo_len)
|
||||
if cmd_mo is None:
|
||||
return 1
|
||||
viperlib.snprintf(cmd_mo, mo_len, "%s %s -o %s", MLIR_OPT_CMD, ir_path, mlir_opt_out)
|
||||
mt_len: sizet = len(MLIR_TRANSLATE_CMD) + len(mlir_opt_out) + len(ll_local_path) + 40
|
||||
cmd_mt: str = _mbuddy.alloc(mt_len)
|
||||
if cmd_mt is None:
|
||||
return 1
|
||||
viperlib.snprintf(cmd_mt, mt_len, "%s --mlir-to-llvmir %s -o %s", MLIR_TRANSLATE_CMD, mlir_opt_out, ll_local_path)
|
||||
if _phase2_cmd_path is not None:
|
||||
# 只写命令(须排在下面的 ASan/llc 命令之前)
|
||||
_phase2_write_cmd(cmd_mo)
|
||||
_phase2_write_cmd(cmd_mt)
|
||||
else:
|
||||
mo_rc: int = _run_cmd_wait(cmd_mo)
|
||||
if mo_rc != 0:
|
||||
VLogger.error(f"mlir-opt 失败 (module={module_name}, exit={mo_rc}, cmd={cmd_mo})", "MLIR")
|
||||
return 1
|
||||
mo_len: sizet = len(MLIR_OPT_CMD) + len(ir_path) + len(mlir_opt_out) + 16
|
||||
cmd_mo: str = _mbuddy.alloc(mo_len)
|
||||
if cmd_mo is None:
|
||||
mt_rc: int = _run_cmd_wait(cmd_mt)
|
||||
if mt_rc != 0:
|
||||
VLogger.error(f"mlir-translate 失败 (module={module_name}, exit={mt_rc}, cmd={cmd_mt})", "MLIR")
|
||||
return 1
|
||||
viperlib.snprintf(cmd_mo, mo_len, "%s %s -o %s", MLIR_OPT_CMD, ir_path, mlir_opt_out)
|
||||
mt_len: sizet = len(MLIR_TRANSLATE_CMD) + len(mlir_opt_out) + len(ll_local_path) + 40
|
||||
cmd_mt: str = _mbuddy.alloc(mt_len)
|
||||
if cmd_mt is None:
|
||||
return 1
|
||||
viperlib.snprintf(cmd_mt, mt_len, "%s --mlir-to-llvmir %s -o %s", MLIR_TRANSLATE_CMD, mlir_opt_out, ll_local_path)
|
||||
if _phase2_cmd_path is not None:
|
||||
# 只写命令(须排在下面的 ASan/llc 命令之前)
|
||||
_phase2_write_cmd(cmd_mo)
|
||||
_phase2_write_cmd(cmd_mt)
|
||||
else:
|
||||
mo_rc: int = _run_cmd_wait(cmd_mo)
|
||||
if mo_rc != 0:
|
||||
VLogger.error(f"mlir-opt 失败 (module={module_name}, exit={mo_rc}, cmd={cmd_mo})", "MLIR")
|
||||
return 1
|
||||
mt_rc: int = _run_cmd_wait(cmd_mt)
|
||||
if mt_rc != 0:
|
||||
VLogger.error(f"mlir-translate 失败 (module={module_name}, exit={mt_rc}, cmd={cmd_mt})", "MLIR")
|
||||
return 1
|
||||
compile_input = ll_local_path
|
||||
compile_input = ll_local_path
|
||||
|
||||
# --phase2command 模式:不执行 opt/llc,把 opt(ASan)+ llc 命令写入 bat
|
||||
if _phase2_cmd_path is not None:
|
||||
@@ -577,25 +576,24 @@ def init_llc_task(task: LlcTask | t.CPtr, ir_path: str, output_dir: str,
|
||||
# compile_ll_to_obj 的 compile_input 同口径(否则 opt 生成了插桩产物
|
||||
# 却被 llc 忽略,App 侧 obj 里 0 处 __asan,内存排查半盲)
|
||||
compile_input: str = ir_path
|
||||
# MLIR 后端降级:worker 先跑 mlir-opt(校验)→ mlir-translate(降级回 LLVM IR),
|
||||
# 之后的 ASan OptCmd / LlcCmd 输入必须是 <...>.ll.local。
|
||||
if Config.is_mlir_backend() != 0:
|
||||
ll_local_path: str = _ir_sibling_path(ir_path, ".ll.local")
|
||||
mlir_opt_out: str = _ir_sibling_path(ir_path, ".mlir.opt")
|
||||
if ll_local_path is None or mlir_opt_out is None:
|
||||
return 1
|
||||
mo_len: sizet = len(MLIR_OPT_CMD) + len(ir_path) + len(mlir_opt_out) + 16
|
||||
task.MlirOptCmd = stdlib.malloc(mo_len)
|
||||
if task.MlirOptCmd is None:
|
||||
return 1
|
||||
viperlib.snprintf(task.MlirOptCmd, mo_len, "%s %s -o %s", MLIR_OPT_CMD, ir_path, mlir_opt_out)
|
||||
mt_len: sizet = len(MLIR_TRANSLATE_CMD) + len(mlir_opt_out) + len(ll_local_path) + 40
|
||||
task.MlirTranslateCmd = stdlib.malloc(mt_len)
|
||||
if task.MlirTranslateCmd is None:
|
||||
return 1
|
||||
viperlib.snprintf(task.MlirTranslateCmd, mt_len, "%s --mlir-to-llvmir %s -o %s",
|
||||
MLIR_TRANSLATE_CMD, mlir_opt_out, ll_local_path)
|
||||
compile_input = ll_local_path
|
||||
# MLIR 降级(单端固定,无开关):worker 先跑 mlir-opt(校验)→ mlir-translate
|
||||
# (降级回 LLVM IR),之后的 ASan OptCmd / LlcCmd 输入必须是 <...>.ll.local。
|
||||
ll_local_path: str = _ir_sibling_path(ir_path, ".ll.local")
|
||||
mlir_opt_out: str = _ir_sibling_path(ir_path, ".mlir.opt")
|
||||
if ll_local_path is None or mlir_opt_out is None:
|
||||
return 1
|
||||
mo_len: sizet = len(MLIR_OPT_CMD) + len(ir_path) + len(mlir_opt_out) + 16
|
||||
task.MlirOptCmd = stdlib.malloc(mo_len)
|
||||
if task.MlirOptCmd is None:
|
||||
return 1
|
||||
viperlib.snprintf(task.MlirOptCmd, mo_len, "%s %s -o %s", MLIR_OPT_CMD, ir_path, mlir_opt_out)
|
||||
mt_len: sizet = len(MLIR_TRANSLATE_CMD) + len(mlir_opt_out) + len(ll_local_path) + 40
|
||||
task.MlirTranslateCmd = stdlib.malloc(mt_len)
|
||||
if task.MlirTranslateCmd is None:
|
||||
return 1
|
||||
viperlib.snprintf(task.MlirTranslateCmd, mt_len, "%s --mlir-to-llvmir %s -o %s",
|
||||
MLIR_TRANSLATE_CMD, mlir_opt_out, ll_local_path)
|
||||
compile_input = ll_local_path
|
||||
# ASan 模式:opt 插桩命令(worker 先跑 MLIR 降级/opt 再跑 llc,故 LlcCmd 的输入
|
||||
# 必须指向 asan_path;失败即置 Result)
|
||||
if _asan_mode != 0:
|
||||
|
||||
@@ -7,7 +7,7 @@ import viperlib
|
||||
import w32.fileio as fileio
|
||||
import w32.win32base
|
||||
import ast
|
||||
import llvmlite
|
||||
import mlirlite
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.core.Gen.Translator as HandlesTranslator
|
||||
import lib.core.IncludesScanner as IncludesScanner
|
||||
@@ -522,7 +522,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str,
|
||||
# ============================================================
|
||||
# Phase 1a-pre-generic-all: mark1 前全量预注册 includes 泛型模板
|
||||
#
|
||||
# 非可达泛型文件(_list/_dict/linkedlist/llvmlite 等)的模板若在 Phase2(mark2 之后)才注册会被 reset 回收 → list[int]/dict[...] 特化失败。
|
||||
# 非可达泛型文件(_list/_dict/linkedlist/mlirlite 等)的模板若在 Phase2(mark2 之后)才注册会被 reset 回收 → list[int]/dict[...] 特化失败。
|
||||
# 故对全部 includes 轻量预注册,使模板表与节点都落在 mark1 之前(_PreRegisterAllGenericTemplates 内有 generic marker 文本预筛,不 parse 全部 AST,OOM 风险可控)。
|
||||
full_scan_g: rawptr[IncludesScanner.ScanResult] = IncludesScanner.scan_includes(mb, includes_dir)
|
||||
if full_scan_g is not None:
|
||||
@@ -1087,8 +1087,8 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str,
|
||||
|
||||
# --traceback: inject the startup Install() ctor when translating traceback.vp
|
||||
# (its stub/text.ll below are what Phase2 reuses to build the .obj). The
|
||||
# injector lives in the Gen layer (already depends on llvmlite), so this
|
||||
# module gains no cross-module llvmlite symbol dependency.
|
||||
# injector lives in the Gen layer (already depends on mlirlite), so this
|
||||
# module gains no cross-module mlirlite symbol dependency.
|
||||
if BuildPipeline._traceback_mode != 0 and BuildPipeline._tb_basename_is_traceback(file_path) != 0:
|
||||
HandlesTranslator.InjectTracebackInstallCtor(tr)
|
||||
|
||||
@@ -1113,7 +1113,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str,
|
||||
stdlib.free(tr._nonlocal_names)
|
||||
failed += 1
|
||||
continue
|
||||
tr.dump_ir(stub_buf, PHASE1_IR_SIZE, llvmlite.OUTPUT_STUB)
|
||||
tr.dump_ir(stub_buf, PHASE1_IR_SIZE, mlirlite.OUTPUT_STUB)
|
||||
stub_len: sizet = string.strlen(stub_buf)
|
||||
|
||||
# save stub.ll
|
||||
@@ -1137,7 +1137,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str,
|
||||
stdlib.free(tr._nonlocal_names)
|
||||
failed += 1
|
||||
continue
|
||||
tr.dump_ir(text_buf, PHASE1_IR_SIZE, llvmlite.OUTPUT_TEXT)
|
||||
tr.dump_ir(text_buf, PHASE1_IR_SIZE, mlirlite.OUTPUT_TEXT)
|
||||
text_len: sizet = string.strlen(text_buf)
|
||||
|
||||
# save text.ll
|
||||
@@ -1158,7 +1158,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str,
|
||||
full_buf_p1: bytes = stdlib.malloc(PHASE1_FULL_SIZE)
|
||||
if full_buf_p1 is None:
|
||||
VLogger.error("full.ll 缓冲区分配失败", "Phase1")
|
||||
tr.dump_ir(full_buf_p1, PHASE1_FULL_SIZE, llvmlite.OUTPUT_FULL)
|
||||
tr.dump_ir(full_buf_p1, PHASE1_FULL_SIZE, mlirlite.OUTPUT_FULL)
|
||||
full_len_p1: sizet = string.strlen(full_buf_p1)
|
||||
full_path_p1: str = StubMergerCollect._sliced_path(temp_dir, dir_len_p1, sha1, "full.ll")
|
||||
if full_path_p1 is not None:
|
||||
|
||||
@@ -9,7 +9,7 @@ import w32.fileio as fileio
|
||||
import w32.win32file
|
||||
import w32.win32base
|
||||
import ast
|
||||
import llvmlite
|
||||
import mlirlite
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.core.Gen.Translator as HandlesTranslator
|
||||
import lib.core.IncludesScanner as IncludesScanner
|
||||
|
||||
@@ -8,7 +8,7 @@ import w32.fileio as fileio
|
||||
import w32.win32file
|
||||
import w32.win32base
|
||||
import ast
|
||||
import llvmlite
|
||||
import mlirlite
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.core.Gen.Translator as HandlesTranslator
|
||||
import lib.core.IncludesScanner as IncludesScanner
|
||||
|
||||
@@ -11,7 +11,7 @@ import w32.win32file
|
||||
import w32.win32base
|
||||
import sys
|
||||
import ast
|
||||
import llvmlite
|
||||
import mlirlite
|
||||
import subprocess
|
||||
import argparse
|
||||
import lib.core.VLogger as VLogger
|
||||
@@ -1069,7 +1069,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*,
|
||||
stub_buf_a: bytes = stdlib.malloc(PHASE_A_IR_SIZE)
|
||||
if stub_buf_a is None:
|
||||
VLogger.error("stub 缓冲区分配失败", "PhaseA")
|
||||
tr_a.dump_ir(stub_buf_a, PHASE_A_IR_SIZE, llvmlite.OUTPUT_STUB)
|
||||
tr_a.dump_ir(stub_buf_a, PHASE_A_IR_SIZE, mlirlite.OUTPUT_STUB)
|
||||
stub_len_a: sizet = string.strlen(stub_buf_a)
|
||||
|
||||
# save stub.ll (切片路径: temp_dir/{sha1前缀}/{sha1}.stub.ll)
|
||||
@@ -1086,7 +1086,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*,
|
||||
text_buf_a: bytes = stdlib.malloc(PHASE_A_IR_SIZE)
|
||||
if text_buf_a is None:
|
||||
VLogger.error("text 缓冲区分配失败", "PhaseA")
|
||||
tr_a.dump_ir(text_buf_a, PHASE_A_IR_SIZE, llvmlite.OUTPUT_TEXT)
|
||||
tr_a.dump_ir(text_buf_a, PHASE_A_IR_SIZE, mlirlite.OUTPUT_TEXT)
|
||||
text_len_a: sizet = string.strlen(text_buf_a)
|
||||
|
||||
# save text.ll (切片路径)
|
||||
@@ -1106,7 +1106,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*,
|
||||
full_buf_a: bytes = stdlib.malloc(PHASE_A_FULL_SIZE)
|
||||
if full_buf_a is None:
|
||||
VLogger.error("full.ll 缓冲区分配失败", "PhaseA")
|
||||
tr_a.dump_ir(full_buf_a, PHASE_A_FULL_SIZE, llvmlite.OUTPUT_FULL)
|
||||
tr_a.dump_ir(full_buf_a, PHASE_A_FULL_SIZE, mlirlite.OUTPUT_FULL)
|
||||
full_len_a: sizet = string.strlen(full_buf_a)
|
||||
full_path_a: str = StubMergerCollect._sliced_path(temp_dir, td_len_pa, ent.Sha1, "full.ll")
|
||||
if full_path_a is not None:
|
||||
@@ -1484,7 +1484,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*,
|
||||
# 保存 stub.ll (切片路径)
|
||||
inc_stub_buf: bytes = stdlib.malloc(PBP_IR_SIZE)
|
||||
if inc_stub_buf is not None:
|
||||
tr_mi.dump_ir(inc_stub_buf, PBP_IR_SIZE, llvmlite.OUTPUT_STUB)
|
||||
tr_mi.dump_ir(inc_stub_buf, PBP_IR_SIZE, mlirlite.OUTPUT_STUB)
|
||||
inc_stub_len: sizet = string.strlen(inc_stub_buf)
|
||||
inc_stub_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "stub.ll")
|
||||
if inc_stub_path is not None:
|
||||
@@ -1497,7 +1497,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*,
|
||||
# 保存 text.ll (切片路径)
|
||||
inc_text_buf: bytes = stdlib.malloc(PBP_IR_SIZE)
|
||||
if inc_text_buf is not None:
|
||||
tr_mi.dump_ir(inc_text_buf, PBP_IR_SIZE, llvmlite.OUTPUT_TEXT)
|
||||
tr_mi.dump_ir(inc_text_buf, PBP_IR_SIZE, mlirlite.OUTPUT_TEXT)
|
||||
inc_text_len: sizet = string.strlen(inc_text_buf)
|
||||
inc_text_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "text.ll")
|
||||
if inc_text_path is not None:
|
||||
@@ -1513,7 +1513,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*,
|
||||
inc_full_buf: bytes = stdlib.malloc(PBP_FULL_SIZE)
|
||||
if inc_full_buf is None:
|
||||
VLogger.error("full.ll 缓冲区分配失败", "PhaseB+")
|
||||
tr_mi.dump_ir(inc_full_buf, PBP_FULL_SIZE, llvmlite.OUTPUT_FULL)
|
||||
tr_mi.dump_ir(inc_full_buf, PBP_FULL_SIZE, mlirlite.OUTPUT_FULL)
|
||||
inc_full_len: sizet = string.strlen(inc_full_buf)
|
||||
inc_full_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "full.ll")
|
||||
if inc_full_path is not None:
|
||||
|
||||
Reference in new issue
Block a user