Skip to content

Commit 6d1184d

Browse files
authored
[CIR][NFC] Organize emit functions in CIRGenFunction.h (#133017)
To make rebasing the incubator project easier, we've been trying to place upstreamed code in the same order in which it appears in the incubator project. However, while the upstream implementation is still relatively sparse, it is often difficult to find points of reference for placement of new declarations. To help with that, I refactored CIRGenFunction.h in the incubator to put all the emit* functions in one place and sort them alphabetically. This change reorganizes the upstream CIRGenFunction.h to match the new incubator ordering.
1 parent a80aad2 commit 6d1184d

File tree

1 file changed

+137
-124
lines changed

1 file changed

+137
-124
lines changed

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 137 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,6 @@ class CIRGenFunction : public CIRGenTypeCache {
108108
bool isParam = false);
109109

110110
public:
111-
mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,
112-
mlir::Location loc, clang::CharUnits alignment,
113-
bool insertIntoFnEntryBlock,
114-
mlir::Value arraySize = nullptr);
115-
mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,
116-
mlir::Location loc, clang::CharUnits alignment,
117-
mlir::OpBuilder::InsertPoint ip,
118-
mlir::Value arraySize = nullptr);
119-
120111
mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt);
121112

122113
private:
@@ -139,9 +130,6 @@ class CIRGenFunction : public CIRGenTypeCache {
139130
~VarDeclContext() { restore(); }
140131
};
141132

142-
void emitAndUpdateRetAlloca(clang::QualType type, mlir::Location loc,
143-
clang::CharUnits alignment);
144-
145133
public:
146134
/// Use to track source locations across nested visitor traversals.
147135
/// Always use a `SourceLocRAIIObject` to change currSrcLoc.
@@ -170,88 +158,12 @@ class CIRGenFunction : public CIRGenTypeCache {
170158

171159
const clang::LangOptions &getLangOpts() const { return cgm.getLangOpts(); }
172160

173-
/// Emit code to compute the specified expression which can have any type. The
174-
/// result is returned as an RValue struct. If this is an aggregate
175-
/// expression, the aggloc/agglocvolatile arguments indicate where the result
176-
/// should be returned.
177-
RValue emitAnyExpr(const clang::Expr *e);
178-
179161
void finishFunction(SourceLocation endLoc);
180-
mlir::LogicalResult emitFunctionBody(const clang::Stmt *body);
181-
182-
/// Build a debug stoppoint if we are emitting debug info.
183-
void emitStopPoint(const Stmt *s);
184-
185-
// Build CIR for a statement. useCurrentScope should be true if no
186-
// new scopes need be created when finding a compound statement.
187-
mlir::LogicalResult
188-
emitStmt(const clang::Stmt *s, bool useCurrentScope,
189-
llvm::ArrayRef<const Attr *> attrs = std::nullopt);
190-
191-
mlir::LogicalResult emitSimpleStmt(const clang::Stmt *s,
192-
bool useCurrentScope);
193-
194-
mlir::LogicalResult emitForStmt(const clang::ForStmt &S);
195-
196-
void emitCompoundStmt(const clang::CompoundStmt &s);
197-
198-
void emitCompoundStmtWithoutScope(const clang::CompoundStmt &s);
199-
200-
/// Emit code to compute the specified expression,
201-
/// ignoring the result.
202-
void emitIgnoredExpr(const clang::Expr *e);
203-
204-
mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s);
205-
206-
mlir::LogicalResult emitReturnStmt(const clang::ReturnStmt &s);
207-
208-
/// Given an expression that represents a value lvalue, this method emits
209-
/// the address of the lvalue, then loads the result as an rvalue,
210-
/// returning the rvalue.
211-
RValue emitLoadOfLValue(LValue lv, SourceLocation loc);
212-
213-
/// EmitLoadOfScalar - Load a scalar value from an address, taking
214-
/// care to appropriately convert from the memory representation to
215-
/// the LLVM value representation. The l-value must be a simple
216-
/// l-value.
217-
mlir::Value emitLoadOfScalar(LValue lvalue, SourceLocation loc);
218-
219-
/// Emit code to compute a designator that specifies the location
220-
/// of the expression.
221-
/// FIXME: document this function better.
222-
LValue emitLValue(const clang::Expr *e);
223-
224-
void emitDecl(const clang::Decl &d);
225-
226-
void emitScalarInit(const clang::Expr *init, mlir::Location loc,
227-
LValue lvalue, bool capturedByInit = false);
228-
229-
LValue emitDeclRefLValue(const clang::DeclRefExpr *e);
230-
LValue emitUnaryOpLValue(const clang::UnaryOperator *e);
231-
LValue emitBinaryOperatorLValue(const BinaryOperator *e);
232162

233163
/// Determine whether the given initializer is trivial in the sense
234164
/// that it requires no code to be generated.
235165
bool isTrivialInitializer(const Expr *init);
236166

