================
@@ -412,38 +412,31 @@ void CIRGenFunction::LexicalScope::emitImplicitReturn() {
(void)emitReturn(localScope->endLoc);
}
-cir::TryOp CIRGenFunction::LexicalScope::getClosestTryParent() {
- LexicalScope *scope = this;
- while (scope) {
- if (scope->isTry())
- return scope->getTry();
- scope = scope->parentScope;
- }
- return nullptr;
-}
-
-void CIRGenFunction::startFunction(GlobalDecl gd, QualType returnType,
- cir::FuncOp fn, cir::FuncType funcType,
- FunctionArgList args, SourceLocation loc,
- SourceLocation startLoc) {
- assert(!curFn &&
- "CIRGenFunction can only be used for one function at a time");
+/// An argument came in as a promoted argument; demote it back to its
+/// declared type.
+static mlir::Value emitArgumentDemotion(CIRGenFunction &cgf, const VarDecl
*var,
+ mlir::Value value) {
+ mlir::Type ty = cgf.convertType(var->getType());
- curFn = fn;
+ // This can happen with promotions that actually don't change the
+ // underlying type, like the enum promotions.
+ if (value.getType() == ty)
+ return value;
- const Decl *d = gd.getDecl();
-
- didCallStackSave = false;
- curCodeDecl = d;
- const auto *fd = dyn_cast_or_null<FunctionDecl>(d);
- curFuncDecl = d->getNonClosureContext();
+ assert((mlir::isa<cir::IntType>(ty) || cir::isAnyFloatingPointType(ty)) &&
+ "unexpected promotion type");
- prologueCleanupDepth = ehStack.stable_begin();
+ if (mlir::isa<cir::IntType>(ty))
+ return cgf.getBuilder().CIRBaseBuilderTy::createIntCast(value, ty);
- mlir::Block *entryBB = &fn.getBlocks().front();
- builder.setInsertionPointToStart(entryBB);
+ return cgf.getBuilder().CIRBaseBuilderTy::createCast(cir::CastKind::floating,
+ value, ty);
+}
- // TODO(cir): this should live in `emitFunctionProlog
+void CIRGenFunction::emitFunctionProlog(const FunctionArgList &args,
+ mlir::Block *entryBB,
+ const FunctionDecl *fd,
+ SourceLocation bodyBeginLoc) {
// Declare all the function arguments in the symbol table.
----------------
andykaylor wrote:
Classic codegen starts this function by checking the FunctionDecl for
`NakedAttr` and returning immediately if it's present. We should have a check
for that.
```
// Naked functions don't have prologues.
if (fd && fd->hasAttr<NakedAttr>()) {
cgm.errorNYI(bodyBeginLoc, "naked function decl");
}
```
https://github.com/llvm/llvm-project/pull/170915
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits