Skip to content

Commit d74cb3e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into unify_privatization_paths
2 parents 1bf0e55 + 6ce0474 commit d74cb3e

File tree

8 files changed

+450
-15
lines changed

8 files changed

+450
-15
lines changed

lldb/docs/use/qemu-testing.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ forwarded for this to work.
172172

173173
.. note::
174174
These options are used to create a "port map" within ``lldb-server``.
175-
Unfortunately this map is not shared across all the processes it may create,
175+
Unfortunately this map is not cleaned up on Windows on connection close,
176176
and across a few uses you may run out of valid ports. To work around this,
177177
restart the platform every so often, especially after running a set of tests.
178+
This is tracked here: https://github.com/llvm/llvm-project/issues/90923

lldb/tools/lldb-server/lldb-platform.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,12 @@ int main_platform(int argc, char *argv[]) {
282282
}
283283
}
284284

285-
do {
286-
GDBRemoteCommunicationServerPlatform platform(
287-
acceptor_up->GetSocketProtocol(), acceptor_up->GetSocketScheme());
288-
289-
if (port_offset > 0)
290-
platform.SetPortOffset(port_offset);
291-
292-
if (!gdbserver_portmap.empty()) {
293-
platform.SetPortMap(std::move(gdbserver_portmap));
294-
}
285+
GDBRemoteCommunicationServerPlatform platform(
286+
acceptor_up->GetSocketProtocol(), acceptor_up->GetSocketScheme());
287+
if (port_offset > 0)
288+
platform.SetPortOffset(port_offset);
295289

290+
do {
296291
const bool children_inherit_accept_socket = true;
297292
Connection *conn = nullptr;
298293
error = acceptor_up->Accept(children_inherit_accept_socket, conn);
@@ -301,13 +296,37 @@ int main_platform(int argc, char *argv[]) {
301296
exit(socket_error);
302297
}
303298
printf("Connection established.\n");
299+
304300
if (g_server) {
305301
// Collect child zombie processes.
306302
#if !defined(_WIN32)
307-
while (waitpid(-1, nullptr, WNOHANG) > 0)
308-
;
303+
::pid_t waitResult;
304+
while ((waitResult = waitpid(-1, nullptr, WNOHANG)) > 0) {
305+
// waitResult is the child pid
306+
gdbserver_portmap.FreePortForProcess(waitResult);
307+
}
309308
#endif
310-
if (fork()) {
309+
// TODO: Clean up portmap for Windows when children die
310+
// See https://github.com/llvm/llvm-project/issues/90923
311+
312+
// After collecting zombie ports, get the next available
313+
GDBRemoteCommunicationServerPlatform::PortMap portmap_for_child;
314+
llvm::Expected<uint16_t> available_port =
315+
gdbserver_portmap.GetNextAvailablePort();
316+
if (available_port)
317+
portmap_for_child.AllowPort(*available_port);
318+
else {
319+
llvm::consumeError(available_port.takeError());
320+
fprintf(stderr,
321+
"no available gdbserver port for connection - dropping...\n");
322+
delete conn;
323+
continue;
324+
}
325+
platform.SetPortMap(std::move(portmap_for_child));
326+
327+
auto childPid = fork();
328+
if (childPid) {
329+
gdbserver_portmap.AssociatePortWithProcess(*available_port, childPid);
311330
// Parent doesn't need a connection to the lldb client
312331
delete conn;
313332

@@ -323,7 +342,11 @@ int main_platform(int argc, char *argv[]) {
323342
// If not running as a server, this process will not accept
324343
// connections while a connection is active.
325344
acceptor_up.reset();
345+
346+
// When not running in server mode, use all available ports
347+
platform.SetPortMap(std::move(gdbserver_portmap));
326348
}
349+
327350
platform.SetConnection(std::unique_ptr<Connection>(conn));
328351

329352
if (platform.IsConnected()) {

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
786786
SDValue ScalarizeVecRes_InregOp(SDNode *N);
787787
SDValue ScalarizeVecRes_VecInregOp(SDNode *N);
788788

789+
SDValue ScalarizeVecRes_ADDRSPACECAST(SDNode *N);
789790
SDValue ScalarizeVecRes_BITCAST(SDNode *N);
790791
SDValue ScalarizeVecRes_BUILD_VECTOR(SDNode *N);
791792
SDValue ScalarizeVecRes_EXTRACT_SUBVECTOR(SDNode *N);
@@ -853,6 +854,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
853854
void SplitVecRes_BinOp(SDNode *N, SDValue &Lo, SDValue &Hi);
854855
void SplitVecRes_TernaryOp(SDNode *N, SDValue &Lo, SDValue &Hi);
855856
void SplitVecRes_UnaryOp(SDNode *N, SDValue &Lo, SDValue &Hi);
857+
void SplitVecRes_ADDRSPACECAST(SDNode *N, SDValue &Lo, SDValue &Hi);
856858
void SplitVecRes_FFREXP(SDNode *N, unsigned ResNo, SDValue &Lo, SDValue &Hi);
857859
void SplitVecRes_ExtendOp(SDNode *N, SDValue &Lo, SDValue &Hi);
858860
void SplitVecRes_InregOp(SDNode *N, SDValue &Lo, SDValue &Hi);
@@ -956,6 +958,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
956958
// Widen Vector Result Promotion.
957959
void WidenVectorResult(SDNode *N, unsigned ResNo);
958960
SDValue WidenVecRes_MERGE_VALUES(SDNode* N, unsigned ResNo);
961+
SDValue WidenVecRes_ADDRSPACECAST(SDNode *N);
959962
SDValue WidenVecRes_AssertZext(SDNode* N);
960963
SDValue WidenVecRes_BITCAST(SDNode* N);
961964
SDValue WidenVecRes_BUILD_VECTOR(SDNode* N);

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/ADT/SmallBitVector.h"
2424
#include "llvm/Analysis/MemoryLocation.h"
2525
#include "llvm/Analysis/VectorUtils.h"
26+
#include "llvm/CodeGen/ISDOpcodes.h"
2627
#include "llvm/IR/DataLayout.h"
2728
#include "llvm/Support/ErrorHandling.h"
2829
#include "llvm/Support/TypeSize.h"
@@ -116,6 +117,9 @@ void DAGTypeLegalizer::ScalarizeVectorResult(SDNode *N, unsigned ResNo) {
116117
case ISD::FCANONICALIZE:
117118
R = ScalarizeVecRes_UnaryOp(N);
118119
break;
120+
case ISD::ADDRSPACECAST:
121+
R = ScalarizeVecRes_ADDRSPACECAST(N);
122+
break;
119123
case ISD::FFREXP:
120124
R = ScalarizeVecRes_FFREXP(N, ResNo);
121125
break;
@@ -475,6 +479,31 @@ SDValue DAGTypeLegalizer::ScalarizeVecRes_VecInregOp(SDNode *N) {
475479
llvm_unreachable("Illegal extend_vector_inreg opcode");
476480
}
477481

482+
SDValue DAGTypeLegalizer::ScalarizeVecRes_ADDRSPACECAST(SDNode *N) {
483+
EVT DestVT = N->getValueType(0).getVectorElementType();
484+
SDValue Op = N->getOperand(0);
485+
EVT OpVT = Op.getValueType();
486+
SDLoc DL(N);
487+
// The result needs scalarizing, but it's not a given that the source does.
488+
// This is a workaround for targets where it's impossible to scalarize the
489+
// result of a conversion, because the source type is legal.
490+
// For instance, this happens on AArch64: v1i1 is illegal but v1i{8,16,32}
491+
// are widened to v8i8, v4i16, and v2i32, which is legal, because v1i64 is
492+
// legal and was not scalarized.
493+
// See the similar logic in ScalarizeVecRes_SETCC
494+
if (getTypeAction(OpVT) == TargetLowering::TypeScalarizeVector) {
495+
Op = GetScalarizedVector(Op);
496+
} else {
497+
EVT VT = OpVT.getVectorElementType();
498+
Op = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, Op,
499+
DAG.getVectorIdxConstant(0, DL));
500+
}
501+
auto *AddrSpaceCastN = cast<AddrSpaceCastSDNode>(N);
502+
unsigned SrcAS = AddrSpaceCastN->getSrcAddressSpace();
503+
unsigned DestAS = AddrSpaceCastN->getDestAddressSpace();
504+
return DAG.getAddrSpaceCast(DL, DestVT, Op, SrcAS, DestAS);
505+
}
506+
478507
SDValue DAGTypeLegalizer::ScalarizeVecRes_SCALAR_TO_VECTOR(SDNode *N) {
479508
// If the operand is wider than the vector element type then it is implicitly
480509
// truncated. Make that explicit here.
@@ -1122,6 +1151,9 @@ void DAGTypeLegalizer::SplitVectorResult(SDNode *N, unsigned ResNo) {
11221151
case ISD::FCANONICALIZE:
11231152
SplitVecRes_UnaryOp(N, Lo, Hi);
11241153
break;
1154+
case ISD::ADDRSPACECAST:
1155+
SplitVecRes_ADDRSPACECAST(N, Lo, Hi);
1156+
break;
11251157
case ISD::FFREXP:
11261158
SplitVecRes_FFREXP(N, ResNo, Lo, Hi);
11271159
break;
@@ -2353,6 +2385,26 @@ void DAGTypeLegalizer::SplitVecRes_UnaryOp(SDNode *N, SDValue &Lo,
23532385
Hi = DAG.getNode(Opcode, dl, HiVT, {Hi, MaskHi, EVLHi}, Flags);
23542386
}
23552387

2388+
void DAGTypeLegalizer::SplitVecRes_ADDRSPACECAST(SDNode *N, SDValue &Lo,
2389+
SDValue &Hi) {
2390+
SDLoc dl(N);
2391+
auto [LoVT, HiVT] = DAG.GetSplitDestVTs(N->getValueType(0));
2392+
2393+
// If the input also splits, handle it directly for a compile time speedup.
2394+
// Otherwise split it by hand.
2395+
EVT InVT = N->getOperand(0).getValueType();
2396+
if (getTypeAction(InVT) == TargetLowering::TypeSplitVector)
2397+
GetSplitVector(N->getOperand(0), Lo, Hi);
2398+
else
2399+
std::tie(Lo, Hi) = DAG.SplitVectorOperand(N, 0);
2400+
2401+
auto *AddrSpaceCastN = cast<AddrSpaceCastSDNode>(N);
2402+
unsigned SrcAS = AddrSpaceCastN->getSrcAddressSpace();
2403+
unsigned DestAS = AddrSpaceCastN->getDestAddressSpace();
2404+
Lo = DAG.getAddrSpaceCast(dl, LoVT, Lo, SrcAS, DestAS);
2405+
Hi = DAG.getAddrSpaceCast(dl, HiVT, Hi, SrcAS, DestAS);
2406+
}
2407+
23562408
void DAGTypeLegalizer::SplitVecRes_FFREXP(SDNode *N, unsigned ResNo,
23572409
SDValue &Lo, SDValue &Hi) {
23582410
SDLoc dl(N);
@@ -4121,6 +4173,9 @@ void DAGTypeLegalizer::WidenVectorResult(SDNode *N, unsigned ResNo) {
41214173
report_fatal_error("Do not know how to widen the result of this operator!");
41224174

41234175
case ISD::MERGE_VALUES: Res = WidenVecRes_MERGE_VALUES(N, ResNo); break;
4176+
case ISD::ADDRSPACECAST:
4177+
Res = WidenVecRes_ADDRSPACECAST(N);
4178+
break;
41244179
case ISD::AssertZext: Res = WidenVecRes_AssertZext(N); break;
41254180
case ISD::BITCAST: Res = WidenVecRes_BITCAST(N); break;
41264181
case ISD::BUILD_VECTOR: Res = WidenVecRes_BUILD_VECTOR(N); break;
@@ -5086,6 +5141,16 @@ SDValue DAGTypeLegalizer::WidenVecRes_MERGE_VALUES(SDNode *N, unsigned ResNo) {
50865141
return GetWidenedVector(WidenVec);
50875142
}
50885143

5144+
SDValue DAGTypeLegalizer::WidenVecRes_ADDRSPACECAST(SDNode *N) {
5145+
EVT WidenVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
5146+
SDValue InOp = GetWidenedVector(N->getOperand(0));
5147+
auto *AddrSpaceCastN = cast<AddrSpaceCastSDNode>(N);
5148+
5149+
return DAG.getAddrSpaceCast(SDLoc(N), WidenVT, InOp,
5150+
AddrSpaceCastN->getSrcAddressSpace(),
5151+
AddrSpaceCastN->getDestAddressSpace());
5152+
}
5153+
50895154
SDValue DAGTypeLegalizer::WidenVecRes_BITCAST(SDNode *N) {
50905155
SDValue InOp = N->getOperand(0);
50915156
EVT InVT = InOp.getValueType();

llvm/lib/Target/X86/X86.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,10 @@ def TuningFastMOVBE
739739
: SubtargetFeature<"fast-movbe", "HasFastMOVBE", "true",
740740
"Prefer a movbe over a single-use load + bswap / single-use bswap + store">;
741741

742+
def TuningFastImm16
743+
: SubtargetFeature<"fast-imm16", "HasFastImm16", "true",
744+
"Prefer a i16 instruction with i16 immediate over extension to i32">;
745+
742746
def TuningUseSLMArithCosts
743747
: SubtargetFeature<"use-slm-arith-costs", "UseSLMArithCosts", "true",
744748
"Use Silvermont specific arithmetic costs">;
@@ -1146,6 +1150,7 @@ def ProcessorFeatures {
11461150
TuningSlowDivide32,
11471151
TuningSlowDivide64,
11481152
TuningSlowTwoMemOps,
1153+
TuningFastImm16,
11491154
TuningLEAUsesAG,
11501155
TuningPadShortFunctions,
11511156
TuningInsertVZEROUPPER,
@@ -1166,6 +1171,7 @@ def ProcessorFeatures {
11661171
TuningSlowPMULLD,
11671172
TuningFast7ByteNOP,
11681173
TuningFastMOVBE,
1174+
TuningFastImm16,
11691175
TuningPOPCNTFalseDeps,
11701176
TuningInsertVZEROUPPER,
11711177
TuningNoDomainDelay];
@@ -1187,6 +1193,7 @@ def ProcessorFeatures {
11871193
TuningSlowLEA,
11881194
TuningSlowIncDec,
11891195
TuningFastMOVBE,
1196+
TuningFastImm16,
11901197
TuningPOPCNTFalseDeps,
11911198
TuningInsertVZEROUPPER,
11921199
TuningNoDomainDelay];
@@ -1201,6 +1208,7 @@ def ProcessorFeatures {
12011208
TuningSlowLEA,
12021209
TuningSlowIncDec,
12031210
TuningFastMOVBE,
1211+
TuningFastImm16,
12041212
TuningInsertVZEROUPPER,
12051213
TuningNoDomainDelay];
12061214
list<SubtargetFeature> GLPFeatures =
@@ -1321,6 +1329,7 @@ def ProcessorFeatures {
13211329
TuningPreferMaskRegisters,
13221330
TuningFastGather,
13231331
TuningFastMOVBE,
1332+
TuningFastImm16,
13241333
TuningSlowPMADDWD];
13251334
// TODO Add AVX5124FMAPS/AVX5124VNNIW features
13261335
list<SubtargetFeature> KNMFeatures =
@@ -1364,6 +1373,7 @@ def ProcessorFeatures {
13641373
TuningFastScalarShiftMasks,
13651374
TuningFastVectorShiftMasks,
13661375
TuningSlowSHLD,
1376+
TuningFastImm16,
13671377
TuningSBBDepBreaking,
13681378
TuningInsertVZEROUPPER];
13691379

@@ -1384,6 +1394,7 @@ def ProcessorFeatures {
13841394
TuningFastScalarShiftMasks,
13851395
TuningFastVectorShiftMasks,
13861396
TuningFastMOVBE,
1397+
TuningFastImm16,
13871398
TuningSBBDepBreaking,
13881399
TuningSlowSHLD];
13891400
list<SubtargetFeature> BtVer2Features =
@@ -1488,6 +1499,7 @@ def ProcessorFeatures {
14881499
TuningFastScalarShiftMasks,
14891500
TuningFastVariablePerLaneShuffle,
14901501
TuningFastMOVBE,
1502+
TuningFastImm16,
14911503
TuningSlowSHLD,
14921504
TuningSBBDepBreaking,
14931505
TuningInsertVZEROUPPER,

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22690,7 +22690,7 @@ static SDValue EmitCmp(SDValue Op0, SDValue Op1, unsigned X86CC,
2269022690

2269122691
// Only promote the compare up to I32 if it is a 16 bit operation
2269222692
// with an immediate. 16 bit immediates are to be avoided.
22693-
if (CmpVT == MVT::i16 && !Subtarget.isAtom() &&
22693+
if (CmpVT == MVT::i16 && !Subtarget.hasFastImm16() &&
2269422694
!DAG.getMachineFunction().getFunction().hasMinSize()) {
2269522695
ConstantSDNode *COp0 = dyn_cast<ConstantSDNode>(Op0);
2269622696
ConstantSDNode *COp1 = dyn_cast<ConstantSDNode>(Op1);

0 commit comments

Comments
 (0)