Skip to content

Commit 4f1b362

Browse files
authored
merge main into amd-staging (llvm#2839)
passed all but one smoke-fort-limbo test
2 parents b6bca4a + a440aa0 commit 4f1b362

File tree

90 files changed

+2575
-935
lines changed

Some content is hidden

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

90 files changed

+2575
-935
lines changed

clang/include/clang/Basic/riscv_andes_vector.td

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,52 @@ include "riscv_vector_common.td"
1818
// Instruction definitions
1919
//===----------------------------------------------------------------------===//
2020

21+
// Andes Vector BFLOAT16 Conversion Extension (XAndesVBFHCvt)
22+
23+
let RequiredFeatures = ["xandesvbfhcvt"],
24+
Log2LMUL = [-2, -1, 0, 1, 2],
25+
HasMasked = false,
26+
UnMaskedPolicyScheme = HasPassthruOperand in {
27+
def nds_vfwcvt_s_bf16 : RVVConvBuiltin<"Fw", "Fwv", "y", "nds_vfwcvt_s">;
28+
29+
let ManualCodegen = [{
30+
{
31+
// LLVM intrinsic
32+
// Unmasked: (passthru, op0, frm, vl)
33+
SmallVector<llvm::Value*, 4> Operands;
34+
bool HasMaskedOff = !(PolicyAttrs & RVV_VTA);
35+
bool HasRoundModeOp = HasMaskedOff ? Ops.size() == 4 : Ops.size() == 3;
36+
37+
unsigned Offset = HasMaskedOff ? 1 : 0;
38+
39+
if (!HasMaskedOff)
40+
Operands.push_back(llvm::PoisonValue::get(ResultType));
41+
else
42+
Operands.push_back(Ops[0]);
43+
44+
Operands.push_back(Ops[Offset]); // op0
45+
46+
if (HasRoundModeOp) {
47+
Operands.push_back(Ops[Offset + 1]); // frm
48+
Operands.push_back(Ops[Offset + 2]); // vl
49+
} else {
50+
Operands.push_back(ConstantInt::get(Ops[Offset + 1]->getType(), 7)); // frm
51+
Operands.push_back(Ops[Offset + 1]); // vl
52+
}
53+
54+
IntrinsicTypes = {ResultType, Ops[Offset]->getType(),
55+
Operands.back()->getType()};
56+
llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
57+
return Builder.CreateCall(F, Operands, "");
58+
}
59+
}] in {
60+
let HasFRMRoundModeOp = 1, Name = "nds_vfncvt_bf16_s", IRName = "nds_vfncvt_bf16_s" in
61+
def nds_vfncvt_bf16_s_rm : RVVConvBuiltin<"v", "vFwu", "y", "nds_vfncvt_bf16">;
62+
63+
def nds_vfncvt_bf16_s : RVVConvBuiltin<"v", "vFw", "y", "nds_vfncvt_bf16">;
64+
}
65+
}
66+
2167
// Andes Vector Packed FP16 Extension (XAndesVPackFPH)
2268

2369
multiclass RVVFPMAD {

clang/include/clang/Basic/riscv_vector.td

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ let ManualCodegen = [{
18161816
// Unmasked: (passthru, op0, round_mode, vl)
18171817
// Masked: (passthru, op0, mask, frm, vl, policy)
18181818

1819-
SmallVector<llvm::Value*, 7> Operands;
1819+
SmallVector<llvm::Value*, 6> Operands;
18201820
bool HasMaskedOff = !(
18211821
(IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) ||
18221822
(!IsMasked && PolicyAttrs & RVV_VTA));
@@ -2013,15 +2013,15 @@ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
20132013
}
20142014

20152015
// Zvfbfmin - Vector convert BF16 to FP32
2016-
let Log2LMUL = [-2, -1, 0, 1, 2] in
2016+
let RequiredFeatures = ["zvfbfmin"], Log2LMUL = [-2, -1, 0, 1, 2] in
20172017
def vfwcvtbf16_f_f_v : RVVConvBuiltin<"Fw", "Fwv", "y", "vfwcvtbf16_f">;
20182018

20192019
let ManualCodegen = [{
20202020
{
20212021
// LLVM intrinsic
20222022
// Unmasked: (passthru, op0, frm, vl)
20232023
// Masked: (passthru, op0, mask, frm, vl, policy)
2024-
SmallVector<llvm::Value*, 7> Operands;
2024+
SmallVector<llvm::Value*, 6> Operands;
20252025
bool HasMaskedOff = !(
20262026
(IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) ||
20272027
(!IsMasked && PolicyAttrs & RVV_VTA));
@@ -2121,7 +2121,8 @@ let ManualCodegen = [{
21212121
}
21222122

21232123
// Zvfbfmin - Vector convert FP32 to BF16
2124-
let Log2LMUL = [-2, -1, 0, 1, 2],
2124+
let RequiredFeatures = ["zvfbfmin"],
2125+
Log2LMUL = [-2, -1, 0, 1, 2],
21252126
OverloadedName = "vfncvtbf16_f" in
21262127
defm : RVVConvBuiltinSet<"vfncvtbf16_f_f_w", "y", [["v", "vFwu"]]>;
21272128
}
@@ -2225,7 +2226,7 @@ let ManualCodegen = [{
22252226
// Unmasked: (passthru, op0, op1, round_mode, vl)
22262227
// Masked: (passthru, vector_in, vector_in/scalar_in, mask, frm, vl, policy)
22272228

2228-
SmallVector<llvm::Value*, 7> Operands;
2229+
SmallVector<llvm::Value*, 6> Operands;
22292230
bool HasMaskedOff = !(
22302231
(IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) ||
22312232
(!IsMasked && PolicyAttrs & RVV_VTA));

clang/include/clang/Lex/Preprocessor.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ class Preprocessor {
350350
/// Whether the last token we lexed was an '@'.
351351
bool LastTokenWasAt = false;
352352

353-
/// First pp-token in current translation unit.
354-
std::optional<Token> FirstPPToken;
353+
/// First pp-token source location in current translation unit.
354+
SourceLocation FirstPPTokenLoc;
355355

356356
/// A position within a C++20 import-seq.
357357
class StdCXXImportSeq {
@@ -1769,20 +1769,13 @@ class Preprocessor {
17691769
std::optional<LexEmbedParametersResult> LexEmbedParameters(Token &Current,
17701770
bool ForHasEmbed);
17711771

1772-
/// Whether the preprocessor already seen the first pp-token in main file.
1773-
bool hasSeenMainFileFirstPPToken() const { return FirstPPToken.has_value(); }
1774-
1775-
/// Record first pp-token and check if it has a Token::FirstPPToken flag.
1776-
void HandleMainFileFirstPPToken(const Token &Tok) {
1777-
if (!hasSeenMainFileFirstPPToken() && Tok.isFirstPPToken() &&
1778-
SourceMgr.isWrittenInMainFile(Tok.getLocation()))
1779-
FirstPPToken = Tok;
1772+
/// Get the start location of the first pp-token in main file.
1773+
SourceLocation getMainFileFirstPPTokenLoc() const {
1774+
assert(FirstPPTokenLoc.isValid() &&
1775+
"Did not see the first pp-token in the main file");
1776+
return FirstPPTokenLoc;
17801777
}
17811778

1782-
Token getMainFileFirstPPToken() const {
1783-
assert(FirstPPToken && "First main file pp-token doesn't exists");
1784-
return *FirstPPToken;
1785-
}
17861779
bool LexAfterModuleImport(Token &Result);
17871780
void CollectPpImportSuffix(SmallVectorImpl<Token> &Toks);
17881781

clang/include/clang/Lex/TokenLexer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ class TokenLexer {
139139
void Init(const Token *TokArray, unsigned NumToks, bool DisableMacroExpansion,
140140
bool OwnsTokens, bool IsReinject);
141141

142-
/// If the next token lexed will pop this macro off the expansion stack,
143-
/// return std::nullopt, otherwise return the next unexpanded token.
142+
/// If TokenLexer::isAtEnd returns true(the next token lexed will pop this
143+
/// macro off the expansion stack), return std::nullopt, otherwise return the
144+
/// next unexpanded token.
144145
std::optional<Token> peekNextPPToken() const;
145146

146147
/// Lex and return a token from this macro stream.

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ class AnnotatingParser {
14111411
if (Prev->isPointerOrReference())
14121412
Prev->setFinalizedType(TT_PointerOrReference);
14131413
} else if ((CurrentToken && CurrentToken->is(tok::numeric_constant)) ||
1414-
(Prev && Prev->is(TT_StartOfName) && !Scopes.empty() &&
1414+
(Prev->is(TT_StartOfName) && !Scopes.empty() &&
14151415
Scopes.back() == ST_Class)) {
14161416
Tok->setType(TT_BitFieldColon);
14171417
} else if (Contexts.size() == 1 &&

clang/lib/Lex/Lexer.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,6 +3228,7 @@ std::optional<Token> Lexer::peekNextPPToken() {
32283228
bool atStartOfLine = IsAtStartOfLine;
32293229
bool atPhysicalStartOfLine = IsAtPhysicalStartOfLine;
32303230
bool leadingSpace = HasLeadingSpace;
3231+
bool isFirstPPToken = IsFirstPPToken;
32313232

32323233
Token Tok;
32333234
Lex(Tok);
@@ -3238,7 +3239,7 @@ std::optional<Token> Lexer::peekNextPPToken() {
32383239
HasLeadingSpace = leadingSpace;
32393240
IsAtStartOfLine = atStartOfLine;
32403241
IsAtPhysicalStartOfLine = atPhysicalStartOfLine;
3241-
3242+
IsFirstPPToken = isFirstPPToken;
32423243
// Restore the lexer back to non-skipping mode.
32433244
LexingRawMode = false;
32443245

@@ -3740,10 +3741,6 @@ bool Lexer::Lex(Token &Result) {
37403741
bool returnedToken = LexTokenInternal(Result, atPhysicalStartOfLine);
37413742
// (After the LexTokenInternal call, the lexer might be destroyed.)
37423743
assert((returnedToken || !isRawLex) && "Raw lex must succeed");
3743-
3744-
if (returnedToken && Result.isFirstPPToken() && PP &&
3745-
!PP->hasSeenMainFileFirstPPToken())
3746-
PP->HandleMainFileFirstPPToken(Result);
37473744
return returnedToken;
37483745
}
37493746

@@ -4547,8 +4544,6 @@ const char *Lexer::convertDependencyDirectiveToken(
45474544
Result.setFlag((Token::TokenFlags)DDTok.Flags);
45484545
Result.setLength(DDTok.Length);
45494546
BufferPtr = TokPtr + DDTok.Length;
4550-
if (PP && !PP->hasSeenMainFileFirstPPToken() && Result.isFirstPPToken())
4551-
PP->HandleMainFileFirstPPToken(Result);
45524547
return TokPtr;
45534548
}
45544549

clang/lib/Lex/PPDirectives.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,9 +1242,6 @@ void Preprocessor::HandleDirective(Token &Result) {
12421242
// pp-directive.
12431243
bool ReadAnyTokensBeforeDirective =CurPPLexer->MIOpt.getHasReadAnyTokensVal();
12441244

1245-
if (!hasSeenMainFileFirstPPToken())
1246-
HandleMainFileFirstPPToken(Result);
1247-
12481245
// Save the '#' token in case we need to return it later.
12491246
Token SavedHash = Result;
12501247

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
431431
// to disable the optimization in this case.
432432
if (CurPPLexer) CurPPLexer->MIOpt.ExpandedMacro();
433433

434-
if (!hasSeenMainFileFirstPPToken())
435-
HandleMainFileFirstPPToken(Identifier);
436-
437434
// If this is a builtin macro, like __LINE__ or _Pragma, handle it specially.
438435
if (MI->isBuiltinMacro()) {
439436
if (Callbacks)

clang/lib/Lex/Preprocessor.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,21 @@ void Preprocessor::EnterMainSourceFile() {
566566
// #imported, it won't be re-entered.
567567
if (OptionalFileEntryRef FE = SourceMgr.getFileEntryRefForID(MainFileID))
568568
markIncluded(*FE);
569+
570+
// Record the first PP token in the main file. This is used to generate
571+
// better diagnostics for C++ modules.
572+
//
573+
// // This is a comment.
574+
// #define FOO int // note: add 'module;' to the start of the file
575+
// ^ FirstPPToken // to introduce a global module fragment.
576+
//
577+
// export module M; // error: module declaration must occur
578+
// // at the start of the translation unit.
579+
if (getLangOpts().CPlusPlusModules) {
580+
std::optional<Token> FirstPPTok = CurLexer->peekNextPPToken();
581+
if (FirstPPTok && FirstPPTok->isFirstPPToken())
582+
FirstPPTokenLoc = FirstPPTok->getLocation();
583+
}
569584
}
570585

571586
// Preprocess Predefines to populate the initial preprocessor state.

clang/lib/Sema/SemaModule.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,9 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
337337
// tokens in a file (excluding the global module fragment.).
338338
if (getLangOpts().CPlusPlusModules && !IntroducerIsFirstPPToken && !SeenGMF) {
339339
Diag(ModuleLoc, diag::err_module_decl_not_at_start);
340-
SourceLocation BeginLoc = PP.getMainFileFirstPPToken().getLocation();
341-
if (BeginLoc.isValid()) {
342-
Diag(BeginLoc, diag::note_global_module_introducer_missing)
343-
<< FixItHint::CreateInsertion(BeginLoc, "module;\n");
344-
}
340+
SourceLocation BeginLoc = PP.getMainFileFirstPPTokenLoc();
341+
Diag(BeginLoc, diag::note_global_module_introducer_missing)
342+
<< FixItHint::CreateInsertion(BeginLoc, "module;\n");
345343
}
346344

347345
// C++23 [module.unit]p1: ... The identifiers module and import shall not

0 commit comments

Comments
 (0)