Wednesday, September 28, 2011
Monday, September 26, 2011
(本文是 http://llvm.org/releases/2.9/docs/LangRef.html 的阅读笔记,前作为《LLVM笔记(2):LLVM的语言(中)》。)
- Instruction Reference
- terminator instruction
- indicates which block should be executed after the current block is finished
- yields ‘void’ value,
- ret (return)
- ret <type> <value>
- ret void
- branch
- br i1 <cond>, label <iftrue>, label <iffalse>
- br label <dest> ; Unconditional branch
- switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
- indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
- invoke
- invoke [cconv] [ret attrs] <ptr to function ty> <function ptr val>(<function args>) [fn attrs] to label <normal label> unwind label <exception label>
- unwind
- unreachable
- binary instruction
- add, fadd, sub, fsub
- mul, fmul, udiv, sdiv, fdiv, urem, srem, frem
- bitwise binary instructions
- shl, lshr, ashr
- and, or, xor
- memory instructions
- Vector Operations
- extractelement
- <result> = extractelement <n x <ty>> <val>, i32 <idx> ; yields <ty>
- insertelement
- <result> = insertelement <n x <ty>> <val>, <ty> <elt>, i32 <idx> ; yields <n x <ty>>
- shufflevector
- <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
- Aggregate Operations
- extractvalue
- <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
- insertvalue
- <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx> ; yields <aggregate type>
- Memory Access and Addressing Operations
- alloca
- <result> = alloca <type>[, <ty> <NumElements>][, align <alignment>] ; yields {type*}:result
- load
- <result> = load <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>]
- <result> = volatile load <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>]
- !<index> = !{ i32 1 }
- store
- store <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>] ; yields {void}
- volatile store <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>] ; yields {void}
- getelementptr
- <result> = getelementptr <pty>* <ptrval>{, <ty> <idx>}*
- <result> = getelementptr inbounds <pty>* <ptrval>{, <ty> <idx>}*
- Conversion Operations
- trunc .. to (truncate value type)
- zext .. to (zero ext)
- sext .. to (sign ext)
- fptrunc .. to (float point truncate)
- fpext .. to
- fptoui .. to (float point to unsigned int)
- fptosi .. to
- uitofp .. to
- sitofp .. to
- ptrtoint .. to (pointer to int)
- inttoptr .. to
- bitcast .. to
- other instructions
- ‘icmp’ Instruction
- <result> = icmp <cond> <ty> <op1>, <op2> ; yields {i1} or {<N x i1>}:result
- Intrinsic Functions
- Variable Argument Handling Intrinsics
- llvm.va_start
- llvm.va_end
- llvm.va_copy
- Accurate Garbage Collection Intrinsics
- llvm.gcroot
- llvm.gcread
- llvm.gcwrite
- Code Generator Intrinsics
- llvm.returnaddress
- declare i8 *@llvm.returnaddress(i32 <level>)
- llvm.frameaddress
- declare i8* @llvm.frameaddress(i32 <level>)
- llvm.stacksave
- declare i8* @llvm.stacksave()
- llvm.stackrestore
- declare void @llvm.stackrestore(i8* %ptr)
- llvm.prefetch
- declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>)
- llvm.pcmarker
- declare void @llvm.pcmarker(i32 <id>)
- llvm.readcyclecounter
- declare i64 @llvm.readcyclecounter()
- Standard C Library Intrinsics
- llvm.memcpy llvm.memmove llvm.memset.*
- llvm.sqrt.* llvm.powi.* llvm.sin.* llvm.cos.* llvm.pow.*
- Bit Manipulation Intrinsics
- llvm.bswap.*
- llvm.ctpop.*
- counts the number of bits set
- llvm.ctlz.*
- count the number of leading zeros
- llvm.cttz.*
- count the number of trailing zeros
- llvm.sadd.with.overflow.*
- llvm.uadd.with.overflow.*
- llvm.ssub.with.overflow.*
- llvm.usub.with.overflow.*
- llvm.smul.with.overflow.*
- llvm.umul.with.overflow.*
- Half Precision Floating Point Intrinsics
- llvm.convert.to.fp16
- llvm.convert.from.fp16
- Debugger Intrinsics
- start with llvm.dbg. prefix
- Exception Handling Intrinsics
- start with llvm.eh. prefix
- Trampoline Intrinsic
- Atomic Operations and Synchronization Intrinsics
- llvm.memory.barrier
- llvm.atomic.cmp.swap.*
- llvm.atomic.swap.*
- llvm.atomic.load.add.* llvm.atomic.load.sub.*
- llvm.atomic.load.and.* llvm.atomic.load.nand.* llvm.atomic.load.or.* llvm.atomic.load.xor.*
- llvm.atomic.load.max.* llvm.atomic.load.min.* llvm.atomic.load.umax.* llvm.atomic.load.umin.*
- Memory Use Markers
- llvm.lifetime.start
- llvm.lifetime.end
- llvm.invariant.start
- llvm.invariant.end
- General Intrinsics
- llvm.var.annotation
- llvm.annotation.*
- llvm.trap
- llvm.stackprotector
- llvm.objectsize
Sunday, September 25, 2011
(本文是 http://llvm.org/releases/2.9/docs/LangRef.html 的阅读笔记,前作为《LLVM笔记(1):LLVM的语言(上)》。)
- Type System
- Type Classifications
- integer: i1, i2, i3, … i8, … i16, … i32, … i64
- floating point: float, double, x86_fp80, fp128, ppc_fp128
- first class: integer, floating point, pointer, vector, structure, array, label, metadata.
- primitive: label, void, integer, floating point, x86mmx, metadata.
- derived: array, function, pointer, structure, packed structure, vector, opaque.
- Array type
- Function Type
- Structure Type
- Packed Structure Type
- Pointer Type
- Vector Type
- Opaque Type: represents unknown type
- Type Up-references
- needed by the asmprinter for printing out cyclic types
- Constants
- Simple Constants
- Boolean(true, false)
- Integer(e.g. 42)
- Floating point(3.14 or 6.02E+23 or
double 0x432ff973cafa8000 (IEEE))
- Null pointer (null)
- Complex Constants
- Structure constants
- { i32 4, float 17.0, i32* @G }
- @G = external global i32
- Array constants
- [ i32 42, i32 11, i32 74 ]
- Vector constants
- [ i32 42, i32 11, i32 74 ]
- Zero initialization
- Metadata node
- metadata !{ i32 0, metadata !”test” }
- Global Variable and Function Addresses
- Undefined Values
- The string ‘undef’ can be used anywhere a constant is expected, and indicates that the user of the value may receive an unspecified bit-pattern.
- Trap Values
- Addresses of Basic Blocks
- blockaddress(@function, %block)
- Constant Expressions
- trunc, zext, sext, fptrunc, fpext, fptoui, fptosi, uitofp, sitofp, ptrtoint, inttoptr, bitcast
- getelementptr, select, icmp, fcmp, extractelement, insertelement, shufflevector, extractvalue, insertvalue
- OPCODE
- Other Values
- Inline Assembler Expressions
- Inline Asm Metadata
- Metadata Nodes and Metadata Strings
- Intrinsic Global Variables
- The ‘llvm.used’ Global Variable
- The @llvm.used global is an array with i8* element type which has appending linkage.
- The ‘llvm.compiler.used’ Global Variable
- The ‘llvm.global_ctors’ Global Variable
- The ‘llvm.global_dtors’ Global Variable
Wednesday, September 21, 2011
(本文是 http://llvm.org/releases/2.9/docs/LangRef.html 的阅读笔记,前作为《LLVM笔记(0):在一切开始之前》。)
- 一句话总结: 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.
- LLVM语言有三种形式:in-memory compiler IR, on-disk bitcode representation, human readable assembly language representation。三种表现形式是等价的。
- LLVM语言的目标是:一方面 light-weight and low-level,另一方面expressive, typed, and extensible。
- Identifiers
- ‘;’开始注释
- High Level Structure
- Module
- llvm linker to combine
- global values: functions and global variables
- linkage types
- private, linker_private, linker_private_weak, linker_private_weak_def_auto
- internal, available_externally, linkonce, weak, common, appending, extern_weak
- linkonce_odr, weak_odr
- externally visible (default)
- Calling Conventions
- ccc: the C calling convention
- fastcc: the fast calling convention
- coldcc: the cold calling convention
- Visibility styles (for global variables and functions):
- default, hidden, protected
- Named types
- e.g. %mytype = type { %mytype*, i32 }
- Global variables
- many aspects can be controlled
- Functions
- definition and declaration
- definition contains a list of basic blocks, Control Flow Graph for the function
- each basic block optionally starts with a label, contains a list of instructions, and ends with a terminator instruction
- first basic block is special: 1. immediately executed on entrance; 2. not allowed to have predecessors
- Aliases
- Named Metadata: a collection of metadata
- Parameter Attributes
- zeroext, signext, inreg, byval, sret, noalias, nocapture, nest
- Garbage Collector Names
- Function Attributes
- Module-Level Inline Assembly
- Data Layout
- target datalayout = “layout specification”
- Pointer Aliasing Rules
- memory access must be through pointers
- a pointer value is based on another pointer value according to the rules
- Volatile Memory Accesses