Skip to content

Commit 66fc5f0

Browse files
committed
[CIR][NFC] Organize emit functions in CIRGenFunction.h
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 df01131 commit 66fc5f0

File tree

1 file changed

+131
-118
lines changed

1 file changed

+131
-118
lines changed

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 131 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +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-
114111
mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt);
115112

116113
private:
@@ -133,9 +130,6 @@ class CIRGenFunction : public CIRGenTypeCache {
133130
~VarDeclContext() { restore(); }
134131
};
135132

136-
void emitAndUpdateRetAlloca(clang::QualType type, mlir::Location loc,
137-
clang::CharUnits alignment);
138-
139133
public:
140134
/// Use to track source locations across nested visitor traversals.
141135
/// Always use a `SourceLocRAIIObject` to change currSrcLoc.
@@ -164,88 +158,12 @@ class CIRGenFunction : public CIRGenTypeCache {
164158

165159
const clang::LangOptions &getLangOpts() const { return cgm.getLangOpts(); }
166160

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

227163
/// Determine whether the given initializer is trivial in the sense
228164
/// that it requires no code to be generated.
229165
bool isTrivialInitializer(const Expr *init);
230166

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

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

329-
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv,
330-
bool isInc, bool isPre);
331-
332-
/// Emit the computation of the specified expression of scalar type.
333-
mlir::Value emitScalarExpr(const clang::Expr *e);
334-
mlir::Value emitPromotedScalarExpr(const Expr *e, QualType promotionType);
335223
cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
336224
cir::FuncType funcType);
337225

@@ -346,12 +234,6 @@ class CIRGenFunction : public CIRGenTypeCache {
346234
FunctionArgList args, clang::SourceLocation loc,
347235
clang::SourceLocation startLoc);
348236

349-
/// Emit a conversion from the specified type to the specified destination
350-
/// type, both of which are CIR scalar types.
351-
mlir::Value emitScalarConversion(mlir::Value src, clang::QualType srcType,
352-
clang::QualType dstType,
353-
clang::SourceLocation loc);
354-
355237
/// Represents a scope, including function bodies, compound statements, and
356238
/// the substatements of if/while/do/for/switch/try statements. This class
357239
/// handles any automatic cleanup, along with the return value.
@@ -482,6 +364,137 @@ class CIRGenFunction : public CIRGenTypeCache {
482364

483365
LexicalScope *curLexScope = nullptr;
484366

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

0 commit comments

Comments
 (0)