Skip to content

Commit ef050ff

Browse files
committed
[HIPIFY][fix] LLVM upstream preparations - Part 4 - namespace usage revision
1 parent 1f79dac commit ef050ff

7 files changed

Lines changed: 42 additions & 34 deletions

File tree

src/CUDA2HIP_Doc.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,22 @@ THE SOFTWARE.
2828

2929
namespace doc {
3030

31-
using namespace std;
32-
using namespace llvm;
31+
using std::string;
32+
using std::map;
33+
using std::vector;
34+
using std::unique_ptr;
35+
using std::ostream;
36+
using std::ofstream;
37+
using std::stringstream;
38+
using std::error_code;
39+
using std::make_pair;
40+
using std::endl;
3341

34-
typedef map<unsigned int, StringRef> sectionMap;
35-
typedef map<StringRef, hipCounter> functionMap;
42+
typedef map<unsigned int, llvm::StringRef> sectionMap;
43+
typedef map<llvm::StringRef, hipCounter> functionMap;
3644
typedef functionMap typeMap;
37-
typedef map<StringRef, cudaAPIversions> versionMap;
38-
typedef map<StringRef, hipAPIversions> hipVersionMap;
45+
typedef map<llvm::StringRef, cudaAPIversions> versionMap;
46+
typedef map<llvm::StringRef, hipAPIversions> hipVersionMap;
3947
typedef map<llvm::StringRef, hipAPIChangedVersions> hipChangedVersionMap;
4048
typedef map<llvm::StringRef, cudaAPIChangedVersions> cudaChangedVersionMap;
4149
typedef map<llvm::StringRef, cudaAPIUnsupportedVersions> cudaUnsupportedVersionMap;
@@ -106,7 +114,6 @@ namespace doc {
106114
const string sMIOPEN_md = sMIOPEN_ + md_ext;
107115
const string sMIOPEN_csv = sMIOPEN_ + csv_ext;
108116
const string sCUDNN = "CUDNN";
109-
110117
const string sFFT = "CUFFT_API_supported_by_HIP";
111118
const string sFFT_md = sFFT + md_ext;
112119
const string sFFT_csv = sFFT + csv_ext;
@@ -243,15 +250,15 @@ namespace doc {
243250

244251
bool init(docType t) {
245252
string file = (dir.empty() ? getFileName(t) : dir + "/" + getFileName(t));
246-
SmallString<128> tmpFile;
247-
EC = sys::fs::createTemporaryFile(file, getExtension(t), tmpFile);
253+
llvm::SmallString<128> tmpFile;
254+
EC = llvm::sys::fs::createTemporaryFile(file, getExtension(t), tmpFile);
248255
if (EC) {
249-
errs() << "\n" << sHipify << sError << EC.message() << ": " << tmpFile << "\n";
256+
llvm::errs() << "\n" << sHipify << sError << EC.message() << ": " << tmpFile << "\n";
250257
return false;
251258
}
252259
files.insert({ t, file });
253260
tmpFiles.insert({ t, tmpFile.str().str() });
254-
streams.insert(make_pair(t, unique_ptr<ostream>(new ofstream(tmpFile.c_str(), ios_base::trunc))));
261+
streams.insert(make_pair(t, unique_ptr<ostream>(new ofstream(tmpFile.c_str(), std::ios_base::trunc))));
255262
return true;
256263
}
257264

@@ -464,12 +471,12 @@ namespace doc {
464471
bool fini(docType format) {
465472
streams[format].get()->flush();
466473
bool bRet = true;
467-
EC = sys::fs::copy_file(tmpFiles[format], files[format]);
474+
EC = llvm::sys::fs::copy_file(tmpFiles[format], files[format]);
468475
if (EC) {
469-
errs() << "\n" << sHipify << sError << EC.message() << ": while copying " << tmpFiles[format] << " to " << files[format] << "\n";
476+
llvm::errs() << "\n" << sHipify << sError << EC.message() << ": while copying " << tmpFiles[format] << " to " << files[format] << "\n";
470477
bRet = false;
471478
}
472-
if (!SaveTemps) sys::fs::remove(tmpFiles[format]);
479+
if (!SaveTemps) llvm::sys::fs::remove(tmpFiles[format]);
473480
return bRet;
474481
}
475482

src/HipifyAction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ THE SOFTWARE.
3535
#include "CUDA2HIP.h"
3636
#include "ArgParse.h"
3737

38+
using namespace llvm;
3839
using namespace hipify;
3940

4041
const std::string sHIP = "HIP";

src/HipifyAction.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ THE SOFTWARE.
3232

3333
namespace ct = clang::tooling;
3434
namespace mat = clang::ast_matchers;
35-
using namespace llvm;
3635

3736
/**
3837
* A FrontendAction that hipifies CUDA programs.
@@ -68,7 +67,7 @@ class HipifyAction : public clang::ASTFrontendAction,
6867
clang::SourceLocation firstHeaderLoc;
6968
clang::SourceLocation pragmaOnceLoc;
7069
// Rewrite a string literal to refer to hip, not CUDA.
71-
void RewriteString(StringRef s, clang::SourceLocation start);
70+
void RewriteString(llvm::StringRef s, clang::SourceLocation start);
7271
// Replace a CUDA identifier with the corresponding hip identifier, if applicable.
7372
void RewriteToken(const clang::Token &t);
7473
// Calculate str's SourceLocation in SourceRange sr
@@ -91,12 +90,12 @@ class HipifyAction : public clang::ASTFrontendAction,
9190
// Called by the preprocessor for each include directive during the non-raw lexing pass.
9291
void InclusionDirective(clang::SourceLocation hash_loc,
9392
const clang::Token &include_token,
94-
StringRef file_name,
93+
llvm::StringRef file_name,
9594
bool is_angled,
9695
clang::CharSourceRange filename_range,
9796
const clang::FileEntry *file,
98-
StringRef search_path,
99-
StringRef relative_path,
97+
llvm::StringRef search_path,
98+
llvm::StringRef relative_path,
10099
const clang::Module *imported);
101100
// Called by the preprocessor for each pragma directive during the non-raw lexing pass.
102101
void PragmaDirective(clang::SourceLocation Loc, clang::PragmaIntroducerKind Introducer);
@@ -117,7 +116,7 @@ class HipifyAction : public clang::ASTFrontendAction,
117116
void EndSourceFileAction() override;
118117
// MatchCallback API entry point. Called by the AST visitor while searching the AST for things we registered an interest for.
119118
void run(const mat::MatchFinder::MatchResult &Result) override;
120-
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &CI, StringRef InFile) override;
119+
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef InFile) override;
121120
bool Exclude(const hipCounter &hipToken);
122-
void FindAndReplace(StringRef name, clang::SourceLocation sl, const std::map<StringRef, hipCounter> &repMap, bool bReplace = true);
121+
void FindAndReplace(llvm::StringRef name, clang::SourceLocation sl, const std::map<llvm::StringRef, hipCounter> &repMap, bool bReplace = true);
123122
};

src/LLVMCompat.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ THE SOFTWARE.
2828
#include "clang/Lex/PreprocessorOptions.h"
2929
#include "clang/Frontend/CompilerInstance.h"
3030

31+
using namespace llvm;
32+
3133
const std::string sHipify = "[HIPIFY] ", sConflict = "conflict: ", sError = "error: ", sWarning = "warning: ";
3234

3335
namespace llcompat {

src/LLVMCompat.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ clang::SourceLocation getEndLoc(const clang::TypeLoc &typeLoc);
5757

5858
void PrintStackTraceOnErrorSignal();
5959

60-
using namespace llvm;
61-
6260
/**
6361
* Get the replacement map for a given filename in a RefactoringTool.
6462
*
6563
* Older LLVM versions don't actually support multiple filenames, so everything all gets
6664
* smushed together. It is the caller's responsibility to cope with this.
6765
*/
68-
ct::Replacements &getReplacements(ct::RefactoringTool &Tool, StringRef file);
66+
ct::Replacements &getReplacements(ct::RefactoringTool &Tool, llvm::StringRef file);
6967

7068
/**
7169
* Add a Replacement to a Replacements.
@@ -80,7 +78,7 @@ void EnterPreprocessorTokenStream(clang::Preprocessor &_pp,
8078
size_t len,
8179
bool DisableMacroExpansion);
8280

83-
std::error_code real_path(const Twine &path, SmallVectorImpl<char> &output,
81+
std::error_code real_path(const llvm::Twine &path, llvm::SmallVectorImpl<char> &output,
8482
bool expand_tilde = false);
8583

8684
bool pragma_once_outside_header();
@@ -92,9 +90,9 @@ bool CheckCompatibility();
9290
clang::SourceLocation getEndOfExpansionRangeForLoc(const clang::SourceManager &SM, const clang::SourceLocation &loc);
9391

9492
#if LLVM_VERSION_MAJOR >= 12
95-
typedef MemoryBufferRef Memory_Buffer;
93+
typedef llvm::MemoryBufferRef Memory_Buffer;
9694
#else
97-
typedef const MemoryBuffer *Memory_Buffer;
95+
typedef const llvm::MemoryBuffer *Memory_Buffer;
9896
#endif
9997

10098
Memory_Buffer getMemoryBuffer(const clang::SourceManager &SM);

src/LocalHeader.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
using namespace clang;
1717
using namespace clang::tooling;
1818
using namespace llvm;
19-
using namespace std;
2019

2120
static std::string normalizeSmallStringPath(SmallString<256> &p) {
22-
llvm::sys::path::remove_dots(p, true);
21+
sys::path::remove_dots(p, true);
2322

2423
SmallString<256> realBuf;
25-
std::error_code ec = llvm::sys::fs::real_path(p, realBuf);
24+
std::error_code ec = sys::fs::real_path(p, realBuf);
2625
if (!ec) {
2726
return std::string(realBuf.str());
2827
}
@@ -34,20 +33,20 @@ static bool pathExists(const std::string &p) {
3433
SmallString<256> in(p.begin(), p.end());
3534

3635
SmallString<256> realBuf;
37-
std::error_code ec = llvm::sys::fs::real_path(in, realBuf);
36+
std::error_code ec = sys::fs::real_path(in, realBuf);
3837
if (!ec) return true;
3938

4039
SmallString<256> norm = in;
41-
llvm::sys::path::remove_dots(norm, true);
42-
return llvm::sys::fs::exists(norm);
40+
sys::path::remove_dots(norm, true);
41+
return sys::fs::exists(norm);
4342
}
4443

4544
namespace {
4645
static const std::regex LocalIncludeRe(
4746
R"(^\s*#\s*include\s*\"([^\"\n]+)\"\s*(?://.*)?$)", std::regex::ECMAScript);
4847

4948
bool readFile(const std::string &path, std::string &out) {
50-
auto MBOrErr = llvm::MemoryBuffer::getFile(path);
49+
auto MBOrErr = MemoryBuffer::getFile(path);
5150
if (!MBOrErr) return false;
5251
out = MBOrErr->get()->getBuffer().str();
5352
return true;

src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ THE SOFTWARE.
5555

5656
constexpr auto DEBUG_TYPE = "cuda2hip";
5757

58+
using namespace llvm;
59+
5860
namespace ct = clang::tooling;
5961

6062
void cleanupHipifyOptions(std::vector<const char*> &args) {

0 commit comments

Comments
 (0)