Skip to content

Commit 24bd54d

Browse files
authored
Merge pull request #50 from schweitzpgi/release_70
merge latest from llvm mirror to Release 70
2 parents 4a9339f + cc5aa71 commit 24bd54d

34 files changed

+580
-281
lines changed

include/clang/AST/DeclBase.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@ class DeclContextLookupResult {
12161216
value_type SingleElement;
12171217

12181218
public:
1219-
iterator() = default;
12201219
explicit iterator(pointer Pos, value_type Single = nullptr)
12211220
: IteratorBase(Pos), SingleElement(Single) {}
12221221

include/clang/Basic/Attr.td

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,39 @@ def Target : InheritableAttr {
19531953
return parse(getFeaturesStr());
19541954
}
19551955

1956+
StringRef getArchitecture() const {
1957+
StringRef Features = getFeaturesStr();
1958+
if (Features == "default") return {};
1959+
1960+
SmallVector<StringRef, 1> AttrFeatures;
1961+
Features.split(AttrFeatures, ",");
1962+
1963+
for (auto &Feature : AttrFeatures) {
1964+
Feature = Feature.trim();
1965+
if (Feature.startswith("arch="))
1966+
return Feature.drop_front(sizeof("arch=") - 1);
1967+
}
1968+
return "";
1969+
}
1970+
1971+
// Gets the list of features as simple string-refs with no +/- or 'no-'.
1972+
// Only adds the items to 'Out' that are additions.
1973+
void getAddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
1974+
StringRef Features = getFeaturesStr();
1975+
if (Features == "default") return;
1976+
1977+
SmallVector<StringRef, 1> AttrFeatures;
1978+
Features.split(AttrFeatures, ",");
1979+
1980+
for (auto &Feature : AttrFeatures) {
1981+
Feature = Feature.trim();
1982+
1983+
if (!Feature.startswith("no-") && !Feature.startswith("arch=") &&
1984+
!Feature.startswith("fpmath=") && !Feature.startswith("tune="))
1985+
Out.push_back(Feature);
1986+
}
1987+
}
1988+
19561989
template<class Compare>
19571990
ParsedTargetAttr parse(Compare cmp) const {
19581991
ParsedTargetAttr Attrs = parse();

include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3364,7 +3364,7 @@ def IFuncDocs : Documentation {
33643364
let Content = [{
33653365
``__attribute__((ifunc("resolver")))`` is used to mark that the address of a declaration should be resolved at runtime by calling a resolver function.
33663366

3367-
The symbol name of the resolver function is given in quotes. A function with this name (after mangling) must be defined in the current translation unit; it may be ``static``. The resolver function should take no arguments and return a pointer.
3367+
The symbol name of the resolver function is given in quotes. A function with this name (after mangling) must be defined in the current translation unit; it may be ``static``. The resolver function should return a pointer.
33683368

33693369
The ``ifunc`` attribute may only be used on a function declaration. A function declaration with an ``ifunc`` attribute is considered to be a definition of the declared entity. The entity must not have weak linkage; for example, in C++, it cannot be applied to a declaration if a definition at that location would be considered inline.
33703370

include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def warn_option_invalid_ocl_version : Warning<
238238
"OpenCL version %0 does not support the option '%1'">, InGroup<Deprecated>;
239239

240240
def warn_stdlibcxx_not_found : Warning<
241-
"include path for stdlibc++ headers not found; pass '-std=libc++' on the "
241+
"include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the "
242242
"command line to use the libc++ standard library instead">,
243243
InGroup<DiagGroup<"stdlibcxx-not-found">>;
244244
}

include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,8 +2857,6 @@ def err_cyclic_alias : Error<
28572857
"%select{alias|ifunc}0 definition is part of a cycle">;
28582858
def err_ifunc_resolver_return : Error<
28592859
"ifunc resolver function must return a pointer">;
2860-
def err_ifunc_resolver_params : Error<
2861-
"ifunc resolver function must have no parameters">;
28622860
def warn_attribute_wrong_decl_type_str : Warning<
28632861
"%0 attribute only applies to %1">, InGroup<IgnoredAttributes>;
28642862
def err_attribute_wrong_decl_type_str : Error<

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9734,6 +9734,10 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
97349734
return true;
97359735

97369736
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
9737+
// Multiversioned functions always have to be emitted, because they are used
9738+
// by the resolver.
9739+
if (FD->isMultiVersion())
9740+
return true;
97379741
// Forward declarations aren't required.
97389742
if (!FD->doesThisDeclarationHaveABody())
97399743
return FD->doesDeclarationForceExternallyVisibleDefinition();

lib/AST/Decl.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
725725
// If we're paying attention to global visibility, apply
726726
// -finline-visibility-hidden if this is an inline method.
727727
if (useInlineVisibilityHidden(D))
728-
LV.mergeVisibility(HiddenVisibility, true);
728+
LV.mergeVisibility(HiddenVisibility, /*visibilityExplicit=*/false);
729729
}
730730
}
731731

@@ -915,7 +915,7 @@ LinkageComputer::getLVForClassMember(const NamedDecl *D,
915915
// Note that we do this before merging information about
916916
// the class visibility.
917917
if (!LV.isVisibilityExplicit() && useInlineVisibilityHidden(D))
918-
LV.mergeVisibility(HiddenVisibility, true);
918+
LV.mergeVisibility(HiddenVisibility, /*visibilityExplicit=*/false);
919919
}
920920

921921
// If this class member has an explicit visibility attribute, the only
@@ -1262,7 +1262,27 @@ LinkageInfo LinkageComputer::getLVForLocalDecl(const NamedDecl *D,
12621262
!isTemplateInstantiation(FD->getTemplateSpecializationKind()))
12631263
return LinkageInfo::none();
12641264

1265+
// If a function is hidden by -fvisibility-inlines-hidden option and
1266+
// is not explicitly attributed as a hidden function,
1267+
// we should not make static local variables in the function hidden.
12651268
LV = getLVForDecl(FD, computation);
1269+
if (isa<VarDecl>(D) && useInlineVisibilityHidden(FD) &&
1270+
!LV.isVisibilityExplicit()) {
1271+
assert(cast<VarDecl>(D)->isStaticLocal());
1272+
// If this was an implicitly hidden inline method, check again for
1273+
// explicit visibility on the parent class, and use that for static locals
1274+
// if present.
1275+
if (const auto *MD = dyn_cast<CXXMethodDecl>(FD))
1276+
LV = getLVForDecl(MD->getParent(), computation);
1277+
if (!LV.isVisibilityExplicit()) {
1278+
Visibility globalVisibility =
1279+
computation.isValueVisibility()
1280+
? Context.getLangOpts().getValueVisibilityMode()
1281+
: Context.getLangOpts().getTypeVisibilityMode();
1282+
return LinkageInfo(VisibleNoLinkage, globalVisibility,
1283+
/*visibilityExplicit=*/false);
1284+
}
1285+
}
12661286
}
12671287
if (!isExternallyVisible(LV.getLinkage()))
12681288
return LinkageInfo::none();

lib/CodeGen/CodeGenFunction.cpp

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,91 +2359,53 @@ void CodeGenFunction::EmitSanitizerStatReport(llvm::SanitizerStatKind SSK) {
23592359
CGM.getSanStats().create(IRB, SSK);
23602360
}
23612361

2362-
llvm::Value *CodeGenFunction::FormResolverCondition(
2363-
const TargetMultiVersionResolverOption &RO) {
2364-
llvm::Value *TrueCondition = nullptr;
2365-
if (!RO.ParsedAttribute.Architecture.empty())
2366-
TrueCondition = EmitX86CpuIs(RO.ParsedAttribute.Architecture);
2367-
2368-
if (!RO.ParsedAttribute.Features.empty()) {
2369-
SmallVector<StringRef, 8> FeatureList;
2370-
llvm::for_each(RO.ParsedAttribute.Features,
2371-
[&FeatureList](const std::string &Feature) {
2372-
FeatureList.push_back(StringRef{Feature}.substr(1));
2373-
});
2374-
llvm::Value *FeatureCmp = EmitX86CpuSupports(FeatureList);
2375-
TrueCondition = TrueCondition ? Builder.CreateAnd(TrueCondition, FeatureCmp)
2376-
: FeatureCmp;
2377-
}
2378-
return TrueCondition;
2379-
}
2380-
2381-
void CodeGenFunction::EmitTargetMultiVersionResolver(
2382-
llvm::Function *Resolver,
2383-
ArrayRef<TargetMultiVersionResolverOption> Options) {
2384-
assert((getContext().getTargetInfo().getTriple().getArch() ==
2385-
llvm::Triple::x86 ||
2386-
getContext().getTargetInfo().getTriple().getArch() ==
2387-
llvm::Triple::x86_64) &&
2388-
"Only implemented for x86 targets");
2389-
2390-
// Main function's basic block.
2391-
llvm::BasicBlock *CurBlock = createBasicBlock("entry", Resolver);
2392-
Builder.SetInsertPoint(CurBlock);
2393-
EmitX86CpuInit();
2362+
llvm::Value *
2363+
CodeGenFunction::FormResolverCondition(const MultiVersionResolverOption &RO) {
2364+
llvm::Value *Condition = nullptr;
23942365

2395-
llvm::Function *DefaultFunc = nullptr;
2396-
for (const TargetMultiVersionResolverOption &RO : Options) {
2397-
Builder.SetInsertPoint(CurBlock);
2398-
llvm::Value *TrueCondition = FormResolverCondition(RO);
2366+
if (!RO.Conditions.Architecture.empty())
2367+
Condition = EmitX86CpuIs(RO.Conditions.Architecture);
23992368

2400-
if (!TrueCondition) {
2401-
DefaultFunc = RO.Function;
2402-
} else {
2403-
llvm::BasicBlock *RetBlock = createBasicBlock("ro_ret", Resolver);
2404-
llvm::IRBuilder<> RetBuilder(RetBlock);
2405-
RetBuilder.CreateRet(RO.Function);
2406-
CurBlock = createBasicBlock("ro_else", Resolver);
2407-
Builder.CreateCondBr(TrueCondition, RetBlock, CurBlock);
2408-
}
2369+
if (!RO.Conditions.Features.empty()) {
2370+
llvm::Value *FeatureCond = EmitX86CpuSupports(RO.Conditions.Features);
2371+
Condition =
2372+
Condition ? Builder.CreateAnd(Condition, FeatureCond) : FeatureCond;
24092373
}
2410-
2411-
assert(DefaultFunc && "No default version?");
2412-
// Emit return from the 'else-ist' block.
2413-
Builder.SetInsertPoint(CurBlock);
2414-
Builder.CreateRet(DefaultFunc);
2374+
return Condition;
24152375
}
24162376

2417-
void CodeGenFunction::EmitCPUDispatchMultiVersionResolver(
2418-
llvm::Function *Resolver,
2419-
ArrayRef<CPUDispatchMultiVersionResolverOption> Options) {
2377+
void CodeGenFunction::EmitMultiVersionResolver(
2378+
llvm::Function *Resolver, ArrayRef<MultiVersionResolverOption> Options) {
24202379
assert((getContext().getTargetInfo().getTriple().getArch() ==
24212380
llvm::Triple::x86 ||
24222381
getContext().getTargetInfo().getTriple().getArch() ==
24232382
llvm::Triple::x86_64) &&
24242383
"Only implemented for x86 targets");
2425-
24262384
// Main function's basic block.
24272385
llvm::BasicBlock *CurBlock = createBasicBlock("resolver_entry", Resolver);
24282386
Builder.SetInsertPoint(CurBlock);
24292387
EmitX86CpuInit();
24302388

2431-
for (const CPUDispatchMultiVersionResolverOption &RO : Options) {
2389+
for (const MultiVersionResolverOption &RO : Options) {
24322390
Builder.SetInsertPoint(CurBlock);
2391+
llvm::Value *Condition = FormResolverCondition(RO);
24332392

2434-
// "generic" case should catch-all.
2435-
if (RO.FeatureMask == 0) {
2393+
// The 'default' or 'generic' case.
2394+
if (!Condition) {
2395+
assert(&RO == Options.end() - 1 &&
2396+
"Default or Generic case must be last");
24362397
Builder.CreateRet(RO.Function);
24372398
return;
24382399
}
2400+
24392401
llvm::BasicBlock *RetBlock = createBasicBlock("resolver_return", Resolver);
24402402
llvm::IRBuilder<> RetBuilder(RetBlock);
24412403
RetBuilder.CreateRet(RO.Function);
24422404
CurBlock = createBasicBlock("resolver_else", Resolver);
2443-
llvm::Value *TrueCondition = EmitX86CpuSupports(RO.FeatureMask);
2444-
Builder.CreateCondBr(TrueCondition, RetBlock, CurBlock);
2405+
Builder.CreateCondBr(Condition, RetBlock, CurBlock);
24452406
}
24462407

2408+
// If no generic/default, emit an unreachable.
24472409
Builder.SetInsertPoint(CurBlock);
24482410
llvm::CallInst *TrapCall = EmitTrapCall(llvm::Intrinsic::trap);
24492411
TrapCall->setDoesNotReturn();

lib/CodeGen/CodeGenFunction.h

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,30 +4247,26 @@ class CodeGenFunction : public CodeGenTypeCache {
42474247

42484248
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK);
42494249

4250-
struct TargetMultiVersionResolverOption {
4250+
struct MultiVersionResolverOption {
42514251
llvm::Function *Function;
4252-
TargetAttr::ParsedTargetAttr ParsedAttribute;
4253-
unsigned Priority;
4254-
TargetMultiVersionResolverOption(
4255-
const TargetInfo &TargInfo, llvm::Function *F,
4256-
const clang::TargetAttr::ParsedTargetAttr &PT)
4257-
: Function(F), ParsedAttribute(PT), Priority(0u) {
4258-
for (StringRef Feat : PT.Features)
4259-
Priority = std::max(Priority,
4260-
TargInfo.multiVersionSortPriority(Feat.substr(1)));
4261-
4262-
if (!PT.Architecture.empty())
4263-
Priority = std::max(Priority,
4264-
TargInfo.multiVersionSortPriority(PT.Architecture));
4265-
}
4252+
struct Conds {
4253+
StringRef Architecture;
4254+
llvm::SmallVector<StringRef, 8> Features;
42664255

4267-
bool operator>(const TargetMultiVersionResolverOption &Other) const {
4268-
return Priority > Other.Priority;
4269-
}
4256+
Conds(StringRef Arch, ArrayRef<StringRef> Feats)
4257+
: Architecture(Arch), Features(Feats.begin(), Feats.end()) {}
4258+
} Conditions;
4259+
4260+
MultiVersionResolverOption(llvm::Function *F, StringRef Arch,
4261+
ArrayRef<StringRef> Feats)
4262+
: Function(F), Conditions(Arch, Feats) {}
42704263
};
4271-
void EmitTargetMultiVersionResolver(
4272-
llvm::Function *Resolver,
4273-
ArrayRef<TargetMultiVersionResolverOption> Options);
4264+
4265+
// Emits the body of a multiversion function's resolver. Assumes that the
4266+
// options are already sorted in the proper order, with the 'default' option
4267+
// last (if it exists).
4268+
void EmitMultiVersionResolver(llvm::Function *Resolver,
4269+
ArrayRef<MultiVersionResolverOption> Options);
42744270

42754271
struct CPUDispatchMultiVersionResolverOption {
42764272
llvm::Function *Function;
@@ -4306,8 +4302,7 @@ class CodeGenFunction : public CodeGenTypeCache {
43064302
llvm::Value *EmitX86CpuSupports(ArrayRef<StringRef> FeatureStrs);
43074303
llvm::Value *EmitX86CpuSupports(uint32_t Mask);
43084304
llvm::Value *EmitX86CpuInit();
4309-
llvm::Value *
4310-
FormResolverCondition(const TargetMultiVersionResolverOption &RO);
4305+
llvm::Value *FormResolverCondition(const MultiVersionResolverOption &RO);
43114306
};
43124307

43134308
inline DominatingLLVMValue::saved_type

0 commit comments

Comments
 (0)