From 4dcf3fc621592daf6d81893df8b5d644c606d7f2 Mon Sep 17 00:00:00 2001 From: Weining Lu Date: Mon, 25 Sep 2023 13:42:00 +0800 Subject: [PATCH] [Memory] Call __clear_cache in InvalidateInstructionCache on LoongArch As the comments of `InvalidateInstructionCache`: Before the JIT can run a block of code that has been emitted it must invalidate the instruction cache on some platforms. I think it applies to LoongArch as LoongArch has a weak memory-model. But I'm not able to write a test to demonstrate this issue. Perhaps self-modifing code should be wrote? --- llvm/lib/Support/Unix/Memory.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc index 4c8f6b2ea7d3a..69bd1164343da 100644 --- a/llvm/lib/Support/Unix/Memory.inc +++ b/llvm/lib/Support/Unix/Memory.inc @@ -237,7 +237,8 @@ void Memory::InvalidateInstructionCache(const void *Addr, size_t Len) { for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize) asm volatile("icbi 0, %0" : : "r"(Line)); asm volatile("isync"); -#elif (defined(__arm__) || defined(__aarch64__) || defined(__mips__)) && \ +#elif (defined(__arm__) || defined(__aarch64__) || defined(__loongarch__) || \ + defined(__mips__)) && \ defined(__GNUC__) // FIXME: Can we safely always call this for __GNUC__ everywhere? const char *Start = static_cast(Addr);