gcc内部:计算指令成本 [英] gcc internals: calculating instruction costs

查看:255
本文介绍了gcc内部:计算指令成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个架构工作一个gcc后端。该架构具有用于索引数组访问的指令;因此, ld r0,(r1,r2)等效于 r0 = r1 [r2] 其中 r1 是一个 int32_t *

I'm working on a gcc backend for an architecture. The architecture has instructions for indexed array access; so, ld r0, (r1, r2) is equivalent to r0 = r1[r2] where r1 is a int32_t*.

.md 具有以下模式的文件:

I'm representing this in the .md file with the following pattern:

(define_insn "*si_load_indexed"
  [
    (set
      (match_operand:SI 0 "register_operand" "=r")
      (mem:SI
        (plus:SI
          (mult:SI
            (match_operand:SI 1 "register_operand" "%r")
            (const_int 4))
          (match_operand:SI 2 "register_operand" "r"))))
  ]
  ""
  "ld %0, (%2, %1)"
  [(set_attr "length" "4")]
)

但是,该指令从未实际发出。看看指令组合阶段的调试输出,我看到:

However, the instruction is never actually being emitted. Looking at the debug output from the instruction combining stage, I see this:

Trying 8, 9 -> 10:
Successfully matched this instruction:
(set (reg:SI 47 [ *_5 ])
    (mem:SI (plus:SI (mult:SI (reg/v:SI 43 [ b ])
                (const_int 4 [0x4]))
            (reg:SI 0 r0 [ a ])) [2 *_5+0 S4 A32]))
rejecting combination of insns 8, 9 and 10
original costs 8 + 4 + 4 = 16
replacement cost 32


$ b b

如果我正确读取,说明指令模式已匹配,但指令由于比原来的指令更昂贵而被拒绝。

If I've read this correctly, it indicates that the instruction pattern has been matched, but the instruction has been rejected due to being more expensive than the original instructions.

那么,它如何计算我的教学费用呢?它从哪里得到32(从似乎奇怪的高)?如何说服gcc真正使用这个指令?

So, how is it calculating the cost of my instruction? Where's it getting that 32 from (which seems weirdly high)? How do I persuade gcc to actually use this instruction?

推荐答案

这样问题的正确位置是gcc@gcc.gnu .org。如果你问聪明的问题,他们非常有帮助。 :)

The proper place to asked questions like this is gcc@gcc.gnu.org. They're very helpful if you ask intelligent questions. :)

当然,你应该首先阅读内部手册。相关部分位于此处: http://gcc.gnu.org/onlinedocs/gccint /Costs.html#Costs

You should read the Internals Manual first, of course. The relevant section is here: http://gcc.gnu.org/onlinedocs/gccint/Costs.html#Costs

我相信你需要查看 TARGET_RTX_COSTS ,但我可以是错的。默认行为是估计成本通过逐步通过RTL和加法操作,我想,但它是复杂,一段时间,因为我看看它(看看 rtx_costs )。

I believe you need to look at TARGET_RTX_COSTS, but I could be wrong. The default behaviour is to estimate the cost by stepping through the RTL recursively and adding up the operations, I think, but it's convoluted and a while since I looked at it (look at rtx_costs).

其他端口添加指令属性以帮助他们判断成本。

Other ports add instruction attributes to help them judge costs.

这篇关于gcc内部:计算指令成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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