Skip to content

Commit ece3bee

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:beffc821e829 into amd-gfx:010f535d2674
Local branch amd-gfx 010f535 Merged main:6eee238975e4 into amd-gfx:4d4ec95d174b Remote branch main beffc82 [CodeLayout] CDSortImpl: remove HotChains and remove linear-time erase_value from mergeChains (llvm#69276)
2 parents 010f535 + beffc82 commit ece3bee

File tree

15 files changed

+165
-48
lines changed

15 files changed

+165
-48
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_platform.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,15 @@
303303
# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40)
304304
# endif
305305
#elif SANITIZER_RISCV64
306-
# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
306+
// FIXME: Rather than hardcoding the VMA here, we should rely on
307+
// GetMaxUserVirtualAddress(). This will require some refactoring though since
308+
// many places either hardcode some value or SANITIZER_MMAP_RANGE_SIZE is
309+
// assumed to be some constant integer.
310+
# if SANITIZER_FUCHSIA
311+
# define SANITIZER_MMAP_RANGE_SIZE (1ULL << 38)
312+
# else
313+
# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
314+
# endif
307315
#elif defined(__aarch64__)
308316
# if SANITIZER_APPLE
309317
# if SANITIZER_OSX || SANITIZER_IOSSIM

lldb/examples/synthetic/gnu_libstdcpp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,11 @@ def get_variant_npos_value(index_byte_size):
914914
if index == npos_value:
915915
return " No Value"
916916

917+
# Invalid index can happen when the variant is not initialized yet.
918+
template_arg_count = data_obj.GetType().GetNumberOfTemplateArguments()
919+
if index >= template_arg_count:
920+
return " <Invalid>"
921+
917922
active_type = data_obj.GetType().GetTemplateArgumentType(index)
918923
return f" Active Type = {active_type.GetDisplayTypeName()} "
919924

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7182,6 +7182,9 @@ GetNthTemplateArgument(const clang::ClassTemplateSpecializationDecl *decl,
71827182
// Note that 'idx' counts from the beginning of all template arguments
71837183
// (including the ones preceding the parameter pack).
71847184
const auto &pack = args[last_idx];
7185+
if (idx >= pack.pack_size())
7186+
return nullptr;
7187+
71857188
const size_t pack_idx = idx - last_idx;
71867189
assert(pack_idx < pack.pack_size() && "parameter pack index out-of-bounds");
71877190
return &pack.pack_elements()[pack_idx];

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,29 @@ def test_with_run_command(self):
7171
substrs=["v_many_types_no_value = No Value"],
7272
)
7373
"""
74+
75+
@add_test_categories(["libstdcxx"])
76+
def test_invalid_variant_index(self):
77+
"""Test LibStdC++ data formatter for std::variant with invalid index."""
78+
self.build()
79+
80+
(self.target, self.process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
81+
self, "// break here", lldb.SBFileSpec("main.cpp", False)
82+
)
83+
84+
lldbutil.continue_to_breakpoint(self.process, bkpt)
85+
86+
self.expect(
87+
"frame variable v1",
88+
substrs=["v1 = Active Type = int {", "Value = 12", "}"],
89+
)
90+
91+
var_v1 = thread.frames[0].FindVariable("v1")
92+
var_v1_raw_obj = var_v1.GetNonSyntheticValue()
93+
index_obj = var_v1_raw_obj.GetChildMemberWithName("_M_index")
94+
self.assertTrue(index_obj and index_obj.IsValid())
95+
96+
INVALID_INDEX = "100"
97+
index_obj.SetValueFromCString(INVALID_INDEX)
98+
99+
self.expect("frame variable v1", substrs=["v1 = <Invalid>"])

llvm/docs/LangRef.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ added in the future:
309309
prototype of all callees to exactly match the prototype of the
310310
function definition. Furthermore the inliner doesn't consider such function
311311
calls for inlining.
312-
"``cc 10``" - GHC convention
312+
"``ghccc``" - GHC convention
313313
This calling convention has been implemented specifically for use by
314314
the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_.
315315
It passes everything in registers, going to extremes to achieve this

llvm/docs/TestSuiteGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ benchmarks. CMake can print a list of them:
177177
- `TEST_SUITE_FORTRAN`
178178

179179
Activate that Fortran tests. This is a work in progress. More information can be
180-
found in the [Flang documentation](https://flang.llvm.org/docs/html/FortranLLVMTestSuite.html)
180+
found in the [Flang documentation](https://flang.llvm.org/docs/FortranLLVMTestSuite.html)
181181

182182
- `TEST_SUITE_RUN_UNDER`
183183

llvm/docs/WritingAnLLVMPass.rst

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,7 @@ series of passes:
10201020
instead of traversing the entire program. It reduces the memory consumption
10211021
of compiler, because, for example, only one `DominatorSet
10221022
<https://llvm.org/doxygen/classllvm_1_1DominatorSet.html>`_ needs to be
1023-
calculated at a time. This also makes it possible to implement some
1024-
:ref:`interesting enhancements <writing-an-llvm-pass-SMP>` in the future.
1023+
calculated at a time.
10251024

10261025
The effectiveness of the ``PassManager`` is influenced directly by how much
10271026
information it has about the behaviors of the passes it is scheduling. For
@@ -1350,29 +1349,3 @@ some with solutions, some without.
13501349
Hopefully these tips will help with common case debugging situations. If you'd
13511350
like to contribute some tips of your own, just contact `Chris
13521351
<mailto:[email protected]>`_.
1353-
1354-
Future extensions planned
1355-
-------------------------
1356-
1357-
Although the LLVM Pass Infrastructure is very capable as it stands, and does
1358-
some nifty stuff, there are things we'd like to add in the future. Here is
1359-
where we are going:
1360-
1361-
.. _writing-an-llvm-pass-SMP:
1362-
1363-
Multithreaded LLVM
1364-
^^^^^^^^^^^^^^^^^^
1365-
1366-
Multiple CPU machines are becoming more common and compilation can never be
1367-
fast enough: obviously we should allow for a multithreaded compiler. Because
1368-
of the semantics defined for passes above (specifically they cannot maintain
1369-
state across invocations of their ``run*`` methods), a nice clean way to
1370-
implement a multithreaded compiler would be for the ``PassManager`` class to
1371-
create multiple instances of each pass object, and allow the separate instances
1372-
to be hacking on different parts of the program at the same time.
1373-
1374-
This implementation would prevent each of the passes from having to implement
1375-
multithreaded constructs, requiring only the LLVM core to have locking in a few
1376-
places (for global resources). Although this is a simple extension, we simply
1377-
haven't had time (or multiprocessor machines, thus a reason) to implement this.
1378-
Despite that, we have kept the LLVM passes SMP ready, and you should too.

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 477827
19+
#define LLVM_MAIN_REVISION 477835
2020

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

llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void M68kMCCodeEmitter::encodeInstruction(const MCInst &MI,
204204
SmallVectorImpl<MCFixup> &Fixups,
205205
const MCSubtargetInfo &STI) const {
206206
LLVM_DEBUG(dbgs() << "EncodeInstruction: " << MCII.getName(MI.getOpcode())
207-
<< "(" << Opcode << ")\n");
207+
<< "(" << MI.getOpcode() << ")\n");
208208
(void)MCII;
209209

210210
// Try using the new method first.

llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
194194
}
195195
case TargetOpcode::G_SEXT_INREG:
196196
return selectSExtInreg(MI, MIB);
197+
case TargetOpcode::G_FRAME_INDEX: {
198+
// TODO: We may want to replace this code with the SelectionDAG patterns,
199+
// which fail to get imported because it uses FrameAddrRegImm, which is a
200+
// ComplexPattern
201+
MI.setDesc(TII.get(RISCV::ADDI));
202+
MI.addOperand(MachineOperand::CreateImm(0));
203+
return constrainSelectedInstRegOperands(MI, TII, TRI, RBI);
204+
}
197205
case TargetOpcode::G_SELECT:
198206
return selectSelect(MI, MIB, MRI);
199207
default:

llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
135135
case TargetOpcode::G_STORE:
136136
break;
137137
case TargetOpcode::G_CONSTANT:
138+
case TargetOpcode::G_FRAME_INDEX:
138139
case TargetOpcode::G_GLOBAL_VALUE:
139140
case TargetOpcode::G_BRCOND:
140141
OperandsMapping = getOperandsMapping({GPRValueMapping, nullptr});

llvm/lib/Transforms/Utils/CodeLayout.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,6 @@ class CDSortImpl {
10251025
// Merge pairs of chains while improving the objective.
10261026
mergeChainPairs();
10271027

1028-
LLVM_DEBUG(dbgs() << "Cache-directed function sorting reduced the number"
1029-
<< " of chains from " << NumNodes << " to "
1030-
<< HotChains.size() << "\n");
1031-
10321028
// Collect nodes from all the chains.
10331029
return concatChains();
10341030
}
@@ -1074,16 +1070,13 @@ class CDSortImpl {
10741070

10751071
// Initialize chains.
10761072
AllChains.reserve(NumNodes);
1077-
HotChains.reserve(NumNodes);
10781073
for (NodeT &Node : AllNodes) {
10791074
// Adjust execution counts.
10801075
Node.ExecutionCount = std::max(Node.ExecutionCount, Node.inCount());
10811076
Node.ExecutionCount = std::max(Node.ExecutionCount, Node.outCount());
10821077
// Create chain.
10831078
AllChains.emplace_back(Node.Index, &Node);
10841079
Node.CurChain = &AllChains.back();
1085-
if (Node.ExecutionCount > 0)
1086-
HotChains.push_back(&AllChains.back());
10871080
}
10881081

10891082
// Initialize chain edges.
@@ -1116,8 +1109,12 @@ class CDSortImpl {
11161109
std::set<ChainEdge *, decltype(GainComparator)> Queue(GainComparator);
11171110

11181111
// Insert the edges into the queue.
1119-
for (ChainT *ChainPred : HotChains) {
1120-
for (const auto &[_, Edge] : ChainPred->Edges) {
1112+
[[maybe_unused]] size_t NumActiveChains = 0;
1113+
for (NodeT &Node : AllNodes) {
1114+
if (Node.ExecutionCount == 0)
1115+
continue;
1116+
++NumActiveChains;
1117+
for (const auto &[_, Edge] : Node.CurChain->Edges) {
11211118
// Ignore self-edges.
11221119
if (Edge->isSelfEdge())
11231120
continue;
@@ -1152,6 +1149,7 @@ class CDSortImpl {
11521149
MergeGainT BestGain = BestEdge->getMergeGain();
11531150
mergeChains(BestSrcChain, BestDstChain, BestGain.mergeOffset(),
11541151
BestGain.mergeType());
1152+
--NumActiveChains;
11551153

11561154
// Insert newly created edges into the queue.
11571155
for (const auto &[_, Edge] : BestSrcChain->Edges) {
@@ -1167,6 +1165,10 @@ class CDSortImpl {
11671165
Queue.insert(Edge);
11681166
}
11691167
}
1168+
1169+
LLVM_DEBUG(dbgs() << "Cache-directed function sorting reduced the number"
1170+
<< " of chains from " << NumNodes << " to "
1171+
<< NumActiveChains << "\n");
11701172
}
11711173

11721174
/// Compute the gain of merging two chains.
@@ -1301,9 +1303,6 @@ class CDSortImpl {
13011303
// Merge the edges.
13021304
Into->mergeEdges(From);
13031305
From->clear();
1304-
1305-
// Remove the chain from the list of active chains.
1306-
llvm::erase_value(HotChains, From);
13071306
}
13081307

13091308
/// Concatenate all chains into the final order.
@@ -1370,9 +1369,6 @@ class CDSortImpl {
13701369
/// All edges between the chains.
13711370
std::vector<ChainEdge> AllEdges;
13721371

1373-
/// Active chains. The vector gets updated at runtime when chains are merged.
1374-
std::vector<ChainT *> HotChains;
1375-
13761372
/// The total number of samples in the graph.
13771373
uint64_t TotalSamples{0};
13781374

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv32 -run-pass=instruction-select %s -o - \
3+
# RUN: | FileCheck %s
4+
--- |
5+
define ptr @frame_index() {
6+
entry:
7+
%x = alloca i32, align 4
8+
ret ptr %x
9+
}
10+
11+
...
12+
---
13+
name: frame_index
14+
legalized: true
15+
regBankSelected: true
16+
registers:
17+
- { id: 0, class: gprb, preferred-register: '' }
18+
stack:
19+
- { id: 0, name: x, type: default, offset: 0, size: 4, alignment: 4,
20+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
21+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
22+
body: |
23+
bb.1.entry:
24+
; CHECK-LABEL: name: frame_index
25+
; CHECK: [[ADDI:%[0-9]+]]:gpr = ADDI %stack.0.x, 0
26+
; CHECK-NEXT: $x10 = COPY [[ADDI]]
27+
; CHECK-NEXT: PseudoRET implicit $x10
28+
%0:gprb(p0) = G_FRAME_INDEX %stack.0.x
29+
$x10 = COPY %0(p0)
30+
PseudoRET implicit $x10
31+
32+
...
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv64 -run-pass=instruction-select %s -o - \
3+
# RUN: | FileCheck %s
4+
--- |
5+
define ptr @frame_index() {
6+
entry:
7+
%x = alloca i32, align 4
8+
ret ptr %x
9+
}
10+
11+
...
12+
---
13+
name: frame_index
14+
legalized: true
15+
regBankSelected: true
16+
registers:
17+
- { id: 0, class: gprb, preferred-register: '' }
18+
stack:
19+
- { id: 0, name: x, type: default, offset: 0, size: 4, alignment: 4,
20+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
21+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
22+
body: |
23+
bb.1.entry:
24+
; CHECK-LABEL: name: frame_index
25+
; CHECK: [[ADDI:%[0-9]+]]:gpr = ADDI %stack.0.x, 0
26+
; CHECK-NEXT: $x10 = COPY [[ADDI]]
27+
; CHECK-NEXT: PseudoRET implicit $x10
28+
%0:gprb(p0) = G_FRAME_INDEX %stack.0.x
29+
$x10 = COPY %0(p0)
30+
PseudoRET implicit $x10
31+
32+
...
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv32 -run-pass=regbankselect %s -o - \
3+
# RUN: | FileCheck %s
4+
# RUN: llc -mtriple=riscv64 -run-pass=regbankselect %s -o - \
5+
# RUN: | FileCheck %s
6+
--- |
7+
define ptr @frame_index() {
8+
entry:
9+
%x = alloca i32, align 4
10+
ret ptr %x
11+
}
12+
13+
...
14+
---
15+
name: frame_index
16+
legalized: true
17+
registers:
18+
- { id: 0, class: _, preferred-register: '' }
19+
stack:
20+
- { id: 0, name: x, type: default, offset: 0, size: 4, alignment: 4,
21+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
22+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
23+
body: |
24+
bb.1.entry:
25+
; CHECK-LABEL: name: frame_index
26+
; CHECK: [[FRAME_INDEX:%[0-9]+]]:gprb(p0) = G_FRAME_INDEX %stack.0.x
27+
; CHECK-NEXT: $x10 = COPY [[FRAME_INDEX]](p0)
28+
; CHECK-NEXT: PseudoRET implicit $x10
29+
%0:_(p0) = G_FRAME_INDEX %stack.0.x
30+
$x10 = COPY %0(p0)
31+
PseudoRET implicit $x10
32+
33+
...

0 commit comments

Comments
 (0)