1
votes

In the below code the function has 2 arguments, which I assume are stored in %0 and %1.
Jet the function starts with %3.
What is %2 used for?

define void @swap(i32*, i32*) #0 {
  %3 = alloca i32*, align 8
  %4 = alloca i32*, align 8
  %5 = alloca i32*, align 8
  store i32* %0, i32** %3, align 8
  store i32* %1, i32** %4, align 8
  %6 = load i32*, i32** %3, align 8
  store i32* %6, i32** %5, align 8
  %7 = load i32*, i32** %4, align 8
  store i32* %7, i32** %3, align 8
  %8 = load i32*, i32** %5, align 8
  store i32* %8, i32** %4, align 8
  ret void
}

The above LLVM code was generated with clang from this c code:

void swap(int* i, int* j){
    int* temp = i;
    i = j;
    j = temp;
}
1
%2 may have the named of an instruction which was generated, later found to be superfluous, and deleted. %2 or %42 doesn't mean anything, it's just a name supplied if the caller doesn't supply an explicit name. - arnt

1 Answers

2
votes

%2 is the name of the entry basic block. Non-entry BBs have their names explicit, like <label>:123.