Introduction to identifiers of LLVM assembly language instruction manuals

Source: Internet
Author: User
Tags regular expression reserved
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.