Hacker News new | ask | show | jobs
by buttproblem 4168 days ago
> LLVM doesn't have an intermediate representation comparable to Gimple: LLIR seems to be at the level of the registers rather than the nice abstract Gimple

LLVM variables are sometimes called registers but they are machine independent. The bit width is arbitrary (e.g., you can create a 129-bit integer). The use of the term register is a misleading analogy; often LLVM-IR is compared to assembly language so the use of the term register was also used.

I do not know GIMPLE and couldn't find a good description of the IR instructions. But, it seems that LLVM IR is somewhat similar to low GIMPLE.

1 comments

Will have to take another look, but it still sounds to me like LLVM IR is more comparable to RTL (https://gcc.gnu.org/onlinedocs/gccint/RTL.html#RTL).

Gimple variables have types comparable with C types - you get pointers, arrays.

For example:

  int sum10(int values[10]) {
    int i;
    int sum = 0;
    for(i=0;i<10;++i) { sum += values[i]; }
    values[0] = 342;
    return sum;
  }
is compiled down to:

  sum10 (int * values)
  {
    long unsigned int D.1598;
    long unsigned int D.1599;
    int * D.1600;
    int D.1601;
    int D.1602;
    int i;
    int sum;

    sum = 0;
    i = 0;
    goto <D.1595>;
    <D.1594>:
    D.1598 = (long unsigned int) i;
    D.1599 = D.1598 * 4;
    D.1600 = values + D.1599;
    D.1601 = *D.1600;
    sum = D.1601 + sum;
    i = i + 1;
    <D.1595>:
    if (i <= 9) goto <D.1594>; else goto <D.1596>;
    <D.1596>:
    *values = 342;
    D.1602 = sum;
    return D.1602;
  }
As far as I know, LLVM does exactly the same thing; the LLVM representation of that code would have a different syntax of course, but semantically would be exactly equivalent to the Gimple version you've presented.