From 13fd15ccbdd9a1b16e561eb5c989cf092b2b5382 Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Thu, 15 Jan 2004 00:14:41 +0000 Subject: * Conform to HTML 4.01 strict DTD * Use stylesheets instead of hard-coding formatting git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10868 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ProgrammersManual.html | 2720 +++++++++++++++++++++++-------------------- 1 file changed, 1438 insertions(+), 1282 deletions(-) (limited to 'docs') diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 56751e2..dfd8a20 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -1,20 +1,18 @@ - + LLVM Programmer's Manual + - - - - - - - -
  LLVM Programmer's Manual
+ + +
+ LLVM Programmer's Manual +
+
    -
  1. Introduction
  2. +
  3. Introduction
  4. General Information
    • The C++ Standard Template Library - - - - - - -
      Introduction
      -
        + -This document is meant to highlight some of the important classes and + +
        + +

        This document is meant to highlight some of the important classes and interfaces available in the LLVM source-base. This manual is not intended to explain what LLVM is, how it works, and what LLVM code looks like. It assumes that you know the basics of LLVM and are interested in writing transformations or otherwise analyzing or manipulating the -code. -

        This document should get you oriented so that you can find your +code.

        + +

        This document should get you oriented so that you can find your way in the continuously growing source code that makes up the LLVM infrastructure. Note that this manual is not intended to serve as a replacement for reading the source code, so if you think there should be a method in one of these classes to do something, but it's not listed, check the source. Links to the doxygen sources are provided to make this as easy as possible.

        -

        The first section of this document describes general information -that is useful to know when working in the LLVM infrastructure, and the -second describes the Core LLVM classes. In the future this manual will -be extended with information describing how to use extension libraries, -such as dominator information, CFG traversal routines, and useful -utilities like the InstVisitor -template.

        -

        -
      - - - - - - -
      General Information
      -
        + +

        The first section of this document describes general information that is +useful to know when working in the LLVM infrastructure, and the second describes +the Core LLVM classes. In the future this manual will be extended with +information describing how to use extension libraries, such as dominator +information, CFG traversal routines, and useful utilities like the InstVisitor template.

        + + + -This section contains general information that is useful if you are -working in the LLVM source-base, but that isn't specific to any -particular API. -

        -
      - - - - - - - -
         The C++ Standard Template -Library
      -
        -LLVM makes heavy use of the C++ Standard Template Library (STL), + + + +
        + +

        This section contains general information that is useful if you are working +in the LLVM source-base, but that isn't specific to any particular API.

        + +
        + + + + +
        + +

        LLVM makes heavy use of the C++ Standard Template Library (STL), perhaps much more than you are used to, or have seen before. Because of this, you might want to do a little background reading in the techniques used and capabilities of the library. There are many good pages that discuss the STL, and several books on the subject that you -can get, so it will not be discussed in this document. -

        Here are some useful links:

        -

        -
          -
        1. Dinkumware C++ -Library reference - an excellent reference for the STL and other -parts of the standard C++ library.
        2. -
        3. C++ In a Nutshell - -This is an O'Reilly book in the making. It has a decent Standard Library -Reference that rivals Dinkumware's, and is actually free until the -book is published.
        4. -
        5. C++ Frequently -Asked Questions
        6. -
        7. SGI's STL Programmer's -Guide - Contains a useful Introduction -to the STL.
        8. -
        9. Bjarne -Stroustrup's C++ Page
        10. -
        -

        You are also encouraged to take a look at the LLVM Coding Standards guide which -focuses on how to write maintainable code more than where to put your -curly braces.

        -

        -
      - - - - - - - -
         Other useful references
      - - - - - - - -
      Important and useful LLVM -APIs
      -
        +
+ + + -Here we highlight some LLVM APIs that are generally useful and good to -know about when writing transformations. -

- - - - - - - - -
   The isa<>, -cast<> and dyn_cast<> templates
- - - - - - - - -
   The DEBUG() macro -& -debug option
- -

-
Fine grained debug info with DEBUG_TYPE() and the -debug-only -option

- - - - - - - - -
   The Statistic -template & -stats option
- - - - - - - -
Helpful Hints for Common -Operations
- - - - - - - - -
   Basic Inspection and -Traversal Routines
- -