237-
/// Emit an expression as an initializer for an object (variable, field, etc.)
238-
/// at the given location. The expression is not necessarily the normal
239-
/// initializer for the object, and the address is not necessarily
240-
/// its normal location.
241-
///
242-
/// \param init the initializing expression
243-
/// \param d the object to act as if we're initializing
244-
/// \param lvalue the lvalue to initialize
245-
/// \param capturedByInit true if \p d is a __block variable whose address is
246-
/// potentially changed by the initializer
247-
void emitExprAsInit(const clang::Expr *init, const clang::ValueDecl *d,
248-
LValue lvalue, bool capturedByInit = false);
249-
250-
/// Emit code and set up symbol table for a variable declaration with auto,
251-
/// register, or no storage class specifier. These turn into simple stack
252-
/// objects, globals depending on target.
253-
void emitAutoVarDecl(const clang::VarDecl &d);
254-
255167
struct AutoVarEmission {
256168
const clang::VarDecl *Variable;
257169
/// The address of the alloca for languages with explicit address space
@@ -297,30 +209,6 @@ class CIRGenFunction : public CIRGenTypeCache {
297209
}
298210
};
299211

300-
AutoVarEmission emitAutoVarAlloca(const clang::VarDecl &d);
301-
void emitAutoVarInit(const AutoVarEmission &emission);
302-
void emitAutoVarCleanups(const AutoVarEmission &emission);
303-
304-
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile,
305-
clang::QualType ty, bool isInit = false,
306-
bool isNontemporal = false);
307-
void emitStoreOfScalar(mlir::Value value, LValue lvalue, bool isInit);
308-
309-
/// Given a value and its clang type, returns the value casted to its memory
310-
/// representation.
311-
/// Note: CIR defers most of the special casting to the final lowering passes
312-
/// to conserve the high level information.
313-
mlir::Value emitToMemory(mlir::Value Value, clang::QualType Ty);
314-
315-
/// Store the specified rvalue into the specified
316-
/// lvalue, where both are guaranteed to the have the same type, and that type
317-
/// is 'Ty'.
318-
void emitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false);
319-
320-
/// This method handles emission of any variable declaration
321-
/// inside a function, including static vars etc.
322-
void emitVarDecl(const clang::VarDecl &d);
323-
324212
/// Perform the usual unary conversions on the specified expression and
325213
/// compare the result against zero, returning an Int1Ty value.
326214
mlir::Value evaluateExprAsBool(const clang::Expr *e);
@@ -332,12 +220,6 @@ class CIRGenFunction : public CIRGenTypeCache {
332220
// TODO: Add symbol table support
333221
}
334222

335-
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv,
336-
bool isInc, bool isPre);
337-
338-
/// Emit the computation of the specified expression of scalar type.
339-
mlir::Value emitScalarExpr(const clang::Expr *e);
340-
mlir::Value emitPromotedScalarExpr(const Expr *e, QualType promotionType);
341223
cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
342224
cir::FuncType funcType);
343225

@@ -352,12 +234,6 @@ class CIRGenFunction : public CIRGenTypeCache {
352234
FunctionArgList args, clang::SourceLocation loc,
353235
clang::SourceLocation startLoc);
354236

