[PATCH] Ignore device-side asm constraint errors while compiling CUDA code for host and vice versa.
Artem Belevich
tra at google.com
Tue Mar 17 13:38:12 PDT 2015
Hi echristo, eliben,
Ignore device-side asm constraint errors while compiling CUDA code for host and vice versa.
http://reviews.llvm.org/D8392
Files:
lib/Sema/SemaStmtAsm.cpp
test/SemaCUDA/asm-constraints.cu
Index: lib/Sema/SemaStmtAsm.cpp
===================================================================
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -124,6 +124,19 @@
// The parser verifies that there is a string literal here.
assert(AsmString->isAscii());
+ bool ValidateConstraints;
+ if (getLangOpts().CUDA) {
+ // In CUDA mode don't verify asm constraints in device functions during host
+ // compilation and vice versa.
+ bool InDeviceMode = getLangOpts().CUDAIsDevice;
+ FunctionDecl *FD = getCurFunctionDecl();
+ bool IsDeviceFunction =
+ FD && (FD->hasAttr<CUDADeviceAttr>() || FD->hasAttr<CUDAGlobalAttr>());
+ ValidateConstraints = IsDeviceFunction == InDeviceMode;
+ } else {
+ ValidateConstraints = true;
+ }
+
for (unsigned i = 0; i != NumOutputs; i++) {
StringLiteral *Literal = Constraints[i];
assert(Literal->isAscii());
@@ -133,7 +146,8 @@
OutputName = Names[i]->getName();
TargetInfo::ConstraintInfo Info(Literal->getString(), OutputName);
- if (!Context.getTargetInfo().validateOutputConstraint(Info))
+ if (ValidateConstraints &&
+ !Context.getTargetInfo().validateOutputConstraint(Info))
return StmtError(Diag(Literal->getLocStart(),
diag::err_asm_invalid_output_constraint)
<< Info.getConstraintStr());
@@ -207,8 +221,9 @@
InputName = Names[i]->getName();
TargetInfo::ConstraintInfo Info(Literal->getString(), InputName);
- if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos.data(),
- NumOutputs, Info)) {
+ if (ValidateConstraints &&
+ !Context.getTargetInfo().validateInputConstraint(
+ OutputConstraintInfos.data(), NumOutputs, Info)) {
return StmtError(Diag(Literal->getLocStart(),
diag::err_asm_invalid_input_constraint)
<< Info.getConstraintStr());
Index: test/SemaCUDA/asm-constraints.cu
===================================================================
--- /dev/null
+++ test/SemaCUDA/asm-constraints.cu
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple nvptx-unknown-cuda -fsyntax-only -fcuda-is-device -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+__attribute__((device)) void df() {
+ short h;
+ // asm with PTX constraints. Some of them are PTX-specific.
+ __asm__("dont care" : "=h"(h): "f"(0.0), "d"(0.0), "h"(0), "r"(0), "l"(0));
+}
+
+void hf() {
+ int a;
+ // Asm with x86 constraints that are not supported by PTX.
+ __asm__("dont care" : "=a"(a): "a"(0), "b"(0), "c"(0));
+}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8392.22118.patch
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150317/8fd43396/attachment.bin>
More information about the cfe-commits
mailing list