Skip to content

Commit 45be8a8

Browse files
authored
Merge branch 'main' into inbelic/rs-resource-range-intervals
2 parents ab4bbe0 + 2488f26 commit 45be8a8

File tree

223 files changed

+5562
-3019
lines changed

Some content is hidden

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

223 files changed

+5562
-3019
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,10 @@ CODEGENOPT(StaticClosure, 1, 0)
483483
/// Assume that UAVs/SRVs may alias
484484
CODEGENOPT(ResMayAlias, 1, 0)
485485

486-
/// Enables unwind v2 (epilog) information for x64 Windows.
487-
CODEGENOPT(WinX64EHUnwindV2, 1, 0)
486+
/// Controls how unwind v2 (epilog) information should be generated for x64
487+
/// Windows.
488+
ENUM_CODEGENOPT(WinX64EHUnwindV2, llvm::WinX64EHUnwindV2Mode,
489+
2, llvm::WinX64EHUnwindV2Mode::Disabled)
488490

489491
/// FIXME: Make DebugOptions its own top-level .def file.
490492
#include "DebugOptions.def"

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ struct MissingFeatures {
236236
static bool runCleanupsScope() { return false; }
237237
static bool lowerAggregateLoadStore() { return false; }
238238
static bool dataLayoutTypeAllocSize() { return false; }
239+
static bool asmLabelAttr() { return false; }
239240

240241
// Missing types
241242
static bool dataMemberType() { return false; }

clang/include/clang/Driver/Options.td

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,11 +2167,14 @@ defm assume_nothrow_exception_dtor: BoolFOption<"assume-nothrow-exception-dtor",
21672167
LangOpts<"AssumeNothrowExceptionDtor">, DefaultFalse,
21682168
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Assume that exception objects' destructors are non-throwing">,
21692169
NegFlag<SetFalse>>;
2170-
defm winx64_eh_unwindv2 : BoolFOption<"winx64-eh-unwindv2",
2171-
CodeGenOpts<"WinX64EHUnwindV2">, DefaultFalse,
2172-
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
2173-
NegFlag<SetFalse, [], [ClangOption], "Disable">,
2174-
BothFlags<[], [ClangOption], " unwind v2 (epilog) information for x64 Windows">>;
2170+
def winx64_eh_unwindv2
2171+
: Joined<["-"], "fwinx64-eh-unwindv2=">, Group<f_Group>,
2172+
Visibility<[ClangOption, CC1Option]>,
2173+
HelpText<"Generate unwind v2 (epilog) information for x64 Windows">,
2174+
Values<"disabled,best-effort,required">,
2175+
NormalizedValues<["Disabled", "BestEffort", "Required"]>,
2176+
NormalizedValuesScope<"llvm::WinX64EHUnwindV2Mode">,
2177+
MarshallingInfoEnum<CodeGenOpts<"WinX64EHUnwindV2">, "Disabled">;
21752178
def fexcess_precision_EQ : Joined<["-"], "fexcess-precision=">, Group<f_Group>,
21762179
Visibility<[ClangOption, CLOption]>,
21772180
HelpText<"Allows control over excess precision on targets where native "
@@ -8972,7 +8975,9 @@ def _SLASH_volatile_Group : OptionGroup<"</volatile group>">,
89728975
Group<cl_compile_Group>;
89738976

89748977
def _SLASH_d2epilogunwind : CLFlag<"d2epilogunwind">,
8975-
HelpText<"Enable unwind v2 (epilog) information for x64 Windows">;
8978+
HelpText<"Best effort generate unwind v2 (epilog) information for x64 Windows">;
8979+
def _SLASH_d2epilogunwindrequirev2 : CLFlag<"d2epilogunwindrequirev2">,
8980+
HelpText<"Require generation of unwind v2 (epilog) information for x64 Windows">;
89768981
def _SLASH_EH : CLJoined<"EH">, HelpText<"Set exception handling model">;
89778982
def _SLASH_EP : CLFlag<"EP">,
89788983
HelpText<"Disable linemarker output and preprocess to stdout">;

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@
2020
#include "mlir/Support/LLVM.h"
2121
#include "clang/AST/Expr.h"
2222
#include "clang/AST/GlobalDecl.h"
23+
#include "clang/CIR/MissingFeatures.h"
2324
#include "llvm/Support/ErrorHandling.h"
2425

2526
using namespace clang;
2627
using namespace clang::CIRGen;
28+
using namespace llvm;
29+
30+
static RValue emitLibraryCall(CIRGenFunction &cgf, const FunctionDecl *fd,
31+
const CallExpr *e, mlir::Operation *calleeValue) {
32+
CIRGenCallee callee = CIRGenCallee::forDirect(calleeValue, GlobalDecl(fd));
33+
return cgf.emitCall(e->getCallee()->getType(), callee, e, ReturnValueSlot());
34+
}
2735

2836
RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
2937
const CallExpr *e,
@@ -49,7 +57,34 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
4957
}
5058
}
5159

