LLVM IR 即 LLVM Language Reference Manual 15 翻译: 001节

2023-10-31

Abstract

This document is a reference manual for the LLVM assembly language. LLVM is a Static Single Assignment (SSA) based representation that provides type safety, low-level operations, flexibility, and the capability of representing ‘all’ high-level languages cleanly. It is the common code representation used throughout all phases of the LLVM compilation strategy.

Introduction

The LLVM code representation is designed to be used in three different forms: as an in-memory compiler IR, as an on-disk bitcode representation (suitable for fast loading by a Just-In-Time compiler), and as a human readable assembly language representation. This allows LLVM to provide a powerful intermediate representation for efficient compiler transformations and analysis, while providing a natural means to debug and visualize the transformations. The three different forms of LLVM are all equivalent. This document describes the human readable representation and notation.

The LLVM representation aims to be light-weight and low-level while being expressive, typed, and extensible at the same time. It aims to be a “universal IR” of sorts, by being at a low enough level that high-level ideas may be cleanly mapped to it (similar to how microprocessors are “universal IR’s”, allowing many source languages to be mapped to them). By providing type information, LLVM can be used as the target of optimizations: for example, through pointer analysis, it can be proven that a C automatic variable is never accessed outside of the current function, allowing it to be promoted to a simple SSA value instead of a memory location.

Well-Formedness

It is important to note that this document describes ‘well formed’ LLVM assembly language. There is a difference between what the parser accepts and what is considered ‘well formed’. For example, the following instruction is syntactically okay, but not well formed:

%x = add i32 1, %x

because the definition of %x does not dominate all of its uses. The LLVM infrastructure provides a verification pass that may be used to verify that an LLVM module is well formed. This pass is automatically run by the parser after parsing input assembly and by the optimizer before it outputs bitcode. The violations pointed out by the verifier pass indicate bugs in transformation passes or input to the parser.

Identifiers

