Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (triSYCL#24)
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
abhinavgaba committed Jun 6, 2020
2 parents 50a1d2e + 0d4e243 commit f148720
Show file tree
Hide file tree
Showing 111 changed files with 2,993 additions and 3,470 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def err_drv_no_cuda_libdevice : Error<

def err_drv_no_rocm_installation : Error<
"cannot find ROCm installation. Provide its path via --rocm-path, or pass "
"-nogpulib and -nogpuinc to build without ROCm device library and HIP includes.">;
"-nogpulib.">;
def err_drv_no_rocm_device_lib : Error<
"cannot find device library for %0. Provide path to different ROCm installation "
"via --rocm-path, or pass -nogpulib to build without linking default libraries.">;
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10811,6 +10811,14 @@ def err_matrix_separate_incomplete_index: Error<
def err_matrix_subscript_comma: Error<
"comma expressions are not allowed as indices in matrix subscript expressions">;

def warn_mismatched_import : Warning<
"import %select{module|name}0 (%1) does not match the import %select{module|name}0 (%2) of the "
"previous declaration">,
InGroup<IgnoredAttributes>;
def warn_import_on_definition : Warning<
"import %select{module|name}0 cannot be applied to a function with a definition">,
InGroup<IgnoredAttributes>;

// SYCL-specific diagnostics
def err_sycl_kernel_incorrectly_named : Error<
"kernel %select{name is missing"
Expand Down
3 changes: 1 addition & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2697,8 +2697,7 @@ def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group<pedantic_Group>;
def no__dead__strip__inits__and__terms : Flag<["-"], "no_dead_strip_inits_and_terms">;
def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, CoreOption]>,
HelpText<"Disable builtin #include directories">;
def nogpuinc : Flag<["-"], "nogpuinc">;
def : Flag<["-"], "nocudainc">, Alias<nogpuinc>;
def nocudainc : Flag<["-"], "nocudainc">;
def nogpulib : Flag<["-"], "nogpulib">,
HelpText<"Do not link device library for CUDA/HIP device compilation">;
def : Flag<["-"], "nocudalib">, Alias<nogpulib>;
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,10 +632,6 @@ class ToolChain {
virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;

/// Add arguments to use system-specific HIP includes.
virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;

/// Add arguments to use MCU GCC toolchain includes.
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,10 @@ class Sema final {
const InternalLinkageAttr &AL);
CommonAttr *mergeCommonAttr(Decl *D, const ParsedAttr &AL);
CommonAttr *mergeCommonAttr(Decl *D, const CommonAttr &AL);
WebAssemblyImportNameAttr *mergeImportNameAttr(
Decl *D, const WebAssemblyImportNameAttr &AL);
WebAssemblyImportModuleAttr *mergeImportModuleAttr(
Decl *D, const WebAssemblyImportModuleAttr &AL);

void mergeDeclAttributes(NamedDecl *New, Decl *Old,
AvailabilityMergeKind AMK = AMK_Redeclaration);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4985,7 +4985,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
// Add metadata for calls to MSAllocator functions
if (getDebugInfo() && TargetDecl &&
TargetDecl->hasAttr<MSAllocatorAttr>())
getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);
getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);

// 4. Finish the call.

Expand Down
12 changes: 5 additions & 7 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2146,16 +2146,14 @@ llvm::DIType *CGDebugInfo::getOrCreateStandaloneType(QualType D,
return T;
}

