Skip to content

Commit f9257e6

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:15d9d0fa8f55936625882a28759f0ec0033cb6de into amd-gfx:df9c746d9591
Local branch amd-gfx df9c746 Merged main:37daff028fcec27f2be1bb990df77e19c0244ccf into amd-gfx:2c4204e0a79d Remote branch main 15d9d0f [VPlan] Also print final VPlan directly before codegen/execute. (llvm#82269)
2 parents df9c746 + 15d9d0f commit f9257e6

File tree

32 files changed

+628
-103
lines changed

32 files changed

+628
-103
lines changed

clang/docs/LibASTMatchersReference.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7049,7 +7049,7 @@ <h2 id="traversal-matchers">AST Traversal Matchers</h2>
70497049
</pre></td></tr>
70507050

70517051

7052-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>&gt;</td><td class="name" onclick="toggle('hasFoldInit0')"><a name="hasFoldInit0Anchor">hasFoldInit</a></td><td>ast_matchers::Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMacher</td></tr>
7052+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>&gt;</td><td class="name" onclick="toggle('hasFoldInit0')"><a name="hasFoldInit0Anchor">hasFoldInit</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMacher</td></tr>
70537053
<tr><td colspan="4" class="doc" id="hasFoldInit0"><pre>Matches the operand that does not contain the parameter pack.
70547054

70557055
Example matches `(0 + ... + args)` and `(args * ... * 1)`
@@ -7089,7 +7089,7 @@ <h2 id="traversal-matchers">AST Traversal Matchers</h2>
70897089
</pre></td></tr>
70907090

70917091

7092-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>&gt;</td><td class="name" onclick="toggle('hasPattern0')"><a name="hasPattern0Anchor">hasPattern</a></td><td>ast_matchers::Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMacher</td></tr>
7092+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>&gt;</td><td class="name" onclick="toggle('hasPattern0')"><a name="hasPattern0Anchor">hasPattern</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMacher</td></tr>
70937093
<tr><td colspan="4" class="doc" id="hasPattern0"><pre>Matches the operand that contains the parameter pack.
70947094

70957095
Example matches `(0 + ... + args)`
@@ -7859,7 +7859,7 @@ <h2 id="traversal-matchers">AST Traversal Matchers</h2>
78597859
</pre></td></tr>
78607860

78617861

7862-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>&gt;</td><td class="name" onclick="toggle('forEachTemplateArgument0')"><a name="forEachTemplateArgument0Anchor">forEachTemplateArgument</a></td><td>clang::ast_matchers::Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
7862+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>&gt;</td><td class="name" onclick="toggle('forEachTemplateArgument0')"><a name="forEachTemplateArgument0Anchor">forEachTemplateArgument</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
78637863
<tr><td colspan="4" class="doc" id="forEachTemplateArgument0"><pre>Matches classTemplateSpecialization, templateSpecializationType and
78647864
functionDecl nodes where the template argument matches the inner matcher.
78657865
This matcher may produce multiple matches.
@@ -8454,7 +8454,7 @@ <h2 id="traversal-matchers">AST Traversal Matchers</h2>
84548454
</pre></td></tr>
84558455

84568456

8457-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('ignoringElidableConstructorCall0')"><a name="ignoringElidableConstructorCall0Anchor">ignoringElidableConstructorCall</a></td><td>ast_matchers::Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
8457+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</td><td class="name" onclick="toggle('ignoringElidableConstructorCall0')"><a name="ignoringElidableConstructorCall0Anchor">ignoringElidableConstructorCall</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
84588458
<tr><td colspan="4" class="doc" id="ignoringElidableConstructorCall0"><pre>Matches expressions that match InnerMatcher that are possibly wrapped in an
84598459
elidable constructor and other corresponding bookkeeping nodes.
84608460

@@ -8691,7 +8691,7 @@ <h2 id="traversal-matchers">AST Traversal Matchers</h2>
86918691
</pre></td></tr>
86928692

86938693

8694-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('forEachTemplateArgument2')"><a name="forEachTemplateArgument2Anchor">forEachTemplateArgument</a></td><td>clang::ast_matchers::Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
8694+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('forEachTemplateArgument2')"><a name="forEachTemplateArgument2Anchor">forEachTemplateArgument</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
86958695
<tr><td colspan="4" class="doc" id="forEachTemplateArgument2"><pre>Matches classTemplateSpecialization, templateSpecializationType and
86968696
functionDecl nodes where the template argument matches the inner matcher.
86978697
This matcher may produce multiple matches.
@@ -8959,7 +8959,7 @@ <h2 id="traversal-matchers">AST Traversal Matchers</h2>
89598959
</pre></td></tr>
89608960

89618961

8962-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>&gt;</td><td class="name" onclick="toggle('hasInit0')"><a name="hasInit0Anchor">hasInit</a></td><td>unsigned N, ast_matchers::Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
8962+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>&gt;</td><td class="name" onclick="toggle('hasInit0')"><a name="hasInit0Anchor">hasInit</a></td><td>unsigned N, Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
89638963
<tr><td colspan="4" class="doc" id="hasInit0"><pre>Matches the n'th item of an initializer list expression.
89648964

89658965
Example matches y.
@@ -10026,7 +10026,7 @@ <h2 id="traversal-matchers">AST Traversal Matchers</h2>
1002610026
</pre></td></tr>
1002710027

1002810028

10029-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>&gt;</td><td class="name" onclick="toggle('forEachTemplateArgument1')"><a name="forEachTemplateArgument1Anchor">forEachTemplateArgument</a></td><td>clang::ast_matchers::Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
10029+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>&gt;</td><td class="name" onclick="toggle('forEachTemplateArgument1')"><a name="forEachTemplateArgument1Anchor">forEachTemplateArgument</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>&gt; InnerMatcher</td></tr>
1003010030
<tr><td colspan="4" class="doc" id="forEachTemplateArgument1"><pre>Matches classTemplateSpecialization, templateSpecializationType and
1003110031
functionDecl nodes where the template argument matches the inner matcher.
1003210032
This matcher may produce multiple matches.

clang/docs/tools/dump_ast_matchers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def strip_doxygen(comment):
116116

117117
def unify_arguments(args):
118118
"""Gets rid of anything the user doesn't care about in the argument list."""
119+
args = re.sub(r"clang::ast_matchers::internal::", r"", args)
120+
args = re.sub(r"ast_matchers::internal::", r"", args)
119121
args = re.sub(r"internal::", r"", args)
120122
args = re.sub(r"extern const\s+(.*)&", r"\1 ", args)
121123
args = re.sub(r"&", r" ", args)

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4580,8 +4580,7 @@ AST_POLYMORPHIC_MATCHER_P2(hasArgument,
45804580
/// return (args * ... * 1);
45814581
/// }
45824582
/// \endcode
4583-
AST_MATCHER_P(CXXFoldExpr, hasFoldInit, ast_matchers::internal::Matcher<Expr>,
4584-
InnerMacher) {
4583+
AST_MATCHER_P(CXXFoldExpr, hasFoldInit, internal::Matcher<Expr>, InnerMacher) {
45854584
const auto *const Init = Node.getInit();
45864585
return Init && InnerMacher.matches(*Init, Finder, Builder);
45874586
}
@@ -4603,8 +4602,7 @@ AST_MATCHER_P(CXXFoldExpr, hasFoldInit, ast_matchers::internal::Matcher<Expr>,
46034602
/// return (args * ... * 1);
46044603
/// }
46054604
/// \endcode
4606-
AST_MATCHER_P(CXXFoldExpr, hasPattern, ast_matchers::internal::Matcher<Expr>,
4607-
InnerMacher) {
4605+
AST_MATCHER_P(CXXFoldExpr, hasPattern, internal::Matcher<Expr>, InnerMacher) {
46084606
const Expr *const Pattern = Node.getPattern();
46094607
return Pattern && InnerMacher.matches(*Pattern, Finder, Builder);
46104608
}
@@ -4685,8 +4683,8 @@ AST_MATCHER(CXXFoldExpr, isBinaryFold) { return Node.getInit() != nullptr; }
46854683
/// \code
46864684
/// int x{y}.
46874685
/// \endcode
4688-
AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N,
4689-
ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
4686+
AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N, internal::Matcher<Expr>,
4687+
InnerMatcher) {
46904688
return N < Node.getNumInits() &&
46914689
InnerMatcher.matches(*Node.getInit(N), Finder, Builder);
46924690
}
@@ -5309,7 +5307,7 @@ AST_POLYMORPHIC_MATCHER_P(
53095307
forEachTemplateArgument,
53105308
AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,
53115309
TemplateSpecializationType, FunctionDecl),
5312-
clang::ast_matchers::internal::Matcher<TemplateArgument>, InnerMatcher) {
5310+
internal::Matcher<TemplateArgument>, InnerMatcher) {
53135311
ArrayRef<TemplateArgument> TemplateArgs =
53145312
clang::ast_matchers::internal::getTemplateSpecializationArgs(Node);
53155313
clang::ast_matchers::internal::BoundNodesTreeBuilder Result;
@@ -8525,8 +8523,8 @@ AST_MATCHER(FunctionDecl, hasTrailingReturn) {
85258523
///
85268524
/// ``varDecl(hasInitializer(ignoringElidableConstructorCall(callExpr())))``
85278525
/// matches ``H D = G()`` in C++11 through C++17 (and beyond).
8528-
AST_MATCHER_P(Expr, ignoringElidableConstructorCall,
8529-
ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
8526+
AST_MATCHER_P(Expr, ignoringElidableConstructorCall, internal::Matcher<Expr>,
8527+
InnerMatcher) {
85308528
// E tracks the node that we are examining.
85318529
const Expr *E = &Node;
85328530
// If present, remove an outer `ExprWithCleanups` corresponding to the

clang/lib/CodeGen/CGCall.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,12 +3221,11 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
32213221

32223222
llvm::StructType *STy =
32233223
dyn_cast<llvm::StructType>(ArgI.getCoerceToType());
3224-
llvm::TypeSize StructSize;
3225-
llvm::TypeSize PtrElementSize;
32263224
if (ArgI.isDirect() && !ArgI.getCanBeFlattened() && STy &&
32273225
STy->getNumElements() > 1) {
3228-
StructSize = CGM.getDataLayout().getTypeAllocSize(STy);
3229-
PtrElementSize =
3226+
[[maybe_unused]] llvm::TypeSize StructSize =
3227+
CGM.getDataLayout().getTypeAllocSize(STy);
3228+
[[maybe_unused]] llvm::TypeSize PtrElementSize =
32303229
CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(Ty));
32313230
if (STy->containsHomogeneousScalableVectorTypes()) {
32323231
assert(StructSize == PtrElementSize &&
@@ -5310,12 +5309,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
53105309

53115310
llvm::StructType *STy =
53125311
dyn_cast<llvm::StructType>(ArgInfo.getCoerceToType());
5313-
llvm::Type *SrcTy = ConvertTypeForMem(I->Ty);
5314-
llvm::TypeSize SrcTypeSize;
5315-
llvm::TypeSize DstTypeSize;
53165312
if (STy && ArgInfo.isDirect() && !ArgInfo.getCanBeFlattened()) {
5317-
SrcTypeSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
5318-
DstTypeSize = CGM.getDataLayout().getTypeAllocSize(STy);
5313+
llvm::Type *SrcTy = ConvertTypeForMem(I->Ty);
5314+
[[maybe_unused]] llvm::TypeSize SrcTypeSize =
5315+
CGM.getDataLayout().getTypeAllocSize(SrcTy);
5316+
[[maybe_unused]] llvm::TypeSize DstTypeSize =
5317+
CGM.getDataLayout().getTypeAllocSize(STy);
53195318
if (STy->containsHomogeneousScalableVectorTypes()) {
53205319
assert(SrcTypeSize == DstTypeSize &&
53215320
"Only allow non-fractional movement of structure with "

flang/include/flang/Lower/AbstractConverter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "flang/Common/Fortran.h"
1717
#include "flang/Lower/LoweringOptions.h"
1818
#include "flang/Lower/PFTDefs.h"
19-
#include "flang/Lower/SymbolMap.h"
2019
#include "flang/Optimizer/Builder/BoxValue.h"
2120
#include "flang/Semantics/symbol.h"
2221
#include "mlir/IR/Builders.h"
@@ -54,6 +53,7 @@ class DerivedTypeSpec;
5453

5554
namespace lower {
5655
class SymMap;
56+
class SymbolBox;
5757
namespace pft {
5858
struct Variable;
5959
}

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "Utils.h"
1616
#include "flang/Lower/PFTBuilder.h"
17+
#include "flang/Lower/SymbolMap.h"
1718
#include "flang/Optimizer/Builder/Todo.h"
1819
#include "flang/Semantics/tools.h"
1920
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"

flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,14 @@ class HlfirIntrinsicConversion : public mlir::OpRewritePattern<OP> {
176176
rewriter.eraseOp(use);
177177
}
178178
}
179-
rewriter.replaceAllUsesWith(op->getResults(), {base});
179+
// TODO: This entire pass should be a greedy pattern rewrite or a manual
180+
// IR traversal. A dialect conversion cannot be used here because
181+
// `replaceAllUsesWith` is not supported. Similarly, `replaceOp` is not
182+
// suitable because "op->getResult(0)" and "base" can have different types.
183+
// In such a case, the dialect conversion will attempt to convert the type,
184+
// but no type converter is specified in this pass. Also note that all
185+
// patterns in this pass are actually rewrite patterns.
186+
op->getResult(0).replaceAllUsesWith(base);
180187
rewriter.replaceOp(op, base);
181188
}
182189
};

llvm/docs/CommandGuide/llvm-objcopy.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,15 @@ them.
455455
Set the start address of the output to ``<addr>``. Overrides any previously
456456
specified :option:`--change-start` or :option:`--adjust-start` options.
457457

458+
.. option:: --set-symbol-visibility <symbol>=<visibility>
459+
460+
Change the visibility of a symbol to the specified value.
461+
462+
.. option:: --set-symbols-visibility <filename>=<visibility>
463+
464+
Read a list of symbols from <filename> and change their visibility to the
465+
specified value. Visibility values: default, internal, hidden, protected.
466+
458467
.. option:: --split-dwo <dwo-file>
459468

460469
Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and

llvm/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ Changes to the LLVM tools
147147
if it's not specified with the ``--format`` argument and cannot be inferred from
148148
input files.
149149

150+
* llvm-objcopy now supports ``--set-symbol-visibility`` and
151+
``--set-symbols-visibility`` options for ELF input to change the
152+
visibility of symbols.
153+
150154
Changes to LLDB
151155
---------------------------------
152156

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 490988
19+
#define LLVM_MAIN_REVISION 491000
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/ObjCopy/ELF/ELFConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_OBJCOPY_ELF_ELFCONFIG_H
1010
#define LLVM_OBJCOPY_ELF_ELFCONFIG_H
1111

12+
#include "llvm/ObjCopy/CommonConfig.h"
1213
#include "llvm/Object/ELFTypes.h"
1314

1415
namespace llvm {
@@ -18,6 +19,8 @@ namespace objcopy {
1819
struct ELFConfig {
1920
uint8_t NewSymbolVisibility = (uint8_t)ELF::STV_DEFAULT;
2021

22+
std::vector<std::pair<NameMatcher, uint8_t>> SymbolsToSetVisibility;
23+
2124
// ELF entry point address expression. The input parameter is an entry point
2225
// address in the input ELF file. The entry address in the output file is
2326
// calculated with EntryExpr(input_address), when either --set-start or

llvm/include/llvm/Support/TypeSize.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ class TypeSize : public details::FixedOrScalableQuantity<TypeSize, uint64_t> {
321321
: FixedOrScalableQuantity(V) {}
322322

323323
public:
324-
constexpr TypeSize() : FixedOrScalableQuantity(0, false) {}
325-
326324
constexpr TypeSize(ScalarTy Quantity, bool Scalable)
327325
: FixedOrScalableQuantity(Quantity, Scalable) {}
328326

llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config,
300300
Config.SymbolsToLocalize.matches(Sym.Name)))
301301
Sym.Binding = STB_LOCAL;
302302

303+
for (auto &[Matcher, Visibility] : ELFConfig.SymbolsToSetVisibility)
304+
if (Matcher.matches(Sym.Name))
305+
Sym.Visibility = Visibility;
306+
303307
// Note: these two globalize flags have very similar names but different
304308
// meanings:
305309
//

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,34 @@ bool X86FrameLowering::needsDwarfCFI(const MachineFunction &MF) const {
14181418
return !isWin64Prologue(MF) && MF.needsFrameMoves();
14191419
}
14201420

1421+
/// Return true if an opcode is part of the REP group of instructions
1422+
static bool isOpcodeRep(unsigned Opcode) {
1423+
switch (Opcode) {
1424+
case X86::REPNE_PREFIX:
1425+
case X86::REP_MOVSB_32:
1426+
case X86::REP_MOVSB_64:
1427+
case X86::REP_MOVSD_32:
1428+
case X86::REP_MOVSD_64:
1429+
case X86::REP_MOVSQ_32:
1430+
case X86::REP_MOVSQ_64:
1431+
case X86::REP_MOVSW_32:
1432+
case X86::REP_MOVSW_64:
1433+
case X86::REP_PREFIX:
1434+
case X86::REP_STOSB_32:
1435+
case X86::REP_STOSB_64:
1436+
case X86::REP_STOSD_32:
1437+
case X86::REP_STOSD_64:
1438+
case X86::REP_STOSQ_32:
1439+
case X86::REP_STOSQ_64:
1440+
case X86::REP_STOSW_32:
1441+
case X86::REP_STOSW_64:
1442+
return true;
1443+
default:
1444+
break;
1445+
}
1446+
return false;
1447+
}
1448+
14211449
/// emitPrologue - Push callee-saved registers onto the stack, which
14221450
/// automatically adjust the stack pointer. Adjust the stack pointer to allocate
14231451
/// space for local variables. Also emit labels used by the exception handler to
@@ -2194,13 +2222,44 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF,
21942222
// flag (DF in EFLAGS register). Clear this flag by creating "cld" instruction
21952223
// in each prologue of interrupt handler function.
21962224
//
2197-
// FIXME: Create "cld" instruction only in these cases:
2225+
// Create "cld" instruction only in these cases:
21982226
// 1. The interrupt handling function uses any of the "rep" instructions.
21992227
// 2. Interrupt handling function calls another function.
2228+
// 3. If there are any inline asm blocks, as we do not know what they do
22002229
//
2201-
if (Fn.getCallingConv() == CallingConv::X86_INTR)
2202-
BuildMI(MBB, MBBI, DL, TII.get(X86::CLD))
2203-
.setMIFlag(MachineInstr::FrameSetup);
2230+
// TODO: We should also emit cld if we detect the use of std, but as of now,
2231+
// the compiler does not even emit that instruction or even define it, so in
2232+
// practice, this would only happen with inline asm, which we cover anyway.
2233+
if (Fn.getCallingConv() == CallingConv::X86_INTR) {
2234+
bool NeedsCLD = false;
2235+
2236+
for (const MachineBasicBlock &B : MF) {
2237+
for (const MachineInstr &MI : B) {
2238+
if (MI.isCall()) {
2239+
NeedsCLD = true;
2240+
break;
2241+
}
2242+
2243+
if (isOpcodeRep(MI.getOpcode())) {
2244+
NeedsCLD = true;
2245+
break;
2246+
}
2247+
2248+
if (MI.isInlineAsm()) {
2249+
// TODO: Parse asm for rep instructions or call sites?
2250+
// For now, let's play it safe and emit a cld instruction
2251+
// just in case.
2252+
NeedsCLD = true;
2253+
break;
2254+
}
2255+
}
2256+
}
2257+
2258+
if (NeedsCLD) {
2259+
BuildMI(MBB, MBBI, DL, TII.get(X86::CLD))
2260+
.setMIFlag(MachineInstr::FrameSetup);
2261+
}
2262+
}
22042263

22052264
// At this point we know if the function has WinCFI or not.
22062265
MF.setHasWinCFI(HasWinCFI);

0 commit comments

Comments
 (0)