summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/BackendUtil.cpp8
-rw-r--r--clang/lib/CodeGen/CGBlocks.cpp25
-rw-r--r--clang/lib/CodeGen/CGCall.cpp15
-rw-r--r--clang/lib/CodeGen/CGCoroutine.cpp14
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp64
-rw-r--r--clang/lib/CodeGen/CGException.cpp51
-rw-r--r--clang/lib/CodeGen/CGLoopInfo.cpp46
-rw-r--r--clang/lib/CodeGen/CGObjC.cpp52
-rw-r--r--clang/lib/CodeGen/CGObjCGNU.cpp5
-rw-r--r--clang/lib/CodeGen/CGObjCMac.cpp94
-rw-r--r--clang/lib/CodeGen/CGOpenMPRuntime.cpp4
-rw-r--r--clang/lib/CodeGen/CMakeLists.txt1
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp2
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp3
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp8
-rw-r--r--clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp211
-rw-r--r--clang/lib/CodeGen/TargetBuiltins/PPC.cpp5
-rw-r--r--clang/lib/CodeGen/TargetBuiltins/RISCV.cpp6
-rw-r--r--clang/lib/CodeGen/TargetBuiltins/SPIR.cpp12
-rw-r--r--clang/lib/CodeGen/TargetInfo.h3
-rw-r--r--clang/lib/CodeGen/Targets/PNaCl.cpp114
-rw-r--r--clang/lib/CodeGen/Targets/X86.cpp35
22 files changed, 532 insertions, 246 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 2f6d4c414e73..1b7257857dd3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -407,13 +407,13 @@ static bool initTargetOptions(const CompilerInstance &CI,
// Set EABI version.
Options.EABIVersion = TargetOpts.EABIVersion;
- if (LangOpts.hasSjLjExceptions())
+ if (CodeGenOpts.hasSjLjExceptions())
Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
- if (LangOpts.hasSEHExceptions())
+ if (CodeGenOpts.hasSEHExceptions())
Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
- if (LangOpts.hasDWARFExceptions())
+ if (CodeGenOpts.hasDWARFExceptions())
Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
- if (LangOpts.hasWasmExceptions())
+ if (CodeGenOpts.hasWasmExceptions())
Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
Options.NoInfsFPMath = LangOpts.NoHonorInfs;
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index f3ddf7bf9a46..0e80522536e1 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -853,9 +853,24 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {
offset += size;
index++;
};
+ auto addSignedHeaderField =
+ [&](llvm::Value *Value, const PointerAuthSchema &Schema,
+ GlobalDecl Decl, QualType Type, CharUnits Size, const Twine &Name) {
+ auto StorageAddress = projectField(index, Name);
+ if (Schema) {
+ auto AuthInfo = EmitPointerAuthInfo(
+ Schema, StorageAddress.emitRawPointer(*this), Decl, Type);
+ Value = EmitPointerAuthSign(AuthInfo, Value);
+ }
+ Builder.CreateStore(Value, StorageAddress);
+ offset += Size;
+ index++;
+ };
if (!IsOpenCL) {
- addHeaderField(isa, getPointerSize(), "block.isa");
+ addSignedHeaderField(
+ isa, CGM.getCodeGenOpts().PointerAuth.ObjCIsaPointers, GlobalDecl(),
+ QualType(), getPointerSize(), "block.isa");
addHeaderField(llvm::ConstantInt::get(IntTy, flags.getBitMask()),
getIntSize(), "block.flags");
addHeaderField(llvm::ConstantInt::get(IntTy, 0), getIntSize(),
@@ -1285,7 +1300,9 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,
if (IsWindows)
fields.addNullPointer(CGM.Int8PtrPtrTy);
else
- fields.add(CGM.getNSConcreteGlobalBlock());
+ fields.addSignedPointer(CGM.getNSConcreteGlobalBlock(),
+ CGM.getCodeGenOpts().PointerAuth.ObjCIsaPointers,
+ GlobalDecl(), QualType());
// __flags
BlockFlags flags = BLOCK_IS_GLOBAL;
@@ -1532,8 +1549,8 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
llvm::BasicBlock *resume = Builder.GetInsertBlock();
// Go back to the entry.
- if (entry_ptr->getNextNonDebugInstruction())
- entry_ptr = entry_ptr->getNextNonDebugInstruction()->getIterator();
+ if (entry_ptr->getNextNode())
+ entry_ptr = entry_ptr->getNextNode()->getIterator();
else
entry_ptr = entry->end();
Builder.SetInsertPoint(entry, entry_ptr);
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index c8c3d6b20c49..19d8ba26d44d 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2852,8 +2852,21 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
if (AI.getInReg())
Attrs.addAttribute(llvm::Attribute::InReg);
- if (AI.getIndirectByVal())
+ // Depending on the ABI, this may be either a byval or a dead_on_return
+ // argument.
+ if (AI.getIndirectByVal()) {
Attrs.addByValAttr(getTypes().ConvertTypeForMem(ParamType));
+ } else {
+ // Add dead_on_return when the object's lifetime ends in the callee.
+ // This includes trivially-destructible objects, as well as objects
+ // whose destruction / clean-up is carried out within the callee (e.g.,
+ // Obj-C ARC-managed structs, MSVC callee-destroyed objects).
+ if (!ParamType.isDestructedType() || !ParamType->isRecordType() ||
+ ParamType->castAs<RecordType>()
+ ->getDecl()
+ ->isParamDestroyedInCallee())
+ Attrs.addAttribute(llvm::Attribute::DeadOnReturn);
+ }
auto *Decl = ParamType->getAsRecordDecl();
if (CodeGenOpts.PassByValueIsNoAlias && Decl &&
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp b/clang/lib/CodeGen/CGCoroutine.cpp
index 0fc488e98aaf..117ef3d16e21 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -707,11 +707,15 @@ struct GetReturnObjectManager {
Builder.CreateStore(Builder.getFalse(), GroActiveFlag);
GroEmission = CGF.EmitAutoVarAlloca(*GroVarDecl);
- auto *GroAlloca = dyn_cast_or_null<llvm::AllocaInst>(
- GroEmission.getOriginalAllocatedAddress().getPointer());
- assert(GroAlloca && "expected alloca to be emitted");
- GroAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,
- llvm::MDNode::get(CGF.CGM.getLLVMContext(), {}));
+
+ if (!GroVarDecl->isNRVOVariable()) {
+ // NRVO variables don't have allocas and won't have the same issue.
+ auto *GroAlloca = dyn_cast_or_null<llvm::AllocaInst>(
+ GroEmission.getOriginalAllocatedAddress().getPointer());
+ assert(GroAlloca && "expected alloca to be emitted");
+ GroAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,
+ llvm::MDNode::get(CGF.CGM.getLLVMContext(), {}));
+ }
// Remember the top of EHStack before emitting the cleanup.
auto old_top = CGF.EHStack.stable_begin();
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8bf7d24d8551..446cf8d9e05c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -170,6 +170,10 @@ void CGDebugInfo::addInstToSpecificSourceAtom(llvm::Instruction *KeyInstruction,
if (!Group || !CGM.getCodeGenOpts().DebugKeyInstructions)
return;
+ llvm::DISubprogram *SP = KeyInstruction->getFunction()->getSubprogram();
+ if (!SP || !SP->getKeyInstructionsEnabled())
+ return;
+
addInstSourceAtomMetadata(KeyInstruction, Group, /*Rank=*/1);
llvm::Instruction *BackupI =
@@ -514,6 +518,8 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<64> &Checksum) const {
case clang::CodeGenOptions::DSH_SHA256:
llvm::toHex(llvm::SHA256::hash(Data), /*LowerCase=*/true, Checksum);
return llvm::DIFile::CSK_SHA256;
+ case clang::CodeGenOptions::DSH_NONE:
+ return std::nullopt;
}
llvm_unreachable("Unhandled DebugSrcHashKind enum");
}
@@ -797,7 +803,8 @@ void CGDebugInfo::CreateCompileUnit() {
// Create new compile unit.
TheCU = DBuilder.createCompileUnit(
LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
- LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
+ CGOpts.OptimizationLevel != 0 || CGOpts.PrepareForLTO ||
+ CGOpts.PrepareForThinLTO,
CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
NameTableKind, CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
@@ -2282,7 +2289,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
Flags |= llvm::DINode::FlagRValueReference;
if (!Method->isExternallyVisible())
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
- if (CGM.getLangOpts().Optimize)
+ if (CGM.getCodeGenOpts().OptimizationLevel != 0)
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
// In this debug mode, emit type info for a class when its constructor type
@@ -4353,7 +4360,7 @@ llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
FD->getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
if (!FD->isExternallyVisible())
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
- if (CGM.getLangOpts().Optimize)
+ if (CGM.getCodeGenOpts().OptimizationLevel != 0)
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
if (Stub) {
@@ -4629,6 +4636,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
llvm::DIFile *Unit = getOrCreateFile(Loc);
llvm::DIScope *FDContext = Unit;
llvm::DINodeArray TParamsArray;
+ bool KeyInstructions = CGM.getCodeGenOpts().DebugKeyInstructions;
if (!HasDecl) {
// Use llvm function name.
LinkageName = Fn->getName();
@@ -4645,6 +4653,9 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
}
collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
TParamsArray, Flags);
+ // Disable KIs if this is a coroutine.
+ KeyInstructions =
+ KeyInstructions && !isa_and_present<CoroutineBodyStmt>(FD->getBody());
} else if (const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
Name = getObjCMethodName(OMD);
Flags |= llvm::DINode::FlagPrototyped;
@@ -4679,7 +4690,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
if (Fn->hasLocalLinkage())
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
- if (CGM.getLangOpts().Optimize)
+ if (CGM.getCodeGenOpts().OptimizationLevel != 0)
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
llvm::DINode::DIFlags FlagsForDef = Flags | getCallSiteRelatedAttrs();
@@ -4706,7 +4717,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
llvm::DISubprogram *SP = DBuilder.createFunction(
FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
FlagsForDef, SPFlagsForDef, TParamsArray.get(), Decl, nullptr,
- Annotations, "", CGM.getCodeGenOpts().DebugKeyInstructions);
+ Annotations, "", KeyInstructions);
Fn->setSubprogram(SP);
// We might get here with a VarDecl in the case we're generating
@@ -4762,7 +4773,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
unsigned LineNo = getLineNumber(Loc);
unsigned ScopeLine = 0;
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
- if (CGM.getLangOpts().Optimize)
+ if (CGM.getCodeGenOpts().OptimizationLevel != 0)
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
@@ -5094,7 +5105,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
// Use VarDecl's Tag, Scope and Line number.
auto FieldAlign = getDeclAlignIfRequired(Field, CGM.getContext());
auto *D = DBuilder.createAutoVariable(
- Scope, FieldName, Unit, Line, FieldTy, CGM.getLangOpts().Optimize,
+ Scope, FieldName, Unit, Line, FieldTy,
+ CGM.getCodeGenOpts().OptimizationLevel != 0,
Flags | llvm::DINode::FlagArtificial, FieldAlign);
// Insert an llvm.dbg.declare into the current block.
@@ -5120,9 +5132,9 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
llvm::DILocalVariable *D = nullptr;
if (ArgNo) {
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
- D = DBuilder.createParameterVariable(Scope, Name, *ArgNo, Unit, Line, Ty,
- CGM.getLangOpts().Optimize, Flags,
- Annotations);
+ D = DBuilder.createParameterVariable(
+ Scope, Name, *ArgNo, Unit, Line, Ty,
+ CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Annotations);
} else {
// For normal local variable, we will try to find out whether 'VD' is the
// copy parameter of coroutine.
@@ -5163,8 +5175,9 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
D = RemapCoroArgToLocalVar();
// Or we will create a new DIVariable for this Decl if D dose not exists.
if (!D)
- D = DBuilder.createAutoVariable(Scope, Name, Unit, Line, Ty,
- CGM.getLangOpts().Optimize, Flags, Align);
+ D = DBuilder.createAutoVariable(
+ Scope, Name, Unit, Line, Ty,
+ CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Align);
}
// Insert an llvm.dbg.declare into the current block.
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
@@ -5218,7 +5231,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
// Create the descriptor for the variable.
llvm::DILocalVariable *D = DBuilder.createAutoVariable(
- Scope, Name, Unit, Line, Ty, CGM.getLangOpts().Optimize,
+ Scope, Name, Unit, Line, Ty, CGM.getCodeGenOpts().OptimizationLevel != 0,
llvm::DINode::FlagZero, Align);
if (const MemberExpr *ME = dyn_cast<MemberExpr>(BD->getBinding())) {
@@ -5316,9 +5329,10 @@ void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
StringRef Name = D->getName();
// Create the descriptor for the label.
- auto *L = DBuilder.createLabel(
- Scope, Name, Unit, Line, Column, /*IsArtificial=*/false,
- /*CoroSuspendIdx=*/std::nullopt, CGM.getLangOpts().Optimize);
+ auto *L = DBuilder.createLabel(Scope, Name, Unit, Line, Column,
+ /*IsArtificial=*/false,
+ /*CoroSuspendIdx=*/std::nullopt,
+ CGM.getCodeGenOpts().OptimizationLevel != 0);
// Insert an llvm.dbg.label into the current block.
DBuilder.insertLabel(L,
@@ -5581,7 +5595,8 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
// Create the descriptor for the parameter.
auto *debugVar = DBuilder.createParameterVariable(
- scope, Name, ArgNo, tunit, line, type, CGM.getLangOpts().Optimize, flags);
+ scope, Name, ArgNo, tunit, line, type,
+ CGM.getCodeGenOpts().OptimizationLevel != 0, flags);
// Insert an llvm.dbg.declare into the current block.
DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
@@ -6356,7 +6371,7 @@ llvm::DebugLoc CGDebugInfo::SourceLocToDebugLoc(SourceLocation Loc) {
llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {
// Call site-related attributes are only useful in optimized programs, and
// when there's a possibility of debugging backtraces.
- if (!CGM.getLangOpts().Optimize ||
+ if (CGM.getCodeGenOpts().OptimizationLevel == 0 ||
DebugKind == llvm::codegenoptions::NoDebugInfo ||
DebugKind == llvm::codegenoptions::LocTrackingOnly)
return llvm::DINode::FlagZero;
@@ -6465,24 +6480,27 @@ SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal) {
llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
ArrayRef<SanitizerKind::SanitizerOrdinal> Ordinals,
SanitizerHandler Handler) {
+ llvm::DILocation *CheckDebugLoc = Builder.getCurrentDebugLocation();
+ auto *DI = getDebugInfo();
+ if (!DI)
+ return CheckDebugLoc;
+
std::string Label;
if (Ordinals.size() == 1)
Label = SanitizerOrdinalToCheckLabel(Ordinals[0]);
else
Label = SanitizerHandlerToCheckLabel(Handler);
- llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
-
for (auto Ord : Ordinals) {
// TODO: deprecate ClArrayBoundsPseudoFn
if (((ClArrayBoundsPseudoFn && Ord == SanitizerKind::SO_ArrayBounds) ||
CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo.has(Ord)) &&
- CheckDI) {
- return getDebugInfo()->CreateSyntheticInlineAt(CheckDI, Label);
+ CheckDebugLoc) {
+ return DI->CreateSyntheticInlineAt(CheckDebugLoc, Label);
}
}
- return CheckDI;
+ return CheckDebugLoc;
}
SanitizerDebugLocation::SanitizerDebugLocation(
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index ad138b9876e8..f86af4581c34 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -131,20 +131,21 @@ const EHPersonality EHPersonality::ZOS_CPlusPlus = {"__zos_cxx_personality_v2",
nullptr};
static const EHPersonality &getCPersonality(const TargetInfo &Target,
- const LangOptions &L) {
+ const CodeGenOptions &CGOpts) {
const llvm::Triple &T = Target.getTriple();
if (T.isWindowsMSVCEnvironment())
return EHPersonality::MSVC_CxxFrameHandler3;
- if (L.hasSjLjExceptions())
+ if (CGOpts.hasSjLjExceptions())
return EHPersonality::GNU_C_SJLJ;
- if (L.hasDWARFExceptions())
+ if (CGOpts.hasDWARFExceptions())
return EHPersonality::GNU_C;
- if (L.hasSEHExceptions())
+ if (CGOpts.hasSEHExceptions())
return EHPersonality::GNU_C_SEH;
return EHPersonality::GNU_C;
}
static const EHPersonality &getObjCPersonality(const TargetInfo &Target,
+ const CodeGenOptions &CGOpts,
const LangOptions &L) {
const llvm::Triple &T = Target.getTriple();
if (T.isWindowsMSVCEnvironment())
@@ -152,7 +153,7 @@ static const EHPersonality &getObjCPersonality(const TargetInfo &Target,
switch (L.ObjCRuntime.getKind()) {
case ObjCRuntime::FragileMacOSX:
- return getCPersonality(Target, L);
+ return getCPersonality(Target, CGOpts);
case ObjCRuntime::MacOSX:
case ObjCRuntime::iOS:
case ObjCRuntime::WatchOS:
@@ -165,9 +166,9 @@ static const EHPersonality &getObjCPersonality(const TargetInfo &Target,
[[fallthrough]];
case ObjCRuntime::GCC:
case ObjCRuntime::ObjFW:
- if (L.hasSjLjExceptions())
+ if (CGOpts.hasSjLjExceptions())
return EHPersonality::GNU_ObjC_SJLJ;
- if (L.hasSEHExceptions())
+ if (CGOpts.hasSEHExceptions())
return EHPersonality::GNU_ObjC_SEH;
return EHPersonality::GNU_ObjC;
}
@@ -175,19 +176,19 @@ static const EHPersonality &getObjCPersonality(const TargetInfo &Target,
}
static const EHPersonality &getCXXPersonality(const TargetInfo &Target,
- const LangOptions &L) {
+ const CodeGenOptions &CGOpts) {
const llvm::Triple &T = Target.getTriple();
if (T.isWindowsMSVCEnvironment())
return EHPersonality::MSVC_CxxFrameHandler3;
if (T.isOSAIX())
return EHPersonality::XL_CPlusPlus;
- if (L.hasSjLjExceptions())
+ if (CGOpts.hasSjLjExceptions())
return EHPersonality::GNU_CPlusPlus_SJLJ;
- if (L.hasDWARFExceptions())
+ if (CGOpts.hasDWARFExceptions())
return EHPersonality::GNU_CPlusPlus;
- if (L.hasSEHExceptions())
+ if (CGOpts.hasSEHExceptions())
return EHPersonality::GNU_CPlusPlus_SEH;
- if (L.hasWasmExceptions())
+ if (CGOpts.hasWasmExceptions())
return EHPersonality::GNU_Wasm_CPlusPlus;
if (T.isOSzOS())
return EHPersonality::ZOS_CPlusPlus;
@@ -197,6 +198,7 @@ static const EHPersonality &getCXXPersonality(const TargetInfo &Target,
/// Determines the personality function to use when both C++
/// and Objective-C exceptions are being caught.
static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target,
+ const CodeGenOptions &CGOpts,
const LangOptions &L) {
if (Target.getTriple().isWindowsMSVCEnvironment())
return EHPersonality::MSVC_CxxFrameHandler3;
@@ -205,7 +207,7 @@ static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target,
// In the fragile ABI, just use C++ exception handling and hope
// they're not doing crazy exception mixing.
case ObjCRuntime::FragileMacOSX:
- return getCXXPersonality(Target, L);
+ return getCXXPersonality(Target, CGOpts);
// The ObjC personality defers to the C++ personality for non-ObjC
// handlers. Unlike the C++ case, we use the same personality
@@ -213,7 +215,7 @@ static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target,
case ObjCRuntime::MacOSX:
case ObjCRuntime::iOS:
case ObjCRuntime::WatchOS:
- return getObjCPersonality(Target, L);
+ return getObjCPersonality(Target, CGOpts, L);
case ObjCRuntime::GNUstep:
return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
@@ -223,7 +225,7 @@ static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target,
// mixed EH. Use the ObjC personality just to avoid returning null.
case ObjCRuntime::GCC:
case ObjCRuntime::ObjFW:
- return getObjCPersonality(Target, L);
+ return getObjCPersonality(Target, CGOpts, L);
}
llvm_unreachable("bad runtime kind");
}
@@ -237,6 +239,7 @@ static const EHPersonality &getSEHPersonalityMSVC(const llvm::Triple &T) {
const EHPersonality &EHPersonality::get(CodeGenModule &CGM,
const FunctionDecl *FD) {
const llvm::Triple &T = CGM.getTarget().getTriple();
+ const CodeGenOptions &CGOpts = CGM.getCodeGenOpts();
const LangOptions &L = CGM.getLangOpts();
const TargetInfo &Target = CGM.getTarget();
@@ -245,10 +248,10 @@ const EHPersonality &EHPersonality::get(CodeGenModule &CGM,
return getSEHPersonalityMSVC(T);
if (L.ObjC)
- return L.CPlusPlus ? getObjCXXPersonality(Target, L)
- : getObjCPersonality(Target, L);
- return L.CPlusPlus ? getCXXPersonality(Target, L)
- : getCPersonality(Target, L);
+ return L.CPlusPlus ? getObjCXXPersonality(Target, CGOpts, L)
+ : getObjCPersonality(Target, CGOpts, L);
+ return L.CPlusPlus ? getCXXPersonality(Target, CGOpts)
+ : getCPersonality(Target, CGOpts);
}
const EHPersonality &EHPersonality::get(CodeGenFunction &CGF) {
@@ -344,7 +347,7 @@ void CodeGenModule::SimplifyPersonality() {
return;
const EHPersonality &ObjCXX = EHPersonality::get(*this, /*FD=*/nullptr);
- const EHPersonality &CXX = getCXXPersonality(getTarget(), LangOpts);
+ const EHPersonality &CXX = getCXXPersonality(getTarget(), CodeGenOpts);
if (&ObjCXX == &CXX)
return;
@@ -500,7 +503,7 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
// In Wasm EH we currently treat 'throw()' in the same way as 'noexcept'. In
// case of throw with types, we ignore it and print a warning for now.
// TODO Correctly handle exception specification in Wasm EH
- if (CGM.getLangOpts().hasWasmExceptions()) {
+ if (CGM.getCodeGenOpts().hasWasmExceptions()) {
if (EST == EST_DynamicNone)
EHStack.pushTerminate();
else
@@ -515,8 +518,8 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
// throw with types.
// TODO Correctly handle exception specification in Emscripten EH
if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly &&
- CGM.getLangOpts().getExceptionHandling() ==
- LangOptions::ExceptionHandlingKind::None &&
+ CGM.getCodeGenOpts().getExceptionHandling() ==
+ CodeGenOptions::ExceptionHandlingKind::None &&
EST == EST_Dynamic)
CGM.getDiags().Report(D->getLocation(),
diag::warn_wasm_dynamic_exception_spec_ignored)
@@ -604,7 +607,7 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
// case of throw with types, we ignore it and print a warning for now.
// TODO Correctly handle exception specification in wasm
- if (CGM.getLangOpts().hasWasmExceptions()) {
+ if (CGM.getCodeGenOpts().hasWasmExceptions()) {
if (EST == EST_DynamicNone)
EHStack.popTerminate();
return;
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index 4a9092842858..b2b569a43038 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/CodeGen/CGLoopInfo.cpp
@@ -221,18 +221,6 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs,
return createUnrollAndJamMetadata(Attrs, LoopProperties, HasUserTransforms);
}
- // Apply all loop properties to the vectorized loop.
- SmallVector<Metadata *, 4> FollowupLoopProperties;
- FollowupLoopProperties.append(LoopProperties.begin(), LoopProperties.end());
-
- // Don't vectorize an already vectorized loop.
- FollowupLoopProperties.push_back(
- MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.isvectorized")));
-
- bool FollowupHasTransforms = false;
- SmallVector<Metadata *, 4> Followup = createUnrollAndJamMetadata(
- Attrs, FollowupLoopProperties, FollowupHasTransforms);
-
SmallVector<Metadata *, 4> Args;
Args.append(LoopProperties.begin(), LoopProperties.end());
@@ -286,22 +274,46 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs,
// 5) it is implied when vectorize.width is unset (0) and the user
// explicitly requested fixed-width vectorization, i.e.
// vectorize.scalable.enable is false.
+ bool VectorizeEnabled = false;
if (Attrs.VectorizeEnable != LoopAttributes::Unspecified ||
(IsVectorPredicateEnabled && Attrs.VectorizeWidth != 1) ||
Attrs.VectorizeWidth > 1 ||
Attrs.VectorizeScalable == LoopAttributes::Enable ||
(Attrs.VectorizeScalable == LoopAttributes::Disable &&
Attrs.VectorizeWidth != 1)) {
- bool AttrVal = Attrs.VectorizeEnable != LoopAttributes::Disable;
+ VectorizeEnabled = Attrs.VectorizeEnable != LoopAttributes::Disable;
Args.push_back(
MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.enable"),
ConstantAsMetadata::get(ConstantInt::get(
- llvm::Type::getInt1Ty(Ctx), AttrVal))}));
+ llvm::Type::getInt1Ty(Ctx), VectorizeEnabled))}));
}
- if (FollowupHasTransforms)
- Args.push_back(
- createFollowupMetadata("llvm.loop.vectorize.followup_all", Followup));
+ // Apply all loop properties to the vectorized loop.
+ SmallVector<Metadata *, 4> FollowupLoopProperties;
+
+ // If vectorization is not explicitly enabled, the follow-up metadata will be
+ // directly appended to the list currently being created. In that case, adding
+ // LoopProperties to FollowupLoopProperties would result in duplication.
+ if (VectorizeEnabled)
+ FollowupLoopProperties.append(LoopProperties.begin(), LoopProperties.end());
+
+ // Don't vectorize an already vectorized loop.
+ FollowupLoopProperties.push_back(
+ MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.isvectorized")));
+
+ bool FollowupHasTransforms = false;
+ SmallVector<Metadata *, 4> Followup = createUnrollAndJamMetadata(
+ Attrs, FollowupLoopProperties, FollowupHasTransforms);
+
+ if (FollowupHasTransforms) {
+ // If vectorization is explicitly enabled, we create a follow-up metadata,
+ // otherwise directly add the contents of it to Args.
+ if (VectorizeEnabled)
+ Args.push_back(
+ createFollowupMetadata("llvm.loop.vectorize.followup_all", Followup));
+ else
+ Args.append(Followup.begin(), Followup.end());
+ }
HasUserTransforms = true;
return Args;
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 6f87444d3f67..24b6ce7c1c70 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -1193,16 +1193,23 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
ivarAddr = ivarAddr.withElementType(bitcastType);
llvm::LoadInst *load = Builder.CreateLoad(ivarAddr, "load");
load->setAtomic(llvm::AtomicOrdering::Unordered);
+ llvm::Value *ivarVal = load;
+ if (PointerAuthQualifier PAQ = ivar->getType().getPointerAuth()) {
+ CGPointerAuthInfo SrcInfo = EmitPointerAuthInfo(PAQ, ivarAddr);
+ CGPointerAuthInfo TargetInfo =
+ CGM.getPointerAuthInfoForType(getterMethod->getReturnType());
+ ivarVal = emitPointerAuthResign(ivarVal, ivar->getType(), SrcInfo,
+ TargetInfo, /*isKnownNonNull=*/false);
+ }
// Store that value into the return address. Doing this with a
// bitcast is likely to produce some pretty ugly IR, but it's not
// the *most* terrible thing in the world.
llvm::Type *retTy = ConvertType(getterMethod->getReturnType());
uint64_t retTySize = CGM.getDataLayout().getTypeSizeInBits(retTy);
- llvm::Value *ivarVal = load;
if (ivarSize > retTySize) {
bitcastType = llvm::Type::getIntNTy(getLLVMContext(), retTySize);
- ivarVal = Builder.CreateTrunc(load, bitcastType);
+ ivarVal = Builder.CreateTrunc(ivarVal, bitcastType);
}
Builder.CreateStore(ivarVal, ReturnValue.withElementType(bitcastType));
@@ -1214,6 +1221,16 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
case PropertyImplStrategy::GetSetProperty: {
llvm::FunctionCallee getPropertyFn =
CGM.getObjCRuntime().GetPropertyGetFunction();
+
+ if (ivar->getType().getPointerAuth()) {
+ // This currently cannot be hit, but if we ever allow objc pointers
+ // to be signed, this will become possible. Reaching here would require
+ // a copy, weak, etc property backed by an authenticated pointer.
+ CGM.ErrorUnsupported(propImpl,
+ "Obj-C getter requiring pointer authentication");
+ return;
+ }
+
if (!getPropertyFn) {
CGM.ErrorUnsupported(propImpl, "Obj-C getter requiring atomic copy");
return;
@@ -1269,7 +1286,9 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), ivar, 0);
QualType ivarType = ivar->getType();
- switch (getEvaluationKind(ivarType)) {
+ auto EvaluationKind = getEvaluationKind(ivarType);
+ assert(!ivarType.getPointerAuth() || EvaluationKind == TEK_Scalar);
+ switch (EvaluationKind) {
case TEK_Complex: {
ComplexPairTy pair = EmitLoadOfComplex(LV, SourceLocation());
EmitStoreOfComplex(pair, MakeAddrLValue(ReturnValue, ivarType),
@@ -1287,6 +1306,11 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
case TEK_Scalar: {
llvm::Value *value;
if (propType->isReferenceType()) {
+ if (ivarType.getPointerAuth()) {
+ CGM.ErrorUnsupported(propImpl,
+ "Obj-C getter for authenticated reference type");
+ return;
+ }
value = LV.getAddress().emitRawPointer(*this);
} else {
// We want to load and autoreleaseReturnValue ARC __weak ivars.
@@ -1300,7 +1324,19 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
// Otherwise we want to do a simple load, suppressing the
// final autorelease.
} else {
- value = EmitLoadOfLValue(LV, SourceLocation()).getScalarVal();
+ if (PointerAuthQualifier PAQ = ivar->getType().getPointerAuth()) {
+ Address ivarAddr = LV.getAddress();
+ llvm::LoadInst *LoadInst = Builder.CreateLoad(ivarAddr, "load");
+ llvm::Value *Load = LoadInst;
+ auto SrcInfo = EmitPointerAuthInfo(PAQ, ivarAddr);
+ auto TargetInfo =
+ CGM.getPointerAuthInfoForType(getterMethod->getReturnType());
+ Load = emitPointerAuthResign(Load, ivarType, SrcInfo, TargetInfo,
+ /*isKnownNonNull=*/false);
+ value = Load;
+ } else
+ value = EmitLoadOfLValue(LV, SourceLocation()).getScalarVal();
+
AutoreleaseResult = false;
}
@@ -1490,6 +1526,14 @@ CodeGenFunction::generateObjCSetterBody(const ObjCImplementationDecl *classImpl,
llvm::Value *load = Builder.CreateLoad(argAddr);
+ if (PointerAuthQualifier PAQ = ivar->getType().getPointerAuth()) {
+ QualType PropertyType = propImpl->getPropertyDecl()->getType();
+ CGPointerAuthInfo SrcInfo = CGM.getPointerAuthInfoForType(PropertyType);
+ CGPointerAuthInfo TargetInfo = EmitPointerAuthInfo(PAQ, ivarAddr);
+ load = emitPointerAuthResign(load, ivar->getType(), SrcInfo, TargetInfo,
+ /*isKnownNonNull=*/false);
+ }
+
// Perform an atomic store. There are no memory ordering requirements.
llvm::StoreInst *store = Builder.CreateStore(load, ivarAddr);
store->setAtomic(llvm::AtomicOrdering::Unordered);
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index d828702cbb87..8acf8d2ddec0 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1942,8 +1942,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
// struct objc_class *sibling_class
classFields.addNullPointer(PtrTy);
// struct objc_protocol_list *protocols;
- auto RuntimeProtocols = GetRuntimeProtocolList(classDecl->protocol_begin(),
- classDecl->protocol_end());
+ auto RuntimeProtocols =
+ GetRuntimeProtocolList(classDecl->all_referenced_protocol_begin(),
+ classDecl->all_referenced_protocol_end());
SmallVector<llvm::Constant *, 16> Protocols;
for (const auto *I : RuntimeProtocols)
Protocols.push_back(GenerateProtocolRef(I));
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index a52c92cdbc83..8e71a576552d 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1935,7 +1935,9 @@ CGObjCCommonMac::GenerateConstantNSString(const StringLiteral *Literal) {
auto Fields = Builder.beginStruct(NSConstantStringType);
// Class pointer.
- Fields.add(Class);
+ Fields.addSignedPointer(Class,
+ CGM.getCodeGenOpts().PointerAuth.ObjCIsaPointers,
+ GlobalDecl(), QualType());
// String pointer.
llvm::Constant *C =
@@ -4975,10 +4977,7 @@ enum ImageInfoFlags {
eImageInfo_GCOnly = (1 << 2),
eImageInfo_OptimizedByDyld = (1 << 3), // This flag is set by the dyld shared cache.
- // A flag indicating that the module has no instances of a @synthesize of a
- // superclass variable. This flag used to be consumed by the runtime to work
- // around miscompile by gcc.
- eImageInfo_CorrectedSynthesize = (1 << 4), // This flag is no longer set by clang.
+ eImageInfo_SignedClassRO = (1 << 4), // Reused (was _CorrectedSynthesize)
eImageInfo_ImageIsSimulated = (1 << 5),
eImageInfo_ClassProperties = (1 << 6)
};
@@ -5036,6 +5035,17 @@ void CGObjCCommonMac::EmitImageInfo() {
// Indicate whether we are generating class properties.
Mod.addModuleFlag(llvm::Module::Error, "Objective-C Class Properties",
eImageInfo_ClassProperties);
+
+ // Indicate whether we want enforcement of pointer signing for class_ro_t
+ // pointers.
+ if (CGM.getLangOpts().PointerAuthObjcClassROPointers)
+ Mod.addModuleFlag(llvm::Module::Error,
+ "Objective-C Enforce ClassRO Pointer Signing",
+ eImageInfo_SignedClassRO);
+ else
+ Mod.addModuleFlag(llvm::Module::Error,
+ "Objective-C Enforce ClassRO Pointer Signing",
+ llvm::ConstantInt::get(Int8Ty, 0));
}
// struct objc_module {
@@ -6223,11 +6233,19 @@ llvm::GlobalVariable *CGObjCNonFragileABIMac::BuildClassRoTInitializer(
methods.push_back(MD);
}
- values.add(emitMethodList(ID->getObjCRuntimeNameAsString(),
- (flags & NonFragileABI_Class_Meta)
- ? MethodListType::ClassMethods
- : MethodListType::InstanceMethods,
- methods));
+ llvm::Constant *MethListPtr = emitMethodList(
+ ID->getObjCRuntimeNameAsString(),
+ (flags & NonFragileABI_Class_Meta) ? MethodListType::ClassMethods
+ : MethodListType::InstanceMethods,
+ methods);
+
+ const PointerAuthSchema &MethListSchema =
+ CGM.getCodeGenOpts().PointerAuth.ObjCMethodListPointer;
+ if (!MethListPtr->isNullValue())
+ values.addSignedPointer(MethListPtr, MethListSchema, GlobalDecl(),
+ QualType());
+ else
+ values.add(MethListPtr);
const ObjCInterfaceDecl *OID = ID->getClassInterface();
assert(OID && "CGObjCNonFragileABIMac::BuildClassRoTInitializer");
@@ -6275,15 +6293,20 @@ llvm::GlobalVariable *CGObjCNonFragileABIMac::BuildClassObject(
bool HiddenVisibility) {
ConstantInitBuilder builder(CGM);
auto values = builder.beginStruct(ObjCTypes.ClassnfABITy);
- values.add(IsAGV);
- if (SuperClassGV) {
- values.add(SuperClassGV);
- } else {
+ const PointerAuthOptions &PointerAuthOpts = CGM.getCodeGenOpts().PointerAuth;
+ values.addSignedPointer(IsAGV, PointerAuthOpts.ObjCIsaPointers, GlobalDecl(),
+ QualType());
+ if (SuperClassGV)
+ values.addSignedPointer(SuperClassGV, PointerAuthOpts.ObjCSuperPointers,
+ GlobalDecl(), QualType());
+ else
values.addNullPointer(ObjCTypes.ClassnfABIPtrTy);
- }
+
values.add(ObjCEmptyCacheVar);
values.add(ObjCEmptyVtableVar);
- values.add(ClassRoGV);
+
+ values.addSignedPointer(ClassRoGV, PointerAuthOpts.ObjCClassROPointers,
+ GlobalDecl(), QualType());
llvm::GlobalVariable *GV = cast<llvm::GlobalVariable>(
GetClassGlobal(CI, isMetaclass, ForDefinition));
@@ -6543,15 +6566,27 @@ void CGObjCNonFragileABIMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
}
}
- auto instanceMethodList = emitMethodList(
+ llvm::Constant *InstanceMethodList = emitMethodList(
listName, MethodListType::CategoryInstanceMethods, instanceMethods);
- auto classMethodList = emitMethodList(
+ const PointerAuthSchema &MethListSchema =
+ CGM.getCodeGenOpts().PointerAuth.ObjCMethodListPointer;
+ if (!InstanceMethodList->isNullValue())
+ values.addSignedPointer(InstanceMethodList, MethListSchema, GlobalDecl(),
+ QualType());
+ else
+ values.add(InstanceMethodList);
+
+ llvm::Constant *ClassMethodList = emitMethodList(
listName, MethodListType::CategoryClassMethods, classMethods);
- values.add(instanceMethodList);
- values.add(classMethodList);
+ if (!ClassMethodList->isNullValue())
+ values.addSignedPointer(ClassMethodList, MethListSchema, GlobalDecl(),
+ QualType());
+ else
+ values.add(ClassMethodList);
+
// Keep track of whether we have actual metadata to emit.
bool isEmptyCategory =
- instanceMethodList->isNullValue() && classMethodList->isNullValue();
+ InstanceMethodList->isNullValue() && ClassMethodList->isNullValue();
const ObjCCategoryDecl *Category =
Interface->FindCategoryDeclaration(OCD->getIdentifier());
@@ -6629,7 +6664,13 @@ void CGObjCNonFragileABIMac::emitMethodConstant(ConstantArrayBuilder &builder,
} else {
llvm::Function *fn = GetMethodDefinition(MD);
assert(fn && "no definition for method?");
- method.add(fn);
+ if (const PointerAuthSchema &Schema =
+ CGM.getCodeGenOpts().PointerAuth.ObjCMethodListFunctionPointers) {
+ llvm::Constant *Bitcast =
+ llvm::ConstantExpr::getBitCast(fn, ObjCTypes.Int8PtrProgramASTy);
+ method.addSignedPointer(Bitcast, Schema, GlobalDecl(), QualType());
+ } else
+ method.add(fn);
}
method.finishAndAddTo(builder);
@@ -7672,10 +7713,15 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
}
llvm::Value *VTableIdx = llvm::ConstantInt::get(CGM.Int32Ty, 2);
+ llvm::Constant *VTablePtr = llvm::ConstantExpr::getInBoundsGetElementPtr(
+ VTableGV->getValueType(), VTableGV, VTableIdx);
+
ConstantInitBuilder builder(CGM);
auto values = builder.beginStruct(ObjCTypes.EHTypeTy);
- values.add(llvm::ConstantExpr::getInBoundsGetElementPtr(
- VTableGV->getValueType(), VTableGV, VTableIdx));
+ const PointerAuthSchema &TypeInfoSchema =
+ CGM.getCodeGenOpts().PointerAuth.CXXTypeInfoVTablePointer;
+ values.addSignedPointer(VTablePtr, TypeInfoSchema, GlobalDecl(), QualType());
+
values.add(GetClassName(ClassName));
values.add(GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition));
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index a5f2f0efa2c3..ce2dd4d76368 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1092,7 +1092,7 @@ emitCombinerOrInitializer(CodeGenModule &CGM, QualType Ty,
auto *Fn = llvm::Function::Create(FnTy, llvm::GlobalValue::InternalLinkage,
Name, &CGM.getModule());
CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FnInfo);
- if (CGM.getLangOpts().Optimize) {
+ if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
Fn->removeFnAttr(llvm::Attribute::NoInline);
Fn->removeFnAttr(llvm::Attribute::OptimizeNone);
Fn->addFnAttr(llvm::Attribute::AlwaysInline);
@@ -3199,7 +3199,7 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, SourceLocation Loc,
&CGM.getModule());
CGM.SetInternalFunctionAttributes(GlobalDecl(), TaskPrivatesMap,
TaskPrivatesMapFnInfo);
- if (CGM.getLangOpts().Optimize) {
+ if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
TaskPrivatesMap->removeFnAttr(llvm::Attribute::NoInline);
TaskPrivatesMap->removeFnAttr(llvm::Attribute::OptimizeNone);
TaskPrivatesMap->addFnAttr(llvm::Attribute::AlwaysInline);
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index a05b31f971e1..0f2a352886e7 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -144,7 +144,6 @@ add_clang_library(clangCodeGen
Targets/MSP430.cpp
Targets/Mips.cpp
Targets/NVPTX.cpp
- Targets/PNaCl.cpp
Targets/PPC.cpp
Targets/RISCV.cpp
Targets/SPIR.cpp
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 5493cc92bd8b..eb5b6045510d 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -995,7 +995,7 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
std::vector<std::unique_ptr<ASTConsumer>> Consumers(2);
Consumers[0] = std::make_unique<ReducedBMIGenerator>(
CI.getPreprocessor(), CI.getModuleCache(),
- CI.getFrontendOpts().ModuleOutputPath);
+ CI.getFrontendOpts().ModuleOutputPath, CI.getCodeGenOpts());
Consumers[1] = std::move(Result);
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 776a646ceb32..0fda31c8e5fa 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -161,8 +161,7 @@ void CodeGenFunction::CGFPOptionsRAII::ConstructorHelper(FPOptions FPFeatures) {
llvm::RoundingMode NewRoundingBehavior = FPFeatures.getRoundingMode();
CGF.Builder.setDefaultConstrainedRounding(NewRoundingBehavior);
auto NewExceptionBehavior =
- ToConstrainedExceptMD(static_cast<LangOptions::FPExceptionModeKind>(
- FPFeatures.getExceptionMode()));
+ ToConstrainedExceptMD(FPFeatures.getExceptionMode());
CGF.Builder.setDefaultConstrainedExcept(NewExceptionBehavior);
CGF.SetFastMathFlags(FPFeatures);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index c8866f15745c..236cc3d9e890 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -118,9 +118,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
return createM68kTargetCodeGenInfo(CGM);
case llvm::Triple::mips:
case llvm::Triple::mipsel:
- if (Triple.getOS() == llvm::Triple::NaCl)
- return createPNaClTargetCodeGenInfo(CGM);
- else if (Triple.getOS() == llvm::Triple::Win32)
+ if (Triple.getOS() == llvm::Triple::Win32)
return createWindowsMIPSTargetCodeGenInfo(CGM, /*IsOS32=*/true);
return createMIPSTargetCodeGenInfo(CGM, /*IsOS32=*/true);
@@ -6616,7 +6614,9 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
auto Fields = Builder.beginStruct(STy);
// Class pointer.
- Fields.add(cast<llvm::Constant>(CFConstantStringClassRef));
+ Fields.addSignedPointer(cast<llvm::Constant>(CFConstantStringClassRef),
+ getCodeGenOpts().PointerAuth.ObjCIsaPointers,
+ GlobalDecl(), QualType());
// Flags.
if (IsSwiftABI) {
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index f09b3b92c4ea..ee736a281621 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -411,15 +411,18 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
case AMDGPU::BI__builtin_amdgcn_rcp:
case AMDGPU::BI__builtin_amdgcn_rcpf:
case AMDGPU::BI__builtin_amdgcn_rcph:
+ case AMDGPU::BI__builtin_amdgcn_rcp_bf16:
return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_rcp);
case AMDGPU::BI__builtin_amdgcn_sqrt:
case AMDGPU::BI__builtin_amdgcn_sqrtf:
case AMDGPU::BI__builtin_amdgcn_sqrth:
+ case AMDGPU::BI__builtin_amdgcn_sqrt_bf16:
return emitBuiltinWithOneOverloadedType<1>(*this, E,
Intrinsic::amdgcn_sqrt);
case AMDGPU::BI__builtin_amdgcn_rsq:
case AMDGPU::BI__builtin_amdgcn_rsqf:
case AMDGPU::BI__builtin_amdgcn_rsqh:
+ case AMDGPU::BI__builtin_amdgcn_rsq_bf16:
return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_rsq);
case AMDGPU::BI__builtin_amdgcn_rsq_clamp:
case AMDGPU::BI__builtin_amdgcn_rsq_clampf:
@@ -427,15 +430,19 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
Intrinsic::amdgcn_rsq_clamp);
case AMDGPU::BI__builtin_amdgcn_sinf:
case AMDGPU::BI__builtin_amdgcn_sinh:
+ case AMDGPU::BI__builtin_amdgcn_sin_bf16:
return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_sin);
case AMDGPU::BI__builtin_amdgcn_cosf:
case AMDGPU::BI__builtin_amdgcn_cosh:
+ case AMDGPU::BI__builtin_amdgcn_cos_bf16:
return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_cos);
case AMDGPU::BI__builtin_amdgcn_dispatch_ptr:
return EmitAMDGPUDispatchPtr(*this, E);
case AMDGPU::BI__builtin_amdgcn_logf:
+ case AMDGPU::BI__builtin_amdgcn_log_bf16:
return emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::amdgcn_log);
case AMDGPU::BI__builtin_amdgcn_exp2f:
+ case AMDGPU::BI__builtin_amdgcn_exp2_bf16:
return emitBuiltinWithOneOverloadedType<1>(*this, E,
Intrinsic::amdgcn_exp2);
case AMDGPU::BI__builtin_amdgcn_log_clampf:
@@ -497,6 +504,11 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, { ResultType });
return Builder.CreateCall(F, { Src });
}
+ case AMDGPU::BI__builtin_amdgcn_tanhf:
+ case AMDGPU::BI__builtin_amdgcn_tanhh:
+ case AMDGPU::BI__builtin_amdgcn_tanh_bf16:
+ return emitBuiltinWithOneOverloadedType<1>(*this, E,
+ Intrinsic::amdgcn_tanh);
case AMDGPU::BI__builtin_amdgcn_uicmp:
case AMDGPU::BI__builtin_amdgcn_uicmpl:
case AMDGPU::BI__builtin_amdgcn_sicmp:
@@ -818,7 +830,46 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
- case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64: {
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64:
+ // GFX1250 WMMA builtins
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x4_f32:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x32_bf16:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x32_f16:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x32_f16:
+ case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x32_bf16:
+ case AMDGPU::BI__builtin_amdgcn_wmma_bf16f32_16x16x32_bf16:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_fp8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_fp8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_bf8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_bf8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_fp8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_fp8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_bf8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_bf8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_fp8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_fp8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_bf8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_bf8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_fp8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_fp8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_bf8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_bf8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x64_iu8:
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_32x16x128_f4:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x64_f16:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x64_bf16:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x64_f16:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x64_bf16:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_bf16f32_16x16x64_bf16:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_fp8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_fp8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_bf8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_bf8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_fp8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_fp8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_bf8_fp8:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_bf8_bf8:
+ case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x128_iu8: {
// These operations perform a matrix multiplication and accumulation of
// the form:
@@ -833,6 +884,8 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
// "false".
bool AppendFalseForOpselArg = false;
unsigned BuiltinWMMAOp;
+ // Need return type when D and C are of different types.
+ bool NeedReturnType = false;
switch (BuiltinID) {
case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32:
@@ -971,6 +1024,160 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
ArgsForMatchingMatrixTypes = {2, 0, 1, 3}; // CD, A, B, Index
BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_bf8;
break;
+ // GFX1250 WMMA builtins
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x4_f32:
+ ArgsForMatchingMatrixTypes = {5, 1};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x4_f32;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x32_bf16:
+ ArgsForMatchingMatrixTypes = {5, 1};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x32_bf16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x32_f16:
+ ArgsForMatchingMatrixTypes = {5, 1};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x32_f16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x32_f16:
+ ArgsForMatchingMatrixTypes = {5, 1};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x32_f16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x32_bf16:
+ ArgsForMatchingMatrixTypes = {5, 1};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_bf16_16x16x32_bf16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_bf16f32_16x16x32_bf16:
+ NeedReturnType = true;
+ ArgsForMatchingMatrixTypes = {1, 5};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_bf16f32_16x16x32_bf16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_fp8_fp8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x64_fp8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_fp8_bf8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x64_fp8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_bf8_fp8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x64_bf8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_bf8_bf8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x64_bf8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_fp8_fp8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x64_fp8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_fp8_bf8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x64_fp8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_bf8_fp8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x64_bf8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_bf8_bf8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x64_bf8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_fp8_fp8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x128_fp8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_fp8_bf8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x128_fp8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_bf8_fp8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x128_bf8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_bf8_bf8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x128_bf8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_fp8_fp8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x128_fp8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_fp8_bf8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x128_fp8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_bf8_fp8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x128_bf8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_bf8_bf8:
+ ArgsForMatchingMatrixTypes = {3, 0};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x128_bf8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x64_iu8:
+ ArgsForMatchingMatrixTypes = {4, 1};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x64_iu8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_wmma_f32_32x16x128_f4:
+ ArgsForMatchingMatrixTypes = {3, 0, 1};
+ BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_32x16x128_f4;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x64_f16:
+ ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x64_f16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x64_bf16:
+ ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x64_bf16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x64_f16:
+ ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f16_16x16x64_f16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x64_bf16:
+ ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_bf16_16x16x64_bf16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_bf16f32_16x16x64_bf16:
+ ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_bf16f32_16x16x64_bf16;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_fp8_fp8:
+ ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x128_fp8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_fp8_bf8:
+ ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x128_fp8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_bf8_fp8:
+ ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x128_bf8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_bf8_bf8:
+ ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x128_bf8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_fp8_fp8:
+ ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f16_16x16x128_fp8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_fp8_bf8:
+ ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f16_16x16x128_fp8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_bf8_fp8:
+ ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f16_16x16x128_bf8_fp8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_bf8_bf8:
+ ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f16_16x16x128_bf8_bf8;
+ break;
+ case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x128_iu8:
+ ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
+ BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8;
+ break;
}
SmallVector<Value *, 6> Args;
@@ -980,6 +1187,8 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
Args.push_back(Builder.getFalse());
SmallVector<llvm::Type *, 6> ArgTypes;
+ if (NeedReturnType)
+ ArgTypes.push_back(ConvertType(E->getType()));
for (auto ArgIdx : ArgsForMatchingMatrixTypes)
ArgTypes.push_back(Args[ArgIdx]->getType());
diff --git a/clang/lib/CodeGen/TargetBuiltins/PPC.cpp b/clang/lib/CodeGen/TargetBuiltins/PPC.cpp
index f9890285f0aa..270e9fc976f2 100644
--- a/clang/lib/CodeGen/TargetBuiltins/PPC.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/PPC.cpp
@@ -1151,6 +1151,11 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
Value *Acc = Builder.CreateLoad(Addr);
CallOps.push_back(Acc);
}
+ if (BuiltinID == PPC::BI__builtin_mma_dmmr ||
+ BuiltinID == PPC::BI__builtin_mma_dmxor) {
+ Address Addr = EmitPointerWithAlignment(E->getArg(1));
+ Ops[1] = Builder.CreateLoad(Addr);
+ }
for (unsigned i=1; i<Ops.size(); i++)
CallOps.push_back(Ops[i]);
llvm::Function *F = CGM.getIntrinsic(ID);
diff --git a/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp b/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
index 89e3f6f203df..b08a0588c5ac 100644
--- a/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
@@ -413,6 +413,12 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
ID = Intrinsic::riscv_cv_alu_subuRN;
break;
+ // XAndesBFHCvt
+ case RISCV::BI__builtin_riscv_nds_fcvt_s_bf16:
+ return Builder.CreateFPExt(Ops[0], FloatTy);
+ case RISCV::BI__builtin_riscv_nds_fcvt_bf16_s:
+ return Builder.CreateFPTrunc(Ops[0], BFloatTy);
+
// Vector builtins are handled from here.
#include "clang/Basic/riscv_vector_builtin_cg.inc"
diff --git a/clang/lib/CodeGen/TargetBuiltins/SPIR.cpp b/clang/lib/CodeGen/TargetBuiltins/SPIR.cpp
index 16243951c7be..243aad8bf708 100644
--- a/clang/lib/CodeGen/TargetBuiltins/SPIR.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/SPIR.cpp
@@ -58,6 +58,18 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned BuiltinID,
/*ReturnType=*/I->getType(), Intrinsic::spv_reflect,
ArrayRef<Value *>{I, N}, nullptr, "spv.reflect");
}
+ case SPIRV::BI__builtin_spirv_refract: {
+ Value *I = EmitScalarExpr(E->getArg(0));
+ Value *N = EmitScalarExpr(E->getArg(1));
+ Value *eta = EmitScalarExpr(E->getArg(2));
+ assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+ E->getArg(1)->getType()->hasFloatingRepresentation() &&
+ E->getArg(2)->getType()->isFloatingType() &&
+ "refract operands must have a float representation");
+ return Builder.CreateIntrinsic(
+ /*ReturnType=*/I->getType(), Intrinsic::spv_refract,
+ ArrayRef<Value *>{I, N, eta}, nullptr, "spv.refract");
+ }
case SPIRV::BI__builtin_spirv_smoothstep: {
Value *Min = EmitScalarExpr(E->getArg(0));
Value *Max = EmitScalarExpr(E->getArg(1));
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index b4057d369f98..d0edae129509 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -545,9 +545,6 @@ createMSP430TargetCodeGenInfo(CodeGenModule &CGM);
std::unique_ptr<TargetCodeGenInfo>
createNVPTXTargetCodeGenInfo(CodeGenModule &CGM);
-std::unique_ptr<TargetCodeGenInfo>
-createPNaClTargetCodeGenInfo(CodeGenModule &CGM);
-
enum class PPC64_SVR4_ABIKind {
ELFv1 = 0,
ELFv2,
diff --git a/clang/lib/CodeGen/Targets/PNaCl.cpp b/clang/lib/CodeGen/Targets/PNaCl.cpp
deleted file mode 100644
index 358010785850..000000000000
--- a/clang/lib/CodeGen/Targets/PNaCl.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-//===- PNaCl.cpp ----------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "ABIInfoImpl.h"
-#include "TargetInfo.h"
-
-using namespace clang;
-using namespace clang::CodeGen;
-
-//===----------------------------------------------------------------------===//
-// le32/PNaCl bitcode ABI Implementation
-//
-// This is a simplified version of the x86_32 ABI. Arguments and return values
-// are always passed on the stack.
-//===----------------------------------------------------------------------===//
-
-class PNaClABIInfo : public ABIInfo {
- public:
- PNaClABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {}
-
- ABIArgInfo classifyReturnType(QualType RetTy) const;
- ABIArgInfo classifyArgumentType(QualType RetTy) const;
-
- void computeInfo(CGFunctionInfo &FI) const override;
- RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
- AggValueSlot Slot) const override;
-};
-
-class PNaClTargetCodeGenInfo : public TargetCodeGenInfo {
- public:
- PNaClTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
- : TargetCodeGenInfo(std::make_unique<PNaClABIInfo>(CGT)) {}
-};
-
-void PNaClABIInfo::computeInfo(CGFunctionInfo &FI) const {
- if (!getCXXABI().classifyReturnType(FI))
- FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
-
- for (auto &I : FI.arguments())
- I.info = classifyArgumentType(I.type);
-}
-
-RValue PNaClABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
- QualType Ty, AggValueSlot Slot) const {
- // The PNaCL ABI is a bit odd, in that varargs don't use normal
- // function classification. Structs get passed directly for varargs
- // functions, through a rewriting transform in
- // pnacl-llvm/lib/Transforms/NaCl/ExpandVarArgs.cpp, which allows
- // this target to actually support a va_arg instructions with an
- // aggregate type, unlike other targets.
- return CGF.EmitLoadOfAnyValue(
- CGF.MakeAddrLValue(
- EmitVAArgInstr(CGF, VAListAddr, Ty, ABIArgInfo::getDirect()), Ty),
- Slot);
-}
-
-/// Classify argument of given type \p Ty.
-ABIArgInfo PNaClABIInfo::classifyArgumentType(QualType Ty) const {
- if (isAggregateTypeForABI(Ty)) {
- if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
- return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
- RAA == CGCXXABI::RAA_DirectInMemory);
- return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace());
- } else if (const EnumType *EnumTy = Ty->getAs<EnumType>()) {
- // Treat an enum type as its underlying type.
- Ty = EnumTy->getDecl()->getIntegerType();
- } else if (Ty->isFloatingType()) {
- // Floating-point types don't go inreg.
- return ABIArgInfo::getDirect();
- } else if (const auto *EIT = Ty->getAs<BitIntType>()) {
- // Treat bit-precise integers as integers if <= 64, otherwise pass
- // indirectly.
- if (EIT->getNumBits() > 64)
- return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace());
- return ABIArgInfo::getDirect();
- }
-
- return (isPromotableIntegerTypeForABI(Ty) ? ABIArgInfo::getExtend(Ty)
- : ABIArgInfo::getDirect());
-}
-
-ABIArgInfo PNaClABIInfo::classifyReturnType(QualType RetTy) const {
- if (RetTy->isVoidType())
- return ABIArgInfo::getIgnore();
-
- // In the PNaCl ABI we always return records/structures on the stack.
- if (isAggregateTypeForABI(RetTy))
- return getNaturalAlignIndirect(RetTy, getDataLayout().getAllocaAddrSpace());
-
- // Treat bit-precise integers as integers if <= 64, otherwise pass indirectly.
- if (const auto *EIT = RetTy->getAs<BitIntType>()) {
- if (EIT->getNumBits() > 64)
- return getNaturalAlignIndirect(RetTy,
- getDataLayout().getAllocaAddrSpace());
- return ABIArgInfo::getDirect();
- }
-
- // Treat an enum type as its underlying type.
- if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
- RetTy = EnumTy->getDecl()->getIntegerType();
-
- return (isPromotableIntegerTypeForABI(RetTy) ? ABIArgInfo::getExtend(RetTy)
- : ABIArgInfo::getDirect());
-}
-
-std::unique_ptr<TargetCodeGenInfo>
-CodeGen::createPNaClTargetCodeGenInfo(CodeGenModule &CGM) {
- return std::make_unique<PNaClTargetCodeGenInfo>(CGM.getTypes());
-}
diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index 0f59caac2323..abb91486e7ee 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2470,13 +2470,12 @@ GetSSETypeAtOffset(llvm::Type *IRType, unsigned IROffset,
return llvm::Type::getDoubleTy(getVMContext());
}
-
/// GetINTEGERTypeAtOffset - The ABI specifies that a value should be passed in
-/// an 8-byte GPR. This means that we either have a scalar or we are talking
-/// about the high or low part of an up-to-16-byte struct. This routine picks
-/// the best LLVM IR type to represent this, which may be i64 or may be anything
-/// else that the backend will pass in a GPR that works better (e.g. i8, %foo*,
-/// etc).
+/// one or more 8-byte GPRs. This means that we either have a scalar or we are
+/// talking about the high and/or low part of an up-to-16-byte struct. This
+/// routine picks the best LLVM IR type to represent this, which may be i64 or
+/// may be anything else that the backend will pass in GPRs that works better
+/// (e.g. i8, %foo*, etc).
///
/// PrefType is an LLVM IR type that corresponds to (part of) the IR type for
/// the source type. IROffset is an offset in bytes into the LLVM IR type that
@@ -2534,6 +2533,13 @@ GetINTEGERTypeAtOffset(llvm::Type *IRType, unsigned IROffset,
SourceOffset);
}
+ // if we have a 128-bit integer, we can pass it safely using an i128
+ // so we return that
+ if (IRType->isIntegerTy(128)) {
+ assert(IROffset == 0);
+ return IRType;
+ }
+
// Okay, we don't have any better idea of what to pass, so we pass this in an
// integer register that isn't too big to fit the rest of the struct.
unsigned TySizeInBytes =
@@ -2572,8 +2578,7 @@ GetX86_64ByValArgumentPair(llvm::Type *Lo, llvm::Type *Hi,
if (HiStart != 8) {
// There are usually two sorts of types the ABI generation code can produce
// for the low part of a pair that aren't 8 bytes in size: half, float or
- // i8/i16/i32. This can also include pointers when they are 32-bit (X32 and
- // NaCl).
+ // i8/i16/i32. This can also include pointers when they are 32-bit (X32).
// Promote these to a larger type.
if (Lo->isHalfTy() || Lo->isFloatTy())
Lo = llvm::Type::getDoubleTy(Lo->getContext());
@@ -2592,8 +2597,7 @@ GetX86_64ByValArgumentPair(llvm::Type *Lo, llvm::Type *Hi,
return Result;
}
-ABIArgInfo X86_64ABIInfo::
-classifyReturnType(QualType RetTy) const {
+ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy) const {
// AMD64-ABI 3.2.3p4: Rule 1. Classify the return type with the
// classification algorithm.
X86_64ABIInfo::Class Lo, Hi;
@@ -2639,6 +2643,12 @@ classifyReturnType(QualType RetTy) const {
isPromotableIntegerTypeForABI(RetTy))
return ABIArgInfo::getExtend(RetTy);
}
+
+ if (ResType->isIntegerTy(128)) {
+ // i128 are passed directly
+ assert(Hi == Integer);
+ return ABIArgInfo::getDirect(ResType);
+ }
break;
// AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next
@@ -2784,6 +2794,11 @@ X86_64ABIInfo::classifyArgumentType(QualType Ty, unsigned freeIntRegs,
return ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty));
}
+ if (ResType->isIntegerTy(128)) {
+ assert(Hi == Integer);
+ ++neededInt;
+ return ABIArgInfo::getDirect(ResType);
+ }
break;
// AMD64-ABI 3.2.3p3: Rule 3. If the class is SSE, the next