355-
/// Emit a conversion from the specified type to the specified destination
356-
/// type, both of which are CIR scalar types.
357-
mlir::Value emitScalarConversion(mlir::Value src, clang::QualType srcType,
358-
clang::QualType dstType,
359-
clang::SourceLocation loc);
360-
361237
/// Represents a scope, including function bodies, compound statements, and
362238
/// the substatements of if/while/do/for/switch/try statements. This class
363239
/// handles any automatic cleanup, along with the return value.
@@ -488,6 +364,143 @@ class CIRGenFunction : public CIRGenTypeCache {
488364

489365
LexicalScope *curLexScope = nullptr;
490366

367+
/// ----------------------
368+
/// CIR emit functions
369+
/// ----------------------
370+
private:
371+
void emitAndUpdateRetAlloca(clang::QualType type, mlir::Location loc,
372+
clang::CharUnits alignment);
373+
374+
public:
375+
mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,
376+
mlir::Location loc, clang::CharUnits alignment,
377+
bool insertIntoFnEntryBlock,
378+
mlir::Value arraySize = nullptr);
379+
mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,
380+
mlir::Location loc, clang::CharUnits alignment,
381+
mlir::OpBuilder::InsertPoint ip,
382+
mlir::Value arraySize = nullptr);
383+
384+
/// Emit code to compute the specified expression which can have any type. The
385+
/// result is returned as an RValue struct. If this is an aggregate
386+
/// expression, the aggloc/agglocvolatile arguments indicate where the result
387+
/// should be returned.
388+
RValue emitAnyExpr(const clang::Expr *e);
389+
390+
AutoVarEmission emitAutoVarAlloca(const clang::VarDecl &d);
391+
392+
/// Emit code and set up symbol table for a variable declaration with auto,
393+
/// register, or no storage class specifier. These turn into simple stack
394+
/// objects, globals depending on target.
395+
void emitAutoVarDecl(const clang::VarDecl &d);
396+
397+
void emitAutoVarCleanups(const AutoVarEmission &emission);
398+
void emitAutoVarInit(const AutoVarEmission &emission);
399+
400+
LValue emitBinaryOperatorLValue(const BinaryOperator *e);
401+
402+
/// Emit an expression as an initializer for an object (variable, field, etc.)
403+
/// at the given location. The expression is not necessarily the normal
404+
/// initializer for the object, and the address is not necessarily
405+
/// its normal location.
406+
///
407+
/// \param init the initializing expression
408+
/// \param d the object to act as if we're initializing
409+
/// \param lvalue the lvalue to initialize
410+
/// \param capturedByInit true if \p d is a __block variable whose address is
411+
/// potentially changed by the initializer
412+
void emitExprAsInit(const clang::Expr *init, const clang::ValueDecl *d,
413+
LValue lvalue, bool capturedByInit = false);
414+
415+
mlir::LogicalResult emitFunctionBody(const clang::Stmt *body);
416+
417+
mlir::Value emitPromotedScalarExpr(const Expr *e, QualType promotionType);
418+
419+
/// Emit the computation of the specified expression of scalar type.
420+
mlir::Value emitScalarExpr(const clang::Expr *e);
421+
422+
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv,
423+
bool isInc, bool isPre);
424+
425+
/// Build a debug stoppoint if we are emitting debug info.
426+
void emitStopPoint(const Stmt *s);
427+
428+
// Build CIR for a statement. useCurrentScope should be true if no
429+
// new scopes need be created when finding a compound statement.
430+
mlir::LogicalResult
431+
emitStmt(const clang::Stmt *s, bool useCurrentScope,
432+
llvm::ArrayRef<const Attr *> attrs = std::nullopt);
433+
434+
mlir::LogicalResult emitSimpleStmt(const clang::Stmt *s,
435+
bool useCurrentScope);
436+
437+
mlir::LogicalResult emitForStmt(const clang::ForStmt &s);
438+
439+
void emitCompoundStmt(const clang::CompoundStmt &s);
440+
441+
void emitCompoundStmtWithoutScope(const clang::CompoundStmt &s);
442+
443+
void emitDecl(const clang::Decl &d);
444+
mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s);
445+
LValue emitDeclRefLValue(const clang::DeclRefExpr *e);
446+
447+
/// Emit code to compute the specified expression,
448+
/// ignoring the result.
449+
void emitIgnoredExpr(const clang::Expr *e);
450+
451+
/// Given an expression that represents a value lvalue, this method emits
452+
/// the address of the lvalue, then loads the result as an rvalue,
453+
/// returning the rvalue.
454+
RValue emitLoadOfLValue(LValue lv, SourceLocation loc);
455+
456+
/// EmitLoadOfScalar - Load a scalar value from an address, taking
457+
/// care to appropriately convert from the memory representation to
458+
/// the LLVM value representation. The l-value must be a simple
459+
/// l-value.
460+
mlir::Value emitLoadOfScalar(LValue lvalue, SourceLocation loc);
461+
462+
/// Emit code to compute a designator that specifies the location
463+
/// of the expression.
464+
/// FIXME: document this function better.
465+
LValue emitLValue(const clang::Expr *e);
466+
467+
mlir::LogicalResult emitReturnStmt(const clang::ReturnStmt &s);
468+
469+
/// Emit a conversion from the specified type to the specified destination
470+
/// type, both of which are CIR scalar types.
471+
mlir::Value emitScalarConversion(mlir::Value src, clang::QualType srcType,
472+
clang::QualType dstType,
473+
clang::SourceLocation loc);
474+
475+
void emitScalarInit(const clang::Expr *init, mlir::Location loc,
476+
LValue lvalue, bool capturedByInit = false);
477+
478+
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile,
479+
clang::QualType ty, bool isInit = false,
480+
bool isNontemporal = false);
481+
void emitStoreOfScalar(mlir::Value value, LValue lvalue, bool isInit);
482+
483+
/// Store the specified rvalue into the specified
484+
/// lvalue, where both are guaranteed to the have the same type, and that type
485+
/// is 'Ty'.
486+
void emitStoreThroughLValue(RValue src, LValue dst, bool isInit = false);
487+
488+
/// Given a value and its clang type, returns the value casted to its memory
489+
/// representation.
490+
/// Note: CIR defers most of the special casting to the final lowering passes
491+
/// to conserve the high level information.
492+
mlir::Value emitToMemory(mlir::Value value, clang::QualType ty);
493+
494+
LValue emitUnaryOpLValue(const clang::UnaryOperator *e);
495+
496+
/// This method handles emission of any variable declaration
497+
/// inside a function, including static vars etc.
498+
void emitVarDecl(const clang::VarDecl &d);
499+
500+
/// ----------------------
501+
/// CIR build helpers
502+
/// -----------------
503+
public:
491504
Address createTempAlloca(mlir::Type ty, CharUnits align, mlir::Location loc,
492505
const Twine &name, bool insertIntoFnEntryBlock);
493506
};

0 commit comments

Comments
 (0)