diff --git a/docs/LangRef.html b/docs/LangRef.html index f3e5d9f2e11..414b452f622 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -156,8 +156,6 @@
  • Memory Access and Addressing Operations
      -
    1. 'malloc' Instruction
    2. -
    3. 'free' Instruction
    4. 'alloca' Instruction
    5. 'load' Instruction
    6. 'store' Instruction
    7. @@ -3833,93 +3831,11 @@ Instruction

      A key design point of an SSA-based representation is how it represents memory. In LLVM, no memory locations are in SSA form, which makes things - very simple. This section describes how to read, write, allocate, and free + very simple. This section describes how to read, write, and allocate memory in LLVM.

      - - - -
      - -
      Syntax:
      -
      -  <result> = malloc <type>[, i32 <NumElements>][, align <alignment>]     ; yields {type*}:result
      -
      - -
      Overview:
      -

      The 'malloc' instruction allocates memory from the system heap and - returns a pointer to it. The object is always allocated in the generic - address space (address space zero).

      - -
      Arguments:
      -

      The 'malloc' instruction allocates - sizeof(<type>)*NumElements bytes of memory from the operating - system and returns a pointer of the appropriate type to the program. If - "NumElements" is specified, it is the number of elements allocated, otherwise - "NumElements" is defaulted to be one. If a constant alignment is specified, - the value result of the allocation is guaranteed to be aligned to at least - that boundary. If not specified, or if zero, the target can choose to align - the allocation on any convenient boundary compatible with the type.

      - -

      'type' must be a sized type.

      - -
      Semantics:
      -

      Memory is allocated using the system "malloc" function, and a - pointer is returned. The result of a zero byte allocation is undefined. The - result is null if there is insufficient memory available.

      - -
      Example:
      -
      -  %array  = malloc [4 x i8]                     ; yields {[%4 x i8]*}:array
      -
      -  %size   = add i32 2, 2                        ; yields {i32}:size = i32 4
      -  %array1 = malloc i8, i32 4                    ; yields {i8*}:array1
      -  %array2 = malloc [12 x i8], i32 %size         ; yields {[12 x i8]*}:array2
      -  %array3 = malloc i32, i32 4, align 1024       ; yields {i32*}:array3
      -  %array4 = malloc i32, align 1024              ; yields {i32*}:array4
      -
      - -

      Note that the code generator does not yet respect the alignment value.

      - -
      - - - - -
      - -
      Syntax:
      -
      -  free <type> <value>                           ; yields {void}
      -
      - -
      Overview:
      -

      The 'free' instruction returns memory back to the unused memory heap - to be reallocated in the future.

      - -
      Arguments:
      -

      'value' shall be a pointer value that points to a value that was - allocated with the 'malloc' instruction.

      - -
      Semantics:
      -

      Access to the memory pointed to by the pointer is no longer defined after - this instruction executes. If the pointer is null, the operation is a - noop.

      - -
      Example:
      -
      -  %array  = malloc [4 x i8]                     ; yields {[4 x i8]*}:array
      -            free   [4 x i8]* %array
      -
      - -
      -
      'alloca' Instruction @@ -6624,7 +6540,8 @@ LLVM.

      Example:
      -%ptr      = malloc i32
      +%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
      +%ptr      = bitcast i8* %mallocP to i32*
                   store i32 4, %ptr
       
       %result1  = load i32* %ptr      ; yields {i32}:result1 = 4
      @@ -6675,7 +6592,8 @@ LLVM.

      Examples:
      -%ptr      = malloc i32
      +%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
      +%ptr      = bitcast i8* %mallocP to i32*
                   store i32 4, %ptr
       
       %val1     = add i32 4, 4
      @@ -6730,7 +6648,8 @@ LLVM.

      Examples:
      -%ptr      = malloc i32
      +%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
      +%ptr      = bitcast i8* %mallocP to i32*
                   store i32 4, %ptr
       
       %val1     = add i32 4, 4
      @@ -6785,8 +6704,9 @@ LLVM.

      Examples:
      -%ptr      = malloc i32
      -        store i32 4, %ptr
      +%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
      +%ptr      = bitcast i8* %mallocP to i32*
      +            store i32 4, %ptr
       %result1  = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 4 )
                                       ; yields {i32}:result1 = 4
       %result2  = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 2 )
      @@ -6836,8 +6756,9 @@ LLVM.

      Examples:
      -%ptr      = malloc i32
      -        store i32 8, %ptr
      +%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
      +%ptr      = bitcast i8* %mallocP to i32*
      +            store i32 8, %ptr
       %result1  = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 4 )
                                       ; yields {i32}:result1 = 8
       %result2  = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 2 )
      @@ -6913,8 +6834,9 @@ LLVM.

      Examples:
      -%ptr      = malloc i32
      -        store i32 0x0F0F, %ptr
      +%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
      +%ptr      = bitcast i8* %mallocP to i32*
      +            store i32 0x0F0F, %ptr
       %result0  = call i32 @llvm.atomic.load.nand.i32.p0i32( i32* %ptr, i32 0xFF )
                                       ; yields {i32}:result0 = 0x0F0F
       %result1  = call i32 @llvm.atomic.load.and.i32.p0i32( i32* %ptr, i32 0xFF )
      @@ -6991,8 +6913,9 @@ LLVM.

      Examples:
      -%ptr      = malloc i32
      -        store i32 7, %ptr
      +%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
      +%ptr      = bitcast i8* %mallocP to i32*
      +            store i32 7, %ptr
       %result0  = call i32 @llvm.atomic.load.min.i32.p0i32( i32* %ptr, i32 -2 )
                                       ; yields {i32}:result0 = 7
       %result1  = call i32 @llvm.atomic.load.max.i32.p0i32( i32* %ptr, i32 8 )