Skip to content

Commit 7e7c135

Browse files
authored
Merge pull request llvm#633 from AMD-Lightning-Internal/amd/merge/upstream_merge_20250212191148
merge main into amd-staging
2 parents f5acae8 + f8ad521 commit 7e7c135

File tree

638 files changed

+34351
-32802
lines changed

Some content is hidden

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

638 files changed

+34351
-32802
lines changed

.github/workflows/release-binaries-all.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ on:
2727
required: true
2828
default: false
2929
type: boolean
30+
secrets:
31+
RELEASE_TASKS_USER_TOKEN:
32+
description: "Secret used to check user permissions."
33+
required: false
3034

3135
pull_request:
3236
types:

bolt/include/bolt/Core/BinarySection.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,9 @@ class BinarySection {
359359

360360
/// Add a new relocation at the given /p Offset.
361361
void addRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,
362-
uint64_t Addend, uint64_t Value = 0,
363-
bool Pending = false) {
362+
uint64_t Addend, uint64_t Value = 0) {
364363
assert(Offset < getSize() && "offset not within section bounds");
365-
if (!Pending) {
366-
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
367-
} else {
368-
PendingRelocations.emplace_back(
369-
Relocation{Offset, Symbol, Type, Addend, Value});
370-
}
364+
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
371365
}
372366

373367
/// Add a dynamic relocation at the given /p Offset.

bolt/unittests/Core/BinaryContext.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ TEST_P(BinaryContextTester, FlushPendingRelocCALL26) {
9393
DataSize, 4);
9494
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
9595
ASSERT_TRUE(RelSymbol1);
96-
BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0, true);
96+
BS.addPendingRelocation(
97+
Relocation{8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0});
9798
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
9899
ASSERT_TRUE(RelSymbol2);
99-
BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0, true);
100+
BS.addPendingRelocation(
101+
Relocation{12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0});
100102

101-
std::error_code EC;
102103
SmallVector<char> Vect(DataSize);
103104
raw_svector_ostream OS(Vect);
104105

@@ -134,12 +135,13 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
134135
(uint8_t *)Data, Size, 4);
135136
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
136137
ASSERT_TRUE(RelSymbol1);
137-
BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0, true);
138+
BS.addPendingRelocation(
139+
Relocation{8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0});
138140
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
139141
ASSERT_TRUE(RelSymbol2);
140-
BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0, true);
142+
BS.addPendingRelocation(
143+
Relocation{12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0});
141144

142-
std::error_code EC;
143145
SmallVector<char> Vect(Size);
144146
raw_svector_ostream OS(Vect);
145147

clang/cmake/modules/AddClang.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ macro(add_clang_library name)
138138
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
139139
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
140140

141-
if (LLVM_ENABLE_PDB)
142-
install(FILES $<TARGET_PDB_FILE:${name}> DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name} OPTIONAL)
143-
endif()
144-
145141
if (NOT LLVM_ENABLE_IDE)
146142
add_llvm_install_targets(install-${lib}
147143
DEPENDS ${lib}

clang/docs/HLSL/FunctionCalls.rst

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,14 @@ which is a term made up for HLSL. A cx-value is a temporary value which may be
248248
the result of a cast, and stores its value back to an lvalue when the value
249249
expires.
250250

251-
To represent this concept in Clang we introduce a new ``HLSLOutParamExpr``. An
252-
``HLSLOutParamExpr`` has two forms, one with a single sub-expression and one
253-
with two sub-expressions.
251+
To represent this concept in Clang we introduce a new ``HLSLOutArgExpr``. An
252+
``HLSLOutArgExpr`` has three sub-expressions:
254253

255-
The single sub-expression form is used when the argument expression and the
256-
function parameter are the same type, so no cast is required. As in this
257-
example:
254+
* An OpaqueValueExpr of the argument lvalue expression.
255+
* An OpaqueValueExpr of the copy-initialized parameter temporary.
256+
* A BinaryOpExpr assigning the first with the value of the second.
257+
258+
Given this example:
258259

259260
.. code-block:: c++
260261

@@ -267,23 +268,36 @@ example:
267268
Init(V);
268269
}
269270