52-
mlir::Location loc = getLoc(e->getExprLoc());
53-
cgm.errorNYI(loc, "non constant foldable builtin calls");
60+
const FunctionDecl *fd = gd.getDecl()->getAsFunction();
61+
62+
// If this is an alias for a lib function (e.g. __builtin_sin), emit
63+
// the call using the normal call path, but using the unmangled
64+
// version of the function name.
65+
if (getContext().BuiltinInfo.isLibFunction(builtinID))
66+
return emitLibraryCall(*this, fd, e,
67+
cgm.getBuiltinLibFunction(fd, builtinID));
68+
69+
cgm.errorNYI(e->getSourceRange(), "unimplemented builtin call");
5470
return getUndefRValue(e->getType());
5571
}
72+
73+
/// Given a builtin id for a function like "__builtin_fabsf", return a Function*
74+
/// for "fabsf".
75+
cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *fd,
76+
unsigned builtinID) {
77+
assert(astContext.BuiltinInfo.isLibFunction(builtinID));
78+
79+
// Get the name, skip over the __builtin_ prefix (if necessary). We may have
80+
// to build this up so provide a small stack buffer to handle the vast
81+
// majority of names.
82+
llvm::SmallString<64> name;
83+
84+
assert(!cir::MissingFeatures::asmLabelAttr());
85+
name = astContext.BuiltinInfo.getName(builtinID).substr(10);
86+
87+
GlobalDecl d(fd);
88+
mlir::Type type = convertType(fd->getType());
89+
return getOrCreateCIRFunction(name, type, d, /*forVTable=*/false);
90+
}

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ class CIRGenModule : public CIRGenTypeCache {
301301
cir::FuncType funcType,
302302
const clang::FunctionDecl *funcDecl);
303303

304+
/// Given a builtin id for a function like "__builtin_fabsf", return a
305+
/// Function* for "fabsf".
306+
cir::FuncOp getBuiltinLibFunction(const FunctionDecl *fd, unsigned builtinID);
307+
304308
mlir::IntegerAttr getSize(CharUnits size) {
305309
return builder.getSizeFromCharUnits(size);
306310
}

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,6 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
471471
}
472472
}
473473

474-
void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
475-
llvm::Function *Fn) {
476-
if (FD->isInExportDeclContext()) {
477-
const StringRef ExportAttrKindStr = "hlsl.export";
478-
Fn->addFnAttr(ExportAttrKindStr);
479-
}
480-
}
481-
482474
static void gatherFunctions(SmallVectorImpl<Function *> &Fns, llvm::Module &M,
483475
bool CtorOrDtor) {
484476
const auto *GV =

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
12671267
if (FD->hasAttr<HLSLShaderAttr>()) {
12681268
CGM.getHLSLRuntime().emitEntryFunction(FD, Fn);
12691269
}
1270-
CGM.getHLSLRuntime().setHLSLFunctionAttributes(FD, Fn);
12711270
}
12721271

12731272
EmitFunctionProlog(*CurFnInfo, CurFn, Args);

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,10 @@ void CodeGenModule::Release() {
13191319
1);
13201320

13211321
// Enable unwind v2 (epilog).
1322-
if (CodeGenOpts.WinX64EHUnwindV2)
1323-
getModule().addModuleFlag(llvm::Module::Warning, "winx64-eh-unwindv2", 1);
1322+
if (CodeGenOpts.getWinX64EHUnwindV2() != llvm::WinX64EHUnwindV2Mode::Disabled)
1323+
getModule().addModuleFlag(
1324+
llvm::Module::Warning, "winx64-eh-unwindv2",
1325+
static_cast<unsigned>(CodeGenOpts.getWinX64EHUnwindV2()));
13241326

13251327
// Indicate whether this Module was compiled with -fopenmp
13261328
if (getLangOpts().OpenMP && !getLangOpts().OpenMPSimd)
@@ -1666,6 +1668,11 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
16661668
return;
16671669
}
16681670

1671+
if (Context.getLangOpts().HLSL && !D->isInExportDeclContext()) {
1672+
GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
1673+
return;
1674+
}
1675+
16691676
if (GV->hasDLLExportStorageClass() || GV->hasDLLImportStorageClass()) {
16701677
// Reject incompatible dlllstorage and visibility annotations.
16711678
if (!LV.isVisibilityExplicit())

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7360,8 +7360,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
73607360
}
73617361

73627362
// Unwind v2 (epilog) information for x64 Windows.
7363-
Args.addOptInFlag(CmdArgs, options::OPT_fwinx64_eh_unwindv2,
7364-
options::OPT_fno_winx64_eh_unwindv2);
7363+
Args.AddLastArg(CmdArgs, options::OPT_winx64_eh_unwindv2);
73657364

73667365
// C++ "sane" operator new.
73677366
Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
@@ -8418,8 +8417,10 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
84188417
CmdArgs.push_back("-fms-kernel");
84198418

84208419
// Unwind v2 (epilog) information for x64 Windows.
8421-
if (Args.hasArg(options::OPT__SLASH_d2epilogunwind))
8422-
CmdArgs.push_back("-fwinx64-eh-unwindv2");
8420+
if (Args.hasArg(options::OPT__SLASH_d2epilogunwindrequirev2))
8421+
CmdArgs.push_back("-fwinx64-eh-unwindv2=required");
8422+
else if (Args.hasArg(options::OPT__SLASH_d2epilogunwind))
8423+
CmdArgs.push_back("-fwinx64-eh-unwindv2=best-effort");
84238424

84248425
for (const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
84258426
StringRef GuardArgs = A->getValue();

clang/lib/Parse/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(LLVM_LINK_COMPONENTS
2+
FrontendHLSL
23
FrontendOpenMP
34
MC
45
MCParser

0 commit comments

Comments
 (0)