llvm之IR手册翻译(4)

原网址是:http://llvm.org/docs/LangRef.html#abstract
下面这些是我自己的翻译,肯定有很多不恰当的地方,做这些只是希望自己以后翻阅更加方便,如果能对大家有所帮助那是极好的!


全局变量
全局变量定义分配内存在编译时,而不是在程序运行时。
全局变量的定义必须初始化。
全局变量还可以声明,在这种情况下,他没有被初始化。
定义或者声明的全局变量都会存在一个准确的地方或者可选指定的准确的地方。
在变量没有被改变的情况下可以定义为一个全局常量(可以更好的优化,允许全局数据存在一个可执行的只读部分,等)。需要注意的是需要在运行时初始化的变量,不能标记为常量因为这里存的是变量。
LLVM明确允许全局变量声明为常量,即使最终定义不是如此。这个能力可以被用来更好的优化程序,但需要的语言定义,以保证基于’constantness’优化是有效的,不包括的定义。
作为SSA值,全局变量定义指针值实是在程序的所有基本快范围内。全局变量总是定义一个指针,指向自己的“内容”类型,因为他们描述一个内存区域,并在LLVM所有内存对象都通过指针访问。
全局变量可以打上“unnamed_addr”指示的地址不重要,只有内容重要。这样标记常量可以与其他常量合并,如果它们具有相同的初始值。需要注意的是一个常数地址是重要的可以与“unnamed_addr”常量合并,结果是一个常量且地址为重要的。
全局变量声明存在一个特定目标编号的地址空间。为了支持他们的目标,地址空间可能会影响如何执行优化和/或什么样的目标指令用于访问变量。缺省地址空间是零。地址空间限定必须先于任何其他属性。
LLVM允许为全局变量指定一个明确的部分。如果目标支持它,它会发出指定部分的全局变量。此外,全局变量可以放置在“COMDAT”,如果目标具有必要支持。
缺省情况下,全局初始化优化是通过假设在模块中定义的全局变量不从它们的初始值到全局初始化开始前没有改变。这对即使变量有外部模块潜在的访问,包括它是“external”链接类型或出现在@ llvm.used或dllexported中依然成立。这种假设可以通过标记全局变量为“externally_initialized”取消。
全局变量可以指定精确的对准,它必须是2的幂。如果不存在,对准被设置为零,全局变量的对准同过目标设置不管是否方便。如果指定了明确的对准,全局变量被迫准确对齐。目标和优化不准过度对准全局变量如果全局变量有一个分配的部分。在这种情况下,额外的对准可能是观察到:例如,代码可以假定全局变量紧密堆积在其部分并试图遍历它们作为一个数组,对齐填充会打破这个迭代。最大调整为1<<29。
全局变量还可以有一个DLL存储类。
变量和别名可以有一个线程本地存储模式。
语法:

