Version: v0.19.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2021 License: BSD-3-Clause Imports: 1 Imported by: 0



Package llvmutil contains utility functions used across multiple compiler packages. For example, they may be used by both the compiler pacakge and transformation packages.

Normally, utility packages are avoided. However, in this case, the utility functions are non-trivial and hard to get right. Copying them to multiple places would be a big risk if only one of them is updated.



This section is empty.


This section is empty.


func CreateEntryBlockAlloca

func CreateEntryBlockAlloca(builder llvm.Builder, t llvm.Type, name string) llvm.Value

CreateEntryBlockAlloca creates a new alloca in the entry block, even though the IR builder is located elsewhere. It assumes that the insert point is at the end of the current block.

func CreateInstructionAlloca

func CreateInstructionAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, inst llvm.Value, name string) llvm.Value

CreateInstructionAlloca creates an alloca in the entry block, and places lifetime control intrinsics around the instruction

func CreateTemporaryAlloca

func CreateTemporaryAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, name string) (alloca, bitcast, size llvm.Value)

CreateTemporaryAlloca creates a new alloca in the entry block and adds lifetime start infromation in the IR signalling that the alloca won't be used before this point.

This is useful for creating temporary allocas for intrinsics. Don't forget to end the lifetime using emitLifetimeEnd after you're done with it.

func EmitLifetimeEnd

func EmitLifetimeEnd(builder llvm.Builder, mod llvm.Module, ptr, size llvm.Value)

EmitLifetimeEnd signals the end of an (alloca) lifetime by calling the llvm.lifetime.end intrinsic. It is commonly used together with createTemporaryAlloca.

func EmitPointerPack

func EmitPointerPack(builder llvm.Builder, mod llvm.Module, needsStackObjects bool, values []llvm.Value) llvm.Value

EmitPointerPack packs the list of values into a single pointer value using bitcasts, or else allocates a value on the heap if it cannot be packed in the pointer value directly. It returns the pointer with the packed data. If the values are all constants, they are be stored in a constant global and deduplicated.

func EmitPointerUnpack

func EmitPointerUnpack(builder llvm.Builder, mod llvm.Module, ptr llvm.Value, valueTypes []llvm.Type) []llvm.Value

EmitPointerUnpack extracts a list of values packed using EmitPointerPack.

func SplitBasicBlock

func SplitBasicBlock(builder llvm.Builder, afterInst llvm.Value, insertAfter llvm.BasicBlock, name string) llvm.BasicBlock

SplitBasicBlock splits a LLVM basic block into two parts. All instructions after afterInst are moved into a new basic block (created right after the current one) with the given name.


This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to