Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (intel#38)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticSemaKinds.td
  • Loading branch information
sndmitriev committed Oct 8, 2019
2 parents 2b97380 + 05e4697 commit 8ffa613
Show file tree
Hide file tree
Showing 229 changed files with 7,529 additions and 3,146 deletions.
24 changes: 24 additions & 0 deletions clang/include/clang/Basic/BuiltinsBPF.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===--- BuiltinsBPF.def - BPF Builtin function database --------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the BPF-specific builtin function database. Users of
// this file must define the BUILTIN macro to make use of this information.
//
//===----------------------------------------------------------------------===//

// The format of this database matches clang/Basic/Builtins.def.

#if defined(BUILTIN) && !defined(TARGET_BUILTIN)
# define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
#endif

// Get record field information.
TARGET_BUILTIN(__builtin_preserve_field_info, "Ui.", "t", "")

#undef BUILTIN
#undef TARGET_BUILTIN
9 changes: 9 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,15 @@ def warn_omp_declare_variant_cs_name_expected : Warning<
InGroup<OpenMPClauses>;
def err_omp_declare_variant_item_expected : Error<
"expected %0 in '%1' context selector of '%2' selector set of 'omp declare variant' directive">;
def err_omp_declare_variant_ctx_set_mutiple_use : Error<
"context selector set '%0' is used already in the same 'omp declare variant' directive">;
def note_omp_declare_variant_ctx_set_used_here : Note<
"previously context selector set '%0' used here">;
def err_omp_expected_comma_brace : Error<"expected '}' or ',' after '%0'">;
def err_omp_declare_variant_ctx_mutiple_use : Error<
"context trait selector '%0' is used already in the same '%1' context selector set of 'omp declare variant' directive">;
def note_omp_declare_variant_ctx_used_here : Note<
"previously context trait selector '%0' used here">;
def warn_omp_more_one_device_type_clause : Warning<
"more than one 'device_type' clause is specified">,
InGroup<OpenMPClauses>;
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10015,6 +10015,11 @@ def err_sycl_attibute_cannot_be_applied_here
"|function with a raw pointer return type"
"|function with a raw pointer parameter type}1">;

def err_preserve_field_info_not_field : Error<
"__builtin_preserve_field_info argument %0 not a field access">;
def err_preserve_field_info_not_const: Error<
"__builtin_preserve_field_info argument %0 not a constant">;

def err_bit_cast_non_trivially_copyable : Error<
"__builtin_bit_cast %select{source|destination}0 type must be trivially copyable">;
def err_bit_cast_type_size_mismatch : Error<
Expand Down
10 changes: 10 additions & 0 deletions clang/include/clang/Basic/TargetBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ namespace clang {
};
}

/// BPF builtins
namespace BPF {
enum {
LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
#include "clang/Basic/BuiltinsBPF.def"
LastTSBuiltin
};
}

/// PPC builtins
namespace PPC {
enum {
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -11195,6 +11195,7 @@ class Sema {
bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);

bool CheckAArch64BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
bool CheckHexagonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
bool CheckHexagonBuiltinCpu(unsigned BuiltinID, CallExpr *TheCall);
bool CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall);
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Clang_Basic {
textual header "Basic/BuiltinsAArch64.def"
textual header "Basic/BuiltinsAMDGPU.def"
textual header "Basic/BuiltinsARM.def"
textual header "Basic/BuiltinsBPF.def"
textual header "Basic/Builtins.def"
textual header "Basic/BuiltinsHexagon.def"
textual header "Basic/BuiltinsLe64.def"
Expand Down
12 changes: 12 additions & 0 deletions clang/lib/Basic/Targets/BPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
#include "BPF.h"
#include "Targets.h"
#include "clang/Basic/MacroBuilder.h"
#include "clang/Basic/TargetBuiltins.h"
#include "llvm/ADT/StringRef.h"

using namespace clang;
using namespace clang::targets;

const Builtin::Info BPFTargetInfo::BuiltinInfo[] = {
#define BUILTIN(ID, TYPE, ATTRS) \
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
#include "clang/Basic/BuiltinsBPF.def"
};

void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
Builder.defineMacro("__bpf__");
Expand All @@ -34,3 +41,8 @@ bool BPFTargetInfo::isValidCPUName(StringRef Name) const {
void BPFTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
}

ArrayRef<Builtin::Info> BPFTargetInfo::getTargetBuiltins() const {
return llvm::makeArrayRef(BuiltinInfo, clang::BPF::LastTSBuiltin -
Builtin::FirstTSBuiltin);
}
4 changes: 3 additions & 1 deletion clang/lib/Basic/Targets/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace clang {
namespace targets {

class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
static const Builtin::Info BuiltinInfo[];

public:
BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
: TargetInfo(Triple) {
Expand Down Expand Up @@ -54,7 +56,7 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
Features[Name] = Enabled;
}

ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
ArrayRef<Builtin::Info> getTargetBuiltins() const override;

const char *getClobbers() const override { return ""; }

Expand Down
34 changes: 34 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4246,6 +4246,9 @@ static Value *EmitTargetArchBuiltinExpr(CodeGenFunction *CGF,
case llvm::Triple::aarch64:
case llvm::Triple::aarch64_be:
return CGF->EmitAArch64BuiltinExpr(BuiltinID, E, Arch);
case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
return CGF->EmitBPFBuiltinExpr(BuiltinID, E);
case llvm::Triple::x86:
case llvm::Triple::x86_64:
return CGF->EmitX86BuiltinExpr(BuiltinID, E);
Expand Down Expand Up @@ -9304,6 +9307,37 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
}
}

Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
const CallExpr *E) {
assert(BuiltinID == BPF::BI__builtin_preserve_field_info &&
"unexpected ARM builtin");

const Expr *Arg = E->getArg(0);
bool IsBitField = Arg->IgnoreParens()->getObjectKind() == OK_BitField;

if (!getDebugInfo()) {
CGM.Error(E->getExprLoc(), "using builtin_preserve_field_info() without -g");
return IsBitField ? EmitLValue(Arg).getBitFieldPointer()
: EmitLValue(Arg).getPointer();
}

// Enable underlying preserve_*_access_index() generation.
bool OldIsInPreservedAIRegion = IsInPreservedAIRegion;
IsInPreservedAIRegion = true;
Value *FieldAddr = IsBitField ? EmitLValue(Arg).getBitFieldPointer()
: EmitLValue(Arg).getPointer();
IsInPreservedAIRegion = OldIsInPreservedAIRegion;

ConstantInt *C = cast<ConstantInt>(EmitScalarExpr(E->getArg(1)));
Value *InfoKind = ConstantInt::get(Int64Ty, C->getSExtValue());

// Built the IR for the preserve_field_info intrinsic.
llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getDeclaration(
&CGM.getModule(), llvm::Intrinsic::bpf_preserve_field_info,
{FieldAddr->getType()});
return Builder.CreateCall(FnGetFieldInfo, {FieldAddr, InfoKind});
}

llvm::Value *CodeGenFunction::
BuildVector(ArrayRef<llvm::Value*> Ops) {
assert((Ops.size() & (Ops.size() - 1)) == 0 &&
Expand Down
16 changes: 13 additions & 3 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4000,9 +4000,19 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
const CGBitFieldInfo &Info = RL.getBitFieldInfo(field);
Address Addr = base.getAddress();
unsigned Idx = RL.getLLVMFieldNo(field);
if (Idx != 0)
// For structs, we GEP to the field that the record layout suggests.
Addr = Builder.CreateStructGEP(Addr, Idx, field->getName());
if (!IsInPreservedAIRegion) {
if (Idx != 0)
// For structs, we GEP to the field that the record layout suggests.
Addr = Builder.CreateStructGEP(Addr, Idx, field->getName());
} else {
const RecordDecl *rec = field->getParent();
llvm::DIType *DbgInfo = getDebugInfo()->getOrCreateRecordType(
getContext().getRecordType(rec), rec->getLocation());
Addr = Builder.CreatePreserveStructAccessIndex(Addr, Idx,
getDebugInfoFIndex(rec, field->getFieldIndex()),
DbgInfo);
}

// Get the access type.
llvm::Type *FieldIntTy =
llvm::Type::getIntNTy(getLLVMContext(), Info.StorageSize);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -3760,6 +3760,7 @@ class CodeGenFunction : public CodeGenTypeCache {
llvm::Value *vectorWrapScalar16(llvm::Value *Op);
llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
llvm::Triple::ArchType Arch);
llvm::Value *EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E);

llvm::Value *BuildVector(ArrayRef<llvm::Value*> Ops);
llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3877,7 +3877,8 @@ class OffloadingActionBuilder final {
// the resulting list. Otherwise, just append the device actions. For
// device only compilation, HostAction is a null pointer, therefore only do
// this when HostAction is not a null pointer.
if (CanUseBundler && HostAction && !OffloadAL.empty()) {
if (CanUseBundler && HostAction &&
HostAction->getType() != types::TY_Nothing && !OffloadAL.empty()) {
// Add the host action to the list in order to create the bundling action.
OffloadAL.push_back(HostAction);

Expand Down
52 changes: 40 additions & 12 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ static ExprResult parseContextScore(Parser &P) {
/// 'vendor' '(' [ 'score' '(' <score _expr> ')' ':' ] <vendor> { ',' <vendor> }
/// ')'
static void parseImplementationSelector(
Parser &P, SourceLocation Loc,
Parser &P, SourceLocation Loc, llvm::StringMap<SourceLocation> &UsedCtx,
llvm::function_ref<void(SourceRange,
const Sema::OpenMPDeclareVariantCtsSelectorData &)>
Callback) {
Expand All @@ -832,6 +832,15 @@ static void parseImplementationSelector(
}
SmallString<16> Buffer;
StringRef CtxSelectorName = P.getPreprocessor().getSpelling(Tok, Buffer);
auto Res = UsedCtx.try_emplace(CtxSelectorName, Tok.getLocation());
if (!Res.second) {
// OpenMP 5.0, 2.3.2 Context Selectors, Restrictions.
// Each trait-selector-name can only be specified once.
P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_ctx_mutiple_use)
<< CtxSelectorName << "implementation";
P.Diag(Res.first->getValue(), diag::note_omp_declare_variant_ctx_used_here)
<< CtxSelectorName;
}
OMPDeclareVariantAttr::CtxSelectorType CSKind =
OMPDeclareVariantAttr::CtxUnknown;
(void)OMPDeclareVariantAttr::ConvertStrToCtxSelectorType(CtxSelectorName,
Expand Down Expand Up @@ -892,6 +901,7 @@ bool Parser::parseOpenMPContextSelectors(
llvm::function_ref<void(SourceRange,
const Sema::OpenMPDeclareVariantCtsSelectorData &)>
Callback) {
llvm::StringMap<SourceLocation> UsedCtxSets;
do {
// Parse inner context selector set name.
if (!Tok.is(tok::identifier)) {
Expand All @@ -901,6 +911,16 @@ bool Parser::parseOpenMPContextSelectors(
}
SmallString<16> Buffer;
StringRef CtxSelectorSetName = PP.getSpelling(Tok, Buffer);
auto Res = UsedCtxSets.try_emplace(CtxSelectorSetName, Tok.getLocation());
if (!Res.second) {
// OpenMP 5.0, 2.3.2 Context Selectors, Restrictions.
// Each trait-set-selector-name can only be specified once.
Diag(Tok.getLocation(), diag::err_omp_declare_variant_ctx_set_mutiple_use)
<< CtxSelectorSetName;
Diag(Res.first->getValue(),
diag::note_omp_declare_variant_ctx_set_used_here)
<< CtxSelectorSetName;
}
// Parse '='.
(void)ConsumeToken();
if (Tok.isNot(tok::equal)) {
Expand All @@ -921,17 +941,25 @@ bool Parser::parseOpenMPContextSelectors(
OMPDeclareVariantAttr::CtxSetUnknown;
(void)OMPDeclareVariantAttr::ConvertStrToCtxSelectorSetType(
CtxSelectorSetName, CSSKind);
switch (CSSKind) {
case OMPDeclareVariantAttr::CtxSetImplementation:
parseImplementationSelector(*this, Loc, Callback);
break;
case OMPDeclareVariantAttr::CtxSetUnknown:
// Skip until either '}', ')', or end of directive.
while (!SkipUntil(tok::r_brace, tok::r_paren,
tok::annot_pragma_openmp_end, StopBeforeMatch))
;
break;
}
llvm::StringMap<SourceLocation> UsedCtx;
do {
switch (CSSKind) {
case OMPDeclareVariantAttr::CtxSetImplementation:
parseImplementationSelector(*this, Loc, UsedCtx, Callback);
break;
case OMPDeclareVariantAttr::CtxSetUnknown:
// Skip until either '}', ')', or end of directive.
while (!SkipUntil(tok::r_brace, tok::r_paren,
tok::annot_pragma_openmp_end, StopBeforeMatch))
;
break;
}
const Token PrevTok = Tok;
if (!TryConsumeToken(tok::comma) && Tok.isNot(tok::r_brace))
Diag(Tok, diag::err_omp_expected_comma_brace)
<< (PrevTok.isAnnotation() ? "context selector trait"
: PP.getSpelling(PrevTok));
} while (Tok.is(tok::identifier));
// Parse '}'.
(void)TBr.consumeClose();
}
Expand Down
39 changes: 39 additions & 0 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,11 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
if (CheckAArch64BuiltinFunctionCall(BuiltinID, TheCall))
return ExprError();
break;
case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
if (CheckBPFBuiltinFunctionCall(BuiltinID, TheCall))
return ExprError();
break;
case llvm::Triple::hexagon:
if (CheckHexagonBuiltinFunctionCall(BuiltinID, TheCall))
return ExprError();
Expand Down Expand Up @@ -1950,6 +1955,40 @@ bool Sema::CheckAArch64BuiltinFunctionCall(unsigned BuiltinID,
return SemaBuiltinConstantArgRange(TheCall, i, l, u + l);
}

bool Sema::CheckBPFBuiltinFunctionCall(unsigned BuiltinID,
CallExpr *TheCall) {
assert(BuiltinID == BPF::BI__builtin_preserve_field_info &&
"unexpected ARM builtin");

if (checkArgCount(*this, TheCall, 2))
return true;

// The first argument needs to be a record field access.
// If it is an array element access, we delay decision
// to BPF backend to check whether the access is a
// field access or not.
Expr *Arg = TheCall->getArg(0);
if (Arg->getType()->getAsPlaceholderType() ||
(Arg->IgnoreParens()->getObjectKind() != OK_BitField &&
!dyn_cast<MemberExpr>(Arg->IgnoreParens()) &&
!dyn_cast<ArraySubscriptExpr>(Arg->IgnoreParens()))) {
Diag(Arg->getBeginLoc(), diag::err_preserve_field_info_not_field)
<< 1 << Arg->getSourceRange();
return true;
}

// The second argument needs to be a constant int
llvm::APSInt Value;
if (!TheCall->getArg(1)->isIntegerConstantExpr(Value, Context)) {
Diag(Arg->getBeginLoc(), diag::err_preserve_field_info_not_const)
<< 2 << Arg->getSourceRange();
return true;
}

TheCall->setType(Context.UnsignedIntTy);
return false;
}

bool Sema::CheckHexagonBuiltinCpu(unsigned BuiltinID, CallExpr *TheCall) {
struct BuiltinAndString {
unsigned BuiltinID;
Expand Down
35 changes: 35 additions & 0 deletions clang/test/CodeGen/builtins-bpf-preserve-field-info-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// REQUIRES: bpf-registered-target
// RUN: %clang -target bpf -emit-llvm -S -g %s -o - | FileCheck %s

#define _(x, y) (__builtin_preserve_field_info((x), (y)))

struct s1 {
char a;
char b:2;
};

union u1 {
char a;
char b:2;
};

unsigned unit1(struct s1 *arg) {
return _(arg->a, 10) + _(arg->b, 10);
}
// CHECK: define dso_local i32 @unit1
// CHECK: call i8* @llvm.preserve.struct.access.index.p0i8.p0s_struct.s1s(%struct.s1* %{{[0-9a-z]+}}, i32 0, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S1:[0-9]+]]
// CHECK: call i32 @llvm.bpf.preserve.field.info.p0i8(i8* %{{[0-9a-z]+}}, i64 10), !dbg !{{[0-9]+}}
// CHECK: call i8* @llvm.preserve.struct.access.index.p0i8.p0s_struct.s1s(%struct.s1* %{{[0-9a-z]+}}, i32 1, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S1:[0-9]+]]
// CHECK: call i32 @llvm.bpf.preserve.field.info.p0i8(i8* %{{[0-9a-z]+}}, i64 10), !dbg !{{[0-9]+}}

unsigned unit2(union u1 *arg) {
return _(arg->a, 10) + _(arg->b, 10);
}
// CHECK: define dso_local i32 @unit2
// CHECK: call %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1* %{{[0-9a-z]+}}, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_U1:[0-9]+]]
// CHECK: call i32 @llvm.bpf.preserve.field.info.p0i8(i8* %{{[0-9a-z]+}}, i64 10), !dbg !{{[0-9]+}}
// CHECK: call i8* @llvm.preserve.struct.access.index.p0i8.p0s_union.u1s(%union.u1* %{{[0-9a-z]+}}, i32 0, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_U1:[0-9]+]]
// CHECK: call i32 @llvm.bpf.preserve.field.info.p0i8(i8* %{{[0-9a-z]+}}, i64 10), !dbg !{{[0-9]+}}

// CHECK: ![[STRUCT_S1]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1"
// CHECK: ![[UNION_U1]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1"
Loading

0 comments on commit 8ffa613

Please sign in to comment.