This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Convert lit tests to new addr space mapping, part 1
AbandonedPublic

Authored by yaxunl on Nov 2 2017, 11:19 AM.

Details

Summary

Convert AMDGPU/*.ll to use amdgiz environment by the following script.

The plan is to convert all lit tests in llvm and calng for amdgpu to use amdgiz step by step,
then make amdgiz the default environment and clean up the old address space mapping.

#!/bin/bash
#
# script to convert .ll from old address space mapping
# to new address space mapping for AMDGPU.
#
# addr space change:
# 0 -> 5
# 4 -> 0
#

if [[ $# -ne 2 ]]; then
  echo "Convert .ll from old address space mapping to new address space mapping for AMDGPU"
  echo "Usage: chaddr.sh file newfile"
  exit
fi

file=$1
newf=$2

if grep amdgiz $file >/dev/null; then
    exit
fi

has_amdgcn=0
if grep 'mtriple=amdgcn' $file >/dev/null; then
  has_amdgcn=1
elif grep 'march=amdgcn' $file >/dev/null; then
  has_amdgcn=1
fi

has_r600=0
if grep 'mtriple=r600' $file >/dev/null; then
  has_r600=1
elif grep 'march=r600' $file >/dev/null; then
  has_r600=1
fi

if [[ $has_amdgcn == 0 && $has_r600 == 0 ]] ; then
  exit
fi

cp $file $newf

sed -i -e 's:\([]a-zA-Z0-9_>][]a-zA-Z0-9_>]* *\)\*:\1 addrspace(5)*:g' \
    -e 's: addrspace(4) *\*:*:g' \
    -e 's: addrspace(0) *\*: addrspace(5)*:g' \
    -e 's: \(addrspace(.)\*\)\*: \1 addrspace(5)*:g' \
    -e 's:-mtriple=\([^ ]*\):-mtriple=\1-amdgiz:g' \
    -e 's:-march=\([^ ]*\):-march=\1 -mtriple=\1---amdgiz:g' \
    -e 's:-mtriple=\([^ ]*\) \(.*\)-mtriple=\([^ ]*\): \2 -mtriple=\3:g' \
    -e 's: = alloca \(.*\): = alloca \1, addrspace(5):g' \
    -e '/INT/s: addrspace(5)\*:*:g' \
    -e '/SET/s: addrspace(5)\*:*:g' \
    -e '/MOV/s: addrspace(5)\*:*:g' \
    -e '/SH/s: addrspace(5)\*:*:g' \
    -e '/MUL/s: addrspace(5)\*:*:g' \
    -e '/LDS/s: addrspace(5)\*:*:g' \
    -e '/IEEE/s: addrspace(5)\*:*:g' \
    -e '/NoAlias/s: addrspace(5)\*:*:g' \
    -e '/DOT/s: addrspace(5)\*:*:g' \
    $newf

if ! grep mtriple $newf >/dev/null; then
  sed -i -e 's:-march=\([^ ]*\):-march=\1 -mtriple=\1---amdgiz:g' $newf
fi
 
## add missing datalayout 
if grep alloca $file >/dev/null && ! grep datalayout $file >/dev/null; then
    line=$(cat -n $file | grep ';.*RUN'| tail -1 |while read a b; do echo $a; done)
    let "line=line+1"
    sed -i "${line}i"'target datalayout = "A5"' $newf
fi

Diff Detail

Event Timeline

yaxunl created this revision.Nov 2 2017, 11:19 AM
arsenm edited edge metadata.Nov 3 2017, 6:18 AM

You should put the script you used to convert in the commit message since I'll undoubtedly need to convert some tests at some point

yaxunl added a comment.Nov 3 2017, 7:15 AM

You should put the script you used to convert in the commit message since I'll undoubtedly need to convert some tests at some point

I will add it.

yaxunl updated this revision to Diff 121485.Nov 3 2017, 8:22 AM

Add the script for converting .ll from old addr space to new addr space.

yaxunl added a comment.Nov 3 2017, 8:32 AM

the script is chaddr.sh.

yaxunl updated this revision to Diff 121660.Nov 5 2017, 12:20 PM

Update tests.

arsenm added a comment.Nov 5 2017, 3:52 PM

The script isn't that big, so in the past the policy has been to just put the body of the script literally in the commit message rather than adding a temporary file that will be forgotten.

This is adding the amdgiz environment to all the tests, which is not what I expected. I expected that to be removed and to change the default to the new mapping thus removing the need for the triple changes in all of these tests. Is your plan to do that as a separate step after?

yaxunl added a comment.Nov 9 2017, 5:11 PM

The script isn't that big, so in the past the policy has been to just put the body of the script literally in the commit message rather than adding a temporary file that will be forgotten.

This is adding the amdgiz environment to all the tests, which is not what I expected. I expected that to be removed and to change the default to the new mapping thus removing the need for the triple changes in all of these tests. Is your plan to do that as a separate step after?

Yes. Because I have to convert all llvm and clang lit tests then be able to change amdgiz to be the default address space and remove the code about the old address space mapping. However there are still issues which I need to fix. If I do not do the conversion by parts, I face the risk of regression of already passing lit tests. So my plan is to convert the passing lit tests gradually, until all tests are using amdgiz, then make it default in llvm and clang and remove the old address space mapping.

yaxunl updated this revision to Diff 122441.Nov 10 2017, 8:21 AM
yaxunl edited the summary of this revision. (Show Details)
yaxunl added a subscriber: jvesely.

Update all passing ll tests under AMDGPU for new addr space mapping.

Remove the script and put it in git log.

yaxunl updated this revision to Diff 122634.Nov 13 2017, 4:04 AM
yaxunl edited the summary of this revision. (Show Details)

Fixed some script issue and added more passing tests.

yaxunl abandoned this revision.Dec 7 2017, 7:51 AM

superseded by D40955