Thanks to visit codestin.com
Credit goes to clang.llvm.org

clang 22.0.0git
CIRGenModule.h
Go to the documentation of this file.
1//===--- CIRGenModule.h - Per-Module state for CIR gen ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is the internal per-translation-unit state used for CIR translation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
14#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
15
16#include "CIRGenBuilder.h"
17#include "CIRGenCall.h"
18#include "CIRGenTypeCache.h"
19#include "CIRGenTypes.h"
20#include "CIRGenVTables.h"
21#include "CIRGenValue.h"
22
23#include "clang/AST/CharUnits.h"
26
27#include "TargetInfo.h"
28#include "mlir/IR/Builders.h"
29#include "mlir/IR/BuiltinOps.h"
30#include "mlir/IR/MLIRContext.h"
31#include "clang/AST/Decl.h"
35#include "llvm/ADT/StringRef.h"
36#include "llvm/TargetParser/Triple.h"
37
38namespace clang {
39class ASTContext;
40class CodeGenOptions;
41class Decl;
42class GlobalDecl;
43class LangOptions;
44class TargetInfo;
45class VarDecl;
46
47namespace CIRGen {
48
49class CIRGenFunction;
50class CIRGenCXXABI;
51
52enum ForDefinition_t : bool { NotForDefinition = false, ForDefinition = true };
53
54/// This class organizes the cross-function state that is used while generating
55/// CIR code.
56class CIRGenModule : public CIRGenTypeCache {
57 CIRGenModule(CIRGenModule &) = delete;
58 CIRGenModule &operator=(CIRGenModule &) = delete;
59
60public:
61 CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
62 const clang::CodeGenOptions &cgo,
64
66
67private:
68 mutable std::unique_ptr<TargetCIRGenInfo> theTargetCIRGenInfo;
69
70 CIRGenBuilderTy builder;
71
72 /// Hold Clang AST information.
73 clang::ASTContext &astContext;
74
75 const clang::LangOptions &langOpts;
76
77 const clang::CodeGenOptions &codeGenOpts;
78
79 /// A "module" matches a c/cpp source file: containing a list of functions.
80 mlir::ModuleOp theModule;
81
83
84 const clang::TargetInfo &target;
85
86 std::unique_ptr<CIRGenCXXABI> abi;
87
88 CIRGenTypes genTypes;
89
90 /// Holds information about C++ vtables.
91 CIRGenVTables vtables;
92
93 /// Per-function codegen information. Updated everytime emitCIR is called
94 /// for FunctionDecls's.
95 CIRGenFunction *curCGF = nullptr;
96
98
99public:
100 mlir::ModuleOp getModule() const { return theModule; }
101 CIRGenBuilderTy &getBuilder() { return builder; }
102 clang::ASTContext &getASTContext() const { return astContext; }
103 const clang::TargetInfo &getTarget() const { return target; }
104 const clang::CodeGenOptions &getCodeGenOpts() const { return codeGenOpts; }
105 clang::DiagnosticsEngine &getDiags() const { return diags; }
106 CIRGenTypes &getTypes() { return genTypes; }
107 const clang::LangOptions &getLangOpts() const { return langOpts; }
108
109 CIRGenCXXABI &getCXXABI() const { return *abi; }
110 mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
111
113 // FIXME(cir): instead of creating a CIRDataLayout every time, set it as an
114 // attribute for the CIRModule class.
115 return cir::CIRDataLayout(theModule);
116 }
117
118 /// -------
119 /// Handling globals
120 /// -------
121
122 mlir::Operation *lastGlobalOp = nullptr;
123
124 /// Keep a map between lambda fields and names, this needs to be per module
125 /// since lambdas might get generated later as part of defered work, and since
126 /// the pointers are supposed to be uniqued, should be fine. Revisit this if
127 /// it ends up taking too much memory.
128 llvm::DenseMap<const clang::FieldDecl *, llvm::StringRef> lambdaFieldToName;
129
130 /// Tell the consumer that this variable has been instantiated.
132
133 llvm::DenseMap<const Decl *, cir::GlobalOp> staticLocalDeclMap;
134
135 mlir::Operation *getGlobalValue(llvm::StringRef ref);
136
137 cir::GlobalOp getStaticLocalDeclAddress(const VarDecl *d) {
138 return staticLocalDeclMap[d];
139 }
140
141 void setStaticLocalDeclAddress(const VarDecl *d, cir::GlobalOp c) {
143 }
144
145 cir::GlobalOp getOrCreateStaticVarDecl(const VarDecl &d,
146 cir::GlobalLinkageKind linkage);
147
148 /// If the specified mangled name is not in the module, create and return an
149 /// mlir::GlobalOp value
150 cir::GlobalOp getOrCreateCIRGlobal(llvm::StringRef mangledName, mlir::Type ty,
151 LangAS langAS, const VarDecl *d,
152 ForDefinition_t isForDefinition);
153
154 cir::GlobalOp getOrCreateCIRGlobal(const VarDecl *d, mlir::Type ty,
155 ForDefinition_t isForDefinition);
156
157 static cir::GlobalOp createGlobalOp(CIRGenModule &cgm, mlir::Location loc,
158 llvm::StringRef name, mlir::Type t,
159 bool isConstant = false,
160 mlir::Operation *insertPoint = nullptr);
161
163 // In C23 (N3096) $6.7.10:
164 // """
165 // If any object is initialized with an empty initializer, then it is
166 // subject to default initialization:
167 // - if it is an aggregate, every member is initialized (recursively)
168 // according to these rules, and any padding is initialized to zero bits;
169 // - if it is a union, the first named member is initialized (recursively)
170 // according to these rules, and any padding is initialized to zero bits.
171 //
172 // If the aggregate or union contains elements or members that are
173 // aggregates or unions, these rules apply recursively to the subaggregates
174 // or contained unions.
175 //
176 // If there are fewer initializers in a brace-enclosed list than there are
177 // elements or members of an aggregate, or fewer characters in a string
178 // literal used to initialize an array of known size than there are elements
179 // in the array, the remainder of the aggregate is subject to default
180 // initialization.
181 // """
182 //
183 // The standard seems ambiguous in the following two areas:
184 // 1. For a union type with empty initializer, if the first named member is
185 // not the largest member, then the bytes comes after the first named member
186 // but before padding are left unspecified. An example is:
187 // union U { int a; long long b;};
188 // union U u = {}; // The first 4 bytes are 0, but 4-8 bytes are left
189 // unspecified.
190 //
191 // 2. It only mentions padding for empty initializer, but doesn't mention
192 // padding for a non empty initialization list. And if the aggregation or
193 // union contains elements or members that are aggregates or unions, and
194 // some are non empty initializers, while others are empty initializers,
195 // the padding initialization is unclear. An example is:
196 // struct S1 { int a; long long b; };
197 // struct S2 { char c; struct S1 s1; };
198 // // The values for paddings between s2.c and s2.s1.a, between s2.s1.a
199 // and s2.s1.b are unclear.
200 // struct S2 s2 = { 'c' };
201 //
202 // Here we choose to zero initiailize left bytes of a union type because
203 // projects like the Linux kernel are relying on this behavior. If we don't
204 // explicitly zero initialize them, the undef values can be optimized to
205 // return garbage data. We also choose to zero initialize paddings for
206 // aggregates and unions, no matter they are initialized by empty
207 // initializers or non empty initializers. This can provide a consistent
208 // behavior. So projects like the Linux kernel can rely on it.
209 return !getLangOpts().CPlusPlus;
210 }
211
212 llvm::StringMap<unsigned> cgGlobalNames;
213 std::string getUniqueGlobalName(const std::string &baseName);
214
215 /// Return the mlir::Value for the address of the given global variable.
216 /// If Ty is non-null and if the global doesn't exist, then it will be created
217 /// with the specified type instead of whatever the normal requested type
218 /// would be. If IsForDefinition is true, it is guaranteed that an actual
219 /// global with type Ty will be returned, not conversion of a variable with
220 /// the same mangled name but some other type.
221 mlir::Value
222 getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty = {},
223 ForDefinition_t isForDefinition = NotForDefinition);
224
225 /// Return the mlir::GlobalViewAttr for the address of the given global.
226 cir::GlobalViewAttr getAddrOfGlobalVarAttr(const VarDecl *d);
227
229 const CXXRecordDecl *derivedClass,
230 llvm::iterator_range<CastExpr::path_const_iterator> path);
231
232 /// Get the CIR attributes and calling convention to use for a particular
233 /// function type.
234 ///
235 /// \param calleeInfo - The callee information these attributes are being
236 /// constructed for. If valid, the attributes applied to this decl may
237 /// contribute to the function attributes and calling convention.
239 mlir::NamedAttrList &attrs);
240
241 /// Will return a global variable of the given type. If a variable with a
242 /// different type already exists then a new variable with the right type
243 /// will be created and all uses of the old variable will be replaced with a
244 /// bitcast to the new variable.
246 mlir::Location loc, llvm::StringRef name, mlir::Type ty,
247 cir::GlobalLinkageKind linkage, clang::CharUnits alignment);
248
249 void emitVTable(const CXXRecordDecl *rd);
250
251 /// Return the appropriate linkage for the vtable, VTT, and type information
252 /// of the given class.
253 cir::GlobalLinkageKind getVTableLinkage(const CXXRecordDecl *rd);
254
255 /// Get the address of the RTTI descriptor for the given type.
256 mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty,
257 bool forEH = false);
258
259 static mlir::SymbolTable::Visibility getMLIRVisibility(Visibility v) {
260 switch (v) {
262 return mlir::SymbolTable::Visibility::Public;
263 case HiddenVisibility:
264 return mlir::SymbolTable::Visibility::Private;
266 // The distinction between ProtectedVisibility and DefaultVisibility is
267 // that symbols with ProtectedVisibility, while visible to the dynamic
268 // linker like DefaultVisibility, are guaranteed to always dynamically
269 // resolve to a symbol in the current shared object. There is currently no
270 // equivalent MLIR visibility, so we fall back on the fact that the symbol
271 // is visible.
272 return mlir::SymbolTable::Visibility::Public;
273 }
274 llvm_unreachable("unknown visibility!");
275 }
276
277 /// Return a constant array for the given string.
278 mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e);
279
280 /// Return a global symbol reference to a constant array for the given string
281 /// literal.
282 cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s,
283 llvm::StringRef name = ".str");
284
285 /// Return a global symbol reference to a constant array for the given string
286 /// literal.
287 cir::GlobalViewAttr
289 llvm::StringRef name = ".str");
290
291 /// Set attributes which are common to any form of a global definition (alias,
292 /// Objective-C method, function, global variable).
293 ///
294 /// NOTE: This should only be called for definitions.
295 void setCommonAttributes(GlobalDecl gd, mlir::Operation *op);
296
298
299 /// Helpers to convert the presumed location of Clang's SourceLocation to an
300 /// MLIR Location.
301 mlir::Location getLoc(clang::SourceLocation cLoc);
302 mlir::Location getLoc(clang::SourceRange cRange);
303
304 /// Return the best known alignment for an unknown pointer to a
305 /// particular class.
307
308 /// FIXME: this could likely be a common helper and not necessarily related
309 /// with codegen.
311 LValueBaseInfo *baseInfo);
312
313 /// TODO: Add TBAAAccessInfo
315 const CXXRecordDecl *baseDecl,
316 CharUnits expectedTargetAlign);
317
318 /// Returns the assumed alignment of a virtual base of a class.
320 const CXXRecordDecl *derived,
321 const CXXRecordDecl *vbase);
322
323 cir::FuncOp
325 const CIRGenFunctionInfo *fnInfo = nullptr,
326 cir::FuncType fnType = nullptr, bool dontDefer = false,
327 ForDefinition_t isForDefinition = NotForDefinition) {
328 return getAddrAndTypeOfCXXStructor(gd, fnInfo, fnType, dontDefer,
329 isForDefinition)
330 .second;
331 }
332
333 std::pair<cir::FuncType, cir::FuncOp> getAddrAndTypeOfCXXStructor(
334 clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo = nullptr,
335 cir::FuncType fnType = nullptr, bool dontDefer = false,
336 ForDefinition_t isForDefinition = NotForDefinition);
337
338 mlir::Type getVTableComponentType();
339 CIRGenVTables &getVTables() { return vtables; }
340
342 return vtables.getItaniumVTableContext();
343 }
345 return vtables.getItaniumVTableContext();
346 }
347
348 /// This contains all the decls which have definitions but which are deferred
349 /// for emission and therefore should only be output if they are actually
350 /// used. If a decl is in this, then it is known to have not been referenced
351 /// yet.
352 std::map<llvm::StringRef, clang::GlobalDecl> deferredDecls;
353
354 // This is a list of deferred decls which we have seen that *are* actually
355 // referenced. These get code generated when the module is done.
356 std::vector<clang::GlobalDecl> deferredDeclsToEmit;
358 deferredDeclsToEmit.emplace_back(GD);
359 }
360
362
363 /// Determine whether the definition must be emitted; if this returns \c
364 /// false, the definition can be emitted lazily if it's used.
365 bool mustBeEmitted(const clang::ValueDecl *d);
366
367 /// Determine whether the definition can be emitted eagerly, or should be
368 /// delayed until the end of the translation unit. This is relevant for
369 /// definitions whose linkage can change, e.g. implicit function
370 /// instantiations which may later be explicitly instantiated.
372
373 bool verifyModule() const;
374
375 /// Return the address of the given function. If funcType is non-null, then
376 /// this function will use the specified type if it has to create it.
377 // TODO: this is a bit weird as `GetAddr` given we give back a FuncOp?
378 cir::FuncOp
379 getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType = nullptr,
380 bool forVTable = false, bool dontDefer = false,
381 ForDefinition_t isForDefinition = NotForDefinition);
382
383 mlir::Operation *
385 ForDefinition_t isForDefinition = NotForDefinition);
386
387 // Return whether RTTI information should be emitted for this target.
388 bool shouldEmitRTTI(bool forEH = false) {
389 return (forEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
390 !(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
391 getTriple().isNVPTX());
392 }
393
394 /// Emit type info if type of an expression is a variably modified
395 /// type. Also emit proper debug info for cast types.
397 CIRGenFunction *cgf = nullptr);
398
399 /// Emit code for a single global function or variable declaration. Forward
400 /// declarations are emitted lazily.
402
403 void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op,
404 GlobalDecl aliasGD, cir::FuncOp aliasee,
405 cir::GlobalLinkageKind linkage);
406
407 mlir::Type convertType(clang::QualType type);
408
409 /// Set the visibility for the given global.
410 void setGlobalVisibility(mlir::Operation *op, const NamedDecl *d) const;
411 void setDSOLocal(mlir::Operation *op) const;
412 void setDSOLocal(cir::CIRGlobalValueInterface gv) const;
413
414 /// Set visibility, dllimport/dllexport and dso_local.
415 /// This must be called after dllimport/dllexport is set.
416 void setGVProperties(mlir::Operation *op, const NamedDecl *d) const;
417 void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const;
418
419 /// Set function attributes for a function declaration.
420 void setFunctionAttributes(GlobalDecl gd, cir::FuncOp f,
421 bool isIncompleteFunction, bool isThunk);
422
424 mlir::Operation *op = nullptr);
425 void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
427 bool isTentative = false);
428
429 /// Emit the function that initializes the specified global
430 void emitCXXGlobalVarDeclInit(const VarDecl *varDecl, cir::GlobalOp addr,
431 bool performInit);
432
433 void emitCXXGlobalVarDeclInitFunc(const VarDecl *vd, cir::GlobalOp addr,
434 bool performInit);
435
437
438 // C++ related functions.
439 void emitDeclContext(const DeclContext *dc);
440
441 /// Return the result of value-initializing the given type, i.e. a null
442 /// expression of the given type.
443 mlir::Value emitNullConstant(QualType t, mlir::Location loc);
444
445 llvm::StringRef getMangledName(clang::GlobalDecl gd);
446
447 void emitTentativeDefinition(const VarDecl *d);
448
449 // Make sure that this type is translated.
450 void updateCompletedType(const clang::TagDecl *td);
451
452 // Produce code for this constructor/destructor. This method doesn't try to
453 // apply any ABI rules about which other constructors/destructors are needed
454 // or if they are alias to each other.
456
457 bool supportsCOMDAT() const;
458 void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op);
459
460 static void setInitializer(cir::GlobalOp &op, mlir::Attribute value);
461
462 void replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old,
463 cir::FuncOp newFn);
464
465 cir::FuncOp
466 getOrCreateCIRFunction(llvm::StringRef mangledName, mlir::Type funcType,
467 clang::GlobalDecl gd, bool forVTable,
468 bool dontDefer = false, bool isThunk = false,
469 ForDefinition_t isForDefinition = NotForDefinition,
470 mlir::ArrayAttr extraAttrs = {});
471
472 cir::FuncOp createCIRFunction(mlir::Location loc, llvm::StringRef name,
473 cir::FuncType funcType,
474 const clang::FunctionDecl *funcDecl);
475
476 /// Given a builtin id for a function like "__builtin_fabsf", return a
477 /// Function* for "fabsf".
478 cir::FuncOp getBuiltinLibFunction(const FunctionDecl *fd, unsigned builtinID);
479
480 mlir::IntegerAttr getSize(CharUnits size) {
481 return builder.getSizeFromCharUnits(size);
482 }
483
484 /// Emit any needed decls for which code generation was deferred.
485 void emitDeferred();
486
487 /// Helper for `emitDeferred` to apply actual codegen.
488 void emitGlobalDecl(const clang::GlobalDecl &d);
489
490 const llvm::Triple &getTriple() const { return target.getTriple(); }
491
492 // Finalize CIR code generation.
493 void release();
494
495 /// -------
496 /// Visibility and Linkage
497 /// -------
498
499 static mlir::SymbolTable::Visibility
500 getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK);
501 static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(
502 clang::VisibilityAttr::VisibilityType visibility);
503 cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl);
504 cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd);
505 static mlir::SymbolTable::Visibility getMLIRVisibility(cir::GlobalOp op);
506 cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd,
507 GVALinkage linkage,
508 bool isConstantVariable);
509 void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f) {
510 cir::GlobalLinkageKind l = getFunctionLinkage(gd);
511 f.setLinkageAttr(cir::GlobalLinkageKindAttr::get(&getMLIRContext(), l));
512 mlir::SymbolTable::setSymbolVisibility(f,
514 }
515
516 cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd,
517 bool isConstant);
518
519 void addReplacement(llvm::StringRef name, mlir::Operation *op);
520
521 /// Helpers to emit "not yet implemented" error diagnostics
522 DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef);
523
524 template <typename T>
525 DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature,
526 const T &name) {
527 unsigned diagID =
528 diags.getCustomDiagID(DiagnosticsEngine::Error,
529 "ClangIR code gen Not Yet Implemented: %0: %1");
530 return diags.Report(loc, diagID) << feature << name;
531 }
532
533 DiagnosticBuilder errorNYI(mlir::Location loc, llvm::StringRef feature) {
534 // TODO: Convert the location to a SourceLocation
535 unsigned diagID = diags.getCustomDiagID(
536 DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
537 return diags.Report(diagID) << feature;
538 }
539
540 DiagnosticBuilder errorNYI(llvm::StringRef feature) const {
541 // TODO: Make a default location? currSrcLoc?
542 unsigned diagID = diags.getCustomDiagID(
543 DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
544 return diags.Report(diagID) << feature;
545 }
546
547 DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef);
548
549 template <typename T>
550 DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature,
551 const T &name) {
552 return errorNYI(loc.getBegin(), feature, name) << loc;
553 }
554
555private:
556 // An ordered map of canonical GlobalDecls to their mangled names.
557 llvm::MapVector<clang::GlobalDecl, llvm::StringRef> mangledDeclNames;
558 llvm::StringMap<clang::GlobalDecl, llvm::BumpPtrAllocator> manglings;
559
560 // FIXME: should we use llvm::TrackingVH<mlir::Operation> here?
561 typedef llvm::StringMap<mlir::Operation *> ReplacementsTy;
562 ReplacementsTy replacements;
563 /// Call replaceAllUsesWith on all pairs in replacements.
564 void applyReplacements();
565
566 /// A helper function to replace all uses of OldF to NewF that replace
567 /// the type of pointer arguments. This is not needed to tradtional
568 /// pipeline since LLVM has opaque pointers but CIR not.
569 void replacePointerTypeArgs(cir::FuncOp oldF, cir::FuncOp newF);
570
571 void setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op);
572
573 /// Map source language used to a CIR attribute.
574 std::optional<cir::SourceLanguage> getCIRSourceLanguage() const;
575};
576} // namespace CIRGen
577
578} // namespace clang
579
580#endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
Defines the SourceManager interface.
__device__ __2f16 float __ockl_bool s
__device__ __2f16 float c
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
Implements C++ ABI-specific code generation functions.
Abstract information about a function or function prototype.
Definition CIRGenCall.h:27
void emitCXXGlobalVarDeclInit(const VarDecl *varDecl, cir::GlobalOp addr, bool performInit)
Emit the function that initializes the specified global.
void replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old, cir::FuncOp newFn)
This function is called when we implement a function with no prototype, e.g.
llvm::StringRef getMangledName(clang::GlobalDecl gd)
cir::GlobalOp getOrCreateStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage)
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *derivedClass, llvm::iterator_range< CastExpr::path_const_iterator > path)
void setGlobalVisibility(mlir::Operation *op, const NamedDecl *d) const
Set the visibility for the given global.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
void emitDeferred()
Emit any needed decls for which code generation was deferred.
clang::ASTContext & getASTContext() const
cir::FuncOp getAddrOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
void emitTopLevelDecl(clang::Decl *decl)
CharUnits getDynamicOffsetAlignment(CharUnits actualBaseAlign, const CXXRecordDecl *baseDecl, CharUnits expectedTargetAlign)
TODO: Add TBAAAccessInfo.
void addReplacement(llvm::StringRef name, mlir::Operation *op)
mlir::Type convertType(clang::QualType type)
bool shouldEmitRTTI(bool forEH=false)
cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
bool mustBeEmitted(const clang::ValueDecl *d)
Determine whether the definition must be emitted; if this returns false, the definition can be emitte...
void constructAttributeList(CIRGenCalleeInfo calleeInfo, mlir::NamedAttrList &attrs)
Get the CIR attributes and calling convention to use for a particular function type.
mlir::IntegerAttr getSize(CharUnits size)
DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature, const T &name)
CIRGenBuilderTy & getBuilder()
void setDSOLocal(mlir::Operation *op) const
std::string getUniqueGlobalName(const std::string &baseName)
std::pair< cir::FuncType, cir::FuncOp > getAddrAndTypeOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
ItaniumVTableContext & getItaniumVTableContext()
void setGVProperties(mlir::Operation *op, const NamedDecl *d) const
Set visibility, dllimport/dllexport and dso_local.
cir::GlobalOp getOrCreateCIRGlobal(llvm::StringRef mangledName, mlir::Type ty, LangAS langAS, const VarDecl *d, ForDefinition_t isForDefinition)
If the specified mangled name is not in the module, create and return an mlir::GlobalOp value.
llvm::DenseMap< const Decl *, cir::GlobalOp > staticLocalDeclMap
clang::CharUnits getClassPointerAlignment(const clang::CXXRecordDecl *rd)
Return the best known alignment for an unknown pointer to a particular class.
void handleCXXStaticMemberVarInstantiation(VarDecl *vd)
Tell the consumer that this variable has been instantiated.
void emitGlobalDefinition(clang::GlobalDecl gd, mlir::Operation *op=nullptr)
clang::DiagnosticsEngine & getDiags() const
CharUnits getVBaseAlignment(CharUnits derivedAlign, const CXXRecordDecl *derived, const CXXRecordDecl *vbase)
Returns the assumed alignment of a virtual base of a class.
mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty, bool forEH=false)
Get the address of the RTTI descriptor for the given type.
clang::CharUnits getNaturalTypeAlignment(clang::QualType t, LValueBaseInfo *baseInfo)
FIXME: this could likely be a common helper and not necessarily related with codegen.
void setFunctionAttributes(GlobalDecl gd, cir::FuncOp f, bool isIncompleteFunction, bool isThunk)
Set function attributes for a function declaration.
static mlir::SymbolTable::Visibility getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK)
const ItaniumVTableContext & getItaniumVTableContext() const
const clang::TargetInfo & getTarget() const
cir::FuncOp getBuiltinLibFunction(const FunctionDecl *fd, unsigned builtinID)
Given a builtin id for a function like "__builtin_fabsf", return a Function* for "fabsf".
const llvm::Triple & getTriple() const
static mlir::SymbolTable::Visibility getMLIRVisibility(Visibility v)
void emitTentativeDefinition(const VarDecl *d)
cir::GlobalOp createOrReplaceCXXRuntimeVariable(mlir::Location loc, llvm::StringRef name, mlir::Type ty, cir::GlobalLinkageKind linkage, clang::CharUnits alignment)
Will return a global variable of the given type.
void emitGlobalDecl(const clang::GlobalDecl &d)
Helper for emitDeferred to apply actual codegen.
cir::FuncOp getOrCreateCIRFunction(llvm::StringRef mangledName, mlir::Type funcType, clang::GlobalDecl gd, bool forVTable, bool dontDefer=false, bool isThunk=false, ForDefinition_t isForDefinition=NotForDefinition, mlir::ArrayAttr extraAttrs={})
void emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative=false)
DiagnosticBuilder errorNYI(mlir::Location loc, llvm::StringRef feature)
cir::FuncOp getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType=nullptr, bool forVTable=false, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
Return the address of the given function.
void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op, GlobalDecl aliasGD, cir::FuncOp aliasee, cir::GlobalLinkageKind linkage)
void emitGlobalOpenACCDecl(const clang::OpenACCConstructDecl *cd)
void emitExplicitCastExprType(const ExplicitCastExpr *e, CIRGenFunction *cgf=nullptr)
Emit type info if type of an expression is a variably modified type.
const cir::CIRDataLayout getDataLayout() const
std::map< llvm::StringRef, clang::GlobalDecl > deferredDecls
This contains all the decls which have definitions but which are deferred for emission and therefore ...
mlir::Value getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty={}, ForDefinition_t isForDefinition=NotForDefinition)
Return the mlir::Value for the address of the given global variable.
static void setInitializer(cir::GlobalOp &op, mlir::Attribute value)
cir::GlobalViewAttr getAddrOfGlobalVarAttr(const VarDecl *d)
Return the mlir::GlobalViewAttr for the address of the given global.
cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd)
void updateCompletedType(const clang::TagDecl *td)
const clang::CodeGenOptions & getCodeGenOpts() const
const clang::LangOptions & getLangOpts() const
void addDeferredDeclToEmit(clang::GlobalDecl GD)
cir::FuncOp createCIRFunction(mlir::Location loc, llvm::StringRef name, cir::FuncType funcType, const clang::FunctionDecl *funcDecl)
const TargetCIRGenInfo & getTargetCIRGenInfo()
void emitCXXGlobalVarDeclInitFunc(const VarDecl *vd, cir::GlobalOp addr, bool performInit)
void setStaticLocalDeclAddress(const VarDecl *d, cir::GlobalOp c)
void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const
cir::FuncOp codegenCXXStructor(clang::GlobalDecl gd)
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
mlir::Operation * lastGlobalOp
static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(clang::VisibilityAttr::VisibilityType visibility)
llvm::StringMap< unsigned > cgGlobalNames
mlir::Operation * getGlobalValue(llvm::StringRef ref)
mlir::Value emitNullConstant(QualType t, mlir::Location loc)
Return the result of value-initializing the given type, i.e.
mlir::ModuleOp getModule() const
cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd, GVALinkage linkage, bool isConstantVariable)
mlir::MLIRContext & getMLIRContext()
mlir::Operation * getAddrOfGlobal(clang::GlobalDecl gd, ForDefinition_t isForDefinition=NotForDefinition)
DiagnosticBuilder errorNYI(llvm::StringRef feature) const
static cir::GlobalOp createGlobalOp(CIRGenModule &cgm, mlir::Location loc, llvm::StringRef name, mlir::Type t, bool isConstant=false, mlir::Operation *insertPoint=nullptr)
void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op)
cir::GlobalOp getStaticLocalDeclAddress(const VarDecl *d)
CIRGenCXXABI & getCXXABI() const
cir::GlobalViewAttr getAddrOfConstantStringFromLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
void emitDeclContext(const DeclContext *dc)
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
bool mayBeEmittedEagerly(const clang::ValueDecl *d)
Determine whether the definition can be emitted eagerly, or should be delayed until the end of the tr...
llvm::DenseMap< const clang::FieldDecl *, llvm::StringRef > lambdaFieldToName
Keep a map between lambda fields and names, this needs to be per module since lambdas might get gener...
DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature, const T &name)
cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd, bool isConstant)
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op)
CIRGenVTables & getVTables()
void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f)
std::vector< clang::GlobalDecl > deferredDeclsToEmit
void emitVTable(const CXXRecordDecl *rd)
This is a callback from Sema to tell us that a particular vtable is required to be emitted in this tr...
cir::GlobalLinkageKind getVTableLinkage(const CXXRecordDecl *rd)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e)
Return a constant array for the given string.
cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl)
void setCommonAttributes(GlobalDecl gd, mlir::Operation *op)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition CIRGenTypes.h:48
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1449
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Represents a ValueDecl that came out of a declarator.
Definition Decl.h:780
A little helper class used to produce diagnostics.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3862
Represents a function declaration or definition.
Definition Decl.h:2000
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
This represents a decl that may have a name.
Definition Decl.h:274
A (possibly-)qualified type.
Definition TypeBase.h:937
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1799
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3717
Exposes information about the current target.
Definition TargetInfo.h:226
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
Represents a variable declaration or definition.
Definition Decl.h:926
Defines the clang::TargetInfo interface.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition Linkage.h:72
const FunctionProtoType * T
LangAS
Defines the address space values used by the address space qualifier of QualType.
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition Visibility.h:34
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition Visibility.h:37
@ ProtectedVisibility
Objects with "protected" visibility are seen by the dynamic linker but always dynamically resolve to ...
Definition Visibility.h:42
@ DefaultVisibility
Objects with "default" visibility are seen by the dynamic linker and act like normal objects.
Definition Visibility.h:46