This is an archive of the discontinued LLVM Phabricator instance.

[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
ClosedPublic

Authored by dblaikie on Feb 13 2015, 5:32 PM.

Details

Summary

One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.

This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.

  • This doesn't modify gep operators, only instructions (operators will be handled separately)
  • Textual IR changes only. Bitcode (including upgrade) and changing the in-memory representation will be in separate changes.
  • geps of vectors are transformed as: getelementptr <4 x float*> %x, ... ->getelementptr float, <4 x float*> %x, ... Then, once the opaque pointer type is introduced, this will ultimately look like: getelementptr float, <4 x ptr> %x with the unambiguous interpretation that it is a vector of pointers to float.
  • address spaces remain on the pointer, not the type: getelementptr float addrspace(1)* %x ->getelementptr float, float addrspace(1)* %x Then, eventually: getelementptr float, ptr addrspace(1) %x

Importantly, the massive amount of test case churn has been automated by same crappy python code. I had to manually update a few test cases that wouldn't fit the script's model (r228970,r229196,r229197,r229198). The python script just massages stdin and writes the result to stdout, I then wrapped that in a shell script to handle replacing files, then using the usual find+xargs to migrate all the files.

update.py:
import fileinput
import sys
import re

ib = re.compile("getelementptr inbounds +[^( ]")
norm = re.compile("getelementptr +[^( ]")

ibrep = re.compile(r"(^.*?getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")

def conv(match, line):

if not match:
  return line
line = match.groups()[0] 
if len(match.groups()[5]) == 0:
  line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line

for line in sys.stdin:

if line.find("getelementptr ") == line.find("getelementptr inbounds"):
  if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
    line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
  line = conv(re.match(normrep, line), line)
sys.stdout.write(line)

apply.sh:
#!/bin/bash
for name in "$@"
do

python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"

done

The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"

After that, check-all (with llvm, clang, clang-tools-extra, lld, compiler-rt
all checked out - I haven't looked at polly yet). I haven't included the actual
test changes in this review to make it easier to look at - but they are /only/
the changes created by this script (except the unit test change, which I have
included) - nothing manual.

The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.

Diff Detail

Event Timeline

dblaikie updated this revision to Diff 19951.Feb 13 2015, 5:32 PM
dblaikie updated this revision to Diff 19952.
dblaikie retitled this revision from to [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction.
dblaikie updated this object.
dblaikie added a subscriber: Unknown Object (MLST).

Line wrapping some text in the description.

grosser edited edge metadata.Feb 14 2015, 6:30 AM

Hi David,

that looks looks like a reasonable first step. I just checked your scripts on Polly and they work (with the exception of a single case). Feel free to just update the Polly test cases yourself or drop me a line when you pushed the patches upstream.

rafael added inline comments.Feb 26 2015, 12:41 PM
include/llvm/IR/Instructions.h
848 ↗(On Diff #19952)

This is already in. Can you rebase the patch?

rafael added inline comments.Feb 26 2015, 12:42 PM
lib/AsmParser/LLParser.cpp
5444

clang-format please.

5461

This assert can fail on user input, no? It should be a real error report.

dblaikie updated this revision to Diff 20803.Feb 26 2015, 4:14 PM
dblaikie edited edge metadata.

rebase, add/improve error handling and test error cases

rafael accepted this revision.Feb 27 2015, 6:53 AM
rafael edited edge metadata.

LGTM

This revision is now accepted and ready to land.Feb 27 2015, 6:53 AM
This revision was automatically updated to reflect the committed changes.