Skip to content

Commit 462ca5c

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:1ffcac1b077a into amd-gfx:653f6e417e10
Local branch amd-gfx 653f6e4 Merged main:fcb160eabc49 into amd-gfx:382975c0c086 Remote branch main 1ffcac1 [RISCV][GISel] Rename ValueMappingsIdx->ValueMappingIdx. NFC
2 parents 653f6e4 + 1ffcac1 commit 462ca5c

File tree

8 files changed

+116
-38
lines changed

8 files changed

+116
-38
lines changed

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,46 @@ FuzzyFindRequest speculativeFuzzyFindRequestForCompletion(
14911491
return CachedReq;
14921492
}
14931493

1494+
// This function is similar to Lexer::findNextToken(), but assumes
1495+
// that the input SourceLocation is the completion point (which is
1496+
// a case findNextToken() does not handle).
1497+
std::optional<Token>
1498+
findTokenAfterCompletionPoint(SourceLocation CompletionPoint,
1499+
const SourceManager &SM,
1500+
const LangOptions &LangOpts) {
1501+
SourceLocation Loc = CompletionPoint;
1502+
if (Loc.isMacroID()) {
1503+
if (!Lexer::isAtEndOfMacroExpansion(Loc, SM, LangOpts, &Loc))
1504+
return std::nullopt;
1505+
}
1506+
1507+
// Advance to the next SourceLocation after the completion point.
1508+
// Lexer::findNextToken() would call MeasureTokenLength() here,
1509+
// which does not handle the completion point (and can't, because
1510+
// the Lexer instance it constructs internally doesn't have a
1511+
// Preprocessor and so doesn't know about the completion point).
1512+
Loc = Loc.getLocWithOffset(1);
1513+
1514+
// Break down the source location.
1515+
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
1516+
1517+
// Try to load the file buffer.
1518+
bool InvalidTemp = false;
1519+
StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
1520+
if (InvalidTemp)
1521+
return std::nullopt;
1522+
1523+
const char *TokenBegin = File.data() + LocInfo.second;
1524+
1525+
// Lex from the start of the given location.
1526+
Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
1527+
TokenBegin, File.end());
1528+
// Find the token.
1529+
Token Tok;
1530+
TheLexer.LexFromRawLexer(Tok);
1531+
return Tok;
1532+
}
1533+
14941534
// Runs Sema-based (AST) and Index-based completion, returns merged results.
14951535
//
14961536
// There are a few tricky considerations:
@@ -1589,7 +1629,7 @@ class CodeCompleteFlow {
15891629
auto Style = getFormatStyleForFile(SemaCCInput.FileName,
15901630
SemaCCInput.ParseInput.Contents,
15911631
*SemaCCInput.ParseInput.TFS);
1592-
const auto NextToken = Lexer::findNextToken(
1632+
const auto NextToken = findTokenAfterCompletionPoint(
15931633
Recorder->CCSema->getPreprocessor().getCodeCompletionLoc(),
15941634
Recorder->CCSema->getSourceManager(), Recorder->CCSema->LangOpts);
15951635
if (NextToken)

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3892,6 +3892,29 @@ TEST(CompletionTest, FunctionArgsExist) {
38923892
kind(CompletionItemKind::Function))));
38933893
}
38943894

