Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (intel#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
bader committed Dec 11, 2019
2 parents 95b732d + d77ae15 commit 140a28d
Show file tree
Hide file tree
Showing 27 changed files with 219 additions and 21 deletions.
5 changes: 5 additions & 0 deletions clang/include/clang/AST/ASTConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class ASTConsumer {
/// modified by the introduction of an implicit zero initializer.
virtual void CompleteTentativeDefinition(VarDecl *D) {}

/// CompleteExternalDeclaration - Callback invoked at the end of a translation
/// unit to notify the consumer that the given external declaration should be
/// completed.
virtual void CompleteExternalDeclaration(VarDecl *D) {}

/// Callback invoked when an MSInheritanceAttr has been attached to a
/// CXXRecordDecl.
virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,9 @@ class TargetInfo : public virtual TransferrableTargetInfo,

virtual void setAuxTarget(const TargetInfo *Aux) {}

/// Whether target allows debuginfo types for decl only variables.
virtual bool allowDebugInfoForExternalVar() const { return false; }

protected:
/// Copy type and layout related info.
void copyAuxTarget(const TargetInfo *Aux);
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@ class Sema final {
/// All the tentative definitions encountered in the TU.
TentativeDefinitionsType TentativeDefinitions;

/// All the external declarations encoutered and used in the TU.
SmallVector<VarDecl *, 4> ExternalDeclarations;

typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
&ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
UnusedFileScopedDeclsType;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
return None;
}

bool allowDebugInfoForExternalVar() const override { return true; }

CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
switch (CC) {
default:
Expand Down
23 changes: 21 additions & 2 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4482,7 +4482,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,

GVE = DBuilder.createGlobalVariableExpression(
DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
Var->hasLocalLinkage(),
Var->hasLocalLinkage(), true,
Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
Align);
Expand Down Expand Up @@ -4585,10 +4585,29 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {

GV.reset(DBuilder.createGlobalVariableExpression(
DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
true, true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
TemplateParameters, Align));
}

void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
const VarDecl *D) {
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
if (D->hasAttr<NoDebugAttr>())
return;

auto Align = getDeclAlignIfRequired(D, CGM.getContext());
llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
StringRef Name = D->getName();
llvm::DIType *Ty = getOrCreateType(D->getType(), Unit);

llvm::DIScope *DContext = getDeclContextDescriptor(D);
llvm::DIGlobalVariableExpression *GVE =
DBuilder.createGlobalVariableExpression(
DContext, Name, StringRef(), Unit, getLineNumber(D->getLocation()),
Ty, false, false, nullptr, nullptr, nullptr, Align);
Var->addDebugInfo(GVE);
}

llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
if (!LexicalBlockStack.empty())
return LexicalBlockStack.back();
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/CGDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ class CGDebugInfo {
/// Emit a constant global variable's debug info.
void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);

/// Emit information about an external variable.
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);

/// Emit C++ using directive.
void EmitUsingDirective(const UsingDirectiveDecl &UD);

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ namespace clang {
Gen->CompleteTentativeDefinition(D);
}

void CompleteExternalDeclaration(VarDecl *D) override {
Gen->CompleteExternalDeclaration(D);
}

void AssignInheritanceModel(CXXRecordDecl *RD) override {
Gen->AssignInheritanceModel(RD);
}
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3755,6 +3755,10 @@ void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) {
EmitGlobalVarDefinition(D);
}

void CodeGenModule::EmitExternalDeclaration(const VarDecl *D) {
EmitExternalVarDeclaration(D);
}

CharUnits CodeGenModule::GetTargetTypeStoreSize(llvm::Type *Ty) const {
return Context.toCharUnitsFromBits(
getDataLayout().getTypeStoreSizeInBits(Ty));
Expand Down Expand Up @@ -4271,6 +4275,19 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
DI->EmitGlobalVariable(GV, D);
}

void CodeGenModule::EmitExternalVarDeclaration(const VarDecl *D) {
if (CGDebugInfo *DI = getModuleDebugInfo())
if (getCodeGenOpts().getDebugInfo() >= codegenoptions::LimitedDebugInfo) {
QualType ASTTy = D->getType();
llvm::Type *Ty = getTypes().ConvertTypeForMem(D->getType());
llvm::PointerType *PTy =
llvm::PointerType::get(Ty, getContext().getTargetAddressSpace(ASTTy));
llvm::Constant *GV = GetOrCreateLLVMGlobal(D->getName(), PTy, D);
DI->EmitExternalVariable(
cast<llvm::GlobalVariable>(GV->stripPointerCasts()), D);
}
}

static bool isVarDeclStrongDefinition(const ASTContext &Context,
CodeGenModule &CGM, const VarDecl *D,
bool NoCommon) {
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,8 @@ class CodeGenModule : public CodeGenTypeCache {

void EmitTentativeDefinition(const VarDecl *D);

void EmitExternalDeclaration(const VarDecl *D);

void EmitVTable(CXXRecordDecl *Class);

void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
Expand Down Expand Up @@ -1413,6 +1415,7 @@ class CodeGenModule : public CodeGenTypeCache {
void EmitMultiVersionFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);

void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
void EmitExternalVarDeclaration(const VarDecl *D);
void EmitAliasDefinition(GlobalDecl GD);
void emitIFuncDefinition(GlobalDecl GD);
void emitCPUDispatchDefinition(GlobalDecl GD);
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/ModuleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ namespace {
Builder->EmitTentativeDefinition(D);
}

void CompleteExternalDeclaration(VarDecl *D) override {
Builder->EmitExternalDeclaration(D);
}

void HandleVTable(CXXRecordDecl *RD) override {
if (Diags.hasErrorOccurred())
return;
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,13 @@ void Sema::ActOnEndOfTranslationUnit() {
Consumer.CompleteTentativeDefinition(VD);
}

for (auto D : ExternalDeclarations) {
if (!D || D->isInvalidDecl() || D->getPreviousDecl() || !D->isUsed())
continue;

Consumer.CompleteExternalDeclaration(D);
}

// If there were errors, disable 'unused' warnings since they will mostly be
// noise. Don't warn for a use from a module: either we should warn on all
// file-scope declarations in modules or not at all, but whether the
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12203,6 +12203,10 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
Diag(Var->getLocation(), diag::note_private_extern);
}

if (Context.getTargetInfo().allowDebugInfoForExternalVar() &&
!Var->isInvalidDecl() && !getLangOpts().CPlusPlus)
ExternalDeclarations.push_back(Var);

return;

case VarDecl::TentativeDefinition:
Expand Down
27 changes: 27 additions & 0 deletions clang/test/CodeGen/debug-info-extern-basic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// REQUIRES: bpf-registered-target
// RUN: %clang -target bpf -emit-llvm -S -g %s -o - | FileCheck %s

extern char ch;
int test() {
return ch;
}

int test2() {
extern char ch2;
return ch2;
}

extern int (*foo)(int);
int test3() {
return foo(0);
}

// CHECK: distinct !DIGlobalVariable(name: "ch",{{.*}} type: ![[CHART:[0-9]+]], isLocal: false, isDefinition: false
// CHECK: distinct !DIGlobalVariable(name: "ch2",{{.*}} type: ![[CHART]], isLocal: false, isDefinition: false
// CHECK: ![[CHART]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)

// CHECK: distinct !DIGlobalVariable(name: "foo",{{.*}} type: ![[FUNC:[0-9]+]], isLocal: false, isDefinition: false)
// CHECK: ![[FUNC]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[SUB:[0-9]+]], size: 64)
// CHECK: ![[SUB]] = !DISubroutineType(types: ![[TYPES:[0-9]+]])
// CHECK: ![[TYPES]] = !{![[BASET:[0-9]+]], ![[BASET]]}
// CHECK: ![[BASET]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
11 changes: 11 additions & 0 deletions clang/test/CodeGen/debug-info-extern-duplicate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// REQUIRES: bpf-registered-target
// RUN: %clang -target bpf -emit-llvm -S -g %s -o - | FileCheck %s

extern char ch;
extern char ch;
int test() {
return ch;
}

// CHECK: distinct !DIGlobalVariable(name: "ch",{{.*}} type: ![[T:[0-9]+]], isLocal: false, isDefinition: false
// CHECK-NOT: distinct !DIGlobalVariable(name: "ch"
23 changes: 23 additions & 0 deletions clang/test/CodeGen/debug-info-extern-multi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// REQUIRES: bpf-registered-target
// RUN: %clang -target bpf -emit-llvm -S -g %s -o - | FileCheck %s

extern char ch;
int test() {
extern short sh;
return ch + sh;
}

extern char (*foo)(char);
int test2() {
return foo(0) + ch;
}

// CHECK: distinct !DIGlobalVariable(name: "ch",{{.*}} type: ![[Tch:[0-9]+]], isLocal: false, isDefinition: false
// CHECK: distinct !DIGlobalVariable(name: "sh",{{.*}} type: ![[Tsh:[0-9]+]], isLocal: false, isDefinition: false
// CHECK: ![[Tsh]] = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)

// CHECK: distinct !DIGlobalVariable(name: "foo",{{.*}} type: ![[Tptr:[0-9]+]], isLocal: false, isDefinition: false
// ![[Tptr]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[Tsub:[0-9]+]], size: 64)
// ![[Tsub]] = !DISubroutineType(types: ![[Tproto:[0-9]+]])
// ![[Tproto]] = !{![[Tch]], ![[Tch]]}
// CHECK: ![[Tch]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
27 changes: 27 additions & 0 deletions clang/test/CodeGen/debug-info-extern-unused.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// REQUIRES: bpf-registered-target
// RUN: %clang -target bpf -emit-llvm -S -g %s -o - | FileCheck %s

extern char ch;
int test() {
return 0;
}

int test2() {
extern char ch2;
return 0;
}

extern int (*foo)(int);
int test3() {
return 0;
}

int test4() {
extern int (*foo2)(int);
return 0;
}

// CHECK-NOT: distinct !DIGlobalVariable(name: "ch"
// CHECK-NOT: distinct !DIGlobalVariable(name: "ch2"
// CHECK-NOT: distinct !DIGlobalVariable(name: "foo"
// CHECK-NOT: distinct !DIGlobalVariable(name: "foo2"
4 changes: 3 additions & 1 deletion compiler-rt/lib/scudo/standalone/checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ bool hasHardwareCRC32() {
__get_cpuid(1, &Eax, &Ebx, &Ecx, &Edx);
return !!(Ecx & bit_SSE4_2);
}

#elif defined(__arm__) || defined(__aarch64__)
#ifndef AT_HWCAP
#define AT_HWCAP 16
Expand All @@ -65,6 +64,9 @@ bool hasHardwareCRC32() {
return !!(getauxval(AT_HWCAP) & HWCAP_CRC32);
#endif // SCUDO_FUCHSIA
}
#else
// No hardware CRC32 implemented in Scudo for other architectures.
bool hasHardwareCRC32() { return false; }
#endif // defined(__x86_64__) || defined(__i386__)

} // namespace scudo
7 changes: 4 additions & 3 deletions llvm-spirv/lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
SPIRVCopyMemorySized *BC = static_cast<SPIRVCopyMemorySized *>(BV);
CallInst *CI = nullptr;
llvm::Value *Dst = transValue(BC->getTarget(), F, BB);
Align Alignment = Align(BC->getAlignment());
unsigned Align = BC->getAlignment();
llvm::Value *Size = transValue(BC->getSize(), F, BB);
bool IsVolatile = BC->SPIRVMemoryAccess::isVolatile();
IRBuilder<> Builder(BB);
Expand All @@ -1545,14 +1545,15 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
NewDst = llvm::BitCastInst::CreatePointerCast(Dst, Int8PointerTy,
"", BB);
}
CI = Builder.CreateMemSet(NewDst, Src, Size, Alignment, IsVolatile);
CI = Builder.CreateMemSet(NewDst, Src, Size, MaybeAlign(Align),
IsVolatile);
}
}
}
}
if (!CI) {
llvm::Value *Src = transValue(BC->getSource(), F, BB);
CI = Builder.CreateMemCpy(Dst, BC->getAlignment(), Src, BC->getAlignment(), Size, IsVolatile);
CI = Builder.CreateMemCpy(Dst, Align, Src, Align, Size, IsVolatile);
}
if (isFuncNoUnwind())
CI->getFunction()->addFnAttr(Attribute::NoUnwind);
Expand Down
6 changes: 3 additions & 3 deletions llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ MDNode *SPIRVToLLVMDbgTran::transGlobalVariable(const SPIRVExtInst *DebugInst) {
bool IsDefinition = Ops[FlagsIdx] & SPIRVDebug::FlagIsDefinition;
MDNode *VarDecl = nullptr;
if (IsDefinition) {
VarDecl = Builder.createGlobalVariableExpression(Parent, Name, LinkageName,
File, LineNo, Ty, IsLocal,
nullptr, StaticMemberDecl);
VarDecl = Builder.createGlobalVariableExpression(
Parent, Name, LinkageName, File, LineNo, Ty, IsLocal, IsDefinition,
nullptr, StaticMemberDecl);
} else {
VarDecl = Builder.createTempGlobalVariableFwdDecl(
Parent, Name, LinkageName, File, LineNo, Ty, IsLocal, StaticMemberDecl);
Expand Down
6 changes: 4 additions & 2 deletions llvm/docs/Vectorizers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,10 @@ into vector operations.
.. code-block:: c++

void foo(int a1, int a2, int b1, int b2, int *A) {
A[0] = a1*(a1 + b1)/b1 + 50*b1/a1;
A[1] = a2*(a2 + b2)/b2 + 50*b2/a2;
A[0] = a1*(a1 + b1);
A[1] = a2*(a2 + b2);
A[2] = a1*(a1 + b1);
A[3] = a2*(a2 + b2);
}

The SLP-vectorizer processes the code bottom-up, across basic blocks, in search of scalars to combine.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ namespace llvm {
/// specified)
DIGlobalVariableExpression *createGlobalVariableExpression(
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
unsigned LineNo, DIType *Ty, bool isLocalToUnit,
unsigned LineNo, DIType *Ty, bool isLocalToUnit, bool isDefined = true,
DIExpression *Expr = nullptr, MDNode *Decl = nullptr,
MDTuple *templateParams = nullptr, uint32_t AlignInBits = 0);

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/IR/DIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,14 @@ static void checkGlobalVariableScope(DIScope *Context) {

DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression(
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr,
unsigned LineNumber, DIType *Ty, bool isLocalToUnit,
bool isDefined, DIExpression *Expr,
MDNode *Decl, MDTuple *templateParams, uint32_t AlignInBits) {
checkGlobalVariableScope(Context);

auto *GV = DIGlobalVariable::getDistinct(
VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl),
LineNumber, Ty, isLocalToUnit, isDefined, cast_or_null<DIDerivedType>(Decl),
templateParams, AlignInBits);
if (!Expr)
Expr = createExpression();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression(
return wrap(unwrap(Builder)->createGlobalVariableExpression(
unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen},
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
true, unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
nullptr, AlignInBits));
}

Expand Down
Loading

0 comments on commit 140a28d

Please sign in to comment.