Skip to content

Commit 60df19f

Browse files
author
git apple-llvm automerger
committed
Merge commit 'a25df95dd775' from apple/stable/20210107 into swift/main
2 parents 3f79a31 + a25df95 commit 60df19f

Some content is hidden

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

50 files changed

+2012
-153
lines changed

clang/docs/MatrixTypes.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,21 @@ more explicit.
118118
Matrix Type Binary Operators
119119
----------------------------
120120

121-
Each matrix type supports the following binary operators: ``+``, ``-`` and ``*``. The ``*``
122-
operator provides matrix multiplication, while ``+`` and ``-`` are performed
123-
element-wise. There are also scalar versions of the operators, which take a
124-
matrix type and the matrix element type. The operation is applied to all
125-
elements of the matrix using the scalar value.
126-
127-
For ``BIN_OP`` in ``+``, ``-``, ``*`` given the expression ``M1 BIN_OP M2`` where
128-
at least one of ``M1`` or ``M2`` is of matrix type and, for `*`, the other is of
129-
a real type:
121+
Given two matrixes, the ``+`` and ``-`` operators perform element-wise addition
122+
and subtraction, while the ``*`` operator performs matrix multiplication.
123+
``+``, ``-``, ``*``, and ``/`` can also be used with a matrix and a scalar
124+
value, applying the operation to each element of the matrix.
125+
126+
Earlier versions of this extension did not support division by a scalar.
127+
You can test for the availability of this feature with
128+
``__has_extension(matrix_types_scalar_division)``.
129+
130+
For the expression ``M1 BIN_OP M2`` where
131+
* ``BIN_OP`` is one of ``+`` or ``-``, one of ``M1`` and ``M2`` is of matrix
132+
type, and the other is of matrix type or real type; or
133+
* ``BIN_OP`` is ``*``, one of ``M1`` and ``M2`` is of matrix type, and the
134+
other is of a real type; or
135+
* ``BIN_OP`` is ``/``, ``M1`` is of matrix type, and ``M2`` is of a real type:
130136

131137
* The usual arithmetic conversions are applied to ``M1`` and ``M2``. [ Note: if ``M1`` or
132138
``M2`` are of a real type, they are broadcast to matrices here. — end note ]

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7478,9 +7478,10 @@ def err_conditional_vector_element_size : Error<
74787478
def err_conditional_vector_has_void : Error<
74797479
"GNU vector conditional operand cannot be %select{void|a throw expression}0">;
74807480
def err_conditional_vector_operand_type
7481-
: Error<"%select{enumeration|extended vector}0 type %1 is not allowed in a "
7482-
"vector conditional">;
7483-
def err_conditional_vector_mismatched_vectors
7481+
: Error<"enumeration type %0 is not allowed in a vector conditional">;
7482+
def err_conditional_vector_cond_result_mismatch
7483+
: Error<"cannot mix vectors and extended vectors in a vector conditional">;
7484+
def err_conditional_vector_mismatched
74847485
: Error<"vector operands to the vector conditional must be the same type "
74857486
"%diff{($ and $)|}0,1}">;
74867487

clang/include/clang/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ EXTENSION(pragma_clang_attribute_external_declaration, true)
266266
EXTENSION(gnu_asm, LangOpts.GNUAsm)
267267
EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
268268
EXTENSION(matrix_types, LangOpts.MatrixTypes)
269+
EXTENSION(matrix_types_scalar_division, true)
269270

270271
FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && LangOpts.RelativeCXXABIVTables)
271272

