Skip to content

Commit 1947eb9

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#2967)
2 parents e0384a7 + adc5660 commit 1947eb9

File tree

161 files changed

+1485
-1355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+1485
-1355
lines changed

clang/include/clang/Basic/SourceManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ class SourceManager : public RefCountedBase<SourceManager> {
767767
/// LastFileIDLookup records the last FileID looked up or created, because it
768768
/// is very common to look up many tokens from the same file.
769769
mutable FileID LastFileIDLookup;
770+
mutable SourceLocation::UIntTy LastLookupStartOffset;
771+
mutable SourceLocation::UIntTy LastLookupEndOffset; // exclude
770772

771773
/// Holds information for \#line directives.
772774
///
@@ -1901,9 +1903,8 @@ class SourceManager : public RefCountedBase<SourceManager> {
19011903

19021904
FileID getFileID(SourceLocation::UIntTy SLocOffset) const {
19031905
// If our one-entry cache covers this offset, just return it.
1904-
if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1906+
if (SLocOffset >= LastLookupStartOffset && SLocOffset < LastLookupEndOffset)
19051907
return LastFileIDLookup;
1906-
19071908
return getFileIDSlow(SLocOffset);
19081909
}
19091910

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,10 @@ def fno_convergent_functions : Flag<["-"], "fno-convergent-functions">,
11431143

11441144
// Common offloading options
11451145
let Group = offload_Group in {
1146+
def offload_targets_EQ : CommaJoined<["--"], "offload-targets=">,
1147+
Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
1148+
HelpText<"Specify a list of target architectures to use for offloading.">;
1149+
11461150
def offload_arch_EQ : CommaJoined<["--"], "offload-arch=">,
11471151
Visibility<[ClangOption, FlangOption]>,
11481152
HelpText<"Specify an offloading device architecture for CUDA, HIP, or OpenMP. (e.g. sm_35). "
@@ -3693,7 +3697,7 @@ def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, Group<f_Group>,
36933697
Flags<[NoArgumentUnused, HelpHidden]>;
36943698
def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group<f_Group>,
36953699
Flags<[NoArgumentUnused, HelpHidden]>, Visibility<[ClangOption, CC1Option]>;
3696-
def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">,
3700+
def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">, Alias<offload_targets_EQ>,
36973701
Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
36983702
HelpText<"Specify comma-separated list of triples OpenMP offloading targets to be supported">;
36993703
def fopenmp_relocatable_target : Flag<["-"], "fopenmp-relocatable-target">,

clang/lib/Basic/SourceManager.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ void SourceManager::clearIDTables() {
335335
LastLineNoFileIDQuery = FileID();
336336
LastLineNoContentCache = nullptr;
337337
LastFileIDLookup = FileID();
338+
LastLookupStartOffset = LastLookupEndOffset = 0;
338339

339340
IncludedLocMap.clear();
340341
if (LineTable)
@@ -630,9 +631,11 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename,
630631
LocalSLocEntryTable.push_back(
631632
SLocEntry::get(NextLocalOffset,
632633
FileInfo::get(IncludePos, File, FileCharacter, Filename)));
634+
LastLookupStartOffset = NextLocalOffset;
633635
// We do a +1 here because we want a SourceLocation that means "the end of the
634636
// file", e.g. for the "no newline at the end of the file" diagnostic.
635637
NextLocalOffset += FileSize + 1;
638+
LastLookupEndOffset = NextLocalOffset;
636639
updateSlocUsageStats();
637640

638641
// Set LastFileIDLookup to the newly created file. The next getFileID call is
@@ -802,8 +805,9 @@ FileID SourceManager::getFileIDSlow(SourceLocation::UIntTy SLocOffset) const {
802805
/// loaded one.
803806
FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
804807
assert(SLocOffset < NextLocalOffset && "Bad function choice");
805-
assert(SLocOffset >= LocalSLocEntryTable[0].getOffset() &&
808+
assert(SLocOffset >= LocalSLocEntryTable[0].getOffset() && SLocOffset > 0 &&
806809
"Invalid SLocOffset");
810+
assert(LastFileIDLookup.ID >= 0 && "Only cache local file sloc entry");
807811

808812
// After the first and second level caches, I see two common sorts of
809813
// behavior: 1) a lot of searched FileID's are "near" the cached file
@@ -823,13 +827,11 @@ FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
823827
unsigned LessIndex = 0;
824828
// upper bound of the search range.
825829
unsigned GreaterIndex = LocalSLocEntryTable.size();
826-
if (LastFileIDLookup.ID >= 0) {
827-
// Use the LastFileIDLookup to prune the search space.
828-
if (LocalSLocEntryTable[LastFileIDLookup.ID].getOffset() < SLocOffset)
829-
LessIndex = LastFileIDLookup.ID;
830-
else
831-
GreaterIndex = LastFileIDLookup.ID;
832-
}
830+
// Use the LastFileIDLookup to prune the search space.
831+
if (LastLookupStartOffset < SLocOffset)
832+
LessIndex = LastFileIDLookup.ID;
833+
else
834+
GreaterIndex = LastFileIDLookup.ID;
833835

834836
// Find the FileID that contains this.
835837
unsigned NumProbes = 0;
@@ -840,7 +842,12 @@ FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
840842
FileID Res = FileID::get(int(GreaterIndex));
841843
// Remember it. We have good locality across FileID lookups.
842844
LastFileIDLookup = Res;
843-
NumLinearScans += NumProbes+1;
845+
LastLookupStartOffset = LocalSLocEntryTable[GreaterIndex].getOffset();
846+
LastLookupEndOffset =
847+
GreaterIndex + 1 >= LocalSLocEntryTable.size()
848+
? NextLocalOffset
849+
: LocalSLocEntryTable[GreaterIndex + 1].getOffset();
850+
NumLinearScans += NumProbes + 1;
844851
return Res;
845852
}
846853
if (++NumProbes == 8)
@@ -864,6 +871,8 @@ FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
864871
// At this point, LessIndex is the index of the *first element greater than*
865872
// SLocOffset. The element we are actually looking for is the one immediately
866873
// before it.
874+
LastLookupStartOffset = LocalSLocEntryTable[LessIndex - 1].getOffset();
875+
LastLookupEndOffset = LocalSLocEntryTable[LessIndex].getOffset();
867876
return LastFileIDLookup = FileID::get(LessIndex - 1);
868877
}
869878

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
999999
/*SpecificToolchain=*/true);
10001000
} else if (IsHIP && !UseLLVMOffload) {
10011001
if (auto *OMPTargetArg =
1002-
C.getInputArgs().getLastArg(options::OPT_fopenmp_targets_EQ)) {
1002+
C.getInputArgs().getLastArg(options::OPT_offload_targets_EQ)) {
10031003
Diag(clang::diag::err_drv_unsupported_opt_for_language_mode)
10041004
<< OMPTargetArg->getSpelling() << "HIP";
10051005
return;
@@ -1033,7 +1033,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
10331033
((IsCuda || IsHIP) && UseLLVMOffload) ||
10341034
(C.getInputArgs().hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
10351035
options::OPT_fno_openmp, false) &&
1036-
(C.getInputArgs().hasArg(options::OPT_fopenmp_targets_EQ) ||
1036+
(C.getInputArgs().hasArg(options::OPT_offload_targets_EQ) ||
10371037
C.getInputArgs().hasArg(options::OPT_offload_arch_EQ)));
10381038
if (IsOpenMPOffloading) {
10391039
// We expect that -fopenmp-targets is always used in conjunction with the
@@ -1049,7 +1049,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
10491049
// valid triple. Otherwise, if only --offload-arch= was specified we instead
10501050
// attempt to derive the appropriate toolchains from the arguments.
10511051
if (Arg *OpenMPTargets =
1052-
C.getInputArgs().getLastArg(options::OPT_fopenmp_targets_EQ)) {
1052+
C.getInputArgs().getLastArg(options::OPT_offload_targets_EQ)) {
10531053
if (OpenMPTargets && !OpenMPTargets->getNumValues()) {
10541054
Diag(clang::diag::warn_drv_empty_joined_argument)
10551055
<< OpenMPTargets->getAsString(C.getInputArgs());
@@ -1127,7 +1127,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11271127
Diag(clang::diag::err_drv_failed_to_deduce_target_from_arch)
11281128
<< "native";
11291129
}
1130-
} else if (C.getInputArgs().hasArg(options::OPT_fopenmp_targets_EQ)) {
1130+
} else if (C.getInputArgs().hasArg(options::OPT_offload_targets_EQ)) {
11311131
Diag(clang::diag::err_drv_expecting_fopenmp_with_fopenmp_targets);
11321132
return;
11331133
}

clang/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs(
17421742
continue;
17431743
}
17441744
if (XOpenMPTargetNoTriple && XOpenMPTargetArg &&
1745-
Args.getAllArgValues(options::OPT_fopenmp_targets_EQ).size() != 1) {
1745+
Args.getAllArgValues(options::OPT_offload_targets_EQ).size() != 1) {
17461746
getDriver().Diag(diag::err_drv_Xopenmp_target_missing_triple);
17471747
continue;
17481748
}

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation &C,
15421542

15431543
// For all the host OpenMP offloading compile jobs we need to pass the targets
15441544
// information using -fopenmp-targets= option.
1545-
constexpr llvm::StringLiteral Targets("-fopenmp-targets=");
1545+
constexpr llvm::StringLiteral Targets("--offload-targets=");
15461546

15471547
SmallVector<std::string> Triples;
15481548
auto TCRange = C.getOffloadToolChains<Action::OFK_OpenMP>();

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3962,7 +3962,7 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
39623962
llvm::interleave(
39633963
Opts.OMPTargetTriples, OS,
39643964
[&OS](const llvm::Triple &T) { OS << T.str(); }, ",");
3965-
GenerateArg(Consumer, OPT_fopenmp_targets_EQ, Targets);
3965+
GenerateArg(Consumer, OPT_offload_targets_EQ, Targets);
39663966
}
39673967

39683968
if (!Opts.OMPHostIRFile.empty())
@@ -4393,7 +4393,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
43934393
Opts.OpenMPIRBuilder =
43944394
Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_enable_irbuilder);
43954395
bool IsTargetSpecified =
4396-
Opts.OpenMPIsTargetDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
4396+
Opts.OpenMPIsTargetDevice || Args.hasArg(options::OPT_offload_targets_EQ);
4397+
43974398
if (Opts.OpenMP || Opts.OpenMPSimd) {
43984399
if (int Version = getLastArgIntValue(
43994400
Args, OPT_fopenmp_version_EQ,
@@ -4510,7 +4511,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
45104511
options::OPT_fno_openmp_assume_no_nested_parallelism, isOFastUsed(Args));
45114512

45124513
// Get the OpenMP target triples if any.
4513-
if (Arg *A = Args.getLastArg(options::OPT_fopenmp_targets_EQ)) {
4514+
if (Arg *A = Args.getLastArg(options::OPT_offload_targets_EQ)) {
45144515
enum ArchPtrSize { Arch16Bit, Arch32Bit, Arch64Bit };
45154516
auto getArchPtrSize = [](const llvm::Triple &T) {
45164517
if (T.isArch16Bit())

clang/test/Driver/amdgpu-openmp-sanitize-options.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
// NOXNACK: warning: ignoring '-fsanitize=address' option for offload arch 'gfx908' as it is not currently supported there. Use it with an offload arch containing 'xnack+' instead
5555
// XNACKNEG: warning: ignoring '-fsanitize=address' option for offload arch 'gfx908:xnack-' as it is not currently supported there. Use it with an offload arch containing 'xnack+' instead
5656

57-
// HOSTSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "-fopenmp-targets=amdgcn-amd-amdhsa".* "-x" "c".*}}
57+
// HOSTSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "--offload-targets=amdgcn-amd-amdhsa".* "-x" "c".*}}
5858

5959
// GPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu".* "-emit-llvm-bc".* "-mlink-bitcode-file" "[^"]*asanrtl.bc".* "-mlink-bitcode-file" "[^"]*ockl.bc".* "-target-cpu" "(gfx908|gfx900)".* "-fopenmp".* "-fsanitize=address".* "-x" "c".*}}
6060
// NOGPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu".* "-emit-llvm-bc".* "-target-cpu" "(gfx908|gfx900)".* "-fopenmp".* "-x" "c".*}}
6161

6262
// SAN: {{"[^"]*clang-offload-packager[^"]*" "-o".* "--image=file=.*.bc,triple=amdgcn-amd-amdhsa,arch=gfx908(:xnack\-|:xnack\+)?,kind=openmp(,feature=(\-xnack|\+xnack))?"}}
63-
// SAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "-fopenmp-targets=amdgcn-amd-amdhsa".* "-x" "ir".*}}
63+
// SAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "--offload-targets=amdgcn-amd-amdhsa".* "-x" "ir".*}}
6464
// SAN: {{"[^"]*clang-linker-wrapper[^"]*".* "--host-triple=x86_64-unknown-linux-gnu".* "--linker-path=[^"]*".* "--whole-archive" "[^"]*(libclang_rt.asan_static.a|libclang_rt.asan_static-x86_64.a)".* "--whole-archive" "[^"]*(libclang_rt.asan.a|libclang_rt.asan-x86_64.a)".*}}

clang/test/Driver/hip-options.hip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
// RUN: not %clang --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
119119
// RUN: --offload-arch=gfx906 -fopenmp=libomp -fopenmp-targets=amdgcn %s 2>&1 \
120120
// RUN: | FileCheck -check-prefix=OMPTGT %s
121-
// OMPTGT: unsupported option '-fopenmp-targets=' for language mode 'HIP'
121+
// OMPTGT: unsupported option '--offload-targets=' for language mode 'HIP'
122122

123123
// Check -Xoffload-linker option is passed to lld.
124124

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ static bool parseOpenMPArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
12621262

12631263
// Get the OpenMP target triples if any.
12641264
if (auto *arg =
1265-
args.getLastArg(clang::driver::options::OPT_fopenmp_targets_EQ)) {
1265+
args.getLastArg(clang::driver::options::OPT_offload_targets_EQ)) {
12661266
enum ArchPtrSize { Arch16Bit, Arch32Bit, Arch64Bit };
12671267
auto getArchPtrSize = [](const llvm::Triple &triple) {
12681268
if (triple.isArch16Bit())

0 commit comments

Comments
 (0)