Skip to content

Commit 1928ca4

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:631bcbe9de13e160d427ad7452a7ef2ca67911ab into amd-gfx:c94dc53f6a77
Local branch amd-gfx c94dc53 Merged main:09cd5a86733a362f12542a11ffd834cac885eb32 into amd-gfx:a6a072505de2 Remote branch main 631bcbe [llvm][cmake] Properly place clang runtime directory on linker command line when WinMsvc.cmake is involved (llvm#110084)
2 parents c94dc53 + 631bcbe commit 1928ca4

38 files changed

+1487
-310
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ std::optional<bool> isUncounted(const QualType T) {
155155
std::optional<bool> isUncounted(const CXXRecordDecl* Class)
156156
{
157157
// Keep isRefCounted first as it's cheaper.
158-
if (isRefCounted(Class))
158+
if (!Class || isRefCounted(Class))
159159
return false;
160160

161161
std::optional<bool> IsRefCountable = isRefCountable(Class);

clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class UncountedCallArgsChecker
8686
return;
8787
}
8888
auto *E = MemberCallExpr->getImplicitObjectArgument();
89-
QualType ArgType = MemberCallExpr->getObjectType();
89+
QualType ArgType = MemberCallExpr->getObjectType().getCanonicalType();
9090
std::optional<bool> IsUncounted = isUncounted(ArgType);
9191
if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
9292
reportBugOnThis(E);
@@ -102,12 +102,13 @@ class UncountedCallArgsChecker
102102
// if ((*P)->hasAttr<SafeRefCntblRawPtrAttr>())
103103
// continue;
104104

105-
const auto *ArgType = (*P)->getType().getTypePtrOrNull();
106-
if (!ArgType)
105+
QualType ArgType = (*P)->getType().getCanonicalType();
106+
const auto *TypePtr = ArgType.getTypePtrOrNull();
107+
if (!TypePtr)
107108
continue; // FIXME? Should we bail?
108109

109110
// FIXME: more complex types (arrays, references to raw pointers, etc)
110-
std::optional<bool> IsUncounted = isUncountedPtr(ArgType);
111+
std::optional<bool> IsUncounted = isUncountedPtr(TypePtr);
111112
if (!IsUncounted || !(*IsUncounted))
112113
continue;
113114

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
3+
#include "mock-types.h"
4+
5+
class Object {
6+
public:
7+
void ref() const;
8+
void deref() const;
9+
10+
bool constFunc() const;
11+
void mutableFunc();
12+
};
13+
14+
class Caller {
15+
void someFunction();
16+
void otherFunction();
17+
private:
18+
RefPtr<Object> m_obj;
19+
};
20+
21+
void Caller::someFunction()
22+
{
23+
m_obj->constFunc();
24+
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
25+
m_obj->mutableFunc();
26+
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
27+
}

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ set(files
2323
__algorithm/find_if.h
2424
__algorithm/find_if_not.h
2525
__algorithm/find_segment_if.h
26-
__algorithm/fold.h
2726
__algorithm/for_each.h
2827
__algorithm/for_each_n.h
2928
__algorithm/for_each_segment.h
@@ -98,6 +97,7 @@ set(files
9897
__algorithm/ranges_find_if.h
9998
__algorithm/ranges_find_if_not.h
10099
__algorithm/ranges_find_last.h
100+
__algorithm/ranges_fold.h
101101
__algorithm/ranges_for_each.h
102102
__algorithm/ranges_for_each_n.h
103103
__algorithm/ranges_generate.h

libcxx/include/__algorithm/fold.h renamed to libcxx/include/__algorithm/ranges_fold.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#ifndef _LIBCPP___ALGORITHM_FOLD_H
11-
#define _LIBCPP___ALGORITHM_FOLD_H
10+
#ifndef _LIBCPP___ALGORITHM_RANGES_FOLD_H
11+
#define _LIBCPP___ALGORITHM_RANGES_FOLD_H
1212

1313
#include <__concepts/assignable.h>
1414
#include <__concepts/constructible.h>
@@ -126,4 +126,4 @@ _LIBCPP_END_NAMESPACE_STD
126126

127127
_LIBCPP_POP_MACROS
128128

129-
#endif // _LIBCPP___ALGORITHM_FOLD_H
129+
#endif // _LIBCPP___ALGORITHM_RANGES_FOLD_H

libcxx/include/algorithm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,10 +2020,10 @@ template <class BidirectionalIterator, class Compare>
20202020
#endif
20212021

20222022
#if _LIBCPP_STD_VER >= 23
2023-
# include <__algorithm/fold.h>
20242023
# include <__algorithm/ranges_contains_subrange.h>
20252024
# include <__algorithm/ranges_ends_with.h>
20262025
# include <__algorithm/ranges_find_last.h>
2026+
# include <__algorithm/ranges_fold.h>
20272027
# include <__algorithm/ranges_starts_with.h>
20282028
#endif // _LIBCPP_STD_VER >= 23
20292029

libcxx/include/module.modulemap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ module std [system] {
412412
module find_if { header "__algorithm/find_if.h" }
413413
module find_segment_if { header "__algorithm/find_segment_if.h" }
414414
module find { header "__algorithm/find.h" }
415-
module fold { header "__algorithm/fold.h" }
416415
module for_each_n { header "__algorithm/for_each_n.h" }
417416
module for_each_segment { header "__algorithm/for_each_segment.h" }
418417
module for_each { header "__algorithm/for_each.h" }
@@ -529,6 +528,7 @@ module std [system] {
529528
module ranges_find_if { header "__algorithm/ranges_find_if.h" }
530529
module ranges_find_last { header "__algorithm/ranges_find_last.h" }
531530
module ranges_find { header "__algorithm/ranges_find.h" }
531+
module ranges_fold { header "__algorithm/ranges_fold.h" }
532532
module ranges_for_each_n {
533533
header "__algorithm/ranges_for_each_n.h"
534534
export std.algorithm.in_fun_result

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ function(append value)
324324
endforeach(variable)
325325
endfunction()
326326

327+
function(prepend value)
328+
foreach(variable ${ARGN})
329+
set(${variable} "${value} ${${variable}}" PARENT_SCOPE)
330+
endforeach(variable)
331+
endfunction()
332+
327333
function(append_if condition value)
328334
if (${condition})
329335
foreach(variable ${ARGN})
@@ -1198,7 +1204,7 @@ if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER))
11981204
endif()
11991205
file(TO_CMAKE_PATH "${clang_compiler_rt_file}" clang_compiler_rt_file)
12001206
get_filename_component(clang_runtime_dir "${clang_compiler_rt_file}" DIRECTORY)
1201-
append("/libpath:\"${clang_runtime_dir}\""
1207+
prepend("/libpath:\"${clang_runtime_dir}\""
12021208
CMAKE_EXE_LINKER_FLAGS
12031209
CMAKE_MODULE_LINKER_FLAGS
12041210
CMAKE_SHARED_LINKER_FLAGS)

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 513234
19+
#define LLVM_MAIN_REVISION 513241
2020

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

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,20 +447,20 @@ class AArch64MCInstrAnalysis : public MCInstrAnalysis {
447447
const MCRegisterClass &FPR128RC =
448448
MRI.getRegClass(AArch64::FPR128RegClassID);
449449

450-
auto ClearsSuperReg = [=](unsigned RegID) {
450+
auto ClearsSuperReg = [=](MCRegister Reg) {
451451
// An update to the lower 32 bits of a 64 bit integer register is
452452
// architecturally defined to zero extend the upper 32 bits on a write.
453-
if (GPR32RC.contains(RegID))
453+
if (GPR32RC.contains(Reg))
454454
return true;
455455
// SIMD&FP instructions operating on scalar data only acccess the lower
456456
// bits of a register, the upper bits are zero extended on a write. For
457457
// SIMD vector registers smaller than 128-bits, the upper 64-bits of the
458458
// register are zero extended on a write.
459459
// When VL is higher than 128 bits, any write to a SIMD&FP register sets
460460
// bits higher than 128 to zero.
461-
return FPR8RC.contains(RegID) || FPR16RC.contains(RegID) ||
462-
FPR32RC.contains(RegID) || FPR64RC.contains(RegID) ||
463-
FPR128RC.contains(RegID);
461+
return FPR8RC.contains(Reg) || FPR16RC.contains(Reg) ||
462+
FPR32RC.contains(Reg) || FPR64RC.contains(Reg) ||
463+
FPR128RC.contains(Reg);
464464
};
465465

466466
Mask.clearAllBits();

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,13 @@ struct RISCVOperand final : public MCParsedAsmOperand {
480480
RISCVMCRegisterClasses[RISCV::GPRRegClassID].contains(Reg.RegNum);
481481
}
482482

483+
bool isGPRF16() const {
484+
return Kind == KindTy::Register &&
485+
RISCVMCRegisterClasses[RISCV::GPRF16RegClassID].contains(Reg.RegNum);
486+
}
487+
483488
bool isGPRAsFPR() const { return isGPR() && Reg.IsGPRAsFPR; }
489+
bool isGPRAsFPR16() const { return isGPRF16() && Reg.IsGPRAsFPR; }
484490
bool isGPRPairAsFPR() const { return isGPRPair() && Reg.IsGPRAsFPR; }
485491

486492
bool isGPRPair() const {
@@ -1342,6 +1348,10 @@ unsigned RISCVAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
13421348
Op.Reg.RegNum = convertFPR64ToFPR16(Reg);
13431349
return Match_Success;
13441350
}
1351+
if (Kind == MCK_GPRAsFPR16 && Op.isGPRAsFPR()) {
1352+
Op.Reg.RegNum = Reg - RISCV::X0 + RISCV::X0_H;
1353+
return Match_Success;
1354+
}
13451355

13461356
// There are some GPRF64AsFPR instructions that have no RV32 equivalent. We
13471357
// reject them at parsing thinking we should match as GPRPairAsFPR for RV32.

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, uint32_t RegNo,
8181
return MCDisassembler::Success;
8282
}
8383

84+
static DecodeStatus DecodeGPRF16RegisterClass(MCInst &Inst, uint32_t RegNo,
85+
uint64_t Address,
86+
const MCDisassembler *Decoder) {
87+
bool IsRVE = Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
88+
89+
if (RegNo >= 32 || (IsRVE && RegNo >= 16))
90+
return MCDisassembler::Fail;
91+
92+
MCRegister Reg = RISCV::X0_H + RegNo;
93+
Inst.addOperand(MCOperand::createReg(Reg));
94+
return MCDisassembler::Success;
95+
}
96+
8497
static DecodeStatus DecodeGPRX1X5RegisterClass(MCInst &Inst, uint32_t RegNo,
8598
uint64_t Address,
8699
const MCDisassembler *Decoder) {

llvm/lib/Target/RISCV/RISCVCallingConv.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ ArrayRef<MCPhysReg> RISCV::getArgGPRs(const RISCVABI::ABI ABI) {
139139
return ArrayRef(ArgIGPRs);
140140
}
141141

142+
static ArrayRef<MCPhysReg> getArgGPR16s(const RISCVABI::ABI ABI) {
143+
// The GPRs used for passing arguments in the ILP32* and LP64* ABIs, except
144+
// the ILP32E ABI.
145+
static const MCPhysReg ArgIGPRs[] = {RISCV::X10_H, RISCV::X11_H, RISCV::X12_H,
146+
RISCV::X13_H, RISCV::X14_H, RISCV::X15_H,
147+
RISCV::X16_H, RISCV::X17_H};
148+
// The GPRs used for passing arguments in the ILP32E/LP64E ABI.
149+
static const MCPhysReg ArgEGPRs[] = {RISCV::X10_H, RISCV::X11_H,
150+
RISCV::X12_H, RISCV::X13_H,
151+
RISCV::X14_H, RISCV::X15_H};
152+
153+
if (ABI == RISCVABI::ABI_ILP32E || ABI == RISCVABI::ABI_LP64E)
154+
return ArrayRef(ArgEGPRs);
155+
156+
return ArrayRef(ArgIGPRs);
157+
}
158+
142159
static ArrayRef<MCPhysReg> getFastCCArgGPRs(const RISCVABI::ABI ABI) {
143160
// The GPRs used for passing arguments in the FastCC, X5 and X6 might be used
144161
// for save-restore libcall, so we don't use them.
@@ -157,6 +174,26 @@ static ArrayRef<MCPhysReg> getFastCCArgGPRs(const RISCVABI::ABI ABI) {
157174
return ArrayRef(FastCCIGPRs);
158175
}
159176

177+
static ArrayRef<MCPhysReg> getFastCCArgGPRF16s(const RISCVABI::ABI ABI) {
178+
// The GPRs used for passing arguments in the FastCC, X5 and X6 might be used
179+
// for save-restore libcall, so we don't use them.
180+
// Don't use X7 for fastcc, since Zicfilp uses X7 as the label register.
181+
static const MCPhysReg FastCCIGPRs[] = {
182+
RISCV::X10_H, RISCV::X11_H, RISCV::X12_H, RISCV::X13_H,
183+
RISCV::X14_H, RISCV::X15_H, RISCV::X16_H, RISCV::X17_H,
184+
RISCV::X28_H, RISCV::X29_H, RISCV::X30_H, RISCV::X31_H};
185+
186+
// The GPRs used for passing arguments in the FastCC when using ILP32E/LP64E.
187+
static const MCPhysReg FastCCEGPRs[] = {RISCV::X10_H, RISCV::X11_H,
188+
RISCV::X12_H, RISCV::X13_H,
189+
RISCV::X14_H, RISCV::X15_H};
190+
191+
if (ABI == RISCVABI::ABI_ILP32E || ABI == RISCVABI::ABI_LP64E)
192+
return ArrayRef(FastCCEGPRs);
193+
194+
return ArrayRef(FastCCIGPRs);
195+
}
196+
160197
// Pass a 2*XLEN argument that has been split into two XLEN values through
161198
// registers or the stack as necessary.
162199
static bool CC_RISCVAssign2XLen(unsigned XLen, CCState &State, CCValAssign VA1,
@@ -320,6 +357,13 @@ bool llvm::CC_RISCV(unsigned ValNo, MVT ValVT, MVT LocVT,
320357
}
321358
}
322359

360+
if ((ValVT == MVT::f16 && Subtarget.hasStdExtZhinxmin())) {
361+
if (MCRegister Reg = State.AllocateReg(getArgGPR16s(ABI))) {
362+
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
363+
return false;
364+
}
365+
}
366+
323367
ArrayRef<MCPhysReg> ArgGPRs = RISCV::getArgGPRs(ABI);
324368

325369
// Zfinx/Zdinx use GPR without a bitcast when possible.
@@ -564,9 +608,16 @@ bool llvm::CC_RISCV_FastCC(unsigned ValNo, MVT ValVT, MVT LocVT,
564608

565609
MVT XLenVT = Subtarget.getXLenVT();
566610

611+
// Check if there is an available GPRF16 before hitting the stack.
612+
if ((LocVT == MVT::f16 && Subtarget.hasStdExtZhinxmin())) {
613+
if (MCRegister Reg = State.AllocateReg(getFastCCArgGPRF16s(ABI))) {
614+
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
615+
return false;
616+
}
617+
}
618+
567619
// Check if there is an available GPR before hitting the stack.
568-
if ((LocVT == MVT::f16 && Subtarget.hasStdExtZhinxmin()) ||
569-
(LocVT == MVT::f32 && Subtarget.hasStdExtZfinx()) ||
620+
if ((LocVT == MVT::f32 && Subtarget.hasStdExtZfinx()) ||
570621
(LocVT == MVT::f64 && Subtarget.is64Bit() &&
571622
Subtarget.hasStdExtZdinx())) {
572623
if (MCRegister Reg = State.AllocateReg(getFastCCArgGPRs(ABI))) {

llvm/lib/Target/RISCV/RISCVDeadRegisterDefinitions.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ bool RISCVDeadRegisterDefinitions::runOnMachineFunction(MachineFunction &MF) {
9393
continue;
9494
LLVM_DEBUG(dbgs() << " Dead def operand #" << I << " in:\n ";
9595
MI.print(dbgs()));
96+
Register X0Reg;
9697
const TargetRegisterClass *RC = TII->getRegClass(Desc, I, TRI, MF);
97-
if (!(RC && RC->contains(RISCV::X0))) {
98+
if (RC && RC->contains(RISCV::X0)) {
99+
X0Reg = RISCV::X0;
100+
} else if (RC && RC->contains(RISCV::X0_H)) {
101+
X0Reg = RISCV::X0_H;
102+
} else {
98103
LLVM_DEBUG(dbgs() << " Ignoring, register is not a GPR.\n");
99104
continue;
100105
}
101106
assert(LIS.hasInterval(Reg));
102107
LIS.removeInterval(Reg);
103-
MO.setReg(RISCV::X0);
108+
MO.setReg(X0Reg);
104109
LLVM_DEBUG(dbgs() << " Replacing with zero register. New:\n ";
105110
MI.print(dbgs()));
106111
++NumDeadDefsReplaced;

llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class RISCVExpandPseudo : public MachineFunctionPass {
4848
MachineBasicBlock::iterator &NextMBBI);
4949
bool expandVMSET_VMCLR(MachineBasicBlock &MBB,
5050
MachineBasicBlock::iterator MBBI, unsigned Opcode);
51+
bool expandMV_FPR16INX(MachineBasicBlock &MBB,
52+
MachineBasicBlock::iterator MBBI);
5153
bool expandRV32ZdinxStore(MachineBasicBlock &MBB,
5254
MachineBasicBlock::iterator MBBI);
5355
bool expandRV32ZdinxLoad(MachineBasicBlock &MBB,
@@ -104,6 +106,8 @@ bool RISCVExpandPseudo::expandMI(MachineBasicBlock &MBB,
104106
// expanded instructions for each pseudo is correct in the Size field of the
105107
// tablegen definition for the pseudo.
106108
switch (MBBI->getOpcode()) {
109+
case RISCV::PseudoMV_FPR16INX:
110+
return expandMV_FPR16INX(MBB, MBBI);
107111
case RISCV::PseudoRV32ZdinxSD:
108112
return expandRV32ZdinxStore(MBB, MBBI);
109113
case RISCV::PseudoRV32ZdinxLD:
@@ -266,6 +270,23 @@ bool RISCVExpandPseudo::expandVMSET_VMCLR(MachineBasicBlock &MBB,
266270
return true;
267271
}
268272

273+
bool RISCVExpandPseudo::expandMV_FPR16INX(MachineBasicBlock &MBB,
274+
MachineBasicBlock::iterator MBBI) {
275+
DebugLoc DL = MBBI->getDebugLoc();
276+
const TargetRegisterInfo *TRI = STI->getRegisterInfo();
277+
Register DstReg = TRI->getMatchingSuperReg(
278+
MBBI->getOperand(0).getReg(), RISCV::sub_16, &RISCV::GPRRegClass);
279+
Register SrcReg = TRI->getMatchingSuperReg(
280+
MBBI->getOperand(1).getReg(), RISCV::sub_16, &RISCV::GPRRegClass);
281+
282+
BuildMI(MBB, MBBI, DL, TII->get(RISCV::ADDI), DstReg)
283+
.addReg(SrcReg, getKillRegState(MBBI->getOperand(1).isKill()))
284+
.addImm(0);
285+
286+
MBBI->eraseFromParent(); // The pseudo instruction is gone now.
287+
return true;
288+
}
289+
269290
// This function expands the PseudoRV32ZdinxSD for storing a double-precision
270291
// floating-point value into memory by generating an equivalent instruction
271292
// sequence for RV32.

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,10 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
928928
}
929929

930930
SDNode *Res;
931-
if (Opc == RISCV::FCVT_D_W_IN32X || Opc == RISCV::FCVT_D_W)
931+
if (VT.SimpleTy == MVT::f16 && Opc == RISCV::COPY) {
932+
Res =
933+
CurDAG->getTargetExtractSubreg(RISCV::sub_16, DL, VT, Imm).getNode();
934+
} else if (Opc == RISCV::FCVT_D_W_IN32X || Opc == RISCV::FCVT_D_W)
932935
Res = CurDAG->getMachineNode(
933936
Opc, DL, VT, Imm,
934937
CurDAG->getTargetConstant(RISCVFPRndMode::RNE, DL, XLenVT));

0 commit comments

Comments
 (0)