[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 31 12:09:34 PDT 2024
================
@@ -24,9 +27,140 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
- : astCtx(astctx), langOpts(astctx.getLangOpts()),
- theModule{mlir::ModuleOp::create(mlir::UnknownLoc())},
- target(astCtx.getTargetInfo()) {}
+ : builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+ theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
+ diags(diags), target(astCtx.getTargetInfo()) {}
+
+mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
+ assert(cLoc.isValid() && "expected valid source location");
+ const SourceManager &sm = astCtx.getSourceManager();
+ PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
+ StringRef filename = pLoc.getFilename();
+ return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+ pLoc.getLine(), pLoc.getColumn());
+}
+
+mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
+ assert(cRange.isValid() && "expected a valid source range");
+ mlir::Location begin = getLoc(cRange.getBegin());
+ mlir::Location end = getLoc(cRange.getEnd());
+ SmallVector<mlir::Location, 2> locs = {begin, end};
+ mlir::Attribute metadata;
+ return mlir::FusedLoc::get(locs, metadata, builder.getContext());
+}
+
+void CIRGenModule::buildGlobal(clang::GlobalDecl gd) {
+ const auto *global = cast<ValueDecl>(gd.getDecl());
+
+ if (const auto *fd = dyn_cast<FunctionDecl>(global)) {
+ // Update deferred annotations with the latest declaration if the function
+ // was already used or defined.
+ if (fd->hasAttr<AnnotateAttr>()) {
+ errorNYI(fd->getSourceRange(), "defferedAnnotations");
+ }
+ if (!fd->doesThisDeclarationHaveABody()) {
----------------
erichkeane wrote:
Should we make sure we're looking at the 'latest' declaration before we ask this? You could otherwise get the 'canonical' declaration (or a first, etc, if the body of the referring declrefexpr was formed before the definition exists) that doesn't have a definition, despite it being defined later.
https://github.com/llvm/llvm-project/pull/113483
More information about the cfe-commits
mailing list