Repository: spack/spack

Issue:
Spack should support the llvm-enabled pgi compiler
Add support for finding / configuring PGI LLVM with `spack compiler find`.

### Rationale

PGI 2018 includes a production version of the PGI Linux/x86-64 compilers with an LLVM code generator and OpenMP runtime. It includes most features, languages, and programming model support found in the default PGI compilers, as well as the PGI debugger and profiler.

### Description

```
[joan5896@shas0136 ~]$ spack compiler add --scope=site /curc/sw/spack/summit/opt/spack/linux-rhel7-x86_64/gcc-4.8.5/pgi-18.4-p3oqv4mfexi5soq4lvfhb4vkrl4cpxqj/linux86-64-llvm/18.4
==> Found no new compilers
==> Compilers are defined in the following files:
    /curc/sw/spack/summit/etc/spack/compilers.yaml
```

This should either find `pgi%18.4`, or a new compiler `pgi-llvm%18.4` (preferred, I think)


Discussion:
I have the same issue with Intel parallel studio 2019.2...
![intelspacknotfound](https://user-images.githubusercontent.com/943165/52776696-73c86b00-3042-11e9-95b2-f6cbc734a285.png)

@anderbubble This should be a really easy feature to add. What are the compiler executable names, the same as PGI? What is the output of `pgcc -V`?

@francesco-bongiovanni Same question, what is the output of `icc --version`?
> @anderbubble This should be a really easy feature to add. What are the compiler executable names, the same as PGI? What is the output of `pgcc -V`?
> 
> @francesco-bongiovanni Same question, what is the output of `icc --version`?

icc (ICC) 19.0.2.187 20190117
Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.

@francesco-bongiovanni That output looks pretty standard, no idea why Spack wouldn't be picking it up. Are you sure it isn't already in your `compilers.yaml`?
> @anderbubble This should be a really easy feature to add. What are the compiler executable names, the same as PGI?

Looks like they're basically the same; just in a different path and with (optionally?) an `-llvm` suffix.

```
$ ls /curc/sw/spack/opt/spack/linux-rhel7-x86_64/gcc-4.8.5/pgi-18.4-p3oqv4mfexi5soq4lvfhb4vkrl4cpxqj/linux86-64-llvm/18.4/bin/
acc1rc                     jpgdbg.jar        pgappend     pgdebug         pggpp2-llvm    pgprofrc
acclin8664rc               lin8664rc         pgc++        pgexplain.xml   pgicg          pgserv
addlocalrc                 lin86rc           pgcc         pgextract       pgimport       pgsize
add_network_host           llvmrc            pgcc-llvm    pgf90           pgipa          pgsmart
balloontip.jar             llvmversionrc     pgccllvmrc   pgf901-llvm     PGlaf.jar      pgsupport
CcffReader.jar             lmborrow          pgc-llvm     pgf902-llvm     pgllvmrc       pgtjavarc
ccrc                       lmutil            pgc++llvm    pgf90-llvm      pgllvmx8664rc  pgtlinrc
c++llvmrc                  localrc.shas0136  pgc-llvm_ex  pgf90-llvm_ex   pgllvmx86rc    pgtoolsrc
cppcurc                    makellvmlocalrc   pgcollect    pgf90llvmrc     pgnvd          pgtxwinrc
cpprc                      makelocalrc       pgcollectrc  pgf90rc         pgnvd64rc      pgunzip
c++rc                      mpirun_dbg.pgdbg  PGcomp.jar   pgf95           pgnvdlinrc     PGutil.jar
fnativerc                  nativerc          pgcpuid      pgfortran       pgnvdrc        pgzip
ganymed-ssh2-build251.jar  noiparc           pgcudainit   pgfortran-llvm  pgnvvm         rsyntaxtextarea.jar
iparc                      pgaccelerror      pgdbg        pgftnrc         pgobjinfo      versionrc
jide-common.jar            pgaccelinfo       pgdbglinrc   pggpp1-llvm     pgprepro       x8664rc
jide-dock.jar              pgacclnk          pgdbgrc      pggpp2ex-llvm   pgprof         x86rc
```

> What is the output of `pgcc -V`?

Looks the same, just with `-llvm` in the compiler name output.

```
$ /curc/sw/spack/opt/spack/linux-rhel7-x86_64/gcc-4.8.5/pgi-18.4-p3oqv4mfexi5soq4lvfhb4vkrl4cpxqj/linux86-64-llvm/18.4/bin/pgcc-llvm -V

pgcc-llvm 18.4-0 LLVM 64-bit target on x86-64 Linux -tp haswell 
PGI Compilers and Tools
Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.
```

Resolving patch:
diff --git a/lib/spack/spack/compilers/pgi.py b/lib/spack/spack/compilers/pgi.py
--- a/lib/spack/spack/compilers/pgi.py
+++ b/lib/spack/spack/compilers/pgi.py
@@ -19,6 +19,10 @@ class Pgi(spack.compiler.Compiler):
     # Subclasses use possible names of Fortran 90 compiler
     fc_names = ['pgfortran', 'pgf95', 'pgf90']
 
+    # LLVM-enabled PGI compilers add a '-llvm' suffix:
+    #   pgcc-llvm, pgc++llvm, pgfortran-llvm
+    suffixes = ['-?llvm']
+
     # Named wrapper links within build_env_path
     link_paths = {'cc': 'pgi/pgcc',
                   'cxx': 'pgi/pgc++',
@@ -29,7 +33,7 @@ class Pgi(spack.compiler.Compiler):
     PrgEnv_compiler = 'pgi'
 
     version_argument = '-V'
-    version_regex = r'pg[^ ]* ([0-9.]+)-[0-9]+ [^ ]+ target on '
+    version_regex = r'pg[^ ]* ([0-9.]+)-[0-9]+ (LLVM )?[^ ]+ target on '
 
     @property
     def openmp_flag(self):


Test patch:
diff --git a/lib/spack/spack/test/compilers.py b/lib/spack/spack/test/compilers.py
--- a/lib/spack/spack/test/compilers.py
+++ b/lib/spack/spack/test/compilers.py
@@ -316,7 +316,13 @@ def test_nag_version_detection(version_str, expected_version):
     # Output on PowerPC
     ('pgcc 17.4-0 linuxpower target on Linuxpower\n'
      'PGI Compilers and Tools\n'
-     'Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.\n', '17.4')
+     'Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.\n',
+     '17.4'),
+    # Output when LLVM-enabled
+    ('pgcc-llvm 18.4-0 LLVM 64-bit target on x86-64 Linux -tp haswell\n'
+     'PGI Compilers and Tools\n'
+     'Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.\n',
+     '18.4')
 ])
 def test_pgi_version_detection(version_str, expected_version):
     version = spack.compilers.pgi.Pgi.extract_version_from_output(version_str)