Skip to content

Commit f73f237

Browse files
committed
Merge branch 'main' into fix_layout_assign
2 parents 5705d74 + 99e53cb commit f73f237

File tree

288 files changed

+7410
-4044
lines changed

Some content is hidden

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

288 files changed

+7410
-4044
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/Dialect/IR/CIROps.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,8 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, SameTypeOperands]> {
21552155
`(` $kind `,` $lhs `,` $rhs `)` `:` qualified(type($lhs)) `,`
21562156
qualified(type($result)) attr-dict
21572157
}];
2158+
2159+
let hasFolder = 1;
21582160
}
21592161

21602162
//===----------------------------------------------------------------------===//

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/CIRGenExprComplex.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
2121
bool isInit);
2222

2323
mlir::Value VisitInitListExpr(InitListExpr *e);
24+
25+
mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
2426
};
2527

2628
} // namespace
@@ -66,6 +68,34 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) {
6668
return builder.create<cir::ConstantOp>(loc, complexAttr);
6769
}
6870

71+
mlir::Value
72+
ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *il) {
73+
auto ty = mlir::cast<cir::ComplexType>(cgf.convertType(il->getType()));
74+
mlir::Type elementTy = ty.getElementType();
75+
mlir::Location loc = cgf.getLoc(il->getExprLoc());
76+
77+
mlir::TypedAttr realValueAttr;
78+
mlir::TypedAttr imagValueAttr;
79+
80+
if (mlir::isa<cir::IntType>(elementTy)) {
81+
llvm::APInt imagValue = cast<IntegerLiteral>(il->getSubExpr())->getValue();
82+
realValueAttr = cir::IntAttr::get(elementTy, 0);
83+
imagValueAttr = cir::IntAttr::get(elementTy, imagValue);
84+
} else {
85+
assert(mlir::isa<cir::CIRFPTypeInterface>(elementTy) &&
86+
"Expected complex element type to be floating-point");
87+
88+
llvm::APFloat imagValue =
89+
cast<FloatingLiteral>(il->getSubExpr())->getValue();
90+
realValueAttr = cir::FPAttr::get(
91+
elementTy, llvm::APFloat::getZero(imagValue.getSemantics()));
92+
imagValueAttr = cir::FPAttr::get(elementTy, imagValue);
93+
}
94+
95+
auto complexAttr = cir::ConstComplexAttr::get(realValueAttr, imagValueAttr);
96+
return builder.create<cir::ConstantOp>(loc, complexAttr);
97+
}
98+
6999
mlir::Value CIRGenFunction::emitComplexExpr(const Expr *e) {
70100
assert(e && getComplexType(e->getType()) &&
71101
"Invalid complex expression to emit");

0 commit comments

Comments
 (0)