编译器优化和Thread.MemoryBarrier [英] Compiler optimizations and Thread.MemoryBarrier

查看:92
本文介绍了编译器优化和Thread.MemoryBarrier的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


编译器优化和Thread.MemoryBarrier()

Compiler optimizations and Thread.MemoryBarrier()

我们知道允许编译器重新排列不依赖于顺序的指令优化程序。关于Thread.MemoryBarrier()内存栅栏,什么是'Thread.MemoryBarrier()'阻止编译器从
重新排列指令?

We know that the compiler is allowed to rearrange instructions that are not co-dependent in order to optimize the program. With regard to the Thread.MemoryBarrier() memory fence, what is it about the 'Thread.MemoryBarrier()' that prevents the compiler from rearranging instructions?

例如,什么阻止编译器将函数Foo()转换为下面的函数Bar()? 编译器在代码中看到什么使它改变了默认行为? 它是与Thread.MemoryBarrier()关联的特殊属性,
是硬编码的函数名称,还是其他显然不明显的东西?

For example, what prevents the compiler from converting function Foo() into a function Bar() below ?  What does the compiler see in the code that makes it change its default behavior?  Is it a special attribute associated with Thread.MemoryBarrier(), is it the hard-coded function name, or is it something else that's clearly not obvious?

知道这个,我将预测我自己可以创建具有隐式内置栅栏的方法。

By knowing this, I will predict that I myself can create methods that have implicit built-in fences.

推荐答案

CoreCLR 1.1.2硬编码名称
src / vm / ecalllist.h

 FCIntrinsic("MemoryBarrier", ThreadNative::FCMemoryBarrier, CORINFO_INTRINSIC_MemoryBarrier)

ThreadNative :: FCMemoryBarrier在
src / vm / comsynchronizable.cpp
它使用特定于体系结构的MemoryBarrier
中定义的宏
src / gc / env / gcenv.base.h
。但是,我怀疑它实际上并没有被调用,因为
中的Compiler :: impIntrinsic
src\jit\importer.cpp
识别CORINFO_INTRINSIC_MemoryBarrier并将其转换为GT_MEMORYBARRIER,并且然后代码生成器调用

CodeGen :: instGen_MemoryBarrier
,它以内联方式发出代码。

ThreadNative::FCMemoryBarrier is defined in src/vm/comsynchronizable.cpp and it uses the architecture-specific MemoryBarrier macro defined in src/gc/env/gcenv.base.h. However, I suspect it is not actually called, because Compiler::impIntrinsic in src\jit\importer.cpp recognizes CORINFO_INTRINSIC_MemoryBarrier and translates it to GT_MEMORYBARRIER, and the code generators then call CodeGen::instGen_MemoryBarrier, which emits the code inline.


这篇关于编译器优化和Thread.MemoryBarrier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