ir

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: 0BSD, Unlicense Imports: 14 Imported by: 113

Documentation

Overview

Package ir declares the types used to represent LLVM IR modules.

Example
package main

import (
	"fmt"

	"github.com/llir/llvm/ir"
	"github.com/llir/llvm/ir/constant"
	"github.com/llir/llvm/ir/types"
)

func main() {
	// This example produces LLVM IR code equivalent to the following C code,
	// which implements a pseudo-random number generator.
	//
	//    int abs(int x);
	//
	//    int seed = 0;
	//
	//    // ref: https://en.wikipedia.org/wiki/Linear_congruential_generator
	//    //    a = 0x15A4E35
	//    //    c = 1
	//    int rand(void) {
	//       seed = seed*0x15A4E35 + 1;
	//       return abs(seed);
	//    }

	// Create convenience types and constants.
	i32 := types.I32
	zero := constant.NewInt(i32, 0)
	a := constant.NewInt(i32, 0x15A4E35) // multiplier of the PRNG.
	c := constant.NewInt(i32, 1)         // increment of the PRNG.

	// Create a new LLVM IR module.
	m := ir.NewModule()

	// Create an external function declaration and append it to the module.
	//
	//    int abs(int x);
	abs := m.NewFunc("abs", i32, ir.NewParam("x", i32))

	// Create a global variable definition and append it to the module.
	//
	//    int seed = 0;
	seed := m.NewGlobalDef("seed", zero)

	// Create a function definition and append it to the module.
	//
	//    int rand(void) { ... }
	rand := m.NewFunc("rand", i32)

	// Create an unnamed entry basic block and append it to the `rand` function.
	entry := rand.NewBlock("")

	// Create instructions and append them to the entry basic block.
	tmp1 := entry.NewLoad(types.I32, seed)
	tmp2 := entry.NewMul(tmp1, a)
	tmp3 := entry.NewAdd(tmp2, c)
	entry.NewStore(tmp3, seed)
	tmp4 := entry.NewCall(abs, tmp3)
	entry.NewRet(tmp4)

	// Print the LLVM IR assembly of the module.
	fmt.Println(m)

}
Output:


@seed = global i32 0

declare i32 @abs(i32 %x)

define i32 @rand() {
0:
	%1 = load i32, i32* @seed
	%2 = mul i32 %1, 22695477
	%3 = add i32 %2, 1
	store i32 %3, i32* @seed
	%4 = call i32 @abs(i32 %3)
	ret i32 %4
}
Example (Callgraph)
// This example program analyses an LLVM IR module to produce a callgraph in
// Graphviz DOT format.
package main

import (
	"fmt"
	"strings"

	"github.com/llir/llvm/asm"
	"github.com/llir/llvm/ir"
)

func main() {
	// Parse LLVM IR assembly file.
	m, err := asm.ParseFile("testdata/eval.ll")
	if err != nil {
		panic(err)
	}
	// Produce callgraph of module.
	callgraph := genCallgraph(m)
	// Output callgraph in Graphviz DOT format.
	fmt.Println(callgraph)

}

// genCallgraph returns the callgraph in Graphviz DOT format of the given LLVM
// IR module.
func genCallgraph(m *ir.Module) string {
	buf := &strings.Builder{}
	buf.WriteString("digraph {\n")
	// For each function of the module.
	for _, f := range m.Funcs {
		// Add caller node.
		caller := f.Ident()
		fmt.Fprintf(buf, "\t%q\n", caller)
		// For each basic block of the function.
		for _, block := range f.Blocks {
			// For each non-branching instruction of the basic block.
			for _, inst := range block.Insts {
				// Type switch on instruction to find call instructions.
				switch inst := inst.(type) {
				case *ir.InstCall:
					callee := inst.Callee.Ident()
					// Add edges from caller to callee.
					fmt.Fprintf(buf, "\t%q -> %q\n", caller, callee)
				}
			}
			// Terminator of basic block.
			switch term := block.Term.(type) {
			case *ir.TermRet:
				// do something.
				_ = term
			}
		}
	}
	buf.WriteString("}")
	return buf.String()
}
Output:


digraph {
	"@add"
	"@sub"
	"@f"
	"@f" -> "@printf"
	"@main"
	"@main" -> "@add"
	"@main" -> "@sub"
	"@main" -> "@f"
	"@printf"
}
Example (Evaluator)
// This example program parses testdata/eval.ll, evaluates the return value of
// the @main function and prints the result to standard output. The result
// should be 42.
package main

import (
	"fmt"
	"log"

	"github.com/llir/llvm/asm"
	"github.com/llir/llvm/ir"
	"github.com/llir/llvm/ir/constant"
	"github.com/llir/llvm/ir/types"
	"github.com/llir/llvm/ir/value"
)

func main() {
	// Parse the LLVM IR assembly file `eval.ll`.
	m, err := asm.ParseFile("testdata/eval.ll")
	if err != nil {
		log.Fatalf("%+v", err)
	}
	// Evalute and print the return value of the `@main` function.
	for _, f := range m.Funcs {
		if f.Name() == "main" {
			e := newEvaluator(f)
			fmt.Println("result:", e.eval())
			break
		}
	}

}

// evaluator is a function evaluator.
type evaluator struct {
	// Function being evaluated.
	f *ir.Func
	// Function arguments.
	args []value.Value
}

// newEvaluator returns a new function evaluator, for evaluating the result of
// invoking f with args.
func newEvaluator(f *ir.Func, args ...value.Value) *evaluator {
	return &evaluator{f: f, args: args}
}

// eval evalutes f and returns the corresponding 32-bit integer.
func (e *evaluator) eval() uint32 {
	f := e.f
	if !types.Equal(f.Sig.RetType, types.I32) {
		panic(fmt.Errorf("support for function return type %s not yet implemented", f.Sig.RetType))
	}
	for _, block := range f.Blocks {
		switch term := block.Term.(type) {
		case *ir.TermRet:
			// Note: support for functions with more than one ret terminator not
			// yet implemented.
			if term.X != nil {
				// The result of the first return value of a function is evaluated.
				return e.evalValue(term.X)
			}
		}
	}
	panic(fmt.Errorf("unable to locate ret terminator in function %q", f.Ident()))
}

// evalInst evaluates inst and returns the corresponding 32-bit integer.
func (e *evaluator) evalInst(inst ir.Instruction) uint32 {
	switch inst := inst.(type) {
	// Binary instructions.
	case *ir.InstAdd:
		return e.evalValue(inst.X) + e.evalValue(inst.Y)
	case *ir.InstSub:
		return e.evalValue(inst.X) - e.evalValue(inst.Y)
	case *ir.InstMul:
		return e.evalValue(inst.X) * e.evalValue(inst.Y)
	case *ir.InstUDiv:
		return e.evalValue(inst.X) / e.evalValue(inst.Y)
	case *ir.InstSDiv:
		return e.evalValue(inst.X) / e.evalValue(inst.Y)
	case *ir.InstURem:
		return e.evalValue(inst.X) % e.evalValue(inst.Y)
	case *ir.InstSRem:
		return e.evalValue(inst.X) % e.evalValue(inst.Y)
	// Bitwise instructions.
	case *ir.InstShl:
		return e.evalValue(inst.X) << e.evalValue(inst.Y)
	case *ir.InstLShr:
		return e.evalValue(inst.X) >> e.evalValue(inst.Y)
	case *ir.InstAShr:
		x, y := e.evalValue(inst.X), e.evalValue(inst.Y)
		result := x >> y
		// sign extend.
		if x&0x80000000 != 0 {
			result = signExt(result)
		}
		return result
	case *ir.InstAnd:
		return e.evalValue(inst.X) & e.evalValue(inst.Y)
	case *ir.InstOr:
		return e.evalValue(inst.X) | e.evalValue(inst.Y)
	case *ir.InstXor:
		return e.evalValue(inst.X) ^ e.evalValue(inst.Y)
	// Other instructions.
	case *ir.InstCall:
		callee, ok := inst.Callee.(*ir.Func)
		if !ok {
			panic(fmt.Errorf("support for callee type %T not yet implemented", inst.Callee))
		}
		ee := newEvaluator(callee, inst.Args...)
		return ee.eval()
	default:
		panic(fmt.Errorf("support for instruction type %T not yet implemented", inst))
	}
}

// evalValue evalutes v and returns the corresponding 32-bit integer.
func (e *evaluator) evalValue(v value.Value) uint32 {
	switch v := v.(type) {
	case ir.Instruction:
		return e.evalInst(v)
	case *constant.Int:
		return uint32(v.X.Int64())
	case *ir.Param:
		f := e.f
		for i, param := range f.Params {
			if v.Ident() == param.Ident() {
				return e.evalValue(e.args[i])
			}
		}
		panic(fmt.Errorf("unable to locate paramater %q of function %q", v.Ident(), f.Ident()))
	default:
		panic(fmt.Errorf("support for value type %T not yet implemented", v))
	}
}

// signExt sign extends x.
func signExt(x uint32) uint32 {
	for i := uint32(31); i >= 0; i-- {
		mask := uint32(1 << i)
		if x&mask != 0 {
			break
		}
		x |= mask
	}
	return x
}
Output:


result: 42
Example (Main)
package main

import (
	"fmt"

	"github.com/llir/llvm/ir"
	"github.com/llir/llvm/ir/constant"
	"github.com/llir/llvm/ir/types"
)

func main() {
	// This example produces LLVM IR code equivalent to the following C code:
	//
	//    int main() {
	//       int a = 32;
	//       int b = 16;
	//       return a + b;
	//    }
	//
	// Read: https://blog.felixangell.com/an-introduction-to-llvm-in-go for inspiration.

	// Create convenience types.
	i32 := types.I32

	// Create a new LLVM IR module.
	m := ir.NewModule()
	// int main() { ... }
	main := m.NewFunc("main", i32)

	// Create an unnamed entry basic block and append it to the `main` function.
	entry := main.NewBlock("")
	// Create instructions and append them to the entry basic block.

	// %a = alloca i32
	a := entry.NewAlloca(i32)
	a.SetName("a")

	// %b = alloca i32
	b := entry.NewAlloca(i32)
	b.SetName("b")

	// store i32 32, i32* %a
	entry.NewStore(constant.NewInt(i32, 32), a)

	// store i32 16, i32* %b
	entry.NewStore(constant.NewInt(i32, 16), b)

	// %1 = load i32, i32* %a
	tmpA := entry.NewLoad(types.I32, a)

	// %2 = load i32, i32* %b
	tmpB := entry.NewLoad(types.I32, b)

	// %3 = add nsw i32 %1, %2
	tmpC := entry.NewAdd(tmpA, tmpB)

	// ret i32 %3
	entry.NewRet(tmpC)

	// Print the LLVM IR assembly of the module.
	fmt.Println(m)

}
Output:


define i32 @main() {
0:
	%a = alloca i32
	%b = alloca i32
	store i32 32, i32* %a
	store i32 16, i32* %b
	%1 = load i32, i32* %a
	%2 = load i32, i32* %b
	%3 = add i32 %1, %2
	ret i32 %3
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alias

type Alias struct {
	// Alias name (without '@' prefix).
	GlobalIdent
	// Aliasee.
	Aliasee constant.Constant

	// Pointer type of aliasee.
	Typ *types.PointerType
	// (optional) Linkage; zero value if not present.
	Linkage enum.Linkage
	// (optional) Preemption; zero value if not present.
	Preemption enum.Preemption
	// (optional) Visibility; zero value if not present.
	Visibility enum.Visibility
	// (optional) DLL storage class; zero value if not present.
	DLLStorageClass enum.DLLStorageClass
	// (optional) Thread local storage model; zero value if not present.
	TLSModel enum.TLSModel
	// (optional) Unnamed address; zero value if not present.
	UnnamedAddr enum.UnnamedAddr
	// (optional) Partition name; empty if not present.
	Partition string
}

Alias is an alias of a global identifier or constant expression.

func NewAlias

func NewAlias(name string, aliasee constant.Constant) *Alias

NewAlias returns a new alias based on the given alias name and aliasee.

func (*Alias) IsConstant

func (*Alias) IsConstant()

IsConstant ensures that only constants can be assigned to the constant.Constant interface.

func (*Alias) LLString

func (a *Alias) LLString() string

LLString returns the LLVM syntax representation of the alias definition.

Name=GlobalIdent '=' (ExternLinkage | Linkageopt) Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt IndirectSymbolKind ContentType=Type ',' IndirectSymbol Partitions=(',' Partition)*

func (*Alias) String

func (a *Alias) String() string

String returns the LLVM syntax representation of the alias as a type-value pair.

func (*Alias) Type

func (a *Alias) Type() types.Type

Type returns the type of the alias.

type Align

type Align uint64

Align is a memory alignment attribute.

func (Align) IsFuncAttribute

func (Align) IsFuncAttribute()

IsFuncAttribute ensures that only function attributes can be assigned to the ir.FuncAttribute interface.

func (Align) IsParamAttribute

func (Align) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (Align) IsReturnAttribute

func (Align) IsReturnAttribute()

IsReturnAttribute ensures that only return attributes can be assigned to the ir.ReturnAttribute interface.

func (Align) String

func (align Align) String() string

String returns the string representation of the alignment attribute.

type AlignStack

type AlignStack uint64

AlignStack is a stack alignment attribute.

func (AlignStack) IsFuncAttribute

func (AlignStack) IsFuncAttribute()

IsFuncAttribute ensures that only function attributes can be assigned to the ir.FuncAttribute interface.

func (AlignStack) IsParamAttribute added in v0.3.5

func (AlignStack) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (AlignStack) String

func (align AlignStack) String() string

String returns the string representation of the stack alignment attribute.

type AllocSize

type AllocSize struct {
	// Element size parameter index.
	ElemSizeIndex int
	// Number of elements parameter index; -1 if not present.
	NElemsIndex int
}

AllocSize is an attribute for functions like malloc. If the second parameter is omitted, NElemsIndex will be -1.

func (AllocSize) IsFuncAttribute

func (AllocSize) IsFuncAttribute()

IsFuncAttribute ensures that only function attributes can be assigned to the ir.FuncAttribute interface.

func (AllocSize) String

func (a AllocSize) String() string

String returns the string representation of the allocsize attribute.

type Arg

type Arg struct {
	// Argument value.
	value.Value
	// (optional) Parameter attributes.
	Attrs []ParamAttribute
}

Arg is a function argument with optional parameter attributes.

func NewArg

func NewArg(x value.Value, attrs ...ParamAttribute) *Arg

NewArg returns a new function argument based on the given value and parameter attributes.

func (*Arg) String

func (arg *Arg) String() string

String returns a string representation of the function argument.

type AttrGroupDef

type AttrGroupDef struct {
	// Attribute group ID (without '#' prefix).
	ID int64
	// Function attributes.
	FuncAttrs []FuncAttribute
}

AttrGroupDef is an attribute group definition.

func (*AttrGroupDef) IsFuncAttribute

func (*AttrGroupDef) IsFuncAttribute()

IsFuncAttribute ensures that only function attributes can be assigned to the ir.FuncAttribute interface.

func (*AttrGroupDef) LLString

func (a *AttrGroupDef) LLString() string

LLString returns the LLVM syntax representation of the attribute group definition.

'attributes' ID=AttrGroupID '=' '{' FuncAttrs=FuncAttribute* '}'

func (*AttrGroupDef) String

func (a *AttrGroupDef) String() string

String returns the string representation of the attribute group definition.

type AttrPair

type AttrPair struct {
	Key   string
	Value string
}

AttrPair is an attribute key-value pair (used in function, parameter and return attributes).

func (AttrPair) IsFuncAttribute

func (AttrPair) IsFuncAttribute()

IsFuncAttribute ensures that only function attributes can be assigned to the ir.FuncAttribute interface.

func (AttrPair) IsParamAttribute

func (AttrPair) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (AttrPair) IsReturnAttribute

func (AttrPair) IsReturnAttribute()

IsReturnAttribute ensures that only return attributes can be assigned to the ir.ReturnAttribute interface.

func (AttrPair) String

func (a AttrPair) String() string

String returns the string representation of the attribute key-value pair.

type AttrString

type AttrString string

AttrString is an attribute string (used in function, parameter and return attributes).

func (AttrString) IsFuncAttribute

func (AttrString) IsFuncAttribute()

IsFuncAttribute ensures that only function attributes can be assigned to the ir.FuncAttribute interface.

func (AttrString) IsParamAttribute

func (AttrString) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (AttrString) IsReturnAttribute

func (AttrString) IsReturnAttribute()

IsReturnAttribute ensures that only return attributes can be assigned to the ir.ReturnAttribute interface.

func (AttrString) String

func (a AttrString) String() string

String returns the string representation of the attribute string.

type Block

type Block struct {
	// Name of local variable associated with the basic block.
	LocalIdent
	// Instructions of the basic block.
	Insts []Instruction
	// Terminator of the basic block.
	Term Terminator

	// Parent function; field set by ir.Func.NewBlock.
	Parent *Func `json:"-"`
}

Block is an LLVM IR basic block; a sequence of non-branching instructions terminated by a control flow instruction (e.g. br or ret).

func NewBlock

func NewBlock(name string) *Block

NewBlock returns a new basic block based on the given label name. An empty label name indicates an unnamed basic block.

func (*Block) LLString

func (block *Block) LLString() string

LLString returns the LLVM syntax representation of the basic block definition.

Name=LabelIdentopt Insts=Instruction* Term=Terminator

func (*Block) NewAShr

func (block *Block) NewAShr(x, y value.Value) *InstAShr

NewAShr appends a new ashr instruction to the basic block based on the given operands.

func (*Block) NewAdd

func (block *Block) NewAdd(x, y value.Value) *InstAdd

NewAdd appends a new add instruction to the basic block based on the given operands.

func (*Block) NewAddrSpaceCast

func (block *Block) NewAddrSpaceCast(from value.Value, to types.Type) *InstAddrSpaceCast

NewAddrSpaceCast appends a new addrspacecast instruction to the basic block based on the given source value and target type.

func (*Block) NewAlloca

func (block *Block) NewAlloca(elemType types.Type) *InstAlloca

NewAlloca appends a new alloca instruction to the basic block based on the given element type.

func (*Block) NewAnd

func (block *Block) NewAnd(x, y value.Value) *InstAnd

NewAnd appends a new and instruction to the basic block based on the given operands.

func (*Block) NewAtomicRMW

func (block *Block) NewAtomicRMW(op enum.AtomicOp, dst, x value.Value, ordering enum.AtomicOrdering) *InstAtomicRMW

NewAtomicRMW appends a new atomicrmw instruction to the basic block based on the given atomic operation, destination address, operand and atomic ordering.

func (*Block) NewBitCast

func (block *Block) NewBitCast(from value.Value, to types.Type) *InstBitCast

NewBitCast appends a new bitcast instruction to the basic block based on the given source value and target type.

func (*Block) NewBr

func (block *Block) NewBr(target *Block) *TermBr

NewBr sets the terminator of the basic block to a new unconditional br terminator based on the given target basic block.

func (*Block) NewCall

func (block *Block) NewCall(callee value.Value, args ...value.Value) *InstCall

NewCall appends a new call instruction to the basic block based on the given callee and function arguments.

TODO: specify the set of underlying types of callee.

func (*Block) NewCallBr

func (block *Block) NewCallBr(callee value.Value, args []value.Value, normalRetTarget *Block, otherRetTargets ...*Block) *TermCallBr

NewCallBr sets the terminator of the basic block to a new callbr terminator based on the given callee, function arguments and control flow return points for normal and exceptional execution.

TODO: specify the set of underlying types of callee.

func (*Block) NewCatchPad

func (block *Block) NewCatchPad(catchSwitch *TermCatchSwitch, args ...value.Value) *InstCatchPad

NewCatchPad appends a new catchpad instruction to the basic block based on the given parent catchswitch terminator and exception arguments.

func (*Block) NewCatchRet

func (block *Block) NewCatchRet(catchPad *InstCatchPad, target *Block) *TermCatchRet

NewCatchRet sets the terminator of the basic block to a new catchret terminator based on the given exit catchpad and target basic block.

func (*Block) NewCatchSwitch

func (block *Block) NewCatchSwitch(parentPad ExceptionPad, handlers []*Block, defaultUnwindTarget *Block) *TermCatchSwitch

NewCatchSwitch sets the terminator of the basic block to a new catchswitch terminator based on the given parent exception pad, exception handlers and optional default unwind target. If defaultUnwindTarget is nil, catchswitch unwinds to caller function.

func (*Block) NewCleanupPad

func (block *Block) NewCleanupPad(parentPad ExceptionPad, args ...value.Value) *InstCleanupPad

NewCleanupPad appends a new cleanuppad instruction to the basic block based on the given parent exception pad and exception arguments.

func (*Block) NewCleanupRet

func (block *Block) NewCleanupRet(cleanupPad *InstCleanupPad, unwindTarget *Block) *TermCleanupRet

NewCleanupRet sets the terminator of the basic block to a new cleanupret terminator based on the given exit cleanuppad and optional unwind target. If unwindTarget is nil, cleanupret unwinds to caller function.

func (*Block) NewCmpXchg

func (block *Block) NewCmpXchg(ptr, cmp, new value.Value, successOrdering, failureOrdering enum.AtomicOrdering) *InstCmpXchg

NewCmpXchg appends a new cmpxchg instruction to the basic block based on the given address, value to compare against, new value to store, and atomic orderings for success and failure.

func (*Block) NewCondBr

func (block *Block) NewCondBr(cond value.Value, targetTrue, targetFalse *Block) *TermCondBr

NewCondBr sets the terminator of the basic block to a new conditional br terminator based on the given branching condition and conditional target basic blocks.

func (*Block) NewExtractElement

func (block *Block) NewExtractElement(x, index value.Value) *InstExtractElement

NewExtractElement appends a new extractelement instruction to the basic block based on the given vector and element index.

func (*Block) NewExtractValue

func (block *Block) NewExtractValue(x value.Value, indices ...uint64) *InstExtractValue

NewExtractValue appends a new extractvalue instruction to the basic block based on the given aggregate value and indicies.

func (*Block) NewFAdd

func (block *Block) NewFAdd(x, y value.Value) *InstFAdd

NewFAdd appends a new fadd instruction to the basic block based on the given operands.

func (*Block) NewFCmp

func (block *Block) NewFCmp(pred enum.FPred, x, y value.Value) *InstFCmp

NewFCmp appends a new fcmp instruction to the basic block based on the given floating-point comparison predicate and floating-point scalar or vector operands.

func (*Block) NewFDiv

func (block *Block) NewFDiv(x, y value.Value) *InstFDiv

NewFDiv appends a new fdiv instruction to the basic block based on the given operands.

func (*Block) NewFMul

func (block *Block) NewFMul(x, y value.Value) *InstFMul

NewFMul appends a new fmul instruction to the basic block based on the given operands.

func (*Block) NewFNeg

func (block *Block) NewFNeg(x value.Value) *InstFNeg

NewFNeg appends a new fneg instruction to the basic block based on the given operand.

func (*Block) NewFPExt

func (block *Block) NewFPExt(from value.Value, to types.Type) *InstFPExt

NewFPExt appends a new fpext instruction to the basic block based on the given source value and target type.

func (*Block) NewFPToSI

func (block *Block) NewFPToSI(from value.Value, to types.Type) *InstFPToSI

NewFPToSI appends a new fptosi instruction to the basic block based on the given source value and target type.

func (*Block) NewFPToUI

func (block *Block) NewFPToUI(from value.Value, to types.Type) *InstFPToUI

NewFPToUI appends a new fptoui instruction to the basic block based on the given source value and target type.

func (*Block) NewFPTrunc

func (block *Block) NewFPTrunc(from value.Value, to types.Type) *InstFPTrunc

NewFPTrunc appends a new fptrunc instruction to the basic block based on the given source value and target type.

func (*Block) NewFRem

func (block *Block) NewFRem(x, y value.Value) *InstFRem

NewFRem appends a new frem instruction to the basic block based on the given operands.

func (*Block) NewFSub

func (block *Block) NewFSub(x, y value.Value) *InstFSub

NewFSub appends a new fsub instruction to the basic block based on the given operands.

func (*Block) NewFence

func (block *Block) NewFence(ordering enum.AtomicOrdering) *InstFence

NewFence appends a new fence instruction to the basic block based on the given atomic ordering.

func (*Block) NewGetElementPtr

func (block *Block) NewGetElementPtr(elemType types.Type, src value.Value, indices ...value.Value) *InstGetElementPtr

NewGetElementPtr appends a new getelementptr instruction to the basic block based on the given element type, source address and element indices.

func (*Block) NewICmp

func (block *Block) NewICmp(pred enum.IPred, x, y value.Value) *InstICmp

NewICmp appends a new icmp instruction to the basic block based on the given integer comparison predicate and integer scalar or vector operands.

func (*Block) NewIndirectBr

func (block *Block) NewIndirectBr(addr value.Value, validTargets ...*Block) *TermIndirectBr

NewIndirectBr sets the terminator of the basic block to a new indirectbr terminator based on the given target address (derived from a blockaddress constant of type i8*) and set of valid target basic blocks.

func (*Block) NewInsertElement

func (block *Block) NewInsertElement(x, elem, index value.Value) *InstInsertElement

NewInsertElement appends a new insertelement instruction to the basic block based on the given vector, element and element index.

func (*Block) NewInsertValue

func (block *Block) NewInsertValue(x, elem value.Value, indices ...uint64) *InstInsertValue

NewInsertValue appends a new insertvalue instruction to the basic block based on the given aggregate value, element and indicies.

func (*Block) NewIntToPtr

func (block *Block) NewIntToPtr(from value.Value, to types.Type) *InstIntToPtr

NewIntToPtr appends a new inttoptr instruction to the basic block based on the given source value and target type.

func (*Block) NewInvoke

func (block *Block) NewInvoke(invokee value.Value, args []value.Value, normalRetTarget, exceptionRetTarget *Block) *TermInvoke

NewInvoke sets the terminator of the basic block to a new invoke terminator based on the given invokee, function arguments and control flow return points for normal and exceptional execution.

TODO: specify the set of underlying types of invokee.

func (*Block) NewLShr

func (block *Block) NewLShr(x, y value.Value) *InstLShr

NewLShr appends a new lshr instruction to the basic block based on the given operands.

func (*Block) NewLandingPad

func (block *Block) NewLandingPad(resultType types.Type, clauses ...*Clause) *InstLandingPad

NewLandingPad appends a new landingpad instruction to the basic block based on the given result type and filter/catch clauses.

func (*Block) NewLoad

func (block *Block) NewLoad(elemType types.Type, src value.Value) *InstLoad

NewLoad appends a new load instruction to the basic block based on the given element type and source address.

func (*Block) NewMul

func (block *Block) NewMul(x, y value.Value) *InstMul

NewMul appends a new mul instruction to the basic block based on the given operands.

func (*Block) NewOr

func (block *Block) NewOr(x, y value.Value) *InstOr

NewOr appends a new or instruction to the basic block based on the given operands.

func (*Block) NewPhi

func (block *Block) NewPhi(incs ...*Incoming) *InstPhi

NewPhi appends a new phi instruction to the basic block based on the given incoming values.

func (*Block) NewPtrToInt

func (block *Block) NewPtrToInt(from value.Value, to types.Type) *InstPtrToInt

NewPtrToInt appends a new ptrtoint instruction to the basic block based on the given source value and target type.

func (*Block) NewResume

func (block *Block) NewResume(x value.Value) *TermResume

NewResume sets the terminator of the basic block to a new resume terminator based on the given exception argument to propagate.

func (*Block) NewRet

func (block *Block) NewRet(x value.Value) *TermRet

NewRet sets the terminator of the basic block to a new ret terminator based on the given return value. A nil return value indicates a void return.

func (*Block) NewSDiv

func (block *Block) NewSDiv(x, y value.Value) *InstSDiv

NewSDiv appends a new sdiv instruction to the basic block based on the given operands.

func (*Block) NewSExt

func (block *Block) NewSExt(from value.Value, to types.Type) *InstSExt

NewSExt appends a new sext instruction to the basic block based on the given source value and target type.

func (*Block) NewSIToFP

func (block *Block) NewSIToFP(from value.Value, to types.Type) *InstSIToFP

NewSIToFP appends a new sitofp instruction to the basic block based on the given source value and target type.

func (*Block) NewSRem

func (block *Block) NewSRem(x, y value.Value) *InstSRem

NewSRem appends a new srem instruction to the basic block based on the given operands.

func (*Block) NewSelect

func (block *Block) NewSelect(cond, valueTrue, valueFalse value.Value) *InstSelect

NewSelect appends a new select instruction to the basic block based on the given selection condition and true and false condition values.

func (*Block) NewShl

func (block *Block) NewShl(x, y value.Value) *InstShl

NewShl appends a new shl instruction to the basic block based on the given operands.

func (*Block) NewShuffleVector

func (block *Block) NewShuffleVector(x, y, mask value.Value) *InstShuffleVector

NewShuffleVector appends a new shufflevector instruction to the basic block based on the given vectors and shuffle mask.

func (*Block) NewStore

func (block *Block) NewStore(src, dst value.Value) *InstStore

NewStore appends a new store instruction to the basic block based on the given source value and destination address.

func (*Block) NewSub

func (block *Block) NewSub(x, y value.Value) *InstSub

NewSub appends a new sub instruction to the basic block based on the given operands.

func (*Block) NewSwitch

func (block *Block) NewSwitch(x value.Value, targetDefault *Block, cases ...*Case) *TermSwitch

NewSwitch sets the terminator of the basic block to a new switch terminator based on the given control variable, default target basic block and switch cases.

func (*Block) NewTrunc

func (block *Block) NewTrunc(from value.Value, to types.Type) *InstTrunc

NewTrunc appends a new trunc instruction to the basic block based on the given source value and target type.

func (*Block) NewUDiv

func (block *Block) NewUDiv(x, y value.Value) *InstUDiv

NewUDiv appends a new udiv instruction to the basic block based on the given operands.

func (*Block) NewUIToFP

func (block *Block) NewUIToFP(from value.Value, to types.Type) *InstUIToFP

NewUIToFP appends a new uitofp instruction to the basic block based on the given source value and target type.

func (*Block) NewURem

func (block *Block) NewURem(x, y value.Value) *InstURem

NewURem appends a new urem instruction to the basic block based on the given operands.

func (*Block) NewUnreachable

func (block *Block) NewUnreachable() *TermUnreachable

NewUnreachable sets the terminator of the basic block to a new unreachable terminator.

func (*Block) NewVAArg

func (block *Block) NewVAArg(vaList value.Value, argType types.Type) *InstVAArg

NewVAArg appends a new va_arg instruction to the basic block based on the given variable argument list and argument type.

func (*Block) NewXor

func (block *Block) NewXor(x, y value.Value) *InstXor

NewXor appends a new xor instruction to the basic block based on the given operands.

func (*Block) NewZExt

func (block *Block) NewZExt(from value.Value, to types.Type) *InstZExt

NewZExt appends a new zext instruction to the basic block based on the given source value and target type.

func (*Block) String

func (block *Block) String() string

String returns the LLVM syntax representation of the basic block as a type-value pair.

func (*Block) Type

func (block *Block) Type() types.Type

Type returns the type of the basic block.

type ByRef added in v0.3.5

type ByRef struct {
	// Parameter type.
	Typ types.Type
}

ByRef is a byref parameter attribute.

func (ByRef) IsParamAttribute added in v0.3.5

func (ByRef) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (ByRef) String added in v0.3.5

func (b ByRef) String() string

String returns the string representation of the byref parameter attribute.

type Byval

type Byval struct {
	// (optional) Parameter type.
	Typ types.Type
}

Byval is a byval parameter attribute.

func (Byval) IsParamAttribute

func (Byval) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (Byval) String

func (b Byval) String() string

String returns the string representation of the byval parameter attribute.

type Case

type Case struct {
	// Case comparand.
	X value.Value // constant.Constant (integer constant or integer constant expression)
	// Case target branch.
	Target value.Value // *ir.Block
}

Case is a switch case.

func NewCase

func NewCase(x constant.Constant, target *Block) *Case

NewCase returns a new switch case based on the given case comparand and target basic block.

func (*Case) String

func (c *Case) String() string

String returns the string representation of the switch case.

type Clause

type Clause struct {
	// Clause type (catch or filter).
	Type enum.ClauseType
	// Operand.
	X value.Value
}

Clause is a landingpad catch or filter clause.

func NewClause

func NewClause(clauseType enum.ClauseType, x value.Value) *Clause

NewClause returns a new landingpad clause based on the given clause type and operand.

func (*Clause) String

func (clause *Clause) String() string

String returns the string representation of the landingpad clause.

type ComdatDef

type ComdatDef struct {
	// Comdat name (without '$' prefix).
	Name string
	// Comdat kind.
	Kind enum.SelectionKind
}

ComdatDef is a comdat definition top-level entity.

func (*ComdatDef) LLString

func (c *ComdatDef) LLString() string

LLString returns the LLVM syntax representation of the Comdat definition.

Name=ComdatName '=' 'comdat' Kind=SelectionKind

func (*ComdatDef) String

func (c *ComdatDef) String() string

String returns the string representation of the Comdat definition.

type Dereferenceable

type Dereferenceable struct {
	// Number of bytes known to be dereferenceable.
	N uint64
	// (optional) Either dereferenceable or null if set.
	DerefOrNull bool
}

Dereferenceable is a dereferenceable memory attribute.

func (Dereferenceable) IsParamAttribute

func (Dereferenceable) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (Dereferenceable) IsReturnAttribute

func (Dereferenceable) IsReturnAttribute()

IsReturnAttribute ensures that only return attributes can be assigned to the ir.ReturnAttribute interface.

func (Dereferenceable) String

func (d Dereferenceable) String() string

String returns the string representation of the dereferenceable memory attribute.

type ElementType added in v0.3.5

type ElementType struct {
	// Parameter type.
	Typ types.Type
}

ElementType is a elementtype parameter attribute.

func (ElementType) IsParamAttribute added in v0.3.5

func (ElementType) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (ElementType) String added in v0.3.5

func (b ElementType) String() string

String returns the string representation of the elementtype parameter attribute.

type ExceptionPad

type ExceptionPad interface {
	value.Value
}

ExceptionPad is an exception pad or the none token.

An ExceptionPad has one of the following underlying types.

*ir.InstCatchPad
*ir.InstCleanupPad
*constant.NoneToken

type Func

type Func struct {
	// Function name (without '@' prefix).
	GlobalIdent
	// Function signature.
	Sig *types.FuncType
	// Function parameters.
	Params []*Param
	// Basic blocks.
	Blocks []*Block // nil if declaration.

	// Pointer type to function, including an optional address space. If Typ is
	// nil, the first invocation of Type stores a pointer type with Sig as
	// element.
	Typ *types.PointerType
	// (optional) Linkage.
	Linkage enum.Linkage
	// (optional) Preemption; zero value if not present.
	Preemption enum.Preemption
	// (optional) Visibility; zero value if not present.
	Visibility enum.Visibility
	// (optional) DLL storage class; zero value if not present.
	DLLStorageClass enum.DLLStorageClass
	// (optional) Calling convention; zero value if not present.
	CallingConv enum.CallingConv
	// (optional) Return attributes.
	ReturnAttrs []ReturnAttribute
	// (optional) Unnamed address.
	UnnamedAddr enum.UnnamedAddr
	// (optional) Address space; zero if not present.
	AddrSpace types.AddrSpace
	// (optional) Function attributes.
	FuncAttrs []FuncAttribute
	// (optional) Section name; empty if not present.
	Section string
	// (optional) Partition name; empty if not present.
	Partition string
	// (optional) Comdat; nil if not present.
	Comdat *ComdatDef
	// (optional) Alignment; zero if not present.
	Align Align
	// (optional) Garbage collection; empty if not present.
	GC string
	// (optional) Prefix; nil if not present.
	Prefix constant.Constant
	// (optional) Prologue; nil if not present.
	Prologue constant.Constant
	// (optional) Personality; nil if not present.
	Personality constant.Constant
	// (optional) Use list orders.
	UseListOrders []*UseListOrder
	// (optional) Metadata.
	Metadata

	// Parent module; field set by ir.Module.NewFunc.
	Parent *Module `json:"-"`
	// contains filtered or unexported fields
}

Func is an LLVM IR function. The body of a function definition consists of a set of basic blocks, interconnected by terminator control flow instructions.

func NewFunc

func NewFunc(name string, retType types.Type, params ...*Param) *Func

NewFunc returns a new function based on the given function name, return type and function parameters.

func (*Func) AssignIDs

func (f *Func) AssignIDs() error

AssignIDs assigns IDs to unnamed local variables.

func (*Func) IsConstant

func (*Func) IsConstant()

IsConstant ensures that only constants can be assigned to the constant.Constant interface.

func (*Func) LLString

func (f *Func) LLString() string

LLString returns the LLVM syntax representation of the function definition or declaration.

Function declaration.

'declare' Metadata=MetadataAttachment* Header=FuncHeader

Function definition.

'define' Header=FuncHeader Metadata=MetadataAttachment* Body=FuncBody

func (*Func) NewBlock

func (f *Func) NewBlock(name string) *Block

NewBlock appends a new basic block to the function based on the given label name. An empty label name indicates an unnamed basic block.

The Parent field of the block is set to f.

func (*Func) String

func (f *Func) String() string

String returns the LLVM syntax representation of the function as a type-value pair.

func (*Func) Type

func (f *Func) Type() types.Type

Type returns the type of the function.

type FuncAttribute

type FuncAttribute interface {
	fmt.Stringer
	// IsFuncAttribute ensures that only function attributes can be assigned to
	// the ir.FuncAttribute interface.
	IsFuncAttribute()
}

FuncAttribute is a function attribute.

A FuncAttribute has one of the following underlying types.

ir.AttrString
ir.AttrPair
*ir.AttrGroupDef
ir.Align
ir.AlignStack
ir.AllocSize
enum.FuncAttr

type Global

type Global struct {
	// Global variable name (without '@' prefix).
	GlobalIdent
	// Immutability of global variable (constant or global).
	Immutable bool
	// Content type.
	ContentType types.Type
	// Initial value; or nil if declaration.
	Init constant.Constant

	// Pointer type to global variable, including an optional address space. If
	// Typ is nil, the first invocation of Type stores a pointer type with
	// ContentType as element.
	Typ *types.PointerType
	// (optional) Linkage; zero value if not present.
	Linkage enum.Linkage
	// (optional) Preemption; zero value if not present.
	Preemption enum.Preemption
	// (optional) Visibility; zero value if not present.
	Visibility enum.Visibility
	// (optional) DLL storage class; zero value if not present.
	DLLStorageClass enum.DLLStorageClass
	// (optional) Thread local storage model; zero value if not present.
	TLSModel enum.TLSModel
	// (optional) Unnamed address; zero value if not present.
	UnnamedAddr enum.UnnamedAddr
	// (optional) Address space; zero if not present.
	AddrSpace types.AddrSpace
	// (optional) Externally initialized; false if not present.
	ExternallyInitialized bool
	// (optional) Section name; empty if not present.
	Section string
	// (optional) Partition name; empty if not present.
	Partition string
	// (optional) Comdat; nil if not present.
	Comdat *ComdatDef
	// (optional) Alignment; zero if not present.
	Align Align
	// (optional) Function attributes.
	FuncAttrs []FuncAttribute
	// (optional) Metadata.
	Metadata
}

Global is a global variable declaration or definition.

func NewGlobal

func NewGlobal(name string, contentType types.Type) *Global

NewGlobal returns a new global variable declaration based on the given global variable name and content type.

func NewGlobalDef

func NewGlobalDef(name string, init constant.Constant) *Global

NewGlobalDef returns a new global variable definition based on the given global variable name and initial value.

func (*Global) IsConstant

func (*Global) IsConstant()

IsConstant ensures that only constants can be assigned to the constant.Constant interface.

func (*Global) LLString

func (g *Global) LLString() string

LLString returns the LLVM syntax representation of the global variable definition or declaration.

Global declaration.

Name=GlobalIdent '=' Linkage=ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Partition)? (',' Comdat)? (',' Align)? Metadata=(',' MetadataAttachment)+? FuncAttrs=FuncAttribute+?

