Skip to content

Conversation

@SixWeining
Copy link
Contributor

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?

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?
@llvmbot
Copy link
Member

llvmbot commented Sep 25, 2023

@llvm/pr-subscribers-llvm-support

Changes

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?


Full diff: https://github.com/llvm/llvm-project/pull/67285.diff

1 Files Affected:

  • (modified) llvm/lib/Support/Unix/Memory.inc (+2-1)
diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc
index 4c8f6b2ea7d3a09..69bd1164343da74 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<const char *>(Addr);

Copy link
Contributor

@xen0n xen0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, __clear_cache is DBAR, and I think we need not only DBAR but also IBAR?

@SixWeining
Copy link
Contributor Author

IIRC, __clear_cache is DBAR, and I think we need not only DBAR but also IBAR?

__clear_cache has different implementations:

  • gcc: ibar 0
  • libgcc: empty (I have reported this issue to gcc loongarch maintainers)
  • compiler-rt: ibar 0

@xen0n
Copy link
Contributor

xen0n commented Sep 25, 2023

IIRC, __clear_cache is DBAR, and I think we need not only DBAR but also IBAR?

__clear_cache has different implementations:

* gcc: `ibar 0`

* libgcc: empty (I have reported this issue to gcc loongarch maintainers)

* compiler-rt: `ibar 0`

Hmmm then I must have remembered it wrong (hence the "IIRC" prefix in my reply). No problem from my side then ;-)

@SixWeining SixWeining merged commit fb36658 into llvm:main Oct 19, 2023
@SixWeining SixWeining deleted the __clear_cache branch October 19, 2023 02:16
leecheechen pushed a commit to leecheechen/llvm-project that referenced this pull request Jun 9, 2025
llvm#67285)

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?

(cherry picked from commit fb36658)

Change-Id: I05f81ed770bbc11e74f518d8930f9c538b5ffc50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants