Skip to content

Commit 9ff25cf

Browse files
committed
start cleanup
1 parent 6fcf97d commit 9ff25cf

File tree

12 files changed

+46
-202
lines changed

12 files changed

+46
-202
lines changed

clang/include/clang/Driver/ToolChain.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ class ToolChain {
158158
/// The list of toolchain specific path prefixes to search for programs.
159159
path_list ProgramPaths;
160160

161-
#if 0
162-
path_list IntrinsicModulePaths;
163-
#endif
164-
165161
mutable std::unique_ptr<Tool> Clang;
166162
mutable std::unique_ptr<Tool> Flang;
167163
mutable std::unique_ptr<Tool> Assemble;
@@ -193,8 +189,7 @@ class ToolChain {
193189
EffectiveTriple = std::move(ET);
194190
}
195191

196-
std::optional<std::string>
197-
getFallbackAndroidTargetPath(StringRef BaseDir) const;
192+
198193

199194
mutable std::optional<CXXStdlibType> cxxStdlibType;
200195
mutable std::optional<RuntimeLibType> runtimeLibType;
@@ -307,12 +302,6 @@ class ToolChain {
307302
path_list &getProgramPaths() { return ProgramPaths; }
308303
const path_list &getProgramPaths() const { return ProgramPaths; }
309304

310-
#if 0
311-
path_list &getIntrinsicModulePaths() { return IntrinsicModulePaths; }
312-
const path_list &getIntrinsicModulePaths() const { return IntrinsicModulePaths; }
313-
#endif
314-
315-
316305
const MultilibSet &getMultilibs() const { return Multilibs; }
317306

318307
const llvm::SmallVector<Multilib> &getSelectedMultilibs() const {
@@ -550,11 +539,15 @@ class ToolChain {
550539
StringRef Component,
551540
FileType Type = ToolChain::FT_Static) const;
552541

553-
// Returns Triple without the OSs version.
554-
static llvm::Triple getTripleWithoutOSVersion(const llvm::Triple &T) ;
555542

543+
544+
/// Returns the target-specific path for Flang's intrinsic modules in the resource directory if it exists.
545+
/// @{
556546
static std::optional<std::string> getDefaultIntrinsicModuleDir(StringRef resourceDir, const llvm::Triple &T ,llvm::vfs::FileSystem &VFS, clang::DiagnosticsEngine *Diags );
547+
548+
557549
std::optional<std::string> getDefaultIntrinsicModuleDir( ) const;
550+
/// @}
558551

559552
// Returns the target specific runtime path if it exists.
560553
std::optional<std::string> getRuntimePath() const;

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6538,7 +6538,7 @@ std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const {
65386538
return std::string(P);
65396539

65406540
if (IsFlangMode()) {
6541-
if (auto IntrPath = TC.getDefaultIntrinsicModuleDir ()) {
6541+
if (std::optional<std::string> IntrPath = TC.getDefaultIntrinsicModuleDir ()) {
65426542
SmallString<128> P(*IntrPath);
65436543
llvm::sys::path::append(P, Name);
65446544
if (llvm::sys::fs::exists(Twine(P)))

clang/lib/Driver/ToolChain.cpp

Lines changed: 6 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,8 @@ ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
102102
getFilePaths().push_back(*Path);
103103
for (const auto &Path : getArchSpecificLibPaths())
104104
addIfExists(getFilePaths(), Path);
105-
106-
#if 0
107-
if (std::optional<std::string> Path = getDefaultIntrinsicModuleDir())
108-
getIntrinsicModulePaths().push_back(*Path);
109-
#endif
110105
}
111106

112-
113-
114107
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
115108
ToolChain::executeToolChainProgram(StringRef Executable) const {
116109
llvm::SmallString<64> OutputFile;
@@ -916,51 +909,12 @@ getFallbackAndroidTargetPath(StringRef BaseDir, const llvm::Triple &T, llvm::vfs
916909
return std::string(P);
917910
}
918911

919-
std::optional<std::string>
920-
ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) const {
921-
return ::getFallbackAndroidTargetPath(BaseDir, getTriple(), getVFS(), &D.getDiags());
922-
#if 0
923-
llvm::Triple TripleWithoutLevel(getTriple());
924-
TripleWithoutLevel.setEnvironmentName("android"); // remove any version number
925-
const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str();
926-
unsigned TripleVersion = getTriple().getEnvironmentVersion().getMajor();
927-
unsigned BestVersion = 0;
928-
929-
SmallString<32> TripleDir;
930-
bool UsingUnversionedDir = false;
931-
std::error_code EC;
932-
for (llvm::vfs::directory_iterator LI = getVFS().dir_begin(BaseDir, EC), LE;
933-
!EC && LI != LE; LI = LI.increment(EC)) {
934-
StringRef DirName = llvm::sys::path::filename(LI->path());
935-
StringRef DirNameSuffix = DirName;
936-
if (DirNameSuffix.consume_front(TripleWithoutLevelStr)) {
937-
if (DirNameSuffix.empty() && TripleDir.empty()) {
938-
TripleDir = DirName;
939-
UsingUnversionedDir = true;
940-
} else {
941-
unsigned Version;
942-
if (!DirNameSuffix.getAsInteger(10, Version) && Version > BestVersion &&
943-
Version < TripleVersion) {
944-
BestVersion = Version;
945-
TripleDir = DirName;
946-
UsingUnversionedDir = false;
947-
}
948-
}
949-
}
950-
}
951912

952-
if (TripleDir.empty())
953-
return {};
954913

955-
SmallString<128> P(BaseDir);
956-
llvm::sys::path::append(P, TripleDir);
957-
if (UsingUnversionedDir)
958-
D.Diag(diag::warn_android_unversioned_fallback) << P << getTripleString();
959-
return std::string(P);
960-
#endif
961-
}
962914

963-
llvm::Triple ToolChain::getTripleWithoutOSVersion(const llvm::Triple &Triple) {
915+
/// Returns Triple without the OSs version.
916+
static
917+
llvm::Triple getTripleWithoutOSVersion(const llvm::Triple &Triple) {
964918
return (Triple.hasEnvironment()
965919
? llvm::Triple(Triple.getArchName(), Triple.getVendorName(),
966920
llvm::Triple::getOSTypeName(Triple.getOS()),
@@ -979,7 +933,6 @@ static std::optional<std::string> getTargetSubDirPath(StringRef BaseDir, const
979933
return {};
980934
};
981935

982-
983936
if (auto Path = getPathForTriple(T))
984937
return *Path;
985938

@@ -991,7 +944,7 @@ static std::optional<std::string> getTargetSubDirPath(StringRef BaseDir, const
991944
llvm::Triple::getOSTypeName(T.getOS()));
992945
} else {
993946
// Strip the OS version from the triple.
994-
AIXTriple =ToolChain:: getTripleWithoutOSVersion(T);
947+
AIXTriple =getTripleWithoutOSVersion(T);
995948
}
996949
if (auto Path = getPathForTriple(AIXTriple))
997950
return *Path;
@@ -1000,7 +953,7 @@ static std::optional<std::string> getTargetSubDirPath(StringRef BaseDir, const
1000953
if (T.isOSzOS() &&
1001954
(!T.getOSVersion().empty() || !T.getEnvironmentVersion().empty())) {
1002955
// Build the triple without version information
1003-
const llvm::Triple &TripleWithoutVersion =ToolChain:: getTripleWithoutOSVersion(T);
956+
const llvm::Triple &TripleWithoutVersion =getTripleWithoutOSVersion(T);
1004957
if (auto Path = getPathForTriple(TripleWithoutVersion))
1005958
return *Path;
1006959
}
@@ -1028,7 +981,7 @@ static std::optional<std::string> getTargetSubDirPath(StringRef BaseDir, const
1028981
}
1029982

1030983
if (T.isAndroid())
1031-
return :: getFallbackAndroidTargetPath(BaseDir, T, VFS, Diags);
984+
return getFallbackAndroidTargetPath(BaseDir, T, VFS, Diags);
1032985

1033986
return {};
1034987
}
@@ -1037,77 +990,12 @@ static std::optional<std::string> getTargetSubDirPath(StringRef BaseDir, const
1037990
std::optional<std::string>
1038991
ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
1039992
return ::getTargetSubDirPath(BaseDir, getTriple(), getVFS(),& D.getDiags() );
1040-
#if 0
1041-
auto getPathForTriple =
1042-
[&](const llvm::Triple &Triple) -> std::optional<std::string> {
1043-
SmallString<128> P(BaseDir);
1044-
llvm::sys::path::append(P, Triple.str());
1045-
if (getVFS().exists(P))
1046-
return std::string(P);
1047-
return {};
1048-
};
1049-
1050-
const llvm::Triple &T = getTriple();
1051-
if (auto Path = getPathForTriple(T))
1052-
return *Path;
1053-
1054-
if (T.isOSAIX()) {
1055-
llvm::Triple AIXTriple;
1056-
if (T.getEnvironment() == Triple::UnknownEnvironment) {
1057-
// Strip unknown environment and the OS version from the triple.
1058-
AIXTriple = llvm::Triple(T.getArchName(), T.getVendorName(),
1059-
llvm::Triple::getOSTypeName(T.getOS()));
1060-
} else {
1061-
// Strip the OS version from the triple.
1062-
AIXTriple = getTripleWithoutOSVersion();
1063-
}
1064-
if (auto Path = getPathForTriple(AIXTriple))
1065-
return *Path;
1066-
}
1067-
1068-
if (T.isOSzOS() &&
1069-
(!T.getOSVersion().empty() || !T.getEnvironmentVersion().empty())) {
1070-
// Build the triple without version information
1071-
const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion();
1072-
if (auto Path = getPathForTriple(TripleWithoutVersion))
1073-
return *Path;
1074-
}
1075-
1076-
// When building with per target runtime directories, various ways of naming
1077-
// the Arm architecture may have been normalised to simply "arm".
1078-
// For example "armv8l" (Armv8 AArch32 little endian) is replaced with "arm".
1079-
// Since an armv8l system can use libraries built for earlier architecture
1080-
// versions assuming endian and float ABI match.
1081-
//
1082-
// Original triple: armv8l-unknown-linux-gnueabihf
1083-
// Runtime triple: arm-unknown-linux-gnueabihf
1084-
//
1085-
// We do not do this for armeb (big endian) because doing so could make us
1086-
// select little endian libraries. In addition, all known armeb triples only
1087-
// use the "armeb" architecture name.
1088-
//
1089-
// M profile Arm is bare metal and we know they will not be using the per
1090-
// target runtime directory layout.
1091-
if (T.getArch() == Triple::arm && !T.isArmMClass()) {
1092-
llvm::Triple ArmTriple = T;
1093-
ArmTriple.setArch(Triple::arm);
1094-
if (auto Path = getPathForTriple(ArmTriple))
1095-
return *Path;
1096-
}
1097-
1098-
if (T.isAndroid())
1099-
return getFallbackAndroidTargetPath(BaseDir);
1100-
1101-
return {};
1102-
#endif
1103993
}
1104994

1105995
std::optional< std::string> ToolChain::getDefaultIntrinsicModuleDir(StringRef ResourceDir, const llvm::Triple &T ,llvm::vfs::FileSystem &VFS, clang::DiagnosticsEngine *Diags ) {
1106996
SmallString<128> P(ResourceDir);
1107997
llvm::sys::path::append(P, "finclude");
1108998
return ::getTargetSubDirPath(P, T, VFS, Diags );
1109-
// llvm::sys::path::append(instrinsicsDir, "finclude", triple.str());
1110-
// return instrinsicsDir.str().str();
1111999
}
11121000

11131001
std::optional< std::string> ToolChain::getDefaultIntrinsicModuleDir( ) const {

flang/include/flang/Frontend/CompilerInvocation.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ class CompilerInvocation : public CompilerInvocationBase {
9292
// intrinsic of iso_fortran_env.
9393
std::string allCompilerInvocOpts;
9494

95-
/// Location of the resource directory containing files specific to this instance of Flang.
95+
/// Location of the resource directory containing files specific to this instance/version of Flang.
9696
std::string resourceDir;
9797

9898
/// Semantic options
9999
// TODO: Merge with or translate to frontendOpts. We shouldn't need two sets
100100
// of options.
101-
std::string moduleDir = "."; // MK: even used?
101+
std::string moduleDir = ".";
102102

103103
std::string moduleFileSuffix = ".mod";
104104

@@ -184,10 +184,9 @@ class CompilerInvocation : public CompilerInvocationBase {
184184
const std::string &getResourceDir() const { return resourceDir; }
185185

186186

187-
#if 1
187+
188188
std::string &getModuleDir() { return moduleDir; }
189189
const std::string &getModuleDir() const { return moduleDir; }
190-
#endif
191190

192191
std::string &getModuleFileSuffix() { return moduleFileSuffix; }
193192
const std::string &getModuleFileSuffix() const { return moduleFileSuffix; }
@@ -262,10 +261,7 @@ class CompilerInvocation : public CompilerInvocationBase {
262261
/// Useful setters
263262
void setArgv0(const char *dir) { argv0 = dir; }
264263

265-
266-
void setModuleDir(std::string &dir) {
267-
moduleDir = dir;
268-
}
264+
void setModuleDir(std::string &dir) { moduleDir = dir; }
269265

270266
void setModuleFileSuffix(const char *suffix) {
271267
moduleFileSuffix = std::string(suffix);

flang/include/flang/Frontend/PreprocessorOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ struct PreprocessorOptions {
4545
// consider collecting them in a separate aggregate. For now we keep it here
4646
// as there is no point creating a class for just one field.
4747
std::vector<std::string> searchDirectoriesFromDashI;
48-
49-
// Search directories specified by the user with -J (and -module-dir?)
50-
std::vector<std::string> searchDirectoriesFromDashJ;
51-
5248
// Search directories specified by the user with -fintrinsic-modules-path
5349
std::vector<std::string> searchDirectoriesFromIntrModPath;
5450

flang/include/flang/Parser/options.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ struct Options {
2323

2424
using Predefinition = std::pair<std::string, std::optional<std::string>>;
2525

26-
bool isFixedForm{false};
26+
bool isFixedForm{false};
2727
int fixedFormColumns{72};
2828
common::LanguageFeatureControl features;
2929

30-
/// -J
30+
/// Search paths from -J/-module-dir
31+
/// Only a single path is supported which is also the location for writing modules.
3132
std::vector<std::string> searchDirectories;
3233

33-
/// -fintrinsic-modules-path
34+
/// Search paths from -fintrinsic-modules-path
35+
/// Muliple paths are supported.
3436
std::vector<std::string> intrinsicModuleDirectories;
3537

3638
std::vector<Predefinition> predefinitions;

flang/include/flang/Parser/parse-tree.h

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,27 +3357,9 @@ struct StmtFunctionStmt {
33573357
// !DIR$ NOUNROLL_AND_JAM
33583358
// !DIR$ <anything else>
33593359
struct CompilerDirective {
3360-
template <typename A, typename = common::NoLvalue<A>>
3361-
CompilerDirective(A &&x) : u(std::move(x)) {
3362-
int a = 0;
3363-
}
3364-
using UnionTrait = std::true_type;
3365-
CompilerDirective(CompilerDirective &&) = default;
3366-
CompilerDirective &operator=(CompilerDirective &&) = default;
3367-
CompilerDirective(const CompilerDirective &) = delete;
3368-
CompilerDirective &operator=(const CompilerDirective &) = delete;
3369-
CompilerDirective() = delete;
3360+
UNION_CLASS_BOILERPLATE(CompilerDirective);
33703361
struct IgnoreTKR {
3371-
template <typename... Ts, typename = common::NoLvalue<Ts...>>
3372-
IgnoreTKR(Ts &&...args) : t(std::move(args)...) {
3373-
int b = 0;
3374-
}
3375-
using TupleTrait = std::true_type;
3376-
IgnoreTKR(IgnoreTKR &&) = default;
3377-
IgnoreTKR &operator=(IgnoreTKR &&) = default;
3378-
IgnoreTKR(const IgnoreTKR &) = delete;
3379-
IgnoreTKR &operator=(const IgnoreTKR &) = delete;
3380-
IgnoreTKR() = delete;
3362+
TUPLE_CLASS_BOILERPLATE(IgnoreTKR);
33813363
std::tuple<std::optional<std::list<const char *>>, Name> t;
33823364
};
33833365
struct LoopCount {

flang/include/flang/Parser/provenance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class AllSources {
188188
ProvenanceRange IntersectionWithSourceFiles(ProvenanceRange) const;
189189
llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
190190

191-
public:
191+
private:
192192
struct Inclusion {
193193
const SourceFile &source;
194194
bool isModule{false};

flang/include/flang/Semantics/semantics.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,16 @@ class SemanticsContext {
316316
parser::AllCookedSources &allCookedSources_;
317317
std::optional<parser::CharBlock> location_;
318318

319-
// -J
319+
/// Search paths for non-intrinsic modules.
320+
/// Originates from the -J/-module-dir command line options
320321
std::vector<std::string> searchDirectories_;
321322

322-
// -fintrinsic_modules_path
323+
/// Search paths for intrinsic modules.
324+
/// Originates from the -fintrinsic-modules-path line option
323325
std::vector<std::string> intrinsicModuleDirectories_;
324326

325-
// -module-dir ???
327+
/// Location for emitting module files.
328+
/// Originates from the -J/-module-dir command line options
326329
std::string moduleDirectory_{"."s};
327330

328331
std::string moduleFileSuffix_{".mod"};
@@ -379,7 +382,7 @@ class Semantics {
379382
void EmitMessages(llvm::raw_ostream &);
380383
void DumpSymbols(llvm::raw_ostream &);
381384
void DumpSymbolsSources(llvm::raw_ostream &) const;
382-
bool intrinsicsMode_ = false;
385+
383386
private:
384387
SemanticsContext &context_;
385388
parser::Program &program_;

0 commit comments

Comments
 (0)