Global definition.

Name=GlobalIdent '=' Linkage=Linkageopt Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type Init=Constant (',' Section)? (',' Partition)? (',' Comdat)? (',' Align)? Metadata=(',' MetadataAttachment)+? FuncAttrs=FuncAttribute+?

func (*Global) String

func (g *Global) String() string

String returns the LLVM syntax representation of the global variable as a type-value pair.

func (*Global) Type

func (g *Global) Type() types.Type

Type returns the type of the global variable.

type GlobalIdent

type GlobalIdent struct {
	GlobalName string
	GlobalID   int64
}

GlobalIdent is a global identifier.

func (GlobalIdent) ID

func (i GlobalIdent) ID() int64

ID returns the ID of the global identifier.

func (GlobalIdent) Ident

func (i GlobalIdent) Ident() string

Ident returns the identifier associated with the global identifier.

func (GlobalIdent) IsUnnamed

func (i GlobalIdent) IsUnnamed() bool

IsUnnamed reports whether the global identifier is unnamed.

func (GlobalIdent) Name

func (i GlobalIdent) Name() string

Name returns the name of the global identifier.

If unnamed, the global ID is returned. To distinguish numeric names from unnamed IDs, numeric names are quoted.

func (*GlobalIdent) SetID

func (i *GlobalIdent) SetID(id int64)

SetID sets the ID of the global identifier.

func (*GlobalIdent) SetName

func (i *GlobalIdent) SetName(name string)

SetName sets the name of the global identifier.

type IFunc

type IFunc struct {
	// IFunc name (without '@' prefix).
	GlobalIdent
	// Resolver.
	Resolver constant.Constant

	// Pointer type of resolver.
	Typ *types.PointerType
	// (optional) Linkage; zero value if not present.
	Linkage enum.Linkage
	// (optional) Preemption; zero value if not present.
	Preemption enum.Preemption
	// (optional) Visibility; zero value if not present.
	Visibility enum.Visibility
	// (optional) DLL storage class; zero value if not present.
	DLLStorageClass enum.DLLStorageClass
	// (optional) Thread local storage model; zero value if not present.
	TLSModel enum.TLSModel
	// (optional) Unnamed address; zero value if not present.
	UnnamedAddr enum.UnnamedAddr
	// (optional) Partition name; empty if not present.
	Partition string
}

IFunc is an indirect function (a special kind of function alias).

func NewIFunc

func NewIFunc(name string, resolver constant.Constant) *IFunc

NewIFunc returns a new indirect function based on the given IFunc name and resolver.

func (*IFunc) IsConstant

func (*IFunc) IsConstant()

IsConstant ensures that only constants can be assigned to the constant.Constant interface.

func (*IFunc) LLString

func (i *IFunc) LLString() string

LLString returns the LLVM syntax representation of the IFunc definition.

Name=GlobalIdent '=' (ExternLinkage | Linkageopt) Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt IndirectSymbolKind ContentType=Type ',' IndirectSymbol Partitions=(',' Partition)*

func (*IFunc) String

func (i *IFunc) String() string

String returns the LLVM syntax representation of the IFunc as a type-value pair.

func (*IFunc) Type

func (i *IFunc) Type() types.Type

Type returns the type of the IFunc.

type InAlloca added in v0.3.5

type InAlloca struct {
	Typ types.Type
}

InAlloca is a param attribute.

func (InAlloca) IsParamAttribute added in v0.3.5

func (InAlloca) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (InAlloca) String added in v0.3.5

func (p InAlloca) String() string

String returns a string representation of the InAlloca attribute.

type Incoming

type Incoming struct {
	// Incoming value.
	X value.Value
	// Predecessor basic block of the incoming value.
	Pred value.Value // *ir.Block
}

Incoming is an incoming value of a phi instruction.

func NewIncoming

func NewIncoming(x value.Value, pred *Block) *Incoming

NewIncoming returns a new incoming value based on the given value and predecessor basic block.

func (*Incoming) String

func (inc *Incoming) String() string

String returns the string representation of the incoming value.

type InlineAsm

type InlineAsm struct {
	// Assembly instructions.
	Asm string
	// Constraints.
	Constraint string

	// Type of result produced by the inline assembler expression.
	Typ types.Type
	// (optional) Side effect.
	SideEffect bool
	// (optional) Stack alignment.
	AlignStack bool
	// (optional) Intel dialect.
	IntelDialect bool
}

InlineAsm is an inline assembler expression.

func NewInlineAsm

func NewInlineAsm(typ types.Type, asm, constraint string) *InlineAsm

NewInlineAsm returns a new inline assembler expression based on the given type, assembly instructions and constraints.

