github.com/llir/llvm@v0.3.6/ir/block_memory.go (about) 1 package ir 2 3 import ( 4 "github.com/llir/llvm/ir/enum" 5 "github.com/llir/llvm/ir/types" 6 "github.com/llir/llvm/ir/value" 7 ) 8 9 // --- [ Memory instructions ] ------------------------------------------------- 10 11 // ~~~ [ alloca ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 13 // NewAlloca appends a new alloca instruction to the basic block based on the 14 // given element type. 15 func (block *Block) NewAlloca(elemType types.Type) *InstAlloca { 16 inst := NewAlloca(elemType) 17 block.Insts = append(block.Insts, inst) 18 return inst 19 } 20 21 // ~~~ [ load ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 23 // NewLoad appends a new load instruction to the basic block based on the given 24 // element type and source address. 25 func (block *Block) NewLoad(elemType types.Type, src value.Value) *InstLoad { 26 inst := NewLoad(elemType, src) 27 block.Insts = append(block.Insts, inst) 28 return inst 29 } 30 31 // ~~~ [ store ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 32 33 // NewStore appends a new store instruction to the basic block based on the 34 // given source value and destination address. 35 func (block *Block) NewStore(src, dst value.Value) *InstStore { 36 inst := NewStore(src, dst) 37 block.Insts = append(block.Insts, inst) 38 return inst 39 } 40 41 // ~~~ [ fence ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 42 43 // NewFence appends a new fence instruction to the basic block based on the 44 // given atomic ordering. 45 func (block *Block) NewFence(ordering enum.AtomicOrdering) *InstFence { 46 inst := NewFence(ordering) 47 block.Insts = append(block.Insts, inst) 48 return inst 49 } 50 51 // ~~~ [ cmpxchg ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 53 // NewCmpXchg appends a new cmpxchg instruction to the basic block based on the 54 // given address, value to compare against, new value to store, and atomic 55 // orderings for success and failure. 56 func (block *Block) NewCmpXchg(ptr, cmp, new value.Value, successOrdering, failureOrdering enum.AtomicOrdering) *InstCmpXchg { 57 inst := NewCmpXchg(ptr, cmp, new, successOrdering, failureOrdering) 58 block.Insts = append(block.Insts, inst) 59 return inst 60 } 61 62 // ~~~ [ atomicrmw ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 63 64 // NewAtomicRMW appends a new atomicrmw instruction to the basic block based on 65 // the given atomic operation, destination address, operand and atomic ordering. 66 func (block *Block) NewAtomicRMW(op enum.AtomicOp, dst, x value.Value, ordering enum.AtomicOrdering) *InstAtomicRMW { 67 inst := NewAtomicRMW(op, dst, x, ordering) 68 block.Insts = append(block.Insts, inst) 69 return inst 70 } 71 72 // ~~~ [ getelementptr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 74 // NewGetElementPtr appends a new getelementptr instruction to the basic block 75 // based on the given element type, source address and element indices. 76 func (block *Block) NewGetElementPtr(elemType types.Type, src value.Value, indices ...value.Value) *InstGetElementPtr { 77 inst := NewGetElementPtr(elemType, src, indices...) 78 block.Insts = append(block.Insts, inst) 79 return inst 80 }