Skip to content

Commit 16a0f98

Browse files
authored
merge main into amd-staging (llvm#1758)
2 parents 27968c7 + c51a0fd commit 16a0f98

File tree

114 files changed

+2039
-938
lines changed

Some content is hidden

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

114 files changed

+2039
-938
lines changed

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
1818
set(LLVM_ENABLE_LLD ON CACHE BOOL "")
1919
set(LLVM_ENABLE_LTO ON CACHE BOOL "")
2020
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
21+
set(LLVM_ENABLE_PIC OFF CACHE BOOL "")
2122
set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
2223
set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
2324
set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ related warnings within the method body.
301301
particularly relevant for AMDGPU targets, where they map to corresponding IR
302302
metadata.
303303

304+
- Clang now disallows the use of attributes applied before an
305+
``extern template`` declaration (#GH79893).
306+
304307
Improvements to Clang's diagnostics
305308
-----------------------------------
306309

clang/include/clang/CIR/Dialect/IR/CIRTypesDetails.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct RecordTypeStorage : public mlir::TypeStorage {
5454
RecordType::RecordKind kind)
5555
: members(members), name(name), incomplete(incomplete), packed(packed),
5656
padded(padded), kind(kind) {
57-
assert(name || !incomplete && "Incomplete records must have a name");
57+
assert((name || !incomplete) && "Incomplete records must have a name");
5858
}
5959

6060
KeyTy getAsKey() const {

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4831,15 +4831,17 @@ def EB : Flag<["-"], "EB">, Alias<mbig_endian>;
48314831
def m16 : Flag<["-"], "m16">, Group<m_Group>, Flags<[NoXarchOption]>,
48324832
Visibility<[ClangOption, CLOption, DXCOption]>;
48334833
def m32 : Flag<["-"], "m32">, Group<m_Group>, Flags<[NoXarchOption]>,
4834-
Visibility<[ClangOption, CLOption, DXCOption]>;
4835-
def maix32 : Flag<["-"], "maix32">, Group<m_Group>, Flags<[NoXarchOption]>;
4834+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
4835+
def maix32 : Flag<["-"], "maix32">, Group<m_Group>, Flags<[NoXarchOption]>,
4836+
Visibility<[FlangOption]>;
48364837
def mqdsp6_compat : Flag<["-"], "mqdsp6-compat">, Group<m_Group>,
48374838
Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
48384839
HelpText<"Enable hexagon-qdsp6 backward compatibility">,
48394840
MarshallingInfoFlag<LangOpts<"HexagonQdsp6Compat">>;
48404841
def m64 : Flag<["-"], "m64">, Group<m_Group>, Flags<[NoXarchOption]>,
48414842
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
4842-
def maix64 : Flag<["-"], "maix64">, Group<m_Group>, Flags<[NoXarchOption]>;
4843+
def maix64 : Flag<["-"], "maix64">, Group<m_Group>, Flags<[NoXarchOption]>,
4844+
Visibility<[FlangOption]>;
48434845
def mx32 : Flag<["-"], "mx32">, Group<m_Group>, Flags<[NoXarchOption]>,
48444846
Visibility<[ClangOption, CLOption, DXCOption]>;
48454847
def miamcu : Flag<["-"], "miamcu">, Group<m_Group>, Flags<[NoXarchOption]>,

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -845,18 +845,25 @@ class CompilerInstance : public ModuleLoader {
845845
/// Creates a \c CompilerInstance for compiling a module.
846846
///
847847
/// This expects a properly initialized \c FrontendInputFile.
848+
///
849+
/// Explicitly-specified \c VFS takes precedence over the VFS of this instance
850+
/// when creating the clone and also prevents \c FileManager sharing.
848851
std::unique_ptr<CompilerInstance> cloneForModuleCompileImpl(
849852
SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
850-
StringRef OriginalModuleMapFile, StringRef ModuleFileName);
853+
StringRef OriginalModuleMapFile, StringRef ModuleFileName,
854+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
851855

852856
public:
853857
/// Creates a new \c CompilerInstance for compiling a module.
854858
///
855859
/// This takes care of creating appropriate \c FrontendInputFile for
856860
/// public/private frameworks, inferred modules and such.
857-
std::unique_ptr<CompilerInstance>
858-
cloneForModuleCompile(SourceLocation ImportLoc, Module *Module,
859-
StringRef ModuleFileName);
861+
///
862+
/// Explicitly-specified \c VFS takes precedence over the VFS of this instance
863+
/// when creating the clone and also prevents \c FileManager sharing.
864+
std::unique_ptr<CompilerInstance> cloneForModuleCompile(
865+
SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName,
866+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
860867

861868
/// Compile a module file for the given module, using the options
862869
/// provided by the importing compiler instance. Returns true if the module

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
6363
case clang::TagTypeKind::Enum:
6464
llvm_unreachable("enums are not records");
6565
}
66+
llvm_unreachable("Unsupported record kind");
6667
}
6768

6869
/// Get an incomplete CIR struct type. If we have a complete record

clang/lib/CIR/CodeGen/CIRGenStmtOpenACC.cpp

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,27 @@ class OpenACCClauseCIREmitter final
4646
// diagnostics are gone.
4747
SourceLocation dirLoc;
4848

49+
const OpenACCDeviceTypeClause *lastDeviceTypeClause = nullptr;
50+
4951
void clauseNotImplemented(const OpenACCClause &c) {
5052
cgf.cgm.errorNYI(c.getSourceRange(), "OpenACC Clause", c.getClauseKind());
5153
}
5254

55+
mlir::Value createIntExpr(const Expr *intExpr) {
56+
mlir::Value expr = cgf.emitScalarExpr(intExpr);
57+
mlir::Location exprLoc = cgf.cgm.getLoc(intExpr->getBeginLoc());
58+
59+
mlir::IntegerType targetType = mlir::IntegerType::get(
60+
&cgf.getMLIRContext(), cgf.getContext().getIntWidth(intExpr->getType()),
61+
intExpr->getType()->isSignedIntegerOrEnumerationType()
62+
? mlir::IntegerType::SignednessSemantics::Signed
63+
: mlir::IntegerType::SignednessSemantics::Unsigned);
64+
65+
auto conversionOp = builder.create<mlir::UnrealizedConversionCastOp>(
66+
exprLoc, targetType, expr);
67+
return conversionOp.getResult(0);
68+
}
69+
5370
// 'condition' as an OpenACC grammar production is used for 'if' and (some
5471
// variants of) 'self'. It needs to be emitted as a signless-1-bit value, so
5572
// this function emits the expression, then sets the unrealized conversion
@@ -109,14 +126,15 @@ class OpenACCClauseCIREmitter final
109126
}
110127

111128
void VisitDeviceTypeClause(const OpenACCDeviceTypeClause &clause) {
129+
lastDeviceTypeClause = &clause;
112130
if constexpr (isOneOfTypes<OpTy, InitOp, ShutdownOp>) {
113131
llvm::SmallVector<mlir::Attribute> deviceTypes;
114132
std::optional<mlir::ArrayAttr> existingDeviceTypes =
115133
operation.getDeviceTypes();
116134

117135
// Ensure we keep the existing ones, and in the correct 'new' order.
118136
if (existingDeviceTypes) {
119-
for (const mlir::Attribute &Attr : *existingDeviceTypes)
137+
for (mlir::Attribute Attr : *existingDeviceTypes)
120138
deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get(
121139
builder.getContext(),
122140
cast<mlir::acc::DeviceTypeAttr>(Attr).getValue()));
@@ -136,6 +154,51 @@ class OpenACCClauseCIREmitter final
136154
if (!clause.getArchitectures().empty())
137155
operation.setDeviceType(
138156
decodeDeviceType(clause.getArchitectures()[0].getIdentifierInfo()));
157+
} else if constexpr (isOneOfTypes<OpTy, ParallelOp, SerialOp, KernelsOp>) {
158+
// Nothing to do here, these constructs don't have any IR for these, as
159+
// they just modify the other clauses IR. So setting of `lastDeviceType`
160+
// (done above) is all we need.
161+
} else {
162+
return clauseNotImplemented(clause);
163+
}
164+
}
165+
166+
void VisitNumWorkersClause(const OpenACCNumWorkersClause &clause) {
167+
if constexpr (isOneOfTypes<OpTy, ParallelOp, KernelsOp>) {
168+
// Collect the 'existing' device-type attributes so we can re-create them
169+
// and insert them.
170+
llvm::SmallVector<mlir::Attribute> deviceTypes;
171+
mlir::ArrayAttr existingDeviceTypes =
172+
operation.getNumWorkersDeviceTypeAttr();
173+
174+
if (existingDeviceTypes) {
175+
for (mlir::Attribute Attr : existingDeviceTypes)
176+
deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get(
177+
builder.getContext(),
178+
cast<mlir::acc::DeviceTypeAttr>(Attr).getValue()));
179+
}
180+
181+
// Insert 1 version of the 'int-expr' to the NumWorkers list per-current
182+
// device type.
183+
mlir::Value intExpr = createIntExpr(clause.getIntExpr());
184+
if (lastDeviceTypeClause) {
185+
for (const DeviceTypeArgument &arg :
186+
lastDeviceTypeClause->getArchitectures()) {
187+
deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get(
188+
builder.getContext(), decodeDeviceType(arg.getIdentifierInfo())));
189+
operation.getNumWorkersMutable().append(intExpr);
190+
}
191+
} else {
192+
// Else, we just add a single for 'none'.
193+
deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get(
194+
builder.getContext(), mlir::acc::DeviceType::None));
195+
operation.getNumWorkersMutable().append(intExpr);
196+
}
197+
198+
operation.setNumWorkersDeviceTypeAttr(
199+
mlir::ArrayAttr::get(builder.getContext(), deviceTypes));
200+
} else if constexpr (isOneOfTypes<OpTy, SerialOp>) {
201+
llvm_unreachable("num_workers not valid on serial");
139202
} else {
140203
return clauseNotImplemented(clause);
141204
}

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt,
153153
// out, don't do it. This includes virtual base classes which get laid out
154154
// when a class is translated, even though they aren't embedded by-value into
155155
// the class.
156-
if (const CXXRecordDecl *crd = dyn_cast<CXXRecordDecl>(rd)) {
156+
if (isa<CXXRecordDecl>(rd)) {
157157
assert(!cir::MissingFeatures::cxxSupport());
158158
cgt.getCGModule().errorNYI(rd->getSourceRange(),
159159
"isSafeToConvert: CXXRecordDecl");
@@ -237,7 +237,7 @@ mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) {
237237
assert(insertResult && "isSafeToCovert() should have caught this.");
238238

239239
// Force conversion of non-virtual base classes recursively.
240-
if (const auto *cxxRecordDecl = dyn_cast<CXXRecordDecl>(rd)) {
240+
if (isa<CXXRecordDecl>(rd)) {
241241
cgm.errorNYI(rd->getSourceRange(), "CXXRecordDecl");
242242
}
243243

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,16 @@ static llvm::Triple computeTargetTriple(const Driver &D,
735735
Target.setEnvironment(llvm::Triple::GNUX32);
736736
} else if (A->getOption().matches(options::OPT_m32) ||
737737
A->getOption().matches(options::OPT_maix32)) {
738-
AT = Target.get32BitArchVariant().getArch();
739-
if (Target.getEnvironment() == llvm::Triple::GNUX32)
740-
Target.setEnvironment(llvm::Triple::GNU);
741-
else if (Target.getEnvironment() == llvm::Triple::MuslX32)
742-
Target.setEnvironment(llvm::Triple::Musl);
738+
if (D.IsFlangMode() && !Target.isOSAIX()) {
739+
D.Diag(diag::err_drv_unsupported_opt_for_target)
740+
<< A->getAsString(Args) << Target.str();
741+
} else {
742+
AT = Target.get32BitArchVariant().getArch();
743+
if (Target.getEnvironment() == llvm::Triple::GNUX32)
744+
Target.setEnvironment(llvm::Triple::GNU);
745+
else if (Target.getEnvironment() == llvm::Triple::MuslX32)
746+
Target.setEnvironment(llvm::Triple::Musl);
747+
}
743748
} else if (A->getOption().matches(options::OPT_m16) &&
744749
Target.get32BitArchVariant().getArch() == llvm::Triple::x86) {
745750
AT = llvm::Triple::x86;

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,8 @@ static Language getLanguageFromOptions(const LangOptions &LangOpts) {
11521152

11531153
std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
11541154
SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
1155-
StringRef OriginalModuleMapFile, StringRef ModuleFileName) {
1155+
StringRef OriginalModuleMapFile, StringRef ModuleFileName,
1156+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
11561157
// Construct a compiler invocation for creating this module.
11571158
auto Invocation = std::make_shared<CompilerInvocation>(getInvocation());
11581159

@@ -1212,19 +1213,21 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
12121213
auto &Inv = *Invocation;
12131214
Instance.setInvocation(std::move(Invocation));
12141215

1216+
if (VFS) {
1217+
Instance.createFileManager(std::move(VFS));
1218+
} else if (FrontendOpts.ModulesShareFileManager) {
1219+
Instance.setFileManager(&getFileManager());
1220+
} else {
1221+
Instance.createFileManager(&getVirtualFileSystem());
1222+
}
1223+
12151224
Instance.createDiagnostics(
1216-
getVirtualFileSystem(),
1225+
Instance.getVirtualFileSystem(),
12171226
new ForwardingDiagnosticConsumer(getDiagnosticClient()),
12181227
/*ShouldOwnClient=*/true);
1219-
12201228
if (llvm::is_contained(DiagOpts.SystemHeaderWarningsModules, ModuleName))
12211229
Instance.getDiagnostics().setSuppressSystemWarnings(false);
12221230

1223-
if (FrontendOpts.ModulesShareFileManager) {
1224-
Instance.setFileManager(&getFileManager());
1225-
} else {
1226-
Instance.createFileManager(&getVirtualFileSystem());
1227-
}
12281231
Instance.createSourceManager(Instance.getFileManager());
12291232
SourceManager &SourceMgr = Instance.getSourceManager();
12301233

@@ -1318,7 +1321,8 @@ static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File,
13181321
}
13191322

13201323
std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
1321-
SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName) {
1324+
SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName,
1325+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
13221326
StringRef ModuleName = Module->getTopLevelModuleName();
13231327

13241328
InputKind IK(getLanguageFromOptions(getLangOpts()), InputKind::ModuleMap);
@@ -1363,7 +1367,8 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
13631367
return cloneForModuleCompileImpl(
13641368
ImportLoc, ModuleName,
13651369
FrontendInputFile(ModuleMapFilePath, IK, IsSystem),
1366-
ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName);
1370+
ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName,
1371+
std::move(VFS));
13671372
}
13681373

13691374
// FIXME: We only need to fake up an input file here as a way of
@@ -1380,7 +1385,8 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
13801385
auto Instance = cloneForModuleCompileImpl(
13811386
ImportLoc, ModuleName,
13821387
FrontendInputFile(FakeModuleMapFile, IK, +Module->IsSystem),
1383-
ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName);
1388+
ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName,
1389+
std::move(VFS));
13841390

13851391
std::unique_ptr<llvm::MemoryBuffer> ModuleMapBuffer =
13861392
llvm::MemoryBuffer::getMemBufferCopy(InferredModuleMapContent);

0 commit comments

Comments
 (0)