-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.go
139 lines (135 loc) · 2.81 KB
/
types.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package irutil
import (
"fmt"
"github.com/llir/llvm/ir"
"github.com/llir/llvm/ir/value"
)
// ResetTypes resets the (cached) types of instructions in the given function.
func ResetTypes(f *ir.Func) {
for _, b := range f.Blocks {
for _, inst := range b.Insts {
valueInst, ok := inst.(value.Value)
if !ok {
continue
}
resetType(valueInst)
}
}
}
// resetType resets the (cached) type of the given instruction.
func resetType(inst value.Value) {
switch inst := inst.(type) {
// Unary instructions
case *ir.InstFNeg:
inst.Typ = nil
// Binary instructions
case *ir.InstAdd:
inst.Typ = nil
case *ir.InstFAdd:
inst.Typ = nil
case *ir.InstSub:
inst.Typ = nil
case *ir.InstFSub:
inst.Typ = nil
case *ir.InstMul:
inst.Typ = nil
case *ir.InstFMul:
inst.Typ = nil
case *ir.InstUDiv:
inst.Typ = nil
case *ir.InstSDiv:
inst.Typ = nil
case *ir.InstFDiv:
inst.Typ = nil
case *ir.InstURem:
inst.Typ = nil
case *ir.InstSRem:
inst.Typ = nil
case *ir.InstFRem:
inst.Typ = nil
// Bitwise instructions
case *ir.InstShl:
inst.Typ = nil
case *ir.InstLShr:
inst.Typ = nil
case *ir.InstAShr:
inst.Typ = nil
case *ir.InstAnd:
inst.Typ = nil
case *ir.InstOr:
inst.Typ = nil
case *ir.InstXor:
inst.Typ = nil
// Vector instructions
case *ir.InstExtractElement:
inst.Typ = nil
case *ir.InstInsertElement:
inst.Typ = nil
case *ir.InstShuffleVector:
inst.Typ = nil
// Aggregate instructions
case *ir.InstExtractValue:
inst.Typ = nil
case *ir.InstInsertValue:
inst.Typ = nil
// Memory instructions
case *ir.InstAlloca:
inst.Typ = nil
case *ir.InstLoad:
// type not cached.
case *ir.InstCmpXchg:
inst.Typ = nil
case *ir.InstAtomicRMW:
inst.Typ = nil
case *ir.InstGetElementPtr:
inst.Typ = nil
// Conversion instructions
case *ir.InstTrunc:
// type not cached.
case *ir.InstZExt:
// type not cached.
case *ir.InstSExt:
// type not cached.
case *ir.InstFPTrunc:
// type not cached.
case *ir.InstFPExt:
// type not cached.
case *ir.InstFPToUI:
// type not cached.
case *ir.InstFPToSI:
// type not cached.
case *ir.InstUIToFP:
// type not cached.
case *ir.InstSIToFP:
// type not cached.
case *ir.InstPtrToInt:
// type not cached.
case *ir.InstIntToPtr:
// type not cached.
case *ir.InstBitCast:
// type not cached.
case *ir.InstAddrSpaceCast:
// type not cached.
// Other instructions
case *ir.InstICmp:
inst.Typ = nil
case *ir.InstFCmp:
inst.Typ = nil
case *ir.InstPhi:
inst.Typ = nil
case *ir.InstSelect:
inst.Typ = nil
case *ir.InstCall:
inst.Typ = nil
case *ir.InstVAArg:
// type not cached.
case *ir.InstLandingPad:
// type not cached.
case *ir.InstCatchPad:
// type not cached.
case *ir.InstCleanupPad:
// type not cached.
default:
panic(fmt.Errorf("support for instruction type %T not yet implemented", inst))
}
}