func (*InlineAsm) Ident

func (asm *InlineAsm) Ident() string

Ident returns the identifier associated with the inline assembler expression.

func (*InlineAsm) String

func (asm *InlineAsm) String() string

String returns the LLVM syntax representation of the inline assembler expression as a type-value pair.

func (*InlineAsm) Type

func (asm *InlineAsm) Type() types.Type

Type returns the type of the inline assembler expression.

type InstAShr

type InstAShr struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalars or vectors

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Exact.
	Exact bool
	// (optional) Metadata.
	Metadata
}

InstAShr is an LLVM IR ashr instruction.

func NewAShr

func NewAShr(x, y value.Value) *InstAShr

NewAShr returns a new ashr instruction based on the given operands.

func (*InstAShr) LLString

func (inst *InstAShr) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'ashr' Exactopt X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstAShr) Operands added in v0.3.5

func (inst *InstAShr) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstAShr) String

func (inst *InstAShr) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstAShr) Type

func (inst *InstAShr) Type() types.Type

Type returns the type of the instruction.

type InstAdd

type InstAdd struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalar or integer vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Overflow flags.
	OverflowFlags []enum.OverflowFlag
	// (optional) Metadata.
	Metadata
}

InstAdd is an LLVM IR add instruction.

func NewAdd

func NewAdd(x, y value.Value) *InstAdd

NewAdd returns a new add instruction based on the given operands.

func (*InstAdd) LLString

func (inst *InstAdd) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'add' OverflowFlags=OverflowFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstAdd) Operands added in v0.3.5

func (inst *InstAdd) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstAdd) String

func (inst *InstAdd) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstAdd) Type

func (inst *InstAdd) Type() types.Type

Type returns the type of the instruction.

type InstAddrSpaceCast

type InstAddrSpaceCast struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstAddrSpaceCast is an LLVM IR addrspacecast instruction.

func NewAddrSpaceCast

func NewAddrSpaceCast(from value.Value, to types.Type) *InstAddrSpaceCast

NewAddrSpaceCast returns a new addrspacecast instruction based on the given source value and target type.

func (*InstAddrSpaceCast) LLString

func (inst *InstAddrSpaceCast) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'addrspacecast' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstAddrSpaceCast) Operands added in v0.3.5

func (inst *InstAddrSpaceCast) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstAddrSpaceCast) String

func (inst *InstAddrSpaceCast) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstAddrSpaceCast) Type

func (inst *InstAddrSpaceCast) Type() types.Type

Type returns the type of the instruction.

type InstAlloca

type InstAlloca struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Element type.
	ElemType types.Type
	// (optional) Number of elements; nil if not present.
	NElems value.Value

	// Type of result produced by the instruction, including an optional address
	// space.
	Typ *types.PointerType
	// (optional) In-alloca.
	InAlloca bool
	// (optional) Swift error.
	SwiftError bool
	// (optional) Alignment; zero if not present.
	Align Align
	// (optional) Address space; zero if not present.
	AddrSpace types.AddrSpace
	// (optional) Metadata.
	Metadata
}

InstAlloca is an LLVM IR alloca instruction.

func NewAlloca

func NewAlloca(elemType types.Type) *InstAlloca

NewAlloca returns a new alloca instruction based on the given element type.

func (*InstAlloca) LLString

func (inst *InstAlloca) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'alloca' InAllocaopt SwiftErroropt ElemType=Type NElems=(',' TypeValue)? (',' Align)? (',' AddrSpace)? Metadata=(',' MetadataAttachment)+?

func (*InstAlloca) Operands added in v0.3.5

func (inst *InstAlloca) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstAlloca) String

func (inst *InstAlloca) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstAlloca) Type

func (inst *InstAlloca) Type() types.Type

Type returns the type of the instruction.

type InstAnd

type InstAnd struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalars or vectors

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstAnd is an LLVM IR and instruction.

func NewAnd

func NewAnd(x, y value.Value) *InstAnd

NewAnd returns a new and instruction based on the given operands.

func (*InstAnd) LLString

func (inst *InstAnd) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'and' X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstAnd) Operands added in v0.3.5

func (inst *InstAnd) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstAnd) String

func (inst *InstAnd) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstAnd) Type

func (inst *InstAnd) Type() types.Type

Type returns the type of the instruction.

type InstAtomicRMW

type InstAtomicRMW struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Atomic operation.
	Op enum.AtomicOp
	// Destination address.
	Dst value.Value
	// Operand.
	X value.Value
	// Atomic memory ordering constraints.
	Ordering enum.AtomicOrdering

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Volatile.
	Volatile bool
	// (optional) Sync scope; empty if not present.
	SyncScope string
	// (optional) Metadata.
	Metadata
}

InstAtomicRMW is an LLVM IR atomicrmw instruction.

func NewAtomicRMW

func NewAtomicRMW(op enum.AtomicOp, dst, x value.Value, ordering enum.AtomicOrdering) *InstAtomicRMW

NewAtomicRMW returns a new atomicrmw instruction based on the given atomic operation, destination address, operand and atomic ordering.

func (*InstAtomicRMW) LLString

func (inst *InstAtomicRMW) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'atomicrmw' Volatileopt Op=AtomicOp Dst=TypeValue ',' X=TypeValue SyncScopeopt Ordering=AtomicOrdering Metadata=(',' MetadataAttachment)+?

func (*InstAtomicRMW) Operands added in v0.3.5

func (inst *InstAtomicRMW) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstAtomicRMW) String

func (inst *InstAtomicRMW) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstAtomicRMW) Type

func (inst *InstAtomicRMW) Type() types.Type

Type returns the type of the instruction.

type InstBitCast

type InstBitCast struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstBitCast is an LLVM IR bitcast instruction.

func NewBitCast

func NewBitCast(from value.Value, to types.Type) *InstBitCast

NewBitCast returns a new bitcast instruction based on the given source value and target type.

func (*InstBitCast) LLString

func (inst *InstBitCast) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'bitcast' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstBitCast) Operands added in v0.3.5

func (inst *InstBitCast) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstBitCast) String

func (inst *InstBitCast) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstBitCast) Type

func (inst *InstBitCast) Type() types.Type

Type returns the type of the instruction.

type InstCall

type InstCall struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Callee.
	// TODO: specify the set of underlying types of Callee.
	Callee value.Value
	// Function arguments.
	//
	// Arg has one of the following underlying types:
	//    value.Value
	//    *ir.Arg
	//    TODO: add metadata value?
	Args []value.Value

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Tail; zero if not present.
	Tail enum.Tail
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Calling convention; zero if not present.
	CallingConv enum.CallingConv
	// (optional) Return attributes.
	ReturnAttrs []ReturnAttribute
	// (optional) Address space; zero if not present.
	AddrSpace types.AddrSpace
	// (optional) Function attributes.
	FuncAttrs []FuncAttribute
	// (optional) Operand bundles.
	OperandBundles []*OperandBundle
	// (optional) Metadata.
	Metadata
}

InstCall is an LLVM IR call instruction.

func NewCall

func NewCall(callee value.Value, args ...value.Value) *InstCall

NewCall returns a new call instruction based on the given callee and function arguments.

TODO: specify the set of underlying types of callee.

func (*InstCall) LLString

func (inst *InstCall) LLString() string

LLString returns the LLVM syntax representation of the instruction.

Tailopt 'call' FastMathFlags=FastMathFlag* CallingConvopt ReturnAttrs=ReturnAttribute* AddrSpaceopt Typ=Type Callee=Value '(' Args ')' FuncAttrs=FuncAttribute* OperandBundles=('[' (OperandBundle separator ',')+ ']')? Metadata=(',' MetadataAttachment)+?

func (*InstCall) Operands added in v0.3.5

func (inst *InstCall) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstCall) Sig

func (inst *InstCall) Sig() *types.FuncType

Sig returns the function signature of the callee.

func (*InstCall) String

func (inst *InstCall) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstCall) Type

func (inst *InstCall) Type() types.Type

Type returns the type of the instruction.

type InstCatchPad

type InstCatchPad struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Parent catchswitch terminator.
	CatchSwitch value.Value // *ir.TermCatchSwitch
	// Exception arguments.
	//
	// Arg has one of the following underlying types:
	//    value.Value
	//    TODO: add metadata value?
	Args []value.Value

	// (optional) Metadata.
	Metadata
}

InstCatchPad is an LLVM IR catchpad instruction.

func NewCatchPad

func NewCatchPad(catchSwitch *TermCatchSwitch, args ...value.Value) *InstCatchPad

NewCatchPad returns a new catchpad instruction based on the given parent catchswitch terminator and exception arguments.

func (*InstCatchPad) LLString

func (inst *InstCatchPad) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'catchpad' 'within' CatchSwitch=LocalIdent '[' Args=(ExceptionArg separator ',')* ']' Metadata=(',' MetadataAttachment)+?

func (*InstCatchPad) Operands added in v0.3.5

func (inst *InstCatchPad) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstCatchPad) String

func (inst *InstCatchPad) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstCatchPad) Type

func (inst *InstCatchPad) Type() types.Type

Type returns the type of the instruction.

type InstCleanupPad

type InstCleanupPad struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Parent exception pad.
	ParentPad value.Value // ir.ExceptionPad
	// Exception arguments.
	//
	// Arg has one of the following underlying types:
	//    value.Value
	//    TODO: add metadata value?
	Args []value.Value

	// (optional) Metadata.
	Metadata
}

InstCleanupPad is an LLVM IR cleanuppad instruction.

func NewCleanupPad

func NewCleanupPad(parentPad ExceptionPad, args ...value.Value) *InstCleanupPad

NewCleanupPad returns a new cleanuppad instruction based on the given parent exception pad and exception arguments.

func (*InstCleanupPad) LLString

func (inst *InstCleanupPad) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'cleanuppad' 'within' ParentPad=ExceptionPad '[' Args=(ExceptionArg separator ',')* ']' Metadata=(',' MetadataAttachment)+?

func (*InstCleanupPad) Operands added in v0.3.5

func (inst *InstCleanupPad) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstCleanupPad) String

func (inst *InstCleanupPad) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstCleanupPad) Type

func (inst *InstCleanupPad) Type() types.Type

Type returns the type of the instruction.

type InstCmpXchg

type InstCmpXchg struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Address to read from, compare against and store to.
	Ptr value.Value
	// Value to compare against.
	Cmp value.Value
	// New value to store.
	New value.Value
	// Atomic memory ordering constraints on success.
	SuccessOrdering enum.AtomicOrdering
	// Atomic memory ordering constraints on failure.
	FailureOrdering enum.AtomicOrdering

	// Type of result produced by the instruction; the first field of the struct
	// holds the old value, and the second field indicates success.
	Typ *types.StructType
	// (optional) Weak.
	Weak bool
	// (optional) Volatile.
	Volatile bool
	// (optional) Sync scope; empty if not present.
	SyncScope string
	// (optional) Metadata.
	Metadata
}

InstCmpXchg is an LLVM IR cmpxchg instruction.

func NewCmpXchg

func NewCmpXchg(ptr, cmp, new value.Value, successOrdering, failureOrdering enum.AtomicOrdering) *InstCmpXchg

NewCmpXchg returns a new cmpxchg instruction based on the given address, value to compare against, new value to store, and atomic orderings for success and failure.

func (*InstCmpXchg) LLString

func (inst *InstCmpXchg) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'cmpxchg' Weakopt Volatileopt Ptr=TypeValue ',' Cmp=TypeValue ',' New=TypeValue SyncScopeopt SuccessOrdering=AtomicOrdering FailureOrdering=AtomicOrdering Metadata=(',' MetadataAttachment)+?

func (*InstCmpXchg) Operands added in v0.3.5

func (inst *InstCmpXchg) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstCmpXchg) String

func (inst *InstCmpXchg) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstCmpXchg) Type

func (inst *InstCmpXchg) Type() types.Type

Type returns the type of the instruction. The result type is a struct type with two fields, the first field has the type of the old value and the second field has boolean type.

type InstExtractElement

type InstExtractElement struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Vector.
	X value.Value
	// Element index.
	Index value.Value

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstExtractElement is an LLVM IR extractelement instruction.

func NewExtractElement

func NewExtractElement(x, index value.Value) *InstExtractElement

NewExtractElement returns a new extractelement instruction based on the given vector and element index.

func (*InstExtractElement) LLString

func (inst *InstExtractElement) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'extractelement' X=TypeValue ',' Index=TypeValue Metadata=(',' MetadataAttachment)+?

func (*InstExtractElement) Operands added in v0.3.5

func (inst *InstExtractElement) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstExtractElement) String

func (inst *InstExtractElement) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstExtractElement) Type

func (inst *InstExtractElement) Type() types.Type

Type returns the type of the instruction.

type InstExtractValue

type InstExtractValue struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Aggregate value.
	X value.Value // array or struct
	// Element indices.
	Indices []uint64

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstExtractValue is an LLVM IR extractvalue instruction.

func NewExtractValue

func NewExtractValue(x value.Value, indices ...uint64) *InstExtractValue

NewExtractValue returns a new extractvalue instruction based on the given aggregate value and indicies.

func (*InstExtractValue) LLString

func (inst *InstExtractValue) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'extractvalue' X=TypeValue Indices=(',' UintLit)+ Metadata=(',' MetadataAttachment)+?

func (*InstExtractValue) Operands added in v0.3.5

func (inst *InstExtractValue) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstExtractValue) String

func (inst *InstExtractValue) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstExtractValue) Type

func (inst *InstExtractValue) Type() types.Type

Type returns the type of the instruction.

type InstFAdd

type InstFAdd struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // floating-point scalar or floating-point vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstFAdd is an LLVM IR fadd instruction.

func NewFAdd

func NewFAdd(x, y value.Value) *InstFAdd

NewFAdd returns a new fadd instruction based on the given operands.

func (*InstFAdd) LLString

func (inst *InstFAdd) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fadd' FastMathFlags=FastMathFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstFAdd) Operands added in v0.3.5

func (inst *InstFAdd) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFAdd) String

func (inst *InstFAdd) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFAdd) Type

func (inst *InstFAdd) Type() types.Type

Type returns the type of the instruction.

type InstFCmp

type InstFCmp struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Floating-point comparison predicate.
	Pred enum.FPred
	// Floating-point scalar or vector operands.
	X, Y value.Value // floating-point scalar or floating-point vector

	// Type of result produced by the instruction.
	Typ types.Type // boolean or boolean vector
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstFCmp is an LLVM IR fcmp instruction.

func NewFCmp

func NewFCmp(pred enum.FPred, x, y value.Value) *InstFCmp

NewFCmp returns a new fcmp instruction based on the given floating-point comparison predicate and floating-point scalar or vector operands.

func (*InstFCmp) LLString

func (inst *InstFCmp) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fcmp' FastMathFlags=FastMathFlag* Pred=FPred X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstFCmp) Operands added in v0.3.5

func (inst *InstFCmp) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFCmp) String

func (inst *InstFCmp) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFCmp) Type

func (inst *InstFCmp) Type() types.Type

