Skip to content
Snippets Groups Projects
Commit b3306378 authored by Eric Christopher's avatar Eric Christopher
Browse files

Add support for the always_inline + target feature diagnostic to print

out the first missing target feature that's required and reword
the diagnostic accordingly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253121 91177308-0d34-0410-b5e6-96231b3b80d8
parent 09bdc143
No related branches found
No related tags found
No related merge requests found
......@@ -432,8 +432,9 @@ def err_arm_invalid_specialreg : Error<"invalid special register for builtin">;
def err_invalid_cpu_supports : Error<"invalid cpu feature string for builtin">;
def err_builtin_needs_feature : Error<"%0 needs target feature %1">;
def err_function_needs_feature
: Error<"function %0 and always_inline callee function %1 are required to "
"have matching target features">;
: Error<"always_inline function %1 requires target feature '%2', but would "
"be inlined into function %0 that is compiled without support for "
"'%2'">;
def warn_builtin_unknown : Warning<"use of unknown builtin %0">,
InGroup<ImplicitFunctionDeclare>, DefaultError;
def warn_dyn_class_memaccess : Warning<
......
......@@ -1852,7 +1852,8 @@ template void CGBuilderInserter<PreserveNames>::InsertHelper(
#undef PreserveNames
static bool hasRequiredFeatures(const SmallVectorImpl<StringRef> &ReqFeatures,
CodeGenModule &CGM, const FunctionDecl *FD) {
CodeGenModule &CGM, const FunctionDecl *FD,
std::string &FirstMissing) {
// If there aren't any required features listed then go ahead and return.
if (ReqFeatures.empty())
return false;
......@@ -1870,7 +1871,11 @@ static bool hasRequiredFeatures(const SmallVectorImpl<StringRef> &ReqFeatures,
Feature.split(OrFeatures, "|");
return std::any_of(OrFeatures.begin(), OrFeatures.end(),
[&](StringRef Feature) {
return CallerFeatureMap.lookup(Feature);
if (!CallerFeatureMap.lookup(Feature)) {
FirstMissing = Feature.str();
return false;
}
return true;
});
});
}
......@@ -1893,6 +1898,7 @@ void CodeGenFunction::checkTargetFeatures(const CallExpr *E,
// the td file with the default cpu, for an always_inline function this is any
// listed cpu and any listed features.
unsigned BuiltinID = TargetDecl->getBuiltinID();
std::string MissingFeature;
if (BuiltinID) {
SmallVector<StringRef, 1> ReqFeatures;
const char *FeatureList =
......@@ -1901,8 +1907,7 @@ void CodeGenFunction::checkTargetFeatures(const CallExpr *E,
if (!FeatureList || StringRef(FeatureList) == "")
return;
StringRef(FeatureList).split(ReqFeatures, ",");
if (!hasRequiredFeatures(ReqFeatures, CGM, FD))
if (!hasRequiredFeatures(ReqFeatures, CGM, FD, MissingFeature))
CGM.getDiags().Report(E->getLocStart(), diag::err_builtin_needs_feature)
<< TargetDecl->getDeclName()
<< CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID);
......@@ -1914,8 +1919,8 @@ void CodeGenFunction::checkTargetFeatures(const CallExpr *E,
CGM.getFunctionFeatureMap(CalleeFeatureMap, TargetDecl);
for (const auto &F : CalleeFeatureMap)
ReqFeatures.push_back(F.getKey());
if (!hasRequiredFeatures(ReqFeatures, CGM, FD))
if (!hasRequiredFeatures(ReqFeatures, CGM, FD, MissingFeature))
CGM.getDiags().Report(E->getLocStart(), diag::err_function_needs_feature)
<< FD->getDeclName() << TargetDecl->getDeclName();
<< FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature;
}
}
......@@ -3,5 +3,5 @@
#include <x86intrin.h>
int baz(__m256i a) {
return _mm256_extract_epi32(a, 3); // expected-error {{function 'baz' and always_inline callee function '_mm256_extract_epi32' are required to have matching target features}}
return _mm256_extract_epi32(a, 3); // expected-error {{always_inline function '_mm256_extract_epi32' requires target feature 'sse4.2', but would be inlined into function 'baz' that is compiled without support for 'sse4.2'}}
}
......@@ -3,6 +3,6 @@ int __attribute__((target("avx"), always_inline)) foo(int a) {
return a + 4;
}
int bar() {
return foo(4); // expected-error {{function 'bar' and always_inline callee function 'foo' are required to have matching target features}}
return foo(4); // expected-error {{always_inline function 'foo' requires target feature 'sse4.2', but would be inlined into function 'bar' that is compiled without support for 'sse4.2'}}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment