Skip to content

Commit

Permalink
Manually merged remote-tracking branch 'llvm.org/main' into amd-gfx
Browse files Browse the repository at this point in the history
Change-Id: I5aa9d7609534921e9ed307c658eaef07b219aafb
  • Loading branch information
dstutt committed Jan 11, 2021
2 parents 708f729 + 89878e8 commit 1510cc0
Show file tree
Hide file tree
Showing 577 changed files with 16,862 additions and 4,889 deletions.
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/CodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,8 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
offsetToClangLineColumn(Input.ParseInput.Contents, Input.Offset);

std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer =
llvm::MemoryBuffer::getMemBufferCopy(Input.ParseInput.Contents,
Input.FileName);
llvm::MemoryBuffer::getMemBuffer(Input.ParseInput.Contents,
Input.FileName);
// The diagnostic options must be set before creating a CompilerInstance.
CI->getDiagnosticOpts().IgnoreWarnings = true;
// We reuse the preamble whether it's valid or not. This is a
Expand Down
13 changes: 11 additions & 2 deletions clang-tools-extra/clangd/XRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
// Keep track of SymbolID -> index mapping, to fill in index data later.
llvm::DenseMap<SymbolID, size_t> ResultIndex;

static constexpr trace::Metric LocateASTReferentMetric(
"locate_ast_referent", trace::Metric::Counter, "case");
auto AddResultDecl = [&](const NamedDecl *D) {
D = getPreferredDecl(D);
auto Loc =
Expand Down Expand Up @@ -369,8 +371,10 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
// saved in the AST.
if (CMD->isPure()) {
if (TouchedIdentifier && SM.getSpellingLoc(CMD->getLocation()) ==
TouchedIdentifier->location())
TouchedIdentifier->location()) {
VirtualMethods.insert(getSymbolID(CMD));
LocateASTReferentMetric.record(1, "method-to-override");
}
}
// Special case: void foo() ^override: jump to the overridden method.
const InheritableAttr *Attr = D->getAttr<OverrideAttr>();
Expand All @@ -379,6 +383,7 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
if (Attr && TouchedIdentifier &&
SM.getSpellingLoc(Attr->getLocation()) ==
TouchedIdentifier->location()) {
LocateASTReferentMetric.record(1, "method-to-base");
// We may be overridding multiple methods - offer them all.
for (const NamedDecl *ND : CMD->overridden_methods())
AddResultDecl(ND);
Expand All @@ -403,6 +408,7 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
if (TouchedIdentifier &&
D->getLocation() == TouchedIdentifier->location()) {
LocateASTReferentMetric.record(1, "template-specialization-to-primary");
AddResultDecl(CTSD->getSpecializedTemplate());
continue;
}
Expand All @@ -418,9 +424,12 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
if (const auto *ID = CD->getClassInterface())
if (TouchedIdentifier &&
(CD->getLocation() == TouchedIdentifier->location() ||
ID->getName() == TouchedIdentifier->text(SM)))
ID->getName() == TouchedIdentifier->text(SM))) {
LocateASTReferentMetric.record(1, "objc-category-to-class");
AddResultDecl(ID);
}

LocateASTReferentMetric.record(1, "regular");
// Otherwise the target declaration is the right one.
AddResultDecl(D);
}
Expand Down
6 changes: 4 additions & 2 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ENUM_CODEGENOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
llvm::DebugCompressionType::None)
CODEGENOPT(RelaxELFRelocations, 1, 0) ///< -Wa,--mrelax-relocations
CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm.
CODEGENOPT(Dwarf64 , 1, 0) ///< -gdwarf64.
CODEGENOPT(Dwarf32 , 1, 1) ///< -gdwarf32.
CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new
CODEGENOPT(Autolink , 1, 1) ///< -fno-autolink
Expand Down Expand Up @@ -366,8 +368,8 @@ VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0)
/// Whether to report the hotness of the code region for optimization remarks.
CODEGENOPT(DiagnosticsWithHotness, 1, 0)

/// Whether copy relocations support is available when building as PIE.
CODEGENOPT(PIECopyRelocations, 1, 0)
/// Whether to use direct access relocations (instead of GOT) to reference external data symbols.
CODEGENOPT(DirectAccessExternalData, 1, 0)