Type returns the type of the instruction. The result type is either boolean type or vector of booleans type.

type InstFDiv

type InstFDiv struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // floating-point scalar or floating-point vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstFDiv is an LLVM IR fdiv instruction.

func NewFDiv

func NewFDiv(x, y value.Value) *InstFDiv

NewFDiv returns a new fdiv instruction based on the given operands.

func (*InstFDiv) LLString

func (inst *InstFDiv) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fdiv' FastMathFlags=FastMathFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstFDiv) Operands added in v0.3.5

func (inst *InstFDiv) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFDiv) String

func (inst *InstFDiv) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFDiv) Type

func (inst *InstFDiv) Type() types.Type

Type returns the type of the instruction.

type InstFMul

type InstFMul struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // floating-point scalar or floating-point vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstFMul is an LLVM IR fmul instruction.

func NewFMul

func NewFMul(x, y value.Value) *InstFMul

NewFMul returns a new fmul instruction based on the given operands.

func (*InstFMul) LLString

func (inst *InstFMul) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fmul' FastMathFlags=FastMathFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstFMul) Operands added in v0.3.5

func (inst *InstFMul) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFMul) String

func (inst *InstFMul) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFMul) Type

func (inst *InstFMul) Type() types.Type

Type returns the type of the instruction.

type InstFNeg

type InstFNeg struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operand.
	X value.Value // floating-point scalar or floating-point vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstFNeg is an LLVM IR fneg instruction.

func NewFNeg

func NewFNeg(x value.Value) *InstFNeg

NewFNeg returns a new fneg instruction based on the given operand.

func (*InstFNeg) LLString

func (inst *InstFNeg) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fneg' FastMathFlags=FastMathFlag* X=TypeValue Metadata=(',' MetadataAttachment)+?

func (*InstFNeg) Operands added in v0.3.5

func (inst *InstFNeg) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFNeg) String

func (inst *InstFNeg) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFNeg) Type

func (inst *InstFNeg) Type() types.Type

Type returns the type of the instruction.

type InstFPExt

type InstFPExt struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstFPExt is an LLVM IR fpext instruction.

func NewFPExt

func NewFPExt(from value.Value, to types.Type) *InstFPExt

NewFPExt returns a new fpext instruction based on the given source value and target type.

func (*InstFPExt) LLString

func (inst *InstFPExt) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fpext' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstFPExt) Operands added in v0.3.5

func (inst *InstFPExt) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFPExt) String

func (inst *InstFPExt) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFPExt) Type

func (inst *InstFPExt) Type() types.Type

Type returns the type of the instruction.

type InstFPToSI

type InstFPToSI struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstFPToSI is an LLVM IR fptosi instruction.

func NewFPToSI

func NewFPToSI(from value.Value, to types.Type) *InstFPToSI

NewFPToSI returns a new fptosi instruction based on the given source value and target type.

func (*InstFPToSI) LLString

func (inst *InstFPToSI) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fptosi' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstFPToSI) Operands added in v0.3.5

func (inst *InstFPToSI) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFPToSI) String

func (inst *InstFPToSI) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFPToSI) Type

func (inst *InstFPToSI) Type() types.Type

Type returns the type of the instruction.

type InstFPToUI

type InstFPToUI struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstFPToUI is an LLVM IR fptoui instruction.

func NewFPToUI

func NewFPToUI(from value.Value, to types.Type) *InstFPToUI

NewFPToUI returns a new fptoui instruction based on the given source value and target type.

func (*InstFPToUI) LLString

func (inst *InstFPToUI) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fptoui' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstFPToUI) Operands added in v0.3.5

func (inst *InstFPToUI) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFPToUI) String

func (inst *InstFPToUI) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFPToUI) Type

func (inst *InstFPToUI) Type() types.Type

Type returns the type of the instruction.

type InstFPTrunc

type InstFPTrunc struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstFPTrunc is an LLVM IR fptrunc instruction.

func NewFPTrunc

func NewFPTrunc(from value.Value, to types.Type) *InstFPTrunc

NewFPTrunc returns a new fptrunc instruction based on the given source value and target type.

func (*InstFPTrunc) LLString

func (inst *InstFPTrunc) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fptrunc' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstFPTrunc) Operands added in v0.3.5

func (inst *InstFPTrunc) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFPTrunc) String

func (inst *InstFPTrunc) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFPTrunc) Type

func (inst *InstFPTrunc) Type() types.Type

Type returns the type of the instruction.

type InstFRem

type InstFRem struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // floating-point scalar or floating-point vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstFRem is an LLVM IR frem instruction.

func NewFRem

func NewFRem(x, y value.Value) *InstFRem

NewFRem returns a new frem instruction based on the given operands.

func (*InstFRem) LLString

func (inst *InstFRem) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'frem' FastMathFlags=FastMathFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstFRem) Operands added in v0.3.5

func (inst *InstFRem) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFRem) String

func (inst *InstFRem) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFRem) Type

func (inst *InstFRem) Type() types.Type

Type returns the type of the instruction.

type InstFSub

type InstFSub struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // floating-point scalar or floating-point vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstFSub is an LLVM IR fsub instruction.

func NewFSub

func NewFSub(x, y value.Value) *InstFSub

NewFSub returns a new fsub instruction based on the given operands.

func (*InstFSub) LLString

func (inst *InstFSub) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fsub' FastMathFlags=FastMathFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstFSub) Operands added in v0.3.5

func (inst *InstFSub) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFSub) String

func (inst *InstFSub) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFSub) Type

func (inst *InstFSub) Type() types.Type

Type returns the type of the instruction.

type InstFence

type InstFence struct {
	// Atomic memory ordering constraints.
	Ordering enum.AtomicOrdering

	// (optional) Sync scope; empty if not present.
	SyncScope string
	// (optional) Metadata.
	Metadata
}

InstFence is an LLVM IR fence instruction.

func NewFence

func NewFence(ordering enum.AtomicOrdering) *InstFence

NewFence returns a new fence instruction based on the given atomic ordering.

func (*InstFence) LLString

func (inst *InstFence) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'fence' SyncScopeopt Ordering=AtomicOrdering Metadata=(',' MetadataAttachment)+?

func (*InstFence) Operands added in v0.3.5

func (inst *InstFence) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

type InstFreeze added in v0.3.1

type InstFreeze struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operand.
	X value.Value

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstFreeze is an LLVM IR freeze instruction.

func NewInstFreeze added in v0.3.1

func NewInstFreeze(x value.Value) *InstFreeze

NewInstFreeze returns a new freeze instruction based on the given operand.

func (*InstFreeze) LLString added in v0.3.1

func (inst *InstFreeze) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'freeze' Type Value

func (*InstFreeze) Operands added in v0.3.5

func (inst *InstFreeze) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstFreeze) String added in v0.3.1

func (inst *InstFreeze) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstFreeze) Type added in v0.3.1

func (inst *InstFreeze) Type() types.Type

Type returns the type of the instruction.

type InstGetElementPtr

type InstGetElementPtr struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Element type.
	ElemType types.Type
	// Source address.
	Src value.Value
	// Element indicies.
	Indices []value.Value

	// Type of result produced by the instruction.
	Typ types.Type // *types.PointerType or *types.VectorType (with elements of pointer type)
	// (optional) In-bounds.
	InBounds bool
	// (optional) Metadata.
	Metadata
}

InstGetElementPtr is an LLVM IR getelementptr instruction.

func NewGetElementPtr

func NewGetElementPtr(elemType types.Type, src value.Value, indices ...value.Value) *InstGetElementPtr

NewGetElementPtr returns a new getelementptr instruction based on the given element type, source address and element indices.

func (*InstGetElementPtr) LLString

func (inst *InstGetElementPtr) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'getelementptr' InBoundsopt ElemType=Type ',' Src=TypeValue Indices=(',' TypeValue)* Metadata=(',' MetadataAttachment)+?

func (*InstGetElementPtr) Operands added in v0.3.5

func (inst *InstGetElementPtr) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstGetElementPtr) String

func (inst *InstGetElementPtr) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstGetElementPtr) Type

func (inst *InstGetElementPtr) Type() types.Type

Type returns the type of the instruction.

type InstICmp

type InstICmp struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Integer comparison predicate.
	Pred enum.IPred
	// Integer scalar or vector operands.
	X, Y value.Value // integer scalar, pointer, integer vector or pointer vector.

	// Type of result produced by the instruction.
	Typ types.Type // boolean or boolean vector
	// (optional) Metadata.
	Metadata
}

InstICmp is an LLVM IR icmp instruction.

func NewICmp

func NewICmp(pred enum.IPred, x, y value.Value) *InstICmp

NewICmp returns a new icmp instruction based on the given integer comparison predicate and integer scalar or vector operands.

func (*InstICmp) LLString

func (inst *InstICmp) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'icmp' Pred=IPred X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstICmp) Operands added in v0.3.5

func (inst *InstICmp) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstICmp) String

func (inst *InstICmp) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstICmp) Type

func (inst *InstICmp) Type() types.Type

Type returns the type of the instruction. The result type is either boolean type or vector of booleans type.

type InstInsertElement

type InstInsertElement struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Vector.
	X value.Value
	// Element to insert.
	Elem value.Value
	// Element index.
	Index value.Value

	// Type of result produced by the instruction.
	Typ *types.VectorType
	// (optional) Metadata.
	Metadata
}

InstInsertElement is an LLVM IR insertelement instruction.

func NewInsertElement

func NewInsertElement(x, elem, index value.Value) *InstInsertElement

NewInsertElement returns a new insertelement instruction based on the given vector, element and element index.

func (*InstInsertElement) LLString

func (inst *InstInsertElement) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'insertelement' X=TypeValue ',' Elem=TypeValue ',' Index=TypeValue Metadata=(',' MetadataAttachment)+?

func (*InstInsertElement) Operands added in v0.3.5

func (inst *InstInsertElement) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstInsertElement) String

func (inst *InstInsertElement) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstInsertElement) Type

func (inst *InstInsertElement) Type() types.Type

Type returns the type of the instruction.

type InstInsertValue

type InstInsertValue struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Aggregate value.
	X value.Value // array or struct
	// Element to insert.
	Elem value.Value
	// Element indices.
	Indices []uint64

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstInsertValue is an LLVM IR insertvalue instruction.

func NewInsertValue

func NewInsertValue(x, elem value.Value, indices ...uint64) *InstInsertValue

NewInsertValue returns a new insertvalue instruction based on the given aggregate value, element and indicies.

func (*InstInsertValue) LLString

func (inst *InstInsertValue) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'insertvalue' X=TypeValue ',' Elem=TypeValue Indices=(',' UintLit)+ Metadata=(',' MetadataAttachment)+?

func (*InstInsertValue) Operands added in v0.3.5

func (inst *InstInsertValue) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstInsertValue) String

func (inst *InstInsertValue) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstInsertValue) Type

func (inst *InstInsertValue) Type() types.Type

Type returns the type of the instruction.

type InstIntToPtr

type InstIntToPtr struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstIntToPtr is an LLVM IR inttoptr instruction.

func NewIntToPtr

func NewIntToPtr(from value.Value, to types.Type) *InstIntToPtr

NewIntToPtr returns a new inttoptr instruction based on the given source value and target type.

func (*InstIntToPtr) LLString

func (inst *InstIntToPtr) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'inttoptr' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstIntToPtr) Operands added in v0.3.5

func (inst *InstIntToPtr) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstIntToPtr) String

func (inst *InstIntToPtr) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstIntToPtr) Type

func (inst *InstIntToPtr) Type() types.Type

Type returns the type of the instruction.

type InstLShr

type InstLShr struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalars or vectors

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Exact.
	Exact bool
	// (optional) Metadata.
	Metadata
}

InstLShr is an LLVM IR lshr instruction.

func NewLShr

func NewLShr(x, y value.Value) *InstLShr

NewLShr returns a new lshr instruction based on the given operands.

func (*InstLShr) LLString

func (inst *InstLShr) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'lshr' Exactopt X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstLShr) Operands added in v0.3.5

func (inst *InstLShr) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstLShr) String

func (inst *InstLShr) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstLShr) Type

func (inst *InstLShr) Type() types.Type

Type returns the type of the instruction.

type InstLandingPad

type InstLandingPad struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Result type.
	ResultType types.Type
	// (optional) Cleanup landing pad.
	Cleanup bool
	// Filter and catch clauses; zero or more if Cleanup is true, otherwise one
	// or more.
	Clauses []*Clause

	// (optional) Metadata.
	Metadata
}

InstLandingPad is an LLVM IR landingpad instruction.

func NewLandingPad

func NewLandingPad(resultType types.Type, clauses ...*Clause) *InstLandingPad

NewLandingPad returns a new landingpad instruction based on the given result type and filter/catch clauses.

func (*InstLandingPad) LLString

func (inst *InstLandingPad) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'landingpad' ResultType=Type Cleanupopt Clauses=Clause* Metadata=(',' MetadataAttachment)+?

func (*InstLandingPad) Operands added in v0.3.5

func (inst *InstLandingPad) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstLandingPad) String

func (inst *InstLandingPad) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstLandingPad) Type

func (inst *InstLandingPad) Type() types.Type

Type returns the type of the instruction.

type InstLoad

type InstLoad struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Element type of src.
	ElemType types.Type
	// Source address.
	Src value.Value

	// (optional) Atomic.
	Atomic bool
	// (optional) Volatile.
	Volatile bool
	// (optional) Sync scope; empty if not present.
	SyncScope string
	// (optional) Atomic memory ordering constraints; zero if not present.
	Ordering enum.AtomicOrdering
	// (optional) Alignment; zero if not present.
	Align Align
	// (optional) Metadata.
	Metadata
}

InstLoad is an LLVM IR load instruction.

func NewLoad

func NewLoad(elemType types.Type, src value.Value) *InstLoad

NewLoad returns a new load instruction based on the given element type and source address.

func (*InstLoad) LLString

func (inst *InstLoad) LLString() string

LLString returns the LLVM syntax representation of the instruction.

Load instruction.

'load' Volatileopt ElemType=Type ',' Src=TypeValue (',' Align)? Metadata=(',' MetadataAttachment)+?

Atomic load instruction.

'load' Atomic Volatileopt ElemType=Type ',' Src=TypeValue SyncScopeopt Ordering=AtomicOrdering (',' Align)? Metadata=(',' MetadataAttachment)+?

func (*InstLoad) Operands added in v0.3.5

func (inst *InstLoad) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstLoad) String

func (inst *InstLoad) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstLoad) Type

func (inst *InstLoad) Type() types.Type

Type returns the type of the instruction.

type InstMul

type InstMul struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalar or integer vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Overflow flags.
	OverflowFlags []enum.OverflowFlag
	// (optional) Metadata.
	Metadata
}

InstMul is an LLVM IR mul instruction.

func NewMul

func NewMul(x, y value.Value) *InstMul

NewMul returns a new mul instruction based on the given operands.

func (*InstMul) LLString

func (inst *InstMul) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'mul' OverflowFlags=OverflowFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstMul) Operands added in v0.3.5

