Skip to content

Commit 4aa2178

Browse files
committed
merge main into amd-staging
2 parents 26db529 + 6533ad0 commit 4aa2178

File tree

59 files changed

+782
-662
lines changed

Some content is hidden

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

59 files changed

+782
-662
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,12 +3216,12 @@ void tools::addOffloadCompressArgs(const llvm::opt::ArgList &TCArgs,
32163216
llvm::opt::ArgStringList &CmdArgs) {
32173217
if (TCArgs.hasFlag(options::OPT_offload_compress,
32183218
options::OPT_no_offload_compress, false))
3219-
CmdArgs.push_back("-compress");
3219+
CmdArgs.push_back("--compress");
32203220
if (TCArgs.hasArg(options::OPT_v))
3221-
CmdArgs.push_back("-verbose");
3221+
CmdArgs.push_back("--verbose");
32223222
if (auto *Arg = TCArgs.getLastArg(options::OPT_offload_compression_level_EQ))
32233223
CmdArgs.push_back(
3224-
TCArgs.MakeArgString(Twine("-compression-level=") + Arg->getValue()));
3224+
TCArgs.MakeArgString(Twine("--compression-level=") + Arg->getValue()));
32253225
}
32263226

32273227
void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "clang/Frontend/FrontendAction.h"
1010
#include "clang/AST/ASTConsumer.h"
1111
#include "clang/AST/ASTContext.h"
12+
#include "clang/AST/Decl.h"
1213
#include "clang/AST/DeclGroup.h"
1314
#include "clang/Basic/Builtins.h"
1415
#include "clang/Basic/DiagnosticOptions.h"
@@ -39,6 +40,7 @@
3940
#include "clang/Serialization/ASTReader.h"
4041
#include "clang/Serialization/GlobalModuleIndex.h"
4142
#include "llvm/ADT/ScopeExit.h"
43+
#include "llvm/ADT/SmallPtrSet.h"
4244
#include "llvm/ADT/StringRef.h"
4345
#include "llvm/Support/BuryPointer.h"
4446
#include "llvm/Support/ErrorHandling.h"
@@ -87,12 +89,25 @@ class DeserializedDeclsSourceRangePrinter : public ASTConsumer,
8789
// reducing the granularity and making the output less useful.
8890
return;
8991
}
90-
if (auto *DC = D->getDeclContext(); !DC || !DC->isFileContext()) {
92+
auto *DC = D->getLexicalDeclContext();
93+
if (!DC || !DC->isFileContext()) {
9194
// We choose to work at namespace level to reduce complexity and the
9295
// number of cases we care about.
9396
return;
9497
}
98+
9599
PendingDecls.push_back(D);
100+
if (auto *NS = dyn_cast<NamespaceDecl>(DC)) {
101+
// Add any namespaces we have not seen before.
102+
// Note that we filter out namespaces from DeclRead as it includes too
103+
// all redeclarations and we only want the ones that had other used
104+
// declarations.
105+
while (NS && ProcessedNamespaces.insert(NS).second) {
106+
PendingDecls.push_back(NS);
107+
108+
NS = dyn_cast<NamespaceDecl>(NS->getLexicalParent());
109+
}
110+
}
96111
}
97112

