1target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
2target triple = "armv7m-none-eabi"
3
4%runtime.hashmap = type { %runtime.hashmap*, i8*, i32, i8, i8, i8 }
5
6@answer = constant [6 x i8] c"answer"
7
8; func(keySize, valueSize uint8, sizeHint uintptr) *runtime.hashmap
9declare nonnull %runtime.hashmap* @runtime.hashmapMake(i8, i8, i32)
10
11; func(map[string]int, string, unsafe.Pointer)
12declare void @runtime.hashmapStringSet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture readonly)
13
14; func(map[string]int, string, unsafe.Pointer)
15declare i1 @runtime.hashmapStringGet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture)
16
17define void @testUnused() {
18    ; create the map
19    %map = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0)
20    ; create the value to be stored
21    %hashmap.value = alloca i32
22    store i32 42, i32* %hashmap.value
23    ; store the value
24    %hashmap.value.bitcast = bitcast i32* %hashmap.value to i8*
25    call void @runtime.hashmapStringSet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value.bitcast)
26    ret void
27}
28
29; Note that the following function should ideally be optimized (it could simply
30; return 42), but isn't at the moment.
31define i32 @testReadonly() {
32    ; create the map
33    %map = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0)
34
35    ; create the value to be stored
36    %hashmap.value = alloca i32
37    store i32 42, i32* %hashmap.value
38
39    ; store the value
40    %hashmap.value.bitcast = bitcast i32* %hashmap.value to i8*
41    call void @runtime.hashmapStringSet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value.bitcast)
42
43    ; load the value back
44    %hashmap.value2 = alloca i32
45    %hashmap.value2.bitcast = bitcast i32* %hashmap.value2 to i8*
46    %commaOk = call i1 @runtime.hashmapStringGet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value2.bitcast)
47    %loadedValue = load i32, i32* %hashmap.value2
48
49    ret i32 %loadedValue
50}
51
52define %runtime.hashmap* @testUsed() {
53    %1 = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0)
54    ret %runtime.hashmap* %1
55}
56