cse
이 페이지에서

cse()

함수, 출력 분류

Common-subexpression elimination.

import { cse } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

function cse(m: ModuleDecl): ModuleDecl

매개변수

m ModuleDecl

The module to optimize.

반환값

ModuleDecl

A new module with the rewritten functions; m is not modified.

설명

For every function in m, finds each compound expression that appears two or more times and reads only the function’s inputs (parameters, constants and bindings; never a local variable or a name the function writes to), binds it once to a let, and replaces every occurrence with a reference to that let. The let is placed at the top of the innermost block that contains all of the occurrences, just before the first statement that uses it, so a value used only inside one branch is computed only when that branch runs. A let is never placed inside a loop body. Only the outermost repeated expression is hoisted: two occurrences of sqrt(dot(p, p)) become one temporary holding the whole value. A function whose body contains raw shader text is returned unchanged.

소스

src/core/passes/opt/cse.ts, 255행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고