/// Whether we should use the undefined behaviour optimization for control flow
/// paths that reach the end of a function without executing a required return.
Expand Down
16 changes: 12 additions & 4 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,10 @@ def fpic : Flag<["-"], "fpic">, Group<f_Group>;
def fno_pic : Flag<["-"], "fno-pic">, Group<f_Group>;
def fpie : Flag<["-"], "fpie">, Group<f_Group>;
def fno_pie : Flag<["-"], "fno-pie">, Group<f_Group>;
def fdirect_access_external_data : Flag<["-"], "fdirect-access-external-data">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Don't use GOT indirection to reference external data symbols">;
def fno_direct_access_external_data : Flag<["-"], "fno-direct-access-external-data">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Use GOT indirection to reference external data symbols">;
defm plt : BoolFOption<"plt",
"CodeGenOpts.NoPLT", DefaultsToFalse,
ChangedBy<NegFlag, [], "Use GOT indirection instead of PLT to make external function calls (x86 only)">,
Expand Down Expand Up @@ -2574,6 +2578,10 @@ def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 4">;
def gdwarf_5 : Flag<["-"], "gdwarf-5">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 5">;
def gdwarf64 : Flag<["-"], "gdwarf64">, Group<g_Group>, Flags<[CC1Option]>,
HelpText<"Enables DWARF64 format for ELF binaries, if debug information emission is enabled.">;
def gdwarf32 : Flag<["-"], "gdwarf32">, Group<g_Group>, Flags<[CC1Option]>,
HelpText<"Enables DWARF32 format for ELF binaries, if debug information emission is enabled.">;

def gcodeview : Flag<["-"], "gcodeview">,
HelpText<"Generate CodeView debug information">,
Expand Down Expand Up @@ -3147,10 +3155,10 @@ def mstack_protector_guard_offset_EQ : Joined<["-"], "mstack-protector-guard-off
HelpText<"Use the given offset for addressing the stack-protector guard">;
def mstack_protector_guard_reg_EQ : Joined<["-"], "mstack-protector-guard-reg=">, Group<m_Group>, Flags<[CC1Option]>,
HelpText<"Use the given reg for addressing the stack-protector guard">;
defm pie_copy_relocations : BoolOption<"pie-copy-relocations",
"CodeGenOpts.PIECopyRelocations", DefaultsToFalse,
ChangedBy<PosFlag, [CC1Option], "Use copy relocations support for PIE builds">,
ResetBy<NegFlag>, BothFlags<[]>, "m">, Group<m_Group>;
def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">,
Alias<fdirect_access_external_data>, Group<m_Group>;
def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">,
Alias<fno_direct_access_external_data>, Group<m_Group>;
def mfentry : Flag<["-"], "mfentry">, HelpText<"Insert calls to fentry at function entry (x86/SystemZ only)">,
Flags<[CC1Option]>, Group<m_Group>,
MarshallingInfoFlag<"CodeGenOpts.CallFEntry">;
Expand Down
10 changes: 10 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,16 @@ class Sema final {
return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser);
}

/// Get the type of expression E, triggering instantiation to complete the
/// type if necessary -- that is, if the expression refers to a templated
/// static data member of incomplete array type.
///
/// May still return an incomplete type if instantiation was not possible or
/// if the type is incomplete for a different reason. Use
/// RequireCompleteExprType instead if a diagnostic is expected for an
/// incomplete expression type.
QualType getCompletedType(Expr *E);

