Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

申领对WritingAnLLVMNewPMPass.md的翻译 #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JadeSnow7
Copy link

No description provided.

@@ -1,87 +1,50 @@
---
status: collected
status: translating
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看你已经把翻译都放上来了,所以建议你直接修改status为translate

title: "Writing an LLVM Pass"
author: Linux Kernel Community
collector: tttturtle-russ
collected_date: 20240807
translator: JadeSnow7
translating_date: 20241116
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那这样也要改成translated_date

:::
本文介绍了新的pass管理机制(New Pass Manager,NPM)。LLVM对代码生成管道使用的是传统的pass管理机制(Legacy Pass Manager)。详情参阅
`WritingAnLLVMPass` 和
`NewPassManager`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是英文句号


::: {.contents local=""}
:::
本文介绍了新的pass管理机制(New Pass Manager,NPM)。LLVM对代码生成管道使用的是传统的pass管理机制(Legacy Pass Manager)。详情参阅
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

英文两边如果是中文要加空格分割

link: https://github.com/llvm/llvm-project/blob/main/llvm/docs/WritingAnLLVMNewPMPass.rst
---
# Writing an LLVM Pass
# 编写LLVM Pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

英文两边如果是中文要加空格分割


## Introduction \-\-- What is a pass?
LLVM pass框架是LLVM系统中一个非常重要的组成部分,因为大多数编译器最值得关注的部分都在LLVM pass上。Pass执行着编译器的各种转换和优化工作,它们提供这些转换工作所需要的分析结果,并且最重要的是,它们为编译器代码提供了一种组织技术。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

英文两边如果是中文要加空格分割。请全文进行检测,如果两边是其他符号,可以参考Wiki 中的中文翻译指北来确认

::: title
Warning
:::
与传统pass管理器下的pass不同,传统pass管理器通过继承定义pass接口,而新pass管理器下的pass则依赖于基于概念的多态性,这意味着没有显式的接口(有关详细信息,请参见 `PassManager.h` 中的注释)。所有LLVM pass都继承自CRTP混入 `PassInfoMixin<PassT>` 。pass应该有一个run()方法,该方法返回一个 `PreservedAnalyses` ,并接受某些IR单元以及一个分析管理器作为输入。例如,函数pass将具有如下方法:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRTP混入

mixin是CPP中的一个特殊的类,同时也是LLVM新一代Pass管理器的实现。这里是名词,而不是动词,我的建议是保留英语专有名词

`WritingAnLLVMPass`{.interpreted-text role="doc"} and
`NewPassManager`{.interpreted-text role="doc"}.
::::
我们将向您展示如何构建一个pass,包括设置构建、创建pass,到执行和测试它。查看现有的pass总是学习细节的一个好方法。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass 前后要有空格


First, configure and build LLVM as described in
`GettingStarted`{.interpreted-text role="doc"}.
首先,按照《入门指南》中所述配置和构建 LLVM。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

保留原有格式


Our class is in the `llvm` namespace so that we don\'t pollute the
global namespace.
这段描述说明了如何创建一个 Pass 类,并声明 run() 方法,该方法实际执行 Pass 的功能。通过继承 `PassInfoMixin<PassT>` ,我们可以避免亲自编写一些样板代码。我们的类位于 llvm 命名空间中,以避免污染全局命名空间。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和原文格式保持一致


Next we\'ll create `llvm/lib/Transforms/Utils/HelloWorld.cpp`, starting
with
接下来,我们将创建 llvm/lib/Transforms/Utils/HelloWorld.cpp 文件,并从以下内容开始:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和原文格式保持一致

Now that you have a brand new shiny pass, we can build
`opt`{.interpreted-text role="program"} and use it to run some LLVM IR
through the pass.
现在你已经有了一个全新的pass,我们可以构建 `opt`并使用它将一些 LLVM IR 代码通过该pass处理。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opt后面与中文要有空格

a lit test at `llvm/test/Transforms/Utils/helloworld.ll`. See
`TestingGuide`{.interpreted-text role="doc"} for more information on
testing.
测试我们的 Pass 非常重要,以防止将来出现回归问题。我们将在 llvm/test/Transforms/Utils/helloworld.ll 添加一个 lit 测试。有关测试的更多信息,请参阅《测试指南》。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和原文格式保持一致

`llvm/lib/Passes/PassBuilder.cpp` multiple times for various reasons.
Since it constructs our pass, we need to also add the proper #include in
`llvm/lib/Passes/PassBuilder.cpp`:
在 `llvm/lib/Passes/PassBuilder.cpp` 中包含头文件
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

由于不同的原因,llvm/lib/Passes/PassBuilder.cpp 包含了多次 llvm/lib/Passes/PassRegistry.def。由于其负责构建我们的 pass,所以我们也需要在 llvm/lib/Passes/PassBuilder.cpp 包含正确的头文件。

`LLVM_${NAME}_LINK_INTO_TOOLS` to `ON` turns the project into a
statically linked extension.
- llvm::PassPluginLibraryInfo get##Name##PluginInfo();
- extern "C" ::llvm::PassPluginLibraryInfo llvmGetPassPluginInfo() LLVM_ATTRIBUTE_WEAK;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

与原文格式一致

@tttturtle-russ
Copy link
Member

Any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants