Skip to content

Commit

Permalink
Merged master:ac3e720dc1af into amd-gfx:58d3a7df8949
Browse files Browse the repository at this point in the history
Local branch amd-gfx 58d3a7d Disable selection of S_ADD_CO_PSEUDO and S_SUB_CO_PSEUDO
Remote branch master ac3e720 Make clang HIP headers compatible with C++98
  • Loading branch information
Sw authored and Sw committed Aug 7, 2020
2 parents 58d3a7d + ac3e720 commit 1074414
Show file tree
Hide file tree
Showing 66 changed files with 3,472 additions and 257 deletions.
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10353,6 +10353,10 @@ def err_omp_allocator_used_in_clauses : Error<
"data-sharing or data-mapping attribute clauses">;
def err_omp_allocator_not_in_uses_allocators : Error<
"allocator must be specified in the 'uses_allocators' clause">;
def note_omp_protected_structured_block
: Note<"jump bypasses OpenMP structured block">;
def note_omp_exits_structured_block
: Note<"jump exits scope of OpenMP structured block">;
} // end of OpenMP category

let CategoryName = "Related Result Type Issue" in {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/StmtPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S,
}
OS << NL;
if (!ForceNoStmt && S->hasAssociatedStmt())
PrintStmt(S->getInnermostCapturedStmt()->getCapturedStmt());
PrintStmt(S->getRawStmt());
}

void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
Expand Down
15 changes: 7 additions & 8 deletions clang/lib/Analysis/CFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4913,14 +4913,13 @@ CFGBlock *CFGBuilder::VisitOMPExecutableDirective(OMPExecutableDirective *D,
B = R;
}
// Visit associated structured block if any.
if (!D->isStandaloneDirective())
if (CapturedStmt *CS = D->getInnermostCapturedStmt()) {
Stmt *S = CS->getCapturedStmt();
if (!isa<CompoundStmt>(S))
addLocalScopeAndDtors(S);
if (CFGBlock *R = addStmt(S))
B = R;
}
if (!D->isStandaloneDirective()) {
Stmt *S = D->getRawStmt();
if (!isa<CompoundStmt>(S))
addLocalScopeAndDtors(S);
if (CFGBlock *R = addStmt(S))
B = R;
}

return B;
}
Expand Down
56 changes: 26 additions & 30 deletions clang/lib/CodeGen/CGStmtOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3554,12 +3554,9 @@ void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) {
}

void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &S) {
auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &) {
CGF.EmitStmt(S.getInnermostCapturedStmt()->getCapturedStmt());
};
OMPLexicalScope Scope(*this, S, OMPD_unknown);
CGM.getOpenMPRuntime().emitInlinedDirective(*this, OMPD_section, CodeGen,
S.hasCancel());
LexicalScope Scope(*this, S.getSourceRange());
EmitStopPoint(&S);
EmitStmt(S.getAssociatedStmt());
}

void CodeGenFunction::EmitOMPSingleDirective(const OMPSingleDirective &S) {
Expand Down Expand Up @@ -3610,7 +3607,7 @@ void CodeGenFunction::EmitOMPSingleDirective(const OMPSingleDirective &S) {
static void emitMaster(CodeGenFunction &CGF, const OMPExecutableDirective &S) {
auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
Action.Enter(CGF);
CGF.EmitStmt(S.getInnermostCapturedStmt()->getCapturedStmt());
CGF.EmitStmt(S.getRawStmt());
};
CGF.CGM.getOpenMPRuntime().emitMasterRegion(CGF, CodeGen, S.getBeginLoc());
}
Expand All @@ -3620,8 +3617,7 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;

const CapturedStmt *CS = S.getInnermostCapturedStmt();
const Stmt *MasterRegionBodyStmt = CS->getCapturedStmt();
const Stmt *MasterRegionBodyStmt = S.getAssociatedStmt();

auto FiniCB = [this](InsertPointTy IP) {
OMPBuilderCBHelpers::FinalizeOMPRegion(*this, IP);
Expand All @@ -3635,13 +3631,14 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
CodeGenIP, FiniBB);
};

CGCapturedStmtInfo CGSI(*CS, CR_OpenMP);
CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(*this, &CGSI);
LexicalScope Scope(*this, S.getSourceRange());
EmitStopPoint(&S);
Builder.restoreIP(OMPBuilder.CreateMaster(Builder, BodyGenCB, FiniCB));

return;
}
OMPLexicalScope Scope(*this, S, OMPD_unknown);
LexicalScope Scope(*this, S.getSourceRange());
EmitStopPoint(&S);
emitMaster(*this, S);
}

Expand All @@ -3650,8 +3647,7 @@ void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) {
llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;

const CapturedStmt *CS = S.getInnermostCapturedStmt();
const Stmt *CriticalRegionBodyStmt = CS->getCapturedStmt();
const Stmt *CriticalRegionBodyStmt = S.getAssociatedStmt();
const Expr *Hint = nullptr;
if (const auto *HintClause = S.getSingleClause<OMPHintClause>())
Hint = HintClause->getHint();
Expand All @@ -3676,8 +3672,8 @@ void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) {
CodeGenIP, FiniBB);
};

CGCapturedStmtInfo CGSI(*CS, CR_OpenMP);
CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(*this, &CGSI);
LexicalScope Scope(*this, S.getSourceRange());
EmitStopPoint(&S);
Builder.restoreIP(OMPBuilder.CreateCritical(
Builder, BodyGenCB, FiniCB, S.getDirectiveName().getAsString(),
HintInst));
Expand All @@ -3687,12 +3683,13 @@ void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) {

auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
Action.Enter(CGF);
CGF.EmitStmt(S.getInnermostCapturedStmt()->getCapturedStmt());
CGF.EmitStmt(S.getAssociatedStmt());
};
const Expr *Hint = nullptr;
if (const auto *HintClause = S.getSingleClause<OMPHintClause>())
Hint = HintClause->getHint();
OMPLexicalScope Scope(*this, S, OMPD_unknown);
LexicalScope Scope(*this, S.getSourceRange());
EmitStopPoint(&S);
CGM.getOpenMPRuntime().emitCriticalRegion(*this,
S.getDirectiveName().getAsString(),
CodeGen, S.getBeginLoc(), Hint);
Expand Down Expand Up @@ -5368,17 +5365,11 @@ void CodeGenFunction::EmitOMPAtomicDirective(const OMPAtomicDirective &S) {
}
}

const Stmt *CS = S.getInnermostCapturedStmt()->IgnoreContainers();

auto &&CodeGen = [&S, Kind, AO, CS](CodeGenFunction &CGF,
PrePostActionTy &) {
CGF.EmitStopPoint(CS);
emitOMPAtomicExpr(CGF, Kind, AO, S.isPostfixUpdate(), S.getX(), S.getV(),
S.getExpr(), S.getUpdateExpr(), S.isXLHSInRHSPart(),
S.getBeginLoc());
};
OMPLexicalScope Scope(*this, S, OMPD_unknown);
CGM.getOpenMPRuntime().emitInlinedDirective(*this, OMPD_atomic, CodeGen);
LexicalScope Scope(*this, S.getSourceRange());
EmitStopPoint(S.getAssociatedStmt());
emitOMPAtomicExpr(*this, Kind, AO, S.isPostfixUpdate(), S.getX(), S.getV(),
S.getExpr(), S.getUpdateExpr(), S.isXLHSInRHSPart(),
S.getBeginLoc());
}