3895+
TEST(CompletionTest, FunctionArgsExist_Issue1785) {
3896+
// This is a scenario where the implementation of our check for
3897+
// "is there a function argument list right after the cursor"
3898+
// gave a bogus result.
3899+
clangd::CodeCompleteOptions Opts;
3900+
Opts.EnableSnippets = true;
3901+
// The whitespace in this testcase is important!
3902+
std::string Code = R"cpp(
3903+
void waldo(int);
3904+
3905+
int main()
3906+
{
3907+
wal^
3908+
3909+
3910+
// ( )
3911+
}
3912+
)cpp";
3913+
EXPECT_THAT(
3914+
completions(Code, {}, Opts).Completions,
3915+
Contains(AllOf(labeled("waldo(int)"), snippetSuffix("(${1:int})"))));
3916+
}
3917+
38953918
TEST(CompletionTest, NoCrashDueToMacroOrdering) {
38963919
EXPECT_THAT(completions(R"cpp(
38973920
#define ECHO(X) X

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 480519
19+
#define LLVM_MAIN_REVISION 480524
2020

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ bool RISCVInstructionSelector::replacePtrWithInt(MachineOperand &Op,
432432

433433
const LLT sXLen = LLT::scalar(STI.getXLen());
434434
auto PtrToInt = MIB.buildPtrToInt(sXLen, PtrReg);
435-
MRI.setRegBank(PtrToInt.getReg(0), RBI.getRegBank(RISCV::GPRRegBankID));
435+
MRI.setRegBank(PtrToInt.getReg(0), RBI.getRegBank(RISCV::GPRBRegBankID));
436436
Op.setReg(PtrToInt.getReg(0));
437437
return select(*PtrToInt);
438438
}
@@ -491,12 +491,12 @@ void RISCVInstructionSelector::renderTrailingZeros(MachineInstrBuilder &MIB,
491491

492492
const TargetRegisterClass *RISCVInstructionSelector::getRegClassForTypeOnBank(
493493
LLT Ty, const RegisterBank &RB) const {
494-
if (RB.getID() == RISCV::GPRRegBankID) {
494+
if (RB.getID() == RISCV::GPRBRegBankID) {
495495
if (Ty.getSizeInBits() <= 32 || (STI.is64Bit() && Ty.getSizeInBits() == 64))
496496
return &RISCV::GPRRegClass;
497497
}
498498

499-
if (RB.getID() == RISCV::FPRRegBankID) {
499+
if (RB.getID() == RISCV::FPRBRegBankID) {
500500
if (Ty.getSizeInBits() == 32)
501501
return &RISCV::FPR32RegClass;
502502
if (Ty.getSizeInBits() == 64)

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

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,46 @@ namespace llvm {
2525
namespace RISCV {
2626

2727
const RegisterBankInfo::PartialMapping PartMappings[] = {
28-
{0, 32, GPRRegBank},
29-
{0, 64, GPRRegBank},
30-
{0, 32, FPRRegBank},
31-
{0, 64, FPRRegBank},
28+
{0, 32, GPRBRegBank},
29+
{0, 64, GPRBRegBank},
30+
{0, 32, FPRBRegBank},
31+
{0, 64, FPRBRegBank},
3232
};
3333

3434
enum PartialMappingIdx {
35-
PMI_GPR32 = 0,
36-
PMI_GPR64 = 1,
37-
PMI_FPR32 = 2,
38-
PMI_FPR64 = 3,
35+
PMI_GPRB32 = 0,
36+
PMI_GPRB64 = 1,
37+
PMI_FPRB32 = 2,
38+
PMI_FPRB64 = 3,
3939
};
4040

4141
const RegisterBankInfo::ValueMapping ValueMappings[] = {
4242
// Invalid value mapping.
4343
{nullptr, 0},
4444
// Maximum 3 GPR operands; 32 bit.
45-
{&PartMappings[PMI_GPR32], 1},
46-
{&PartMappings[PMI_GPR32], 1},
47-
{&PartMappings[PMI_GPR32], 1},
45+
{&PartMappings[PMI_GPRB32], 1},
46+
{&PartMappings[PMI_GPRB32], 1},
47+
{&PartMappings[PMI_GPRB32], 1},
4848
// Maximum 3 GPR operands; 64 bit.
49-
{&PartMappings[PMI_GPR64], 1},
50-
{&PartMappings[PMI_GPR64], 1},
51-
{&PartMappings[PMI_GPR64], 1},
49+
{&PartMappings[PMI_GPRB64], 1},
50+
{&PartMappings[PMI_GPRB64], 1},
51+
{&PartMappings[PMI_GPRB64], 1},
5252
// Maximum 3 FPR operands; 32 bit.
53-
{&PartMappings[PMI_FPR32], 1},
54-
{&PartMappings[PMI_FPR32], 1},
55-
{&PartMappings[PMI_FPR32], 1},
53+
{&PartMappings[PMI_FPRB32], 1},
54+
{&PartMappings[PMI_FPRB32], 1},
55+
{&PartMappings[PMI_FPRB32], 1},
5656
// Maximum 3 FPR operands; 64 bit.
57-
{&PartMappings[PMI_FPR64], 1},
58-
{&PartMappings[PMI_FPR64], 1},
59-
{&PartMappings[PMI_FPR64], 1},
57+
{&PartMappings[PMI_FPRB64], 1},
58+
{&PartMappings[PMI_FPRB64], 1},
59+
{&PartMappings[PMI_FPRB64], 1},
6060
};
6161

62-
enum ValueMappingsIdx {
62+
enum ValueMappingIdx {
6363
InvalidIdx = 0,
64-
GPR32Idx = 1,
65-
GPR64Idx = 4,
66-
FPR32Idx = 7,
67-
FPR64Idx = 10,
64+
GPRB32Idx = 1,
65+
GPRB64Idx = 4,
66+
FPRB32Idx = 7,
67+
FPRB64Idx = 10,
6868
};
6969
} // namespace RISCV
7070
} // namespace llvm
@@ -93,19 +93,19 @@ RISCVRegisterBankInfo::getRegBankFromRegClass(const TargetRegisterClass &RC,
9393
case RISCV::SR07RegClassID:
9494
case RISCV::SPRegClassID:
9595
case RISCV::GPRX0RegClassID:
96-
return getRegBank(RISCV::GPRRegBankID);
96+
return getRegBank(RISCV::GPRBRegBankID);
9797
case RISCV::FPR64RegClassID:
9898
case RISCV::FPR16RegClassID:
9999
case RISCV::FPR32RegClassID:
100100
case RISCV::FPR64CRegClassID:
101101
case RISCV::FPR32CRegClassID:
102-
return getRegBank(RISCV::FPRRegBankID);
102+
return getRegBank(RISCV::FPRBRegBankID);
103103
}
104104
}
105105

106106
static const RegisterBankInfo::ValueMapping *getFPValueMapping(unsigned Size) {
107107
assert(Size == 32 || Size == 64);
108-
unsigned Idx = Size == 64 ? RISCV::FPR64Idx : RISCV::FPR32Idx;
108+
unsigned Idx = Size == 64 ? RISCV::FPRB64Idx : RISCV::FPRB32Idx;
109109
return &RISCV::ValueMappings[Idx];
110110
}
111111

@@ -124,12 +124,13 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
124124
const MachineFunction &MF = *MI.getParent()->getParent();
125125
const MachineRegisterInfo &MRI = MF.getRegInfo();
126126

127-
unsigned GPRSize = getMaximumSize(RISCV::GPRRegBankID);
127+
unsigned GPRSize = getMaximumSize(RISCV::GPRBRegBankID);
128128
assert((GPRSize == 32 || GPRSize == 64) && "Unexpected GPR size");
129129

130130
unsigned NumOperands = MI.getNumOperands();
131131
const ValueMapping *GPRValueMapping =
132-
&RISCV::ValueMappings[GPRSize == 64 ? RISCV::GPR64Idx : RISCV::GPR32Idx];
132+
&RISCV::ValueMappings[GPRSize == 64 ? RISCV::GPRB64Idx
133+
: RISCV::GPRB32Idx];
133134
const ValueMapping *OperandsMapping = GPRValueMapping;
134135

135136
switch (Opc) {

llvm/lib/Target/RISCV/GISel/RISCVRegisterBanks.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
/// General Purpose Registers: X.
13-
def GPRRegBank : RegisterBank<"GPRB", [GPR]>;
13+
def GPRBRegBank : RegisterBank<"GPRB", [GPR]>;
1414

1515
/// Floating Point Registers: F.
16-
def FPRRegBank : RegisterBank<"FPRB", [FPR64]>;
16+
def FPRBRegBank : RegisterBank<"FPRB", [FPR64]>;

mlir/lib/Dialect/Vector/Transforms/LowerVectorMask.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ struct MaskOpRewritePattern : OpRewritePattern<MaskOp> {
188188
private:
189189
LogicalResult matchAndRewrite(MaskOp maskOp,
190190
PatternRewriter &rewriter) const final {
191-
auto maskableOp = cast<MaskableOpInterface>(maskOp.getMaskableOp());
191+
auto maskableOp = cast_or_null<MaskableOpInterface>(maskOp.getMaskableOp());
192+
if (!maskableOp)
193+
return failure();
192194
SourceOp sourceOp = dyn_cast<SourceOp>(maskableOp.getOperation());
193195
if (!sourceOp)
194196
return failure();
@@ -282,6 +284,7 @@ struct LowerVectorMaskPass
282284

283285
RewritePatternSet loweringPatterns(context);
284286
populateVectorMaskLoweringPatternsForSideEffectingOps(loweringPatterns);
287+
MaskOp::getCanonicalizationPatterns(loweringPatterns, context);
285288

286289
if (failed(applyPatternsAndFoldGreedily(op, std::move(loweringPatterns))))
287290
signalPassFailure();

mlir/test/Dialect/Vector/lower-vector-mask.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,14 @@ func.func @vector_gather(%arg0: tensor<64xf32>, %arg1: tensor<3xf32>) -> tensor<
7777
// CHECK: %[[VAL_7:.*]] = vector.gather %[[VAL_0]][%[[VAL_4]]] [%[[VAL_3]]], %[[VAL_6]], %[[VAL_2]] : tensor<64xf32>, vector<4xindex>, vector<4xi1>, vector<4xf32> into vector<4xf32>
7878
// CHECK: %[[VAL_8:.*]] = vector.transfer_write %[[VAL_7]], %[[VAL_1]][%[[VAL_4]]], %[[VAL_6]] {in_bounds = [true]} : vector<4xf32>, tensor<3xf32>
7979

80+
// -----
81+
82+
// CHECK-LABEL: func @empty_vector_mask_with_return
83+
// CHECK-SAME: %[[IN:.*]]: vector<8xf32>
84+
func.func @empty_vector_mask_with_return(%a : vector<8xf32>, %mask : vector<8xi1>) -> vector<8xf32> {
85+
// CHECK-NOT: vector.mask
86+
// CHECK: return %[[IN]] : vector<8xf32>
87+
%0 = vector.mask %mask { vector.yield %a : vector<8xf32> } : vector<8xi1> -> vector<8xf32>
88+
return %0 : vector<8xf32>
89+
}
90+

0 commit comments

Comments
 (0)