func (inst *InstMul) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstMul) String

func (inst *InstMul) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstMul) Type

func (inst *InstMul) Type() types.Type

Type returns the type of the instruction.

type InstOr

type InstOr struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalars or vectors

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstOr is an LLVM IR or instruction.

func NewOr

func NewOr(x, y value.Value) *InstOr

NewOr returns a new or instruction based on the given operands.

func (*InstOr) LLString

func (inst *InstOr) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'or' X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstOr) Operands added in v0.3.5

func (inst *InstOr) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstOr) String

func (inst *InstOr) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstOr) Type

func (inst *InstOr) Type() types.Type

Type returns the type of the instruction.

type InstPhi

type InstPhi struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Incoming values.
	Incs []*Incoming

	// Type of result produced by the instruction.
	Typ types.Type // type of incoming value
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstPhi is an LLVM IR phi instruction.

func NewPhi

func NewPhi(incs ...*Incoming) *InstPhi

NewPhi returns a new phi instruction based on the given incoming values.

func (*InstPhi) LLString

func (inst *InstPhi) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'phi' Typ=Type Incs=(Inc separator ',')+ Metadata=(',' MetadataAttachment)+?

func (*InstPhi) Operands added in v0.3.5

func (inst *InstPhi) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstPhi) String

func (inst *InstPhi) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstPhi) Type

func (inst *InstPhi) Type() types.Type

Type returns the type of the instruction. The result type is the type of the incoming value.

type InstPtrToInt

type InstPtrToInt struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstPtrToInt is an LLVM IR ptrtoint instruction.

func NewPtrToInt

func NewPtrToInt(from value.Value, to types.Type) *InstPtrToInt

NewPtrToInt returns a new ptrtoint instruction based on the given source value and target type.

func (*InstPtrToInt) LLString

func (inst *InstPtrToInt) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'ptrtoint' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstPtrToInt) Operands added in v0.3.5

func (inst *InstPtrToInt) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstPtrToInt) String

func (inst *InstPtrToInt) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstPtrToInt) Type

func (inst *InstPtrToInt) Type() types.Type

Type returns the type of the instruction.

type InstSDiv

type InstSDiv struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalar or integer vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Exact.
	Exact bool
	// (optional) Metadata.
	Metadata
}

InstSDiv is an LLVM IR sdiv instruction.

func NewSDiv

func NewSDiv(x, y value.Value) *InstSDiv

NewSDiv returns a new sdiv instruction based on the given operands.

func (*InstSDiv) LLString

func (inst *InstSDiv) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'sdiv' Exactopt X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstSDiv) Operands added in v0.3.5

func (inst *InstSDiv) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstSDiv) String

func (inst *InstSDiv) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstSDiv) Type

func (inst *InstSDiv) Type() types.Type

Type returns the type of the instruction.

type InstSExt

type InstSExt struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstSExt is an LLVM IR sext instruction.

func NewSExt

func NewSExt(from value.Value, to types.Type) *InstSExt

NewSExt returns a new sext instruction based on the given source value and target type.

func (*InstSExt) LLString

func (inst *InstSExt) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'sext' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstSExt) Operands added in v0.3.5

func (inst *InstSExt) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstSExt) String

func (inst *InstSExt) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstSExt) Type

func (inst *InstSExt) Type() types.Type

Type returns the type of the instruction.

type InstSIToFP

type InstSIToFP struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstSIToFP is an LLVM IR sitofp instruction.

func NewSIToFP

func NewSIToFP(from value.Value, to types.Type) *InstSIToFP

NewSIToFP returns a new sitofp instruction based on the given source value and target type.

func (*InstSIToFP) LLString

func (inst *InstSIToFP) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'sitofp' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstSIToFP) Operands added in v0.3.5

func (inst *InstSIToFP) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstSIToFP) String

func (inst *InstSIToFP) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstSIToFP) Type

func (inst *InstSIToFP) Type() types.Type

Type returns the type of the instruction.

type InstSRem

type InstSRem struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalar or integer vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstSRem is an LLVM IR srem instruction.

func NewSRem

func NewSRem(x, y value.Value) *InstSRem

NewSRem returns a new srem instruction based on the given operands.

func (*InstSRem) LLString

func (inst *InstSRem) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'srem' X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstSRem) Operands added in v0.3.5

func (inst *InstSRem) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstSRem) String

func (inst *InstSRem) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstSRem) Type

func (inst *InstSRem) Type() types.Type

Type returns the type of the instruction.

type InstSelect

type InstSelect struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Selection condition.
	Cond value.Value // boolean or boolean vector
	// True condition value.
	ValueTrue value.Value
	// False condition value.
	ValueFalse value.Value

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Fast math flags.
	FastMathFlags []enum.FastMathFlag
	// (optional) Metadata.
	Metadata
}

InstSelect is an LLVM IR select instruction.

func NewSelect

func NewSelect(cond, valueTrue, valueFalse value.Value) *InstSelect

NewSelect returns a new select instruction based on the given selection condition and true and false condition values.

func (*InstSelect) LLString

func (inst *InstSelect) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'select' FastMathFlags=FastMathFlag* Cond=TypeValue ',' ValueTrue=TypeValue ',' ValueFalse=TypeValue Metadata=(',' MetadataAttachment)+?

func (*InstSelect) Operands added in v0.3.5

func (inst *InstSelect) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstSelect) String

func (inst *InstSelect) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstSelect) Type

func (inst *InstSelect) Type() types.Type

Type returns the type of the instruction.

type InstShl

type InstShl struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalar or integer vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Overflow flags.
	OverflowFlags []enum.OverflowFlag
	// (optional) Metadata.
	Metadata
}

InstShl is an LLVM IR shl instruction.

func NewShl

func NewShl(x, y value.Value) *InstShl

NewShl returns a new shl instruction based on the given operands.

func (*InstShl) LLString

func (inst *InstShl) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'shl' OverflowFlags=OverflowFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstShl) Operands added in v0.3.5

func (inst *InstShl) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstShl) String

func (inst *InstShl) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstShl) Type

func (inst *InstShl) Type() types.Type

Type returns the type of the instruction.

type InstShuffleVector

type InstShuffleVector struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Vectors.
	X, Y value.Value
	// Shuffle mask.
	Mask value.Value

	// Type of result produced by the instruction.
	Typ *types.VectorType
	// (optional) Metadata.
	Metadata
}

InstShuffleVector is an LLVM IR shufflevector instruction.

func NewShuffleVector

func NewShuffleVector(x, y, mask value.Value) *InstShuffleVector

NewShuffleVector returns a new shufflevector instruction based on the given vectors and shuffle mask.

func (*InstShuffleVector) LLString

func (inst *InstShuffleVector) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'shufflevector' X=TypeValue ',' Y=TypeValue ',' Mask=TypeValue Metadata=(',' MetadataAttachment)+?

func (*InstShuffleVector) Operands added in v0.3.5

func (inst *InstShuffleVector) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstShuffleVector) String

func (inst *InstShuffleVector) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstShuffleVector) Type

func (inst *InstShuffleVector) Type() types.Type

Type returns the type of the instruction.

type InstStore

type InstStore struct {
	// Source value.
	Src value.Value
	// Destination address.
	Dst value.Value

	// (optional) Atomic.
	Atomic bool
	// (optional) Volatile.
	Volatile bool
	// (optional) Sync scope; empty if not present.
	SyncScope string
	// (optional) Atomic memory ordering constraints; zero if not present.
	Ordering enum.AtomicOrdering
	// (optional) Alignment; zero if not present.
	Align Align
	// (optional) Metadata.
	Metadata
}

InstStore is an LLVM IR store instruction.

func NewStore

func NewStore(src, dst value.Value) *InstStore

NewStore returns a new store instruction based on the given source value and destination address.

func (*InstStore) LLString

func (inst *InstStore) LLString() string

LLString returns the LLVM syntax representation of the instruction.

Store instruction.

'store' Volatileopt Src=TypeValue ',' Dst=TypeValue (',' Align)? Metadata=(',' MetadataAttachment)+?

Atomic store instruction.

'store' Atomic Volatileopt Src=TypeValue ',' Dst=TypeValue SyncScopeopt Ordering=AtomicOrdering (',' Align)? Metadata=(',' MetadataAttachment)+?

func (*InstStore) Operands added in v0.3.5

func (inst *InstStore) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

type InstSub

type InstSub struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalar or integer vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Overflow flags.
	OverflowFlags []enum.OverflowFlag
	// (optional) Metadata.
	Metadata
}

InstSub is an LLVM IR sub instruction.

func NewSub

func NewSub(x, y value.Value) *InstSub

NewSub returns a new sub instruction based on the given operands.

func (*InstSub) LLString

func (inst *InstSub) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'sub' OverflowFlags=OverflowFlag* X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstSub) Operands added in v0.3.5

func (inst *InstSub) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstSub) String

func (inst *InstSub) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstSub) Type

func (inst *InstSub) Type() types.Type

Type returns the type of the instruction.

type InstTrunc

type InstTrunc struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstTrunc is an LLVM IR trunc instruction.

func NewTrunc

func NewTrunc(from value.Value, to types.Type) *InstTrunc

NewTrunc returns a new trunc instruction based on the given source value and target type.

func (*InstTrunc) LLString

func (inst *InstTrunc) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'trunc' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstTrunc) Operands added in v0.3.5

func (inst *InstTrunc) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstTrunc) String

func (inst *InstTrunc) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstTrunc) Type

func (inst *InstTrunc) Type() types.Type

Type returns the type of the instruction.

type InstUDiv

type InstUDiv struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalar or integer vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Exact.
	Exact bool
	// (optional) Metadata.
	Metadata
}

InstUDiv is an LLVM IR udiv instruction.

func NewUDiv

func NewUDiv(x, y value.Value) *InstUDiv

NewUDiv returns a new udiv instruction based on the given operands.

func (*InstUDiv) LLString

func (inst *InstUDiv) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'udiv' Exactopt X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstUDiv) Operands added in v0.3.5

func (inst *InstUDiv) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstUDiv) String

func (inst *InstUDiv) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstUDiv) Type

func (inst *InstUDiv) Type() types.Type

Type returns the type of the instruction.

type InstUIToFP

type InstUIToFP struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstUIToFP is an LLVM IR uitofp instruction.

func NewUIToFP

func NewUIToFP(from value.Value, to types.Type) *InstUIToFP

NewUIToFP returns a new uitofp instruction based on the given source value and target type.

func (*InstUIToFP) LLString

func (inst *InstUIToFP) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'uitofp' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstUIToFP) Operands added in v0.3.5

func (inst *InstUIToFP) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstUIToFP) String

func (inst *InstUIToFP) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstUIToFP) Type

func (inst *InstUIToFP) Type() types.Type

Type returns the type of the instruction.

type InstURem

type InstURem struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalar or integer vector

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstURem is an LLVM IR urem instruction.

func NewURem

func NewURem(x, y value.Value) *InstURem

NewURem returns a new urem instruction based on the given operands.

func (*InstURem) LLString

func (inst *InstURem) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'urem' X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstURem) Operands added in v0.3.5

func (inst *InstURem) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstURem) String

func (inst *InstURem) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstURem) Type

func (inst *InstURem) Type() types.Type

Type returns the type of the instruction.

type InstVAArg

type InstVAArg struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Variable argument list.
	ArgList value.Value
	// Argument type.
	ArgType types.Type

	// (optional) Metadata.
	Metadata
}

InstVAArg is an LLVM IR va_arg instruction.

func NewVAArg

func NewVAArg(argList value.Value, argType types.Type) *InstVAArg

NewVAArg returns a new va_arg instruction based on the given variable argument list and argument type.

func (*InstVAArg) LLString

func (inst *InstVAArg) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'va_arg' ArgList=TypeValue ',' ArgType=Type Metadata=(',' MetadataAttachment)+?

func (*InstVAArg) Operands added in v0.3.5

func (inst *InstVAArg) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstVAArg) String

func (inst *InstVAArg) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstVAArg) Type

func (inst *InstVAArg) Type() types.Type

Type returns the type of the instruction.

type InstXor

type InstXor struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Operands.
	X, Y value.Value // integer scalars or vectors

	// Type of result produced by the instruction.
	Typ types.Type
	// (optional) Metadata.
	Metadata
}

InstXor is an LLVM IR xor instruction.

func NewXor

func NewXor(x, y value.Value) *InstXor

NewXor returns a new xor instruction based on the given operands.

func (*InstXor) LLString

func (inst *InstXor) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'xor' X=TypeValue ',' Y=Value Metadata=(',' MetadataAttachment)+?

func (*InstXor) Operands added in v0.3.5

func (inst *InstXor) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstXor) String

func (inst *InstXor) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstXor) Type

func (inst *InstXor) Type() types.Type

Type returns the type of the instruction.

type InstZExt

type InstZExt struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Value before conversion.
	From value.Value
	// Type after conversion.
	To types.Type

	// (optional) Metadata.
	Metadata
}

InstZExt is an LLVM IR zext instruction.

func NewZExt

func NewZExt(from value.Value, to types.Type) *InstZExt

NewZExt returns a new zext instruction based on the given source value and target type.

func (*InstZExt) LLString

func (inst *InstZExt) LLString() string

LLString returns the LLVM syntax representation of the instruction.

'zext' From=TypeValue 'to' To=Type Metadata=(',' MetadataAttachment)+?

func (*InstZExt) Operands added in v0.3.5

func (inst *InstZExt) Operands() []*value.Value

Operands returns a mutable list of operands of the given instruction.

func (*InstZExt) String

func (inst *InstZExt) String() string

String returns the LLVM syntax representation of the instruction as a type-value pair.

func (*InstZExt) Type

func (inst *InstZExt) Type() types.Type

Type returns the type of the instruction.

type Instruction

type Instruction interface {
	LLStringer

	// Instruction implements the value.User interface.
	value.User
	// contains filtered or unexported methods
}

Instruction is an LLVM IR instruction. All instructions (except store and fence) implement the value.Named interface and may thus be used directly as values.

An Instruction has one of the following underlying types.

Unary instructions

https://llvm.org/docs/LangRef.html#unary-operations

*ir.InstFNeg   // https://pkg.go.dev/github.com/llir/llvm/ir#InstFNeg

Binary instructions

https://llvm.org/docs/LangRef.html#binary-operations

*ir.InstAdd    // https://pkg.go.dev/github.com/llir/llvm/ir#InstAdd
*ir.InstFAdd   // https://pkg.go.dev/github.com/llir/llvm/ir#InstFAdd
*ir.InstSub    // https://pkg.go.dev/github.com/llir/llvm/ir#InstSub
*ir.InstFSub   // https://pkg.go.dev/github.com/llir/llvm/ir#InstFSub
*ir.InstMul    // https://pkg.go.dev/github.com/llir/llvm/ir#InstMul
*ir.InstFMul   // https://pkg.go.dev/github.com/llir/llvm/ir#InstFMul
*ir.InstUDiv   // https://pkg.go.dev/github.com/llir/llvm/ir#InstUDiv
*ir.InstSDiv   // https://pkg.go.dev/github.com/llir/llvm/ir#InstSDiv
*ir.InstFDiv   // https://pkg.go.dev/github.com/llir/llvm/ir#InstFDiv
*ir.InstURem   // https://pkg.go.dev/github.com/llir/llvm/ir#InstURem
*ir.InstSRem   // https://pkg.go.dev/github.com/llir/llvm/ir#InstSRem
*ir.InstFRem   // https://pkg.go.dev/github.com/llir/llvm/ir#InstFRem