static void emitCommonOMPTargetDirective(CodeGenFunction &CGF,
Expand Down Expand Up @@ -6631,7 +6622,12 @@ void CodeGenFunction::EmitSimpleOMPExecutableDirective(
CGF.EmitStmt(D.getInnermostCapturedStmt()->getCapturedStmt());
}
};
{
if (D.getDirectiveKind() == OMPD_atomic ||
D.getDirectiveKind() == OMPD_critical ||
D.getDirectiveKind() == OMPD_section ||
D.getDirectiveKind() == OMPD_master) {
EmitStmt(D.getAssociatedStmt());
} else {
auto LPCRegion =
CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, D);
OMPSimdLexicalScope Scope(*this, D);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Headers/__clang_hip_libdevice_declares.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ __device__ __attribute__((pure)) __2f16 __ocml_log2_2f16(__2f16);
__device__ inline __2f16
__llvm_amdgcn_rcp_2f16(__2f16 __x) // Not currently exposed by ROCDL.
{
return (__2f16){__llvm_amdgcn_rcp_f16(__x.x), __llvm_amdgcn_rcp_f16(__x.y)};
return (__2f16)(__llvm_amdgcn_rcp_f16(__x.x), __llvm_amdgcn_rcp_f16(__x.y));
}
__device__ __attribute__((const)) __2f16 __ocml_rint_2f16(__2f16);
__device__ __attribute__((const)) __2f16 __ocml_rsqrt_2f16(__2f16);
Expand Down
36 changes: 32 additions & 4 deletions clang/lib/Headers/__clang_hip_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <limits.h>
#include <limits>
#include <stdint.h>
#include <assert.h>

#pragma push_macro("__DEVICE__")
#pragma push_macro("__RETURN_TYPE")
Expand All @@ -22,6 +23,34 @@
#define __DEVICE__ static __device__
#define __RETURN_TYPE bool

#if defined (__cplusplus) && __cplusplus < 201103L
//emulate static_assert on type sizes
template<bool>
struct __compare_result{};
template<>
struct __compare_result<true> {
static const bool valid;
};

__DEVICE__
inline void __suppress_unused_warning(bool b) {};
template<unsigned int S, unsigned int T>
__DEVICE__
inline void __static_assert_equal_size() {
__suppress_unused_warning(__compare_result<S==T>::valid);
}

#define __static_assert_type_size_equal(A, B) \
__static_assert_equal_size<A,B>()

#else

#define __static_assert_type_size_equal(A,B) \
static_assert((A) == (B), "")

#endif


__DEVICE__
inline uint64_t __make_mantissa_base8(const char *__tagp) {
uint64_t __r = 0;
Expand Down Expand Up @@ -252,9 +281,8 @@ inline float nanf(const char *__tagp) {
uint32_t exponent : 8;
uint32_t sign : 1;
} bits;

static_assert(sizeof(float) == sizeof(struct ieee_float), "");
} __tmp;
__static_assert_type_size_equal(sizeof(__tmp.val), sizeof(__tmp.bits));

__tmp.bits.sign = 0u;
__tmp.bits.exponent = ~0u;
Expand Down Expand Up @@ -716,8 +744,8 @@ inline double nan(const char *__tagp) {
uint32_t exponent : 11;
uint32_t sign : 1;
} bits;
static_assert(sizeof(double) == sizeof(struct ieee_double), "");
} __tmp;
__static_assert_type_size_equal(sizeof(__tmp.val), sizeof(__tmp.bits));

__tmp.bits.sign = 0u;
__tmp.bits.exponent = ~0u;
Expand All @@ -726,7 +754,7 @@ inline double nan(const char *__tagp) {

return __tmp.val;
#else
static_assert(sizeof(uint64_t) == sizeof(double));
__static_assert_type_size_equal(sizeof(uint64_t), sizeof(double));
uint64_t val = __make_mantissa(__tagp);
val |= 0xFFF << 51;
return *reinterpret_cast<double *>(&val);
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Headers/__clang_hip_runtime_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#define __shared__ __attribute__((shared))
#define __constant__ __attribute__((constant))

#if !defined(__cplusplus) || __cplusplus < 201103L
#define nullptr NULL;
#endif

#if __HIP_ENABLE_DEVICE_MALLOC__
extern "C" __device__ void *__hip_malloc(size_t __size);
extern "C" __device__ void *__hip_free(void *__ptr);
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/Sema/JumpDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtObjC.h"
#include "clang/AST/StmtOpenMP.h"
#include "llvm/ADT/BitVector.h"
using namespace clang;

Expand Down Expand Up @@ -580,6 +581,17 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
break;

default:
if (auto *ED = dyn_cast<OMPExecutableDirective>(S)) {
if (!ED->isStandaloneDirective()) {
unsigned NewParentScope = Scopes.size();
Scopes.emplace_back(ParentScope,
diag::note_omp_protected_structured_block,
diag::note_omp_exits_structured_block,
ED->getStructuredBlock()->getBeginLoc());
BuildScopeInformation(ED->getStructuredBlock(), NewParentScope);
return;
}
}
break;
}

Expand Down Expand Up @@ -904,6 +916,11 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
S.Diag(From->getBeginLoc(), diag::warn_jump_out_of_seh_finally);
break;
}
if (Scopes[I].InDiag == diag::note_omp_protected_structured_block) {
S.Diag(From->getBeginLoc(), diag::err_goto_into_protected_scope);
S.Diag(To->getBeginLoc(), diag::note_omp_exits_structured_block);
break;
}
}
}

Expand Down
Loading

0 comments on commit 1074414

Please sign in to comment.