LLVM identifiers come in two basic types: global and local. Global identifiers (functions, global variables) begin with the '@' character. Local identifiers (register names, types) begin with the '%' character. Additionally, there are three different formats for identifiers, for different purposes:

  1. Named values are represented as a string of characters with their prefix. For example, %foo@DivisionByZero%a.really.long.identifier. The actual regular expression used is ‘[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*’. Identifiers that require other characters in their names can be surrounded with quotes. Special characters may be escaped using "\xx" where xx is the ASCII code for the character in hexadecimal. In this way, any character can be used in a name value, even quotes themselves. The "\01" prefix can be used on global values to suppress mangling.
  2. Unnamed values are represented as an unsigned numeric value with their prefix. For example, %12@2%44.
  3. Constants, which are described in the section Constants below.

LLVM requires that values start with a prefix for two reasons: Compilers don’t need to worry about name clashes with reserved words, and the set of reserved words may be expanded in the future without penalty. Additionally, unnamed identifiers allow a compiler to quickly come up with a temporary variable without having to avoid symbol table conflicts.

Reserved words in LLVM are very similar to reserved words in other languages. There are keywords for different opcodes (‘add’, ‘bitcast’, ‘ret’, etc…), for primitive type names (‘void’, ‘i32’, etc…), and others. These reserved words cannot conflict with variable names, because none of them start with a prefix character ('%' or '@').

Here is an example of LLVM code to multiply the integer variable ‘%X’ by 8:

The easy way:

%result = mul i32 %X, 8

After strength reduction:

%result = shl i32 %X, 3

And the hard way:

%0 = add i32 %X, %X           ; yields i32:%0
%1 = add i32 %0, %0           ; yields i32:%1
%result = add i32 %1, %1

This last way of multiplying %X by 8 illustrates several important lexical features of LLVM:

  1. Comments are delimited with a ‘;’ and go until the end of line.
  2. Unnamed temporaries are created when the result of a computation is not assigned to a named value.
  3. Unnamed temporaries are numbered sequentially (using a per-function incrementing counter, starting with 0). Note that basic blocks and unnamed function parameters are included in this numbering. For example, if the entry basic block is not given a label name and all function parameters are named, then it will get number 0.

It also shows a convention that we follow in this document. When demonstrating instructions, we will follow an instruction with a comment that defines the type and name of value produced.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

LLVM IR 即 LLVM Language Reference Manual 15 翻译: 001节 的相关文章

  • 通过 cmake 链接 libc++ 时 libc++abi 的链接问题

    我正在尝试构建一个简单的 hello world C 使用 LLVM Clang 3 7 0 的程序 根据工具链的源代码构建libc 使用命令行 clang std c 14 stdlib libc fno exceptions hello
  • 如何使用 CUDA/Thrust 对两个数组/向量根据其中一个数组中的值进行排序

    这是一个关于编程的概念问题 总而言之 我有两个数组 向量 我需要对一个数组 向量进行排序 并将更改传播到另一个数组 向量中 这样 如果我对 arrayOne 进行排序 则对于排序中的每个交换 arrayTwo 也会发生同样的情况 现在 我知
  • VS 程序在调试模式下崩溃,但在发布模式下不崩溃?

    我正在 VS 2012 中运行以下程序来尝试 Thrust 函数查找 include cuda runtime h include device launch parameters h include
  • 无法在内存位置找到异常源:cudaError_enum

    我正在尝试确定 Microsoft C 异常的来源 test fft exe 中 0x770ab9bc 处的第一次机会异常 Microsoft C 异常 内存位置 0x016cf234 处的 cudaError enum 我的构建环境是 I
  • 是否可以使用 gold 链接器编译和链接 Clang/LLVM?

    我正在为 LLVM Clang 编写自定义通道 重新编译往往需要一段时间并使用大量内存 我听说 gold 链接器 1 比标准 ld 链接器花费更少的时间并且 2 使用更少的内存 有没有办法将标志传递到 LLVM Clang 构建过程并更改为
  • gcc 与 clang:符号剥离

    gcc 和 AMD Open64 opencc 都有一个 s选项 剥离符号表和重定位信息 到目前为止我还没能在 Clang LLVM 中找到相同的选项 它存在吗 您可以使用stripbinutils 中的实用程序 实际上 llvm ld 有
  • 将 nvidia 运行时添加到 docker 运行时

    我正在运行虚拟机GCP配备特斯拉 GPU 并尝试部署一个PyTorch基于应用程序使用 GPU 加速 我想让 docker 使用这个 GPU 可以从容器访问它 我设法在主机上安装了所有驱动程序 并且该应用程序在那里运行良好 但是当我尝试在
  • cuda-gdb 错误消息

    我尝试使用 cuda gdb 调试我的 CUDA 应用程序 但遇到了一些奇怪的错误 我设置了选项 g G O0构建我的应用程序 我可以在没有 cuda gdb 的情况下运行我的程序 但没有得到正确的结果 因此我决定使用 cuda gdb 但
  • LLVM 互操作性(如 JVM 或 .Net)- 可以吗?

    我最近尝试了一些不同的 LLVM 前端 例如 Clang C Familiy LDC2 D Terra 所有这些语言都可以编译成 LLVM IR 有点可读 和 LLVM IR Bitcode 那么现阶段他们都处于同一 水平 对吗 我的问题是
  • C++ 标准是否允许未初始化的 bool 导致程序崩溃?

    我知道一个 未定义的行为 C 几乎可以让编译器做任何它想做的事情 然而 我遇到了一次令我惊讶的崩溃 因为我认为代码足够安全 在这种情况下 真正的问题仅发生在使用特定编译器的特定平台上 并且仅在启用优化的情况下发生 我尝试了几种方法来重现问题
  • 云或烟雾的粒子系统

    我正在尝试使用 OpenGL 和 CUDA 制作一个简单的用于云和烟雾模拟的粒子系统 如何使粒子系统中的粒子表现得像真正的云或烟雾在低湍流风中的表现 我现在遇到的一些问题是 颗粒聚集成一个大球 粒子扩散到无限远 粒子突然弹射离开 我已经完成
  • CUDA Thrust 的多 GPU 使用

    我想使用我的两张显卡通过 CUDA Thrust 进行计算 我有两张显卡 在单卡上运行对于两张卡都适用 即使我在 std vector 中存储两个 device vector 也是如此 如果我同时使用两张卡 循环中的第一个周期将起作用并且不
  • 为什么 cuCtxCreate 返回旧上下文?

    我已经安装了 CUDA SDK 4 2 64 CUDA工具包4 2 64 CUDA 驱动程序 4 2 64 我检查了 windows 中的每个 nvcuda dll 所有这些都是 4 2 版本 但是当我使用驱动程序 api 创建上下文并使用
  • 用于计算邻居列表的最佳 GPU 算法

    给定 3D 中数千个点的集合 我需要获取落在某个截止值 以欧几里得距离而言 内的每个粒子的邻居列表 并且如果可能的话 从最近到最远排序 在 CUDA 或 OpenCL 语言中 哪种 GPU 算法最快 我所知道的最快的 GPU MD 代码之一
  • NVCC 警告级别

    我希望 NVCC 将以下警告视为错误 warning calling a host function foo from a host device function bar NVCC 文档 NVIDIA CUDA 编译器驱动程序 NVCC
  • 使用 Cuda 并行读取多个文本文件

    我想使用 CUDA 在多个文件中并行搜索给定字符串 我计划使用 pfac 库来搜索给定的字符串 问题是如何并行访问多个文件 示例 我们有一个包含 1000 个文件的文件夹 需要搜索 这里的问题是我应该如何访问给定文件夹中的多个文件 应该动态
  • 如何确定特定的 LLVM 指令是否依赖于另一个指令?

    我正在尝试编写 LLVM 优化过程 我需要一种方法来确定一个 LLVM 指令是否影响另一个指令 或依赖于另一个指令 这些依赖关系可以具有不同的性质 第一条指令创建一个值 另一条指令将其用作操作数 第一条指令写入内存位置 另一条指令从该位置读
  • 对 CUDA 操作进行计时

    我需要计算 CUDA 内核执行的时间 最佳实践指南说我们可以使用事件或标准计时函数 例如clock 在Windows中 我的问题是使用这两个函数给出了完全不同的结果 事实上 与实践中的实际速度相比 事件给出的结果似乎是巨大的 我实际上需要这
  • CUDA 代码会损坏 GPU 吗?

    在测试包含内存错误的 CUDA 时 我的屏幕被冻结了 重新启动后我无法再检测到显卡 我的代码是否有可能物理损坏该卡 这发生在 Ubuntu 14 04 下 我不知道该卡的型号 因为我无法检测到它 但我记得它是一张相当新的卡 感谢所有的评论我
  • 如何从尖点库矩阵格式获取原始指针

    我需要从尖点库矩阵格式获取原始指针 例如 cusp coo matrix

随机推荐

  • 第九章SQL语言

  • Java字节码介绍

    Java字节码 概述 学习 Java 的都知道 我们所编写的 java 代码文件通过编译将会生成 class 文件 最初的方式就是通过 JDK 的 javac 指令来编译 再通过 java 命令执行 main 方法所在的类 从而执行我们的
  • Windows删除流氓软件方法记录

    windows权限管理那相当的糟糕啊 但凡你下载安装国产软件 尤其是那种小广告很多的网站 也有好处 也算是一种免费获得大多数软件的灰色渠道吧 毕竟鱼与熊掌不可兼得嘛 基本都会捆绑一些行为流氓的软件 相对于macos windows就是一个很
  • 安果相亲-找到心仪的另一半 一个安卓免费找对象软件推荐

    安果相亲 全国范围内的真实恋爱相亲平台 致力于帮助用户寻找真实恋爱 我们的实名认证机制确 保用户信息的真实性 汇集了高学历 经济稳定 丰富生活经验的优质单身男女 都在这里真诚地等待那个对的人 每个手机只能注册一个账户 为您提供一个更安全 更
  • ROS联合webots扩展(一)设定目标点进行导航

    设定目标点进行导航 注意 再学习本系列教程时 应该已经安装过ROS了并且需要有一些ROS的基本知识 此教程以webots demo为基础 ubuntu版本 20 04 webots版本 2021a ros版本 noetic 为了能和读者进一
  • 华为HCIE云计算之ebackup备份FC虚拟机

    华为HCIE云计算之ebackup备份FC虚拟机 一 登录ebackup 二 对接FC虚拟化平台 1 对接FC 2 查看FC上所有虚拟机 三 配置存储 1 创建存储单元 2 配置存储池 3 创建存储库 四 ebackup备份流程 1 配置受
  • C#类静态构造函数

    最近有做到面试题如下 class A private static int g n 1 static A g n public A g n public static int main A a1 new A A a2 new A conso
  • CSS 选择器的种类有哪些?怎么用?

    CSS 选择器的种类有哪些 怎么用 CSS 选择器的种类有标签选择器 类选择器 层级选择器 后代选择器 id选择器 组选择器 伪类选择器 作为程序员应该具备根据不同的场景选择适合的CSS选择器 CSS 选择器学习目标 熟悉掌握CSS 选择器
  • 追光的人 团队团队展示

    所属课程 软件工程1916 作业要求 团队作业第一次 团队展示 团队名称 追光的人 作业目标 让团队成员进行初步的认识和了解 互相熟悉 粗定项目类型 1 团队信息 团队名称 追光的人 团队人数 7 团队描述 一万次悲伤 依然会有dream
  • Chat GPT5如果问世会对世界产生什么影响?以及未来chat gpt 5会取代什么类型的工作。

    Chat GPT 5是一种基于人工智能技术的自然语言处理系统 可以自动回复和生成各种文本随着其技术的不断发展和改进 Chat GPT 5对未来世界将会产生以下几方面的影响 1 提升人类语言交流的效率和质量 Chat GPT 5可以高效地处理
  • Redis面试题 (2023最新版)

    文章目录 一 Redis为什么快 1 纯内存访问 2 单线程 避免上下文切换 3 渐进式ReHash 缓存时间戳 1 渐进式ReHash 2 缓存时间戳 二 Redis合适的应用场景 常用基本数据类型 5种 1 字符串 String 1 缓
  • CSS_文字渐变

    定义渐变背景样式 gradient text background image linear gradient to right ff0000 00ff00 渐变色范围 background clip text 应用渐变背景到文本 webk
  • VS2022 CMake报错解决小结

    目录 一 问题背景 二 问题分析 三 问题解决 一 问题背景 VS2022中能够跨平台的工程类型就是CMake项目 一套代码能跨windows Linux Mac多种操作系统 而实际使用时 发现相关资料比较少 需要摸索一下 碰到的问题简述
  • STM32 DMA+ADC连续采样产生的内部噪声和解决办法

    本文讨论的是内部采样频率过高而产生的噪声 DMA ADC连续采样 DMA发送完成产生中断后继续开启ADC转换 如下图中ADC Value数组中出现异常数据 DMA ADC 1ms 间隔采样 异常数据消失 电压12 22 电阻分压系数 4 0
  • javaMail SMTPSendFailedException: java邮件发送常见的异常类型

    421 HL REP 该IP发送行为异常 存在接收者大量不存在情况 被临时禁止连接 请检查是否有用户发送病毒或者垃圾邮件 并核对发送列表有效性 421 HL ICC 该IP同时并发连接数过大 超过了网易的限制 被临时禁止连接 请检查是否有用
  • 【Linux入门指北】第六篇 Linux常用的开发工具

    文章目录 前言 一 Linux编辑器 vi vim 1 vi vim介绍 2 vi vim 各种模式间的相互切换 3 一般模式 4 编辑模式 4 命令行模式 二 Linux软件包管理器 yum RPM 1 yum介绍 2 YUM本地源 系统
  • JavaEE-制作JSTL标签 详解

    使用定制标签库使得JSP程序更加简洁 可读性和可维护性大大的提高了 因此JSP定制标签的优势是非常明显的 它被认为是JSP所有特性中最被看好的特性 我们要编写一个标签 向请求者的浏览器输出 Hello World 同时该标签是一个没有体内容
  • 红队渗透靶场之W1R3S靶场(超详细!)

    W1R3S考察知识 nmap的基本使用 目录爆破工具的使用 CMS漏洞的利用 Linux用户的简单提权 W1R3S靶场搭建 W1R3S靶场下载地址 https download vulnhub com w1r3s w1r3s v1 0 1
  • 用Python做一个简单的视频播放器

    相关文件 关注小编 私信小编领取就好啦 开发工具 Python版本 3 7 8 相关模块 pyqt5模块 以及一些python自带的模块 搭建环境 安装Python并添加到环境变量 pip安装需要的相关模块即可 原理介绍 这里我们主要利用P
  • LLVM IR 即 LLVM Language Reference Manual 15 翻译: 001节

    Abstract This document is a reference manual for the LLVM assembly language LLVM is a Static Single Assignment SSA based