identifier (Identifier)
The identifiers of LLVM exist in two basic types: global and Local. Global identifiers (functions, global variables) begin with the ' @ ' character. The local identifier (register name, type) starts with the '% ' character. In addition, there are three different identifier formats, each with its own purpose:
1. The specified (i.e. defined) variable is represented as a string plus their prefix. For example,%foo, @DivisionByZero,%a.really.long.identifier. The actual regular expression used is ' [%@][a-za-z$._][a-za-z$._0-9] '. Some special characters, such as XX to 16 binary characters is ASCII code, use can be used as "\xx". In this way, any character can be used in a specified value, or even refer to themselves.
2. Unnamed variables (which I understand as temporary variables in IR) are represented as an unsigned number prefix. For example:%12,@2,%44.
3. Constants, which are described later.
LLVM requires that all variables be preceded by a% or @ prefix for two reasons: The compiler does not need to worry about name collisions with LLVM's reserved words, and future LLVM can extend the set of reserved words. In addition, unnamed identifiers allow the compiler to quickly present a temporary variable without the need to consider avoiding symbol table collisions.
LLVM's reserved words are similar to reserved words in other languages. There are keywords for different opcode (' add ', ' bitcast ', ' ret ', etc ... ), there are keywords for the original type name (' void ', ' i32 ', etc .... And so on These reserved words do not conflict with variable names because none of these reserved words starts with a% or @.
Here is an example of a LLVM code that multiplies the integer variable '%x ' by 8:
The simple way:
%result=mul I32%x,8
Another way:
%RESULT=SHL I32%x,i8 3
The difficult way:
Add i32%x,%x; yields{i32}:%0
Add i32% 0,%0 ; yields{i32}:%1
%result=add I32%1,%1
The last method of%x multiplied by 8 illustrates several important lexical features of LLVM:
1. Note start with '; ' until the end of the line.
2. When the calculation result is not specified as a value for a variable, a temporary variable is created.
3. The temporary variable is digitally ordered.
This also prescribes the customs of our post-document. When you want to give an example of an instruction, we'll take a comment after the instruction (to define the type and the name of the resulting variable). Comments are indicated in italics.