Skip to content

Commit

Permalink
Merge pull request #39 from grypp/release_60
Browse files Browse the repository at this point in the history
OpenMP Offload Toolchain is integrated into Flang.
  • Loading branch information
sscalpone authored Oct 12, 2018
2 parents dd75873 + b7c9cb2 commit f90d905
Show file tree
Hide file tree
Showing 4 changed files with 100 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 @@ -670,3 +670,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);
}
4 changes: 4 additions & 0 deletions lib/Driver/ToolChains/Cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ 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
62 changes: 61 additions & 1 deletion lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ void FlangFrontend::ConstructJob(Compilation &C, const JobAction &JA,
ArgStringList UpperCmdArgs;
ArgStringList LowerCmdArgs;
SmallString<256> Stem;
SmallString<256> Path;
std::string OutFile;
bool NeedIEEE = false;
bool NeedFastMath = false;
bool NeedRelaxedMath = false;

bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);

// Check number of inputs for sanity. We need at least one input.
assert(Inputs.size() >= 1 && "Must have at least one input.");

Expand Down Expand Up @@ -792,6 +795,22 @@ void FlangFrontend::ConstructJob(Compilation &C, const JobAction &JA,
UpperCmdArgs.push_back("-output");
UpperCmdArgs.push_back(ILMFile);

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 +918,48 @@ 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));

/* OpenMP GPU Offload */
if(Args.getAllArgValues(options::OPT_fopenmp_targets_EQ).size() > 0) {
SmallString<128> TargetInfo;//("-fopenmp-targets ");
SmallString<256> TargetInfoAsm;//("-fopenmp-targets-asm ");
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 += ',';
// We need to get the string from the triple because it may not be 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";
}
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 @@ -743,6 +743,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 f90d905

Please sign in to comment.