Skip to content

Commit ab1fe1e

Browse files
committed
wip -- emitFunctionProlog
ghstack-source-id: 71a88c0 Pull-Request: #2013
1 parent b3a37c9 commit ab1fe1e

File tree

5 files changed

+248
-45
lines changed

5 files changed

+248
-45
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,17 @@ struct MissingFeatures {
476476
static bool mustProgress() { return false; }
477477

478478
static bool skipTempCopy() { return false; }
479+
480+
static bool addressSpaceInGlobalVar() { return false; }
481+
482+
static bool useARMGuardVarABI() { return false; }
483+
484+
// PtrAuth added a RawAddress type subclassing from Address.
485+
static bool rawAddress() { return false; }
486+
487+
// LLVM has values that can be named (e.g. %x) and MLIR doens't, add this when
488+
// we have a solution
489+
static bool namedValues() { return false; }
479490
};
480491

481492
} // namespace cir

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919
#include "TargetInfo.h"
2020

2121
#include "clang/AST/Attr.h"
22+
#include "clang/AST/Attrs.inc"
23+
#include "clang/AST/Decl.h"
24+
#include "clang/AST/DeclBase.h"
2225
#include "clang/AST/DeclCXX.h"
2326
#include "clang/AST/GlobalDecl.h"
27+
#include "clang/Basic/Specifiers.h"
28+
#include "clang/CIR/ABIArgInfo.h"
2429
#include "clang/CIR/Dialect/IR/CIRDialect.h"
2530
#include "clang/CIR/Dialect/IR/CIRTypes.h"
2631
#include "clang/CIR/FnInfoOpts.h"
@@ -943,6 +948,12 @@ static CanQual<FunctionProtoType> GetFormalType(const CXXMethodDecl *MD) {
943948
.getAs<FunctionProtoType>();
944949
}
945950

