Skip to content

Commit bb451ce

Browse files
authored
Merge pull request #172 from sx-aurora-dev/feature/merge-upstream-20220317
Feature/merge upstream 20220317
2 parents 8ade0bc + 2ae9828 commit bb451ce

File tree

856 files changed

+27508
-5238
lines changed

Some content is hidden

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

856 files changed

+27508
-5238
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,6 @@ class MCPlusBuilder {
526526
return false;
527527
}
528528

529-
virtual bool isMOVSX64rm32(const MCInst &Inst) const {
530-
llvm_unreachable("not implemented");
531-
return false;
532-
}
533-
534529
virtual bool isLeave(const MCInst &Inst) const {
535530
llvm_unreachable("not implemented");
536531
return false;
@@ -1287,7 +1282,8 @@ class MCPlusBuilder {
12871282

12881283
/// Replace instruction with a shorter version that could be relaxed later
12891284
/// if needed.
1290-
virtual bool shortenInstruction(MCInst &Inst) const {
1285+
virtual bool shortenInstruction(MCInst &Inst,
1286+
const MCSubtargetInfo &STI) const {
12911287
llvm_unreachable("not implemented");
12921288
return false;
12931289
}

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ uint64_t ShortenInstructions::shortenInstructions(BinaryFunction &Function) {
10111011
if (opts::Verbosity > 2)
10121012
OriginalInst = Inst;
10131013

1014-
if (!BC.MIB->shortenInstruction(Inst))
1014+
if (!BC.MIB->shortenInstruction(Inst, *BC.STI))
10151015
continue;
10161016

10171017
if (opts::Verbosity > 2) {

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
5151
return false;
5252
}
5353

54-
bool shortenInstruction(MCInst &) const override { return false; }
54+
bool shortenInstruction(MCInst &, const MCSubtargetInfo &) const override {
55+
return false;
56+
}
5557

5658
bool isADRP(const MCInst &Inst) const override {
5759
return Inst.getOpcode() == AArch64::ADRP;

bolt/lib/Target/X86/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(LLVM_LINK_COMPONENTS
22
BOLTCore
3+
BOLTUtils
34
MC
45
Object
56
Support

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/MC/MCInstrInfo.h"
2424
#include "llvm/MC/MCRegister.h"
2525
#include "llvm/MC/MCRegisterInfo.h"
26+
#include "llvm/Support/CommandLine.h"
2627
#include "llvm/Support/DataExtractor.h"
2728
#include "llvm/Support/Debug.h"
2829
#include "llvm/Support/Errc.h"
@@ -35,6 +36,17 @@
3536
using namespace llvm;
3637
using namespace bolt;
3738

39+
namespace opts {
40+
41+
extern cl::OptionCategory BoltOptCategory;
42+
43+
static cl::opt<bool> X86StripRedundantAddressSize(
44+
"x86-strip-redundant-address-size",
45+
cl::desc("Remove redundant Address-Size override prefix"), cl::init(true),
46+
cl::ZeroOrMore, cl::cat(BoltOptCategory));
47+
48+
} // namespace opts
49+
3850
namespace {
3951

4052
unsigned getShortBranchOpcode(unsigned Opcode) {
@@ -265,6 +277,10 @@ bool isTEST(unsigned Opcode) {
265277
}
266278
}
267279

280+
bool isMOVSX64rm32(const MCInst &Inst) {
281+
return Inst.getOpcode() == X86::MOVSX64rm32;
282+
}
283+
268284
class X86MCPlusBuilder : public MCPlusBuilder {
269285
public:
270286
X86MCPlusBuilder(const MCInstrAnalysis *Analysis, const MCInstrInfo *Info,
@@ -542,10 +558,6 @@ class X86MCPlusBuilder : public MCPlusBuilder {
542558
return Inst.getOpcode() == X86::LEA64r;
543559
}
544560

545-
bool isMOVSX64rm32(const MCInst &Inst) const override {
546-
return Inst.getOpcode() == X86::MOVSX64rm32;
547-
}
548-
549561
bool isLeave(const MCInst &Inst) const override {
550562
return Inst.getOpcode() == X86::LEAVE || Inst.getOpcode() == X86::LEAVE64;
551563
}
@@ -2031,14 +2043,26 @@ class X86MCPlusBuilder : public MCPlusBuilder {
20312043
llvm_unreachable("not implemented");
20322044
}
20332045

2034-
bool shortenInstruction(MCInst &Inst) const override {
2046+
bool shortenInstruction(MCInst &Inst,
2047+
const MCSubtargetInfo &STI) const override {
20352048
unsigned OldOpcode = Inst.getOpcode();
20362049
unsigned NewOpcode = OldOpcode;
20372050

2038-
// Check and remove EIZ/RIZ. These cases represent ambiguous cases where SIB
2039-
// byte is present, but no index is used and modrm alone shoud have been
2040-
// enough. Converting to NoRegister effectively removes the SIB byte.
20412051
int MemOpNo = getMemoryOperandNo(Inst);
2052+
2053+
// Check and remove redundant Address-Size override prefix.
2054+
if (opts::X86StripRedundantAddressSize) {
2055+
uint64_t TSFlags = Info->get(OldOpcode).TSFlags;
2056+
unsigned Flags = Inst.getFlags();
2057+
2058+
if (!X86_MC::needsAddressSizeOverride(Inst, STI, MemOpNo, TSFlags) &&
2059+
Flags & X86::IP_HAS_AD_SIZE)
2060+
Inst.setFlags(Flags ^ X86::IP_HAS_AD_SIZE);
2061+
}
2062+
2063+
// Check and remove EIZ/RIZ. These cases represent ambiguous cases where
2064+
// SIB byte is present, but no index is used and modrm alone should have
2065+
// been enough. Converting to NoRegister effectively removes the SIB byte.
20422066
if (MemOpNo >= 0) {
20432067
MCOperand &IndexOp =
20442068
Inst.getOperand(static_cast<unsigned>(MemOpNo) + X86::AddrIndexReg);
@@ -3877,7 +3901,7 @@ class X86MCPlusBuilder : public MCPlusBuilder {
38773901
return BlocksVectorTy();
38783902

38793903
CompareInst.addOperand(MCOperand::createImm(CaseIdx));
3880-
shortenInstruction(CompareInst);
3904+
shortenInstruction(CompareInst, *Ctx->getSubtargetInfo());
38813905

38823906
// jump to next target compare.
38833907
NextTarget =

bolt/test/X86/addr32.s

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Check that we don't accidentally strip addr32 prefix
2+
3+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
4+
# RUN: ld.lld %t.o -o %t.exe -nostdlib
5+
# RUN: llvm-objdump -d %t.exe | FileCheck %s
6+
# RUN: llvm-bolt %t.exe -o %t.out -lite=0 -x86-strip-redundant-address-size=false
7+
# RUN: llvm-objdump -d %t.out | FileCheck %s
8+
# CHECK: 67 e8 {{.*}} addr32 callq {{.*}} <foo>
9+
# RUN: llvm-bolt %t.exe -o %t.out -lite=0 -x86-strip-redundant-address-size=true
10+
# remove test name from objdump output, to only search for addr32 in disassembly
11+
# RUN: llvm-objdump -d %t.out | grep -v addr32.s | FileCheck %s --check-prefix=CHECK-STRIP
12+
# CHECK-STRIP-NOT: addr32
13+
14+
.globl _start
15+
.type _start, @function
16+
_start:
17+
.code64
18+
addr32 callq foo
19+
ret
20+
.size _start, .-_start
21+
22+
.globl foo
23+
.type foo, @function
24+
foo:
25+
ud2

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,26 @@ unsigned evaluateHighlightPriority(const HighlightingToken &Tok) {
313313
//
314314
// In particular, heuristically resolved dependent names get their heuristic
315315
// kind, plus the dependent modifier.
316+
llvm::Optional<HighlightingToken> resolveConflict(const HighlightingToken &A,
317+
const HighlightingToken &B) {
318+
unsigned Priority1 = evaluateHighlightPriority(A);
319+
unsigned Priority2 = evaluateHighlightPriority(B);
320+
if (Priority1 == Priority2 && A.Kind != B.Kind)
321+
return llvm::None;
322+
auto Result = Priority1 > Priority2 ? A : B;
323+
Result.Modifiers = A.Modifiers | B.Modifiers;
324+
return Result;
325+
}
316326
llvm::Optional<HighlightingToken>
317327
resolveConflict(ArrayRef<HighlightingToken> Tokens) {
318328
if (Tokens.size() == 1)
319329
return Tokens[0];
320330

321-
if (Tokens.size() != 2)
322-
return llvm::None;
323-
324-
unsigned Priority1 = evaluateHighlightPriority(Tokens[0]);
325-
unsigned Priority2 = evaluateHighlightPriority(Tokens[1]);
326-
if (Priority1 == Priority2 && Tokens[0].Kind != Tokens[1].Kind)
327-
return llvm::None;
328-
auto Result = Priority1 > Priority2 ? Tokens[0] : Tokens[1];
329-
Result.Modifiers = Tokens[0].Modifiers | Tokens[1].Modifiers;
330-
return Result;
331+
assert(Tokens.size() >= 2);
332+
Optional<HighlightingToken> Winner = resolveConflict(Tokens[0], Tokens[1]);
333+
for (size_t I = 2; Winner && I < Tokens.size(); ++I)
334+
Winner = resolveConflict(*Winner, Tokens[I]);
335+
return Winner;
331336
}
332337

333338
/// Consumes source locations and maps them to text ranges for highlightings.

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,14 @@ sizeof...($TemplateParameter[[Elements]]);
615615
void $Method_decl[[bar1]]() {
616616
$Class[[Foo]]<$TemplateParameter[[U]]>().$Field_dependentName[[Waldo]];
617617
}
618+
619+
void $Method_decl[[Overload]]();
620+
void $Method_decl_readonly[[Overload]]() const;
618621
};
622+
template <typename $TemplateParameter_decl[[T]]>
623+
void $Function_decl[[baz]]($Class[[Foo]]<$TemplateParameter[[T]]> $Parameter_decl[[o]]) {
624+
$Parameter[[o]].$Method_readonly_dependentName[[Overload]]();
625+
}
619626
)cpp",
620627
// Concepts
621628
R"cpp(

clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ class DirectiveMap::Chunk {
143143
} // namespace pseudo
144144
} // namespace clang
145145

146-
#endif
146+
#endif // CLANG_PSEUDO_DIRECTIVEMAP_H

clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ struct GrammarTable {
157157

158158
struct Nonterminal {
159159
std::string Name;
160-
// Corresponding rules that construct the non-terminal, it is a [start, end)
160+
// Corresponding rules that construct the non-terminal, it is a [Start, End)
161161
// index range of the Rules table.
162162
struct {
163-
RuleID start;
164-
RuleID end;
163+
RuleID Start;
164+
RuleID End;
165165
} RuleRange;
166166
};
167167

@@ -179,4 +179,4 @@ struct GrammarTable {
179179
} // namespace pseudo
180180
} // namespace clang
181181

182-
#endif // LLVM_CLANG_TOOLING_SYNTAX_GRAMMAR_H
182+
#endif // CLANG_PSEUDO_GRAMMAR_H

0 commit comments

Comments
 (0)