[@<GlobalVarName> =] [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
                        [unnamed_addr] [AddrSpace] [ExternallyInitialized]
                        <global | constant> <Type> [<InitializerConstant>]
                        [, section "name"] [, comdat [($name)]]
                        [, align <Alignment>]

例如,下面定义的全局变量有初始化,节,并对准一个编号的地址
@G = addrspace(5) constant float 1.0, section "foo", align 4
例子只是声明了一个全局
@G = external global i32
例子定义了一个线程本地类型为thread_local(initialexec)在TSL模
@G = thread_local(initialexec) global i32 0, align 4
函数
LLVM函数定义包括了“define”关键字,可选的链接类型,可选的可见样式,可选的DLL存储类型,可选的调用约定,可选unnamed_addr属性,返回类型,返回类型可选参数属性,函数名,一个(可能是空的)参数列表(每个可选参数的属性),可选的函数属性,可选section,可选对准,可选的Comdat,可选的垃圾收集器的名字,一个可选的前缀,可选的prologue,可选的个性,一个左括号,基本块列表,以及一个右花括号。
LLVM函数声明由“declare”关键字,可选的链接类型,可选的可见样式,可选的DLL存储类型,可选的调用约定,可选unnamed_addr属性,返回类型,返回类型可选参数属性,函数名,参数可能为空的列表,可选对齐,可选的垃圾收集器的名字,一个可选的前缀,以及一个可选的序幕。
函数定义包含基本块的列表,对相应函数形成CFG(控制流图)。每个基本块可任选以一个开始标签(给出的基本块中的入口符号表),包含指令的列表,以及终止指令(例如一个分支或函数返回)结束。如果未提供明确的标记,块指定隐式的编号标签,使用从相同的计数器的下一个值作为无名临时编号。例如,如果一个功能项块不具有显式标签,其将被分配标号“%0”,则第一个无名临时在该块将是“%1”,等等。
在一个函数的第一基本块特别在两个方面:它是函数执行的入口,并且它不允许有前身基本块(即不能有任何分支到一个函数的入口块)。由于该块可前无古人,也不能有任何PHI节点。
LLVM允许为函数指定明确部分。如果目标支持它,它会发出函数指定的部分。此外,该函数可以放在COMDAT。
一个明确的对准可用于一个函数。如果不存在,或者对准被设置为零,则该函数的对准通过目标根据方便设置。如果指定了明确的对准,该函数被强制至少具有多对齐。所有对准必须是2的幂。
如果unnamed_addr属性给出,该地址是已知的并不重要和两个相同的函数可以被合并。
语法:

define [linkage] [visibility] [DLLStorageClass]
       [cconv] [ret attrs]
       <ResultType> @<FunctionName> ([argument list])
       [unnamed_addr] [fn Attrs] [section "name"] [comdat [($name)]]
       [align N] [gc] [prefix Constant] [prologue Constant]
       [personality Constant] { ... }

参数列表是一个逗号分隔的参数序列,其中每个参数是以下形式:
语法:

<type> [parameter Attrs] [name]

未完待续

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Become familiar with the LLVM infrastructure and start using LLVM libraries to design a compiler About This Book Learn to use the LLVM libraries to emit intermediate representation (IR) from high-level language Build your own optimization pass for better code generation Understand AST generation and use it in a meaningful way Who This Book Is For This book is intended for those who already know some of the concepts of compilers and want to quickly get familiar with the LLVM infrastructure and the rich set of libraries that it provides. What You Will Learn Get an introduction to LLVM modular design and LLVM tools Convert frontend code to LLVM IR Implement advanced LLVM IR paradigms Understand the LLVM IR Optimization Pass Manager infrastructure and write an optimization pass Absorb LLVM IR transformations Understand the steps involved in converting LLVM IR to Selection DAG Implement a custom target using the LLVM infrastructure Get a grasp of C's frontend clang, an AST dump, and static analysis In Detail LLVM is currently the point of interest for many firms, and has a very active open source community. It provides us with a compiler infrastructure that can be used to write a compiler for a language. It provides us with a set of reusable libraries that can be used to optimize code, and a target-independent code generator to generate code for different backends. It also provides us with a lot of other utility tools that can be easily integrated into compiler projects. This book details how you can use the LLVM compiler infrastructure libraries effectively, and will enable you to design your own custom compiler with LLVM in a snap. We start with the basics, where you'll get to know all about LLVM. We then cover how you can use LLVM library calls to emit intermediate representation (IR) of simple and complex high-level language paradigms. Moving on, we show you how to implement optimizations at different levels, write an optimization pass, generate code that is independent of a target, and then map the code generated to a backend. The book also walks you through CLANG, IR to IR transformations, advanced IR block transformations, and target machines. By the end of this book, you'll be able to easily utilize the LLVM libraries in your own projects. Style and approach This book deals with topics sequentially, increasing the difficulty level in a step-by-step approach. Each topic is explained with a detailed example, and screenshots are included to help you understand the examples. Table of Contents Chapter 1. Playing with LLVM Chapter 2. Building LLVM IR Chapter 3. Advanced LLVM IR Chapter 4. Basic IR Transformations Chapter 5. Advanced IR Block Transformations Chapter 6. IR to Selection DAG phase Chapter 7. Generating Code for Target Architecture

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值