[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

Jonas Hahnfeld via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 12:11:28 PDT 2018


Hahnfeld added a comment.

In https://reviews.llvm.org/D47849#1124861, @hfinkel wrote:

> In https://reviews.llvm.org/D47849#1124638, @Hahnfeld wrote:
>
> > 2. Incidentally I ran into a closely related problem: I can't `#include <math.h>` in translation units compiled for offloading, Clang complains about inline assembly for x86 (see below). Does that work for you?
> >
> >
> >
> >   In file included from /usr/include/math.h:413:
> >   /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' in asm
> >     __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
> >                                             ^
> >   /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' in asm
> >     __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
> >                                             ^
> >   2 errors generated.
>
>
> Hrmm. I thought that we had fixed that already.
>
> In case it's helpful, in an out-of-tree experimental target I have I ran into a similar problem, and to fix that I wrote the following code in the target's getTargetDefines function (in lib/Basic/Targets):
>
>   // If used as an OpenMP target on x86, x86 target feature macros are defined. math.h
>   // and other system headers will include inline asm if these are defined.
>   Builder.undefineMacro("__SSE2_MATH__");
>   Builder.undefineMacro("__SSE_MATH__");


Just found another workaround:

  diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp
  index 0db15ea..b95f949 100644
  --- a/lib/Sema/SemaStmtAsm.cpp
  +++ b/lib/Sema/SemaStmtAsm.cpp
  @@ -306,7 +306,9 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
   
       TargetInfo::ConstraintInfo Info(Literal->getString(), InputName);
       if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
  -                                                         Info)) {
  +                                                         Info) &&
  +        !(Context.getLangOpts().OpenMPIsDevice &&
  +          Context.getSourceManager().isInSystemHeader(AsmLoc))) {
         return StmtError(Diag(Literal->getLocStart(),
                               diag::err_asm_invalid_input_constraint)
                          << Info.getConstraintStr());

This will ignore all errors during OpenMP device codegen from system headers when the inline assembly is not used. In that case (calling `signbit`) you'll get

  In file included from math.c:2:
  In file included from /usr/include/math.h:413:
  /usr/include/bits/mathinline.h:143:10: error: couldn't allocate input reg for constraint 'x'
    __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
           ^
  1 error generated.

Not sure if that's acceptable...


Repository:
  rC Clang

https://reviews.llvm.org/D47849





More information about the cfe-commits mailing list