-
Iterating over the BasicBlocks in a Function

- -

-
Iterating over the Instructions in a BasicBlock

- -

-
Iterating over the Instructions in a Function

- -

-
Turning an iterator into a class -pointer (and vice-versa)

- -

-
Finding call sites: a slightly -more complex example

- -

-
Treating calls and invokes the -same way

- -

-
Iterating over def-use & -use-def chains

- - - - - - - - -
   Making simple -changes
- -

-
Creating and inserting new Instructions

- -

-
Replacing an Instruction -with another Value

- +and ReplaceInstWithInst.

+

Deleting Instructions

+ - - - - - - -
The Core LLVM Class -Hierarchy Reference
- - - - - - - - -
   The Value class
- -

-
Important Public Members of the Value -class

+ +

The name of this instruction is "foo". NOTE +that the name of any value may be missing (an empty string), so names should +ONLY be used for debugging (making the source code easier to read, +debugging printouts), they should not be used to keep track of values or map +between them. For this purpose, use a std::map of pointers to the +Value itself instead.

+ +

One important aspect of LLVM is that there is no distinction between an SSA +variable and the operation that produces it. Because of this, any reference to +the value produced by an instruction (or the value available as an incoming +argument, for example) is represented as a direct pointer to the class that +represents this value. Although this may take some getting used to, it +simplifies the representation and makes it easier to manipulate.

+ + + + +
+ Important Public Members of the Value class +
+ +
+ - - - - - - - -
   The User class
-
+ + +
+ The User class +
+ +
+ +

+#include "llvm/User.h"
doxygen info: User Class
-Superclass: Value -

The User class is the common base class of all LLVM nodes -that may refer to Values. It exposes a -list of "Operands" that are all of the Values -that the User is referring to. The User class itself is a -subclass of Value.

-

The operands of a User point directly to the LLVM Value that it refers to. Because LLVM uses -Static Single Assignment (SSA) form, there can only be one definition -referred to, allowing this direct connection. This connection provides -the use-def information in LLVM.

-

- -

-
Important Public Members of the User -class

+Superclass: Value

+ +

The User class is the common base class of all LLVM nodes that may +refer to Values. It exposes a list of "Operands" +that are all of the Values that the User is +referring to. The User class itself is a subclass of +Value.

+ +

The operands of a User point directly to the LLVM Value that it refers to. Because LLVM uses Static +Single Assignment (SSA) form, there can only be one definition referred to, +allowing this direct connection. This connection provides the use-def +information in LLVM.

+ +
+ + +
+ Important Public Members of the User class +
+ +
+ +

The User class exposes the operand list in two ways: through +an index access interface and through an iterator based interface.

+ - - - - - - - -
   The Instruction -class
- -

-
Important Public Members of the Instruction -class

+ +
+ + +
+ The Instruction class +
+ +
+ +

#include "llvm/Instruction.h"
+doxygen info: Instruction Class
+Superclasses: User, Value

+ +

The Instruction class is the common base class for all LLVM +instructions. It provides only a few methods, but is a very commonly used +class. The primary data tracked by the Instruction class itself is the +opcode (instruction type) and the parent BasicBlock the Instruction is embedded +into. To represent a specific type of instruction, one of many subclasses of +Instruction are used.

+ +

Because the Instruction class subclasses the User class, its operands can be accessed in the same +way as for other Users (with the +getOperand()/getNumOperands() and +op_begin()/op_end() methods).

An important file for +the Instruction class is the llvm/Instruction.def file. This +file contains some meta-data about the various different types of instructions +in LLVM. It describes the enum values that are used as opcodes (for example +Instruction::Add and Instruction::SetLE), as well as the +concrete sub-classes of Instruction that implement the instruction (for +example BinaryOperator and SetCondInst). Unfortunately, the use of macros in +this file confuses doxygen, so these enum values don't show up correctly in the +doxygen output.

+ +
+ + +
+ Important Public Members of the Instruction + class +
+ +
+ - - - - - - - -
   The BasicBlock -class
-
+ + +
+ The BasicBlock class +
+ +
+ +

#include "llvm/BasicBlock.h"
doxygen info: BasicBlock Class
-Superclass: Value -

