@@ -108,15 +108,6 @@ class CIRGenFunction : public CIRGenTypeCache {
108
108
bool isParam = false );
109
109
110
110
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
-
120
111
mlir::Value createDummyValue (mlir::Location loc, clang::QualType qt);
121
112
122
113
private:
@@ -139,9 +130,6 @@ class CIRGenFunction : public CIRGenTypeCache {
139
130
~VarDeclContext () { restore (); }
140
131
};
141
132
142
- void emitAndUpdateRetAlloca (clang::QualType type, mlir::Location loc,
143
- clang::CharUnits alignment);
144
-
145
133
public:
146
134
// / Use to track source locations across nested visitor traversals.
147
135
// / Always use a `SourceLocRAIIObject` to change currSrcLoc.
@@ -170,88 +158,12 @@ class CIRGenFunction : public CIRGenTypeCache {
170
158
171
159
const clang::LangOptions &getLangOpts () const { return cgm.getLangOpts (); }
172
160
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
-
179
161
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);
232
162
233
163
// / Determine whether the given initializer is trivial in the sense
234
164
// / that it requires no code to be generated.
235
165
bool isTrivialInitializer (const Expr *init);
236
166
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
-
255
167
struct AutoVarEmission {
256
168
const clang::VarDecl *Variable;
257
169
// / The address of the alloca for languages with explicit address space
@@ -297,30 +209,6 @@ class CIRGenFunction : public CIRGenTypeCache {
297
209
}
298
210
};
299
211
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
-
324
212
// / Perform the usual unary conversions on the specified expression and
325
213
// / compare the result against zero, returning an Int1Ty value.
326
214
mlir::Value evaluateExprAsBool (const clang::Expr *e);
@@ -332,12 +220,6 @@ class CIRGenFunction : public CIRGenTypeCache {
332
220
// TODO: Add symbol table support
333
221
}
334
222
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);
341
223
cir::FuncOp generateCode (clang::GlobalDecl gd, cir::FuncOp fn,
342
224
cir::FuncType funcType);
343
225
@@ -352,12 +234,6 @@ class CIRGenFunction : public CIRGenTypeCache {
352
234
FunctionArgList args, clang::SourceLocation loc,
353
235
clang::SourceLocation startLoc);
354
236
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
-
361
237
// / Represents a scope, including function bodies, compound statements, and
362
238
// / the substatements of if/while/do/for/switch/try statements. This class
363
239
// / handles any automatic cleanup, along with the return value.
@@ -488,6 +364,143 @@ class CIRGenFunction : public CIRGenTypeCache {
488
364
489
365
LexicalScope *curLexScope = nullptr ;
490
366
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:
491
504
Address createTempAlloca (mlir::Type ty, CharUnits align, mlir::Location loc,
492
505
const Twine &name, bool insertIntoFnEntryBlock);
493
506
};
0 commit comments