void CGDebugInfo::addHeapAllocSiteMetadata(llvm::Instruction *CI,
QualType D,
void CGDebugInfo::addHeapAllocSiteMetadata(llvm::CallBase *CI,
QualType AllocatedTy,
SourceLocation Loc) {
llvm::MDNode *node;
if (D.getTypePtr()->isVoidPointerType()) {
if (AllocatedTy->isVoidType())
node = llvm::MDNode::get(CGM.getLLVMContext(), None);
} else {
QualType PointeeTy = D.getTypePtr()->getPointeeType();
node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
}
else
node = getOrCreateType(AllocatedTy, getOrCreateFile(Loc));

CI->setMetadata("heapallocsite", node);
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class CGDebugInfo {
llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);

/// Add heapallocsite metadata for MSAllocator calls.
void addHeapAllocSiteMetadata(llvm::Instruction *CallSite, QualType Ty,
void addHeapAllocSiteMetadata(llvm::CallBase *CallSite, QualType AllocatedTy,
SourceLocation Loc);

void completeType(const EnumDecl *ED);
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/CodeGen/CGExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,13 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
RValue RV =
EmitNewDeleteCall(*this, allocator, allocatorType, allocatorArgs);

// Set !heapallocsite metadata on the call to operator new.
if (getDebugInfo()) {
if (auto *newCall = dyn_cast<llvm::CallBase>(RV.getScalarVal()))
getDebugInfo()->addHeapAllocSiteMetadata(newCall, allocType,
E->getExprLoc());
}

// If this was a call to a global replaceable allocation function that does
// not take an alignment argument, the allocator is known to produce
// storage that's suitably aligned for any object that fits, up to a known
Expand Down
14 changes: 9 additions & 5 deletions clang/lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2081,11 +2081,15 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
}
}

// Update heapallocsite metadata when there is an explicit cast.
if (llvm::CallInst *CI = dyn_cast<llvm::CallInst>(Src))
if (CI->getMetadata("heapallocsite") && isa<ExplicitCastExpr>(CE))
CGF.getDebugInfo()->
addHeapAllocSiteMetadata(CI, CE->getType(), CE->getExprLoc());
// Update heapallocsite metadata when there is an explicit pointer cast.
if (auto *CI = dyn_cast<llvm::CallBase>(Src)) {
if (CI->getMetadata("heapallocsite") && isa<ExplicitCastExpr>(CE)) {
QualType PointeeType = DestTy->getPointeeType();
if (!PointeeType.isNull())
CGF.getDebugInfo()->addHeapAllocSiteMetadata(CI, PointeeType,
CE->getExprLoc());
}
}

if (NeedAddrspaceCast) {
llvm::Type *SrcPointeeTy = Src->getType()->getPointerElementType();
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,6 @@ SanitizerMask ToolChain::getSupportedSanitizers() const {
void ToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {}

void ToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {}

void ToolChain::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {}

Expand Down
34 changes: 0 additions & 34 deletions clang/lib/Driver/ToolChains/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,40 +199,6 @@ void RocmInstallationDetector::print(raw_ostream &OS) const {
OS << "Found ROCm installation: " << InstallPath << '\n';
}

void RocmInstallationDetector::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
// HIP header includes standard library wrapper headers under clang
// cuda_wrappers directory. Since these wrapper headers include_next
// standard C++ headers, whereas libc++ headers include_next other clang
// headers. The include paths have to follow this order:
// - wrapper include path
// - standard C++ include path
// - other clang include path
// Since standard C++ and other clang include paths are added in other
// places after this function, here we only need to make sure wrapper
// include path is added.
SmallString<128> P(D.ResourceDir);
llvm::sys::path::append(P, "include");
llvm::sys::path::append(P, "cuda_wrappers");
CC1Args.push_back("-internal-isystem");
CC1Args.push_back(DriverArgs.MakeArgString(P));
CC1Args.push_back("-include");
CC1Args.push_back("__clang_hip_runtime_wrapper.h");
}

if (DriverArgs.hasArg(options::OPT_nogpuinc))
return;

if (!isValid()) {
D.Diag(diag::err_drv_no_rocm_installation);
return;
}

CC1Args.push_back("-internal-isystem");
CC1Args.push_back(DriverArgs.MakeArgString(getIncludePath()));
}

void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
Expand Down
143 changes: 142 additions & 1 deletion clang/lib/Driver/ToolChains/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H

#include "Gnu.h"
#include "ROCm.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
Expand All @@ -22,6 +21,148 @@
namespace clang {
namespace driver {

/// A class to find a viable ROCM installation
/// TODO: Generalize to handle libclc.
class RocmInstallationDetector {
private:
struct ConditionalLibrary {
SmallString<0> On;
SmallString<0> Off;

bool isValid() const {
return !On.empty() && !Off.empty();
}

StringRef get(bool Enabled) const {
assert(isValid());
return Enabled ? On : Off;
}
};

const Driver &D;
bool IsValid = false;
//RocmVersion Version = RocmVersion::UNKNOWN;
SmallString<0> InstallPath;
//SmallString<0> BinPath;
SmallString<0> LibPath;
SmallString<0> LibDevicePath;
SmallString<0> IncludePath;
llvm::StringMap<std::string> LibDeviceMap;

// Libraries that are always linked.
SmallString<0> OCML;
SmallString<0> OCKL;

// Libraries that are always linked depending on the language
SmallString<0> OpenCL;
SmallString<0> HIP;

// Libraries swapped based on compile flags.
ConditionalLibrary WavefrontSize64;
ConditionalLibrary FiniteOnly;
ConditionalLibrary UnsafeMath;
ConditionalLibrary DenormalsAreZero;
ConditionalLibrary CorrectlyRoundedSqrt;

bool allGenericLibsValid() const {
return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&
WavefrontSize64.isValid() && FiniteOnly.isValid() &&
UnsafeMath.isValid() && DenormalsAreZero.isValid() &&
CorrectlyRoundedSqrt.isValid();
}

// CUDA architectures for which we have raised an error in
// CheckRocmVersionSupportsArch.
mutable llvm::SmallSet<CudaArch, 4> ArchsWithBadVersion;

void scanLibDevicePath();

public:
RocmInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
const llvm::opt::ArgList &Args);

/// Add arguments needed to link default bitcode libraries.
void addCommonBitcodeLibCC1Args(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
StringRef LibDeviceFile, bool Wave64,
bool DAZ, bool FiniteOnly, bool UnsafeMathOpt,
bool FastRelaxedMath, bool CorrectSqrt) const;

/// Emit an error if Version does not support the given Arch.
///
/// If either Version or Arch is unknown, does not emit an error. Emits at
/// most one error per Arch.
void CheckRocmVersionSupportsArch(CudaArch Arch) const;

/// Check whether we detected a valid Rocm install.
bool isValid() const { return IsValid; }
/// Print information about the detected CUDA installation.
void print(raw_ostream &OS) const;

/// Get the detected Rocm install's version.
// RocmVersion version() const { return Version; }

/// Get the detected Rocm installation path.
StringRef getInstallPath() const { return InstallPath; }

/// Get the detected path to Rocm's bin directory.
// StringRef getBinPath() const { return BinPath; }

/// Get the detected Rocm Include path.
StringRef getIncludePath() const { return IncludePath; }

/// Get the detected Rocm library path.
StringRef getLibPath() const { return LibPath; }

/// Get the detected Rocm device library path.
StringRef getLibDevicePath() const { return LibDevicePath; }

StringRef getOCMLPath() const {
assert(!OCML.empty());
return OCML;
}

StringRef getOCKLPath() const {
assert(!OCKL.empty());
return OCKL;
}

StringRef getOpenCLPath() const {
assert(!OpenCL.empty());
return OpenCL;
}

StringRef getHIPPath() const {
assert(!HIP.empty());
return HIP;
}

StringRef getWavefrontSize64Path(bool Enabled) const {
return WavefrontSize64.get(Enabled);
}

StringRef getFiniteOnlyPath(bool Enabled) const {
return FiniteOnly.get(Enabled);
}

StringRef getUnsafeMathPath(bool Enabled) const {
return UnsafeMath.get(Enabled);
}

StringRef getDenormalsAreZeroPath(bool Enabled) const {
return DenormalsAreZero.get(Enabled);
}

StringRef getCorrectlyRoundedSqrtPath(bool Enabled) const {
return CorrectlyRoundedSqrt.get(Enabled);
}

/// Get libdevice file for given architecture
std::string getLibDeviceFile(StringRef Gpu) const {
return LibDeviceMap.lookup(Gpu);
}
};

namespace tools {
namespace amdgpu {

Expand Down
10 changes: 4 additions & 6 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,14 +1222,12 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
Args.AddLastArg(CmdArgs, options::OPT_MP);
Args.AddLastArg(CmdArgs, options::OPT_MV);

// Add offload include arguments specific for CUDA/HIP. This must happen
// before we -I or -include anything else, because we must pick up the
// CUDA/HIP headers from the particular CUDA/ROCm installation, rather than
// from e.g. /usr/local/include.
// Add offload include arguments specific for CUDA. This must happen before
// we -I or -include anything else, because we must pick up the CUDA headers
// from the particular CUDA installation, rather than from e.g.
// /usr/local/include.
if (JA.isOffloading(Action::OFK_Cuda))
getToolChain().AddCudaIncludeArgs(Args, CmdArgs);
if (JA.isOffloading(Action::OFK_HIP))
getToolChain().AddHIPIncludeArgs(Args, CmdArgs);

if (JA.isOffloading(Action::OFK_SYCL) ||
Args.hasArg(options::OPT_fsycl_device_only))
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void CudaInstallationDetector::AddCudaIncludeArgs(
CC1Args.push_back(DriverArgs.MakeArgString(P));
}

if (DriverArgs.hasArg(options::OPT_nogpuinc))
if (DriverArgs.hasArg(options::OPT_nocudainc))
return;

if (!isValid()) {
Expand Down Expand Up @@ -813,7 +813,7 @@ void CudaToolChain::adjustDebugInfoKind(
void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// Check our CUDA version if we're going to include the CUDA headers.
if (!DriverArgs.hasArg(options::OPT_nogpuinc) &&
if (!DriverArgs.hasArg(options::OPT_nocudainc) &&
!DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
assert(!Arch.empty() && "Must have an explicit GPU arch.");
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,7 @@ bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: ToolChain(D, Triple, Args), GCCInstallation(D),
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args) {
CudaInstallation(D, Triple, Args) {
getProgramPaths().push_back(getDriver().getInstalledDir());
if (getDriver().getInstalledDir() != getDriver().Dir)
getProgramPaths().push_back(getDriver().Dir);
Expand Down
Loading

0 comments on commit f148720

Please sign in to comment.