This class represents a single entry multiple exit section of the -code, commonly known as a basic block by the compiler community. The BasicBlock -class maintains a list of Instructions, -which form the body of the block. Matching the language definition, -the last element of this list of instructions is always a terminator -instruction (a subclass of the TerminatorInst -class).

-

In addition to tracking the list of instructions that make up the -block, the BasicBlock class also keeps track of the Function that it is embedded into.

-

Note that BasicBlocks themselves are Values, -because they are referenced by instructions like branches and can go in -the switch tables. BasicBlocks have type label.

-

- -

-
Important Public Members of the BasicBlock -class

+Superclass: Value

+ +

This class represents a single entry multiple exit section of the code, +commonly known as a basic block by the compiler community. The +BasicBlock class maintains a list of Instructions, which form the body of the block. +Matching the language definition, the last element of this list of instructions +is always a terminator instruction (a subclass of the TerminatorInst class).

+ +

In addition to tracking the list of instructions that make up the block, the +BasicBlock class also keeps track of the Function that it is embedded into.

+ +

Note that BasicBlocks themselves are Values, because they are referenced by instructions +like branches and can go in the switch tables. BasicBlocks have type +label.

+ +
+ + +
+ Important Public Members of the BasicBlock + class +
+ +
+ - - - - - - - -
   The GlobalValue -class
- -

-
Important Public Members of the GlobalValue -class

+ +
+ + +
+ The GlobalValue class +
+ +
+ +

#include "llvm/GlobalValue.h"
+doxygen info: GlobalValue Class
+Superclasses: User, Value

+ +

Global values (GlobalVariables or Functions) are the only LLVM values that are +visible in the bodies of all Functions. +Because they are visible at global scope, they are also subject to linking with +other globals defined in different translation units. To control the linking +process, GlobalValues know their linkage rules. Specifically, +GlobalValues know whether they have internal or external linkage, as +defined by the LinkageTypes enumerator.

+ +

If a GlobalValue has internal linkage (equivalent to being +static in C), it is not visible to code outside the current translation +unit, and does not participate in linking. If it has external linkage, it is +visible to external code, and does participate in linking. In addition to +linkage information, GlobalValues keep track of which Module they are currently part of.

+ +

Because GlobalValues are memory objects, they are always referred to +by their address. As such, the Type of a +global is always a pointer to its contents. It is important to remember this +when using the GetElementPtrInst instruction because this pointer must +be dereferenced first. For example, if you have a GlobalVariable (a +subclass of GlobalValue) that is an array of 24 ints, type [24 x +int], then the GlobalVariable is a pointer to that array. Although +the address of the first element of this array and the value of the +GlobalVariable are the same, they have different types. The +GlobalVariable's type is [24 x int]. The first element's type +is int. Because of this, accessing a global value requires you to +dereference the pointer with GetElementPtrInst first, then its elements +can be accessed. This is explained in the LLVM +Language Reference Manual.

+ +
+ + +
+ Important Public Members of the GlobalValue + class +
+ +
+ - - - - - - - -
   The Function -class
- -

-
Important Public Members of the Function -class

+ +
+ + +
+ The Function class +
+ +
+ +

#include "llvm/Function.h"
doxygen +info: Function Class
Superclasses: +GlobalValue, User, Value

+ +

The Function class represents a single procedure in LLVM. It is +actually one of the more complex classes in the LLVM heirarchy because it must +keep track of a large amount of data. The Function class keeps track +of a list of BasicBlocks, a list of formal Arguments, and a SymbolTable.

+ +

The list of BasicBlocks is the most +commonly used part of Function objects. The list imposes an implicit +ordering of the blocks in the function, which indicate how the code will be +layed out by the backend. Additionally, the first BasicBlock is the implicit entry node for the +Function. It is not legal in LLVM to explicitly branch to this initial +block. There are no implicit exit nodes, and in fact there may be multiple exit +nodes from a single Function. If the BasicBlock list is empty, this indicates that +the Function is actually a function declaration: the actual body of the +function hasn't been linked in yet.

+ +

In addition to a list of BasicBlocks, the +Function class also keeps track of the list of formal Arguments that the function receives. This +container manages the lifetime of the Argument +nodes, just like the BasicBlock list does for +the BasicBlocks.

+ +

