Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I32336bcbb179552aed09f52c73c7130c5b919cfc
  • Loading branch information
Jenkins committed Feb 4, 2024
2 parents 15ce422 + 3bcb1f2 commit ac1fecc
Show file tree
Hide file tree
Showing 27 changed files with 1,085 additions and 59 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/llvm-project-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,23 @@ jobs:
key: ${{ matrix.os }}
variant: sccache
- name: Build and Test
uses: llvm/actions/build-test-llvm-project@main
env:
# Workaround for https://github.com/actions/virtual-environments/issues/5900.
# This should be a no-op for non-mac OSes
PKG_CONFIG_PATH: /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig//12
with:
cmake_args: '-GNinja -DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLDB_INCLUDE_TESTS=OFF -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache ${{ inputs.extra_cmake_args }}'
build_target: '${{ inputs.build_target }}'
shell: bash
run: |
cmake -G Ninja \
-B build \
-S llvm \
-DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLDB_INCLUDE_TESTS=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
${{ inputs.extra_cmake_args }}
ninja -C build '${{ inputs.build_target }}'
- name: Build and Test libclc
if: "!startsWith(matrix.os, 'windows') && contains(inputs.projects, 'libclc')"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr-code-format.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: "Check code formatting"
on: pull_request_target
branches:
- main

permissions:
pull-requests: write

Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Basic/Sarif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ static std::string percentEncodeURICharacter(char C) {
// should be written out directly. Otherwise, percent
// encode the character and write that out instead of the
// reserved character.
if (llvm::isAlnum(C) ||
StringRef::npos != StringRef("-._~:@!$&'()*+,;=").find(C))
if (llvm::isAlnum(C) || StringRef("-._~:@!$&'()*+,;=").contains(C))
return std::string(&C, 1);
return "%" + llvm::toHex(StringRef(&C, 1));
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/X86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool X86TargetInfo::initFeatureMap(
if (Feature.substr(1, 6) == "avx10.") {
if (Feature[0] == '+') {
HasAVX10 = true;
if (Feature.substr(Feature.size() - 3, 3) == "512")
if (StringRef(Feature).ends_with("512"))
HasAVX10_512 = true;
LastAVX10 = Feature;
} else if (HasAVX10 && Feature == "-avx10.1-256") {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,9 +1347,10 @@ static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction &CGF) {

llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);

// Mark the function as nounwind readonly.
// Mark the function as nounwind willreturn readonly.
llvm::AttrBuilder FuncAttrs(CGF.getLLVMContext());
FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
FuncAttrs.addAttribute(llvm::Attribute::WillReturn);
FuncAttrs.addMemoryAttr(llvm::MemoryEffects::readOnly());
llvm::AttributeList Attrs = llvm::AttributeList::get(
CGF.getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs);
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5838,6 +5838,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// NVPTX/AMDGPU does not care about the code model and will accept
// whatever works for the host.
Ok = true;
} else if (Triple.isSPARC64()) {
if (CM == "medlow")
CM = "small";
else if (CM == "medmid")
CM = "medium";
else if (CM == "medany")
CM = "large";
Ok = CM == "small" || CM == "medium" || CM == "large";
}
if (Ok) {
CmdArgs.push_back(Args.MakeArgString("-mcmodel=" + CM));
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ const B& f(A *a) {

// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), i64) [[NUW_RO:#[0-9]+]]

// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
// CHECK: attributes [[NUW_RO]] = { nounwind willreturn memory(read) }
// CHECK: attributes [[NR]] = { noreturn }
8 changes: 8 additions & 0 deletions clang/test/CodeGenCXX/dynamic-cast-dead.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -I%S %s -O3 -triple x86_64-apple-darwin10 -emit-llvm -fcxx-exceptions -fexceptions -std=c++11 -o - | FileCheck %s
struct A { virtual ~A(); };
struct B : A { };

void foo(A* a) {
// CHECK-NOT: call {{.*}} @__dynamic_cast
B* b = dynamic_cast<B*>(a);
}
2 changes: 1 addition & 1 deletion clang/test/CodeGenCXX/dynamic-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ const B& f(A *a) {

// CHECK: declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) [[NUW_RO:#[0-9]+]]

// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
// CHECK: attributes [[NUW_RO]] = { nounwind willreturn memory(read) }
// CHECK: attributes [[NR]] = { noreturn }
6 changes: 6 additions & 0 deletions clang/test/Driver/sparc64-codemodel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang --target=sparc64 -mcmodel=medlow %s -### 2>&1 | FileCheck -check-prefix=MEDLOW %s
// RUN: %clang --target=sparc64 -mcmodel=medmid %s -### 2>&1 | FileCheck -check-prefix=MEDMID %s
// RUN: %clang --target=sparc64 -mcmodel=medany %s -### 2>&1 | FileCheck -check-prefix=MEDANY %s
// MEDLOW: "-mcmodel=small"
// MEDMID: "-mcmodel=medium"
// MEDANY: "-mcmodel=large"
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MIRParser/MIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ bool MIRParserImpl::parseRegisterInfo(PerFunctionMIParsingState &PFS,
Twine(VReg.ID.Value) + "'");
Info.Explicit = true;

if (StringRef(VReg.Class.Value).equals("_")) {
if (VReg.Class.Value == "_") {
Info.Kind = VRegInfo::GENERIC;
Info.D.RegBank = nullptr;
} else {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/MachineBlockPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2923,8 +2923,8 @@ void MachineBlockPlacement::alignBlocks() {
unsigned MDAlign = 1;
MDNode *LoopID = L->getLoopID();
if (LoopID) {
for (unsigned I = 1, E = LoopID->getNumOperands(); I < E; ++I) {
MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(I));
for (const MDOperand &MDO : llvm::drop_begin(LoopID->operands())) {
MDNode *MD = dyn_cast<MDNode>(MDO);
if (MD == nullptr)
continue;
MDString *S = dyn_cast<MDString>(MD->getOperand(0));
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/MachinePipeliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ void MachinePipeliner::setPragmaPipelineOptions(MachineLoop &L) {
assert(LoopID->getNumOperands() > 0 && "requires atleast one operand");
assert(LoopID->getOperand(0) == LoopID && "invalid loop");

for (unsigned i = 1, e = LoopID->getNumOperands(); i < e; ++i) {
MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
for (const MDOperand &MDO : llvm::drop_begin(LoopID->operands())) {
MDNode *MD = dyn_cast<MDNode>(MDO);

if (MD == nullptr)
continue;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ void RuntimeDyldELF::resolveARMRelocation(const SectionEntry &Section,

void RuntimeDyldELF::setMipsABI(const ObjectFile &Obj) {
if (Arch == Triple::UnknownArch ||
!StringRef(Triple::getArchTypePrefix(Arch)).equals("mips")) {
Triple::getArchTypePrefix(Arch) != "mips") {
IsMipsO32ABI = false;
IsMipsN32ABI = false;
IsMipsN64ABI = false;
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/FileCheck/FileCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,7 @@ bool Pattern::parsePattern(StringRef PatternStr, StringRef Prefix,

if (!(Req.NoCanonicalizeWhiteSpace && Req.MatchFullLines))
// Ignore trailing whitespace.
while (!PatternStr.empty() &&
(PatternStr.back() == ' ' || PatternStr.back() == '\t'))
PatternStr = PatternStr.substr(0, PatternStr.size() - 1);
PatternStr = PatternStr.rtrim(" \t");

// Check that there is something on the line.
if (PatternStr.empty() && CheckTy != Check::CheckEmpty) {
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
.legalForCartesianProduct({s32}, {s32, s64});
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
.legalForCartesianProduct({s32, s64}, {s32});

getActionDefinitionsBuilder({G_GET_FPENV, G_SET_FPENV}).legalFor({s32});
getActionDefinitionsBuilder(G_RESET_FPENV).alwaysLegal();
} else {
getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV})
.libcallFor({s32, s64});
Expand All @@ -219,6 +222,8 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
.libcallForCartesianProduct({s32}, {s32, s64});
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
.libcallForCartesianProduct({s32, s64}, {s32});

getActionDefinitionsBuilder({G_GET_FPENV, G_SET_FPENV}).libcall();
}

// Just expand whatever loads and stores are left.
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Target/ARM/ARMRegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,14 @@ ARMRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
OperandsMapping = getOperandsMapping(OperandBanks);
break;
}
case G_GET_FPENV:
case G_SET_FPENV:
OperandsMapping =
getOperandsMapping({&ARM::ValueMappings[ARM::GPR3OpsIdx], nullptr});
break;
case G_RESET_FPENV:
OperandsMapping = getOperandsMapping({nullptr});
break;
default:
return getInvalidInstructionMapping();
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ def assertsexti32 : PatFrag<(ops node:$src), (assertsext node:$src), [{
return cast<VTSDNode>(N->getOperand(1))->getVT().bitsLE(MVT::i32);
}]>;
def sexti16 : ComplexPattern<XLenVT, 1, "selectSExtBits<16>">;
def sexti16i32 : ComplexPattern<i32, 1, "selectSExtBits<16>">;
def sexti32 : ComplexPattern<i64, 1, "selectSExtBits<32>">;
def assertzexti32 : PatFrag<(ops node:$src), (assertzext node:$src), [{
return cast<VTSDNode>(N->getOperand(1))->getVT().bitsLE(MVT::i32);
Expand Down
26 changes: 24 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,7 @@ defm : LdIdxPat<zextloadi16, TH_LRHU>;

defm : StIdxPat<truncstorei8, TH_SRB, GPR>;
defm : StIdxPat<truncstorei16, TH_SRH, GPR>;
}

let Predicates = [HasVendorXTHeadMemIdx, IsRV32] in {
defm : LdIdxPat<load, TH_LRW, i32>;
defm : StIdxPat<store, TH_SRW, GPR, i32>;
}
Expand Down Expand Up @@ -907,6 +905,13 @@ defm : StoreUpdatePat<post_truncsti8, TH_SBIA, i32>;
defm : StoreUpdatePat<pre_truncsti8, TH_SBIB, i32>;
defm : StoreUpdatePat<post_truncsti16, TH_SHIA, i32>;
defm : StoreUpdatePat<pre_truncsti16, TH_SHIB, i32>;

defm : StIdxPat<truncstorei8, TH_SRB, GPR, i32>;
defm : StIdxPat<truncstorei16, TH_SRH, GPR, i32>;

defm : StZextIdxPat<truncstorei8, TH_SURB, GPR, i32>;
defm : StZextIdxPat<truncstorei16, TH_SURH, GPR, i32>;
defm : StZextIdxPat<store, TH_SURW, GPR, i32>;
}

let Predicates = [HasVendorXTHeadCondMov, IsRV64] in {
Expand All @@ -930,3 +935,20 @@ def : Pat<(select (riscv_seteq (XLenVT GPR:$cond)), (i32 0), (i32 GPR:$b)),
def : Pat<(select (riscv_setne (XLenVT GPR:$cond)), (i32 0), (i32 GPR:$b)),
(TH_MVNEZ GPR:$b, (XLenVT X0), GPR:$cond)>;
} // Predicates = [HasVendorXTHeadCondMov]

let Predicates = [HasVendorXTHeadMac, IsRV64] in {
// mulaw, mulsw are available only in RV64.
def : Pat<(i32 (add GPR:$rd, (mul GPR:$rs1, GPR:$rs2))),
(TH_MULAW GPR:$rd, GPR:$rs1, GPR:$rs2)>;
def : Pat<(i32 (sub GPR:$rd, (mul GPR:$rs1, GPR:$rs2))),
(TH_MULSW GPR:$rd, GPR:$rs1, GPR:$rs2)>;
// mulah, mulsh produce a sign-extended result.
def : Pat<(i32 (add GPR:$rd,
(mul (sexti16i32 (i32 GPR:$rs1)),
(sexti16i32 (i32 GPR:$rs2))))),
(TH_MULAH GPR:$rd, GPR:$rs1, GPR:$rs2)>;
def : Pat<(i32 (sub GPR:$rd,
(mul (sexti16i32 (i32 GPR:$rs1)),
(sexti16i32 (i32 GPR:$rs2))))),
(TH_MULSH GPR:$rd, GPR:$rs1, GPR:$rs2)>;
}
50 changes: 24 additions & 26 deletions llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static bool hasAllWUsers(const MachineInstr &OrigMI, const RISCVSubtarget &ST,
// This function returns true if the machine instruction always outputs a value
// where bits 63:32 match bit 31.
static bool isSignExtendingOpW(const MachineInstr &MI,
const MachineRegisterInfo &MRI) {
const MachineRegisterInfo &MRI, unsigned OpNo) {
uint64_t TSFlags = MI.getDesc().TSFlags;

// Instructions that can be determined from opcode are marked in tablegen.
Expand Down Expand Up @@ -368,8 +368,9 @@ static bool isSignExtendingOpW(const MachineInstr &MI,
// Copying from X0 produces zero.
case RISCV::COPY:
return MI.getOperand(1).getReg() == RISCV::X0;
// Ignore the scratch register destination.
case RISCV::PseudoAtomicLoadNand32:
return true;
return OpNo == 0;
case RISCV::PseudoVMV_X_S: {
// vmv.x.s has at least 33 sign bits if log2(sew) <= 5.
int64_t Log2SEW = MI.getOperand(2).getImm();
Expand All @@ -384,38 +385,35 @@ static bool isSignExtendingOpW(const MachineInstr &MI,
static bool isSignExtendedW(Register SrcReg, const RISCVSubtarget &ST,
const MachineRegisterInfo &MRI,
SmallPtrSetImpl<MachineInstr *> &FixableDef) {
SmallSet<Register, 4> Visited;
SmallVector<Register, 4> Worklist;

SmallPtrSet<const MachineInstr *, 4> Visited;
SmallVector<MachineInstr *, 4> Worklist;

auto AddRegDefToWorkList = [&](Register SrcReg) {
auto AddRegToWorkList = [&](Register SrcReg) {
if (!SrcReg.isVirtual())
return false;
MachineInstr *SrcMI = MRI.getVRegDef(SrcReg);
if (!SrcMI)
return false;
// Code assumes the register is operand 0.
// TODO: Maybe the worklist should store register?
if (!SrcMI->getOperand(0).isReg() ||
SrcMI->getOperand(0).getReg() != SrcReg)
return false;
// Add SrcMI to the worklist.
Worklist.push_back(SrcMI);
Worklist.push_back(SrcReg);
return true;
};

if (!AddRegDefToWorkList(SrcReg))
if (!AddRegToWorkList(SrcReg))
return false;

while (!Worklist.empty()) {
MachineInstr *MI = Worklist.pop_back_val();
Register Reg = Worklist.pop_back_val();

// If we already visited this instruction, we don't need to check it again.
if (!Visited.insert(MI).second)
// If we already visited this register, we don't need to check it again.
if (!Visited.insert(Reg).second)
continue;

MachineInstr *MI = MRI.getVRegDef(Reg);
if (!MI)
continue;

int OpNo = MI->findRegisterDefOperandIdx(Reg);
assert(OpNo != -1 && "Couldn't find register");

// If this is a sign extending operation we don't need to look any further.
if (isSignExtendingOpW(*MI, MRI))
if (isSignExtendingOpW(*MI, MRI, OpNo))
continue;

// Is this an instruction that propagates sign extend?
Expand Down Expand Up @@ -472,7 +470,7 @@ static bool isSignExtendedW(Register SrcReg, const RISCVSubtarget &ST,
continue;
}

if (!AddRegDefToWorkList(CopySrcReg))
if (!AddRegToWorkList(CopySrcReg))
return false;

break;
Expand All @@ -492,7 +490,7 @@ static bool isSignExtendedW(Register SrcReg, const RISCVSubtarget &ST,
// |Remainder| is always <= |Dividend|. If D is 32-bit, then so is R.
// DIV doesn't work because of the edge case 0xf..f 8000 0000 / (long)-1
// Logical operations use a sign extended 12-bit immediate.
if (!AddRegDefToWorkList(MI->getOperand(1).getReg()))
if (!AddRegToWorkList(MI->getOperand(1).getReg()))
return false;

break;
Expand All @@ -507,7 +505,7 @@ static bool isSignExtendedW(Register SrcReg, const RISCVSubtarget &ST,
case RISCV::PseudoCCSRAIW:
// Returns operand 4 or an ADDW/SUBW/etc. of operands 5 and 6. We only
// need to check if operand 4 is sign extended.
if (!AddRegDefToWorkList(MI->getOperand(4).getReg()))
if (!AddRegToWorkList(MI->getOperand(4).getReg()))
return false;
break;
case RISCV::REMU:
Expand Down Expand Up @@ -555,7 +553,7 @@ static bool isSignExtendedW(Register SrcReg, const RISCVSubtarget &ST,
if (!MI->getOperand(I).isReg())
return false;

if (!AddRegDefToWorkList(MI->getOperand(I).getReg()))
if (!AddRegToWorkList(MI->getOperand(I).getReg()))
return false;
}

Expand All @@ -568,7 +566,7 @@ static bool isSignExtendedW(Register SrcReg, const RISCVSubtarget &ST,
case RISCV::VT_MASKCN:
// Instructions return zero or operand 1. Result is sign extended if
// operand 1 is sign extended.
if (!AddRegDefToWorkList(MI->getOperand(1).getReg()))
if (!AddRegToWorkList(MI->getOperand(1).getReg()))
return false;
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ bool WebAssemblyAsmTypeCheck::typeCheck(SMLoc ErrorLoc, const MCInst &Inst,
return true;
if (popType(ErrorLoc, wasm::ValType::I32))
return true;
if (popType(ErrorLoc, Type))
return true;
Stack.push_back(wasm::ValType::I32);
} else if (Name == "table.fill") {
if (getTable(Operands[1]->getStartLoc(), Inst, Type))
Expand Down
Loading

0 comments on commit ac1fecc

Please sign in to comment.