Skip to content

Commit

Permalink
Merge branch 'release_70' of github.com:flang-compiler/flang-driver i…
Browse files Browse the repository at this point in the history
…nto release_70
  • Loading branch information
schweitzpgi committed Dec 18, 2018
2 parents 73ea9be + 4a9339f commit cc5aa71
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
33 changes: 33 additions & 0 deletions lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,3 +830,36 @@ VersionTuple CudaToolChain::computeMSVCVersion(const Driver *D,
const ArgList &Args) const {
return HostTC.computeMSVCVersion(D, Args);
}

static void AddFlangSysIncludeArg(const ArgList &DriverArgs,
ArgStringList &Flang1Args,
ToolChain::path_list IncludePathList) {
std::string ArgValue; // Path argument value

// Make up argument value consisting of paths separated by colons
bool first = true;
for (auto P : IncludePathList) {
if (first) {
first = false;
} else {
ArgValue += ":";
}
ArgValue += P;
}

// Add the argument
Flang1Args.push_back("-stdinc");
Flang1Args.push_back(DriverArgs.MakeArgString(ArgValue));
}

void CudaToolChain::AddFlangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &Flang1Args) const {
path_list IncludePathList;
const Driver &D = getDriver();
if (DriverArgs.hasArg(options::OPT_nostdinc))
return;
SmallString<128> P(D.InstalledDir);
llvm::sys::path::append(P, "../include");
IncludePathList.push_back(P.str());
AddFlangSysIncludeArg(DriverArgs, Flang1Args, IncludePathList);
}
3 changes: 3 additions & 0 deletions lib/Driver/ToolChains/Cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class LLVM_LIBRARY_VISIBILITY CudaToolChain : public ToolChain {
const ToolChain &HostTC;
CudaInstallationDetector CudaInstallation;

void
AddFlangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &Flang1Args) const override;
protected:
Tool *buildAssembler() const override; // ptxas
Tool *buildLinker() const override; // fatbinary (ok, not really a linker)
Expand Down
64 changes: 63 additions & 1 deletion lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,23 @@ void FlangFrontend::ConstructJob(Compilation &C, const JobAction &JA,
UpperCmdArgs.push_back("-output");
UpperCmdArgs.push_back(ILMFile);

SmallString<256> Path;
if(Args.getAllArgValues(options::OPT_fopenmp_targets_EQ).size() > 0) {
SmallString<128> TargetInfo;
Path = llvm::sys::path::parent_path(Output.getFilename());
Arg* Tgts = Args.getLastArg(options::OPT_fopenmp_targets_EQ);
assert(Tgts && Tgts->getNumValues() &&
"OpenMP offloading has to have targets specified.");
for (unsigned i = 0; i < Tgts->getNumValues(); ++i) {
if (i)
TargetInfo += ',';
llvm::Triple T(Tgts->getValue(i));
TargetInfo += T.getTriple();
}
UpperCmdArgs.push_back("-fopenmp-targets");
UpperCmdArgs.push_back(Args.MakeArgString(TargetInfo.str()));
}

C.addCommand(llvm::make_unique<Command>(JA, *this, UpperExec, UpperCmdArgs, Inputs));

// For -fsyntax-only or -E that is it
Expand Down Expand Up @@ -899,7 +916,52 @@ void FlangFrontend::ConstructJob(Compilation &C, const JobAction &JA,
LowerCmdArgs.push_back("-stbfile");
LowerCmdArgs.push_back(STBFile);

LowerCmdArgs.push_back("-asm"); LowerCmdArgs.push_back(Args.MakeArgString(OutFile));
Path = llvm::sys::path::parent_path(Output.getFilename());
bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);

/* OpenMP GPU Offload */
if(Args.getAllArgValues(options::OPT_fopenmp_targets_EQ).size() > 0) {
SmallString<128> TargetInfo;//("-fopenmp-targets ");
SmallString<256> TargetInfoAsm;//("-fopenmp-targets-asm ");

Arg* Tgts = Args.getLastArg(options::OPT_fopenmp_targets_EQ);
assert(Tgts && Tgts->getNumValues() &&
"OpenMP offloading has to have targets specified.");
for (unsigned i = 0; i < Tgts->getNumValues(); ++i) {
if (i)
TargetInfo += ',';
// We need to get the string from the triple because it may be not exactly
// the same as the one we get directly from the arguments.
llvm::Triple T(Tgts->getValue(i));
TargetInfo += T.getTriple();
// We also need to give a output file
TargetInfoAsm += Path;
TargetInfoAsm += "/";
TargetInfoAsm += Stem;
TargetInfoAsm += "-";
TargetInfoAsm += T.getTriple();
TargetInfoAsm += ".ll";
}
// The driver is aware that flang2 can generate multiple files at the same time.
// We mimic it here by exchanging the output files.
// The driver always uses the output file of -asm.
LowerCmdArgs.push_back("-fopenmp-targets");
LowerCmdArgs.push_back(Args.MakeArgString(TargetInfo.str()));
if(IsOpenMPDevice) {
LowerCmdArgs.push_back("-fopenmp-targets-asm");
LowerCmdArgs.push_back(Args.MakeArgString(OutFile));
LowerCmdArgs.push_back("-asm");
LowerCmdArgs.push_back(Args.MakeArgString(TargetInfoAsm.str()));
} else {
LowerCmdArgs.push_back("-fopenmp-targets-asm");
LowerCmdArgs.push_back(Args.MakeArgString(TargetInfoAsm.str()));
LowerCmdArgs.push_back("-asm");
LowerCmdArgs.push_back(Args.MakeArgString(OutFile));
}
} else {
LowerCmdArgs.push_back("-asm");
LowerCmdArgs.push_back(Args.MakeArgString(OutFile));
}

C.addCommand(llvm::make_unique<Command>(JA, *this, LowerExec, LowerCmdArgs, Inputs));
}
Expand Down
2 changes: 2 additions & 0 deletions tools/clang-offload-bundler/ClangOffloadBundler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ static FileHandler *CreateFileHandler(MemoryBuffer &FirstInput) {
return new TextFileHandler(/*Comment=*/"//");
if (FilesType == "ll")
return new TextFileHandler(/*Comment=*/";");
if (FilesType == "f95")
return new TextFileHandler(/*Comment=*/"!");
if (FilesType == "bc")
return new BinaryFileHandler();
if (FilesType == "s")
Expand Down

0 comments on commit cc5aa71

Please sign in to comment.