Bitwise instructions

https://llvm.org/docs/LangRef.html#bitwise-binary-operations

*ir.InstShl    // https://pkg.go.dev/github.com/llir/llvm/ir#InstShl
*ir.InstLShr   // https://pkg.go.dev/github.com/llir/llvm/ir#InstLShr
*ir.InstAShr   // https://pkg.go.dev/github.com/llir/llvm/ir#InstAShr
*ir.InstAnd    // https://pkg.go.dev/github.com/llir/llvm/ir#InstAnd
*ir.InstOr     // https://pkg.go.dev/github.com/llir/llvm/ir#InstOr
*ir.InstXor    // https://pkg.go.dev/github.com/llir/llvm/ir#InstXor

Vector instructions

https://llvm.org/docs/LangRef.html#vector-operations

*ir.InstExtractElement   // https://pkg.go.dev/github.com/llir/llvm/ir#InstExtractElement
*ir.InstInsertElement    // https://pkg.go.dev/github.com/llir/llvm/ir#InstInsertElement
*ir.InstShuffleVector    // https://pkg.go.dev/github.com/llir/llvm/ir#InstShuffleVector

Aggregate instructions

https://llvm.org/docs/LangRef.html#aggregate-operations

*ir.InstExtractValue   // https://pkg.go.dev/github.com/llir/llvm/ir#InstExtractValue
*ir.InstInsertValue    // https://pkg.go.dev/github.com/llir/llvm/ir#InstInsertValue

Memory instructions

https://llvm.org/docs/LangRef.html#memory-access-and-addressing-operations

*ir.InstAlloca          // https://pkg.go.dev/github.com/llir/llvm/ir#InstAlloca
*ir.InstLoad            // https://pkg.go.dev/github.com/llir/llvm/ir#InstLoad
*ir.InstStore           // https://pkg.go.dev/github.com/llir/llvm/ir#InstStore
*ir.InstFence           // https://pkg.go.dev/github.com/llir/llvm/ir#InstFence
*ir.InstCmpXchg         // https://pkg.go.dev/github.com/llir/llvm/ir#InstCmpXchg
*ir.InstAtomicRMW       // https://pkg.go.dev/github.com/llir/llvm/ir#InstAtomicRMW
*ir.InstGetElementPtr   // https://pkg.go.dev/github.com/llir/llvm/ir#InstGetElementPtr

Conversion instructions

https://llvm.org/docs/LangRef.html#conversion-operations

*ir.InstTrunc           // https://pkg.go.dev/github.com/llir/llvm/ir#InstTrunc
*ir.InstZExt            // https://pkg.go.dev/github.com/llir/llvm/ir#InstZExt
*ir.InstSExt            // https://pkg.go.dev/github.com/llir/llvm/ir#InstSExt
*ir.InstFPTrunc         // https://pkg.go.dev/github.com/llir/llvm/ir#InstFPTrunc
*ir.InstFPExt           // https://pkg.go.dev/github.com/llir/llvm/ir#InstFPExt
*ir.InstFPToUI          // https://pkg.go.dev/github.com/llir/llvm/ir#InstFPToUI
*ir.InstFPToSI          // https://pkg.go.dev/github.com/llir/llvm/ir#InstFPToSI
*ir.InstUIToFP          // https://pkg.go.dev/github.com/llir/llvm/ir#InstUIToFP
*ir.InstSIToFP          // https://pkg.go.dev/github.com/llir/llvm/ir#InstSIToFP
*ir.InstPtrToInt        // https://pkg.go.dev/github.com/llir/llvm/ir#InstPtrToInt
*ir.InstIntToPtr        // https://pkg.go.dev/github.com/llir/llvm/ir#InstIntToPtr
*ir.InstBitCast         // https://pkg.go.dev/github.com/llir/llvm/ir#InstBitCast
*ir.InstAddrSpaceCast   // https://pkg.go.dev/github.com/llir/llvm/ir#InstAddrSpaceCast

Other instructions

https://llvm.org/docs/LangRef.html#other-operations

*ir.InstICmp         // https://pkg.go.dev/github.com/llir/llvm/ir#InstICmp
*ir.InstFCmp         // https://pkg.go.dev/github.com/llir/llvm/ir#InstFCmp
*ir.InstPhi          // https://pkg.go.dev/github.com/llir/llvm/ir#InstPhi
*ir.InstSelect       // https://pkg.go.dev/github.com/llir/llvm/ir#InstSelect
*ir.InstFreeze       // https://pkg.go.dev/github.com/llir/llvm/ir#InstFreeze
*ir.InstCall         // https://pkg.go.dev/github.com/llir/llvm/ir#InstCall
*ir.InstVAArg        // https://pkg.go.dev/github.com/llir/llvm/ir#InstVAArg
*ir.InstLandingPad   // https://pkg.go.dev/github.com/llir/llvm/ir#InstLandingPad
*ir.InstCatchPad     // https://pkg.go.dev/github.com/llir/llvm/ir#InstCatchPad
*ir.InstCleanupPad   // https://pkg.go.dev/github.com/llir/llvm/ir#InstCleanupPad

type LLStringer

type LLStringer interface {
	// LLString returns the LLVM syntax representation of the value.
	LLString() string
}

LLStringer is implemented by any value that has a LLString method, which defines the LLVM syntax for that value.

type LocalIdent

type LocalIdent struct {
	LocalName string
	LocalID   int64
}

LocalIdent is a local identifier.

func NewLocalIdent

func NewLocalIdent(ident string) LocalIdent

NewLocalIdent returns a new local identifier based on the given string. An unnamed local ID is used if ident is an integer, and a local name otherwise.

func (LocalIdent) ID

func (i LocalIdent) ID() int64

ID returns the ID of the local identifier.

func (LocalIdent) Ident

func (i LocalIdent) Ident() string

Ident returns the identifier associated with the local identifier.

func (LocalIdent) IsUnnamed

func (i LocalIdent) IsUnnamed() bool

IsUnnamed reports whether the local identifier is unnamed.

func (LocalIdent) Name

func (i LocalIdent) Name() string

Name returns the name of the local identifier.

If unnamed, the local ID is returned. To distinguish numeric names from unnamed IDs, numeric names are quoted.

func (*LocalIdent) SetID

func (i *LocalIdent) SetID(id int64)

SetID sets the ID of the local identifier.

func (*LocalIdent) SetName

func (i *LocalIdent) SetName(name string)

SetName sets the name of the local identifier.

type Metadata

type Metadata []*metadata.Attachment

Metadata is a list of metadata attachments.

func (Metadata) MDAttachments

func (mds Metadata) MDAttachments() []*metadata.Attachment

MDAttachments returns the metadata attachments of the value.

type Module

type Module struct {
	// Type definitions.
	TypeDefs []types.Type
	// Global variable declarations and definitions.
	Globals []*Global
	// Function declarations and definitions.
	Funcs []*Func

	// (optional) Source filename; or empty if not present.
	SourceFilename string
	// (optional) Data layout; or empty if not present.
	DataLayout string
	// (optional) Target triple; or empty if not present.
	TargetTriple string
	// (optional) Module-level inline assembly.
	ModuleAsms []string
	// (optional) Comdat definitions.
	ComdatDefs []*ComdatDef
	// (optional) Aliases.
	Aliases []*Alias
	// (optional) IFuncs.
	IFuncs []*IFunc
	// (optional) Attribute group definitions.
	AttrGroupDefs []*AttrGroupDef
	// (optional) Named metadata definitions.
	NamedMetadataDefs map[string]*metadata.NamedDef
	// (optional) Metadata definitions.
	MetadataDefs []metadata.Definition
	// (optional) Use-list order directives.
	UseListOrders []*UseListOrder
	// (optional) Basic block specific use-list order directives.
	UseListOrderBBs []*UseListOrderBB
	// contains filtered or unexported fields
}

Module is an LLVM IR module, which consists of top-level declarations and definitions.

func NewModule

func NewModule() *Module

NewModule returns a new LLVM IR module.

func (*Module) AssignGlobalIDs added in v0.3.3

func (m *Module) AssignGlobalIDs() error

AssignGlobalIDs assigns IDs to unnamed global variables.

func (*Module) AssignMetadataIDs

func (m *Module) AssignMetadataIDs() error

AssignMetadataIDs assigns metadata IDs to the unnamed metadata definitions of the module.

func (*Module) NewAlias

func (m *Module) NewAlias(name string, aliasee constant.Constant) *Alias

NewAlias appends a new alias to the module based on the given alias name and aliasee.

func (*Module) NewFunc

func (m *Module) NewFunc(name string, retType types.Type, params ...*Param) *Func

NewFunc appends a new function to the module based on the given function name, return type and function parameters.

The Parent field of the function is set to m.

func (*Module) NewGlobal

func (m *Module) NewGlobal(name string, contentType types.Type) *Global

NewGlobal appends a new global variable declaration to the module based on the given global variable name and content type.

func (*Module) NewGlobalDef

func (m *Module) NewGlobalDef(name string, init constant.Constant) *Global

NewGlobalDef appends a new global variable definition to the module based on the given global variable name and initial value.

func (*Module) NewIFunc

func (m *Module) NewIFunc(name string, resolver constant.Constant) *IFunc

NewIFunc appends a new indirect function to the module based on the given IFunc name and resolver.

func (*Module) NewTypeDef

func (m *Module) NewTypeDef(name string, typ types.Type) types.Type

NewTypeDef appends a new type definition to the module based on the given type name and underlying type.

func (*Module) String

func (m *Module) String() string

String returns the string representation of the module in LLVM IR assembly syntax.

func (*Module) WriteTo

func (m *Module) WriteTo(w io.Writer) (n int64, err error)

WriteTo write the string representation of the module in LLVM IR assembly syntax to w.

type OperandBundle

type OperandBundle struct {
	Tag    string
	Inputs []value.Value
}

OperandBundle is a tagged set of SSA values associated with a call-site.

func NewOperandBundle

func NewOperandBundle(tag string, inputs ...value.Value) *OperandBundle

NewOperandBundle returns a new operand bundle based on the given tag and input values.

func (*OperandBundle) String

func (o *OperandBundle) String() string

String returns a string representation of the operand bundle.

type Param

type Param struct {
	// (optional) Parameter name (without '%' prefix).
	LocalIdent
	// Parameter type.
	Typ types.Type

	// (optional) Parameter attributes.
	Attrs []ParamAttribute
}

Param is an LLVM IR function parameter.

func NewParam

func NewParam(name string, typ types.Type) *Param

NewParam returns a new function parameter based on the given name and type.

func (*Param) LLString

func (p *Param) LLString() string

LLString returns the LLVM syntax representation of the function parameter.

Typ=Type Attrs=ParamAttribute* Name=LocalIdent?

func (*Param) String

func (p *Param) String() string

String returns the LLVM syntax representation of the function parameter as a type-value pair.

func (*Param) Type

func (p *Param) Type() types.Type

Type returns the type of the function parameter.

type ParamAttribute

type ParamAttribute interface {
	fmt.Stringer
	// IsParamAttribute ensures that only parameter attributes can be assigned to
	// the ir.ParamAttribute interface.
	IsParamAttribute()
}

ParamAttribute is a parameter attribute.

A ParamAttribute has one of the following underlying types.

ir.AttrString
ir.AttrPair
ir.Align
ir.Dereferenceable
enum.ParamAttr

type Preallocated added in v0.3.3

type Preallocated struct {
	Typ types.Type
}

Preallocated is a func/param attribute.

func (Preallocated) IsFuncAttribute added in v0.3.3

func (Preallocated) IsFuncAttribute()

IsFuncAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (Preallocated) IsParamAttribute added in v0.3.3

func (Preallocated) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (Preallocated) String added in v0.3.3

func (p Preallocated) String() string

String returns a string representation of the Preallocated attribute.

type ReturnAttribute

type ReturnAttribute interface {
	fmt.Stringer
	// IsReturnAttribute ensures that only return attributes can be assigned to
	// the ir.ReturnAttribute interface.
	IsReturnAttribute()
}

ReturnAttribute is a return attribute.

A ReturnAttribute has one of the following underlying types.

ir.AttrString
ir.AttrPair
ir.Align
ir.Dereferenceable
enum.ReturnAttr

type SRet added in v0.3.4

type SRet struct {
	Typ types.Type
}

SRet is an sret parameter attribute.

func (SRet) IsParamAttribute added in v0.3.4

func (SRet) IsParamAttribute()

IsParamAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (SRet) String added in v0.3.4

func (s SRet) String() string

String returns the string representation of the sret parameter attribute.

type TermBr

type TermBr struct {
	// Target branch.
	Target value.Value // *ir.Block

	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Metadata.
	Metadata
}

TermBr is an unconditional LLVM IR br terminator.

func NewBr

func NewBr(target *Block) *TermBr

NewBr returns a new unconditional br terminator based on the given target basic block.

func (*TermBr) LLString

func (term *TermBr) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'br' Target=Label Metadata=(',' MetadataAttachment)+?

func (*TermBr) Operands added in v0.3.5

func (term *TermBr) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermBr) Succs

func (term *TermBr) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type TermCallBr

type TermCallBr struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Callee function.
	// TODO: specify the set of underlying types of Callee.
	Callee value.Value
	// Function arguments.
	//
	// Arg has one of the following underlying types:
	//    value.Value
	//    TODO: add metadata value?
	Args []value.Value
	// Normal control flow return point.
	NormalRetTarget value.Value // *ir.Block
	// Other control flow return points.
	OtherRetTargets []value.Value // slice of *ir.Block

	// Type of result produced by the terminator.
	Typ types.Type
	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Calling convention; zero if not present.
	CallingConv enum.CallingConv
	// (optional) Return attributes.
	ReturnAttrs []ReturnAttribute
	// (optional) Address space; zero if not present.
	AddrSpace types.AddrSpace
	// (optional) Function attributes.
	FuncAttrs []FuncAttribute
	// (optional) Operand bundles.
	OperandBundles []*OperandBundle
	// (optional) Metadata.
	Metadata
}

TermCallBr is an LLVM IR callbr terminator.

func NewCallBr

func NewCallBr(callee value.Value, args []value.Value, normalRetTarget *Block, otherRetTargets ...*Block) *TermCallBr

NewCallBr returns a new callbr terminator based on the given callee, function arguments and control flow return points for normal and exceptional execution.

TODO: specify the set of underlying types of callee.

func (*TermCallBr) LLString

