Skip to content

Commit 6abaee4

Browse files
aykevldeadprogram
authored andcommitted
compiler: remove old atomics workaround for AVR
The bug should have been fixed in any LLVM version that we currently support.
1 parent 1270a50 commit 6abaee4

File tree

1 file changed

+0
-17
lines changed

1 file changed

+0
-17
lines changed

compiler/atomic.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package compiler
22

33
import (
4-
"fmt"
5-
"strings"
6-
74
"tinygo.org/x/go-llvm"
85
)
96

@@ -15,20 +12,6 @@ func (b *builder) createAtomicOp(name string) llvm.Value {
1512
case "AddInt32", "AddInt64", "AddUint32", "AddUint64", "AddUintptr":
1613
ptr := b.getValue(b.fn.Params[0], getPos(b.fn))
1714
val := b.getValue(b.fn.Params[1], getPos(b.fn))
18-
if strings.HasPrefix(b.Triple, "avr") {
19-
// AtomicRMW does not work on AVR as intended:
20-
// - There are some register allocation issues (fixed by https://reviews.llvm.org/D97127 which is not yet in a usable LLVM release)
21-
// - The result is the new value instead of the old value
22-
vType := val.Type()
23-
name := fmt.Sprintf("__sync_fetch_and_add_%d", vType.IntTypeWidth()/8)
24-
fn := b.mod.NamedFunction(name)
25-
if fn.IsNil() {
26-
fn = llvm.AddFunction(b.mod, name, llvm.FunctionType(vType, []llvm.Type{ptr.Type(), vType}, false))
27-
}
28-
oldVal := b.createCall(fn.GlobalValueType(), fn, []llvm.Value{ptr, val}, "")
29-
// Return the new value, not the original value returned.
30-
return b.CreateAdd(oldVal, val, "")
31-
}
3215
oldVal := b.CreateAtomicRMW(llvm.AtomicRMWBinOpAdd, ptr, val, llvm.AtomicOrderingSequentiallyConsistent, true)
3316
// Return the new value, not the original value returned by atomicrmw.
3417
return b.CreateAdd(oldVal, val, "")

0 commit comments

Comments
 (0)