-
Notifications
You must be signed in to change notification settings - Fork 10
/
findInductionVariables.R
35 lines (28 loc) · 1.24 KB
/
findInductionVariables.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
findIVars =
function(mod, canonical = FALSE)
{
if(is.character(mod))
mod = parseIR(mod)
rdefs = getDefinedRoutines(mod, names = FALSE)
if(canonical) {
ans = lapply(rdefs, function(f) {
loops = getLoops(f)
iv = lapply(loops, getInductionVariable)
w = !sapply(iv, is.null)
list(inductonVars = iv[w], loops = loops[w], "function" = replicate(sum(w), f))
})
ans2 = lapply(1:3, function(i) unlist(lapply(ans, `[[`, i)))
names(ans2) = c("inductionVars", "loops", "functions")
ans2
} else {
rloops = lapply(rdefs, function(f) {
la = loopAnalysis(f)
list(loops = getLoops(la), scalarEvolution = la$scalarEvolution)
})
rivars = lapply(rloops, function(x) {
lapply(x$loops, getInductionVariable, x$scalarEvolution)
})
w = sapply(rivars, function(x) sum(!sapply(x, is.null))) > 0
list(inductionVars = rivars[w], loops = lapply(rloops[w], `[[`, 1), functions = rdefs[w])
}
}