Skip to content

Commit 0a76bb1

Browse files
committed
Follow-up and cleanup of simple function upstreaming
1 parent c0f1039 commit 0a76bb1

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,10 @@ mlir::Location CIRGenFunction::getLoc(SourceLocation srcLoc) {
102102
StringRef filename = pLoc.getFilename();
103103
return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
104104
pLoc.getLine(), pLoc.getColumn());
105-
} else {
106-
// Do our best...
107-
assert(currSrcLoc && "expected to inherit some source location");
108-
return *currSrcLoc;
109105
}
106+
// Do our best...
107+
assert(currSrcLoc && "expected to inherit some source location");
108+
return *currSrcLoc;
110109
}
111110

112111
mlir::Location CIRGenFunction::getLoc(SourceRange srcLoc) {
@@ -118,10 +117,10 @@ mlir::Location CIRGenFunction::getLoc(SourceRange srcLoc) {
118117
SmallVector<mlir::Location, 2> locs = {beg, end};
119118
mlir::Attribute metadata;
120119
return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
121-
} else if (currSrcLoc) {
120+
}
121+
if (currSrcLoc) {
122122
return *currSrcLoc;
123123
}
124-
125124
// We're brave, but time to give up.
126125
return builder.getUnknownLoc();
127126
}
@@ -168,15 +167,33 @@ cir::FuncOp CIRGenFunction::generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
168167
SourceLocRAIIObject fnLoc{*this, loc.isValid() ? getLoc(loc)
169168
: builder.getUnknownLoc()};
170169

171-
mlir::Block *entryBB = fn.addEntryBlock();
172-
builder.setInsertionPointToStart(entryBB);
170+
// This will be used once more code is upstreamed.
171+
[[maybe_unused]] mlir::Block *entryBB = fn.addEntryBlock();
173172

174173
startFunction(gd, funcDecl->getReturnType(), fn, funcType, loc,
175174
bodyRange.getBegin());
176-
if (mlir::failed(emitFunctionBody(body))) {
177-
fn.erase();
178-
return nullptr;
179-
}
175+
176+
if (isa<CXXDestructorDecl>(funcDecl))
177+
getCIRGenModule().errorNYI(bodyRange, "C++ destructor definition");
178+
else if (isa<CXXConstructorDecl>(funcDecl))
179+
getCIRGenModule().errorNYI(bodyRange, "C++ constructor definition");
180+
else if (getLangOpts().CUDA && !getLangOpts().CUDAIsDevice &&
181+
funcDecl->hasAttr<CUDAGlobalAttr>())
182+
getCIRGenModule().errorNYI(bodyRange, "CUDA kernel");
183+
else if (isa<CXXMethodDecl>(funcDecl) &&
184+
cast<CXXMethodDecl>(funcDecl)->isLambdaStaticInvoker())
185+
getCIRGenModule().errorNYI(bodyRange, "Lambda static invoker");
186+
else if (funcDecl->isDefaulted() && isa<CXXMethodDecl>(funcDecl) &&
187+
(cast<CXXMethodDecl>(funcDecl)->isCopyAssignmentOperator() ||
188+
cast<CXXMethodDecl>(funcDecl)->isMoveAssignmentOperator()))
189+
getCIRGenModule().errorNYI(bodyRange, "Default assignment operator");
190+
else if (body) {
191+
if (mlir::failed(emitFunctionBody(body))) {
192+
fn.erase();
193+
return nullptr;
194+
}
195+
} else
196+
llvm_unreachable("no definition for normal function");
180197

181198
// This code to insert a cir.return or cir.trap at the end of the function is
182199
// temporary until the function return code, including

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENFUNCTION_H
14-
#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENFUNCTION_H
13+
#ifndef CLANG_LIB_CIR_CODEGEN_CIRGENFUNCTION_H
14+
#define CLANG_LIB_CIR_CODEGEN_CIRGENFUNCTION_H
1515

1616
#include "CIRGenBuilder.h"
1717
#include "CIRGenModule.h"
@@ -25,13 +25,18 @@
2525

2626
#include "llvm/ADT/ScopedHashTable.h"
2727

28+
namespace {
29+
class ScalarExprEmitter;
30+
} // namespace
31+
2832
namespace clang::CIRGen {
2933

3034
class CIRGenFunction : public CIRGenTypeCache {
3135
public:
3236
CIRGenModule &cgm;
3337

3438
private:
39+
friend class ::ScalarExprEmitter;
3540
/// The builder is a helper class to create IR inside a function. The
3641
/// builder is stateful, in particular it keeps an "insertion point": this
3742
/// is where the next operations will be introduced.
@@ -58,11 +63,11 @@ class CIRGenFunction : public CIRGenTypeCache {
5863
return convertType(getContext().getTypeDeclType(T));
5964
}
6065

61-
/// Return the cir::TypeEvaluationKind of QualType \c T.
62-
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType T);
66+
/// Return the cir::TypeEvaluationKind of QualType \c type.
67+
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type);
6368

64-
static bool hasScalarEvaluationKind(clang::QualType T) {
65-
return getEvaluationKind(T) == cir::TEK_Scalar;
69+
static bool hasScalarEvaluationKind(clang::QualType type) {
70+
return getEvaluationKind(type) == cir::TEK_Scalar;
6671
}
6772

6873
CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder,
@@ -94,12 +99,14 @@ class CIRGenFunction : public CIRGenTypeCache {
9499
};
95100

96101
/// Helpers to convert Clang's SourceLocation to a MLIR Location.
97-
mlir::Location getLoc(clang::SourceLocation SLoc);
98-
mlir::Location getLoc(clang::SourceRange SLoc);
102+
mlir::Location getLoc(clang::SourceLocation srcLoc);
103+
mlir::Location getLoc(clang::SourceRange srcLoc);
99104
mlir::Location getLoc(mlir::Location lhs, mlir::Location rhs);
100105

101-
void finishFunction(SourceLocation EndLoc);
102-
mlir::LogicalResult emitFunctionBody(const clang::Stmt *Body);
106+
const clang::LangOptions &getLangOpts() const { return cgm.getLangOpts(); }
107+
108+
void finishFunction(SourceLocation endLoc);
109+
mlir::LogicalResult emitFunctionBody(const clang::Stmt *body);
103110

104111
// Build CIR for a statement. useCurrentScope should be true if no
105112
// new scopes need be created when finding a compound statement.
@@ -122,8 +129,8 @@ class CIRGenFunction : public CIRGenTypeCache {
122129
cir::FuncType funcType);
123130

124131
/// Emit code for the start of a function.
125-
/// \param Loc The location to be associated with the function.
126-
/// \param StartLoc The location of the function body.
132+
/// \param loc The location to be associated with the function.
133+
/// \param startLoc The location of the function body.
127134
void startFunction(clang::GlobalDecl gd, clang::QualType retTy,
128135
cir::FuncOp fn, cir::FuncType funcType,
129136
clang::SourceLocation loc, clang::SourceLocation startLoc);

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class CIRGenModule : public CIRGenTypeCache {
7373
CIRGenBuilderTy &getBuilder() { return builder; }
7474
clang::ASTContext &getASTContext() const { return astContext; }
7575
CIRGenTypes &getTypes() { return genTypes; }
76+
const clang::LangOptions &getLangOpts() const { return langOpts; }
7677
mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
7778

7879
/// Helpers to convert the presumed location of Clang's SourceLocation to an

0 commit comments

Comments
 (0)