clang 23.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 "CIRGenCUDARuntime.h"
18#include "CIRGenCall.h"
19#include "CIRGenTypeCache.h"
20#include "CIRGenTypes.h"
21#include "CIRGenVTables.h"
22#include "CIRGenValue.h"
23
24#include "clang/AST/CharUnits.h"
27
28#include "TargetInfo.h"
29#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
30#include "mlir/IR/Builders.h"
31#include "mlir/IR/BuiltinOps.h"
32#include "mlir/IR/MLIRContext.h"
33#include "clang/AST/Decl.h"
37#include "llvm/ADT/StringRef.h"
38#include "llvm/TargetParser/Triple.h"
39
40namespace clang {
41class ASTContext;
42class CodeGenOptions;
43class Decl;
44class GlobalDecl;
45class LangOptions;
46class TargetInfo;
47class VarDecl;
48
49namespace CIRGen {
50
51class CIRGenFunction;
52class CIRGenCXXABI;
53
54enum ForDefinition_t : bool { NotForDefinition = false, ForDefinition = true };
55
56/// This class organizes the cross-function state that is used while generating
57/// CIR code.
58class CIRGenModule : public CIRGenTypeCache {
59 CIRGenModule(CIRGenModule &) = delete;
60 CIRGenModule &operator=(CIRGenModule &) = delete;
61
62public:
63 CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
64 const clang::CodeGenOptions &cgo,
66
68
69private:
70 mutable std::unique_ptr<TargetCIRGenInfo> theTargetCIRGenInfo;
71
72 CIRGenBuilderTy builder;
73
74 /// Hold Clang AST information.
75 clang::ASTContext &astContext;
76
77 const clang::LangOptions &langOpts;
78
79 const clang::CodeGenOptions &codeGenOpts;
80
81 /// A "module" matches a c/cpp source file: containing a list of functions.
82 mlir::ModuleOp theModule;
83
85
86 const clang::TargetInfo &target;
87
88 std::unique_ptr<CIRGenCXXABI> abi;
89
90 CIRGenTypes genTypes;
91
92 /// Holds information about C++ vtables.
93 CIRGenVTables vtables;
94
95 /// Holds the CUDA runtime
96 std::unique_ptr<CIRGenCUDARuntime> cudaRuntime;
97
98 /// Per-function codegen information. Updated everytime emitCIR is called
99 /// for FunctionDecls's.
100 CIRGenFunction *curCGF = nullptr;
101
103
104 /// Accumulated record layout entries, materialized in release().
105 llvm::SmallVector<mlir::NamedAttribute> recordLayoutEntries;
106
107 llvm::DenseSet<clang::GlobalDecl> diagnosedConflictingDefinitions;
108
109 /// A queue of (optional) vtables to consider emitting.
110 std::vector<const CXXRecordDecl *> deferredVTables;
111
112 /// A queue of (optional) vtables that may be emitted opportunistically.
113 std::vector<const CXXRecordDecl *> opportunisticVTables;
114
115 void createCUDARuntime();
116
117 /// A helper for constructAttributeList that handles return attributes.
118 void constructFunctionReturnAttributes(const CIRGenFunctionInfo &info,
119 const Decl *targetDecl, bool isThunk,
120 mlir::NamedAttrList &retAttrs);
121 /// A helper for constructAttributeList that handles argument attributes.
122 void constructFunctionArgumentAttributes(
123 const CIRGenFunctionInfo &info, bool isThunk,
125 /// A helper function for constructAttributeList that determines whether a
126 /// return value might have been discarded.
127 bool mayDropFunctionReturn(const ASTContext &context, QualType retTy);
128 /// A helper function for constructAttributeList that determines whether
129 /// `noundef` on a return is possible.
130 bool hasStrictReturn(QualType retTy, const Decl *targetDecl);
131
132 llvm::DenseMap<const Expr *, mlir::Operation *>
133 materializedGlobalTemporaryMap;
134
135public:
136 mlir::ModuleOp getModule() const { return theModule; }
137 CIRGenBuilderTy &getBuilder() { return builder; }
138
139 /// Queue a record layout entry for materialization in release().
140 void addRecordLayout(mlir::StringAttr name, cir::RecordLayoutAttr attr) {
141 recordLayoutEntries.push_back(mlir::NamedAttribute(name, attr));
142 }
143 clang::ASTContext &getASTContext() const { return astContext; }
144 const clang::TargetInfo &getTarget() const { return target; }
145 const clang::CodeGenOptions &getCodeGenOpts() const { return codeGenOpts; }
146 clang::DiagnosticsEngine &getDiags() const { return diags; }
147 CIRGenTypes &getTypes() { return genTypes; }
148 const clang::LangOptions &getLangOpts() const { return langOpts; }
149
150 CIRGenCXXABI &getCXXABI() const { return *abi; }
151 mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
152
154 // FIXME(cir): instead of creating a CIRDataLayout every time, set it as an
155 // attribute for the CIRModule class.
156 return cir::CIRDataLayout(theModule);
157 }
158
159 /// -------
160 /// Handling globals
161 /// -------
162
163 mlir::Operation *lastGlobalOp = nullptr;
164
165 /// Keep a map between lambda fields and names, this needs to be per module
166 /// since lambdas might get generated later as part of defered work, and since
167 /// the pointers are supposed to be uniqued, should be fine. Revisit this if
168 /// it ends up taking too much memory.
169 llvm::DenseMap<const clang::FieldDecl *, llvm::StringRef> lambdaFieldToName;
170 /// Map BlockAddrInfoAttr (function name, label name) to the corresponding CIR
171 /// LabelOp. This provides the main lookup table used to resolve block
172 /// addresses into their label operations.
173 llvm::DenseMap<cir::BlockAddrInfoAttr, cir::LabelOp> blockAddressInfoToLabel;
174 /// Map CIR BlockAddressOps directly to their resolved LabelOps.
175 /// Used once a block address has been successfully lowered to a label.
176 llvm::MapVector<cir::BlockAddressOp, cir::LabelOp> blockAddressToLabel;
177 /// Track CIR BlockAddressOps that cannot be resolved immediately
178 /// because their LabelOp has not yet been emitted. These entries
179 /// are solved later once the corresponding label is available.
180 llvm::DenseSet<cir::BlockAddressOp> unresolvedBlockAddressToLabel;
181 cir::LabelOp lookupBlockAddressInfo(cir::BlockAddrInfoAttr blockInfo);
182 void mapBlockAddress(cir::BlockAddrInfoAttr blockInfo, cir::LabelOp label);
183 void mapUnresolvedBlockAddress(cir::BlockAddressOp op);
184 void mapResolvedBlockAddress(cir::BlockAddressOp op, cir::LabelOp);
185 void updateResolvedBlockAddress(cir::BlockAddressOp op,
186 cir::LabelOp newLabel);
187 /// Tell the consumer that this variable has been instantiated.
189
190 llvm::DenseMap<const Decl *, cir::GlobalOp> staticLocalDeclMap;
191 llvm::DenseMap<const VarDecl *, cir::GlobalOp> initializerConstants;
192
193 mlir::Operation *getGlobalValue(llvm::StringRef ref);
194
195 cir::GlobalOp getStaticLocalDeclAddress(const VarDecl *d) {
196 return staticLocalDeclMap[d];
197 }
198
199 void setStaticLocalDeclAddress(const VarDecl *d, cir::GlobalOp c) {
201 }
202
203 cir::GlobalOp getOrCreateStaticVarDecl(const VarDecl &d,
204 cir::GlobalLinkageKind linkage);
205
206 Address createUnnamedGlobalFrom(const VarDecl &d, mlir::Attribute constAttr,
207 CharUnits align);
208
209 /// If the specified mangled name is not in the module, create and return an
210 /// mlir::GlobalOp value
211 cir::GlobalOp getOrCreateCIRGlobal(llvm::StringRef mangledName, mlir::Type ty,
212 LangAS langAS, const VarDecl *d,
213 ForDefinition_t isForDefinition);
214
215 cir::GlobalOp getOrCreateCIRGlobal(const VarDecl *d, mlir::Type ty,
216 ForDefinition_t isForDefinition);
217
218 static cir::GlobalOp
219 createGlobalOp(CIRGenModule &cgm, mlir::Location loc, llvm::StringRef name,
220 mlir::Type t, bool isConstant = false,
221 mlir::ptr::MemorySpaceAttrInterface addrSpace = {},
222 mlir::Operation *insertPoint = nullptr);
223
224 /// Add a global constructor or destructor to the module.
225 /// The priority is optional, if not specified, the default priority is used.
226 void addGlobalCtor(cir::FuncOp ctor,
227 std::optional<int> priority = std::nullopt);
228 void addGlobalDtor(cir::FuncOp dtor,
229 std::optional<int> priority = std::nullopt);
230
232 // In C23 (N3096) $6.7.10:
233 // """
234 // If any object is initialized with an empty initializer, then it is
235 // subject to default initialization:
236 // - if it is an aggregate, every member is initialized (recursively)
237 // according to these rules, and any padding is initialized to zero bits;
238 // - if it is a union, the first named member is initialized (recursively)
239 // according to these rules, and any padding is initialized to zero bits.
240 //
241 // If the aggregate or union contains elements or members that are
242 // aggregates or unions, these rules apply recursively to the subaggregates
243 // or contained unions.
244 //
245 // If there are fewer initializers in a brace-enclosed list than there are
246 // elements or members of an aggregate, or fewer characters in a string
247 // literal used to initialize an array of known size than there are elements
248 // in the array, the remainder of the aggregate is subject to default
249 // initialization.
250 // """
251 //
252 // The standard seems ambiguous in the following two areas:
253 // 1. For a union type with empty initializer, if the first named member is
254 // not the largest member, then the bytes comes after the first named member
255 // but before padding are left unspecified. An example is:
256 // union U { int a; long long b;};
257 // union U u = {}; // The first 4 bytes are 0, but 4-8 bytes are left
258 // unspecified.
259 //
260 // 2. It only mentions padding for empty initializer, but doesn't mention
261 // padding for a non empty initialization list. And if the aggregation or
262 // union contains elements or members that are aggregates or unions, and
263 // some are non empty initializers, while others are empty initializers,
264 // the padding initialization is unclear. An example is:
265 // struct S1 { int a; long long b; };
266 // struct S2 { char c; struct S1 s1; };
267 // // The values for paddings between s2.c and s2.s1.a, between s2.s1.a
268 // and s2.s1.b are unclear.
269 // struct S2 s2 = { 'c' };
270 //
271 // Here we choose to zero initiailize left bytes of a union type because
272 // projects like the Linux kernel are relying on this behavior. If we don't
273 // explicitly zero initialize them, the undef values can be optimized to
274 // return garbage data. We also choose to zero initialize paddings for
275 // aggregates and unions, no matter they are initialized by empty
276 // initializers or non empty initializers. This can provide a consistent
277 // behavior. So projects like the Linux kernel can rely on it.
278 return !getLangOpts().CPlusPlus;
279 }
280
281 llvm::StringMap<unsigned> cgGlobalNames;
282 std::string getUniqueGlobalName(const std::string &baseName);
283
284 /// Return the mlir::Value for the address of the given global variable.
285 /// If Ty is non-null and if the global doesn't exist, then it will be created
286 /// with the specified type instead of whatever the normal requested type
287 /// would be. If IsForDefinition is true, it is guaranteed that an actual
288 /// global with type Ty will be returned, not conversion of a variable with
289 /// the same mangled name but some other type.
290 mlir::Value
291 getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty = {},
292 ForDefinition_t isForDefinition = NotForDefinition);
293
294 /// Get or create a thunk function with the given name and type.
295 cir::FuncOp getAddrOfThunk(StringRef name, mlir::Type fnTy, GlobalDecl gd);
296
297 /// Return the mlir::GlobalViewAttr for the address of the given global.
298 cir::GlobalViewAttr getAddrOfGlobalVarAttr(const VarDecl *d);
299
301 const CXXRecordDecl *derivedClass,
302 llvm::iterator_range<CastExpr::path_const_iterator> path);
303
304 /// Get the CIR attributes and calling convention to use for a particular
305 /// function type.
306 ///
307 /// \param name - The function name.
308 /// \param info - The function type information.
309 /// \param calleeInfo - The callee information these attributes are being
310 /// constructed for. If valid, the attributes applied to this decl may
311 /// contribute to the function attributes and calling convention.
312 /// \param attrs [out] - On return, the attribute list to use.
313 /// \param callingConv [out] - On return, the calling convention to use.
314 /// \param sideEffect [out] - On return, the side effect type of the
315 /// attributes.
316 /// \param attrOnCallSite - Whether or not the attributes are on a call site.
317 /// \param isThunk - Whether the function is a thunk.
319 llvm::StringRef name, const CIRGenFunctionInfo &info,
320 CIRGenCalleeInfo calleeInfo, mlir::NamedAttrList &attrs,
322 mlir::NamedAttrList &retAttrs, cir::CallingConv &callingConv,
323 cir::SideEffect &sideEffect, bool attrOnCallSite, bool isThunk);
324 /// Helper function for constructAttributeList/others. Builds a set of
325 /// function attributes to add to a function based on language opts, codegen
326 /// opts, and some small properties.
327 void addDefaultFunctionAttributes(StringRef name, bool hasOptNoneAttr,
328 bool attrOnCallSite,
329 mlir::NamedAttrList &attrs);
330
331 /// Will return a global variable of the given type. If a variable with a
332 /// different type already exists then a new variable with the right type
333 /// will be created and all uses of the old variable will be replaced with a
334 /// bitcast to the new variable.
336 mlir::Location loc, llvm::StringRef name, mlir::Type ty,
337 cir::GlobalLinkageKind linkage, clang::CharUnits alignment);
338
339 void emitVTable(const CXXRecordDecl *rd);
340
341 /// Return the appropriate linkage for the vtable, VTT, and type information
342 /// of the given class.
343 cir::GlobalLinkageKind getVTableLinkage(const CXXRecordDecl *rd);
344
345 /// Get the address of the RTTI descriptor for the given type.
346 mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty,
347 bool forEH = false);
348
349 static mlir::SymbolTable::Visibility getMLIRVisibility(Visibility v) {
350 switch (v) {
352 return mlir::SymbolTable::Visibility::Public;
353 case HiddenVisibility:
354 return mlir::SymbolTable::Visibility::Private;
356 // The distinction between ProtectedVisibility and DefaultVisibility is
357 // that symbols with ProtectedVisibility, while visible to the dynamic
358 // linker like DefaultVisibility, are guaranteed to always dynamically
359 // resolve to a symbol in the current shared object. There is currently no
360 // equivalent MLIR visibility, so we fall back on the fact that the symbol
361 // is visible.
362 return mlir::SymbolTable::Visibility::Public;
363 }
364 llvm_unreachable("unknown visibility!");
365 }
366
367 llvm::DenseMap<mlir::Attribute, cir::GlobalOp> constantStringMap;
368
369 /// Return a constant array for the given string.
370 mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e);
371
372 /// Return a global symbol reference to a constant array for the given string
373 /// literal.
374 cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s,
375 llvm::StringRef name = ".str");
376
377 /// Return a global symbol reference to a constant array for the given string
378 /// literal.
379 cir::GlobalViewAttr
381 llvm::StringRef name = ".str");
382
383 /// Returns the address space for temporary allocations in the language. This
384 /// ensures that the allocated variable's address space matches the
385 /// expectations of the AST, rather than using the target's allocation address
386 /// space, which may lead to type mismatches in other parts of the IR.
388
389 /// Set attributes which are common to any form of a global definition (alias,
390 /// Objective-C method, function, global variable).
391 ///
392 /// NOTE: This should only be called for definitions.
393 void setCommonAttributes(GlobalDecl gd, mlir::Operation *op);
394
396
397 /// Helpers to convert the presumed location of Clang's SourceLocation to an
398 /// MLIR Location.
399 mlir::Location getLoc(clang::SourceLocation cLoc);
400 mlir::Location getLoc(clang::SourceRange cRange);
401
402 /// Return the best known alignment for an unknown pointer to a
403 /// particular class.
405
406 /// FIXME: this could likely be a common helper and not necessarily related
407 /// with codegen.
409 LValueBaseInfo *baseInfo = nullptr,
410 bool forPointeeType = false);
413 LValueBaseInfo *baseInfo = nullptr);
414
415 /// Returns the minimum object size for an object of the given class type
416 /// (or a class derived from it).
418
419 /// Returns the minimum object size for an object of the given type.
425
426 /// TODO: Add TBAAAccessInfo
428 const CXXRecordDecl *baseDecl,
429 CharUnits expectedTargetAlign);
430
431 /// Returns the assumed alignment of a virtual base of a class.
433 const CXXRecordDecl *derived,
434 const CXXRecordDecl *vbase);
435
436 cir::FuncOp
438 const CIRGenFunctionInfo *fnInfo = nullptr,
439 cir::FuncType fnType = nullptr, bool dontDefer = false,
440 ForDefinition_t isForDefinition = NotForDefinition) {
441 return getAddrAndTypeOfCXXStructor(gd, fnInfo, fnType, dontDefer,
442 isForDefinition)
443 .second;
444 }
445
446 std::pair<cir::FuncType, cir::FuncOp> getAddrAndTypeOfCXXStructor(
447 clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo = nullptr,
448 cir::FuncType fnType = nullptr, bool dontDefer = false,
449 ForDefinition_t isForDefinition = NotForDefinition);
450
451 mlir::Type getVTableComponentType();
452 CIRGenVTables &getVTables() { return vtables; }
453
455 return vtables.getItaniumVTableContext();
456 }
458 return vtables.getItaniumVTableContext();
459 }
460
461 /// This contains all the decls which have definitions but which are deferred
462 /// for emission and therefore should only be output if they are actually
463 /// used. If a decl is in this, then it is known to have not been referenced
464 /// yet.
465 std::map<llvm::StringRef, clang::GlobalDecl> deferredDecls;
466
467 // This is a list of deferred decls which we have seen that *are* actually
468 // referenced. These get code generated when the module is done.
469 std::vector<clang::GlobalDecl> deferredDeclsToEmit;
471 deferredDeclsToEmit.emplace_back(GD);
472 }
473
475
476 /// Determine whether the definition must be emitted; if this returns \c
477 /// false, the definition can be emitted lazily if it's used.
478 bool mustBeEmitted(const clang::ValueDecl *d);
479
480 /// Determine whether the definition can be emitted eagerly, or should be
481 /// delayed until the end of the translation unit. This is relevant for
482 /// definitions whose linkage can change, e.g. implicit function
483 /// instantiations which may later be explicitly instantiated.
485
486 bool verifyModule() const;
487
488 /// Return the address of the given function. If funcType is non-null, then
489 /// this function will use the specified type if it has to create it.
490 // TODO: this is a bit weird as `GetAddr` given we give back a FuncOp?
491 cir::FuncOp
492 getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType = nullptr,
493 bool forVTable = false, bool dontDefer = false,
494 ForDefinition_t isForDefinition = NotForDefinition);
495
496 mlir::Operation *
498 ForDefinition_t isForDefinition = NotForDefinition);
499
500 // Return whether RTTI information should be emitted for this target.
501 bool shouldEmitRTTI(bool forEH = false) {
502 return (forEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
503 !(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
504 getTriple().isNVPTX());
505 }
506
507 /// Emit type info if type of an expression is a variably modified
508 /// type. Also emit proper debug info for cast types.
510 CIRGenFunction *cgf = nullptr);
511
513 deferredVTables.push_back(rd);
514 }
515
516 /// Emit code for a single global function or variable declaration. Forward
517 /// declarations are emitted lazily.
519
520 void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op,
521 GlobalDecl aliasGD, cir::FuncOp aliasee,
522 cir::GlobalLinkageKind linkage);
523
524 mlir::Type convertType(clang::QualType type);
525
526 /// Set the visibility for the given global.
527 void setGlobalVisibility(mlir::Operation *op, const NamedDecl *d) const;
528 void setDSOLocal(mlir::Operation *op) const;
529 void setDSOLocal(cir::CIRGlobalValueInterface gv) const;
530
531 /// Set visibility, dllimport/dllexport and dso_local.
532 /// This must be called after dllimport/dllexport is set.
533 void setGVProperties(mlir::Operation *op, const NamedDecl *d) const;
534 void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const;
535
536 /// Set TLS mode for the given operation based on the given variable
537 /// declaration.
538 void setTLSMode(mlir::Operation *op, const VarDecl &d);
539
540 /// Get TLS mode from CodeGenOptions.
541 cir::TLS_Model getDefaultCIRTLSModel() const;
542
543 /// Set function attributes for a function declaration.
544 void setFunctionAttributes(GlobalDecl gd, cir::FuncOp f,
545 bool isIncompleteFunction, bool isThunk);
546
547 /// Set the CIR function attributes (Sext, zext, etc).
549 cir::FuncOp func, bool isThunk);
550
551 /// Set extra attributes (inline, etc.) for a function.
553 cir::FuncOp f);
554
556 mlir::Operation *op = nullptr);
557 void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
559 bool isTentative = false);
560
561 /// Emit the function that initializes the specified global
562 void emitCXXGlobalVarDeclInit(const VarDecl *varDecl, cir::GlobalOp addr,
563 bool performInit);
564
565 void emitCXXGlobalVarDeclInitFunc(const VarDecl *vd, cir::GlobalOp addr,
566 bool performInit);
567
571 template <typename BeforeOpTy, typename DataClauseTy>
572 void emitGlobalOpenACCDeclareDataOperands(const Expr *varOperand,
573 DataClauseTy dataClause,
574 OpenACCModifierKind modifiers,
575 bool structured, bool implicit,
576 bool requiresDtor);
577 // Each of the acc.routine operations must have a unique name, so we just use
578 // an integer counter. This is how Flang does it, so it seems reasonable.
579 unsigned routineCounter = 0;
580 void emitOpenACCRoutineDecl(const clang::FunctionDecl *funcDecl,
581 cir::FuncOp func, SourceLocation pragmaLoc,
583
591
592 // C++ related functions.
593 void emitDeclContext(const DeclContext *dc);
594
595 /// Return the result of value-initializing the given type, i.e. a null
596 /// expression of the given type.
597 mlir::Value emitNullConstant(QualType t, mlir::Location loc);
598
599 mlir::TypedAttr emitNullConstantAttr(QualType t);
600
601 /// Return a null constant appropriate for zero-initializing a base class with
602 /// the given type. This is usually, but not always, an LLVM null constant.
603 mlir::TypedAttr emitNullConstantForBase(const CXXRecordDecl *record);
604
605 mlir::Value emitMemberPointerConstant(const UnaryOperator *e);
606 /// Returns a null attribute to represent either a null method or null data
607 /// member, depending on the type of mpt.
608 mlir::TypedAttr emitNullMemberAttr(QualType t, const MemberPointerType *mpt);
609
610 llvm::StringRef getMangledName(clang::GlobalDecl gd);
611 // This function is to support the OpenACC 'bind' clause, which names an
612 // alternate name for the function to be called by. This function mangles
613 // `attachedFunction` as-if its name was actually `bindName` (that is, with
614 // the same signature). It has some additional complications, as the 'bind'
615 // target is always going to be a global function, so member functions need an
616 // explicit instead of implicit 'this' parameter, and thus gets mangled
617 // differently.
618 std::string getOpenACCBindMangledName(const IdentifierInfo *bindName,
619 const FunctionDecl *attachedFunction);
620
621 void emitTentativeDefinition(const VarDecl *d);
622
623 // Make sure that this type is translated.
624 void updateCompletedType(const clang::TagDecl *td);
625
626 // Produce code for this constructor/destructor. This method doesn't try to
627 // apply any ABI rules about which other constructors/destructors are needed
628 // or if they are alias to each other.
630
631 bool lookupRepresentativeDecl(llvm::StringRef mangledName,
632 clang::GlobalDecl &gd) const;
633
634 bool supportsCOMDAT() const;
635 void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op);
636
637 static void setInitializer(cir::GlobalOp &op, mlir::Attribute value);
638
639 // Whether a global variable should be emitted by CUDA/HIP host/device
640 // related attributes.
641 bool shouldEmitCUDAGlobalVar(const VarDecl *global) const;
642
643 /// Replace all uses of the old global with the new global, updating types
644 /// and references as needed. Erases the old global when done.
645 void replaceGlobal(cir::GlobalOp oldGV, cir::GlobalOp newGV);
646
647 void replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old,
648 cir::FuncOp newFn);
649
650 cir::FuncOp
651 getOrCreateCIRFunction(llvm::StringRef mangledName, mlir::Type funcType,
652 clang::GlobalDecl gd, bool forVTable,
653 bool dontDefer = false, bool isThunk = false,
654 ForDefinition_t isForDefinition = NotForDefinition,
655 mlir::NamedAttrList extraAttrs = {});
656
657 cir::FuncOp getOrCreateCIRFunction(llvm::StringRef mangledName,
658 mlir::Type funcType, clang::GlobalDecl gd,
659 bool forVTable,
660 mlir::NamedAttrList extraAttrs) {
661 return getOrCreateCIRFunction(mangledName, funcType, gd, forVTable,
662 /*dontDefer=*/false, /*isThunk=*/false,
663 NotForDefinition, extraAttrs);
664 }
665
666 cir::FuncOp createCIRFunction(mlir::Location loc, llvm::StringRef name,
667 cir::FuncType funcType,
668 const clang::FunctionDecl *funcDecl);
669
670 /// Create a CIR function with builtin attribute set.
671 cir::FuncOp createCIRBuiltinFunction(mlir::Location loc, llvm::StringRef name,
672 cir::FuncType ty,
673 const clang::FunctionDecl *fd);
674
675 /// Mark the function as a special member (e.g. constructor, destructor)
676 void setCXXSpecialMemberAttr(cir::FuncOp funcOp,
677 const clang::FunctionDecl *funcDecl);
678
679 cir::FuncOp createRuntimeFunction(cir::FuncType ty, llvm::StringRef name,
680 mlir::NamedAttrList extraAttrs = {},
681 bool isLocal = false,
682 bool assumeConvergent = false);
683
684 static constexpr const char *builtinCoroId = "__builtin_coro_id";
685 static constexpr const char *builtinCoroAlloc = "__builtin_coro_alloc";
686 static constexpr const char *builtinCoroBegin = "__builtin_coro_begin";
687 static constexpr const char *builtinCoroEnd = "__builtin_coro_end";
688
689 /// Given a builtin id for a function like "__builtin_fabsf", return a
690 /// Function* for "fabsf".
691 cir::FuncOp getBuiltinLibFunction(const FunctionDecl *fd, unsigned builtinID);
692
694 assert(cudaRuntime != nullptr);
695 return *cudaRuntime;
696 }
697
698 mlir::IntegerAttr getSize(CharUnits size) {
699 return builder.getSizeFromCharUnits(size);
700 }
701
702 /// Emit any needed decls for which code generation was deferred.
703 void emitDeferred();
704
706 /// Emit any vtables which we deferred and still have a use for.
707 void emitDeferredVTables();
708
709 /// Try to emit external vtables as available_externally if they have emitted
710 /// all inlined virtual functions. It runs after EmitDeferred() and therefore
711 /// is not allowed to create new references to things that need to be emitted
712 /// lazily.
714
715 /// Helper for `emitDeferred` to apply actual codegen.
716 void emitGlobalDecl(const clang::GlobalDecl &d);
717
718 const llvm::Triple &getTriple() const { return target.getTriple(); }
719
720 // Finalize CIR code generation.
721 void release();
722
723 /// Returns a pointer to a global variable representing a temporary with
724 /// static or thread storage duration.
725 mlir::Operation *getAddrOfGlobalTemporary(const MaterializeTemporaryExpr *mte,
726 const Expr *init);
727
728 /// -------
729 /// Visibility and Linkage
730 /// -------
731
732 static mlir::SymbolTable::Visibility
733 getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK);
734 static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(
735 clang::VisibilityAttr::VisibilityType visibility);
736 cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl);
737 cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd);
738 static mlir::SymbolTable::Visibility getMLIRVisibility(cir::GlobalOp op);
739 cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd,
740 GVALinkage linkage,
741 bool isConstantVariable);
742 void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f) {
743 cir::GlobalLinkageKind l = getFunctionLinkage(gd);
744 f.setLinkageAttr(cir::GlobalLinkageKindAttr::get(&getMLIRContext(), l));
745 mlir::SymbolTable::setSymbolVisibility(f,
747 }
748
749 cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd,
750 bool isConstant);
751
752 void addReplacement(llvm::StringRef name, mlir::Operation *op);
753
754 /// Helpers to emit "not yet implemented" error diagnostics
755 DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef);
756
757 template <typename T>
758 DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature,
759 const T &name) {
760 unsigned diagID =
761 diags.getCustomDiagID(DiagnosticsEngine::Error,
762 "ClangIR code gen Not Yet Implemented: %0: %1");
763 return diags.Report(loc, diagID) << feature << name;
764 }
765
766 DiagnosticBuilder errorNYI(mlir::Location loc, llvm::StringRef feature) {
767 // TODO: Convert the location to a SourceLocation
768 unsigned diagID = diags.getCustomDiagID(
769 DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
770 return diags.Report(diagID) << feature;
771 }
772
773 DiagnosticBuilder errorNYI(llvm::StringRef feature) const {
774 // TODO: Make a default location? currSrcLoc?
775 unsigned diagID = diags.getCustomDiagID(
776 DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
777 return diags.Report(diagID) << feature;
778 }
779
780 DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef);
781
782 template <typename T>
783 DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature,
784 const T &name) {
785 return errorNYI(loc.getBegin(), feature, name) << loc;
786 }
787
788 /// Emit a general error that something can't be done.
789 void error(SourceLocation loc, llvm::StringRef error);
790
791 /// Print out an error that codegen doesn't support the specified stmt yet.
792 void errorUnsupported(const Stmt *s, llvm::StringRef type);
793
794 /// Print out an error that codegen doesn't support the specified decl yet.
795 void errorUnsupported(const Decl *d, llvm::StringRef type);
796
797 /// Emits AMDGPU specific Metadata.
798 void emitAMDGPUMetadata();
799
800private:
801 // An ordered map of canonical GlobalDecls to their mangled names.
802 llvm::MapVector<clang::GlobalDecl, llvm::StringRef> mangledDeclNames;
803 llvm::StringMap<clang::GlobalDecl, llvm::BumpPtrAllocator> manglings;
804
805 // FIXME: should we use llvm::TrackingVH<mlir::Operation> here?
806 llvm::MapVector<StringRef, mlir::Operation *> replacements;
807 /// Call replaceAllUsesWith on all pairs in replacements.
808 void applyReplacements();
809
810 void setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op);
811
812 /// Map source language used to a CIR attribute.
813 std::optional<cir::SourceLanguage> getCIRSourceLanguage() const;
814
815 /// Return the AST address space of the underlying global variable for D, as
816 /// determined by its declaration. Normally this is the same as the address
817 /// space of D's type, but in CUDA, address spaces are associated with
818 /// declarations, not types. If D is nullptr, return the default address
819 /// space for global variable.
820 ///
821 /// For languages without explicit address spaces, if D has default address
822 /// space, target-specific global or constant address space may be returned.
823 LangAS getGlobalVarAddressSpace(const VarDecl *decl);
824};
825} // namespace CIRGen
826
827} // namespace clang
828
829#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:226
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Implements C++ ABI-specific code generation functions.
Abstract information about a function or function prototype.
Definition CIRGenCall.h:27
void updateResolvedBlockAddress(cir::BlockAddressOp op, cir::LabelOp newLabel)
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.
static cir::GlobalOp createGlobalOp(CIRGenModule &cgm, mlir::Location loc, llvm::StringRef name, mlir::Type t, bool isConstant=false, mlir::ptr::MemorySpaceAttrInterface addrSpace={}, mlir::Operation *insertPoint=nullptr)
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)
CIRGenCUDARuntime & getCUDARuntime()
llvm::DenseMap< cir::BlockAddrInfoAttr, cir::LabelOp > blockAddressInfoToLabel
Map BlockAddrInfoAttr (function name, label name) to the corresponding CIR LabelOp.
void emitTopLevelDecl(clang::Decl *decl)
CharUnits getDynamicOffsetAlignment(CharUnits actualBaseAlign, const CXXRecordDecl *baseDecl, CharUnits expectedTargetAlign)
TODO: Add TBAAAccessInfo.
void emitGlobalOpenACCDeclareDataOperands(const Expr *varOperand, DataClauseTy dataClause, OpenACCModifierKind modifiers, bool structured, bool implicit, bool requiresDtor)
void emitOMPDeclareMapper(const OMPDeclareMapperDecl *d)
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.
void emitOMPCapturedExpr(const OMPCapturedExprDecl *d)
llvm::DenseMap< const VarDecl *, cir::GlobalOp > initializerConstants
void mapUnresolvedBlockAddress(cir::BlockAddressOp op)
bool mustBeEmitted(const clang::ValueDecl *d)
Determine whether the definition must be emitted; if this returns false, the definition can be emitte...
void emitGlobalOpenACCDeclareDecl(const clang::OpenACCDeclareDecl *cd)
mlir::IntegerAttr getSize(CharUnits size)
void addDefaultFunctionAttributes(StringRef name, bool hasOptNoneAttr, bool attrOnCallSite, mlir::NamedAttrList &attrs)
Helper function for constructAttributeList/others.
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.
cir::FuncOp createCIRBuiltinFunction(mlir::Location loc, llvm::StringRef name, cir::FuncType ty, const clang::FunctionDecl *fd)
Create a CIR function with builtin attribute set.
llvm::DenseMap< const Decl *, cir::GlobalOp > staticLocalDeclMap
void emitGlobalOpenACCRoutineDecl(const clang::OpenACCRoutineDecl *cd)
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.
CharUnits getMinimumClassObjectSize(const CXXRecordDecl *cd)
Returns the minimum object size for an object of the given class type (or a class derived from it).
void emitOMPRequiresDecl(const OMPRequiresDecl *d)
void emitGlobalDefinition(clang::GlobalDecl gd, mlir::Operation *op=nullptr)
void mapResolvedBlockAddress(cir::BlockAddressOp op, cir::LabelOp)
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.
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
mlir::TypedAttr emitNullConstantForBase(const CXXRecordDecl *record)
Return a null constant appropriate for zero-initializing a base class with the given type.
void setCIRFunctionAttributes(GlobalDecl gd, const CIRGenFunctionInfo &info, cir::FuncOp func, bool isThunk)
Set the CIR function attributes (Sext, zext, etc).
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)
CharUnits getMinimumObjectSize(QualType ty)
Returns the minimum object size for an object of the given type.
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 emitOMPAllocateDecl(const OMPAllocateDecl *d)
void error(SourceLocation loc, llvm::StringRef error)
Emit a general error that something can't be done.
void emitGlobalDecl(const clang::GlobalDecl &d)
Helper for emitDeferred to apply actual codegen.
void emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative=false)
cir::FuncOp createRuntimeFunction(cir::FuncType ty, llvm::StringRef name, mlir::NamedAttrList extraAttrs={}, bool isLocal=false, bool assumeConvergent=false)
cir::FuncOp getAddrOfThunk(StringRef name, mlir::Type fnTy, GlobalDecl gd)
Get or create a thunk function with the given name and type.
void setTLSMode(mlir::Operation *op, const VarDecl &d)
Set TLS mode for the given operation based on the given variable declaration.
DiagnosticBuilder errorNYI(mlir::Location loc, llvm::StringRef feature)
void addRecordLayout(mlir::StringAttr name, cir::RecordLayoutAttr attr)
Queue a record layout entry for materialization in release().
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.
mlir::TypedAttr emitNullConstantAttr(QualType t)
void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op, GlobalDecl aliasGD, cir::FuncOp aliasee, cir::GlobalLinkageKind linkage)
mlir::Value emitMemberPointerConstant(const UnaryOperator *e)
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
mlir::Operation * getAddrOfGlobalTemporary(const MaterializeTemporaryExpr *mte, const Expr *init)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
std::map< llvm::StringRef, clang::GlobalDecl > deferredDecls
This contains all the decls which have definitions but which are deferred for emission and therefore ...
void errorUnsupported(const Stmt *s, llvm::StringRef type)
Print out an error that codegen doesn't support the specified stmt yet.
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.
void addGlobalCtor(cir::FuncOp ctor, std::optional< int > priority=std::nullopt)
Add a global constructor or destructor to the module.
cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd)
void updateCompletedType(const clang::TagDecl *td)
const clang::CodeGenOptions & getCodeGenOpts() const
void emitDeferredVTables()
Emit any vtables which we deferred and still have a use for.
const clang::LangOptions & getLangOpts() const
void constructAttributeList(llvm::StringRef name, const CIRGenFunctionInfo &info, CIRGenCalleeInfo calleeInfo, mlir::NamedAttrList &attrs, llvm::MutableArrayRef< mlir::NamedAttrList > argAttrs, mlir::NamedAttrList &retAttrs, cir::CallingConv &callingConv, cir::SideEffect &sideEffect, bool attrOnCallSite, bool isThunk)
Get the CIR attributes and calling convention to use for a particular function type.
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::NamedAttrList extraAttrs={})
void emitOpenACCRoutineDecl(const clang::FunctionDecl *funcDecl, cir::FuncOp func, SourceLocation pragmaLoc, ArrayRef< const OpenACCClause * > clauses)
static constexpr const char * builtinCoroAlloc
void emitVTablesOpportunistically()
Try to emit external vtables as available_externally if they have emitted all inlined virtual functio...
cir::TLS_Model getDefaultCIRTLSModel() const
Get TLS mode from CodeGenOptions.
void addGlobalDtor(cir::FuncOp dtor, std::optional< int > priority=std::nullopt)
Add a function to the list that will be called when the module is unloaded.
void addDeferredDeclToEmit(clang::GlobalDecl GD)
bool shouldEmitCUDAGlobalVar(const VarDecl *global) const
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 addDeferredVTable(const CXXRecordDecl *rd)
void setStaticLocalDeclAddress(const VarDecl *d, cir::GlobalOp c)
void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const
LangAS getLangTempAllocaAddressSpace() const
Returns the address space for temporary allocations in the language.
llvm::DenseSet< cir::BlockAddressOp > unresolvedBlockAddressToLabel
Track CIR BlockAddressOps that cannot be resolved immediately because their LabelOp has not yet been ...
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.
llvm::DenseMap< mlir::Attribute, cir::GlobalOp > constantStringMap
mlir::Operation * lastGlobalOp
void replaceGlobal(cir::GlobalOp oldGV, cir::GlobalOp newGV)
Replace all uses of the old global with the new global, updating types and references as needed.
static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(clang::VisibilityAttr::VisibilityType visibility)
llvm::StringMap< unsigned > cgGlobalNames
void setCXXSpecialMemberAttr(cir::FuncOp funcOp, const clang::FunctionDecl *funcDecl)
Mark the function as a special member (e.g. constructor, destructor)
mlir::TypedAttr emitNullMemberAttr(QualType t, const MemberPointerType *mpt)
Returns a null attribute to represent either a null method or null data member, depending on the type...
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.
void emitOMPDeclareReduction(const OMPDeclareReductionDecl *d)
mlir::ModuleOp getModule() const
clang::CharUnits getNaturalTypeAlignment(clang::QualType t, LValueBaseInfo *baseInfo=nullptr, bool forPointeeType=false)
FIXME: this could likely be a common helper and not necessarily related with codegen.
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
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.
llvm::MapVector< cir::BlockAddressOp, cir::LabelOp > blockAddressToLabel
Map CIR BlockAddressOps directly to their resolved LabelOps.
bool lookupRepresentativeDecl(llvm::StringRef mangledName, clang::GlobalDecl &gd) const
void emitDeclContext(const DeclContext *dc)
static constexpr const char * builtinCoroBegin
static constexpr const char * builtinCoroId
cir::FuncOp getOrCreateCIRFunction(llvm::StringRef mangledName, mlir::Type funcType, clang::GlobalDecl gd, bool forVTable, mlir::NamedAttrList extraAttrs)
clang::CharUnits getNaturalPointeeTypeAlignment(clang::QualType t, LValueBaseInfo *baseInfo=nullptr)
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
cir::LabelOp lookupBlockAddressInfo(cir::BlockAddrInfoAttr blockInfo)
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 mapBlockAddress(cir::BlockAddrInfoAttr blockInfo, cir::LabelOp label)
static constexpr const char * builtinCoroEnd
void setCIRFunctionAttributesForDefinition(const clang::FunctionDecl *fd, cir::FuncOp f)
Set extra attributes (inline, etc.) for a function.
std::string getOpenACCBindMangledName(const IdentifierInfo *bindName, const FunctionDecl *attachedFunction)
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...
void emitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *d)
void emitAMDGPUMetadata()
Emits AMDGPU specific Metadata.
void emitOMPGroupPrivateDecl(const OMPGroupPrivateDecl *d)
cir::GlobalLinkageKind getVTableLinkage(const CXXRecordDecl *rd)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
Address createUnnamedGlobalFrom(const VarDecl &d, mlir::Attribute constAttr, CharUnits align)
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:1462
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:233
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3931
This represents one expression.
Definition Expr.h:112
Represents a function declaration or definition.
Definition Decl.h:2015
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4917
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3703
This represents a decl that may have a name.
Definition Decl.h:274
This represents 'pragma omp allocate ...' directive.
Definition DeclOpenMP.h:536
Pseudo declaration for capturing expressions.
Definition DeclOpenMP.h:445
This represents 'pragma omp declare mapper ...' directive.
Definition DeclOpenMP.h:349
This represents 'pragma omp declare reduction ...' directive.
Definition DeclOpenMP.h:239
This represents 'pragma omp groupprivate ...' directive.
Definition DeclOpenMP.h:173
This represents 'pragma omp requires...' directive.
Definition DeclOpenMP.h:479
This represents 'pragma omp threadprivate ...' directive.
Definition DeclOpenMP.h:110
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
Stmt - This represents one statement.
Definition Stmt.h:86
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1802
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3732
Exposes information about the current target.
Definition TargetInfo.h:227
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2247
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
OpenACCModifierKind
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