clang/include/clang/Basic/Module.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ class Module {
133133
std::string PresumedModuleMapFile;
134134

135135
/// The umbrella header or directory.
136-
llvm::PointerUnion<const FileEntryRef::MapEntry *,
137-
const DirectoryEntryRef::MapEntry *>
138-
Umbrella;
136+
llvm::PointerUnion<const FileEntry *, const DirectoryEntry *> Umbrella;
139137

140138
/// The module signature.
141139
ASTFileSignature Signature;
@@ -197,19 +195,19 @@ class Module {
197195
struct Header {
198196
std::string NameAsWritten;
199197
std::string PathRelativeToRootModuleDirectory;
200-
OptionalFileEntryRefDegradesToFileEntryPtr Entry;
198+
const FileEntry *Entry;
201199

202-
explicit operator bool() { return Entry != None; }
200+
explicit operator bool() { return Entry; }
203201
};
204202

205203
/// Information about a directory name as found in the module map
206204
/// file.
207205
struct DirectoryName {
208206
std::string NameAsWritten;
209207
std::string PathRelativeToRootModuleDirectory;
210-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr Entry;
208+
const DirectoryEntry *Entry;
211209

212-
explicit operator bool() { return Entry != None; }
210+
explicit operator bool() { return Entry; }
213211
};
214212

215213
/// The headers that are part of this module.
@@ -557,16 +555,16 @@ class Module {
557555
/// Retrieve the header that serves as the umbrella header for this
558556
/// module.
559557
Header getUmbrellaHeader() const {
560-
if (auto *ME = Umbrella.dyn_cast<const FileEntryRef::MapEntry *>())
558+
if (auto *FE = Umbrella.dyn_cast<const FileEntry *>())
561559
return Header{UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory,
562-
FileEntryRef(*ME)};
560+
FE};
563561
return Header{};
564562
}
565563

566564
/// Determine whether this module has an umbrella directory that is
567565
/// not based on an umbrella header.
568566
bool hasUmbrellaDir() const {
569-
return Umbrella && Umbrella.is<const DirectoryEntryRef::MapEntry *>();
567+
return Umbrella && Umbrella.is<const DirectoryEntry *>();
570568
}
571569

572570
/// Add a top-level header associated with this module.

clang/include/clang/Lex/ModuleMap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_CLANG_LEX_MODULEMAP_H
1515
#define LLVM_CLANG_LEX_MODULEMAP_H
1616

17-
#include "clang/Basic/FileEntry.h"
1817
#include "clang/Basic/IdentifierTable.h"
1918
#include "clang/Basic/LangOptions.h"
2019
#include "clang/Basic/Module.h"
@@ -38,6 +37,7 @@ namespace clang {
3837

3938
class DiagnosticsEngine;
4039
class DirectoryEntry;
40+
class FileEntry;
4141
class FileManager;
4242
class HeaderSearch;
4343
class SourceManager;
@@ -659,13 +659,13 @@ class ModuleMap {
659659

660660
/// Sets the umbrella header of the given module to the given
661661
/// header.
662-
void setUmbrellaHeader(Module *Mod, FileEntryRef UmbrellaHeader,
662+
void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
663663
Twine NameAsWritten,
664664
Twine PathRelativeToRootModuleDirectory);
665665

666666
/// Sets the umbrella directory of the given module to the given
667667
/// directory.
668-
void setUmbrellaDir(Module *Mod, DirectoryEntryRef UmbrellaDir,
668+
void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
669669
Twine NameAsWritten,
670670
Twine PathRelativeToRootModuleDirectory);
671671

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11474,9 +11474,9 @@ class Sema final {
1147411474
QualType CXXCheckConditionalOperands( // C++ 5.16
1147511475
ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
1147611476
ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
11477-
QualType CheckGNUVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
11478-
ExprResult &RHS,
11479-
SourceLocation QuestionLoc);
11477+
QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
11478+
ExprResult &RHS,
11479+
SourceLocation QuestionLoc);
1148011480
QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
1148111481
bool ConvertArgs = true);
1148211482
QualType FindCompositePointerType(SourceLocation Loc,

clang/lib/AST/Type.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,8 +2081,9 @@ bool Type::isUnsignedIntegerOrEnumerationType() const {
20812081
bool Type::hasUnsignedIntegerRepresentation() const {
20822082
if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
20832083
return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2084-
else
2085-
return isUnsignedIntegerOrEnumerationType();
2084+
if (const auto *VT = dyn_cast<MatrixType>(CanonicalType))
2085+
return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2086+
return isUnsignedIntegerOrEnumerationType();
20862087
}
20872088

20882089
bool Type::isFloatingType() const {

clang/lib/Analysis/CalledOnceCheck.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ static constexpr unsigned EXPECTED_NUMBER_OF_BASIC_BLOCKS = 8;
4848
template <class T>
4949
using CFGSizedVector = llvm::SmallVector<T, EXPECTED_NUMBER_OF_BASIC_BLOCKS>;
5050
constexpr llvm::StringLiteral CONVENTIONAL_NAMES[] = {
51-
"completionHandler", "completion", "withCompletionHandler"};
51+
"completionHandler", "completion", "withCompletionHandler",
52+
"withCompletion", "completionBlock", "withCompletionBlock",
53+
"replyTo", "reply", "withReplyTo"};
5254
constexpr llvm::StringLiteral CONVENTIONAL_SUFFIXES[] = {
53-
"WithCompletionHandler", "WithCompletion"};
55+
"WithCompletionHandler", "WithCompletion", "WithCompletionBlock",
56+
"WithReplyTo", "WithReply"};
5457
constexpr llvm::StringLiteral CONVENTIONAL_CONDITIONS[] = {
5558
"error", "cancel", "shouldCall", "done", "OK", "success"};
5659

@@ -994,13 +997,15 @@ class CalledOnceChecker : public ConstStmtVisitor<CalledOnceChecker> {
994997
return hasConventionalSuffix(MethodSelector.getNameForSlot(0));
995998
}
996999

997-
return isConventional(MethodSelector.getNameForSlot(PieceIndex));
1000+
llvm::StringRef PieceName = MethodSelector.getNameForSlot(PieceIndex);
1001+
return isConventional(PieceName) || hasConventionalSuffix(PieceName);
9981002
}
9991003

10001004
bool shouldBeCalledOnce(const ParmVarDecl *Parameter) const {
10011005
return isExplicitlyMarked(Parameter) ||
10021006
(CheckConventionalParameters &&
1003-
isConventional(Parameter->getName()) &&
1007+
(isConventional(Parameter->getName()) ||
1008+
hasConventionalSuffix(Parameter->getName())) &&
10041009
isConventional(Parameter->getType()));
10051010
}
10061011

clang/lib/Basic/Module.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,8 @@ Module::DirectoryName Module::getUmbrellaDir() const {
253253
if (Header U = getUmbrellaHeader())
254254
return {"", "", U.Entry->getDir()};
255255

256-
if (auto *ME = Umbrella.dyn_cast<const DirectoryEntryRef::MapEntry *>())
257-
return {UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory,
258-
DirectoryEntryRef(*ME)};
259-
260-
return {"", "", None};
256+
return {UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory,
257+
Umbrella.dyn_cast<const DirectoryEntry *>()};
261258
}
262259

263260
void Module::addTopHeader(const FileEntry *File) {

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,6 +3198,20 @@ Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) {
31983198
}
31993199
}
32003200

3201+
if (Ops.Ty->isConstantMatrixType()) {
3202+
llvm::MatrixBuilder<CGBuilderTy> MB(Builder);
3203+
// We need to check the types of the operands of the operator to get the
3204+
// correct matrix dimensions.
3205+
auto *BO = cast<BinaryOperator>(Ops.E);
3206+
assert(
3207+
isa<ConstantMatrixType>(BO->getLHS()->getType().getCanonicalType()) &&
3208+
"first operand must be a matrix");
3209+
assert(BO->getRHS()->getType().getCanonicalType()->isArithmeticType() &&
3210+
"second operand must be an arithmetic type");
3211+
return MB.CreateScalarDiv(Ops.LHS, Ops.RHS,
3212+
Ops.Ty->hasUnsignedIntegerRepresentation());
3213+
}
3214+
32013215
if (Ops.LHS->getType()->isFPOrFPVectorTy()) {
32023216
llvm::Value *Val;
32033217
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Ops.FPFeatures);

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ bool GenerateHeaderModuleAction::BeginSourceFileAction(
304304
<< Name;
305305
continue;
306306
}
307-
Headers.push_back({std::string(Name), std::string(Name), *FE});
307+
Headers.push_back({std::string(Name), std::string(Name),
308+
&FE->getFileEntry()});
308309
}
309310
HS.getModuleMap().createHeaderModule(CI.getLangOpts().CurrentModule, Headers);
310311

clang/lib/Lex/ModuleMap.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ bool ModuleMap::resolveAsBuiltinHeader(
300300
// supplied by Clang. Find that builtin header.
301301
SmallString<128> Path;
302302
llvm::sys::path::append(Path, BuiltinIncludeDir->getName(), Header.FileName);
303-
auto File = SourceMgr.getFileManager().getOptionalFileRef(Path);
303+
auto File = SourceMgr.getFileManager().getFile(Path);
304304
if (!File)
305305
return false;
306306

@@ -1021,7 +1021,7 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
10211021
// Look for an umbrella header.
10221022
SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
10231023
llvm::sys::path::append(UmbrellaName, "Headers", ModuleName + ".h");
1024-
auto UmbrellaHeader = FileMgr.getOptionalFileRef(UmbrellaName);
1024+
auto UmbrellaHeader = FileMgr.getFile(UmbrellaName);
10251025

10261026
// FIXME: If there's no umbrella header, we could probably scan the
10271027
// framework to load *everything*. But, it's not clear that this is a good
@@ -1133,25 +1133,25 @@ Module *ModuleMap::createShadowedModule(StringRef Name, bool IsFramework,
11331133
return Result;
11341134
}
11351135

1136-
void ModuleMap::setUmbrellaHeader(Module *Mod, FileEntryRef UmbrellaHeader,
1136+
void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
11371137
Twine NameAsWritten,
11381138
Twine PathRelativeToRootModuleDirectory) {
11391139
Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
1140-
Mod->Umbrella = &UmbrellaHeader.getMapEntry();
1140+
Mod->Umbrella = UmbrellaHeader;
11411141
Mod->UmbrellaAsWritten = NameAsWritten.str();
11421142
Mod->UmbrellaRelativeToRootModuleDirectory =
11431143
PathRelativeToRootModuleDirectory.str();
1144-
UmbrellaDirs[UmbrellaHeader.getDir()] = Mod;
1144+
UmbrellaDirs[UmbrellaHeader->getDir()] = Mod;
11451145

11461146
// Notify callbacks that we just added a new header.
11471147
for (const auto &Cb : Callbacks)
11481148
Cb->moduleMapAddUmbrellaHeader(&SourceMgr.getFileManager(), UmbrellaHeader);
11491149
}
11501150

1151-
void ModuleMap::setUmbrellaDir(Module *Mod, DirectoryEntryRef UmbrellaDir,
1151+
void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
11521152
Twine NameAsWritten,
11531153
Twine PathRelativeToRootModuleDirectory) {
1154-
Mod->Umbrella = &UmbrellaDir.getMapEntry();
1154+
Mod->Umbrella = UmbrellaDir;
11551155
Mod->UmbrellaAsWritten = NameAsWritten.str();
11561156
Mod->UmbrellaRelativeToRootModuleDirectory =
11571157
PathRelativeToRootModuleDirectory.str();
@@ -2438,15 +2438,15 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
24382438
}
24392439

24402440
// Look for this file.
2441-
Optional<DirectoryEntryRef> Dir;
2441+
const DirectoryEntry *Dir = nullptr;
24422442
if (llvm::sys::path::is_absolute(DirName)) {
2443-
if (auto D = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName))
2443+
if (auto D = SourceMgr.getFileManager().getDirectory(DirName))
24442444
Dir = *D;
24452445
} else {
24462446
SmallString<128> PathName;
24472447
PathName = Directory->getName();
24482448
llvm::sys::path::append(PathName, DirName);
2449-
if (auto D = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName))
2449+
if (auto D = SourceMgr.getFileManager().getDirectory(PathName))
24502450
Dir = *D;
24512451
}
24522452