951+
void CIRGenFunction::emitFunctionProlog(const CIRGenFunctionInfo &functionInfo,
952+
cir::FuncOp fn,
953+
const FunctionArgList &args) {
954+
return;
955+
}
956+
946957
/// TODO(cir): this should be shared with LLVM codegen
947958
static void addExtParameterInfosForCall(
948959
llvm::SmallVectorImpl<FunctionProtoType::ExtParameterInfo> &paramInfos,
@@ -1319,6 +1330,7 @@ CIRGenTypes::arrangeUnprototypedMustTailThunk(const CXXMethodDecl *md) {
13191330
return arrangeCIRFunctionInfo(astContext.VoidTy, cir::FnInfoOpts::None,
13201331
ArgTys, FTP->getExtInfo(), {}, RequiredArgs(1));
13211332
}
1333+
13221334
/// Figure out the rules for calling a function with the given formal type using
13231335
/// the given arguments. The arguments are necessary because the function might
13241336
/// be unprototyped, in which case it's target-dependent in crazy ways.
@@ -1483,3 +1495,35 @@ void CIRGenModule::getDefaultFunctionAttributes(
14831495
// TODO(cir): addMergableDefaultFunctionAttributes(codeGenOpts, funcAttrs);
14841496
}
14851497
}
1498+
1499+
void CIRGenFunction::createCoercedStore(mlir::Value src, Address dst,
1500+
llvm::TypeSize dstSize,
1501+
bool dstIsVolatile) {
1502+
if (!dstSize)
1503+
return;
1504+
1505+
mlir::Type srcTy = src.getType();
1506+
llvm::TypeSize srcSize = CGM.getDataLayout().getTypeAllocSize(srcTy);
1507+
1508+
// GEP into structs to try to make typesm match.
1509+
// FIXME: This isn't really that useful with opaque types, but it impacts a
1510+
// lot of regressiont ests.
1511+
if (srcTy != dst.getElementType()) {
1512+
llvm_unreachable("NYI");
1513+
}
1514+
1515+
if (srcSize.isScalable() || srcSize <= dstSize) {
1516+
if (isa<cir::IntType>(srcTy) &&
1517+
isa<cir::PointerType>(dst.getElementType()) &&
1518+
srcSize == CGM.getDataLayout().getTypeAllocSize(dst.getElementType())) {
1519+
llvm_unreachable("NYI");
1520+
} else {
1521+
getBuilder().createStore(src.getLoc(), src, dst.withElementType(getBuilder(), srcTy),
1522+
dstIsVolatile);
1523+
}
1524+
} else if (isa<cir::IntType>(srcTy)) {
1525+
llvm_unreachable("NYI");
1526+
} else {
1527+
llvm_unreachable("NYI");
1528+
}
1529+
}

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,3 +1289,84 @@ void CIRGenFunction::pushDestroyAndDeferDeactivation(
12891289
pushDestroy(cleanupKind, addr, type, destroyer, useEHCleanupForArray);
12901290
DeferredDeactivationCleanupStack.push_back({EHStack.stable_begin(), flag});
12911291
}
1292+
1293+
/// Emit an alloca (or GlobalValue depending on target)
1294+
/// for the specified parameter and set up LocalDeclMap.
1295+
void CIRGenFunction::emitParmDecl(const VarDecl &varDecl, ParamValue arg,
1296+
unsigned argNo) {
1297+
bool noDebugInfo = false;
1298+
// FIXME: Why isn't ImplicitParamDecl a ParmVarDecl?
1299+
assert((isa<ParmVarDecl>(varDecl) || isa<ImplicitParamDecl>(varDecl)) &&
1300+
"Invalid argument to buildParmDecl");
1301+
1302+
// Set the name of the parameter's initial value to make IR easier to read.
1303+
// Don't modify the names of globals.
1304+
if (cir::MissingFeatures::namedValues())
1305+
llvm_unreachable("NYI");
1306+
1307+
QualType ty = varDecl.getType();
1308+
1309+
// Use better CIR generation for certain implicit parameters.
1310+
if ([[maybe_unused]] auto const *ipd =
1311+
dyn_cast<ImplicitParamDecl>(&varDecl)) {
1312+
llvm_unreachable("NYI");
1313+
}
1314+
1315+
Address declPtr = Address::invalid();
1316+
assert(!cir::MissingFeatures::rawAddress());
1317+
Address allocaPtr = Address::invalid();
1318+
bool doStore = false;
1319+
bool isScalar = hasScalarEvaluationKind(ty);
1320+
bool useIndirectDebugAddress = false;
1321+
1322+
// If we already have a pointer to the argument, reuse the input pointer.
1323+
if (arg.isIndirect()) {
1324+
llvm_unreachable("NYI");
1325+
} else {
1326+
// Check if the parameter address is controlled by OpenMP runtime.
1327+
Address openMPLocalAddr =
1328+
getLangOpts().OpenMP
1329+
? CGM.getOpenMPRuntime().getAddressOfLocalVariable(*this, &varDecl)
1330+
: Address::invalid();
1331+
if (getLangOpts().OpenMP && openMPLocalAddr.isValid()) {
1332+
llvm_unreachable("NYI");
1333+
} else {
1334+
// Otherwise, create a temporary to hold the value.
1335+
declPtr = CreateMemTemp(ty, getContext().getDeclAlign(&varDecl),
1336+
getLoc(varDecl.getLocation()),
1337+
varDecl.getName() + ".addr", &allocaPtr);
1338+
}
1339+
doStore = true;
1340+
}
1341+
1342+
mlir::Value argVal = (doStore ? arg.getDirectValue() : nullptr);
1343+
1344+
LValue lv = makeAddrLValue(declPtr, ty);
1345+
if (isScalar) {
1346+
Qualifiers qs = ty.getQualifiers();
1347+
if ([[maybe_unused]] Qualifiers::ObjCLifetime lt = qs.getObjCLifetime()) {
1348+
llvm_unreachable("NYI");
1349+
}
1350+
}
1351+
1352+
// Store the initial value into the alloca.
1353+
if (doStore)
1354+
emitStoreOfScalar(argVal, lv, /*isInit=*/true);
1355+
1356+
setAddrOfLocalVar(&varDecl, declPtr);
1357+
1358+
// Emit debug info for param declarations in non-thunk functions.
1359+
if (CIRGenDebugInfo *di = getDebugInfo()) {
1360+
llvm_unreachable("NYI");
1361+
}
1362+
1363+
if (varDecl.hasAttr<AnnotateAttr>())
1364+
llvm_unreachable("NYI");
1365+
1366+
// We can only check return value nullability if all arguments to the function
1367+
// staisfy their nullability preconditions. This makes it necessary to emit
1368+
// null checks for args in the function body itself.
1369+
if (requiresReturnValueNullabilityCheck()) {
1370+
llvm_unreachable("NYI");
1371+
}
1372+
}

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ void CIRGenFunction::StartFunction(GlobalDecl gd, QualType retTy,
13311331
llvm_unreachable("NYI");
13321332
}
13331333

1334-
// TODO: emitFunctionProlog
1334+
emitFunctionProlog(*CurFnInfo, cast<cir::FuncOp>(CurFn), args);
13351335

13361336
{
13371337
// Set the insertion point in the builder to the beginning of the

0 commit comments

Comments
 (0)