void completeExprArrayBound(Expr *E);
bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind,
TypeDiagnoser &Diagnoser);
Expand Down
20 changes: 10 additions & 10 deletions clang/lib/APINotes/APINotesTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace clang {
namespace api_notes {
void CommonEntityInfo::dump(llvm::raw_ostream &OS) const {
LLVM_DUMP_METHOD void CommonEntityInfo::dump(llvm::raw_ostream &OS) const {
if (Unavailable)
OS << "[Unavailable] (" << UnavailableMsg << ")" << ' ';
if (UnavailableInSwift)
Expand All @@ -23,7 +23,7 @@ void CommonEntityInfo::dump(llvm::raw_ostream &OS) const {
OS << '\n';
}

void CommonTypeInfo::dump(llvm::raw_ostream &OS) const {
LLVM_DUMP_METHOD void CommonTypeInfo::dump(llvm::raw_ostream &OS) const {
static_cast<const CommonEntityInfo &>(*this).dump(OS);
if (SwiftBridge)
OS << "Swift Briged Type: " << *SwiftBridge << ' ';
Expand All @@ -32,7 +32,7 @@ void CommonTypeInfo::dump(llvm::raw_ostream &OS) const {
OS << '\n';
}

void ObjCContextInfo::dump(llvm::raw_ostream &OS) {
LLVM_DUMP_METHOD void ObjCContextInfo::dump(llvm::raw_ostream &OS) {
static_cast<CommonTypeInfo &>(*this).dump(OS);
if (HasDefaultNullability)
OS << "DefaultNullability: " << DefaultNullability << ' ';
Expand All @@ -45,7 +45,7 @@ void ObjCContextInfo::dump(llvm::raw_ostream &OS) {
OS << '\n';
}

void VariableInfo::dump(llvm::raw_ostream &OS) const {
LLVM_DUMP_METHOD void VariableInfo::dump(llvm::raw_ostream &OS) const {
static_cast<const CommonEntityInfo &>(*this).dump(OS);
if (NullabilityAudited)
OS << "Audited Nullability: " << Nullable << ' ';
Expand All @@ -54,22 +54,22 @@ void VariableInfo::dump(llvm::raw_ostream &OS) const {
OS << '\n';
}

void ObjCPropertyInfo::dump(llvm::raw_ostream &OS) const {
LLVM_DUMP_METHOD void ObjCPropertyInfo::dump(llvm::raw_ostream &OS) const {
static_cast<const VariableInfo &>(*this).dump(OS);
if (SwiftImportAsAccessorsSpecified)
OS << (SwiftImportAsAccessors ? "[SwiftImportAsAccessors] " : "");
OS << '\n';
}

void ParamInfo::dump(llvm::raw_ostream &OS) const {
LLVM_DUMP_METHOD void ParamInfo::dump(llvm::raw_ostream &OS) const {
static_cast<const VariableInfo &>(*this).dump(OS);
if (NoEscapeSpecified)
OS << (NoEscape ? "[NoEscape] " : "");
OS << "RawRetainCountConvention: " << RawRetainCountConvention << ' ';
OS << '\n';
}

void FunctionInfo::dump(llvm::raw_ostream &OS) const {
LLVM_DUMP_METHOD void FunctionInfo::dump(llvm::raw_ostream &OS) const {
static_cast<const CommonEntityInfo &>(*this).dump(OS);
OS << (NullabilityAudited ? "[NullabilityAudited] " : "")
<< "RawRetainCountConvention: " << RawRetainCountConvention << ' ';
Expand All @@ -81,13 +81,13 @@ void FunctionInfo::dump(llvm::raw_ostream &OS) const {
PI.dump(OS);
}

void ObjCMethodInfo::dump(llvm::raw_ostream &OS) {
LLVM_DUMP_METHOD void ObjCMethodInfo::dump(llvm::raw_ostream &OS) {
static_cast<FunctionInfo &>(*this).dump(OS);
OS << (DesignatedInit ? "[DesignatedInit] " : "")
<< (RequiredInit ? "[RequiredInit] " : "") << '\n';
}

void TagInfo::dump(llvm::raw_ostream &OS) {
LLVM_DUMP_METHOD void TagInfo::dump(llvm::raw_ostream &OS) {
static_cast<CommonTypeInfo &>(*this).dump(OS);
if (HasFlagEnum)
OS << (IsFlagEnum ? "[FlagEnum] " : "");
Expand All @@ -97,7 +97,7 @@ void TagInfo::dump(llvm::raw_ostream &OS) {
OS << '\n';
}

void TypedefInfo::dump(llvm::raw_ostream &OS) const {
LLVM_DUMP_METHOD void TypedefInfo::dump(llvm::raw_ostream &OS) const {
static_cast<const CommonTypeInfo &>(*this).dump(OS);
if (SwiftWrapper)
OS << "Swift Type: " << static_cast<long>(*SwiftWrapper) << ' ';
Expand Down
20 changes: 20 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
Options.MCOptions.MCNoWarn = CodeGenOpts.NoWarn;
Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
Options.MCOptions.Dwarf64 = CodeGenOpts.Dwarf64;
Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
Options.MCOptions.ABIName = TargetOpts.ABI;
for (const auto &Entry : HSOpts.UserEntries)
Expand Down Expand Up @@ -1198,6 +1199,25 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
bool IsLTO = CodeGenOpts.PrepareForLTO;

if (LangOpts.ObjCAutoRefCount) {
PB.registerPipelineStartEPCallback(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
if (Level != PassBuilder::OptimizationLevel::O0)
MPM.addPass(
createModuleToFunctionPassAdaptor(ObjCARCExpandPass()));
});
PB.registerPipelineEarlySimplificationEPCallback(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
if (Level != PassBuilder::OptimizationLevel::O0)
MPM.addPass(ObjCARCAPElimPass());
});
PB.registerScalarOptimizerLateEPCallback(
[](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
if (Level != PassBuilder::OptimizationLevel::O0)
FPM.addPass(ObjCARCOptPass());
});
}

// If we reached here with a non-empty index file name, then the index
// file was empty and we are not performing ThinLTO backend compilation
// (used in testing in a distributed build environment). Drop any the type
Expand Down
47 changes: 23 additions & 24 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,26 @@ Optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
}

llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
if (!Loc.isValid())
// If Location is not valid then use main input file.
return TheCU->getFile();

SourceManager &SM = CGM.getContext().getSourceManager();
PresumedLoc PLoc = SM.getPresumedLoc(Loc);

StringRef FileName = PLoc.getFilename();
if (PLoc.isInvalid() || FileName.empty())
// If the location is not valid then use main input file.
return TheCU->getFile();
StringRef FileName;
FileID FID;

if (Loc.isInvalid()) {
// The DIFile used by the CU is distinct from the main source file. Call
// createFile() below for canonicalization if the source file was specified
// with an absolute path.
FileName = TheCU->getFile()->getFilename();
} else {
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
FileName = PLoc.getFilename();

if (FileName.empty()) {
FileName = TheCU->getFile()->getFilename();
} else {
FileName = PLoc.getFilename();
}
FID = PLoc.getFileID();
}

// Cache the results.
auto It = DIFileCache.find(FileName.data());
Expand All @@ -426,11 +435,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {

SmallString<32> Checksum;

// Compute the checksum if possible. If the location is affected by a #line
// directive that refers to a file, PLoc will have an invalid FileID, and we
// will correctly get no checksum.
Optional<llvm::DIFile::ChecksumKind> CSKind =
computeChecksum(PLoc.getFileID(), Checksum);
Optional<llvm::DIFile::ChecksumKind> CSKind = computeChecksum(FID, Checksum);
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
if (CSKind)
CSInfo.emplace(*CSKind, Checksum);
Expand Down Expand Up @@ -2399,7 +2404,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
// its members. Finally, we create a descriptor for the complete type (which
// may refer to the forward decl if the struct is recursive) and replace all
// uses of the forward declaration with the final definition.
llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty, DefUnit);
llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty);

const RecordDecl *D = RD->getDefinition();
if (!D || !D->isCompleteDefinition())
Expand Down Expand Up @@ -3127,10 +3132,6 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) {
}

llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {

// Unwrap the type as needed for debug information.
Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext());

auto It = TypeCache.find(Ty.getAsOpaquePtr());
if (It != TypeCache.end()) {
// Verify that the debug info still exists.
Expand All @@ -3143,8 +3144,6 @@ llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {

void CGDebugInfo::completeTemplateDefinition(
const ClassTemplateSpecializationDecl &SD) {
if (DebugKind <= codegenoptions::DebugLineTablesOnly)
return;
completeUnusedClass(SD);
}

Expand Down Expand Up @@ -3306,8 +3305,8 @@ llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
llvm_unreachable("type should have been unwrapped!");
}

llvm::DICompositeType *CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty,
llvm::DIFile *Unit) {
llvm::DICompositeType *
CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty) {
QualType QTy(Ty, 0);

auto *T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/CodeGen/CGDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,7 @@ class CGDebugInfo {

/// Get the type from the cache or create a new partial type if
/// necessary.
llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty,
llvm::DIFile *F);
llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty);

/// Create type metadata for a source language type.
llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
Expand Down
28 changes: 19 additions & 9 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,17 +983,27 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
if (TT.isPPC64())
return false;

// If we can use copy relocations we can assume it is local.
if (auto *Var = dyn_cast<llvm::GlobalVariable>(GV))
if (!Var->isThreadLocal() &&
(RM == llvm::Reloc::Static || CGOpts.PIECopyRelocations))
if (CGOpts.DirectAccessExternalData) {
// If -fdirect-access-external-data (default for -fno-pic), set dso_local
// for non-thread-local variables. If the symbol is not defined in the
// executable, a copy relocation will be needed at link time. dso_local is
// excluded for thread-local variables because they generally don't support
// copy relocations.
if (auto *Var = dyn_cast<llvm::GlobalVariable>(GV))
if (!Var->isThreadLocal())
return true;

// -fno-pic sets dso_local on a function declaration to allow direct
// accesses when taking its address (similar to a data symbol). If the
// function is not defined in the executable, a canonical PLT entry will be
// needed at link time. -fno-direct-access-external-data can avoid the
// canonical PLT entry. We don't generalize this condition to -fpie/-fpic as
// it could just cause trouble without providing perceptible benefits.
if (isa<llvm::Function>(GV) && !CGOpts.NoPLT && RM == llvm::Reloc::Static)
return true;
}

// If we can use a plt entry as the symbol address we can assume it
// is local.
// FIXME: This should work for PIE, but the gold linker doesn't support it.
if (isa<llvm::Function>(GV) && !CGOpts.NoPLT && RM == llvm::Reloc::Static)
return true;
// If we can use copy relocations we can assume it is local.

// Otherwise don't assume it is local.
return false;
Expand Down
Loading

0 comments on commit 1510cc0

Please sign in to comment.