@@ -2467,7 +2467,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
24672467
SourceMgr.getFileManager().getVirtualFileSystem();
24682468
for (llvm::vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E;
24692469
I != E && !EC; I.increment(EC)) {
2470-
if (auto FE = SourceMgr.getFileManager().getOptionalFileRef(I->path())) {
2470+
if (auto FE = SourceMgr.getFileManager().getFile(I->path())) {
24712471
Module::Header Header = {"", std::string(I->path()), *FE};
24722472
Headers.push_back(std::move(Header));
24732473
}
@@ -2481,15 +2481,15 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
24812481
return;
24822482
}
24832483

2484-
if (Module *OwningModule = Map.UmbrellaDirs[*Dir]) {
2484+
if (Module *OwningModule = Map.UmbrellaDirs[Dir]) {
24852485
Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
24862486
<< OwningModule->getFullModuleName();
24872487
HadError = true;
24882488
return;
24892489
}
24902490

24912491
// Record this umbrella directory.
2492-
Map.setUmbrellaDir(ActiveModule, *Dir, DirNameAsWritten, DirName);
2492+
Map.setUmbrellaDir(ActiveModule, Dir, DirNameAsWritten, DirName);
24932493
}
24942494

24952495
/// Parse a module export declaration.

clang/lib/Sema/SemaExpr.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10222,14 +10222,19 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
1022210222
bool IsCompAssign, bool IsDiv) {
1022310223
checkArithmeticNull(*this, LHS, RHS, Loc, /*IsCompare=*/false);
1022410224

10225-
if (LHS.get()->getType()->isVectorType() ||
10226-
RHS.get()->getType()->isVectorType())
10225+
QualType LHSTy = LHS.get()->getType();
10226+
QualType RHSTy = RHS.get()->getType();
10227+
if (LHSTy->isVectorType() || RHSTy->isVectorType())
1022710228
return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign,
1022810229
/*AllowBothBool*/getLangOpts().AltiVec,
1022910230
/*AllowBoolConversions*/false);
10230-
if (!IsDiv && (LHS.get()->getType()->isConstantMatrixType() ||
10231-
RHS.get()->getType()->isConstantMatrixType()))
10231+
if (!IsDiv &&
10232+
(LHSTy->isConstantMatrixType() || RHSTy->isConstantMatrixType()))
1023210233
return CheckMatrixMultiplyOperands(LHS, RHS, Loc, IsCompAssign);
10234+
// For division, only matrix-by-scalar is supported. Other combinations with
10235+
// matrix types are invalid.
10236+
if (IsDiv && LHSTy->isConstantMatrixType() && RHSTy->isArithmeticType())
10237+
return CheckMatrixElementwiseOperands(LHS, RHS, Loc, IsCompAssign);
1023310238

