What is the difference between Interprocedural and Intraprocedural analysis?

Viewed 695

I have searched a lot to find the difference between the Interprocedural and Intraprocedural analysis. As far as I could understand, the Intraprocedural analysis is applied on a single procedure whereas the Interprocedural analysis is applied on all procedures. This is still not clear to me, more specficialy how this Interprocedural analysis is applied on all procedures?

Can someone please give me an explanation for that?

2 Answers

Interprocedural (think Internet, a network of networks, vs. Intranet, a single network) analysis is analysis that operates on multiple functions, for example the following Interproducedural optimization:

function main() {
   return getConstant() * rand()
}

function getConstant() {
   return 42
}

Could be inlined to:

function main() {
   return 42 * rand()
}

And the following Intraprocedural optimization:

function getNrOfSecondsInWeek() {
  secondsAMinute := 60
  minutesAnHour := 60
  hoursADay := 24
  daysAWeek := 7
  return secondsAMinute * minutesAnHour * hoursADay * daysAWeek;
}

Could be inlined to:

function getNrOfSecondsInWeek() {
  return 604800;
}

Intraprocedural analysis is a mechanism for performing optimization (or other analysis) for each function in a compilation unit, using only the information available for that function and compilation unit.

Interprocedural analysis is a mechanism for performing optimization (or other analysis) across function and compilation unit boundaries.

More information here: https://www.ibm.com/docs/en/zos/2.3.0?topic=option-types-procedural-analysis

Related