The SymbolTable is a very rarely used +LLVM feature that is only used when you have to look up a value by name. Aside +from that, the SymbolTable is used +internally to make sure that there are not conflicts between the names of Instructions, BasicBlocks, or Arguments in the function body.

+ +
+ + +
+ Important Public Members of the Function + class +
+ +
+ - - - - - - - -
   The GlobalVariable -class
-
+ + +
+ The GlobalVariable class +
+ +
+ +

#include "llvm/GlobalVariable.h" +
doxygen info: GlobalVariable -Class
-Superclasses: GlobalValue, User, Value -

Global variables are represented with the (suprise suprise) GlobalVariable -class. Like functions, GlobalVariables are also subclasses of GlobalValue, and as such are always -referenced by their address (global values must live in memory, so their -"name" refers to their address). See GlobalValue for more on -this. Global variables may have an initial value (which must be a Constant), and if they have an -initializer, they may be marked as "constant" themselves (indicating -that their contents never change at runtime).  

-

- -

-
Important Public Members of the GlobalVariable -class

+Class
Superclasses: GlobalValue, User, Value

+ +

Global variables are represented with the (suprise suprise) +GlobalVariable class. Like functions, GlobalVariables are also +subclasses of GlobalValue, and as such are +always referenced by their address (global values must live in memory, so their +"name" refers to their address). See GlobalValue for more on this. Global variables +may have an initial value (which must be a Constant), and if they have an initializer, they +may be marked as "constant" themselves (indicating that their contents never +change at runtime).

+ +
+ + +
+ Important Public Members of the + GlobalVariable class +
+ +
+ - - - - - - - -
   The Module class
- -

-
Important Public Members of the Module -class

+ +
+ + +
+ The Module class +
+ +
+ +

#include "llvm/Module.h"
doxygen info: +Module Class

+ +

The Module class represents the top level structure present in LLVM +programs. An LLVM module is effectively either a translation unit of the +original program or a combination of several translation units merged by the +linker. The Module class keeps track of a list of Functions, a list of GlobalVariables, and a SymbolTable. Additionally, it contains a few +helpful member functions that try to make common operations easy.

+ +
+ + +
+ Important Public Members of the Module class +
+ +
+ -

Constructing a Module -is easy. You can optionally provide a name for it (probably based on the -name of the translation unit).

+ +

Constructing a Module is easy. You can optionally +provide a name for it (probably based on the name of the translation unit).

+ + +
+ + + +
+ + + +
+ + - - - - - - - -
   The Constant -class and subclasses
-
+ + +
+ The Constant class and subclasses +
+ +
+ +

Constant represents a base class for different types of constants. It is subclassed by ConstantBool, ConstantInt, ConstantSInt, ConstantUInt, -ConstantArray etc for representing the various types of Constants. -

- -

-
Important Public Methods

+ConstantArray etc for representing the various types of Constants.

+ +
+ + +
+ Important Public Methods +
+ +
+ - - - - - - - - - -
   The Type class and -Derived Types
- -

-
Important Public Methods

+ +
+ + +
+ The Type class and Derived Types +
+ +
+ +

Type as noted earlier is also a subclass of a Value class. Any primitive +type (like int, short etc) in LLVM is an instance of Type Class. All other +types are instances of subclasses of type like FunctionType, ArrayType +etc. DerivedType is the interface for all such dervied types including +FunctionType, ArrayType, PointerType, StructType. Types can have names. They can +be recursive (StructType). There exists exactly one instance of any type +structure at a time. This allows using pointer equality of Type *s for comparing +types.

+ +
+ + +
+ Important Public Methods +
+ +
+
+ + +
+ The Argument class +
+ +
+ +

This subclass of Value defines the interface for incoming formal arguments to a function. A Function maitanis a list of its formal -arguments. An argument has a pointer to the parent Function. - +arguments. An argument has a pointer to the parent Function.

+ +
+ -
-
By: Dinakar Dhurjati -and Chris Lattner
-
The LLVM -Compiler Infrastructure
- Last -modified: Fri Nov 7 13:24:22 CST 2003
+
+
+ Valid CSS! + Valid HTML 4.01! + + Dinakar Dhurjati and + Chris Lattner
+ The LLVM Compiler Infrastructure
+ Last modified: $Date$ +
+ -- cgit v1.1