Skip to content

Commit

Permalink
Merge from 'sycl' to 'sycl-web' (intel#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
iclsrc committed Mar 8, 2020
2 parents b93fda8 + 2ddf04e commit 1644cc6
Show file tree
Hide file tree
Showing 108 changed files with 2,440 additions and 1,356 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/gh_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ jobs:
with:
ref: sycl
path: repo
- uses: actions/checkout@v2
with:
repository: intel/llvm-docs
path: docs
- name: Install deps
run: sudo apt-get install -y doxygen graphviz ssh ninja-build
- name: Build Docs
Expand All @@ -34,6 +30,7 @@ jobs:
chmod 600 ~/.ssh/id_rsa
eval "$(ssh-agent -s)"
ssh-add -k ~/.ssh/id_rsa
git clone [email protected]:intel/llvm-docs.git docs
cd $GITHUB_WORKSPACE/docs
yes | \cp -rf $GITHUB_WORKSPACE/build/tools/sycl/doc/doxygen/html/* .
git config --global user.name "iclsrc"
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ def warn_drv_treating_input_as_cxx : Warning<
InGroup<Deprecated>;
def warn_drv_pch_not_first_include : Warning<
"precompiled header '%0' was ignored because '%1' is not first '-include'">;
def warn_drv_existing_archive_append: Warning<
"appending to an existing archive '%0'">, InGroup<DiagGroup<"archive-append">>;
def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
InGroup<DiagGroup<"missing-sysroot">>;
def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting '%1'">,
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Types.def
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ TYPE("wholearchive", WholeArchive, INVALID, "a", phases
TYPE("fpga_aocx", FPGA_AOCX, INVALID, "aocx", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("fpga_aocr", FPGA_AOCR, INVALID, "aocr", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("fpga_aoco", FPGA_AOCO, INVALID, "aoco", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("fpga_dependencies", FPGA_Dependencies, INVALID, "d", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("none", Nothing, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGSYCLRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool Util::matchQualifiedTypeName(const CXXRecordDecl *RecTy,
// (namespace) and name.
if (!RecTy)
return false; // only classes/structs supported
const auto *Ctx = dyn_cast<DeclContext>(RecTy);
const auto *Ctx = cast<DeclContext>(RecTy);
StringRef Name = "";

for (const auto &Scope : llvm::reverse(Scopes)) {
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/SYCLLowerIR/LowerWGScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,14 +662,14 @@ static void fixupPrivateMemoryPFWILambdaCaptures(CallInst *PFWICall) {
// now rewrite the captured addresss of a private_memory variables within the
// PFWI lambda object:
for (auto &C : PrivMemCaptures) {
GetElementPtrInst *NewGEP = dyn_cast<GetElementPtrInst>(C.second->clone());
GetElementPtrInst *NewGEP = cast<GetElementPtrInst>(C.second->clone());
NewGEP->insertBefore(PFWICall);
IRBuilder<> Bld(PFWICall->getContext());
Bld.SetInsertPoint(PFWICall);
Value *Val = C.first;
auto ValAS = dyn_cast<PointerType>(Val->getType())->getAddressSpace();
auto PtrAS = dyn_cast<PointerType>(NewGEP->getResultElementType())
->getAddressSpace();
auto ValAS = cast<PointerType>(Val->getType())->getAddressSpace();
auto PtrAS =
cast<PointerType>(NewGEP->getResultElementType())->getAddressSpace();

if (ValAS != PtrAS)
Val = Bld.CreateAddrSpaceCast(Val, NewGEP->getResultElementType());
Expand Down
49 changes: 38 additions & 11 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3253,6 +3253,9 @@ class OffloadingActionBuilder final {
/// Type of output file for FPGA device compilation.
types::ID FPGAOutType = types::TY_FPGA_AOCX;

/// List of objects to extract FPGA dependency info from
ActionList FPGAObjectInputs;

/// List of CUDA architectures to use in this compilation with NVPTX targets.
SmallVector<CudaArch, 8> GpuArchList;

Expand Down Expand Up @@ -3417,8 +3420,12 @@ class OffloadingActionBuilder final {
// Check if the type of the file is the same as the action. Do not
// unbundle it if it is not. Do not unbundle .so files, for example,
// which are not object files.
if (IA->getType() == types::TY_Object && !isObjectFile(FileName))
return ABRT_Inactive;
if (IA->getType() == types::TY_Object) {
if (!isObjectFile(FileName))
return ABRT_Inactive;
if (Args.hasArg(options::OPT_fintelfpga))
FPGAObjectInputs.push_back(IA);
}
// When creating FPGA device fat objects, all host objects are
// partially linked. Gather that list here.
if (IA->getType() == types::TY_Object ||
Expand Down Expand Up @@ -3598,6 +3605,15 @@ class OffloadingActionBuilder final {
Action *DeviceBECompileAction;
ActionList BEActionList;
BEActionList.push_back(DeviceLinkAction);
for (Action *A : FPGAObjectInputs) {
// Send any known objects through the unbundler to grab the
// dependency file associated.
ActionList AL;
AL.push_back(A);
Action *UnbundleAction = C.MakeAction<OffloadUnbundlingJobAction>(
AL, types::TY_FPGA_Dependencies);
BEActionList.push_back(UnbundleAction);
}
for (const auto &A : DeviceLibObjects)
BEActionList.push_back(A);
DeviceBECompileAction =
Expand Down Expand Up @@ -4462,8 +4478,8 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
IA->getInputArg().getOption().hasFlag(options::LinkerInput))
// Pass the Input along to linker only.
continue;
UnbundlerInputs.push_back(LI);
}
UnbundlerInputs.push_back(LI);
}
const Arg *LastArg;
auto addUnbundlerInput = [&](types::ID T, const Arg *A) {
Expand Down Expand Up @@ -5484,14 +5500,25 @@ InputInfo Driver::BuildJobsForActionNoCache(
DependentOffloadKind)}] =
CurI;
}

// Now that we have all the results generated, select the one that should be
// returned for the current depending action.
std::pair<const Action *, std::string> ActionTC = {
A, GetTriplePlusArchString(TC, BoundArch, TargetDeviceOffloadKind)};
assert(CachedResults.find(ActionTC) != CachedResults.end() &&
"Result does not exist??");
Result = CachedResults[ActionTC];
// Do a check for a dependency file unbundle for FPGA. This is out of line
// from a regular unbundle, so just create and return the name of the
// unbundled file.
if (JA->getType() == types::TY_FPGA_Dependencies) {
std::string TmpFileName =
C.getDriver().GetTemporaryPath(llvm::sys::path::stem(BaseInput), "d");
const char *TmpFile =
C.addTempFile(C.getArgs().MakeArgString(TmpFileName));
Result = InputInfo(types::TY_FPGA_Dependencies, TmpFile, TmpFile);
UnbundlingResults.push_back(Result);
} else {
// Now that we have all the results generated, select the one that should
// be returned for the current depending action.
std::pair<const Action *, std::string> ActionTC = {
A, GetTriplePlusArchString(TC, BoundArch, TargetDeviceOffloadKind)};
assert(CachedResults.find(ActionTC) != CachedResults.end() &&
"Result does not exist??");
Result = CachedResults[ActionTC];
}
} else if (JA->getType() == types::TY_Nothing)
Result = InputInfo(A, BaseInput);
else {
Expand Down
68 changes: 57 additions & 11 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
} else if (!ArgMD) {
DepFile = "-";
} else if (ArgMD->getOption().matches(options::OPT_MMD) &&
Args.hasArg(options::OPT_fintelfpga)) {
Args.hasArg(options::OPT_fintelfpga) &&
!Args.hasArg(options::OPT_c)) {
// When generating dependency files for FPGA AOT, the output files will
// always be named after the source file.
DepFile = Args.MakeArgString(Twine(getBaseInputStem(Args, Inputs)) + ".d");
Expand Down Expand Up @@ -3944,10 +3945,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Check number of inputs for sanity. We need at least one input.
assert(Inputs.size() >= 1 && "Must have at least one input.");
// CUDA/HIP compilation may have multiple inputs (source file + results of
// device-side compilations). OpenMP and SYCL device jobs also take the host
// IR as a second input. Module precompilation accepts a list of header files
// to include as part of the module. All other jobs are expected to have
// exactly one input.
// device-side compilations).
// OpenMP device jobs take the host IR as a second input.
// SYCL host jobs accept the integration header from the device-side
// compilation as a second input.
// Module precompilation accepts a list of header files to include as part
// of the module.
// All other jobs are expected to have exactly one input.
bool IsCuda = JA.isOffloading(Action::OFK_Cuda);
bool IsHIP = JA.isOffloading(Action::OFK_HIP);
bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
Expand Down Expand Up @@ -4742,6 +4746,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// `--gpu-use-aux-triple-only` is specified.
if (!Args.getLastArg(options::OPT_gpu_use_aux_triple_only) &&
((IsCuda && JA.isDeviceOffloading(Action::OFK_Cuda)) ||
(IsSYCL && IsSYCLOffloadDevice) ||
(IsHIP && JA.isDeviceOffloading(Action::OFK_HIP)))) {
const ArgList &HostArgs =
C.getArgsForToolChain(nullptr, StringRef(), Action::OFK_None);
Expand Down Expand Up @@ -6782,7 +6787,8 @@ const char *Clang::getDependencyFileName(const ArgList &Args,
const InputInfoList &Inputs) {
// FIXME: Think about this more.

if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
if (Arg *OutputOpt =
Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo)) {
SmallString<128> OutputFilename(OutputOpt->getValue());
llvm::sys::path::replace_extension(OutputFilename, llvm::Twine('d'));
return Args.MakeArgString(OutputFilename);
Expand Down Expand Up @@ -7094,6 +7100,20 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
Triples += CurDep->getOffloadingArch();
}
}
bool IsFPGADepBundle = (TCArgs.hasArg(options::OPT_fintelfpga) &&
Output.getType() == types::TY_Object);
// For -fintelfpga, when bundling objects we also want to bundle up the
// named dependency file.
// TODO - We are currently using the target triple inputs to slot a location
// of the dependency information into the bundle. It would be good to
// separate this out to an explicit option in the bundler for the dependency
// file as it does not match the type being bundled.
if (IsFPGADepBundle) {
Triples += ',';
Triples += Action::GetOffloadKindName(Action::OFK_SYCL);
Triples += '-';
Triples += llvm::Triple::getArchTypeName(llvm::Triple::fpga_dep);
}
CmdArgs.push_back(TCArgs.MakeArgString(Triples));

// Get bundled file command.
Expand All @@ -7118,6 +7138,14 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
}
UB += CurTC->getInputFilename(Inputs[I]);
}
// For -fintelfpga, when bundling objects we also want to bundle up the
// named dependency file.
if (IsFPGADepBundle) {
SmallString<128> CurOutput(Output.getFilename());
llvm::sys::path::replace_extension(CurOutput, "d");
UB += ',';
UB += CurOutput;
}
CmdArgs.push_back(TCArgs.MakeArgString(UB));

// All the inputs are encoded as commands.
Expand Down Expand Up @@ -7148,6 +7176,7 @@ void OffloadBundler::ConstructJobMultipleOutputs(
bool IsMSVCEnv =
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
types::ID InputType(Input.getType());
bool IsFPGADepUnbundle = (JA.getType() == types::TY_FPGA_Dependencies);

// For Linux, we have initial support for fat archives (archives which
// contain bundled objects). We will perform partial linking against the
Expand Down Expand Up @@ -7207,6 +7236,8 @@ void OffloadBundler::ConstructJobMultipleOutputs(
if (InputType == types::TY_FPGA_AOCO ||
(IsMSVCEnv && types::isArchive(InputType)))
TypeArg = "aoo";
if (IsFPGADepUnbundle)
TypeArg = "o";

// Get the type.
CmdArgs.push_back(TCArgs.MakeArgString(Twine("-type=") + TypeArg));
Expand Down Expand Up @@ -7262,7 +7293,15 @@ void OffloadBundler::ConstructJobMultipleOutputs(
Triples += Dep.DependentBoundArch;
}
}

if (IsFPGADepUnbundle) {
// TODO - We are currently using the target triple inputs to slot a location
// of the dependency information into the bundle. It would be good to
// separate this out to an explicit option in the bundler for the dependency
// file as it does not match the type being bundled.
Triples += Action::GetOffloadKindName(Action::OFK_SYCL);
Triples += '-';
Triples += llvm::Triple::getArchTypeName(llvm::Triple::fpga_dep);
}
CmdArgs.push_back(TCArgs.MakeArgString(Triples));

// Get bundled file command.
Expand All @@ -7272,10 +7311,17 @@ void OffloadBundler::ConstructJobMultipleOutputs(
// Get unbundled files command.
SmallString<128> UB;
UB += "-outputs=";
for (unsigned I = 0; I < Outputs.size(); ++I) {
if (I)
UB += ',';
UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
// When dealing with -fintelfpga, there is an additional unbundle step
// that occurs for the dependency file. In that case, do not use the
// dependent information, but just the output file.
if (IsFPGADepUnbundle)
UB += Outputs[0].getFilename();
else {
for (unsigned I = 0; I < Outputs.size(); ++I) {
if (I)
UB += ',';
UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
}
}
CmdArgs.push_back(TCArgs.MakeArgString(UB));
CmdArgs.push_back("-unbundle");
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,12 @@ void tools::gnutools::Linker::constructLLVMARCommand(
const InputInfoList &Input, const ArgList &Args) const {
ArgStringList CmdArgs;
CmdArgs.push_back("cr");
CmdArgs.push_back(Output.getFilename());
const char *OutputFilename = Output.getFilename();
if (llvm::sys::fs::exists(OutputFilename)) {
C.getDriver().Diag(clang::diag::warn_drv_existing_archive_append)
<< OutputFilename;
}
CmdArgs.push_back(OutputFilename);
for (const auto &II : Input) {
if (II.getType() == types::TY_Tempfilelist) {
// Take the list file and pass it in with '@'.
Expand Down
7 changes: 4 additions & 3 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void SYCL::fpga::BackendCompiler::ConstructJob(Compilation &C,
"Unsupported target");

InputInfoList ForeachInputs;
InputInfoList FPGADepFiles;
ArgStringList CmdArgs{"-o", Output.getFilename()};
for (const auto &II : Inputs) {
std::string Filename(II.getFilename());
Expand All @@ -217,6 +218,8 @@ void SYCL::fpga::BackendCompiler::ConstructJob(Compilation &C,
// Add any FPGA library lists. These come in as special tempfile lists.
CmdArgs.push_back(Args.MakeArgString(Twine("-library-list=") +
Filename));
else if (II.getType() == types::TY_FPGA_Dependencies)
FPGADepFiles.push_back(II);
else
CmdArgs.push_back(C.getArgs().MakeArgString(Filename));
}
Expand All @@ -229,8 +232,6 @@ void SYCL::fpga::BackendCompiler::ConstructJob(Compilation &C,
ForeachExt = "aocr";
}


InputInfoList FPGADepFiles;
for (auto *A : Args) {
// Any input file is assumed to have a dependency file associated
if (A->getOption().getKind() == Option::InputClass) {
Expand All @@ -240,7 +241,7 @@ void SYCL::fpga::BackendCompiler::ConstructJob(Compilation &C,
types::ID Ty = getToolChain().LookupTypeForExtension(Ext.drop_front());
if (Ty == types::TY_INVALID)
continue;
if (types::isSrcFile(Ty) || Ty == types::TY_Object) {
if (types::isSrcFile(Ty)) {
llvm::sys::path::replace_extension(FN, "d");
FPGADepFiles.push_back(InputInfo(types::TY_Dependencies,
Args.MakeArgString(FN), Args.MakeArgString(FN)));
Expand Down
12 changes: 3 additions & 9 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,8 @@ static bool IsSyclMathFunc(unsigned BuiltinID) {
case Builtin::BI__builtin_truncl:
case Builtin::BIlroundl:
case Builtin::BI__builtin_lroundl:
case Builtin::BIceil:
case Builtin::BI__builtin_ceil:
case Builtin::BIcopysign:
case Builtin::BI__builtin_copysign:
case Builtin::BIfabs:
case Builtin::BI__builtin_fabs:
case Builtin::BIfloor:
case Builtin::BI__builtin_floor:
case Builtin::BIfmax:
Expand All @@ -158,12 +154,8 @@ static bool IsSyclMathFunc(unsigned BuiltinID) {
case Builtin::BI__builtin_round:
case Builtin::BItrunc:
case Builtin::BI__builtin_trunc:
case Builtin::BIceilf:
case Builtin::BI__builtin_ceilf:
case Builtin::BIcopysignf:
case Builtin::BI__builtin_copysignf:
case Builtin::BIfabsf:
case Builtin::BI__builtin_fabsf:
case Builtin::BIfloorf:
case Builtin::BI__builtin_floorf:
case Builtin::BIfmaxf:
Expand Down Expand Up @@ -215,6 +207,8 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {

if (FunctionDecl *Callee = e->getDirectCallee()) {
Callee = Callee->getCanonicalDecl();
assert(Callee && "Device function canonical decl must be available");

// Remember that all SYCL kernel functions have deferred
// instantiation as template functions. It means that
// all functions used by kernel have already been parsed and have
Expand Down Expand Up @@ -254,7 +248,7 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
}
// Specifically check if the math library function corresponding to this
// builtin is supported for SYCL
unsigned BuiltinID = (Callee ? Callee->getBuiltinID() : 0);
unsigned BuiltinID = Callee->getBuiltinID();
if (BuiltinID && !IsSyclMathFunc(BuiltinID)) {
StringRef Name = SemaRef.Context.BuiltinInfo.getName(BuiltinID);
SemaRef.Diag(e->getExprLoc(), diag::err_builtin_target_unsupported)
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,12 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
<< ArraySize->getSourceRange();
ASM = ArrayType::Normal;
}

// Zero length arrays are disallowed in SYCL device code.
if (getLangOpts().SYCLIsDevice)
SYCLDiagIfDeviceCode(ArraySize->getBeginLoc(),
diag::err_typecheck_zero_array_size)
<< ArraySize->getSourceRange();
} else if (!T->isDependentType() && !T->isVariablyModifiedType() &&
!T->isIncompleteType() && !T->isUndeducedType()) {
// Is the array too large?
Expand Down
Loading

0 comments on commit 1644cc6

Please sign in to comment.