func (term *TermCallBr) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'callbr' CallingConvopt ReturnAttrs=ReturnAttribute* AddrSpaceopt Typ=Type Callee=Value '(' Args ')' FuncAttrs=FuncAttribute* OperandBundles=('[' (OperandBundle separator ',')+ ']')? 'to' NormalRetTarget=Label '[' OtherRetTargets=(Label separator ',')* ']' Metadata=(',' MetadataAttachment)+?

func (*TermCallBr) Operands added in v0.3.5

func (term *TermCallBr) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermCallBr) Sig

func (term *TermCallBr) Sig() *types.FuncType

Sig returns the function signature of the callee.

func (*TermCallBr) String

func (term *TermCallBr) String() string

String returns the LLVM syntax representation of the terminator as a type- value pair.

func (*TermCallBr) Succs

func (term *TermCallBr) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

func (*TermCallBr) Type

func (term *TermCallBr) Type() types.Type

Type returns the type of the terminator.

type TermCatchRet

type TermCatchRet struct {
	// Exit catchpad.
	CatchPad value.Value // *ir.InstCatchPad
	// Target basic block to transfer control flow to.
	Target value.Value // *ir.Block

	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Metadata.
	Metadata
}

TermCatchRet is an LLVM IR catchret terminator, which catches an in-flight exception from CatchPad and returns control flow to normal at Target.

func NewCatchRet

func NewCatchRet(catchPad *InstCatchPad, target *Block) *TermCatchRet

NewCatchRet returns a new catchret terminator based on the given exit catchpad and target basic block.

func (*TermCatchRet) LLString

func (term *TermCatchRet) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'catchret' 'from' CatchPad=Value 'to' Target=Label Metadata=(',' MetadataAttachment)+?

func (*TermCatchRet) Operands added in v0.3.5

func (term *TermCatchRet) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermCatchRet) Succs

func (term *TermCatchRet) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type TermCatchSwitch

type TermCatchSwitch struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Parent exception pad.
	ParentPad value.Value // ir.ExceptionPad
	// Exception handlers.
	Handlers []value.Value // []*ir.Block
	// Optional default target basic block to transfer control flow to; or nil to
	// unwind to caller function.
	DefaultUnwindTarget value.Value // *ir.Block or nil

	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Metadata.
	Metadata
}

TermCatchSwitch is an LLVM IR catchswitch terminator.

func NewCatchSwitch

func NewCatchSwitch(parentPad ExceptionPad, handlers []*Block, defaultUnwindTarget *Block) *TermCatchSwitch

NewCatchSwitch returns a new catchswitch terminator based on the given parent exception pad, exception handlers and optional default unwind target. If defaultUnwindTarget is nil, catchswitch unwinds to caller function.

func (*TermCatchSwitch) LLString

func (term *TermCatchSwitch) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'catchswitch' 'within' ParentPad=ExceptionPad '[' Handlers=Handlers ']' 'unwind' DefaultUnwindTarget=UnwindTarget Metadata=(',' MetadataAttachment)+?

func (*TermCatchSwitch) Operands added in v0.3.5

func (term *TermCatchSwitch) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermCatchSwitch) String

func (term *TermCatchSwitch) String() string

String returns the LLVM syntax representation of the terminator as a type- value pair.

func (*TermCatchSwitch) Succs

func (term *TermCatchSwitch) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

func (*TermCatchSwitch) Type

func (term *TermCatchSwitch) Type() types.Type

Type returns the type of the terminator.

type TermCleanupRet

type TermCleanupRet struct {
	// Exit cleanuppad.
	CleanupPad value.Value // *ir.InstCleanupPad
	// Optional target basic block to transfer control flow to; or nil to unwind
	// to caller function.
	UnwindTarget value.Value // *ir.Block or nil

	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Metadata.
	Metadata
}

TermCleanupRet is an LLVM IR cleanupret terminator, which indicates that the personality function of a cleanuppad has finished and transfers control flow to an optional target basic block or unwinds to the caller function.

func NewCleanupRet

func NewCleanupRet(cleanupPad *InstCleanupPad, unwindTarget *Block) *TermCleanupRet

NewCleanupRet returns a new cleanupret terminator based on the given exit cleanuppad and optional unwind target. If unwindTarget is nil, cleanupret unwinds to caller function.

func (*TermCleanupRet) LLString

func (term *TermCleanupRet) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'cleanupret' 'from' CleanupPad=Value 'unwind' UnwindTarget Metadata=(',' MetadataAttachment)+?

func (*TermCleanupRet) Operands added in v0.3.5

func (term *TermCleanupRet) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermCleanupRet) Succs

func (term *TermCleanupRet) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type TermCondBr

type TermCondBr struct {
	// Branching condition.
	Cond value.Value
	// True condition target branch.
	TargetTrue value.Value // *ir.Block
	// False condition target branch.
	TargetFalse value.Value // *ir.Block

	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Metadata.
	Metadata
}

TermCondBr is a conditional LLVM IR br terminator.

func NewCondBr

func NewCondBr(cond value.Value, targetTrue, targetFalse *Block) *TermCondBr

NewCondBr returns a new conditional br terminator based on the given branching condition and conditional target basic blocks.

func (*TermCondBr) LLString

func (term *TermCondBr) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'br' CondTyp=IntType Cond=Value ',' TargetTrue=Label ',' TargetFalse=Label Metadata=(',' MetadataAttachment)+?

func (*TermCondBr) Operands added in v0.3.5

func (term *TermCondBr) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermCondBr) Succs

func (term *TermCondBr) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type TermIndirectBr

type TermIndirectBr struct {
	// Target address.
	Addr value.Value // blockaddress
	// Set of valid target basic blocks.
	ValidTargets []value.Value // slice of *ir.Block

	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Metadata.
	Metadata
}

TermIndirectBr is an LLVM IR indirectbr terminator.

func NewIndirectBr

func NewIndirectBr(addr value.Value, validTargets ...*Block) *TermIndirectBr

NewIndirectBr returns a new indirectbr terminator based on the given target address (derived from a blockaddress constant of type i8*) and set of valid target basic blocks.

func (*TermIndirectBr) LLString

func (term *TermIndirectBr) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'indirectbr' Addr=TypeValue ',' '[' ValidTargets=(Label separator ',')* ']' Metadata=(',' MetadataAttachment)+?

func (*TermIndirectBr) Operands added in v0.3.5

func (term *TermIndirectBr) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermIndirectBr) Succs

func (term *TermIndirectBr) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type TermInvoke

type TermInvoke struct {
	// Name of local variable associated with the result.
	LocalIdent
	// Invokee (callee function).
	// TODO: specify the set of underlying types of Invokee.
	Invokee value.Value
	// Function arguments.
	//
	// Arg has one of the following underlying types:
	//    value.Value
	//    TODO: add metadata value?
	Args []value.Value
	// Normal control flow return point.
	NormalRetTarget value.Value // *ir.Block
	// Exception control flow return point.
	ExceptionRetTarget value.Value // *ir.Block

	// Type of result produced by the terminator.
	Typ types.Type
	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Calling convention; zero if not present.
	CallingConv enum.CallingConv
	// (optional) Return attributes.
	ReturnAttrs []ReturnAttribute
	// (optional) Address space; zero if not present.
	AddrSpace types.AddrSpace
	// (optional) Function attributes.
	FuncAttrs []FuncAttribute
	// (optional) Operand bundles.
	OperandBundles []*OperandBundle
	// (optional) Metadata.
	Metadata
}

TermInvoke is an LLVM IR invoke terminator.

func NewInvoke

func NewInvoke(invokee value.Value, args []value.Value, normalRetTarget, exceptionRetTarget *Block) *TermInvoke

NewInvoke returns a new invoke terminator based on the given invokee, function arguments and control flow return points for normal and exceptional execution.

TODO: specify the set of underlying types of invokee.

func (*TermInvoke) LLString

func (term *TermInvoke) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'invoke' CallingConvopt ReturnAttrs=ReturnAttribute* AddrSpaceopt Typ=Type Invokee=Value '(' Args ')' FuncAttrs=FuncAttribute* OperandBundles=('[' (OperandBundle separator ',')+ ']')? 'to' NormalRetTarget=Label 'unwind' ExceptionRetTarget=Label Metadata=(',' MetadataAttachment)+?

func (*TermInvoke) Operands added in v0.3.5

func (term *TermInvoke) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermInvoke) Sig

func (term *TermInvoke) Sig() *types.FuncType

Sig returns the function signature of the invokee.

func (*TermInvoke) String

func (term *TermInvoke) String() string

String returns the LLVM syntax representation of the terminator as a type- value pair.

func (*TermInvoke) Succs

func (term *TermInvoke) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

func (*TermInvoke) Type

func (term *TermInvoke) Type() types.Type

Type returns the type of the terminator.

type TermResume

type TermResume struct {
	// Exception argument to propagate.
	X value.Value

	// (optional) Metadata.
	Metadata
}

TermResume is an LLVM IR resume terminator.

func NewResume

func NewResume(x value.Value) *TermResume

NewResume returns a new resume terminator based on the given exception argument to propagate.

func (*TermResume) LLString

func (term *TermResume) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'resume' X=TypeValue Metadata=(',' MetadataAttachment)+?

func (*TermResume) Operands added in v0.3.5

func (term *TermResume) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermResume) Succs

func (term *TermResume) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type TermRet

type TermRet struct {
	// Return value; or nil if void return.
	X value.Value

	// (optional) Metadata.
	Metadata
}

TermRet is an LLVM IR ret terminator.

func NewRet

func NewRet(x value.Value) *TermRet

NewRet returns a new ret terminator based on the given return value. A nil return value indicates a void return.

func (*TermRet) LLString

func (term *TermRet) LLString() string

LLString returns the LLVM syntax representation of the terminator.

Void return instruction.

'ret' XTyp=VoidType Metadata=(',' MetadataAttachment)+?

Value return instruction.

'ret' XTyp=ConcreteType X=Value Metadata=(',' MetadataAttachment)+?

func (*TermRet) Operands added in v0.3.5

func (term *TermRet) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermRet) Succs

func (*TermRet) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type TermSwitch

type TermSwitch struct {
	// Control variable.
	X value.Value
	// Default target branch.
	TargetDefault value.Value // *ir.Block
	// Switch cases.
	Cases []*Case

	// Successor basic blocks of the terminator.
	Successors []*Block
	// (optional) Metadata.
	Metadata
}

TermSwitch is an LLVM IR switch terminator.

func NewSwitch

func NewSwitch(x value.Value, targetDefault *Block, cases ...*Case) *TermSwitch

NewSwitch returns a new switch terminator based on the given control variable, default target basic block and switch cases.

func (*TermSwitch) LLString

func (term *TermSwitch) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'switch' X=TypeValue ',' Default=Label '[' Cases=Case* ']' Metadata=(',' MetadataAttachment)+?

func (*TermSwitch) Operands added in v0.3.5

func (term *TermSwitch) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermSwitch) Succs

func (term *TermSwitch) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type TermUnreachable

type TermUnreachable struct {

	// (optional) Metadata.
	Metadata
}

TermUnreachable is an LLVM IR unreachable terminator.

func NewUnreachable

func NewUnreachable() *TermUnreachable

NewUnreachable returns a new unreachable terminator.

func (*TermUnreachable) LLString

func (term *TermUnreachable) LLString() string

LLString returns the LLVM syntax representation of the terminator.

'unreachable' Metadata=(',' MetadataAttachment)+?

func (*TermUnreachable) Operands added in v0.3.5

func (term *TermUnreachable) Operands() []*value.Value

Operands returns a mutable list of operands of the given terminator.

func (*TermUnreachable) Succs

func (term *TermUnreachable) Succs() []*Block

Succs returns the successor basic blocks of the terminator.

type Terminator

type Terminator interface {
	LLStringer
	// Succs returns the successor basic blocks of the terminator.
	Succs() []*Block
	// Terminator implements the value.User interface.
	value.User
}

Terminator is an LLVM IR terminator instruction (a control flow instruction).

A Terminator has one of the following underlying types.

Terminators

https://llvm.org/docs/LangRef.html#terminator-instructions

*ir.TermRet           // https://pkg.go.dev/github.com/llir/llvm/ir#TermRet
*ir.TermBr            // https://pkg.go.dev/github.com/llir/llvm/ir#TermBr
*ir.TermCondBr        // https://pkg.go.dev/github.com/llir/llvm/ir#TermCondBr
*ir.TermSwitch        // https://pkg.go.dev/github.com/llir/llvm/ir#TermSwitch
*ir.TermIndirectBr    // https://pkg.go.dev/github.com/llir/llvm/ir#TermIndirectBr
*ir.TermInvoke        // https://pkg.go.dev/github.com/llir/llvm/ir#TermInvoke
*ir.TermCallBr        // https://pkg.go.dev/github.com/llir/llvm/ir#TermCallBr
*ir.TermResume        // https://pkg.go.dev/github.com/llir/llvm/ir#TermResume
*ir.TermCatchSwitch   // https://pkg.go.dev/github.com/llir/llvm/ir#TermCatchSwitch
*ir.TermCatchRet      // https://pkg.go.dev/github.com/llir/llvm/ir#TermCatchRet
*ir.TermCleanupRet    // https://pkg.go.dev/github.com/llir/llvm/ir#TermCleanupRet
*ir.TermUnreachable   // https://pkg.go.dev/github.com/llir/llvm/ir#TermUnreachable

type UseListOrder

type UseListOrder struct {
	// Value.
	Value value.Value
	// Use-list order.
	Indices []uint64
}

UseListOrder is a use-list order directive.

func (*UseListOrder) String

func (u *UseListOrder) String() string

String returns the string representation of the use-list order directive definition.

type UseListOrderBB

type UseListOrderBB struct {
	// Function.
	Func *Func
	// Basic block.
	Block *Block
	// Use-list order.
	Indices []uint64
}

UseListOrderBB is a basic block specific use-list order directive.

func (*UseListOrderBB) String

func (u *UseListOrderBB) String() string

String returns the string representation of the basic block specific use- list order directive definition.

type VectorScaleRange added in v0.3.5

type VectorScaleRange struct {
	// Min value.
	Min int
	// Max value.
	Max int
}

VectorScaleRange denotes the min/max vector scale value of a given function. If the second parameter is omitted, Min will be -1.

func (VectorScaleRange) IsFuncAttribute added in v0.3.5

func (VectorScaleRange) IsFuncAttribute()

IsFuncAttribute ensures that only parameter attributes can be assigned to the ir.ParamAttribute interface.

func (VectorScaleRange) String added in v0.3.5

func (a VectorScaleRange) String() string

String returns the string representation of the vscale_range attribute.

Directories

Path Synopsis
Package constant implements values representing immutable LLVM IR constants.
Package constant implements values representing immutable LLVM IR constants.
Package enum defines enumerate types of LLVM IR.
Package enum defines enumerate types of LLVM IR.
Package metadata provides access to LLVM IR metadata.
Package metadata provides access to LLVM IR metadata.
Package types declares the data types of LLVM IR.
Package types declares the data types of LLVM IR.
Package value provides a definition of LLVM IR values.
Package value provides a definition of LLVM IR values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL