Skip to content

Commit 7f8d562

Browse files
author
Jenkins
committed
merge main into amd-stg-open
Change-Id: I3ee32aa50081897c211a761523480f61a7aed6e5
2 parents 28582c8 + 89b0f1e commit 7f8d562

File tree

126 files changed

+4131
-2066
lines changed

Some content is hidden

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

126 files changed

+4131
-2066
lines changed

.github/workflows/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ on:
2424
- 'openmp/docs/**'
2525
- 'polly/docs/**'
2626
- 'flang/docs/**'
27+
- 'flang/include/flang/Optimizer/Dialect/FIROps.td'
2728
pull_request:
2829
paths:
2930
- 'llvm/docs/**'
@@ -37,6 +38,7 @@ on:
3738
- 'openmp/docs/**'
3839
- 'polly/docs/**'
3940
- 'flang/docs/**'
41+
- 'flang/include/flang/Optimizer/Dialect/FIROps.td'
4042

4143
jobs:
4244
check-docs-build:
@@ -80,6 +82,7 @@ jobs:
8082
- 'polly/docs/**'
8183
flang:
8284
- 'flang/docs/**'
85+
- 'flang/include/flang/Optimizer/Dialect/FIROps.td'
8386
- name: Fetch LLVM sources (PR)
8487
if: ${{ github.event_name == 'pull_request' }}
8588
uses: actions/checkout@v4

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,11 +1421,6 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
14211421
Protocol = GV;
14221422
return GV;
14231423
}
1424-
llvm::Constant *EnforceType(llvm::Constant *Val, llvm::Type *Ty) {
1425-
if (Val->getType() == Ty)
1426-
return Val;
1427-
return llvm::ConstantExpr::getBitCast(Val, Ty);
1428-
}
14291424
llvm::Value *GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
14301425
const std::string &TypeEncoding) override {
14311426
return GetConstantSelector(Sel, TypeEncoding);
@@ -1462,7 +1457,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
14621457
auto SelVarName = (StringRef(".objc_selector_") + Sel.getAsString() + "_" +
14631458
MangledTypes).str();
14641459
if (auto *GV = TheModule.getNamedGlobal(SelVarName))
1465-
return EnforceType(GV, SelectorTy);
1460+
return GV;
14661461
ConstantInitBuilder builder(CGM);
14671462
auto SelBuilder = builder.beginStruct();
14681463
SelBuilder.add(ExportUniqueString(Sel.getAsString(), ".objc_sel_name_",
@@ -1473,8 +1468,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
14731468
GV->setComdat(TheModule.getOrInsertComdat(SelVarName));
14741469
GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
14751470
GV->setSection(sectionName<SelectorSection>());
1476-
auto *SelVal = EnforceType(GV, SelectorTy);
1477-
return SelVal;
1471+
return GV;
14781472
}
14791473
llvm::StructType *emptyStruct = nullptr;
14801474

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ CGObjCCommonMac::GenerateConstantNSString(const StringLiteral *Literal) {
20142014
// Don't enforce the target's minimum global alignment, since the only use
20152015
// of the string is via this class initializer.
20162016
GV->setAlignment(llvm::Align(1));
2017-
Fields.addBitCast(GV, CGM.Int8PtrTy);
2017+
Fields.add(GV);
20182018

20192019
// String length.
20202020
Fields.addInt(CGM.IntTy, StringLength);
@@ -3557,8 +3557,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
35573557
// Record a reference to the super class.
35583558
LazySymbols.insert(Super->getIdentifier());
35593559

3560-
values.addBitCast(GetClassName(Super->getObjCRuntimeNameAsString()),
3561-
ObjCTypes.ClassPtrTy);
3560+
values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
35623561
} else {
35633562
values.addNullPointer(ObjCTypes.ClassPtrTy);
35643563
}
@@ -3612,14 +3611,12 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID,
36123611
const ObjCInterfaceDecl *Root = ID->getClassInterface();
36133612
while (const ObjCInterfaceDecl *Super = Root->getSuperClass())
36143613
Root = Super;
3615-
values.addBitCast(GetClassName(Root->getObjCRuntimeNameAsString()),
3616-
ObjCTypes.ClassPtrTy);
3614+
values.add(GetClassName(Root->getObjCRuntimeNameAsString()));
36173615
// The super class for the metaclass is emitted as the name of the
36183616
// super class. The runtime fixes this up to point to the
36193617
// *metaclass* for the super class.
36203618
if (ObjCInterfaceDecl *Super = ID->getClassInterface()->getSuperClass()) {
3621-
values.addBitCast(GetClassName(Super->getObjCRuntimeNameAsString()),
3622-
ObjCTypes.ClassPtrTy);
3619+
values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
36233620
} else {
36243621
values.addNullPointer(ObjCTypes.ClassPtrTy);
36253622
}
@@ -3815,8 +3812,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID,
38153812
void CGObjCMac::emitMethodDescriptionConstant(ConstantArrayBuilder &builder,
38163813
const ObjCMethodDecl *MD) {
38173814
auto description = builder.beginStruct(ObjCTypes.MethodDescriptionTy);
3818-
description.addBitCast(GetMethodVarName(MD->getSelector()),
3819-
ObjCTypes.SelectorPtrTy);
3815+
description.add(GetMethodVarName(MD->getSelector()));
38203816
description.add(GetMethodVarType(MD));
38213817
description.finishAndAddTo(builder);
38223818
}
@@ -3834,10 +3830,9 @@ void CGObjCMac::emitMethodConstant(ConstantArrayBuilder &builder,
38343830
assert(fn && "no definition registered for method");
38353831

38363832
auto method = builder.beginStruct(ObjCTypes.MethodTy);
3837-
method.addBitCast(GetMethodVarName(MD->getSelector()),
3838-
ObjCTypes.SelectorPtrTy);
3833+
method.add(GetMethodVarName(MD->getSelector()));
38393834
method.add(GetMethodVarType(MD));
3840-
method.addBitCast(fn, ObjCTypes.Int8PtrTy);
3835+
method.add(fn);
38413836
method.finishAndAddTo(builder);
38423837
}
38433838

@@ -5191,10 +5186,10 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() {
51915186
if (ID->isWeakImported() && !IMP->isWeakImported())
51925187
DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
51935188

5194-
array.addBitCast(DefinedClasses[i], ObjCTypes.Int8PtrTy);
5189+
array.add(DefinedClasses[i]);
51955190
}
51965191
for (unsigned i=0; i<NumCategories; i++)
5197-
array.addBitCast(DefinedCategories[i], ObjCTypes.Int8PtrTy);
5192+
array.add(DefinedCategories[i]);
51985193

51995194
array.finishAndAddTo(values);
52005195

@@ -6735,8 +6730,7 @@ void CGObjCNonFragileABIMac::emitMethodConstant(ConstantArrayBuilder &builder,
67356730
const ObjCMethodDecl *MD,
67366731
bool forProtocol) {
67376732
auto method = builder.beginStruct(ObjCTypes.MethodTy);
6738-
method.addBitCast(GetMethodVarName(MD->getSelector()),
6739-
ObjCTypes.SelectorPtrTy);
6733+
method.add(GetMethodVarName(MD->getSelector()));
67406734
method.add(GetMethodVarType(MD));
67416735

67426736
if (forProtocol) {
@@ -6745,7 +6739,7 @@ void CGObjCNonFragileABIMac::emitMethodConstant(ConstantArrayBuilder &builder,
67456739
} else {
67466740
llvm::Function *fn = GetMethodDefinition(MD);
67476741
assert(fn && "no definition for method?");
6748-
method.addBitCast(fn, ObjCTypes.Int8PtrProgramASTy);
6742+
method.add(fn);
67496743
}
67506744

67516745
method.finishAndAddTo(builder);

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,9 +3824,10 @@ class TargetLowering : public TargetLoweringBase {
38243824
return false;
38253825
}
38263826

3827-
/// Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the casts are free. This
3828-
/// uses isZExtFree and ZERO_EXTEND for the widening cast, but it could be
3829-
/// generalized for targets with other types of implicit widening casts.
3827+
/// Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the casts are free.
3828+
/// This uses isTruncateFree/isZExtFree and ANY_EXTEND for the widening cast,
3829+
/// but it could be generalized for targets with other types of implicit
3830+
/// widening casts.
38303831
bool ShrinkDemandedOp(SDValue Op, unsigned BitWidth,
38313832
const APInt &DemandedBits,
38323833
TargetLoweringOpt &TLO) const;

llvm/include/llvm/MC/MCFragment.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,11 @@ class MCLEBFragment final : public MCEncodedFragmentWithFixups<10, 1> {
435435
/// The value this fragment should contain.
436436
const MCExpr *Value;
437437

438-
SmallString<8> Contents;
439-
440438
public:
441439
MCLEBFragment(const MCExpr &Value, bool IsSigned, MCSection *Sec = nullptr)
442440
: MCEncodedFragmentWithFixups<10, 1>(FT_LEB, false, Sec),
443441
IsSigned(IsSigned), Value(&Value) {
444-
Contents.push_back(0);
442+
getContents().push_back(0);
445443
}
446444

447445
const MCExpr &getValue() const { return *Value; }

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10852,6 +10852,10 @@ void SelectionDAG::salvageDebugInfo(SDNode &N) {
1085210852
uint64_t Offset;
1085310853
if (RHSConstant)
1085410854
Offset = N.getConstantOperandVal(1);
10855+
// We are not allowed to turn indirect debug values variadic, so
10856+
// don't salvage those.
10857+
if (!RHSConstant && DV->isIndirect())
10858+
continue;
1085510859

1085610860
// Rewrite an ADD constant node into a DIExpression. Since we are
1085710861
// performing arithmetic to compute the variable's *value* in the

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,9 @@ bool TargetLowering::ShrinkDemandedConstant(SDValue Op,
566566
}
567567

568568
/// Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the casts are free.
569-
/// This uses isZExtFree and ZERO_EXTEND for the widening cast, but it could be
570-
/// generalized for targets with other types of implicit widening casts.
569+
/// This uses isTruncateFree/isZExtFree and ANY_EXTEND for the widening cast,
570+
/// but it could be generalized for targets with other types of implicit
571+
/// widening casts.
571572
bool TargetLowering::ShrinkDemandedOp(SDValue Op, unsigned BitWidth,
572573
const APInt &DemandedBits,
573574
TargetLoweringOpt &TLO) const {

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

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
2121
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
2222
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
23+
#include "llvm/CodeGen/MachineJumpTableInfo.h"
2324
#include "llvm/IR/IntrinsicsRISCV.h"
2425
#include "llvm/Support/Debug.h"
2526

@@ -64,6 +65,8 @@ class RISCVInstructionSelector : public InstructionSelector {
6465
bool materializeImm(Register Reg, int64_t Imm, MachineIRBuilder &MIB) const;
6566
bool selectGlobalValue(MachineInstr &MI, MachineIRBuilder &MIB,
6667
MachineRegisterInfo &MRI) const;
68+
bool selectJumpTable(MachineInstr &MI, MachineIRBuilder &MIB,
69+
MachineRegisterInfo &MRI) const;
6770
bool selectSExtInreg(MachineInstr &MI, MachineIRBuilder &MIB) const;
6871
bool selectSelect(MachineInstr &MI, MachineIRBuilder &MIB,
6972
MachineRegisterInfo &MRI) const;
@@ -483,6 +486,8 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
483486
}
484487
case TargetOpcode::G_GLOBAL_VALUE:
485488
return selectGlobalValue(MI, MIB, MRI);
489+
case TargetOpcode::G_JUMP_TABLE:
490+
return selectJumpTable(MI, MIB, MRI);
486491
case TargetOpcode::G_BRCOND: {
487492
Register LHS, RHS;
488493
RISCVCC::CondCode CC;
@@ -493,6 +498,58 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
493498
MI.eraseFromParent();
494499
return constrainSelectedInstRegOperands(*Bcc, TII, TRI, RBI);
495500
}
501+
case TargetOpcode::G_BRJT: {
502+
// FIXME: Move to legalization?
503+
const MachineJumpTableInfo *MJTI = MF.getJumpTableInfo();
504+
unsigned EntrySize = MJTI->getEntrySize(MF.getDataLayout());
505+
assert((EntrySize == 4 || (Subtarget->is64Bit() && EntrySize == 8)) &&
506+
"Unsupported jump-table entry size");
507+
assert(
508+
(MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 ||
509+
MJTI->getEntryKind() == MachineJumpTableInfo::EK_Custom32 ||
510+
MJTI->getEntryKind() == MachineJumpTableInfo::EK_BlockAddress) &&
511+
"Unexpected jump-table entry kind");
512+
513+
auto SLL =
514+
MIB.buildInstr(RISCV::SLLI, {&RISCV::GPRRegClass}, {MI.getOperand(2)})
515+
.addImm(Log2_32(EntrySize));
516+
if (!SLL.constrainAllUses(TII, TRI, RBI))
517+
return false;
518+
519+
// TODO: Use SHXADD. Moving to legalization would fix this automatically.
520+
auto ADD = MIB.buildInstr(RISCV::ADD, {&RISCV::GPRRegClass},
521+
{MI.getOperand(0), SLL.getReg(0)});
522+
if (!ADD.constrainAllUses(TII, TRI, RBI))
523+
return false;
524+
525+
unsigned LdOpc = EntrySize == 8 ? RISCV::LD : RISCV::LW;
526+
auto Dest =
527+
MIB.buildInstr(LdOpc, {&RISCV::GPRRegClass}, {ADD.getReg(0)})
528+
.addImm(0)
529+
.addMemOperand(MF.getMachineMemOperand(
530+
MachinePointerInfo::getJumpTable(MF), MachineMemOperand::MOLoad,
531+
EntrySize, Align(MJTI->getEntryAlignment(MF.getDataLayout()))));
532+
if (!Dest.constrainAllUses(TII, TRI, RBI))
533+
return false;
534+
535+
// If the Kind is EK_LabelDifference32, the table stores an offset from
536+
// the location of the table. Add the table address to get an absolute
537+
// address.
538+
if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32) {
539+
Dest = MIB.buildInstr(RISCV::ADD, {&RISCV::GPRRegClass},
540+
{Dest.getReg(0), MI.getOperand(0)});
541+
if (!Dest.constrainAllUses(TII, TRI, RBI))
542+
return false;
543+
}
544+
545+
auto Branch =
546+
MIB.buildInstr(RISCV::PseudoBRIND, {}, {Dest.getReg(0)}).addImm(0);
547+
if (!Branch.constrainAllUses(TII, TRI, RBI))
548+
return false;
549+
550+
MI.eraseFromParent();
551+
return true;
552+
}
496553
case TargetOpcode::G_SEXT_INREG:
497554
return selectSExtInreg(MI, MIB);
498555
case TargetOpcode::G_FRAME_INDEX: {
@@ -784,6 +841,97 @@ bool RISCVInstructionSelector::selectGlobalValue(
784841
return false;
785842
}
786843

844+
// FIXME: This is very similar to selectGlobalValue. Merge somehow?
845+
bool RISCVInstructionSelector::selectJumpTable(MachineInstr &MI,
846+
MachineIRBuilder &MIB,
847+
MachineRegisterInfo &MRI) const {
848+
assert(MI.getOpcode() == TargetOpcode::G_JUMP_TABLE &&
849+
"Expected G_JUMP_TABLE");
850+
851+
int Idx = MI.getOperand(1).getIndex();
852+
853+
Register DefReg = MI.getOperand(0).getReg();
854+
const LLT DefTy = MRI.getType(DefReg);
855+
MachineInstr *Result = nullptr;
856+
857+
// When HWASAN is used and tagging of global variables is enabled
858+
// they should be accessed via the GOT, since the tagged address of a global
859+
// is incompatible with existing code models. This also applies to non-pic
860+
// mode.
861+
if (TM.isPositionIndependent() || Subtarget->allowTaggedGlobals()) {
862+
if (!Subtarget->allowTaggedGlobals()) {
863+
// Use PC-relative addressing to access the symbol. This generates the
864+
// pattern (PseudoLLA sym), which expands to (addi (auipc %pcrel_hi(sym))
865+
// %pcrel_lo(auipc)).
866+
Result =
867+
MIB.buildInstr(RISCV::PseudoLLA, {DefReg}, {}).addJumpTableIndex(Idx);
868+
} else {
869+
// Use PC-relative addressing to access the GOT for this symbol, then
870+
// load the address from the GOT. This generates the pattern (PseudoLGA
871+
// sym), which expands to (ld (addi (auipc %got_pcrel_hi(sym))
872+
// %pcrel_lo(auipc))).
873+
MachineFunction &MF = *MI.getParent()->getParent();
874+
MachineMemOperand *MemOp = MF.getMachineMemOperand(
875+
MachinePointerInfo::getGOT(MF),
876+
MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
877+
MachineMemOperand::MOInvariant,
878+
DefTy, Align(DefTy.getSizeInBits() / 8));
879+
880+
Result = MIB.buildInstr(RISCV::PseudoLGA, {DefReg}, {})
881+
.addJumpTableIndex(Idx)
882+
.addMemOperand(MemOp);
883+
}
884+
885+
if (!constrainSelectedInstRegOperands(*Result, TII, TRI, RBI))
886+
return false;
887+
888+
MI.eraseFromParent();
889+
return true;
890+
}
891+
892+
switch (TM.getCodeModel()) {
893+
default: {
894+
reportGISelFailure(const_cast<MachineFunction &>(*MF), *TPC, *MORE,
895+
getName(), "Unsupported code model for lowering", MI);
896+
return false;
897+
}
898+
case CodeModel::Small: {
899+
// Must lie within a single 2 GiB address range and must lie between
900+
// absolute addresses -2 GiB and +2 GiB. This generates the pattern (addi
901+
// (lui %hi(sym)) %lo(sym)).
902+
Register AddrHiDest = MRI.createVirtualRegister(&RISCV::GPRRegClass);
903+
MachineInstr *AddrHi = MIB.buildInstr(RISCV::LUI, {AddrHiDest}, {})
904+
.addJumpTableIndex(Idx, RISCVII::MO_HI);
905+
906+
if (!constrainSelectedInstRegOperands(*AddrHi, TII, TRI, RBI))
907+
return false;
908+
909+
Result = MIB.buildInstr(RISCV::ADDI, {DefReg}, {AddrHiDest})
910+
.addJumpTableIndex(Idx, RISCVII::MO_LO);
911+
912+
if (!constrainSelectedInstRegOperands(*Result, TII, TRI, RBI))
913+
return false;
914+
915+
MI.eraseFromParent();
916+
return true;
917+
}
918+
case CodeModel::Medium: {
919+
// Generate a sequence for accessing addresses within any 2GiB range
920+
// within the address space. This generates the pattern (PseudoLLA sym),
921+
// which expands to (addi (auipc %pcrel_hi(sym)) %pcrel_lo(auipc)).
922+
Result =
923+
MIB.buildInstr(RISCV::PseudoLLA, {DefReg}, {}).addJumpTableIndex(Idx);
924+
925+
if (!constrainSelectedInstRegOperands(*Result, TII, TRI, RBI))
926+
return false;
927+
928+
MI.eraseFromParent();
929+
return true;
930+
}
931+
}
932+
return false;
933+
}
934+
787935
bool RISCVInstructionSelector::selectSExtInreg(MachineInstr &MI,
788936
MachineIRBuilder &MIB) const {
789937
if (!STI.isRV64())

0 commit comments

Comments
 (0)