98113
struct Position {
@@ -141,23 +156,25 @@ class DeserializedDeclsSourceRangePrinter : public ASTConsumer,
141156
OptionalFileEntryRef Ref;
142157
};
143158
llvm::DenseMap<const FileEntry *, FileData> FileToRanges;
159+
144160
for (const Decl *D : PendingDecls) {
145-
CharSourceRange R = SM.getExpansionRange(D->getSourceRange());
146-
if (!R.isValid())
147-
continue;
161+
for (CharSourceRange R : getRangesToMark(D)) {
162+
if (!R.isValid())
163+
continue;
148164

149-
auto *F = SM.getFileEntryForID(SM.getFileID(R.getBegin()));
150-
if (F != SM.getFileEntryForID(SM.getFileID(R.getEnd()))) {
151-
// Such cases are rare and difficult to handle.
152-
continue;
153-
}
165+
auto *F = SM.getFileEntryForID(SM.getFileID(R.getBegin()));
166+
if (F != SM.getFileEntryForID(SM.getFileID(R.getEnd()))) {
167+
// Such cases are rare and difficult to handle.
168+
continue;
169+
}
154170

155-
auto &Data = FileToRanges[F];
156-
if (!Data.Ref)
157-
Data.Ref = SM.getFileEntryRefForID(SM.getFileID(R.getBegin()));
158-
Data.FromTo.push_back(
159-
{Position::GetBeginSpelling(SM, R),
160-
Position::GetEndSpelling(SM, R, D->getLangOpts())});
171+
auto &Data = FileToRanges[F];
172+
if (!Data.Ref)
173+
Data.Ref = SM.getFileEntryRefForID(SM.getFileID(R.getBegin()));
174+
Data.FromTo.push_back(
175+
{Position::GetBeginSpelling(SM, R),
176+
Position::GetEndSpelling(SM, R, D->getLangOpts())});
177+
}
161178
}
162179

163180
// To simplify output, merge consecutive and intersecting ranges.
@@ -188,10 +205,49 @@ class DeserializedDeclsSourceRangePrinter : public ASTConsumer,
188205

189206
private:
190207
std::vector<const Decl *> PendingDecls;
208+
llvm::SmallPtrSet<const NamespaceDecl *, 0> ProcessedNamespaces;
191209
bool IsCollectingDecls = true;
192210
const SourceManager &SM;
193211
std::unique_ptr<llvm::raw_ostream> OS;
194212

