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