Skip to content

Commit 144c18c

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3396)
2 parents 09c0e6c + 8ad7614 commit 144c18c

File tree

21 files changed

+322
-105
lines changed

21 files changed

+322
-105
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/include/flang/Evaluate/tools.h

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,10 +1402,8 @@ using OperatorSet = common::EnumSet<Operator, 32>;
14021402

14031403
std::string ToString(Operator op);
14041404

1405-
template <typename... Ts, int Kind>
1406-
Operator OperationCode(
1407-
const evaluate::Operation<evaluate::LogicalOperation<Kind>, Ts...> &op) {
1408-
switch (op.derived().logicalOperator) {
1405+
template <int Kind> Operator OperationCode(const LogicalOperation<Kind> &op) {
1406+
switch (op.logicalOperator) {
14091407
case common::LogicalOperator::And:
14101408
return Operator::And;
14111409
case common::LogicalOperator::Or:
@@ -1420,10 +1418,10 @@ Operator OperationCode(
14201418
return Operator::Unknown;
14211419
}
14221420

1423-
template <typename T, typename... Ts>
1424-
Operator OperationCode(
1425-
const evaluate::Operation<evaluate::Relational<T>, Ts...> &op) {
1426-
switch (op.derived().opr) {
1421+
Operator OperationCode(const Relational<SomeType> &op);
1422+
1423+
template <typename T> Operator OperationCode(const Relational<T> &op) {
1424+
switch (op.opr) {
14271425
case common::RelationalOperator::LT:
14281426
return Operator::Lt;
14291427
case common::RelationalOperator::LE:
@@ -1440,70 +1438,60 @@ Operator OperationCode(
14401438
return Operator::Unknown;
14411439
}
14421440

1443-
template <typename T, typename... Ts>
1444-
Operator OperationCode(const evaluate::Operation<evaluate::Add<T>, Ts...> &op) {
1441+
template <typename T> Operator OperationCode(const Add<T> &op) {
14451442
return Operator::Add;
14461443
}
14471444

1448-
template <typename T, typename... Ts>
1449-
Operator OperationCode(
1450-
const evaluate::Operation<evaluate::Subtract<T>, Ts...> &op) {
1445+
template <typename T> Operator OperationCode(const Subtract<T> &op) {
14511446
return Operator::Sub;
14521447
}
14531448

1454-
template <typename T, typename... Ts>
1455-
Operator OperationCode(
1456-
const evaluate::Operation<evaluate::Multiply<T>, Ts...> &op) {
1449+
template <typename T> Operator OperationCode(const Multiply<T> &op) {
14571450
return Operator::Mul;
14581451
}
14591452

1460-
template <typename T, typename... Ts>
1461-
Operator OperationCode(
1462-
const evaluate::Operation<evaluate::Divide<T>, Ts...> &op) {
1453+
template <typename T> Operator OperationCode(const Divide<T> &op) {
14631454
return Operator::Div;
14641455
}
14651456

1466-
template <typename T, typename... Ts>
1467-
Operator OperationCode(
1468-
const evaluate::Operation<evaluate::Power<T>, Ts...> &op) {
1457+
template <typename T> Operator OperationCode(const Power<T> &op) {
14691458
return Operator::Pow;
14701459
}
14711460

1472-
template <typename T, typename... Ts>
1473-
Operator OperationCode(
1474-
const evaluate::Operation<evaluate::RealToIntPower<T>, Ts...> &op) {
1461+
template <typename T> Operator OperationCode(const RealToIntPower<T> &op) {
14751462
return Operator::Pow;
14761463
}
14771464

1478-
template <typename T, common::TypeCategory C, typename... Ts>
1479-
Operator OperationCode(
1480-
const evaluate::Operation<evaluate::Convert<T, C>, Ts...> &op) {
1465+
template <typename T, common::TypeCategory C>
1466+
Operator OperationCode(const Convert<T, C> &op) {
14811467
if constexpr (C == T::category) {
14821468
return Operator::Resize;
14831469
} else {
14841470
return Operator::Convert;
14851471
}
14861472
}
14871473

1488-
template <typename T, typename... Ts>
1489-
Operator OperationCode(
1490-
const evaluate::Operation<evaluate::Extremum<T>, Ts...> &op) {
1491-
if (op.derived().ordering == evaluate::Ordering::Greater) {
1474+
template <typename T> Operator OperationCode(const Extremum<T> &op) {
1475+
if (op.ordering == Ordering::Greater) {
14921476
return Operator::Max;
14931477
} else {
14941478
return Operator::Min;
14951479
}
14961480
}
14971481

1498-
template <typename T> Operator OperationCode(const evaluate::Constant<T> &x) {
1482+
template <typename T> Operator OperationCode(const Constant<T> &x) {
14991483
return Operator::Constant;
15001484
}
15011485

1486+
template <typename T> Operator OperationCode(const Designator<T> &x) {
1487+
return Operator::Identity;
1488+
}
1489+
15021490
template <typename T> Operator OperationCode(const T &) {
15031491
return Operator::Unknown;
15041492
}
15051493

1506-
Operator OperationCode(const evaluate::ProcedureDesignator &proc);
1494+
Operator OperationCode(const ProcedureDesignator &proc);
15071495

15081496
} // namespace operation
15091497

0 commit comments

Comments
 (0)