LLVM-9.0 学习者教程

LLVM-9.0 学习者教程

LLVM-9.0-Learner-Tutorial A blog for LLVM(v9.0.0 or v11.0.0) beginner, step by step, with detailed documents and comments. Record the way I learn LLVM and accomplish a complete project for FPGA High-Level Synthesis with it. LLVM-9.0-Learner-Tutorial 项目地址: https://gitcode.com/gh_mirrors/ll/LLVM-9.0-Learner-Tutorial

项目介绍

LLVM-9.0-Learner-Tutorial 是一个面向 LLVM(v9.0.0 或 v11.0.0)初学者的详细教程。该项目通过逐步讲解和详细的文档注释,记录了作者学习 LLVM 并最终完成一个完整项目的过程。教程的目标是帮助初学者理解和掌握 LLVM,特别是如何使用 LLVM 进行 FPGA 高层次综合(High-Level Synthesis, HLS)。

项目快速启动

1. 下载项目

首先,克隆项目到本地:

git clone https://github.com/zslwyuan/LLVM-9.0-Learner-Tutorial.git

2. 安装 LLVM-9.0

如果安装 LLVM 时遇到问题,建议使用项目提供的安装脚本:

cd LLVM-9.0-Learner-Tutorial
./install_llvm.sh

3. 构建项目

进入项目目录并使用 CMake 构建项目:

mkdir build
cd build
cmake ..
make

4. 运行测试

构建完成后,可以运行测试来验证安装和构建是否成功:

./TestBuiltFiles.sh

应用案例和最佳实践

案例1:分析程序中的函数名称

通过编写一个分析 pass,可以获取程序中所有函数的名称。以下是一个简单的示例代码:

#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

namespace {
  struct FuncNamePrinter : public FunctionPass {
    static char ID;
    FuncNamePrinter() : FunctionPass(ID) {}

    bool runOnFunction(Function &F) override {
      errs() << "Function Name: " << F.getName() << "\n";
      return false;
    }
  };
}

char FuncNamePrinter::ID = 0;
static RegisterPass<FuncNamePrinter> X("funcname", "Function Name Printer", false, false);

案例2:获取函数中的依赖图

通过编写一个分析 pass,可以获取函数中的依赖图并绘制出来。以下是一个简单的示例代码:

#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Analysis/DependenceAnalysis.h"

using namespace llvm;

namespace {
  struct DependenceGraphPrinter : public FunctionPass {
    static char ID;
    DependenceGraphPrinter() : FunctionPass(ID) {}

    bool runOnFunction(Function &F) override {
      DependenceInfo DI(&F);
      DI.print(errs());
      return false;
    }
  };
}

char DependenceGraphPrinter::ID = 0;
static RegisterPass<DependenceGraphPrinter> Y("depgraph", "Dependence Graph Printer", false, false);

典型生态项目

1. Light-HLS

Light-HLS 是一个基于 LLVM 的项目,专注于 FPGA 高层次综合。它通过分析和优化 LLVM IR,生成适用于 FPGA 的优化代码。

2. Polly

Polly 是 LLVM 的一个子项目,专注于多面体模型(Polyhedral Model)的优化。它通过分析和优化循环结构,提高代码的并行性和性能。

3. Clang

Clang 是 LLVM 的 C/C++ 前端,提供了丰富的 API 和工具,用于源代码的分析和转换。Clang 与 LLVM 紧密集成,是 LLVM 生态系统中的重要组成部分。

LLVM-9.0-Learner-Tutorial A blog for LLVM(v9.0.0 or v11.0.0) beginner, step by step, with detailed documents and comments. Record the way I learn LLVM and accomplish a complete project for FPGA High-Level Synthesis with it. LLVM-9.0-Learner-Tutorial 项目地址: https://gitcode.com/gh_mirrors/ll/LLVM-9.0-Learner-Tutorial

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咎丹娜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值