看板 CompilerDev 關於我們 聯絡資訊
標題下得有點武斷,如果有錯,還請多多指教。 近期研究到這個 Optimization Algorithm,他好像是在 instcombine (peephole)這個 p ass 完成的, 細部的一些機制沒有很深入研究, 大致上的原理是將某一個 IR 指令搬移,使需要用到他的時候才去執行他。 通常都是搬移到 Successor。 感覺上,要把他實作在 assembly code 蠻難的,把他實作在 source code 也不太容易, 是不是做在 IR 上是最合適的?全部都以 basic block 為單位 想深入瞭解但這個 Algorithm 的文章好像不多 另外,我們都知道 O3 的 pass 安排上有他的道理在, 那,我想知道 "為什麼" 目前的 O3 pass 是這樣安排的,這個安排的原因要去哪裡查詢 比較好? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.216.89.29 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/CompilerDev/M.1641560630.A.95E.html
Lipraxde: Instruction sink 記得是為何可以在有 conditional bra 01/07 22:58
Lipraxde: nch 時避免執行到不用的指令,另一個附帶的好處是可以 01/07 22:58
Lipraxde: 減少 live range (對 compilation time 有幫助)。只要 01/07 22:58
Lipraxde: IR 上還保有 data dependency 應該就還能做。不過...這 01/07 22:58
Lipraxde: 是做在 instcombine 裡面的!? 01/07 22:58
在 instcombining.cpp 中,好像是 3730 行那裡有相關實作 https://llvm.org/doxygen/InstructionCombining_8cpp_source.html 但確實我有找到一份純粹是 Sink.cpp 的 source code, https://llvm.org/doxygen/Sink_8cpp_source.html 不曉得兩者差在哪裡,看起來實作內容有差 其中,sink.cpp 這個 pass 可以透過 opt 去應用 opt -enable-new-pm=0 -sink source_ir.ll -S -o dest_ir.ll 不過在 O3 中,並沒有應用這個 sink pass, 而是整併在 instcombine 裏面 想問 Lipraxde 大,所謂的 “IR 上還保有 data dependency 應該就還能做” 是什麼意思呢? ※ 編輯: shane87123 (220.141.73.237 臺灣), 01/08/2022 11:09:31 ※ 編輯: shane87123 (220.141.73.237 臺灣), 01/08/2022 11:10:09
Lipraxde: 其實可以用 git blame 的功能 (github 好用) 看看當初 01/08 13:24
Lipraxde: 的源頭為什麼會有 sink pass以及為什麼會在 instructio 01/08 13:24
Lipraxde: n combine 裡做 sink (我猜是因為 2004 年還沒有 sink 01/08 13:24
Lipraxde: pass,作者直接做在 instruction combine 裡圖個方便) 01/08 13:24
Lipraxde: ,至於為什麼 sink pass 做到後來沒出現在 o3 pass、為 01/08 13:24
Lipraxde: 什麼有了獨立的 pass 大家還是繼續改在 instruction co 01/08 13:24
Lipraxde: mbine 裡呢...這就需要更深的考古學功力了,LLVM 可不 01/08 13:24
Lipraxde: 止這兩個地方有實作 sink,而且看起來可能也不是同時/ 01/08 13:24
Lipraxde: 人做的,都有他們個自的理由,作為一個擁有大量貢獻者 01/08 13:24
Lipraxde: 的開源專案來說,採用理想中最好的方案並不是唯一且必 01/08 13:24
Lipraxde: 要的考量,因此建議是不必太細究這些。 01/08 13:24
Lipraxde: 「IR 上還保有 data dependency 應該就還能做」算是一 01/08 13:35
Lipraxde: 個比較簡略的說法,你想想:將某一個 IR 指令搬移,使 01/08 13:35
Lipraxde: 「需要用到他的時候」才去執行他。想知道什麼時候需要 01/08 13:35
Lipraxde: 用到它自然是需要知道 data dependency 的,總不能不看 01/08 13:35
Lipraxde: 就搬XD 01/08 13:35