Overwork of the include path handling of the CUDA device compiler.

I replaced copies of the include paths with a pointer to the headerSearchOptions. Now, explicit handling of the include paths is not more necessary. Add include paths, which was declared via argument at start also works.
This commit is contained in:
Simeon Ehrig 2018-03-21 14:01:14 +01:00 committed by sftnight
parent 58d99cf4f9
commit 4882fbe886
3 changed files with 29 additions and 41 deletions

View File

@ -11,6 +11,7 @@
#include "cling/Interpreter/InvocationOptions.h"
#include "cling/Utils/Paths.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Program.h"
@ -23,16 +24,19 @@
namespace cling {
IncrementalCUDADeviceCompiler::IncrementalCUDADeviceCompiler(std::string filePath,
std::string & CudaGpuBinaryFileNames,
cling::InvocationOptions & invocationOptions)
IncrementalCUDADeviceCompiler::IncrementalCUDADeviceCompiler(
std::string filePath,
std::string & CudaGpuBinaryFileNames,
cling::InvocationOptions & invocationOptions,
std::shared_ptr<clang::HeaderSearchOptions> headerSearchOptions)
: m_Counter(0),
m_FilePath(filePath),
m_FatbinFilePath(CudaGpuBinaryFileNames),
// We get for example sm_20 from the cling arguments and have to shrink to
// 20.
m_SMLevel(invocationOptions.CompilerOpts.CUDAGpuArch.empty() ? "20" :
invocationOptions.CompilerOpts.CUDAGpuArch.substr(3) ) {
invocationOptions.CompilerOpts.CUDAGpuArch.substr(3) ),
m_HeaderSearchOptions(headerSearchOptions) {
assert(!CudaGpuBinaryFileNames.empty() && "CudaGpuBinaryFileNames can't be empty");
m_Init = generateHelperFiles();
@ -95,9 +99,11 @@ namespace cling {
return true;
}
void IncrementalCUDADeviceCompiler::addHeaders(llvm::SmallVectorImpl<const char*> & argv){
for(std::string &s : m_Headers){
argv.push_back(s.c_str());
void IncrementalCUDADeviceCompiler::addHeaders(
llvm::SmallVectorImpl<std::string> & argv){
for(clang::HeaderSearchOptions::Entry e : m_HeaderSearchOptions->UserEntries){
if(e.Group == clang::frontend::IncludeDirGroup::Angled)
argv.push_back("-I" + e.Path);
}
}
@ -148,7 +154,10 @@ namespace cling {
argv.push_back("-S");
argv.push_back("-Xclang");
argv.push_back("-emit-pch");
addHeaders(argv);
llvm::SmallVector<std::string, 256> headers;
addHeaders(headers);
for(std::string & s : headers)
argv.push_back(s.c_str());
// Is necessary for the cling runtime header.
argv.push_back("-D__CLING__");
std::string cuFilePath = m_GenericFileName + std::to_string(m_Counter)

View File

@ -21,6 +21,7 @@ namespace cling{
namespace clang {
class CodeGenOptions;
class HeaderSearchOptions;
}
namespace llvm {
@ -67,13 +68,14 @@ namespace cling {
///\brief Path to the NIVDIA tool fatbinary.
std::string m_FatbinaryPath;
///\brief Contains the include paths, which will set on runtime. Starts with
/// the include command (-I)
llvm::SmallVector<std::string, 256> m_Headers;
///\brief Argument for the fatbinary tool, which is depend, if the OS is
/// 32 bit or 64 bit.
std::string m_FatbinArch;
///\brief Contains information about all include paths.
///
std::shared_ptr<clang::HeaderSearchOptions> m_HeaderSearchOptions;
///\brief Generate the dummy.cu file and set the paths of m_PTXFilePath and
/// m_GenericFileName.
///
@ -92,7 +94,7 @@ namespace cling {
///\brief Add the include paths from the interpreter runtime to a argument list.
///
///\param [in,out] argv - The include commands will append to the argv vector.
void addHeaders(llvm::SmallVectorImpl<const char*> & argv);
void addHeaders(llvm::SmallVectorImpl<std::string> & argv);
///\brief Start an clang compiler with nvptx backend. Read the content of
/// cling.cu and compile it to a new PCH file. If predecessor PCH file is
@ -124,9 +126,12 @@ namespace cling {
/// be empty.
///\param [in] invocationOptions - Contains values for the arguments of
/// clang and the NVIDIA tool fatbinary.
///\param [in] headerSearchOptions - Contains information about all include
/// paths.
IncrementalCUDADeviceCompiler(std::string filePath,
std::string & CudaGpuBinaryFileNames,
cling::InvocationOptions & invocationOptions);
cling::InvocationOptions & invocationOptions,
std::shared_ptr<clang::HeaderSearchOptions> headerSearchOptions);
///\brief Generate an new fatbin file with the path in CudaGpuBinaryFileNames.
/// It will add the content of input, to the existing source code, which was
@ -139,23 +144,6 @@ namespace cling {
/// fatbin file is written.
bool generateFatbinary(llvm::StringRef input);
///\brief Add a new include path to CUDA device compiler.
///
///\param [in] pathStr - Path to the folder, which should used for header
/// search.
///\param [in] leadingIncludeCommand - If it true, the path has to start
/// with the include command (-I)
void addIncludePath(llvm::StringRef pathStr, bool leadingIncludeCommand);
///\brief Add a vector of new include paths to CUDA device compiler.
///
///\param [in] headers - Vector with paths to the folders, which should used
/// for header search.
///\param [in] leadingIncludeCommand - If it true, the paths have to start
/// with the include command (-I)
void addIncludePaths(const llvm::SmallVectorImpl<std::string> & headers,
bool leadingIncludeCommand);
///\brief Print some information of the IncrementalCUDADeviceCompiler to
/// llvm::outs(). For Example the paths of the files and tools.
void dump();

View File

@ -257,13 +257,8 @@ namespace cling {
m_CUDACompiler.reset(
new IncrementalCUDADeviceCompiler(TmpFolder.data(),
getCI()->getCodeGenOpts().CudaGpuBinaryFileNames[0],
m_Opts));
// Add the cling runtime headers to the CUDA device compiler, that
// it can handle the special functions of cling.
llvm::SmallVector<std::string, 256> clingHeaders;
GetIncludePaths(clingHeaders, false, true);
m_CUDACompiler->addIncludePaths(clingHeaders, true);
m_Opts,
getCI()->getHeaderSearchOptsPtr()));
}
// Tell the diagnostic client that we are entering file parsing mode.
@ -566,10 +561,6 @@ namespace cling {
size_t Idx = HOpts.UserEntries.size();
utils::AddIncludePaths(PathStr, HOpts, Delm);
if(m_Opts.CompilerOpts.CUDA){
m_CUDACompiler->addIncludePath(PathStr, false);
}
Preprocessor& PP = CI->getPreprocessor();
SourceManager& SM = PP.getSourceManager();
FileManager& FM = SM.getFileManager();