270-
The expected AST formulation for this code would be something like:
271+
The expected AST formulation for this code would be something like the example
272+
below. Due to the nature of OpaqueValueExpr nodes, the nodes repeat in the AST
273+
dump. The fake addresses ``0xSOURCE`` and ``0xTEMPORARY`` denote the source
274+
lvalue and argument temporary lvalue expressions.
271275

272276
.. code-block:: text
273277
274278
CallExpr 'void'
275279
|-ImplicitCastExpr 'void (*)(int &)' <FunctionToPointerDecay>
276280
| `-DeclRefExpr 'void (int &)' lvalue Function 'Init' 'void (int &)'
277-
|-HLSLOutParamExpr 'int' lvalue inout
278-
`-DeclRefExpr 'int' lvalue Var 'V' 'int'
279-
280-
The ``HLSLOutParamExpr`` captures that the value is ``inout`` vs ``out`` to
281-
denote whether or not the temporary is initialized from the sub-expression. If
282-
no casting is required the sub-expression denotes the lvalue expression that the
283-
cx-value will be copied to when the value expires.
284-
285-
The two sub-expression form of the AST node is required when the argument type
286-
is not the same as the parameter type. Given this example:
281+
`-HLSLOutArgExpr <col:10> 'int' lvalue inout
282+
|-OpaqueValueExpr 0xSOURCE <col:10> 'int' lvalue
283+
| `-DeclRefExpr <col:10> 'int' lvalue Var 'V' 'int'
284+
|-OpaqueValueExpr 0xTEMPORARY <col:10> 'int' lvalue
285+
| `-ImplicitCastExpr <col:10> 'int' <LValueToRValue>
286+
| `-OpaqueValueExpr 0xSOURCE <col:10> 'int' lvalue
287+
| `-DeclRefExpr <col:10> 'int' lvalue Var 'V' 'int'
288+
`-BinaryOperator <col:10> 'int' lvalue '='
289+
|-OpaqueValueExpr 0xSOURCE <col:10> 'int' lvalue
290+
| `-DeclRefExpr <col:10> 'int' lvalue Var 'V' 'int'
291+
`-ImplicitCastExpr <col:10> 'int' <LValueToRValue>
292+
`-OpaqueValueExpr 0xTEMPORARY <col:10> 'int' lvalue
293+
`-ImplicitCastExpr <col:10> 'int' <LValueToRValue>
294+
`-OpaqueValueExpr 0xSOURCE <col:10> 'int' lvalue
295+
`-DeclRefExpr <col:10> 'int' lvalue Var 'V' 'int'
296+
297+
The ``HLSLOutArgExpr`` captures that the value is ``inout`` vs ``out`` to
298+
denote whether or not the temporary is initialized from the sub-expression.
299+
300+
The example below demonstrates argument casting:
287301

288302
.. code-block:: c++
289303

@@ -295,28 +309,39 @@ is not the same as the parameter type. Given this example:
295309
Trunc(F);
296310
}
297311

298-
For this case the ``HLSLOutParamExpr`` will have sub-expressions to record both
312+
For this case the ``HLSLOutArgExpr`` will have sub-expressions to record both
299313
casting expression sequences for the initialization and write back:
300314

301315
.. code-block:: text
302316
303317
-CallExpr 'void'
304318
|-ImplicitCastExpr 'void (*)(int3 &)' <FunctionToPointerDecay>
305319
| `-DeclRefExpr 'void (int3 &)' lvalue Function 'inc_i32' 'void (int3 &)'
306-
`-HLSLOutParamExpr 'int3' lvalue inout
307-
|-ImplicitCastExpr 'float3' <IntegralToFloating>
308-
| `-ImplicitCastExpr 'int3' <LValueToRValue>
309-
| `-OpaqueValueExpr 'int3' lvalue
310-
`-ImplicitCastExpr 'int3' <FloatingToIntegral>
311-
`-ImplicitCastExpr 'float3' <LValueToRValue>
312-
`-DeclRefExpr 'float3' lvalue 'F' 'float3'
313-
314-
In this formation the write-back casts are captured as the first sub-expression
315-
and they cast from an ``OpaqueValueExpr``. In IR generation we can use the
316-
``OpaqueValueExpr`` as a placeholder for the ``HLSLOutParamExpr``'s temporary
317-
value on function return.
318-
319-
In code generation this can be implemented with some targeted extensions to the
320-
Objective-C write-back support. Specifically extending CGCall.cpp's
321-
``EmitWriteback`` function to support casting expressions and emission of
322-
aggregate lvalues.
320+
`-HLSLOutArgExpr <col:11> 'int3':'vector<int, 3>' lvalue inout
321+
|-OpaqueValueExpr 0xSOURCE <col:11> 'float3':'vector<float, 3>' lvalue
322+
| `-DeclRefExpr <col:11> 'float3':'vector<float, 3>' lvalue Var 'F' 'float3':'vector<float, 3>'
323+
|-OpaqueValueExpr 0xTEMPORARY <col:11> 'int3':'vector<int, 3>' lvalue
324+
| `-ImplicitCastExpr <col:11> 'vector<int, 3>' <FloatingToIntegral>
325+
| `-ImplicitCastExpr <col:11> 'float3':'vector<float, 3>' <LValueToRValue>
326+
| `-OpaqueValueExpr 0xSOURCE <col:11> 'float3':'vector<float, 3>' lvalue
327+
| `-DeclRefExpr <col:11> 'float3':'vector<float, 3>' lvalue Var 'F' 'float3':'vector<float, 3>'
328+
`-BinaryOperator <col:11> 'float3':'vector<float, 3>' lvalue '='
329+
|-OpaqueValueExpr 0xSOURCE <col:11> 'float3':'vector<float, 3>' lvalue
330+
| `-DeclRefExpr <col:11> 'float3':'vector<float, 3>' lvalue Var 'F' 'float3':'vector<float, 3>'
331+
`-ImplicitCastExpr <col:11> 'vector<float, 3>' <IntegralToFloating>
332+
`-ImplicitCastExpr <col:11> 'int3':'vector<int, 3>' <LValueToRValue>
333+
`-OpaqueValueExpr 0xTEMPORARY <col:11> 'int3':'vector<int, 3>' lvalue
334+
`-ImplicitCastExpr <col:11> 'vector<int, 3>' <FloatingToIntegral>
335+
`-ImplicitCastExpr <col:11> 'float3':'vector<float, 3>' <LValueToRValue>
336+
`-OpaqueValueExpr 0xSOURCE <col:11> 'float3':'vector<float, 3>' lvalue
337+
`-DeclRefExpr <col:11> 'float3':'vector<float, 3>' lvalue Var 'F' 'float3':'vector<float, 3>'
338+
339+
The AST representation is the same whether casting is required or not, which
340+
simplifies the code generation. IR generation does the following:
341+
342+
* Emit the argument lvalue expression.
343+
* Initialize the argument:
344+
* For ``inout`` arguments, emit the copy-initialization expression.
345+
* For ``out`` arguments, emit an uninitialized temporary.
346+
* Emit the call
347+
* Emit the write-back BinaryOperator expression.

clang/include/clang/AST/Mangle.h

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,29 @@
2222
#include <optional>
2323

2424
namespace llvm {
25-
class raw_ostream;
25+
class raw_ostream;
2626
}
2727

2828
namespace clang {
29-
class ASTContext;
30-
class BlockDecl;
31-
class CXXConstructorDecl;
32-
class CXXDestructorDecl;
33-
class CXXMethodDecl;
34-
class FunctionDecl;
35-
struct MethodVFTableLocation;
36-
class NamedDecl;
37-
class ObjCMethodDecl;
38-
class StringLiteral;
39-
struct ThisAdjustment;
40-
struct ThunkInfo;
41-
class VarDecl;
29+
class ASTContext;
30+
class BlockDecl;
31+
class CXXConstructorDecl;
32+
class CXXDestructorDecl;
33+
class CXXMethodDecl;
34+
class FunctionDecl;
35+
struct MethodVFTableLocation;
36+
class NamedDecl;
37+
class ObjCMethodDecl;
38+
class StringLiteral;
39+
struct ThisAdjustment;
40+
struct ThunkInfo;
41+
class VarDecl;
4242

4343
/// MangleContext - Context for tracking state which persists across multiple
4444
/// calls to the C++ name mangler.
4545
class MangleContext {
4646
public:
47-
enum ManglerKind {
48-
MK_Itanium,
49-
MK_Microsoft
50-
};
47+
enum ManglerKind { MK_Itanium, MK_Microsoft };
5148

5249
private:
5350
virtual void anchor();
@@ -59,10 +56,10 @@ class MangleContext {
5956
/// ASTContext.
6057
bool IsAux = false;
6158

62-
llvm::DenseMap<const BlockDecl*, unsigned> GlobalBlockIds;
63-
llvm::DenseMap<const BlockDecl*, unsigned> LocalBlockIds;
64-
llvm::DenseMap<const NamedDecl*, uint64_t> AnonStructIds;
65-
llvm::DenseMap<const FunctionDecl*, unsigned> FuncAnonStructSize;
59+
llvm::DenseMap<const BlockDecl *, unsigned> GlobalBlockIds;
60+
llvm::DenseMap<const BlockDecl *, unsigned> LocalBlockIds;
61+
llvm::DenseMap<const NamedDecl *, uint64_t> AnonStructIds;
62+
llvm::DenseMap<const FunctionDecl *, unsigned> FuncAnonStructSize;
6663

6764
public:
6865
ManglerKind getKind() const { return Kind; }
@@ -73,7 +70,7 @@ class MangleContext {
7370
ManglerKind Kind, bool IsAux = false)
7471
: Context(Context), Diags(Diags), Kind(Kind), IsAux(IsAux) {}
7572

76-
virtual ~MangleContext() { }
73+
virtual ~MangleContext() {}
7774

7875
ASTContext &getASTContext() const { return Context; }
7976

@@ -82,10 +79,10 @@ class MangleContext {
8279
virtual void startNewFunction() { LocalBlockIds.clear(); }
8380

8481
unsigned getBlockId(const BlockDecl *BD, bool Local) {
85-
llvm::DenseMap<const BlockDecl *, unsigned> &BlockIds
86-
= Local? LocalBlockIds : GlobalBlockIds;
82+
llvm::DenseMap<const BlockDecl *, unsigned> &BlockIds =
83+
Local ? LocalBlockIds : GlobalBlockIds;
8784
std::pair<llvm::DenseMap<const BlockDecl *, unsigned>::iterator, bool>
88-
Result = BlockIds.insert(std::make_pair(BD, BlockIds.size()));
85+
Result = BlockIds.insert(std::make_pair(BD, BlockIds.size()));
8986
return Result.first->second;
9087
}
9188

@@ -125,7 +122,7 @@ class MangleContext {
125122
return false;
126123
}
127124

128-
virtual void needsUniqueInternalLinkageNames() { }
125+
virtual void needsUniqueInternalLinkageNames() {}
129126

130127
// FIXME: consider replacing raw_ostream & with something like SmallString &.
131128
void mangleName(GlobalDecl GD, raw_ostream &);
@@ -143,10 +140,9 @@ class MangleContext {
143140
virtual void mangleCXXRTTIName(QualType T, raw_ostream &,
144141
bool NormalizeIntegers = false) = 0;
145142
virtual void mangleStringLiteral(const StringLiteral *SL, raw_ostream &) = 0;
146-
virtual void mangleMSGuidDecl(const MSGuidDecl *GD, raw_ostream&);
143+
virtual void mangleMSGuidDecl(const MSGuidDecl *GD, raw_ostream &);
147144

148-
void mangleGlobalBlock(const BlockDecl *BD,
149-
const NamedDecl *ID,
145+
void mangleGlobalBlock(const BlockDecl *BD, const NamedDecl *ID,
150146
raw_ostream &Out);
151147
void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT,
152148
const BlockDecl *BD, raw_ostream &Out);
@@ -314,6 +310,6 @@ class ASTNameGenerator {
314310
class Implementation;
315311
std::unique_ptr<Implementation> Impl;
316312
};
317-
}
313+
} // namespace clang
318314

319315
#endif

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3403,7 +3403,7 @@ def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group<f_Group>,
34033403
def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, Group<f_Group>,
34043404
Visibility<[ClangOption, FlangOption]>;
34053405
defm operator_names : BoolFOption<"operator-names",
3406-
LangOpts<"CXXOperatorNames">, Default<cplusplus.KeyPath>,
3406+
LangOpts<"CXXOperatorNames">, Default<!strconcat(cplusplus.KeyPath, " && !",hlsl.KeyPath)>,
34073407
NegFlag<SetFalse, [], [ClangOption, CC1Option],
34083408
"Do not treat C++ operator name keywords as synonyms for operators">,
34093409
PosFlag<SetTrue>>;

clang/lib/Analysis/LiveVariables.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#include "clang/Analysis/AnalysisDeclContext.h"
1717
#include "clang/Analysis/CFG.h"
1818
#include "clang/Analysis/FlowSensitive/DataflowWorklist.h"
19+
#include "clang/Basic/SourceManager.h"
1920
#include "llvm/ADT/DenseMap.h"
21+
#include "llvm/ADT/STLExtras.h"
2022
#include "llvm/Support/raw_ostream.h"
2123
#include <algorithm>
2224
#include <optional>
@@ -662,12 +664,19 @@ void LiveVariables::dumpExprLiveness(const SourceManager &M) {
662664
}
663665

664666
void LiveVariablesImpl::dumpExprLiveness(const SourceManager &M) {
667+
auto ByBeginLoc = [&M](const Expr *L, const Expr *R) {
668+
return M.isBeforeInTranslationUnit(L->getBeginLoc(), R->getBeginLoc());
669+
};
670+
665671
// Don't iterate over blockEndsToLiveness directly because it's not sorted.
666672
for (const CFGBlock *B : *analysisContext.getCFG()) {
667673

668674
llvm::errs() << "\n[ B" << B->getBlockID()
669675
<< " (live expressions at block exit) ]\n";
670-
for (const Expr *E : blocksEndToLiveness[B].liveExprs) {
676+
std::vector<const Expr *> LiveExprs;
677+
llvm::append_range(LiveExprs, blocksEndToLiveness[B].liveExprs);
678+
llvm::sort(LiveExprs, ByBeginLoc);
679+
for (const Expr *E : LiveExprs) {
671680
llvm::errs() << "\n";
672681
E->dump();
673682
}

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) {
5454
auto *DXILValMD = M.getOrInsertNamedMetadata(DXILValKey);
5555
DXILValMD->addOperand(Val);
5656
}
57-
void addDisableOptimizations(llvm::Module &M) {
58-
StringRef Key = "dx.disable_optimizations";
59-
M.addModuleFlag(llvm::Module::ModFlagBehavior::Override, Key, 1);
60-
}
6157
// cbuffer will be translated into global variable in special address space.
6258
// If translate into C,
6359
// cbuffer A {
@@ -171,8 +167,6 @@ void CGHLSLRuntime::finishCodeGen() {
171167
addDxilValVersion(TargetOpts.DxilValidatorVersion, M);
172168

173169
generateGlobalCtorDtorCalls();
174-
if (CGM.getCodeGenOpts().OptimizationLevel == 0)
175-
addDisableOptimizations(M);
176170

177171
const DataLayout &DL = M.getDataLayout();
178172

0 commit comments

Comments
 (0)