213+
llvm::SmallVector<CharSourceRange, 2> getRangesToMark(const Decl *D) {
214+
auto *NS = dyn_cast<NamespaceDecl>(D);
215+
if (!NS)
216+
return {SM.getExpansionRange(D->getSourceRange())};
217+
218+
SourceLocation LBraceLoc;
219+
if (NS->isAnonymousNamespace()) {
220+
LBraceLoc = NS->getLocation();
221+
} else {
222+
// Start with the location of the identifier.
223+
SourceLocation TokenBeforeLBrace = NS->getLocation();
224+
if (NS->hasAttrs()) {
225+
for (auto *A : NS->getAttrs()) {
226+
// But attributes may go after it.
227+
if (SM.isBeforeInTranslationUnit(TokenBeforeLBrace,
228+
A->getRange().getEnd())) {
229+
// Give up, the attributes are often coming from macros and we
230+
// cannot skip them reliably.
231+
return {};
232+
}
233+
}
234+
}
235+
auto &LangOpts = D->getLangOpts();
236+
// Now skip one token, the next should be the lbrace.
237+
Token Tok;
238+
if (Lexer::getRawToken(TokenBeforeLBrace, Tok, SM, LangOpts, true) ||
239+
Lexer::getRawToken(Tok.getEndLoc(), Tok, SM, LangOpts, true) ||
240+
Tok.getKind() != tok::l_brace) {
241+
// On error or if we did not find the token we expected, avoid marking
242+
// everything inside the namespace as used.
243+
return {};
244+
}
245+
LBraceLoc = Tok.getLocation();
246+
}
247+
return {SM.getExpansionRange(SourceRange(NS->getBeginLoc(), LBraceLoc)),
248+
SM.getExpansionRange(NS->getRBraceLoc())};
249+
}
250+
195251
void printJson(llvm::ArrayRef<RequiredRanges> Result) {
196252
*OS << "{\n";
197253
*OS << R"( "required_ranges": [)" << "\n";

clang/test/CodeGenOpenCL/amdgpu-features.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
// GFX1153: "target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot12-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
109109
// GFX1200: "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot11-insts,+dot12-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+fp8-conversion-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
110110
// GFX1201: "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot11-insts,+dot12-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+fp8-conversion-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
111-
// GFX1250: "target-features"="+16-bit-insts,+ashr-pk-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+bf16-cvt-insts,+bf16-trans-insts,+bitop3-insts,+ci-insts,+dl-insts,+dot7-insts,+dot8-insts,+dpp,+fp8-conversion-insts,+fp8e5m3-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx1250-insts,+gfx8-insts,+gfx9-insts,+permlane16-swap,+prng-inst,+setprio-inc-wg-inst,+tanh-insts,+transpose-load-f4f6-insts,+vmem-pref-insts,+wavefrontsize32
111+
// GFX1250: "target-features"="+16-bit-insts,+ashr-pk-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+bf16-cvt-insts,+bf16-trans-insts,+bitop3-insts,+ci-insts,+dl-insts,+dot7-insts,+dot8-insts,+dpp,+fp8-conversion-insts,+fp8e5m3-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx1250-insts,+gfx8-insts,+gfx9-insts,+permlane16-swap,+prng-inst,+setprio-inc-wg-inst,+tanh-insts,+transpose-load-f4f6-insts,+vmem-pref-insts,+wavefrontsize32"
112112

113113
// GFX1103-W64: "target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot12-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize64"
114114

clang/test/Driver/hip-offload-compress-zlib.hip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// CHECK: clang-offload-bundler{{.*}} -type=bc
1616
// CHECK-SAME: -targets={{.*}}hip-amdgcn-amd-amdhsa-unknown-gfx1100,hip-amdgcn-amd-amdhsa-unknown-gfx1101
17-
// CHECK-SAME: -compress -verbose -compression-level=9
17+
// CHECK-SAME: --compress --verbose --compression-level=9
1818
// CHECK: Compressed bundle format
1919

2020
// Test uncompress of bundled bitcode.
@@ -41,4 +41,4 @@
4141

4242
// CO: clang-offload-bundler{{.*}} "-type=o"
4343
// CO-SAME: -targets={{.*}}hipv4-amdgcn-amd-amdhsa--gfx1100,hipv4-amdgcn-amd-amdhsa--gfx1101
44-
// CO-SAME: "-compress" "-verbose"
44+
// CO-SAME: "--compress" "--verbose"

clang/test/Driver/hip-offload-compress-zstd.hip

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// CHECK: clang-offload-bundler{{.*}} -type=bc
1616
// CHECK-SAME: -targets={{.*}}hip-amdgcn-amd-amdhsa-unknown-gfx1100,hip-amdgcn-amd-amdhsa-unknown-gfx1101
17-
// CHECK-SAME: -compress -verbose -compression-level=9
17+
// CHECK-SAME: --compress --verbose --compression-level=9
1818
// CHECK: Compressed bundle format
1919

2020
// Test uncompress of bundled bitcode.
@@ -41,4 +41,16 @@
4141

4242
// CO: clang-offload-bundler{{.*}} "-type=o"
4343
// CO-SAME: -targets={{.*}}hipv4-amdgcn-amd-amdhsa--gfx1100,hipv4-amdgcn-amd-amdhsa--gfx1101
44-
// CO-SAME: "-compress" "-verbose"
44+
// CO-SAME: "--compress" "--verbose"
45+
46+
// RUN: rm -rf %t.bc
47+
// RUN: %clang -### -v --target=x86_64-linux-gnu \
48+
// RUN: -x hip --offload-arch=gfx1100 --offload-arch=gfx1101 \
49+
// RUN: --offload-new-driver -fgpu-rdc -nogpuinc -nogpulib \
50+
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
51+
// RUN: --offload-compress --offload-compression-level=9 \
52+
// RUN: --gpu-bundle-output \
53+
// RUN: -o %t.bc \
54+
// RUN: 2>&1 | FileCheck %s --check-prefix=NEWDRIVER
55+
56+
// NEWDRIVER: clang-linker-wrapper{{.*}}"--compress" "--verbose" "--compression-level=9"

clang/test/Frontend/dump-minimization-hints.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@
5959
// RANGE-NEXT: "line": 23,
6060
// RANGE-NEXT: "column": 2
6161
// RANGE-NEXT: }
62+
// RANGE-NEXT: },
63+
// RANGE-NEXT: {
64+
// RANGE-NEXT: "from": {
65+
// RANGE-NEXT: "line": 31,
66+
// RANGE-NEXT: "column": 1
67+
// RANGE-NEXT: },
68+
// RANGE-NEXT: "to": {
69+
// RANGE-NEXT: "line": 31,
70+
// RANGE-NEXT: "column": 27
71+
// RANGE-NEXT: }
72+
// RANGE-NEXT: },
73+
// RANGE-NEXT: {
74+
// RANGE-NEXT: "from": {
75+
// RANGE-NEXT: "line": 32,
76+
// RANGE-NEXT: "column": 3
77+
// RANGE-NEXT: },
78+
// RANGE-NEXT: "to": {
79+
// RANGE-NEXT: "line": 32,
80+
// RANGE-NEXT: "column": 12
81+
// RANGE-NEXT: }
82+
// RANGE-NEXT: },
83+
// RANGE-NEXT: {
84+
// RANGE-NEXT: "from": {
85+
// RANGE-NEXT: "line": 34,
86+
// RANGE-NEXT: "column": 1
87+
// RANGE-NEXT: },
88+
// RANGE-NEXT: "to": {
89+
// RANGE-NEXT: "line": 34,
90+
// RANGE-NEXT: "column": 2
91+
// RANGE-NEXT: }
6292
// RANGE-NEXT: }
6393
// RANGE-NEXT: ]
6494
// RANGE-NEXT: }
@@ -88,7 +118,7 @@ int multiply(int a, int b) {
88118
return a * b;
89119
}
90120

91-
inline int unused_by_foo() {} // line 17
121+
inline void unused_by_foo() {} // line 17
92122

93123
inline void recursively_used_by_foo() {} // line 19
94124
inline int used_by_foo() { // line 20
@@ -98,6 +128,20 @@ inline int used_by_foo() { // line 20
98128

99129
struct UnusedByFoo {};
100130

131+
namespace ns_unused_by_foo {
132+
void x();
133+
}
134+
135+
namespace ns_used_by_foo { // line 31
136+
void x(); // line 32
137+
void unused_y();
138+
} // line 34
139+
140+
// Does not have any declarations that are used, so
141+
// will not be marked as used.
142+
namespace ns_used_by_foo {
143+
void unused_z();
144+
}
101145
//--- foo.cpp
102146
#include "foo.h"
103147
int global_value = 5;
@@ -107,5 +151,6 @@ int main() {
107151
int doubled_value = multiply(current_value, 2);
108152
int final_result = doubled_value + global_value;
109153

110-
return used_by_foo();
154+
used_by_foo();
155+
ns_used_by_foo::x();
111156
}

flang/examples/FeatureList/FeatureList.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,9 @@ struct NodeVisitor {
445445
READ_FEATURE(ObjectDecl)
446446
READ_FEATURE(OldParameterStmt)
447447
READ_FEATURE(OmpAlignedClause)
448-
READ_FEATURE(OmpBeginBlockDirective)
448+
READ_FEATURE(OmpBeginDirective)
449449
READ_FEATURE(OmpBeginLoopDirective)
450450
READ_FEATURE(OmpBeginSectionsDirective)
451-
READ_FEATURE(OmpBlockDirective)
452451
READ_FEATURE(OmpClause)
453452
READ_FEATURE(OmpClauseList)
454453
READ_FEATURE(OmpCriticalDirective)
@@ -472,7 +471,7 @@ struct NodeVisitor {
472471
READ_FEATURE(OmpIteration)
473472
READ_FEATURE(OmpIterationOffset)
474473
READ_FEATURE(OmpIterationVector)
475-
READ_FEATURE(OmpEndBlockDirective)
474+
READ_FEATURE(OmpEndDirective)
476475
READ_FEATURE(OmpEndCriticalDirective)
477476
READ_FEATURE(OmpEndLoopDirective)
478477
READ_FEATURE(OmpEndSectionsDirective)

0 commit comments

Comments
 (0)