1023410239
QualType compType = UsualArithmeticConversions(
1023510240
LHS, RHS, Loc, IsCompAssign ? ACK_CompAssign : ACK_Arithmetic);
@@ -10551,7 +10556,11 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, ExprResult &RHS,
1055110556

1055210557
if (LHS.get()->getType()->isConstantMatrixType() ||
1055310558
RHS.get()->getType()->isConstantMatrixType()) {
10554-
return CheckMatrixElementwiseOperands(LHS, RHS, Loc, CompLHSTy);
10559+
QualType compType =
10560+
CheckMatrixElementwiseOperands(LHS, RHS, Loc, CompLHSTy);
10561+
if (CompLHSTy)
10562+
*CompLHSTy = compType;
10563+
return compType;
1055510564
}
1055610565

1055710566
QualType compType = UsualArithmeticConversions(
@@ -10651,7 +10660,11 @@ QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS,
1065110660

1065210661
if (LHS.get()->getType()->isConstantMatrixType() ||
1065310662
RHS.get()->getType()->isConstantMatrixType()) {
10654-
return CheckMatrixElementwiseOperands(LHS, RHS, Loc, CompLHSTy);
10663+
QualType compType =
10664+
CheckMatrixElementwiseOperands(LHS, RHS, Loc, CompLHSTy);
10665+
if (CompLHSTy)
10666+
*CompLHSTy = compType;
10667+
return compType;
1065510668
}
1065610669

1065710670
QualType compType = UsualArithmeticConversions(

0 commit comments

Comments
 (0)