/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/CodeGen/CodeGenFunction.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- 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-function state used for llvm translation. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H |
14 | | #define LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H |
15 | | |
16 | | #include "CGBuilder.h" |
17 | | #include "CGDebugInfo.h" |
18 | | #include "CGLoopInfo.h" |
19 | | #include "CGValue.h" |
20 | | #include "CodeGenModule.h" |
21 | | #include "CodeGenPGO.h" |
22 | | #include "EHScopeStack.h" |
23 | | #include "VarBypassDetector.h" |
24 | | #include "clang/AST/CharUnits.h" |
25 | | #include "clang/AST/CurrentSourceLocExprScope.h" |
26 | | #include "clang/AST/ExprCXX.h" |
27 | | #include "clang/AST/ExprObjC.h" |
28 | | #include "clang/AST/ExprOpenMP.h" |
29 | | #include "clang/AST/StmtOpenMP.h" |
30 | | #include "clang/AST/Type.h" |
31 | | #include "clang/Basic/ABI.h" |
32 | | #include "clang/Basic/CapturedStmt.h" |
33 | | #include "clang/Basic/CodeGenOptions.h" |
34 | | #include "clang/Basic/OpenMPKinds.h" |
35 | | #include "clang/Basic/TargetInfo.h" |
36 | | #include "llvm/ADT/ArrayRef.h" |
37 | | #include "llvm/ADT/DenseMap.h" |
38 | | #include "llvm/ADT/MapVector.h" |
39 | | #include "llvm/ADT/SmallVector.h" |
40 | | #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" |
41 | | #include "llvm/IR/ValueHandle.h" |
42 | | #include "llvm/Support/Debug.h" |
43 | | #include "llvm/Transforms/Utils/SanitizerStats.h" |
44 | | |
45 | | namespace llvm { |
46 | | class BasicBlock; |
47 | | class LLVMContext; |
48 | | class MDNode; |
49 | | class SwitchInst; |
50 | | class Twine; |
51 | | class Value; |
52 | | class CanonicalLoopInfo; |
53 | | } |
54 | | |
55 | | namespace clang { |
56 | | class ASTContext; |
57 | | class CXXDestructorDecl; |
58 | | class CXXForRangeStmt; |
59 | | class CXXTryStmt; |
60 | | class Decl; |
61 | | class LabelDecl; |
62 | | class FunctionDecl; |
63 | | class FunctionProtoType; |
64 | | class LabelStmt; |
65 | | class ObjCContainerDecl; |
66 | | class ObjCInterfaceDecl; |
67 | | class ObjCIvarDecl; |
68 | | class ObjCMethodDecl; |
69 | | class ObjCImplementationDecl; |
70 | | class ObjCPropertyImplDecl; |
71 | | class TargetInfo; |
72 | | class VarDecl; |
73 | | class ObjCForCollectionStmt; |
74 | | class ObjCAtTryStmt; |
75 | | class ObjCAtThrowStmt; |
76 | | class ObjCAtSynchronizedStmt; |
77 | | class ObjCAutoreleasePoolStmt; |
78 | | class OMPUseDevicePtrClause; |
79 | | class OMPUseDeviceAddrClause; |
80 | | class SVETypeFlags; |
81 | | class OMPExecutableDirective; |
82 | | |
83 | | namespace analyze_os_log { |
84 | | class OSLogBufferLayout; |
85 | | } |
86 | | |
87 | | namespace CodeGen { |
88 | | class CodeGenTypes; |
89 | | class CGCallee; |
90 | | class CGFunctionInfo; |
91 | | class CGBlockInfo; |
92 | | class CGCXXABI; |
93 | | class BlockByrefHelpers; |
94 | | class BlockByrefInfo; |
95 | | class BlockFieldFlags; |
96 | | class RegionCodeGenTy; |
97 | | class TargetCodeGenInfo; |
98 | | struct OMPTaskDataTy; |
99 | | struct CGCoroData; |
100 | | |
101 | | /// The kind of evaluation to perform on values of a particular |
102 | | /// type. Basically, is the code in CGExprScalar, CGExprComplex, or |
103 | | /// CGExprAgg? |
104 | | /// |
105 | | /// TODO: should vectors maybe be split out into their own thing? |
106 | | enum TypeEvaluationKind { |
107 | | TEK_Scalar, |
108 | | TEK_Complex, |
109 | | TEK_Aggregate |
110 | | }; |
111 | | |
112 | | #define LIST_SANITIZER_CHECKS \ |
113 | | SANITIZER_CHECK(AddOverflow, add_overflow, 0) \ |
114 | | SANITIZER_CHECK(BuiltinUnreachable, builtin_unreachable, 0) \ |
115 | | SANITIZER_CHECK(CFICheckFail, cfi_check_fail, 0) \ |
116 | | SANITIZER_CHECK(DivremOverflow, divrem_overflow, 0) \ |
117 | | SANITIZER_CHECK(DynamicTypeCacheMiss, dynamic_type_cache_miss, 0) \ |
118 | | SANITIZER_CHECK(FloatCastOverflow, float_cast_overflow, 0) \ |
119 | | SANITIZER_CHECK(FunctionTypeMismatch, function_type_mismatch, 1) \ |
120 | | SANITIZER_CHECK(ImplicitConversion, implicit_conversion, 0) \ |
121 | | SANITIZER_CHECK(InvalidBuiltin, invalid_builtin, 0) \ |
122 | | SANITIZER_CHECK(InvalidObjCCast, invalid_objc_cast, 0) \ |
123 | | SANITIZER_CHECK(LoadInvalidValue, load_invalid_value, 0) \ |
124 | | SANITIZER_CHECK(MissingReturn, missing_return, 0) \ |
125 | | SANITIZER_CHECK(MulOverflow, mul_overflow, 0) \ |
126 | | SANITIZER_CHECK(NegateOverflow, negate_overflow, 0) \ |
127 | | SANITIZER_CHECK(NullabilityArg, nullability_arg, 0) \ |
128 | | SANITIZER_CHECK(NullabilityReturn, nullability_return, 1) \ |
129 | | SANITIZER_CHECK(NonnullArg, nonnull_arg, 0) \ |
130 | | SANITIZER_CHECK(NonnullReturn, nonnull_return, 1) \ |
131 | | SANITIZER_CHECK(OutOfBounds, out_of_bounds, 0) \ |
132 | | SANITIZER_CHECK(PointerOverflow, pointer_overflow, 0) \ |
133 | | SANITIZER_CHECK(ShiftOutOfBounds, shift_out_of_bounds, 0) \ |
134 | | SANITIZER_CHECK(SubOverflow, sub_overflow, 0) \ |
135 | | SANITIZER_CHECK(TypeMismatch, type_mismatch, 1) \ |
136 | | SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0) \ |
137 | | SANITIZER_CHECK(VLABoundNotPositive, vla_bound_not_positive, 0) |
138 | | |
139 | | enum SanitizerHandler { |
140 | | #define SANITIZER_CHECK(Enum, Name, Version) Enum, |
141 | | LIST_SANITIZER_CHECKS |
142 | | #undef SANITIZER_CHECK |
143 | | }; |
144 | | |
145 | | /// Helper class with most of the code for saving a value for a |
146 | | /// conditional expression cleanup. |
147 | | struct DominatingLLVMValue { |
148 | | typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type; |
149 | | |
150 | | /// Answer whether the given value needs extra work to be saved. |
151 | 263 | static bool needsSaving(llvm::Value *value) { |
152 | | // If it's not an instruction, we don't need to save. |
153 | 263 | if (!isa<llvm::Instruction>(value)) return false55 ; |
154 | | |
155 | | // If it's an instruction in the entry block, we don't need to save. |
156 | 208 | llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent(); |
157 | 208 | return (block != &block->getParent()->getEntryBlock()); |
158 | 263 | } |
159 | | |
160 | | static saved_type save(CodeGenFunction &CGF, llvm::Value *value); |
161 | | static llvm::Value *restore(CodeGenFunction &CGF, saved_type value); |
162 | | }; |
163 | | |
164 | | /// A partial specialization of DominatingValue for llvm::Values that |
165 | | /// might be llvm::Instructions. |
166 | | template <class T> struct DominatingPointer<T,true> : DominatingLLVMValue { |
167 | | typedef T *type; |
168 | 68 | static type restore(CodeGenFunction &CGF, saved_type value) { |
169 | 68 | return static_cast<T*>(DominatingLLVMValue::restore(CGF, value)); |
170 | 68 | } |
171 | | }; |
172 | | |
173 | | /// A specialization of DominatingValue for Address. |
174 | | template <> struct DominatingValue<Address> { |
175 | | typedef Address type; |
176 | | |
177 | | struct saved_type { |
178 | | DominatingLLVMValue::saved_type SavedValue; |
179 | | llvm::Type *ElementType; |
180 | | CharUnits Alignment; |
181 | | }; |
182 | | |
183 | 0 | static bool needsSaving(type value) { |
184 | 0 | return DominatingLLVMValue::needsSaving(value.getPointer()); |
185 | 0 | } |
186 | 172 | static saved_type save(CodeGenFunction &CGF, type value) { |
187 | 172 | return { DominatingLLVMValue::save(CGF, value.getPointer()), |
188 | 172 | value.getElementType(), value.getAlignment() }; |
189 | 172 | } |
190 | 190 | static type restore(CodeGenFunction &CGF, saved_type value) { |
191 | 190 | return Address(DominatingLLVMValue::restore(CGF, value.SavedValue), |
192 | 190 | value.ElementType, value.Alignment); |
193 | 190 | } |
194 | | }; |
195 | | |
196 | | /// A specialization of DominatingValue for RValue. |
197 | | template <> struct DominatingValue<RValue> { |
198 | | typedef RValue type; |
199 | | class saved_type { |
200 | | enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral, |
201 | | AggregateAddress, ComplexAddress }; |
202 | | |
203 | | llvm::Value *Value; |
204 | | llvm::Type *ElementType; |
205 | | unsigned K : 3; |
206 | | unsigned Align : 29; |
207 | | saved_type(llvm::Value *v, llvm::Type *e, Kind k, unsigned a = 0) |
208 | 16 | : Value(v), ElementType(e), K(k), Align(a) {} |
209 | | |
210 | | public: |
211 | | static bool needsSaving(RValue value); |
212 | | static saved_type save(CodeGenFunction &CGF, RValue value); |
213 | | RValue restore(CodeGenFunction &CGF); |
214 | | |
215 | | // implementations in CGCleanup.cpp |
216 | | }; |
217 | | |
218 | 0 | static bool needsSaving(type value) { |
219 | 0 | return saved_type::needsSaving(value); |
220 | 0 | } |
221 | 16 | static saved_type save(CodeGenFunction &CGF, type value) { |
222 | 16 | return saved_type::save(CGF, value); |
223 | 16 | } |
224 | 0 | static type restore(CodeGenFunction &CGF, saved_type value) { |
225 | 0 | return value.restore(CGF); |
226 | 0 | } |
227 | | }; |
228 | | |
229 | | /// CodeGenFunction - This class organizes the per-function state that is used |
230 | | /// while generating LLVM code. |
231 | | class CodeGenFunction : public CodeGenTypeCache { |
232 | | CodeGenFunction(const CodeGenFunction &) = delete; |
233 | | void operator=(const CodeGenFunction &) = delete; |
234 | | |
235 | | friend class CGCXXABI; |
236 | | public: |
237 | | /// A jump destination is an abstract label, branching to which may |
238 | | /// require a jump out through normal cleanups. |
239 | | struct JumpDest { |
240 | 1.28M | JumpDest() : Block(nullptr), Index(0) {} |
241 | | JumpDest(llvm::BasicBlock *Block, EHScopeStack::stable_iterator Depth, |
242 | | unsigned Index) |
243 | 422k | : Block(Block), ScopeDepth(Depth), Index(Index) {} |
244 | | |
245 | 472k | bool isValid() const { return Block != nullptr; } |
246 | 1.44M | llvm::BasicBlock *getBlock() const { return Block; } |
247 | 197k | EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; } |
248 | 7.69k | unsigned getDestIndex() const { return Index; } |
249 | | |
250 | | // This should be used cautiously. |
251 | 154 | void setScopeDepth(EHScopeStack::stable_iterator depth) { |
252 | 154 | ScopeDepth = depth; |
253 | 154 | } |
254 | | |
255 | | private: |
256 | | llvm::BasicBlock *Block; |
257 | | EHScopeStack::stable_iterator ScopeDepth; |
258 | | unsigned Index; |
259 | | }; |
260 | | |
261 | | CodeGenModule &CGM; // Per-module state. |
262 | | const TargetInfo &Target; |
263 | | |
264 | | // For EH/SEH outlined funclets, this field points to parent's CGF |
265 | | CodeGenFunction *ParentCGF = nullptr; |
266 | | |
267 | | typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; |
268 | | LoopInfoStack LoopStack; |
269 | | CGBuilderTy Builder; |
270 | | |
271 | | // Stores variables for which we can't generate correct lifetime markers |
272 | | // because of jumps. |
273 | | VarBypassDetector Bypasses; |
274 | | |
275 | | /// List of recently emitted OMPCanonicalLoops. |
276 | | /// |
277 | | /// Since OMPCanonicalLoops are nested inside other statements (in particular |
278 | | /// CapturedStmt generated by OMPExecutableDirective and non-perfectly nested |
279 | | /// loops), we cannot directly call OMPEmitOMPCanonicalLoop and receive its |
280 | | /// llvm::CanonicalLoopInfo. Instead, we call EmitStmt and any |
281 | | /// OMPEmitOMPCanonicalLoop called by it will add its CanonicalLoopInfo to |
282 | | /// this stack when done. Entering a new loop requires clearing this list; it |
283 | | /// either means we start parsing a new loop nest (in which case the previous |
284 | | /// loop nest goes out of scope) or a second loop in the same level in which |
285 | | /// case it would be ambiguous into which of the two (or more) loops the loop |
286 | | /// nest would extend. |
287 | | SmallVector<llvm::CanonicalLoopInfo *, 4> OMPLoopNestStack; |
288 | | |
289 | | /// Number of nested loop to be consumed by the last surrounding |
290 | | /// loop-associated directive. |
291 | | int ExpectedOMPLoopDepth = 0; |
292 | | |
293 | | // CodeGen lambda for loops and support for ordered clause |
294 | | typedef llvm::function_ref<void(CodeGenFunction &, const OMPLoopDirective &, |
295 | | JumpDest)> |
296 | | CodeGenLoopTy; |
297 | | typedef llvm::function_ref<void(CodeGenFunction &, SourceLocation, |
298 | | const unsigned, const bool)> |
299 | | CodeGenOrderedTy; |
300 | | |
301 | | // Codegen lambda for loop bounds in worksharing loop constructs |
302 | | typedef llvm::function_ref<std::pair<LValue, LValue>( |
303 | | CodeGenFunction &, const OMPExecutableDirective &S)> |
304 | | CodeGenLoopBoundsTy; |
305 | | |
306 | | // Codegen lambda for loop bounds in dispatch-based loop implementation |
307 | | typedef llvm::function_ref<std::pair<llvm::Value *, llvm::Value *>( |
308 | | CodeGenFunction &, const OMPExecutableDirective &S, Address LB, |
309 | | Address UB)> |
310 | | CodeGenDispatchBoundsTy; |
311 | | |
312 | | /// CGBuilder insert helper. This function is called after an |
313 | | /// instruction is created using Builder. |
314 | | void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, |
315 | | llvm::BasicBlock *BB, |
316 | | llvm::BasicBlock::iterator InsertPt) const; |
317 | | |
318 | | /// CurFuncDecl - Holds the Decl for the current outermost |
319 | | /// non-closure context. |
320 | | const Decl *CurFuncDecl; |
321 | | /// CurCodeDecl - This is the inner-most code context, which includes blocks. |
322 | | const Decl *CurCodeDecl; |
323 | | const CGFunctionInfo *CurFnInfo; |
324 | | QualType FnRetTy; |
325 | | llvm::Function *CurFn = nullptr; |
326 | | |
327 | | /// Save Parameter Decl for coroutine. |
328 | | llvm::SmallVector<const ParmVarDecl *, 4> FnArgs; |
329 | | |
330 | | // Holds coroutine data if the current function is a coroutine. We use a |
331 | | // wrapper to manage its lifetime, so that we don't have to define CGCoroData |
332 | | // in this header. |
333 | | struct CGCoroInfo { |
334 | | std::unique_ptr<CGCoroData> Data; |
335 | | CGCoroInfo(); |
336 | | ~CGCoroInfo(); |
337 | | }; |
338 | | CGCoroInfo CurCoro; |
339 | | |
340 | 393 | bool isCoroutine() const { |
341 | 393 | return CurCoro.Data != nullptr; |
342 | 393 | } |
343 | | |
344 | | /// CurGD - The GlobalDecl for the current function being compiled. |
345 | | GlobalDecl CurGD; |
346 | | |
347 | | /// PrologueCleanupDepth - The cleanup depth enclosing all the |
348 | | /// cleanups associated with the parameters. |
349 | | EHScopeStack::stable_iterator PrologueCleanupDepth; |
350 | | |
351 | | /// ReturnBlock - Unified return block. |
352 | | JumpDest ReturnBlock; |
353 | | |
354 | | /// ReturnValue - The temporary alloca to hold the return |
355 | | /// value. This is invalid iff the function has no return value. |
356 | | Address ReturnValue = Address::invalid(); |
357 | | |
358 | | /// ReturnValuePointer - The temporary alloca to hold a pointer to sret. |
359 | | /// This is invalid if sret is not in use. |
360 | | Address ReturnValuePointer = Address::invalid(); |
361 | | |
362 | | /// If a return statement is being visited, this holds the return statment's |
363 | | /// result expression. |
364 | | const Expr *RetExpr = nullptr; |
365 | | |
366 | | /// Return true if a label was seen in the current scope. |
367 | 32.8k | bool hasLabelBeenSeenInCurrentScope() const { |
368 | 32.8k | if (CurLexicalScope) |
369 | 11.0k | return CurLexicalScope->hasLabels(); |
370 | 21.7k | return !LabelMap.empty(); |
371 | 32.8k | } |
372 | | |
373 | | /// AllocaInsertPoint - This is an instruction in the entry block before which |
374 | | /// we prefer to insert allocas. |
375 | | llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; |
376 | | |
377 | | private: |
378 | | /// PostAllocaInsertPt - This is a place in the prologue where code can be |
379 | | /// inserted that will be dominated by all the static allocas. This helps |
380 | | /// achieve two things: |
381 | | /// 1. Contiguity of all static allocas (within the prologue) is maintained. |
382 | | /// 2. All other prologue code (which are dominated by static allocas) do |
383 | | /// appear in the source order immediately after all static allocas. |
384 | | /// |
385 | | /// PostAllocaInsertPt will be lazily created when it is *really* required. |
386 | | llvm::AssertingVH<llvm::Instruction> PostAllocaInsertPt = nullptr; |
387 | | |
388 | | public: |
389 | | /// Return PostAllocaInsertPt. If it is not yet created, then insert it |
390 | | /// immediately after AllocaInsertPt. |
391 | 6.29k | llvm::Instruction *getPostAllocaInsertPoint() { |
392 | 6.29k | if (!PostAllocaInsertPt) { |
393 | 2.26k | assert(AllocaInsertPt && |
394 | 2.26k | "Expected static alloca insertion point at function prologue"); |
395 | 0 | assert(AllocaInsertPt->getParent()->isEntryBlock() && |
396 | 2.26k | "EBB should be entry block of the current code gen function"); |
397 | 0 | PostAllocaInsertPt = AllocaInsertPt->clone(); |
398 | 2.26k | PostAllocaInsertPt->setName("postallocapt"); |
399 | 2.26k | PostAllocaInsertPt->insertAfter(AllocaInsertPt); |
400 | 2.26k | } |
401 | | |
402 | 0 | return PostAllocaInsertPt; |
403 | 6.29k | } |
404 | | |
405 | | /// API for captured statement code generation. |
406 | | class CGCapturedStmtInfo { |
407 | | public: |
408 | | explicit CGCapturedStmtInfo(CapturedRegionKind K = CR_Default) |
409 | 40.2k | : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {} |
410 | | explicit CGCapturedStmtInfo(const CapturedStmt &S, |
411 | | CapturedRegionKind K = CR_Default) |
412 | 25.6k | : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) { |
413 | | |
414 | 25.6k | RecordDecl::field_iterator Field = |
415 | 25.6k | S.getCapturedRecordDecl()->field_begin(); |
416 | 25.6k | for (CapturedStmt::const_capture_iterator I = S.capture_begin(), |
417 | 25.6k | E = S.capture_end(); |
418 | 63.9k | I != E; ++I, ++Field38.2k ) { |
419 | 38.2k | if (I->capturesThis()) |
420 | 1.86k | CXXThisFieldDecl = *Field; |
421 | 36.4k | else if (I->capturesVariable()) |
422 | 14.9k | CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field; |
423 | 21.4k | else if (I->capturesVariableByCopy()) |
424 | 18.2k | CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field; |
425 | 38.2k | } |
426 | 25.6k | } |
427 | | |
428 | | virtual ~CGCapturedStmtInfo(); |
429 | | |
430 | 106k | CapturedRegionKind getKind() const { return Kind; } |
431 | | |
432 | 1.04k | virtual void setContextValue(llvm::Value *V) { ThisValue = V; } |
433 | | // Retrieve the value of the context parameter. |
434 | 2.11k | virtual llvm::Value *getContextValue() const { return ThisValue; } |
435 | | |
436 | | /// Lookup the captured field decl for a variable. |
437 | 30.8k | virtual const FieldDecl *lookup(const VarDecl *VD) const { |
438 | 30.8k | return CaptureFields.lookup(VD->getCanonicalDecl()); |
439 | 30.8k | } |
440 | | |
441 | 1.04k | bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; } |
442 | 1.06k | virtual FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; } |
443 | | |
444 | 0 | static bool classof(const CGCapturedStmtInfo *) { |
445 | 0 | return true; |
446 | 0 | } |
447 | | |
448 | | /// Emit the captured statement body. |
449 | 127 | virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S) { |
450 | 127 | CGF.incrementProfileCounter(S); |
451 | 127 | CGF.EmitStmt(S); |
452 | 127 | } |
453 | | |
454 | | /// Get the name of the capture helper. |
455 | 127 | virtual StringRef getHelperName() const { return "__captured_stmt"; } |
456 | | |
457 | | /// Get the CaptureFields |
458 | 6 | llvm::SmallDenseMap<const VarDecl *, FieldDecl *> getCaptureFields() { |
459 | 6 | return CaptureFields; |
460 | 6 | } |
461 | | |
462 | | private: |
463 | | /// The kind of captured statement being generated. |
464 | | CapturedRegionKind Kind; |
465 | | |
466 | | /// Keep the map between VarDecl and FieldDecl. |
467 | | llvm::SmallDenseMap<const VarDecl *, FieldDecl *> CaptureFields; |
468 | | |
469 | | /// The base address of the captured record, passed in as the first |
470 | | /// argument of the parallel region function. |
471 | | llvm::Value *ThisValue; |
472 | | |
473 | | /// Captured 'this' type. |
474 | | FieldDecl *CXXThisFieldDecl; |
475 | | }; |
476 | | CGCapturedStmtInfo *CapturedStmtInfo = nullptr; |
477 | | |
478 | | /// RAII for correct setting/restoring of CapturedStmtInfo. |
479 | | class CGCapturedStmtRAII { |
480 | | private: |
481 | | CodeGenFunction &CGF; |
482 | | CGCapturedStmtInfo *PrevCapturedStmtInfo; |
483 | | public: |
484 | | CGCapturedStmtRAII(CodeGenFunction &CGF, |
485 | | CGCapturedStmtInfo *NewCapturedStmtInfo) |
486 | 25.9k | : CGF(CGF), PrevCapturedStmtInfo(CGF.CapturedStmtInfo) { |
487 | 25.9k | CGF.CapturedStmtInfo = NewCapturedStmtInfo; |
488 | 25.9k | } |
489 | 25.9k | ~CGCapturedStmtRAII() { CGF.CapturedStmtInfo = PrevCapturedStmtInfo; } |
490 | | }; |
491 | | |
492 | | /// An abstract representation of regular/ObjC call/message targets. |
493 | | class AbstractCallee { |
494 | | /// The function declaration of the callee. |
495 | | const Decl *CalleeDecl; |
496 | | |
497 | | public: |
498 | 2.73k | AbstractCallee() : CalleeDecl(nullptr) {} |
499 | 294k | AbstractCallee(const FunctionDecl *FD) : CalleeDecl(FD) {} |
500 | 11.9k | AbstractCallee(const ObjCMethodDecl *OMD) : CalleeDecl(OMD) {} |
501 | 396k | bool hasFunctionDecl() const { |
502 | 396k | return isa_and_nonnull<FunctionDecl>(CalleeDecl); |
503 | 396k | } |
504 | 396k | const Decl *getDecl() const { return CalleeDecl; } |
505 | 365k | unsigned getNumParams() const { |
506 | 365k | if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) |
507 | 365k | return FD->getNumParams(); |
508 | 8 | return cast<ObjCMethodDecl>(CalleeDecl)->param_size(); |
509 | 365k | } |
510 | 276k | const ParmVarDecl *getParamDecl(unsigned I) const { |
511 | 276k | if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) |
512 | 276k | return FD->getParamDecl(I); |
513 | 7 | return *(cast<ObjCMethodDecl>(CalleeDecl)->param_begin() + I); |
514 | 276k | } |
515 | | }; |
516 | | |
517 | | /// Sanitizers enabled for this function. |
518 | | SanitizerSet SanOpts; |
519 | | |
520 | | /// True if CodeGen currently emits code implementing sanitizer checks. |
521 | | bool IsSanitizerScope = false; |
522 | | |
523 | | /// RAII object to set/unset CodeGenFunction::IsSanitizerScope. |
524 | | class SanitizerScope { |
525 | | CodeGenFunction *CGF; |
526 | | public: |
527 | | SanitizerScope(CodeGenFunction *CGF); |
528 | | ~SanitizerScope(); |
529 | | }; |
530 | | |
531 | | /// In C++, whether we are code generating a thunk. This controls whether we |
532 | | /// should emit cleanups. |
533 | | bool CurFuncIsThunk = false; |
534 | | |
535 | | /// In ARC, whether we should autorelease the return value. |
536 | | bool AutoreleaseResult = false; |
537 | | |
538 | | /// Whether we processed a Microsoft-style asm block during CodeGen. These can |
539 | | /// potentially set the return value. |
540 | | bool SawAsmBlock = false; |
541 | | |
542 | | const NamedDecl *CurSEHParent = nullptr; |
543 | | |
544 | | /// True if the current function is an outlined SEH helper. This can be a |
545 | | /// finally block or filter expression. |
546 | | bool IsOutlinedSEHHelper = false; |
547 | | |
548 | | /// True if CodeGen currently emits code inside presereved access index |
549 | | /// region. |
550 | | bool IsInPreservedAIRegion = false; |
551 | | |
552 | | /// True if the current statement has nomerge attribute. |
553 | | bool InNoMergeAttributedStmt = false; |
554 | | |
555 | | /// True if the current statement has noinline attribute. |
556 | | bool InNoInlineAttributedStmt = false; |
557 | | |
558 | | /// True if the current statement has always_inline attribute. |
559 | | bool InAlwaysInlineAttributedStmt = false; |
560 | | |
561 | | // The CallExpr within the current statement that the musttail attribute |
562 | | // applies to. nullptr if there is no 'musttail' on the current statement. |
563 | | const CallExpr *MustTailCall = nullptr; |
564 | | |
565 | | /// Returns true if a function must make progress, which means the |
566 | | /// mustprogress attribute can be added. |
567 | 231k | bool checkIfFunctionMustProgress() { |
568 | 231k | if (CGM.getCodeGenOpts().getFiniteLoops() == |
569 | 231k | CodeGenOptions::FiniteLoopsKind::Never) |
570 | 115 | return false; |
571 | | |
572 | | // C++11 and later guarantees that a thread eventually will do one of the |
573 | | // following (6.9.2.3.1 in C++11): |
574 | | // - terminate, |
575 | | // - make a call to a library I/O function, |
576 | | // - perform an access through a volatile glvalue, or |
577 | | // - perform a synchronization operation or an atomic operation. |
578 | | // |
579 | | // Hence each function is 'mustprogress' in C++11 or later. |
580 | 231k | return getLangOpts().CPlusPlus11; |
581 | 231k | } |
582 | | |
583 | | /// Returns true if a loop must make progress, which means the mustprogress |
584 | | /// attribute can be added. \p HasConstantCond indicates whether the branch |
585 | | /// condition is a known constant. |
586 | 19.8k | bool checkIfLoopMustProgress(bool HasConstantCond) { |
587 | 19.8k | if (CGM.getCodeGenOpts().getFiniteLoops() == |
588 | 19.8k | CodeGenOptions::FiniteLoopsKind::Always) |
589 | 155 | return true; |
590 | 19.6k | if (CGM.getCodeGenOpts().getFiniteLoops() == |
591 | 19.6k | CodeGenOptions::FiniteLoopsKind::Never) |
592 | 155 | return false; |
593 | | |
594 | | // If the containing function must make progress, loops also must make |
595 | | // progress (as in C++11 and later). |
596 | 19.5k | if (checkIfFunctionMustProgress()) |
597 | 18.4k | return true; |
598 | | |
599 | | // Now apply rules for plain C (see 6.8.5.6 in C11). |
600 | | // Loops with constant conditions do not have to make progress in any C |
601 | | // version. |
602 | 1.09k | if (HasConstantCond) |
603 | 278 | return false; |
604 | | |
605 | | // Loops with non-constant conditions must make progress in C11 and later. |
606 | 814 | return getLangOpts().C11; |
607 | 1.09k | } |
608 | | |
609 | | const CodeGen::CGBlockInfo *BlockInfo = nullptr; |
610 | | llvm::Value *BlockPointer = nullptr; |
611 | | |
612 | | llvm::DenseMap<const VarDecl *, FieldDecl *> LambdaCaptureFields; |
613 | | FieldDecl *LambdaThisCaptureField = nullptr; |
614 | | |
615 | | /// A mapping from NRVO variables to the flags used to indicate |
616 | | /// when the NRVO has been applied to this variable. |
617 | | llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags; |
618 | | |
619 | | EHScopeStack EHStack; |
620 | | llvm::SmallVector<char, 256> LifetimeExtendedCleanupStack; |
621 | | llvm::SmallVector<const JumpDest *, 2> SEHTryEpilogueStack; |
622 | | |
623 | | llvm::Instruction *CurrentFuncletPad = nullptr; |
624 | | |
625 | | class CallLifetimeEnd final : public EHScopeStack::Cleanup { |
626 | 0 | bool isRedundantBeforeReturn() override { return true; } |
627 | | |
628 | | llvm::Value *Addr; |
629 | | llvm::Value *Size; |
630 | | |
631 | | public: |
632 | | CallLifetimeEnd(Address addr, llvm::Value *size) |
633 | 4.77k | : Addr(addr.getPointer()), Size(size) {} |
634 | | |
635 | 4.91k | void Emit(CodeGenFunction &CGF, Flags flags) override { |
636 | 4.91k | CGF.EmitLifetimeEnd(Size, Addr); |
637 | 4.91k | } |
638 | | }; |
639 | | |
640 | | /// Header for data within LifetimeExtendedCleanupStack. |
641 | | struct LifetimeExtendedCleanupHeader { |
642 | | /// The size of the following cleanup object. |
643 | | unsigned Size; |
644 | | /// The kind of cleanup to push: a value from the CleanupKind enumeration. |
645 | | unsigned Kind : 31; |
646 | | /// Whether this is a conditional cleanup. |
647 | | unsigned IsConditional : 1; |
648 | | |
649 | 1.14k | size_t getSize() const { return Size; } |
650 | 570 | CleanupKind getKind() const { return (CleanupKind)Kind; } |
651 | 570 | bool isConditional() const { return IsConditional; } |
652 | | }; |
653 | | |
654 | | /// i32s containing the indexes of the cleanup destinations. |
655 | | Address NormalCleanupDest = Address::invalid(); |
656 | | |
657 | | unsigned NextCleanupDestIndex = 1; |
658 | | |
659 | | /// EHResumeBlock - Unified block containing a call to llvm.eh.resume. |
660 | | llvm::BasicBlock *EHResumeBlock = nullptr; |
661 | | |
662 | | /// The exception slot. All landing pads write the current exception pointer |
663 | | /// into this alloca. |
664 | | llvm::Value *ExceptionSlot = nullptr; |
665 | | |
666 | | /// The selector slot. Under the MandatoryCleanup model, all landing pads |
667 | | /// write the current selector value into this alloca. |
668 | | llvm::AllocaInst *EHSelectorSlot = nullptr; |
669 | | |
670 | | /// A stack of exception code slots. Entering an __except block pushes a slot |
671 | | /// on the stack and leaving pops one. The __exception_code() intrinsic loads |
672 | | /// a value from the top of the stack. |
673 | | SmallVector<Address, 1> SEHCodeSlotStack; |
674 | | |
675 | | /// Value returned by __exception_info intrinsic. |
676 | | llvm::Value *SEHInfo = nullptr; |
677 | | |
678 | | /// Emits a landing pad for the current EH stack. |
679 | | llvm::BasicBlock *EmitLandingPad(); |
680 | | |
681 | | llvm::BasicBlock *getInvokeDestImpl(); |
682 | | |
683 | | /// Parent loop-based directive for scan directive. |
684 | | const OMPExecutableDirective *OMPParentLoopDirectiveForScan = nullptr; |
685 | | llvm::BasicBlock *OMPBeforeScanBlock = nullptr; |
686 | | llvm::BasicBlock *OMPAfterScanBlock = nullptr; |
687 | | llvm::BasicBlock *OMPScanExitBlock = nullptr; |
688 | | llvm::BasicBlock *OMPScanDispatch = nullptr; |
689 | | bool OMPFirstScanLoop = false; |
690 | | |
691 | | /// Manages parent directive for scan directives. |
692 | | class ParentLoopDirectiveForScanRegion { |
693 | | CodeGenFunction &CGF; |
694 | | const OMPExecutableDirective *ParentLoopDirectiveForScan; |
695 | | |
696 | | public: |
697 | | ParentLoopDirectiveForScanRegion( |
698 | | CodeGenFunction &CGF, |
699 | | const OMPExecutableDirective &ParentLoopDirectiveForScan) |
700 | | : CGF(CGF), |
701 | 3.67k | ParentLoopDirectiveForScan(CGF.OMPParentLoopDirectiveForScan) { |
702 | 3.67k | CGF.OMPParentLoopDirectiveForScan = &ParentLoopDirectiveForScan; |
703 | 3.67k | } |
704 | 3.67k | ~ParentLoopDirectiveForScanRegion() { |
705 | 3.67k | CGF.OMPParentLoopDirectiveForScan = ParentLoopDirectiveForScan; |
706 | 3.67k | } |
707 | | }; |
708 | | |
709 | | template <class T> |
710 | 519 | typename DominatingValue<T>::saved_type saveValueInCond(T value) { |
711 | 519 | return DominatingValue<T>::save(*this, value); |
712 | 519 | } clang::CodeGen::DominatingValue<clang::CodeGen::Address>::saved_type clang::CodeGen::CodeGenFunction::saveValueInCond<clang::CodeGen::Address>(clang::CodeGen::Address) Line | Count | Source | 710 | 172 | typename DominatingValue<T>::saved_type saveValueInCond(T value) { | 711 | 172 | return DominatingValue<T>::save(*this, value); | 712 | 172 | } |
clang::CodeGen::DominatingValue<clang::QualType>::saved_type clang::CodeGen::CodeGenFunction::saveValueInCond<clang::QualType>(clang::QualType) Line | Count | Source | 710 | 96 | typename DominatingValue<T>::saved_type saveValueInCond(T value) { | 711 | 96 | return DominatingValue<T>::save(*this, value); | 712 | 96 | } |
clang::CodeGen::DominatingValue<llvm::Value*>::saved_type clang::CodeGen::CodeGenFunction::saveValueInCond<llvm::Value*>(llvm::Value*) Line | Count | Source | 710 | 75 | typename DominatingValue<T>::saved_type saveValueInCond(T value) { | 711 | 75 | return DominatingValue<T>::save(*this, value); | 712 | 75 | } |
clang::CodeGen::DominatingValue<void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType)>::saved_type clang::CodeGen::CodeGenFunction::saveValueInCond<void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType)>(void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType)) Line | Count | Source | 710 | 88 | typename DominatingValue<T>::saved_type saveValueInCond(T value) { | 711 | 88 | return DominatingValue<T>::save(*this, value); | 712 | 88 | } |
clang::CodeGen::DominatingValue<bool>::saved_type clang::CodeGen::CodeGenFunction::saveValueInCond<bool>(bool) Line | Count | Source | 710 | 88 | typename DominatingValue<T>::saved_type saveValueInCond(T value) { | 711 | 88 | return DominatingValue<T>::save(*this, value); | 712 | 88 | } |
Unexecuted instantiation: clang::CodeGen::DominatingValue<clang::CharUnits>::saved_type clang::CodeGen::CodeGenFunction::saveValueInCond<clang::CharUnits>(clang::CharUnits) |
713 | | |
714 | | class CGFPOptionsRAII { |
715 | | public: |
716 | | CGFPOptionsRAII(CodeGenFunction &CGF, FPOptions FPFeatures); |
717 | | CGFPOptionsRAII(CodeGenFunction &CGF, const Expr *E); |
718 | | ~CGFPOptionsRAII(); |
719 | | |
720 | | private: |
721 | | void ConstructorHelper(FPOptions FPFeatures); |
722 | | CodeGenFunction &CGF; |
723 | | FPOptions OldFPFeatures; |
724 | | llvm::fp::ExceptionBehavior OldExcept; |
725 | | llvm::RoundingMode OldRounding; |
726 | | Optional<CGBuilderTy::FastMathFlagGuard> FMFGuard; |
727 | | }; |
728 | | FPOptions CurFPFeatures; |
729 | | |
730 | | public: |
731 | | /// ObjCEHValueStack - Stack of Objective-C exception values, used for |
732 | | /// rethrows. |
733 | | SmallVector<llvm::Value*, 8> ObjCEHValueStack; |
734 | | |
735 | | /// A class controlling the emission of a finally block. |
736 | | class FinallyInfo { |
737 | | /// Where the catchall's edge through the cleanup should go. |
738 | | JumpDest RethrowDest; |
739 | | |
740 | | /// A function to call to enter the catch. |
741 | | llvm::FunctionCallee BeginCatchFn; |
742 | | |
743 | | /// An i1 variable indicating whether or not the @finally is |
744 | | /// running for an exception. |
745 | | llvm::AllocaInst *ForEHVar; |
746 | | |
747 | | /// An i8* variable into which the exception pointer to rethrow |
748 | | /// has been saved. |
749 | | llvm::AllocaInst *SavedExnVar; |
750 | | |
751 | | public: |
752 | | void enter(CodeGenFunction &CGF, const Stmt *Finally, |
753 | | llvm::FunctionCallee beginCatchFn, |
754 | | llvm::FunctionCallee endCatchFn, llvm::FunctionCallee rethrowFn); |
755 | | void exit(CodeGenFunction &CGF); |
756 | | }; |
757 | | |
758 | | /// Returns true inside SEH __try blocks. |
759 | 359k | bool isSEHTryScope() const { return !SEHTryEpilogueStack.empty(); } |
760 | | |
761 | | /// Returns true while emitting a cleanuppad. |
762 | 358k | bool isCleanupPadScope() const { |
763 | 358k | return CurrentFuncletPad && isa<llvm::CleanupPadInst>(CurrentFuncletPad)128 ; |
764 | 358k | } |
765 | | |
766 | | /// pushFullExprCleanup - Push a cleanup to be run at the end of the |
767 | | /// current full-expression. Safe against the possibility that |
768 | | /// we're currently inside a conditionally-evaluated expression. |
769 | | template <class T, class... As> |
770 | 8.84k | void pushFullExprCleanup(CleanupKind kind, As... A) { |
771 | | // If we're not in a conditional branch, or if none of the |
772 | | // arguments requires saving, then use the unconditional cleanup. |
773 | 8.84k | if (!isInConditionalBranch()) |
774 | 8.66k | return EHStack.pushCleanup<T>(kind, A...); |
775 | | |
776 | | // Stash values in a tuple so we can guarantee the order of saves. |
777 | 171 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; |
778 | 171 | SavedTuple Saved{saveValueInCond(A)...}; |
779 | | |
780 | 171 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; |
781 | 171 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); |
782 | 171 | initFullExprCleanup(); |
783 | 171 | } CGCall.cpp:void clang::CodeGen::CodeGenFunction::pushFullExprCleanup<(anonymous namespace)::DestroyUnpassedArg, clang::CodeGen::Address, clang::QualType>(clang::CodeGen::CleanupKind, clang::CodeGen::Address, clang::QualType) Line | Count | Source | 770 | 186 | void pushFullExprCleanup(CleanupKind kind, As... A) { | 771 | | // If we're not in a conditional branch, or if none of the | 772 | | // arguments requires saving, then use the unconditional cleanup. | 773 | 186 | if (!isInConditionalBranch()) | 774 | 178 | return EHStack.pushCleanup<T>(kind, A...); | 775 | | | 776 | | // Stash values in a tuple so we can guarantee the order of saves. | 777 | 8 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 778 | 8 | SavedTuple Saved{saveValueInCond(A)...}; | 779 | | | 780 | 8 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 781 | 8 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); | 782 | 8 | initFullExprCleanup(); | 783 | 8 | } |
void clang::CodeGen::CodeGenFunction::pushFullExprCleanup<clang::CodeGen::CodeGenFunction::CallLifetimeEnd, clang::CodeGen::Address, llvm::Value*>(clang::CodeGen::CleanupKind, clang::CodeGen::Address, llvm::Value*) Line | Count | Source | 770 | 809 | void pushFullExprCleanup(CleanupKind kind, As... A) { | 771 | | // If we're not in a conditional branch, or if none of the | 772 | | // arguments requires saving, then use the unconditional cleanup. | 773 | 809 | if (!isInConditionalBranch()) | 774 | 762 | return EHStack.pushCleanup<T>(kind, A...); | 775 | | | 776 | | // Stash values in a tuple so we can guarantee the order of saves. | 777 | 47 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 778 | 47 | SavedTuple Saved{saveValueInCond(A)...}; | 779 | | | 780 | 47 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 781 | 47 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); | 782 | 47 | initFullExprCleanup(); | 783 | 47 | } |
CGDecl.cpp:void clang::CodeGen::CodeGenFunction::pushFullExprCleanup<(anonymous namespace)::DestroyObject, clang::CodeGen::Address, clang::QualType, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType), bool>(clang::CodeGen::CleanupKind, clang::CodeGen::Address, clang::QualType, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType), bool) Line | Count | Source | 770 | 4.90k | void pushFullExprCleanup(CleanupKind kind, As... A) { | 771 | | // If we're not in a conditional branch, or if none of the | 772 | | // arguments requires saving, then use the unconditional cleanup. | 773 | 4.90k | if (!isInConditionalBranch()) | 774 | 4.81k | return EHStack.pushCleanup<T>(kind, A...); | 775 | | | 776 | | // Stash values in a tuple so we can guarantee the order of saves. | 777 | 88 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 778 | 88 | SavedTuple Saved{saveValueInCond(A)...}; | 779 | | | 780 | 88 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 781 | 88 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); | 782 | 88 | initFullExprCleanup(); | 783 | 88 | } |
CGDecl.cpp:void clang::CodeGen::CodeGenFunction::pushFullExprCleanup<(anonymous namespace)::IrregularPartialArrayDestroy, llvm::Value*, clang::CodeGen::Address, clang::QualType, clang::CharUnits, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType)>(clang::CodeGen::CleanupKind, llvm::Value*, clang::CodeGen::Address, clang::QualType, clang::CharUnits, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType)) Line | Count | Source | 770 | 78 | void pushFullExprCleanup(CleanupKind kind, As... A) { | 771 | | // If we're not in a conditional branch, or if none of the | 772 | | // arguments requires saving, then use the unconditional cleanup. | 773 | 78 | if (!isInConditionalBranch()) | 774 | 78 | return EHStack.pushCleanup<T>(kind, A...); | 775 | | | 776 | | // Stash values in a tuple so we can guarantee the order of saves. | 777 | 0 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 778 | 0 | SavedTuple Saved{saveValueInCond(A)...}; | 779 | |
| 780 | 0 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 781 | 0 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); | 782 | 0 | initFullExprCleanup(); | 783 | 0 | } |
CGDecl.cpp:void clang::CodeGen::CodeGenFunction::pushFullExprCleanup<(anonymous namespace)::RegularPartialArrayDestroy, llvm::Value*, llvm::Value*, clang::QualType, clang::CharUnits, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType)>(clang::CodeGen::CleanupKind, llvm::Value*, llvm::Value*, clang::QualType, clang::CharUnits, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType)) Line | Count | Source | 770 | 1.90k | void pushFullExprCleanup(CleanupKind kind, As... A) { | 771 | | // If we're not in a conditional branch, or if none of the | 772 | | // arguments requires saving, then use the unconditional cleanup. | 773 | 1.90k | if (!isInConditionalBranch()) | 774 | 1.90k | return EHStack.pushCleanup<T>(kind, A...); | 775 | | | 776 | | // Stash values in a tuple so we can guarantee the order of saves. | 777 | 0 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 778 | 0 | SavedTuple Saved{saveValueInCond(A)...}; | 779 | |
| 780 | 0 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 781 | 0 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); | 782 | 0 | initFullExprCleanup(); | 783 | 0 | } |
CGException.cpp:void clang::CodeGen::CodeGenFunction::pushFullExprCleanup<(anonymous namespace)::FreeException, llvm::Value*>(clang::CodeGen::CleanupKind, llvm::Value*) Line | Count | Source | 770 | 661 | void pushFullExprCleanup(CleanupKind kind, As... A) { | 771 | | // If we're not in a conditional branch, or if none of the | 772 | | // arguments requires saving, then use the unconditional cleanup. | 773 | 661 | if (!isInConditionalBranch()) | 774 | 648 | return EHStack.pushCleanup<T>(kind, A...); | 775 | | | 776 | | // Stash values in a tuple so we can guarantee the order of saves. | 777 | 13 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 778 | 13 | SavedTuple Saved{saveValueInCond(A)...}; | 779 | | | 780 | 13 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 781 | 13 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); | 782 | 13 | initFullExprCleanup(); | 783 | 13 | } |
CGObjC.cpp:void clang::CodeGen::CodeGenFunction::pushFullExprCleanup<(anonymous namespace)::CallObjCRelease, llvm::Value*>(clang::CodeGen::CleanupKind, llvm::Value*) Line | Count | Source | 770 | 297 | void pushFullExprCleanup(CleanupKind kind, As... A) { | 771 | | // If we're not in a conditional branch, or if none of the | 772 | | // arguments requires saving, then use the unconditional cleanup. | 773 | 297 | if (!isInConditionalBranch()) | 774 | 282 | return EHStack.pushCleanup<T>(kind, A...); | 775 | | | 776 | | // Stash values in a tuple so we can guarantee the order of saves. | 777 | 15 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 778 | 15 | SavedTuple Saved{saveValueInCond(A)...}; | 779 | | | 780 | 15 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 781 | 15 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); | 782 | 15 | initFullExprCleanup(); | 783 | 15 | } |
|
784 | | |
785 | | /// Queue a cleanup to be pushed after finishing the current full-expression, |
786 | | /// potentially with an active flag. |
787 | | template <class T, class... As> |
788 | 21 | void pushCleanupAfterFullExpr(CleanupKind Kind, As... A) { |
789 | 21 | if (!isInConditionalBranch()) |
790 | 21 | return pushCleanupAfterFullExprWithActiveFlag<T>(Kind, Address::invalid(), |
791 | 21 | A...); |
792 | | |
793 | 0 | Address ActiveFlag = createCleanupActiveFlag(); |
794 | 0 | assert(!DominatingValue<Address>::needsSaving(ActiveFlag) && |
795 | 0 | "cleanup active flag should never need saving"); |
796 | | |
797 | 0 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; |
798 | 0 | SavedTuple Saved{saveValueInCond(A)...}; |
799 | |
|
800 | 0 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; |
801 | 0 | pushCleanupAfterFullExprWithActiveFlag<CleanupType>(Kind, ActiveFlag, Saved); |
802 | 0 | } CGBuiltin.cpp:void clang::CodeGen::CodeGenFunction::pushCleanupAfterFullExpr<(anonymous namespace)::CallObjCArcUse, llvm::Value*>(clang::CodeGen::CleanupKind, llvm::Value*) Line | Count | Source | 788 | 4 | void pushCleanupAfterFullExpr(CleanupKind Kind, As... A) { | 789 | 4 | if (!isInConditionalBranch()) | 790 | 4 | return pushCleanupAfterFullExprWithActiveFlag<T>(Kind, Address::invalid(), | 791 | 4 | A...); | 792 | | | 793 | 0 | Address ActiveFlag = createCleanupActiveFlag(); | 794 | 0 | assert(!DominatingValue<Address>::needsSaving(ActiveFlag) && | 795 | 0 | "cleanup active flag should never need saving"); | 796 | | | 797 | 0 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 798 | 0 | SavedTuple Saved{saveValueInCond(A)...}; | 799 | |
| 800 | 0 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 801 | 0 | pushCleanupAfterFullExprWithActiveFlag<CleanupType>(Kind, ActiveFlag, Saved); | 802 | 0 | } |
void clang::CodeGen::CodeGenFunction::pushCleanupAfterFullExpr<clang::CodeGen::CodeGenFunction::CallLifetimeEnd, clang::CodeGen::Address, llvm::Value*>(clang::CodeGen::CleanupKind, clang::CodeGen::Address, llvm::Value*) Line | Count | Source | 788 | 17 | void pushCleanupAfterFullExpr(CleanupKind Kind, As... A) { | 789 | 17 | if (!isInConditionalBranch()) | 790 | 17 | return pushCleanupAfterFullExprWithActiveFlag<T>(Kind, Address::invalid(), | 791 | 17 | A...); | 792 | | | 793 | 0 | Address ActiveFlag = createCleanupActiveFlag(); | 794 | 0 | assert(!DominatingValue<Address>::needsSaving(ActiveFlag) && | 795 | 0 | "cleanup active flag should never need saving"); | 796 | | | 797 | 0 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; | 798 | 0 | SavedTuple Saved{saveValueInCond(A)...}; | 799 | |
| 800 | 0 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; | 801 | 0 | pushCleanupAfterFullExprWithActiveFlag<CleanupType>(Kind, ActiveFlag, Saved); | 802 | 0 | } |
|
803 | | |
804 | | template <class T, class... As> |
805 | | void pushCleanupAfterFullExprWithActiveFlag(CleanupKind Kind, |
806 | 570 | Address ActiveFlag, As... A) { |
807 | 570 | LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind, |
808 | 570 | ActiveFlag.isValid()}; |
809 | | |
810 | 570 | size_t OldSize = LifetimeExtendedCleanupStack.size(); |
811 | 570 | LifetimeExtendedCleanupStack.resize( |
812 | 570 | LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size + |
813 | 570 | (Header.IsConditional ? sizeof(ActiveFlag)29 : 0541 )); |
814 | | |
815 | 570 | static_assert(sizeof(Header) % alignof(T) == 0, |
816 | 570 | "Cleanup will be allocated on misaligned address"); |
817 | 570 | char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; |
818 | 570 | new (Buffer) LifetimeExtendedCleanupHeader(Header); |
819 | 570 | new (Buffer + sizeof(Header)) T(A...); |
820 | 570 | if (Header.IsConditional) |
821 | 29 | new (Buffer + sizeof(Header) + sizeof(T)) Address(ActiveFlag); |
822 | 570 | } CGBuiltin.cpp:void clang::CodeGen::CodeGenFunction::pushCleanupAfterFullExprWithActiveFlag<(anonymous namespace)::CallObjCArcUse, llvm::Value*>(clang::CodeGen::CleanupKind, clang::CodeGen::Address, llvm::Value*) Line | Count | Source | 806 | 4 | Address ActiveFlag, As... A) { | 807 | 4 | LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind, | 808 | 4 | ActiveFlag.isValid()}; | 809 | | | 810 | 4 | size_t OldSize = LifetimeExtendedCleanupStack.size(); | 811 | 4 | LifetimeExtendedCleanupStack.resize( | 812 | 4 | LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size + | 813 | 4 | (Header.IsConditional ? sizeof(ActiveFlag)0 : 0)); | 814 | | | 815 | 4 | static_assert(sizeof(Header) % alignof(T) == 0, | 816 | 4 | "Cleanup will be allocated on misaligned address"); | 817 | 4 | char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; | 818 | 4 | new (Buffer) LifetimeExtendedCleanupHeader(Header); | 819 | 4 | new (Buffer + sizeof(Header)) T(A...); | 820 | 4 | if (Header.IsConditional) | 821 | 0 | new (Buffer + sizeof(Header) + sizeof(T)) Address(ActiveFlag); | 822 | 4 | } |
Unexecuted instantiation: CGBuiltin.cpp:void clang::CodeGen::CodeGenFunction::pushCleanupAfterFullExprWithActiveFlag<clang::CodeGen::EHScopeStack::ConditionalCleanup<(anonymous namespace)::CallObjCArcUse, llvm::Value*>, std::__1::tuple<llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*> > > > >(clang::CodeGen::CleanupKind, clang::CodeGen::Address, std::__1::tuple<llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*> > > >) CGDecl.cpp:void clang::CodeGen::CodeGenFunction::pushCleanupAfterFullExprWithActiveFlag<(anonymous namespace)::DestroyObject, clang::CodeGen::Address, clang::QualType, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType), bool>(clang::CodeGen::CleanupKind, clang::CodeGen::Address, clang::CodeGen::Address, clang::QualType, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType), bool) Line | Count | Source | 806 | 520 | Address ActiveFlag, As... A) { | 807 | 520 | LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind, | 808 | 520 | ActiveFlag.isValid()}; | 809 | | | 810 | 520 | size_t OldSize = LifetimeExtendedCleanupStack.size(); | 811 | 520 | LifetimeExtendedCleanupStack.resize( | 812 | 520 | LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size + | 813 | 520 | (Header.IsConditional ? sizeof(ActiveFlag)0 : 0)); | 814 | | | 815 | 520 | static_assert(sizeof(Header) % alignof(T) == 0, | 816 | 520 | "Cleanup will be allocated on misaligned address"); | 817 | 520 | char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; | 818 | 520 | new (Buffer) LifetimeExtendedCleanupHeader(Header); | 819 | 520 | new (Buffer + sizeof(Header)) T(A...); | 820 | 520 | if (Header.IsConditional) | 821 | 0 | new (Buffer + sizeof(Header) + sizeof(T)) Address(ActiveFlag); | 822 | 520 | } |
CGDecl.cpp:void clang::CodeGen::CodeGenFunction::pushCleanupAfterFullExprWithActiveFlag<clang::CodeGen::EHScopeStack::ConditionalCleanup<(anonymous namespace)::DestroyObject, clang::CodeGen::Address, clang::QualType, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType), bool>, clang::CodeGen::DominatingValue<clang::CodeGen::Address>::saved_type, clang::QualType, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType), bool>(clang::CodeGen::CleanupKind, clang::CodeGen::Address, clang::CodeGen::DominatingValue<clang::CodeGen::Address>::saved_type, clang::QualType, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType), bool) Line | Count | Source | 806 | 29 | Address ActiveFlag, As... A) { | 807 | 29 | LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind, | 808 | 29 | ActiveFlag.isValid()}; | 809 | | | 810 | 29 | size_t OldSize = LifetimeExtendedCleanupStack.size(); | 811 | 29 | LifetimeExtendedCleanupStack.resize( | 812 | 29 | LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size + | 813 | 29 | (Header.IsConditional ? sizeof(ActiveFlag) : 00 )); | 814 | | | 815 | 29 | static_assert(sizeof(Header) % alignof(T) == 0, | 816 | 29 | "Cleanup will be allocated on misaligned address"); | 817 | 29 | char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; | 818 | 29 | new (Buffer) LifetimeExtendedCleanupHeader(Header); | 819 | 29 | new (Buffer + sizeof(Header)) T(A...); | 820 | 29 | if (Header.IsConditional) | 821 | 29 | new (Buffer + sizeof(Header) + sizeof(T)) Address(ActiveFlag); | 822 | 29 | } |
void clang::CodeGen::CodeGenFunction::pushCleanupAfterFullExprWithActiveFlag<clang::CodeGen::CodeGenFunction::CallLifetimeEnd, clang::CodeGen::Address, llvm::Value*>(clang::CodeGen::CleanupKind, clang::CodeGen::Address, clang::CodeGen::Address, llvm::Value*) Line | Count | Source | 806 | 17 | Address ActiveFlag, As... A) { | 807 | 17 | LifetimeExtendedCleanupHeader Header = {sizeof(T), Kind, | 808 | 17 | ActiveFlag.isValid()}; | 809 | | | 810 | 17 | size_t OldSize = LifetimeExtendedCleanupStack.size(); | 811 | 17 | LifetimeExtendedCleanupStack.resize( | 812 | 17 | LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size + | 813 | 17 | (Header.IsConditional ? sizeof(ActiveFlag)0 : 0)); | 814 | | | 815 | 17 | static_assert(sizeof(Header) % alignof(T) == 0, | 816 | 17 | "Cleanup will be allocated on misaligned address"); | 817 | 17 | char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; | 818 | 17 | new (Buffer) LifetimeExtendedCleanupHeader(Header); | 819 | 17 | new (Buffer + sizeof(Header)) T(A...); | 820 | 17 | if (Header.IsConditional) | 821 | 0 | new (Buffer + sizeof(Header) + sizeof(T)) Address(ActiveFlag); | 822 | 17 | } |
Unexecuted instantiation: void clang::CodeGen::CodeGenFunction::pushCleanupAfterFullExprWithActiveFlag<clang::CodeGen::EHScopeStack::ConditionalCleanup<clang::CodeGen::CodeGenFunction::CallLifetimeEnd, clang::CodeGen::Address, llvm::Value*>, std::__1::tuple<clang::CodeGen::DominatingValue<clang::CodeGen::Address>::saved_type, llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*> > > > >(clang::CodeGen::CleanupKind, clang::CodeGen::Address, std::__1::tuple<clang::CodeGen::DominatingValue<clang::CodeGen::Address>::saved_type, llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*> > > >) |
823 | | |
824 | | /// Set up the last cleanup that was pushed as a conditional |
825 | | /// full-expression cleanup. |
826 | 177 | void initFullExprCleanup() { |
827 | 177 | initFullExprCleanupWithFlag(createCleanupActiveFlag()); |
828 | 177 | } |
829 | | |
830 | | void initFullExprCleanupWithFlag(Address ActiveFlag); |
831 | | Address createCleanupActiveFlag(); |
832 | | |
833 | | /// PushDestructorCleanup - Push a cleanup to call the |
834 | | /// complete-object destructor of an object of the given type at the |
835 | | /// given address. Does nothing if T is not a C++ class type with a |
836 | | /// non-trivial destructor. |
837 | | void PushDestructorCleanup(QualType T, Address Addr); |
838 | | |
839 | | /// PushDestructorCleanup - Push a cleanup to call the |
840 | | /// complete-object variant of the given destructor on the object at |
841 | | /// the given address. |
842 | | void PushDestructorCleanup(const CXXDestructorDecl *Dtor, QualType T, |
843 | | Address Addr); |
844 | | |
845 | | /// PopCleanupBlock - Will pop the cleanup entry on the stack and |
846 | | /// process all branch fixups. |
847 | | void PopCleanupBlock(bool FallThroughIsBranchThrough = false); |
848 | | |
849 | | /// DeactivateCleanupBlock - Deactivates the given cleanup block. |
850 | | /// The block cannot be reactivated. Pops it if it's the top of the |
851 | | /// stack. |
852 | | /// |
853 | | /// \param DominatingIP - An instruction which is known to |
854 | | /// dominate the current IP (if set) and which lies along |
855 | | /// all paths of execution between the current IP and the |
856 | | /// the point at which the cleanup comes into scope. |
857 | | void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, |
858 | | llvm::Instruction *DominatingIP); |
859 | | |
860 | | /// ActivateCleanupBlock - Activates an initially-inactive cleanup. |
861 | | /// Cannot be used to resurrect a deactivated cleanup. |
862 | | /// |
863 | | /// \param DominatingIP - An instruction which is known to |
864 | | /// dominate the current IP (if set) and which lies along |
865 | | /// all paths of execution between the current IP and the |
866 | | /// the point at which the cleanup comes into scope. |
867 | | void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, |
868 | | llvm::Instruction *DominatingIP); |
869 | | |
870 | | /// Enters a new scope for capturing cleanups, all of which |
871 | | /// will be executed once the scope is exited. |
872 | | class RunCleanupsScope { |
873 | | EHScopeStack::stable_iterator CleanupStackDepth, OldCleanupScopeDepth; |
874 | | size_t LifetimeExtendedCleanupStackSize; |
875 | | bool OldDidCallStackSave; |
876 | | protected: |
877 | | bool PerformCleanup; |
878 | | private: |
879 | | |
880 | | RunCleanupsScope(const RunCleanupsScope &) = delete; |
881 | | void operator=(const RunCleanupsScope &) = delete; |
882 | | |
883 | | protected: |
884 | | CodeGenFunction& CGF; |
885 | | |
886 | | public: |
887 | | /// Enter a new cleanup scope. |
888 | | explicit RunCleanupsScope(CodeGenFunction &CGF) |
889 | | : PerformCleanup(true), CGF(CGF) |
890 | 999k | { |
891 | 999k | CleanupStackDepth = CGF.EHStack.stable_begin(); |
892 | 999k | LifetimeExtendedCleanupStackSize = |
893 | 999k | CGF.LifetimeExtendedCleanupStack.size(); |
894 | 999k | OldDidCallStackSave = CGF.DidCallStackSave; |
895 | 999k | CGF.DidCallStackSave = false; |
896 | 999k | OldCleanupScopeDepth = CGF.CurrentCleanupScopeDepth; |
897 | 999k | CGF.CurrentCleanupScopeDepth = CleanupStackDepth; |
898 | 999k | } |
899 | | |
900 | | /// Exit this cleanup scope, emitting any accumulated cleanups. |
901 | 999k | ~RunCleanupsScope() { |
902 | 999k | if (PerformCleanup) |
903 | 330k | ForceCleanup(); |
904 | 999k | } |
905 | | |
906 | | /// Determine whether this scope requires any cleanups. |
907 | 34.0k | bool requiresCleanups() const { |
908 | 34.0k | return CGF.EHStack.stable_begin() != CleanupStackDepth; |
909 | 34.0k | } |
910 | | |
911 | | /// Force the emission of cleanups now, instead of waiting |
912 | | /// until this object is destroyed. |
913 | | /// \param ValuesToReload - A list of values that need to be available at |
914 | | /// the insertion point after cleanup emission. If cleanup emission created |
915 | | /// a shared cleanup block, these value pointers will be rewritten. |
916 | | /// Otherwise, they not will be modified. |
917 | 999k | void ForceCleanup(std::initializer_list<llvm::Value**> ValuesToReload = {}) { |
918 | 999k | assert(PerformCleanup && "Already forced cleanup"); |
919 | 0 | CGF.DidCallStackSave = OldDidCallStackSave; |
920 | 999k | CGF.PopCleanupBlocks(CleanupStackDepth, LifetimeExtendedCleanupStackSize, |
921 | 999k | ValuesToReload); |
922 | 999k | PerformCleanup = false; |
923 | 999k | CGF.CurrentCleanupScopeDepth = OldCleanupScopeDepth; |
924 | 999k | } |
925 | | }; |
926 | | |
927 | | // Cleanup stack depth of the RunCleanupsScope that was pushed most recently. |
928 | | EHScopeStack::stable_iterator CurrentCleanupScopeDepth = |
929 | | EHScopeStack::stable_end(); |
930 | | |
931 | | class LexicalScope : public RunCleanupsScope { |
932 | | SourceRange Range; |
933 | | SmallVector<const LabelDecl*, 4> Labels; |
934 | | LexicalScope *ParentScope; |
935 | | |
936 | | LexicalScope(const LexicalScope &) = delete; |
937 | | void operator=(const LexicalScope &) = delete; |
938 | | |
939 | | public: |
940 | | /// Enter a new cleanup scope. |
941 | | explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range) |
942 | 321k | : RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) { |
943 | 321k | CGF.CurLexicalScope = this; |
944 | 321k | if (CGDebugInfo *DI = CGF.getDebugInfo()) |
945 | 211k | DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin()); |
946 | 321k | } |
947 | | |
948 | 0 | void addLabel(const LabelDecl *label) { |
949 | 0 | assert(PerformCleanup && "adding label to dead scope?"); |
950 | 0 | Labels.push_back(label); |
951 | 0 | } |
952 | | |
953 | | /// Exit this cleanup scope, emitting any accumulated |
954 | | /// cleanups. |
955 | 321k | ~LexicalScope() { |
956 | 321k | if (CGDebugInfo *DI = CGF.getDebugInfo()) |
957 | 211k | DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd()); |
958 | | |
959 | | // If we should perform a cleanup, force them now. Note that |
960 | | // this ends the cleanup scope before rescoping any labels. |
961 | 321k | if (PerformCleanup) { |
962 | 286k | ApplyDebugLocation DL(CGF, Range.getEnd()); |
963 | 286k | ForceCleanup(); |
964 | 286k | } |
965 | 321k | } |
966 | | |
967 | | /// Force the emission of cleanups now, instead of waiting |
968 | | /// until this object is destroyed. |
969 | 321k | void ForceCleanup() { |
970 | 321k | CGF.CurLexicalScope = ParentScope; |
971 | 321k | RunCleanupsScope::ForceCleanup(); |
972 | | |
973 | 321k | if (!Labels.empty()) |
974 | 0 | rescopeLabels(); |
975 | 321k | } |
976 | | |
977 | 11.0k | bool hasLabels() const { |
978 | 11.0k | return !Labels.empty(); |
979 | 11.0k | } |
980 | | |
981 | | void rescopeLabels(); |
982 | | }; |
983 | | |
984 | | typedef llvm::DenseMap<const Decl *, Address> DeclMapTy; |
985 | | |
986 | | /// The class used to assign some variables some temporarily addresses. |
987 | | class OMPMapVars { |
988 | | DeclMapTy SavedLocals; |
989 | | DeclMapTy SavedTempAddresses; |
990 | | OMPMapVars(const OMPMapVars &) = delete; |
991 | | void operator=(const OMPMapVars &) = delete; |
992 | | |
993 | | public: |
994 | 153k | explicit OMPMapVars() = default; |
995 | 153k | ~OMPMapVars() { |
996 | 153k | assert(SavedLocals.empty() && "Did not restored original addresses."); |
997 | 153k | }; |
998 | | |
999 | | /// Sets the address of the variable \p LocalVD to be \p TempAddr in |
1000 | | /// function \p CGF. |
1001 | | /// \return true if at least one variable was set already, false otherwise. |
1002 | | bool setVarAddr(CodeGenFunction &CGF, const VarDecl *LocalVD, |
1003 | 175k | Address TempAddr) { |
1004 | 175k | LocalVD = LocalVD->getCanonicalDecl(); |
1005 | | // Only save it once. |
1006 | 175k | if (SavedLocals.count(LocalVD)) return false20.7k ; |
1007 | | |
1008 | | // Copy the existing local entry to SavedLocals. |
1009 | 154k | auto it = CGF.LocalDeclMap.find(LocalVD); |
1010 | 154k | if (it != CGF.LocalDeclMap.end()) |
1011 | 54.4k | SavedLocals.try_emplace(LocalVD, it->second); |
1012 | 99.8k | else |
1013 | 99.8k | SavedLocals.try_emplace(LocalVD, Address::invalid()); |
1014 | | |
1015 | | // Generate the private entry. |
1016 | 154k | QualType VarTy = LocalVD->getType(); |
1017 | 154k | if (VarTy->isReferenceType()) { |
1018 | 4.54k | Address Temp = CGF.CreateMemTemp(VarTy); |
1019 | 4.54k | CGF.Builder.CreateStore(TempAddr.getPointer(), Temp); |
1020 | 4.54k | TempAddr = Temp; |
1021 | 4.54k | } |
1022 | 154k | SavedTempAddresses.try_emplace(LocalVD, TempAddr); |
1023 | | |
1024 | 154k | return true; |
1025 | 175k | } |
1026 | | |
1027 | | /// Applies new addresses to the list of the variables. |
1028 | | /// \return true if at least one variable is using new address, false |
1029 | | /// otherwise. |
1030 | 140k | bool apply(CodeGenFunction &CGF) { |
1031 | 140k | copyInto(SavedTempAddresses, CGF.LocalDeclMap); |
1032 | 140k | SavedTempAddresses.clear(); |
1033 | 140k | return !SavedLocals.empty(); |
1034 | 140k | } |
1035 | | |
1036 | | /// Restores original addresses of the variables. |
1037 | 153k | void restore(CodeGenFunction &CGF) { |
1038 | 153k | if (!SavedLocals.empty()) { |
1039 | 84.2k | copyInto(SavedLocals, CGF.LocalDeclMap); |
1040 | 84.2k | SavedLocals.clear(); |
1041 | 84.2k | } |
1042 | 153k | } |
1043 | | |
1044 | | private: |
1045 | | /// Copy all the entries in the source map over the corresponding |
1046 | | /// entries in the destination, which must exist. |
1047 | 224k | static void copyInto(const DeclMapTy &Src, DeclMapTy &Dest) { |
1048 | 308k | for (auto &Pair : Src) { |
1049 | 308k | if (!Pair.second.isValid()) { |
1050 | 99.8k | Dest.erase(Pair.first); |
1051 | 99.8k | continue; |
1052 | 99.8k | } |
1053 | | |
1054 | 208k | auto I = Dest.find(Pair.first); |
1055 | 208k | if (I != Dest.end()) |
1056 | 108k | I->second = Pair.second; |
1057 | 99.8k | else |
1058 | 99.8k | Dest.insert(Pair); |
1059 | 208k | } |
1060 | 224k | } |
1061 | | }; |
1062 | | |
1063 | | /// The scope used to remap some variables as private in the OpenMP loop body |
1064 | | /// (or other captured region emitted without outlining), and to restore old |
1065 | | /// vars back on exit. |
1066 | | class OMPPrivateScope : public RunCleanupsScope { |
1067 | | OMPMapVars MappedVars; |
1068 | | OMPPrivateScope(const OMPPrivateScope &) = delete; |
1069 | | void operator=(const OMPPrivateScope &) = delete; |
1070 | | |
1071 | | public: |
1072 | | /// Enter a new OpenMP private scope. |
1073 | 134k | explicit OMPPrivateScope(CodeGenFunction &CGF) : RunCleanupsScope(CGF) {} |
1074 | | |
1075 | | /// Registers \p LocalVD variable as a private with \p Addr as the address |
1076 | | /// of the corresponding private variable. \p |
1077 | | /// PrivateGen is the address of the generated private variable. |
1078 | | /// \return true if the variable is registered as private, false if it has |
1079 | | /// been privatized already. |
1080 | 154k | bool addPrivate(const VarDecl *LocalVD, Address Addr) { |
1081 | 154k | assert(PerformCleanup && "adding private to dead scope"); |
1082 | 0 | return MappedVars.setVarAddr(CGF, LocalVD, Addr); |
1083 | 154k | } |
1084 | | |
1085 | | /// Privatizes local variables previously registered as private. |
1086 | | /// Registration is separate from the actual privatization to allow |
1087 | | /// initializers use values of the original variables, not the private one. |
1088 | | /// This is important, for example, if the private variable is a class |
1089 | | /// variable initialized by a constructor that references other private |
1090 | | /// variables. But at initialization original variables must be used, not |
1091 | | /// private copies. |
1092 | | /// \return true if at least one variable was privatized, false otherwise. |
1093 | 120k | bool Privatize() { return MappedVars.apply(CGF); } |
1094 | | |
1095 | 134k | void ForceCleanup() { |
1096 | 134k | RunCleanupsScope::ForceCleanup(); |
1097 | 134k | MappedVars.restore(CGF); |
1098 | 134k | } |
1099 | | |
1100 | | /// Exit scope - all the mapped variables are restored. |
1101 | 134k | ~OMPPrivateScope() { |
1102 | 134k | if (PerformCleanup) |
1103 | 108k | ForceCleanup(); |
1104 | 134k | } |
1105 | | |
1106 | | /// Checks if the global variable is captured in current function. |
1107 | 7.20k | bool isGlobalVarCaptured(const VarDecl *VD) const { |
1108 | 7.20k | VD = VD->getCanonicalDecl(); |
1109 | 7.20k | return !VD->isLocalVarDeclOrParm() && CGF.LocalDeclMap.count(VD) > 0905 ; |
1110 | 7.20k | } |
1111 | | }; |
1112 | | |
1113 | | /// Save/restore original map of previously emitted local vars in case when we |
1114 | | /// need to duplicate emission of the same code several times in the same |
1115 | | /// function for OpenMP code. |
1116 | | class OMPLocalDeclMapRAII { |
1117 | | CodeGenFunction &CGF; |
1118 | | DeclMapTy SavedMap; |
1119 | | |
1120 | | public: |
1121 | | OMPLocalDeclMapRAII(CodeGenFunction &CGF) |
1122 | 13.9k | : CGF(CGF), SavedMap(CGF.LocalDeclMap) {} |
1123 | 13.9k | ~OMPLocalDeclMapRAII() { SavedMap.swap(CGF.LocalDeclMap); } |
1124 | | }; |
1125 | | |
1126 | | /// Takes the old cleanup stack size and emits the cleanup blocks |
1127 | | /// that have been added. |
1128 | | void |
1129 | | PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, |
1130 | | std::initializer_list<llvm::Value **> ValuesToReload = {}); |
1131 | | |
1132 | | /// Takes the old cleanup stack size and emits the cleanup blocks |
1133 | | /// that have been added, then adds all lifetime-extended cleanups from |
1134 | | /// the given position to the stack. |
1135 | | void |
1136 | | PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, |
1137 | | size_t OldLifetimeExtendedStackSize, |
1138 | | std::initializer_list<llvm::Value **> ValuesToReload = {}); |
1139 | | |
1140 | | void ResolveBranchFixups(llvm::BasicBlock *Target); |
1141 | | |
1142 | | /// The given basic block lies in the current EH scope, but may be a |
1143 | | /// target of a potentially scope-crossing jump; get a stable handle |
1144 | | /// to which we can perform this jump later. |
1145 | 422k | JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { |
1146 | 422k | return JumpDest(Target, |
1147 | 422k | EHStack.getInnermostNormalCleanup(), |
1148 | 422k | NextCleanupDestIndex++); |
1149 | 422k | } |
1150 | | |
1151 | | /// The given basic block lies in the current EH scope, but may be a |
1152 | | /// target of a potentially scope-crossing jump; get a stable handle |
1153 | | /// to which we can perform this jump later. |
1154 | 413k | JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) { |
1155 | 413k | return getJumpDestInCurrentScope(createBasicBlock(Name)); |
1156 | 413k | } |
1157 | | |
1158 | | /// EmitBranchThroughCleanup - Emit a branch from the current insert |
1159 | | /// block through the normal cleanup handling code (if any) and then |
1160 | | /// on to \arg Dest. |
1161 | | void EmitBranchThroughCleanup(JumpDest Dest); |
1162 | | |
1163 | | /// isObviouslyBranchWithoutCleanups - Return true if a branch to the |
1164 | | /// specified destination obviously has no cleanups to run. 'false' is always |
1165 | | /// a conservatively correct answer for this method. |
1166 | | bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const; |
1167 | | |
1168 | | /// popCatchScope - Pops the catch scope at the top of the EHScope |
1169 | | /// stack, emitting any required code (other than the catch handlers |
1170 | | /// themselves). |
1171 | | void popCatchScope(); |
1172 | | |
1173 | | llvm::BasicBlock *getEHResumeBlock(bool isCleanup); |
1174 | | llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope); |
1175 | | llvm::BasicBlock * |
1176 | | getFuncletEHDispatchBlock(EHScopeStack::stable_iterator scope); |
1177 | | |
1178 | | /// An object to manage conditionally-evaluated expressions. |
1179 | | class ConditionalEvaluation { |
1180 | | llvm::BasicBlock *StartBB; |
1181 | | |
1182 | | public: |
1183 | | ConditionalEvaluation(CodeGenFunction &CGF) |
1184 | 21.6k | : StartBB(CGF.Builder.GetInsertBlock()) {} |
1185 | | |
1186 | 31.3k | void begin(CodeGenFunction &CGF) { |
1187 | 31.3k | assert(CGF.OutermostConditional != this); |
1188 | 31.3k | if (!CGF.OutermostConditional) |
1189 | 31.1k | CGF.OutermostConditional = this; |
1190 | 31.3k | } |
1191 | | |
1192 | 31.3k | void end(CodeGenFunction &CGF) { |
1193 | 31.3k | assert(CGF.OutermostConditional != nullptr); |
1194 | 31.3k | if (CGF.OutermostConditional == this) |
1195 | 31.1k | CGF.OutermostConditional = nullptr; |
1196 | 31.3k | } |
1197 | | |
1198 | | /// Returns a block which will be executed prior to each |
1199 | | /// evaluation of the conditional code. |
1200 | 215 | llvm::BasicBlock *getStartingBlock() const { |
1201 | 215 | return StartBB; |
1202 | 215 | } |
1203 | | }; |
1204 | | |
1205 | | /// isInConditionalBranch - Return true if we're currently emitting |
1206 | | /// one branch or the other of a conditional expression. |
1207 | 11.2k | bool isInConditionalBranch() const { return OutermostConditional != nullptr; } |
1208 | | |
1209 | 206 | void setBeforeOutermostConditional(llvm::Value *value, Address addr) { |
1210 | 206 | assert(isInConditionalBranch()); |
1211 | 0 | llvm::BasicBlock *block = OutermostConditional->getStartingBlock(); |
1212 | 206 | auto store = new llvm::StoreInst(value, addr.getPointer(), &block->back()); |
1213 | 206 | store->setAlignment(addr.getAlignment().getAsAlign()); |
1214 | 206 | } |
1215 | | |
1216 | | /// An RAII object to record that we're evaluating a statement |
1217 | | /// expression. |
1218 | | class StmtExprEvaluation { |
1219 | | CodeGenFunction &CGF; |
1220 | | |
1221 | | /// We have to save the outermost conditional: cleanups in a |
1222 | | /// statement expression aren't conditional just because the |
1223 | | /// StmtExpr is. |
1224 | | ConditionalEvaluation *SavedOutermostConditional; |
1225 | | |
1226 | | public: |
1227 | | StmtExprEvaluation(CodeGenFunction &CGF) |
1228 | 4.27k | : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) { |
1229 | 4.27k | CGF.OutermostConditional = nullptr; |
1230 | 4.27k | } |
1231 | | |
1232 | 4.27k | ~StmtExprEvaluation() { |
1233 | 4.27k | CGF.OutermostConditional = SavedOutermostConditional; |
1234 | 4.27k | CGF.EnsureInsertPoint(); |
1235 | 4.27k | } |
1236 | | }; |
1237 | | |
1238 | | /// An object which temporarily prevents a value from being |
1239 | | /// destroyed by aggressive peephole optimizations that assume that |
1240 | | /// all uses of a value have been realized in the IR. |
1241 | | class PeepholeProtection { |
1242 | | llvm::Instruction *Inst; |
1243 | | friend class CodeGenFunction; |
1244 | | |
1245 | | public: |
1246 | 16.2k | PeepholeProtection() : Inst(nullptr) {} |
1247 | | }; |
1248 | | |
1249 | | /// A non-RAII class containing all the information about a bound |
1250 | | /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for |
1251 | | /// this which makes individual mappings very simple; using this |
1252 | | /// class directly is useful when you have a variable number of |
1253 | | /// opaque values or don't want the RAII functionality for some |
1254 | | /// reason. |
1255 | | class OpaqueValueMappingData { |
1256 | | const OpaqueValueExpr *OpaqueValue; |
1257 | | bool BoundLValue; |
1258 | | CodeGenFunction::PeepholeProtection Protection; |
1259 | | |
1260 | | OpaqueValueMappingData(const OpaqueValueExpr *ov, |
1261 | | bool boundLValue) |
1262 | 2.23k | : OpaqueValue(ov), BoundLValue(boundLValue) {} |
1263 | | public: |
1264 | 12.3k | OpaqueValueMappingData() : OpaqueValue(nullptr) {} |
1265 | | |
1266 | 7.78k | static bool shouldBindAsLValue(const Expr *expr) { |
1267 | | // gl-values should be bound as l-values for obvious reasons. |
1268 | | // Records should be bound as l-values because IR generation |
1269 | | // always keeps them in memory. Expressions of function type |
1270 | | // act exactly like l-values but are formally required to be |
1271 | | // r-values in C. |
1272 | 7.78k | return expr->isGLValue() || |
1273 | 7.78k | expr->getType()->isFunctionType()4.51k || |
1274 | 7.78k | hasAggregateEvaluationKind(expr->getType())4.51k ; |
1275 | 7.78k | } |
1276 | | |
1277 | | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
1278 | | const OpaqueValueExpr *ov, |
1279 | 637 | const Expr *e) { |
1280 | 637 | if (shouldBindAsLValue(ov)) |
1281 | 355 | return bind(CGF, ov, CGF.EmitLValue(e)); |
1282 | 282 | return bind(CGF, ov, CGF.EmitAnyExpr(e)); |
1283 | 637 | } |
1284 | | |
1285 | | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
1286 | | const OpaqueValueExpr *ov, |
1287 | 534 | const LValue &lv) { |
1288 | 534 | assert(shouldBindAsLValue(ov)); |
1289 | 0 | CGF.OpaqueLValues.insert(std::make_pair(ov, lv)); |
1290 | 534 | return OpaqueValueMappingData(ov, true); |
1291 | 534 | } |
1292 | | |
1293 | | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
1294 | | const OpaqueValueExpr *ov, |
1295 | 1.69k | const RValue &rv) { |
1296 | 1.69k | assert(!shouldBindAsLValue(ov)); |
1297 | 0 | CGF.OpaqueRValues.insert(std::make_pair(ov, rv)); |
1298 | | |
1299 | 1.69k | OpaqueValueMappingData data(ov, false); |
1300 | | |
1301 | | // Work around an extremely aggressive peephole optimization in |
1302 | | // EmitScalarConversion which assumes that all other uses of a |
1303 | | // value are extant. |
1304 | 1.69k | data.Protection = CGF.protectFromPeepholes(rv); |
1305 | | |
1306 | 1.69k | return data; |
1307 | 1.69k | } |
1308 | | |
1309 | 13.6k | bool isValid() const { return OpaqueValue != nullptr; } |
1310 | 6 | void clear() { OpaqueValue = nullptr; } |
1311 | | |
1312 | 2.23k | void unbind(CodeGenFunction &CGF) { |
1313 | 2.23k | assert(OpaqueValue && "no data to unbind!"); |
1314 | | |
1315 | 2.23k | if (BoundLValue) { |
1316 | 534 | CGF.OpaqueLValues.erase(OpaqueValue); |
1317 | 1.69k | } else { |
1318 | 1.69k | CGF.OpaqueRValues.erase(OpaqueValue); |
1319 | 1.69k | CGF.unprotectFromPeepholes(Protection); |
1320 | 1.69k | } |
1321 | 2.23k | } |
1322 | | }; |
1323 | | |
1324 | | /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr. |
1325 | | class OpaqueValueMapping { |
1326 | | CodeGenFunction &CGF; |
1327 | | OpaqueValueMappingData Data; |
1328 | | |
1329 | | public: |
1330 | 3.82k | static bool shouldBindAsLValue(const Expr *expr) { |
1331 | 3.82k | return OpaqueValueMappingData::shouldBindAsLValue(expr); |
1332 | 3.82k | } |
1333 | | |
1334 | | /// Build the opaque value mapping for the given conditional |
1335 | | /// operator if it's the GNU ?: extension. This is a common |
1336 | | /// enough pattern that the convenience operator is really |
1337 | | /// helpful. |
1338 | | /// |
1339 | | OpaqueValueMapping(CodeGenFunction &CGF, |
1340 | 11.9k | const AbstractConditionalOperator *op) : CGF(CGF) { |
1341 | 11.9k | if (isa<ConditionalOperator>(op)) |
1342 | | // Leave Data empty. |
1343 | 11.9k | return; |
1344 | | |
1345 | 29 | const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op); |
1346 | 29 | Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(), |
1347 | 29 | e->getCommon()); |
1348 | 29 | } |
1349 | | |
1350 | | /// Build the opaque value mapping for an OpaqueValueExpr whose source |
1351 | | /// expression is set to the expression the OVE represents. |
1352 | | OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *OV) |
1353 | 39 | : CGF(CGF) { |
1354 | 39 | if (OV) { |
1355 | 39 | assert(OV->getSourceExpr() && "wrong form of OpaqueValueMapping used " |
1356 | 39 | "for OVE with no source expression"); |
1357 | 0 | Data = OpaqueValueMappingData::bind(CGF, OV, OV->getSourceExpr()); |
1358 | 39 | } |
1359 | 39 | } |
1360 | | |
1361 | | OpaqueValueMapping(CodeGenFunction &CGF, |
1362 | | const OpaqueValueExpr *opaqueValue, |
1363 | | LValue lvalue) |
1364 | 169 | : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) { |
1365 | 169 | } |
1366 | | |
1367 | | OpaqueValueMapping(CodeGenFunction &CGF, |
1368 | | const OpaqueValueExpr *opaqueValue, |
1369 | | RValue rvalue) |
1370 | 1.41k | : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) { |
1371 | 1.41k | } |
1372 | | |
1373 | 6 | void pop() { |
1374 | 6 | Data.unbind(CGF); |
1375 | 6 | Data.clear(); |
1376 | 6 | } |
1377 | | |
1378 | 13.6k | ~OpaqueValueMapping() { |
1379 | 13.6k | if (Data.isValid()) Data.unbind(CGF)1.64k ; |
1380 | 13.6k | } |
1381 | | }; |
1382 | | |
1383 | | private: |
1384 | | CGDebugInfo *DebugInfo; |
1385 | | /// Used to create unique names for artificial VLA size debug info variables. |
1386 | | unsigned VLAExprCounter = 0; |
1387 | | bool DisableDebugInfo = false; |
1388 | | |
1389 | | /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid |
1390 | | /// calling llvm.stacksave for multiple VLAs in the same scope. |
1391 | | bool DidCallStackSave = false; |
1392 | | |
1393 | | /// IndirectBranch - The first time an indirect goto is seen we create a block |
1394 | | /// with an indirect branch. Every time we see the address of a label taken, |
1395 | | /// we add the label to the indirect goto. Every subsequent indirect goto is |
1396 | | /// codegen'd as a jump to the IndirectBranch's basic block. |
1397 | | llvm::IndirectBrInst *IndirectBranch = nullptr; |
1398 | | |
1399 | | /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C |
1400 | | /// decls. |
1401 | | DeclMapTy LocalDeclMap; |
1402 | | |
1403 | | // Keep track of the cleanups for callee-destructed parameters pushed to the |
1404 | | // cleanup stack so that they can be deactivated later. |
1405 | | llvm::DenseMap<const ParmVarDecl *, EHScopeStack::stable_iterator> |
1406 | | CalleeDestructedParamCleanups; |
1407 | | |
1408 | | /// SizeArguments - If a ParmVarDecl had the pass_object_size attribute, this |
1409 | | /// will contain a mapping from said ParmVarDecl to its implicit "object_size" |
1410 | | /// parameter. |
1411 | | llvm::SmallDenseMap<const ParmVarDecl *, const ImplicitParamDecl *, 2> |
1412 | | SizeArguments; |
1413 | | |
1414 | | /// Track escaped local variables with auto storage. Used during SEH |
1415 | | /// outlining to produce a call to llvm.localescape. |
1416 | | llvm::DenseMap<llvm::AllocaInst *, int> EscapedLocals; |
1417 | | |
1418 | | /// LabelMap - This keeps track of the LLVM basic block for each C label. |
1419 | | llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap; |
1420 | | |
1421 | | // BreakContinueStack - This keeps track of where break and continue |
1422 | | // statements should jump to. |
1423 | | struct BreakContinue { |
1424 | | BreakContinue(JumpDest Break, JumpDest Continue) |
1425 | 46.6k | : BreakBlock(Break), ContinueBlock(Continue) {} |
1426 | | |
1427 | | JumpDest BreakBlock; |
1428 | | JumpDest ContinueBlock; |
1429 | | }; |
1430 | | SmallVector<BreakContinue, 8> BreakContinueStack; |
1431 | | |
1432 | | /// Handles cancellation exit points in OpenMP-related constructs. |
1433 | | class OpenMPCancelExitStack { |
1434 | | /// Tracks cancellation exit point and join point for cancel-related exit |
1435 | | /// and normal exit. |
1436 | | struct CancelExit { |
1437 | 315k | CancelExit() = default; |
1438 | | CancelExit(OpenMPDirectiveKind Kind, JumpDest ExitBlock, |
1439 | | JumpDest ContBlock) |
1440 | 4.42k | : Kind(Kind), ExitBlock(ExitBlock), ContBlock(ContBlock) {} |
1441 | | OpenMPDirectiveKind Kind = llvm::omp::OMPD_unknown; |
1442 | | /// true if the exit block has been emitted already by the special |
1443 | | /// emitExit() call, false if the default codegen is used. |
1444 | | bool HasBeenEmitted = false; |
1445 | | JumpDest ExitBlock; |
1446 | | JumpDest ContBlock; |
1447 | | }; |
1448 | | |
1449 | | SmallVector<CancelExit, 8> Stack; |
1450 | | |
1451 | | public: |
1452 | 315k | OpenMPCancelExitStack() : Stack(1) {} |
1453 | 315k | ~OpenMPCancelExitStack() = default; |
1454 | | /// Fetches the exit block for the current OpenMP construct. |
1455 | 9.13k | JumpDest getExitBlock() const { return Stack.back().ExitBlock; } |
1456 | | /// Emits exit block with special codegen procedure specific for the related |
1457 | | /// OpenMP construct + emits code for normal construct cleanup. |
1458 | | void emitExit(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, |
1459 | 5.01k | const llvm::function_ref<void(CodeGenFunction &)> CodeGen) { |
1460 | 5.01k | if (Stack.back().Kind == Kind && getExitBlock().isValid()4.39k ) { |
1461 | 93 | assert(CGF.getOMPCancelDestination(Kind).isValid()); |
1462 | 0 | assert(CGF.HaveInsertPoint()); |
1463 | 0 | assert(!Stack.back().HasBeenEmitted); |
1464 | 0 | auto IP = CGF.Builder.saveAndClearIP(); |
1465 | 93 | CGF.EmitBlock(Stack.back().ExitBlock.getBlock()); |
1466 | 93 | CodeGen(CGF); |
1467 | 93 | CGF.EmitBranch(Stack.back().ContBlock.getBlock()); |
1468 | 93 | CGF.Builder.restoreIP(IP); |
1469 | 93 | Stack.back().HasBeenEmitted = true; |
1470 | 93 | } |
1471 | 0 | CodeGen(CGF); |
1472 | 5.01k | } |
1473 | | /// Enter the cancel supporting \a Kind construct. |
1474 | | /// \param Kind OpenMP directive that supports cancel constructs. |
1475 | | /// \param HasCancel true, if the construct has inner cancel directive, |
1476 | | /// false otherwise. |
1477 | 4.42k | void enter(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, bool HasCancel) { |
1478 | 4.42k | Stack.push_back({Kind, |
1479 | 4.42k | HasCancel ? CGF.getJumpDestInCurrentScope("cancel.exit")93 |
1480 | 4.42k | : JumpDest()4.33k , |
1481 | 4.42k | HasCancel ? CGF.getJumpDestInCurrentScope("cancel.cont")93 |
1482 | 4.42k | : JumpDest()4.33k }); |
1483 | 4.42k | } |
1484 | | /// Emits default exit point for the cancel construct (if the special one |
1485 | | /// has not be used) + join point for cancel/normal exits. |
1486 | 4.42k | void exit(CodeGenFunction &CGF) { |
1487 | 4.42k | if (getExitBlock().isValid()) { |
1488 | 93 | assert(CGF.getOMPCancelDestination(Stack.back().Kind).isValid()); |
1489 | 0 | bool HaveIP = CGF.HaveInsertPoint(); |
1490 | 93 | if (!Stack.back().HasBeenEmitted) { |
1491 | 0 | if (HaveIP) |
1492 | 0 | CGF.EmitBranchThroughCleanup(Stack.back().ContBlock); |
1493 | 0 | CGF.EmitBlock(Stack.back().ExitBlock.getBlock()); |
1494 | 0 | CGF.EmitBranchThroughCleanup(Stack.back().ContBlock); |
1495 | 0 | } |
1496 | 93 | CGF.EmitBlock(Stack.back().ContBlock.getBlock()); |
1497 | 93 | if (!HaveIP) { |
1498 | 0 | CGF.Builder.CreateUnreachable(); |
1499 | 0 | CGF.Builder.ClearInsertionPoint(); |
1500 | 0 | } |
1501 | 93 | } |
1502 | 0 | Stack.pop_back(); |
1503 | 4.42k | } |
1504 | | }; |
1505 | | OpenMPCancelExitStack OMPCancelStack; |
1506 | | |
1507 | | /// Lower the Likelihood knowledge about the \p Cond via llvm.expect intrin. |
1508 | | llvm::Value *emitCondLikelihoodViaExpectIntrinsic(llvm::Value *Cond, |
1509 | | Stmt::Likelihood LH); |
1510 | | |
1511 | | CodeGenPGO PGO; |
1512 | | |
1513 | | /// Calculate branch weights appropriate for PGO data |
1514 | | llvm::MDNode *createProfileWeights(uint64_t TrueCount, |
1515 | | uint64_t FalseCount) const; |
1516 | | llvm::MDNode *createProfileWeights(ArrayRef<uint64_t> Weights) const; |
1517 | | llvm::MDNode *createProfileWeightsForLoop(const Stmt *Cond, |
1518 | | uint64_t LoopCount) const; |
1519 | | |
1520 | | public: |
1521 | | /// Increment the profiler's counter for the given statement by \p StepV. |
1522 | | /// If \p StepV is null, the default increment is 1. |
1523 | 459k | void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { |
1524 | 459k | if (CGM.getCodeGenOpts().hasProfileClangInstr() && |
1525 | 459k | !CurFn->hasFnAttribute(llvm::Attribute::NoProfile)1.13k ) |
1526 | 1.12k | PGO.emitCounterIncrement(Builder, S, StepV); |
1527 | 459k | PGO.setCurrentStmt(S); |
1528 | 459k | } |
1529 | | |
1530 | | /// Get the profiler's count for the given statement. |
1531 | 182k | uint64_t getProfileCount(const Stmt *S) { |
1532 | 182k | return PGO.getStmtCount(S).value_or(0); |
1533 | 182k | } |
1534 | | |
1535 | | /// Set the profiler's current count. |
1536 | 9.47k | void setCurrentProfileCount(uint64_t Count) { |
1537 | 9.47k | PGO.setCurrentRegionCount(Count); |
1538 | 9.47k | } |
1539 | | |
1540 | | /// Get the profiler's current count. This is generally the count for the most |
1541 | | /// recently incremented counter. |
1542 | 165k | uint64_t getCurrentProfileCount() { |
1543 | 165k | return PGO.getCurrentRegionCount(); |
1544 | 165k | } |
1545 | | |
1546 | | private: |
1547 | | |
1548 | | /// SwitchInsn - This is nearest current switch instruction. It is null if |
1549 | | /// current context is not in a switch. |
1550 | | llvm::SwitchInst *SwitchInsn = nullptr; |
1551 | | /// The branch weights of SwitchInsn when doing instrumentation based PGO. |
1552 | | SmallVector<uint64_t, 16> *SwitchWeights = nullptr; |
1553 | | |
1554 | | /// The likelihood attributes of the SwitchCase. |
1555 | | SmallVector<Stmt::Likelihood, 16> *SwitchLikelihood = nullptr; |
1556 | | |
1557 | | /// CaseRangeBlock - This block holds if condition check for last case |
1558 | | /// statement range in current switch instruction. |
1559 | | llvm::BasicBlock *CaseRangeBlock = nullptr; |
1560 | | |
1561 | | /// OpaqueLValues - Keeps track of the current set of opaque value |
1562 | | /// expressions. |
1563 | | llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues; |
1564 | | llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues; |
1565 | | |
1566 | | // VLASizeMap - This keeps track of the associated size for each VLA type. |
1567 | | // We track this by the size expression rather than the type itself because |
1568 | | // in certain situations, like a const qualifier applied to an VLA typedef, |
1569 | | // multiple VLA types can share the same size expression. |
1570 | | // FIXME: Maybe this could be a stack of maps that is pushed/popped as we |
1571 | | // enter/leave scopes. |
1572 | | llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; |
1573 | | |
1574 | | /// A block containing a single 'unreachable' instruction. Created |
1575 | | /// lazily by getUnreachableBlock(). |
1576 | | llvm::BasicBlock *UnreachableBlock = nullptr; |
1577 | | |
1578 | | /// Counts of the number return expressions in the function. |
1579 | | unsigned NumReturnExprs = 0; |
1580 | | |
1581 | | /// Count the number of simple (constant) return expressions in the function. |
1582 | | unsigned NumSimpleReturnExprs = 0; |
1583 | | |
1584 | | /// The last regular (non-return) debug location (breakpoint) in the function. |
1585 | | SourceLocation LastStopPoint; |
1586 | | |
1587 | | public: |
1588 | | /// Source location information about the default argument or member |
1589 | | /// initializer expression we're evaluating, if any. |
1590 | | CurrentSourceLocExprScope CurSourceLocExprScope; |
1591 | | using SourceLocExprScopeGuard = |
1592 | | CurrentSourceLocExprScope::SourceLocExprScopeGuard; |
1593 | | |
1594 | | /// A scope within which we are constructing the fields of an object which |
1595 | | /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use |
1596 | | /// if we need to evaluate a CXXDefaultInitExpr within the evaluation. |
1597 | | class FieldConstructionScope { |
1598 | | public: |
1599 | | FieldConstructionScope(CodeGenFunction &CGF, Address This) |
1600 | 26.1k | : CGF(CGF), OldCXXDefaultInitExprThis(CGF.CXXDefaultInitExprThis) { |
1601 | 26.1k | CGF.CXXDefaultInitExprThis = This; |
1602 | 26.1k | } |
1603 | 26.1k | ~FieldConstructionScope() { |
1604 | 26.1k | CGF.CXXDefaultInitExprThis = OldCXXDefaultInitExprThis; |
1605 | 26.1k | } |
1606 | | |
1607 | | private: |
1608 | | CodeGenFunction &CGF; |
1609 | | Address OldCXXDefaultInitExprThis; |
1610 | | }; |
1611 | | |
1612 | | /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this' |
1613 | | /// is overridden to be the object under construction. |
1614 | | class CXXDefaultInitExprScope { |
1615 | | public: |
1616 | | CXXDefaultInitExprScope(CodeGenFunction &CGF, const CXXDefaultInitExpr *E) |
1617 | | : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue), |
1618 | | OldCXXThisAlignment(CGF.CXXThisAlignment), |
1619 | 1.18k | SourceLocScope(E, CGF.CurSourceLocExprScope) { |
1620 | 1.18k | CGF.CXXThisValue = CGF.CXXDefaultInitExprThis.getPointer(); |
1621 | 1.18k | CGF.CXXThisAlignment = CGF.CXXDefaultInitExprThis.getAlignment(); |
1622 | 1.18k | } |
1623 | 1.18k | ~CXXDefaultInitExprScope() { |
1624 | 1.18k | CGF.CXXThisValue = OldCXXThisValue; |
1625 | 1.18k | CGF.CXXThisAlignment = OldCXXThisAlignment; |
1626 | 1.18k | } |
1627 | | |
1628 | | public: |
1629 | | CodeGenFunction &CGF; |
1630 | | llvm::Value *OldCXXThisValue; |
1631 | | CharUnits OldCXXThisAlignment; |
1632 | | SourceLocExprScopeGuard SourceLocScope; |
1633 | | }; |
1634 | | |
1635 | | struct CXXDefaultArgExprScope : SourceLocExprScopeGuard { |
1636 | | CXXDefaultArgExprScope(CodeGenFunction &CGF, const CXXDefaultArgExpr *E) |
1637 | 4.12k | : SourceLocExprScopeGuard(E, CGF.CurSourceLocExprScope) {} |
1638 | | }; |
1639 | | |
1640 | | /// The scope of an ArrayInitLoopExpr. Within this scope, the value of the |
1641 | | /// current loop index is overridden. |
1642 | | class ArrayInitLoopExprScope { |
1643 | | public: |
1644 | | ArrayInitLoopExprScope(CodeGenFunction &CGF, llvm::Value *Index) |
1645 | 39 | : CGF(CGF), OldArrayInitIndex(CGF.ArrayInitIndex) { |
1646 | 39 | CGF.ArrayInitIndex = Index; |
1647 | 39 | } |
1648 | 39 | ~ArrayInitLoopExprScope() { |
1649 | 39 | CGF.ArrayInitIndex = OldArrayInitIndex; |
1650 | 39 | } |
1651 | | |
1652 | | private: |
1653 | | CodeGenFunction &CGF; |
1654 | | llvm::Value *OldArrayInitIndex; |
1655 | | }; |
1656 | | |
1657 | | class InlinedInheritingConstructorScope { |
1658 | | public: |
1659 | | InlinedInheritingConstructorScope(CodeGenFunction &CGF, GlobalDecl GD) |
1660 | | : CGF(CGF), OldCurGD(CGF.CurGD), OldCurFuncDecl(CGF.CurFuncDecl), |
1661 | | OldCurCodeDecl(CGF.CurCodeDecl), |
1662 | | OldCXXABIThisDecl(CGF.CXXABIThisDecl), |
1663 | | OldCXXABIThisValue(CGF.CXXABIThisValue), |
1664 | | OldCXXThisValue(CGF.CXXThisValue), |
1665 | | OldCXXABIThisAlignment(CGF.CXXABIThisAlignment), |
1666 | | OldCXXThisAlignment(CGF.CXXThisAlignment), |
1667 | | OldReturnValue(CGF.ReturnValue), OldFnRetTy(CGF.FnRetTy), |
1668 | | OldCXXInheritedCtorInitExprArgs( |
1669 | 47 | std::move(CGF.CXXInheritedCtorInitExprArgs)) { |
1670 | 47 | CGF.CurGD = GD; |
1671 | 47 | CGF.CurFuncDecl = CGF.CurCodeDecl = |
1672 | 47 | cast<CXXConstructorDecl>(GD.getDecl()); |
1673 | 47 | CGF.CXXABIThisDecl = nullptr; |
1674 | 47 | CGF.CXXABIThisValue = nullptr; |
1675 | 47 | CGF.CXXThisValue = nullptr; |
1676 | 47 | CGF.CXXABIThisAlignment = CharUnits(); |
1677 | 47 | CGF.CXXThisAlignment = CharUnits(); |
1678 | 47 | CGF.ReturnValue = Address::invalid(); |
1679 | 47 | CGF.FnRetTy = QualType(); |
1680 | 47 | CGF.CXXInheritedCtorInitExprArgs.clear(); |
1681 | 47 | } |
1682 | 47 | ~InlinedInheritingConstructorScope() { |
1683 | 47 | CGF.CurGD = OldCurGD; |
1684 | 47 | CGF.CurFuncDecl = OldCurFuncDecl; |
1685 | 47 | CGF.CurCodeDecl = OldCurCodeDecl; |
1686 | 47 | CGF.CXXABIThisDecl = OldCXXABIThisDecl; |
1687 | 47 | CGF.CXXABIThisValue = OldCXXABIThisValue; |
1688 | 47 | CGF.CXXThisValue = OldCXXThisValue; |
1689 | 47 | CGF.CXXABIThisAlignment = OldCXXABIThisAlignment; |
1690 | 47 | CGF.CXXThisAlignment = OldCXXThisAlignment; |
1691 | 47 | CGF.ReturnValue = OldReturnValue; |
1692 | 47 | CGF.FnRetTy = OldFnRetTy; |
1693 | 47 | CGF.CXXInheritedCtorInitExprArgs = |
1694 | 47 | std::move(OldCXXInheritedCtorInitExprArgs); |
1695 | 47 | } |
1696 | | |
1697 | | private: |
1698 | | CodeGenFunction &CGF; |
1699 | | GlobalDecl OldCurGD; |
1700 | | const Decl *OldCurFuncDecl; |
1701 | | const Decl *OldCurCodeDecl; |
1702 | | ImplicitParamDecl *OldCXXABIThisDecl; |
1703 | | llvm::Value *OldCXXABIThisValue; |
1704 | | llvm::Value *OldCXXThisValue; |
1705 | | CharUnits OldCXXABIThisAlignment; |
1706 | | CharUnits OldCXXThisAlignment; |
1707 | | Address OldReturnValue; |
1708 | | QualType OldFnRetTy; |
1709 | | CallArgList OldCXXInheritedCtorInitExprArgs; |
1710 | | }; |
1711 | | |
1712 | | // Helper class for the OpenMP IR Builder. Allows reusability of code used for |
1713 | | // region body, and finalization codegen callbacks. This will class will also |
1714 | | // contain privatization functions used by the privatization call backs |
1715 | | // |
1716 | | // TODO: this is temporary class for things that are being moved out of |
1717 | | // CGOpenMPRuntime, new versions of current CodeGenFunction methods, or |
1718 | | // utility function for use with the OMPBuilder. Once that move to use the |
1719 | | // OMPBuilder is done, everything here will either become part of CodeGenFunc. |
1720 | | // directly, or a new helper class that will contain functions used by both |
1721 | | // this and the OMPBuilder |
1722 | | |
1723 | | struct OMPBuilderCBHelpers { |
1724 | | |
1725 | | OMPBuilderCBHelpers() = delete; |
1726 | | OMPBuilderCBHelpers(const OMPBuilderCBHelpers &) = delete; |
1727 | | OMPBuilderCBHelpers &operator=(const OMPBuilderCBHelpers &) = delete; |
1728 | | |
1729 | | using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy; |
1730 | | |
1731 | | /// Cleanup action for allocate support. |
1732 | | class OMPAllocateCleanupTy final : public EHScopeStack::Cleanup { |
1733 | | |
1734 | | private: |
1735 | | llvm::CallInst *RTLFnCI; |
1736 | | |
1737 | | public: |
1738 | 0 | OMPAllocateCleanupTy(llvm::CallInst *RLFnCI) : RTLFnCI(RLFnCI) { |
1739 | 0 | RLFnCI->removeFromParent(); |
1740 | 0 | } |
1741 | | |
1742 | 0 | void Emit(CodeGenFunction &CGF, Flags /*flags*/) override { |
1743 | 0 | if (!CGF.HaveInsertPoint()) |
1744 | 0 | return; |
1745 | 0 | CGF.Builder.Insert(RTLFnCI); |
1746 | 0 | } |
1747 | | }; |
1748 | | |
1749 | | /// Returns address of the threadprivate variable for the current |
1750 | | /// thread. This Also create any necessary OMP runtime calls. |
1751 | | /// |
1752 | | /// \param VD VarDecl for Threadprivate variable. |
1753 | | /// \param VDAddr Address of the Vardecl |
1754 | | /// \param Loc The location where the barrier directive was encountered |
1755 | | static Address getAddrOfThreadPrivate(CodeGenFunction &CGF, |
1756 | | const VarDecl *VD, Address VDAddr, |
1757 | | SourceLocation Loc); |
1758 | | |
1759 | | /// Gets the OpenMP-specific address of the local variable /p VD. |
1760 | | static Address getAddressOfLocalVariable(CodeGenFunction &CGF, |
1761 | | const VarDecl *VD); |
1762 | | /// Get the platform-specific name separator. |
1763 | | /// \param Parts different parts of the final name that needs separation |
1764 | | /// \param FirstSeparator First separator used between the initial two |
1765 | | /// parts of the name. |
1766 | | /// \param Separator separator used between all of the rest consecutinve |
1767 | | /// parts of the name |
1768 | | static std::string getNameWithSeparators(ArrayRef<StringRef> Parts, |
1769 | | StringRef FirstSeparator = ".", |
1770 | | StringRef Separator = "."); |
1771 | | /// Emit the Finalization for an OMP region |
1772 | | /// \param CGF The Codegen function this belongs to |
1773 | | /// \param IP Insertion point for generating the finalization code. |
1774 | 176 | static void FinalizeOMPRegion(CodeGenFunction &CGF, InsertPointTy IP) { |
1775 | 176 | CGBuilderTy::InsertPointGuard IPG(CGF.Builder); |
1776 | 176 | assert(IP.getBlock()->end() != IP.getPoint() && |
1777 | 176 | "OpenMP IR Builder should cause terminated block!"); |
1778 | | |
1779 | 0 | llvm::BasicBlock *IPBB = IP.getBlock(); |
1780 | 176 | llvm::BasicBlock *DestBB = IPBB->getUniqueSuccessor(); |
1781 | 176 | assert(DestBB && "Finalization block should have one successor!"); |
1782 | | |
1783 | | // erase and replace with cleanup branch. |
1784 | 0 | IPBB->getTerminator()->eraseFromParent(); |
1785 | 176 | CGF.Builder.SetInsertPoint(IPBB); |
1786 | 176 | CodeGenFunction::JumpDest Dest = CGF.getJumpDestInCurrentScope(DestBB); |
1787 | 176 | CGF.EmitBranchThroughCleanup(Dest); |
1788 | 176 | } |
1789 | | |
1790 | | /// Emit the body of an OMP region |
1791 | | /// \param CGF The Codegen function this belongs to |
1792 | | /// \param RegionBodyStmt The body statement for the OpenMP region being |
1793 | | /// generated |
1794 | | /// \param AllocaIP Where to insert alloca instructions |
1795 | | /// \param CodeGenIP Where to insert the region code |
1796 | | /// \param RegionName Name to be used for new blocks |
1797 | | static void EmitOMPInlinedRegionBody(CodeGenFunction &CGF, |
1798 | | const Stmt *RegionBodyStmt, |
1799 | | InsertPointTy AllocaIP, |
1800 | | InsertPointTy CodeGenIP, |
1801 | | Twine RegionName); |
1802 | | |
1803 | | static void EmitCaptureStmt(CodeGenFunction &CGF, InsertPointTy CodeGenIP, |
1804 | | llvm::BasicBlock &FiniBB, llvm::Function *Fn, |
1805 | 8 | ArrayRef<llvm::Value *> Args) { |
1806 | 8 | llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock(); |
1807 | 8 | if (llvm::Instruction *CodeGenIPBBTI = CodeGenIPBB->getTerminator()) |
1808 | 0 | CodeGenIPBBTI->eraseFromParent(); |
1809 | | |
1810 | 8 | CGF.Builder.SetInsertPoint(CodeGenIPBB); |
1811 | | |
1812 | 8 | if (Fn->doesNotThrow()) |
1813 | 0 | CGF.EmitNounwindRuntimeCall(Fn, Args); |
1814 | 8 | else |
1815 | 8 | CGF.EmitRuntimeCall(Fn, Args); |
1816 | | |
1817 | 8 | if (CGF.Builder.saveIP().isSet()) |
1818 | 8 | CGF.Builder.CreateBr(&FiniBB); |
1819 | 8 | } |
1820 | | |
1821 | | /// Emit the body of an OMP region that will be outlined in |
1822 | | /// OpenMPIRBuilder::finalize(). |
1823 | | /// \param CGF The Codegen function this belongs to |
1824 | | /// \param RegionBodyStmt The body statement for the OpenMP region being |
1825 | | /// generated |
1826 | | /// \param AllocaIP Where to insert alloca instructions |
1827 | | /// \param CodeGenIP Where to insert the region code |
1828 | | /// \param RegionName Name to be used for new blocks |
1829 | | static void EmitOMPOutlinedRegionBody(CodeGenFunction &CGF, |
1830 | | const Stmt *RegionBodyStmt, |
1831 | | InsertPointTy AllocaIP, |
1832 | | InsertPointTy CodeGenIP, |
1833 | | Twine RegionName); |
1834 | | |
1835 | | /// RAII for preserving necessary info during Outlined region body codegen. |
1836 | | class OutlinedRegionBodyRAII { |
1837 | | |
1838 | | llvm::AssertingVH<llvm::Instruction> OldAllocaIP; |
1839 | | CodeGenFunction::JumpDest OldReturnBlock; |
1840 | | CodeGenFunction &CGF; |
1841 | | |
1842 | | public: |
1843 | | OutlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP, |
1844 | | llvm::BasicBlock &RetBB) |
1845 | 50 | : CGF(cgf) { |
1846 | 50 | assert(AllocaIP.isSet() && |
1847 | 50 | "Must specify Insertion point for allocas of outlined function"); |
1848 | 0 | OldAllocaIP = CGF.AllocaInsertPt; |
1849 | 50 | CGF.AllocaInsertPt = &*AllocaIP.getPoint(); |
1850 | | |
1851 | 50 | OldReturnBlock = CGF.ReturnBlock; |
1852 | 50 | CGF.ReturnBlock = CGF.getJumpDestInCurrentScope(&RetBB); |
1853 | 50 | } |
1854 | | |
1855 | 50 | ~OutlinedRegionBodyRAII() { |
1856 | 50 | CGF.AllocaInsertPt = OldAllocaIP; |
1857 | 50 | CGF.ReturnBlock = OldReturnBlock; |
1858 | 50 | } |
1859 | | }; |
1860 | | |
1861 | | /// RAII for preserving necessary info during inlined region body codegen. |
1862 | | class InlinedRegionBodyRAII { |
1863 | | |
1864 | | llvm::AssertingVH<llvm::Instruction> OldAllocaIP; |
1865 | | CodeGenFunction &CGF; |
1866 | | |
1867 | | public: |
1868 | | InlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP, |
1869 | | llvm::BasicBlock &FiniBB) |
1870 | 98 | : CGF(cgf) { |
1871 | | // Alloca insertion block should be in the entry block of the containing |
1872 | | // function so it expects an empty AllocaIP in which case will reuse the |
1873 | | // old alloca insertion point, or a new AllocaIP in the same block as |
1874 | | // the old one |
1875 | 98 | assert((!AllocaIP.isSet() || |
1876 | 98 | CGF.AllocaInsertPt->getParent() == AllocaIP.getBlock()) && |
1877 | 98 | "Insertion point should be in the entry block of containing " |
1878 | 98 | "function!"); |
1879 | 0 | OldAllocaIP = CGF.AllocaInsertPt; |
1880 | 98 | if (AllocaIP.isSet()) |
1881 | 0 | CGF.AllocaInsertPt = &*AllocaIP.getPoint(); |
1882 | | |
1883 | | // TODO: Remove the call, after making sure the counter is not used by |
1884 | | // the EHStack. |
1885 | | // Since this is an inlined region, it should not modify the |
1886 | | // ReturnBlock, and should reuse the one for the enclosing outlined |
1887 | | // region. So, the JumpDest being return by the function is discarded |
1888 | 98 | (void)CGF.getJumpDestInCurrentScope(&FiniBB); |
1889 | 98 | } |
1890 | | |
1891 | 98 | ~InlinedRegionBodyRAII() { CGF.AllocaInsertPt = OldAllocaIP; } |
1892 | | }; |
1893 | | }; |
1894 | | |
1895 | | private: |
1896 | | /// CXXThisDecl - When generating code for a C++ member function, |
1897 | | /// this will hold the implicit 'this' declaration. |
1898 | | ImplicitParamDecl *CXXABIThisDecl = nullptr; |
1899 | | llvm::Value *CXXABIThisValue = nullptr; |
1900 | | llvm::Value *CXXThisValue = nullptr; |
1901 | | CharUnits CXXABIThisAlignment; |
1902 | | CharUnits CXXThisAlignment; |
1903 | | |
1904 | | /// The value of 'this' to use when evaluating CXXDefaultInitExprs within |
1905 | | /// this expression. |
1906 | | Address CXXDefaultInitExprThis = Address::invalid(); |
1907 | | |
1908 | | /// The current array initialization index when evaluating an |
1909 | | /// ArrayInitIndexExpr within an ArrayInitLoopExpr. |
1910 | | llvm::Value *ArrayInitIndex = nullptr; |
1911 | | |
1912 | | /// The values of function arguments to use when evaluating |
1913 | | /// CXXInheritedCtorInitExprs within this context. |
1914 | | CallArgList CXXInheritedCtorInitExprArgs; |
1915 | | |
1916 | | /// CXXStructorImplicitParamDecl - When generating code for a constructor or |
1917 | | /// destructor, this will hold the implicit argument (e.g. VTT). |
1918 | | ImplicitParamDecl *CXXStructorImplicitParamDecl = nullptr; |
1919 | | llvm::Value *CXXStructorImplicitParamValue = nullptr; |
1920 | | |
1921 | | /// OutermostConditional - Points to the outermost active |
1922 | | /// conditional control. This is used so that we know if a |
1923 | | /// temporary should be destroyed conditionally. |
1924 | | ConditionalEvaluation *OutermostConditional = nullptr; |
1925 | | |
1926 | | /// The current lexical scope. |
1927 | | LexicalScope *CurLexicalScope = nullptr; |
1928 | | |
1929 | | /// The current source location that should be used for exception |
1930 | | /// handling code. |
1931 | | SourceLocation CurEHLocation; |
1932 | | |
1933 | | /// BlockByrefInfos - For each __block variable, contains |
1934 | | /// information about the layout of the variable. |
1935 | | llvm::DenseMap<const ValueDecl *, BlockByrefInfo> BlockByrefInfos; |
1936 | | |
1937 | | /// Used by -fsanitize=nullability-return to determine whether the return |
1938 | | /// value can be checked. |
1939 | | llvm::Value *RetValNullabilityPrecondition = nullptr; |
1940 | | |
1941 | | /// Check if -fsanitize=nullability-return instrumentation is required for |
1942 | | /// this function. |
1943 | 1.14M | bool requiresReturnValueNullabilityCheck() const { |
1944 | 1.14M | return RetValNullabilityPrecondition; |
1945 | 1.14M | } |
1946 | | |
1947 | | /// Used to store precise source locations for return statements by the |
1948 | | /// runtime return value checks. |
1949 | | Address ReturnLocation = Address::invalid(); |
1950 | | |
1951 | | /// Check if the return value of this function requires sanitization. |
1952 | | bool requiresReturnValueCheck() const; |
1953 | | |
1954 | | llvm::BasicBlock *TerminateLandingPad = nullptr; |
1955 | | llvm::BasicBlock *TerminateHandler = nullptr; |
1956 | | llvm::SmallVector<llvm::BasicBlock *, 2> TrapBBs; |
1957 | | |
1958 | | /// Terminate funclets keyed by parent funclet pad. |
1959 | | llvm::MapVector<llvm::Value *, llvm::BasicBlock *> TerminateFunclets; |
1960 | | |
1961 | | /// Largest vector width used in ths function. Will be used to create a |
1962 | | /// function attribute. |
1963 | | unsigned LargestVectorWidth = 0; |
1964 | | |
1965 | | /// True if we need emit the life-time markers. This is initially set in |
1966 | | /// the constructor, but could be overwritten to true if this is a coroutine. |
1967 | | bool ShouldEmitLifetimeMarkers; |
1968 | | |
1969 | | /// Add OpenCL kernel arg metadata and the kernel attribute metadata to |
1970 | | /// the function metadata. |
1971 | | void EmitKernelMetadata(const FunctionDecl *FD, llvm::Function *Fn); |
1972 | | |
1973 | | public: |
1974 | | CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false); |
1975 | | ~CodeGenFunction(); |
1976 | | |
1977 | 546k | CodeGenTypes &getTypes() const { return CGM.getTypes(); } |
1978 | 16.4M | ASTContext &getContext() const { return CGM.getContext(); } |
1979 | 12.3M | CGDebugInfo *getDebugInfo() { |
1980 | 12.3M | if (DisableDebugInfo) |
1981 | 7.79k | return nullptr; |
1982 | 12.3M | return DebugInfo; |
1983 | 12.3M | } |
1984 | 2.82k | void disableDebugInfo() { DisableDebugInfo = true; } |
1985 | 2.82k | void enableDebugInfo() { DisableDebugInfo = false; } |
1986 | | |
1987 | 229 | bool shouldUseFusedARCCalls() { |
1988 | 229 | return CGM.getCodeGenOpts().OptimizationLevel == 0; |
1989 | 229 | } |
1990 | | |
1991 | 12.0M | const LangOptions &getLangOpts() const { return CGM.getLangOpts(); } |
1992 | | |
1993 | | /// Returns a pointer to the function's exception object and selector slot, |
1994 | | /// which is assigned in every landing pad. |
1995 | | Address getExceptionSlot(); |
1996 | | Address getEHSelectorSlot(); |
1997 | | |
1998 | | /// Returns the contents of the function's exception object and selector |
1999 | | /// slots. |
2000 | | llvm::Value *getExceptionFromSlot(); |
2001 | | llvm::Value *getSelectorFromSlot(); |
2002 | | |
2003 | | Address getNormalCleanupDestSlot(); |
2004 | | |
2005 | 444 | llvm::BasicBlock *getUnreachableBlock() { |
2006 | 444 | if (!UnreachableBlock) { |
2007 | 399 | UnreachableBlock = createBasicBlock("unreachable"); |
2008 | 399 | new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock); |
2009 | 399 | } |
2010 | 444 | return UnreachableBlock; |
2011 | 444 | } |
2012 | | |
2013 | 233k | llvm::BasicBlock *getInvokeDest() { |
2014 | 233k | if (!EHStack.requiresLandingPad()) return nullptr194k ; |
2015 | 38.6k | return getInvokeDestImpl(); |
2016 | 233k | } |
2017 | | |
2018 | 359k | bool currentFunctionUsesSEHTry() const { return CurSEHParent != nullptr; } |
2019 | | |
2020 | 645k | const TargetInfo &getTarget() const { return Target; } |
2021 | 3.46M | llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); } |
2022 | 31.4k | const TargetCodeGenInfo &getTargetHooks() const { |
2023 | 31.4k | return CGM.getTargetCodeGenInfo(); |
2024 | 31.4k | } |
2025 | | |
2026 | | //===--------------------------------------------------------------------===// |
2027 | | // Cleanups |
2028 | | //===--------------------------------------------------------------------===// |
2029 | | |
2030 | | typedef void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty); |
2031 | | |
2032 | | void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, |
2033 | | Address arrayEndPointer, |
2034 | | QualType elementType, |
2035 | | CharUnits elementAlignment, |
2036 | | Destroyer *destroyer); |
2037 | | void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, |
2038 | | llvm::Value *arrayEnd, |
2039 | | QualType elementType, |
2040 | | CharUnits elementAlignment, |
2041 | | Destroyer *destroyer); |
2042 | | |
2043 | | void pushDestroy(QualType::DestructionKind dtorKind, |
2044 | | Address addr, QualType type); |
2045 | | void pushEHDestroy(QualType::DestructionKind dtorKind, |
2046 | | Address addr, QualType type); |
2047 | | void pushDestroy(CleanupKind kind, Address addr, QualType type, |
2048 | | Destroyer *destroyer, bool useEHCleanupForArray); |
2049 | | void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, |
2050 | | QualType type, Destroyer *destroyer, |
2051 | | bool useEHCleanupForArray); |
2052 | | void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, |
2053 | | llvm::Value *CompletePtr, |
2054 | | QualType ElementType); |
2055 | | void pushStackRestore(CleanupKind kind, Address SPMem); |
2056 | | void emitDestroy(Address addr, QualType type, Destroyer *destroyer, |
2057 | | bool useEHCleanupForArray); |
2058 | | llvm::Function *generateDestroyHelper(Address addr, QualType type, |
2059 | | Destroyer *destroyer, |
2060 | | bool useEHCleanupForArray, |
2061 | | const VarDecl *VD); |
2062 | | void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, |
2063 | | QualType elementType, CharUnits elementAlign, |
2064 | | Destroyer *destroyer, |
2065 | | bool checkZeroLength, bool useEHCleanup); |
2066 | | |
2067 | | Destroyer *getDestroyer(QualType::DestructionKind destructionKind); |
2068 | | |
2069 | | /// Determines whether an EH cleanup is required to destroy a type |
2070 | | /// with the given destruction kind. |
2071 | 24.0k | bool needsEHCleanup(QualType::DestructionKind kind) { |
2072 | 24.0k | switch (kind) { |
2073 | 17.8k | case QualType::DK_none: |
2074 | 17.8k | return false; |
2075 | 5.10k | case QualType::DK_cxx_destructor: |
2076 | 5.59k | case QualType::DK_objc_weak_lifetime: |
2077 | 5.68k | case QualType::DK_nontrivial_c_struct: |
2078 | 5.68k | return getLangOpts().Exceptions; |
2079 | 560 | case QualType::DK_objc_strong_lifetime: |
2080 | 560 | return getLangOpts().Exceptions && |
2081 | 560 | CGM.getCodeGenOpts().ObjCAutoRefCountExceptions90 ; |
2082 | 24.0k | } |
2083 | 0 | llvm_unreachable("bad destruction kind"); |
2084 | 0 | } |
2085 | | |
2086 | 1.84k | CleanupKind getCleanupKind(QualType::DestructionKind kind) { |
2087 | 1.84k | return (needsEHCleanup(kind) ? NormalAndEHCleanup913 : NormalCleanup933 ); |
2088 | 1.84k | } |
2089 | | |
2090 | | //===--------------------------------------------------------------------===// |
2091 | | // Objective-C |
2092 | | //===--------------------------------------------------------------------===// |
2093 | | |
2094 | | void GenerateObjCMethod(const ObjCMethodDecl *OMD); |
2095 | | |
2096 | | void StartObjCMethod(const ObjCMethodDecl *MD, const ObjCContainerDecl *CD); |
2097 | | |
2098 | | /// GenerateObjCGetter - Synthesize an Objective-C property getter function. |
2099 | | void GenerateObjCGetter(ObjCImplementationDecl *IMP, |
2100 | | const ObjCPropertyImplDecl *PID); |
2101 | | void generateObjCGetterBody(const ObjCImplementationDecl *classImpl, |
2102 | | const ObjCPropertyImplDecl *propImpl, |
2103 | | const ObjCMethodDecl *GetterMothodDecl, |
2104 | | llvm::Constant *AtomicHelperFn); |
2105 | | |
2106 | | void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, |
2107 | | ObjCMethodDecl *MD, bool ctor); |
2108 | | |
2109 | | /// GenerateObjCSetter - Synthesize an Objective-C property setter function |
2110 | | /// for the given property. |
2111 | | void GenerateObjCSetter(ObjCImplementationDecl *IMP, |
2112 | | const ObjCPropertyImplDecl *PID); |
2113 | | void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, |
2114 | | const ObjCPropertyImplDecl *propImpl, |
2115 | | llvm::Constant *AtomicHelperFn); |
2116 | | |
2117 | | //===--------------------------------------------------------------------===// |
2118 | | // Block Bits |
2119 | | //===--------------------------------------------------------------------===// |
2120 | | |
2121 | | /// Emit block literal. |
2122 | | /// \return an LLVM value which is a pointer to a struct which contains |
2123 | | /// information about the block, including the block invoke function, the |
2124 | | /// captured variables, etc. |
2125 | | llvm::Value *EmitBlockLiteral(const BlockExpr *); |
2126 | | |
2127 | | llvm::Function *GenerateBlockFunction(GlobalDecl GD, |
2128 | | const CGBlockInfo &Info, |
2129 | | const DeclMapTy &ldm, |
2130 | | bool IsLambdaConversionToBlock, |
2131 | | bool BuildGlobalBlock); |
2132 | | |
2133 | | /// Check if \p T is a C++ class that has a destructor that can throw. |
2134 | | static bool cxxDestructorCanThrow(QualType T); |
2135 | | |
2136 | | llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo); |
2137 | | llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo); |
2138 | | llvm::Constant *GenerateObjCAtomicSetterCopyHelperFunction( |
2139 | | const ObjCPropertyImplDecl *PID); |
2140 | | llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction( |
2141 | | const ObjCPropertyImplDecl *PID); |
2142 | | llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty); |
2143 | | |
2144 | | void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags, |
2145 | | bool CanThrow); |
2146 | | |
2147 | | class AutoVarEmission; |
2148 | | |
2149 | | void emitByrefStructureInit(const AutoVarEmission &emission); |
2150 | | |
2151 | | /// Enter a cleanup to destroy a __block variable. Note that this |
2152 | | /// cleanup should be a no-op if the variable hasn't left the stack |
2153 | | /// yet; if a cleanup is required for the variable itself, that needs |
2154 | | /// to be done externally. |
2155 | | /// |
2156 | | /// \param Kind Cleanup kind. |
2157 | | /// |
2158 | | /// \param Addr When \p LoadBlockVarAddr is false, the address of the __block |
2159 | | /// structure that will be passed to _Block_object_dispose. When |
2160 | | /// \p LoadBlockVarAddr is true, the address of the field of the block |
2161 | | /// structure that holds the address of the __block structure. |
2162 | | /// |
2163 | | /// \param Flags The flag that will be passed to _Block_object_dispose. |
2164 | | /// |
2165 | | /// \param LoadBlockVarAddr Indicates whether we need to emit a load from |
2166 | | /// \p Addr to get the address of the __block structure. |
2167 | | void enterByrefCleanup(CleanupKind Kind, Address Addr, BlockFieldFlags Flags, |
2168 | | bool LoadBlockVarAddr, bool CanThrow); |
2169 | | |
2170 | | void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, |
2171 | | llvm::Value *ptr); |
2172 | | |
2173 | | Address LoadBlockStruct(); |
2174 | | Address GetAddrOfBlockDecl(const VarDecl *var); |
2175 | | |
2176 | | /// BuildBlockByrefAddress - Computes the location of the |
2177 | | /// data in a variable which is declared as __block. |
2178 | | Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, |
2179 | | bool followForward = true); |
2180 | | Address emitBlockByrefAddress(Address baseAddr, |
2181 | | const BlockByrefInfo &info, |
2182 | | bool followForward, |
2183 | | const llvm::Twine &name); |
2184 | | |
2185 | | const BlockByrefInfo &getBlockByrefInfo(const VarDecl *var); |
2186 | | |
2187 | | QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args); |
2188 | | |
2189 | | void GenerateCode(GlobalDecl GD, llvm::Function *Fn, |
2190 | | const CGFunctionInfo &FnInfo); |
2191 | | |
2192 | | /// Annotate the function with an attribute that disables TSan checking at |
2193 | | /// runtime. |
2194 | | void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn); |
2195 | | |
2196 | | /// Emit code for the start of a function. |
2197 | | /// \param Loc The location to be associated with the function. |
2198 | | /// \param StartLoc The location of the function body. |
2199 | | void StartFunction(GlobalDecl GD, |
2200 | | QualType RetTy, |
2201 | | llvm::Function *Fn, |
2202 | | const CGFunctionInfo &FnInfo, |
2203 | | const FunctionArgList &Args, |
2204 | | SourceLocation Loc = SourceLocation(), |
2205 | | SourceLocation StartLoc = SourceLocation()); |
2206 | | |
2207 | | static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor); |
2208 | | |
2209 | | void EmitConstructorBody(FunctionArgList &Args); |
2210 | | void EmitDestructorBody(FunctionArgList &Args); |
2211 | | void emitImplicitAssignmentOperatorBody(FunctionArgList &Args); |
2212 | | void EmitFunctionBody(const Stmt *Body); |
2213 | | void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S); |
2214 | | |
2215 | | void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator, |
2216 | | CallArgList &CallArgs); |
2217 | | void EmitLambdaBlockInvokeBody(); |
2218 | | void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD); |
2219 | | void EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD); |
2220 | 73 | void EmitLambdaVLACapture(const VariableArrayType *VAT, LValue LV) { |
2221 | 73 | EmitStoreThroughLValue(RValue::get(VLASizeMap[VAT->getSizeExpr()]), LV); |
2222 | 73 | } |
2223 | | void EmitAsanPrologueOrEpilogue(bool Prologue); |
2224 | | |
2225 | | /// Emit the unified return block, trying to avoid its emission when |
2226 | | /// possible. |
2227 | | /// \return The debug location of the user written return statement if the |
2228 | | /// return block is is avoided. |
2229 | | llvm::DebugLoc EmitReturnBlock(); |
2230 | | |
2231 | | /// FinishFunction - Complete IR generation of the current function. It is |
2232 | | /// legal to call this function even if there is no current insertion point. |
2233 | | void FinishFunction(SourceLocation EndLoc=SourceLocation()); |
2234 | | |
2235 | | void StartThunk(llvm::Function *Fn, GlobalDecl GD, |
2236 | | const CGFunctionInfo &FnInfo, bool IsUnprototyped); |
2237 | | |
2238 | | void EmitCallAndReturnForThunk(llvm::FunctionCallee Callee, |
2239 | | const ThunkInfo *Thunk, bool IsUnprototyped); |
2240 | | |
2241 | | void FinishThunk(); |
2242 | | |
2243 | | /// Emit a musttail call for a thunk with a potentially adjusted this pointer. |
2244 | | void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr, |
2245 | | llvm::FunctionCallee Callee); |
2246 | | |
2247 | | /// Generate a thunk for the given method. |
2248 | | void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, |
2249 | | GlobalDecl GD, const ThunkInfo &Thunk, |
2250 | | bool IsUnprototyped); |
2251 | | |
2252 | | llvm::Function *GenerateVarArgsThunk(llvm::Function *Fn, |
2253 | | const CGFunctionInfo &FnInfo, |
2254 | | GlobalDecl GD, const ThunkInfo &Thunk); |
2255 | | |
2256 | | void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, |
2257 | | FunctionArgList &Args); |
2258 | | |
2259 | | void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init); |
2260 | | |
2261 | | /// Struct with all information about dynamic [sub]class needed to set vptr. |
2262 | | struct VPtr { |
2263 | | BaseSubobject Base; |
2264 | | const CXXRecordDecl *NearestVBase; |
2265 | | CharUnits OffsetFromNearestVBase; |
2266 | | const CXXRecordDecl *VTableClass; |
2267 | | }; |
2268 | | |
2269 | | /// Initialize the vtable pointer of the given subobject. |
2270 | | void InitializeVTablePointer(const VPtr &vptr); |
2271 | | |
2272 | | typedef llvm::SmallVector<VPtr, 4> VPtrsVector; |
2273 | | |
2274 | | typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy; |
2275 | | VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass); |
2276 | | |
2277 | | void getVTablePointers(BaseSubobject Base, const CXXRecordDecl *NearestVBase, |
2278 | | CharUnits OffsetFromNearestVBase, |
2279 | | bool BaseIsNonVirtualPrimaryBase, |
2280 | | const CXXRecordDecl *VTableClass, |
2281 | | VisitedVirtualBasesSetTy &VBases, VPtrsVector &vptrs); |
2282 | | |
2283 | | void InitializeVTablePointers(const CXXRecordDecl *ClassDecl); |
2284 | | |
2285 | | /// GetVTablePtr - Return the Value of the vtable pointer member pointed |
2286 | | /// to by This. |
2287 | | llvm::Value *GetVTablePtr(Address This, llvm::Type *VTableTy, |
2288 | | const CXXRecordDecl *VTableClass); |
2289 | | |
2290 | | enum CFITypeCheckKind { |
2291 | | CFITCK_VCall, |
2292 | | CFITCK_NVCall, |
2293 | | CFITCK_DerivedCast, |
2294 | | CFITCK_UnrelatedCast, |
2295 | | CFITCK_ICall, |
2296 | | CFITCK_NVMFCall, |
2297 | | CFITCK_VMFCall, |
2298 | | }; |
2299 | | |
2300 | | /// Derived is the presumed address of an object of type T after a |
2301 | | /// cast. If T is a polymorphic class type, emit a check that the virtual |
2302 | | /// table for Derived belongs to a class derived from T. |
2303 | | void EmitVTablePtrCheckForCast(QualType T, Address Derived, bool MayBeNull, |
2304 | | CFITypeCheckKind TCK, SourceLocation Loc); |
2305 | | |
2306 | | /// EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable. |
2307 | | /// If vptr CFI is enabled, emit a check that VTable is valid. |
2308 | | void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable, |
2309 | | CFITypeCheckKind TCK, SourceLocation Loc); |
2310 | | |
2311 | | /// EmitVTablePtrCheck - Emit a check that VTable is a valid virtual table for |
2312 | | /// RD using llvm.type.test. |
2313 | | void EmitVTablePtrCheck(const CXXRecordDecl *RD, llvm::Value *VTable, |
2314 | | CFITypeCheckKind TCK, SourceLocation Loc); |
2315 | | |
2316 | | /// If whole-program virtual table optimization is enabled, emit an assumption |
2317 | | /// that VTable is a member of RD's type identifier. Or, if vptr CFI is |
2318 | | /// enabled, emit a check that VTable is a member of RD's type identifier. |
2319 | | void EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, |
2320 | | llvm::Value *VTable, SourceLocation Loc); |
2321 | | |
2322 | | /// Returns whether we should perform a type checked load when loading a |
2323 | | /// virtual function for virtual calls to members of RD. This is generally |
2324 | | /// true when both vcall CFI and whole-program-vtables are enabled. |
2325 | | bool ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD); |
2326 | | |
2327 | | /// Emit a type checked load from the given vtable. |
2328 | | llvm::Value *EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, |
2329 | | llvm::Value *VTable, |
2330 | | llvm::Type *VTableTy, |
2331 | | uint64_t VTableByteOffset); |
2332 | | |
2333 | | /// EnterDtorCleanups - Enter the cleanups necessary to complete the |
2334 | | /// given phase of destruction for a destructor. The end result |
2335 | | /// should call destructors on members and base classes in reverse |
2336 | | /// order of their construction. |
2337 | | void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type); |
2338 | | |
2339 | | /// ShouldInstrumentFunction - Return true if the current function should be |
2340 | | /// instrumented with __cyg_profile_func_* calls |
2341 | | bool ShouldInstrumentFunction(); |
2342 | | |
2343 | | /// ShouldSkipSanitizerInstrumentation - Return true if the current function |
2344 | | /// should not be instrumented with sanitizers. |
2345 | | bool ShouldSkipSanitizerInstrumentation(); |
2346 | | |
2347 | | /// ShouldXRayInstrument - Return true if the current function should be |
2348 | | /// instrumented with XRay nop sleds. |
2349 | | bool ShouldXRayInstrumentFunction() const; |
2350 | | |
2351 | | /// AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit |
2352 | | /// XRay custom event handling calls. |
2353 | | bool AlwaysEmitXRayCustomEvents() const; |
2354 | | |
2355 | | /// AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit |
2356 | | /// XRay typed event handling calls. |
2357 | | bool AlwaysEmitXRayTypedEvents() const; |
2358 | | |
2359 | | /// Decode an address used in a function prologue, encoded by \c |
2360 | | /// EncodeAddrForUseInPrologue. |
2361 | | llvm::Value *DecodeAddrUsedInPrologue(llvm::Value *F, |
2362 | | llvm::Value *EncodedAddr); |
2363 | | |
2364 | | /// EmitFunctionProlog - Emit the target specific LLVM code to load the |
2365 | | /// arguments for the given function. This is also responsible for naming the |
2366 | | /// LLVM function arguments. |
2367 | | void EmitFunctionProlog(const CGFunctionInfo &FI, |
2368 | | llvm::Function *Fn, |
2369 | | const FunctionArgList &Args); |
2370 | | |
2371 | | /// EmitFunctionEpilog - Emit the target specific LLVM code to return the |
2372 | | /// given temporary. |
2373 | | void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, |
2374 | | SourceLocation EndLoc); |
2375 | | |
2376 | | /// Emit a test that checks if the return value \p RV is nonnull. |
2377 | | void EmitReturnValueCheck(llvm::Value *RV); |
2378 | | |
2379 | | /// EmitStartEHSpec - Emit the start of the exception spec. |
2380 | | void EmitStartEHSpec(const Decl *D); |
2381 | | |
2382 | | /// EmitEndEHSpec - Emit the end of the exception spec. |
2383 | | void EmitEndEHSpec(const Decl *D); |
2384 | | |
2385 | | /// getTerminateLandingPad - Return a landing pad that just calls terminate. |
2386 | | llvm::BasicBlock *getTerminateLandingPad(); |
2387 | | |
2388 | | /// getTerminateLandingPad - Return a cleanup funclet that just calls |
2389 | | /// terminate. |
2390 | | llvm::BasicBlock *getTerminateFunclet(); |
2391 | | |
2392 | | /// getTerminateHandler - Return a handler (not a landing pad, just |
2393 | | /// a catch handler) that just calls terminate. This is used when |
2394 | | /// a terminate scope encloses a try. |
2395 | | llvm::BasicBlock *getTerminateHandler(); |
2396 | | |
2397 | | llvm::Type *ConvertTypeForMem(QualType T); |
2398 | | llvm::Type *ConvertType(QualType T); |
2399 | 22.6k | llvm::Type *ConvertType(const TypeDecl *T) { |
2400 | 22.6k | return ConvertType(getContext().getTypeDeclType(T)); |
2401 | 22.6k | } |
2402 | | |
2403 | | /// LoadObjCSelf - Load the value of self. This function is only valid while |
2404 | | /// generating code for an Objective-C method. |
2405 | | llvm::Value *LoadObjCSelf(); |
2406 | | |
2407 | | /// TypeOfSelfObject - Return type of object that this self represents. |
2408 | | QualType TypeOfSelfObject(); |
2409 | | |
2410 | | /// getEvaluationKind - Return the TypeEvaluationKind of QualType \c T. |
2411 | | static TypeEvaluationKind getEvaluationKind(QualType T); |
2412 | | |
2413 | 3.96M | static bool hasScalarEvaluationKind(QualType T) { |
2414 | 3.96M | return getEvaluationKind(T) == TEK_Scalar; |
2415 | 3.96M | } |
2416 | | |
2417 | 783k | static bool hasAggregateEvaluationKind(QualType T) { |
2418 | 783k | return getEvaluationKind(T) == TEK_Aggregate; |
2419 | 783k | } |
2420 | | |
2421 | | /// createBasicBlock - Create an LLVM basic block. |
2422 | | llvm::BasicBlock *createBasicBlock(const Twine &name = "", |
2423 | | llvm::Function *parent = nullptr, |
2424 | 1.23M | llvm::BasicBlock *before = nullptr) { |
2425 | 1.23M | return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before); |
2426 | 1.23M | } |
2427 | | |
2428 | | /// getBasicBlockForLabel - Return the LLVM basicblock that the specified |
2429 | | /// label maps to. |
2430 | | JumpDest getJumpDestForLabel(const LabelDecl *S); |
2431 | | |
2432 | | /// SimplifyForwardingBlocks - If the given basic block is only a branch to |
2433 | | /// another basic block, simplify it. This assumes that no other code could |
2434 | | /// potentially reference the basic block. |
2435 | | void SimplifyForwardingBlocks(llvm::BasicBlock *BB); |
2436 | | |
2437 | | /// EmitBlock - Emit the given block \arg BB and set it as the insert point, |
2438 | | /// adding a fall-through branch from the current insert block if |
2439 | | /// necessary. It is legal to call this function even if there is no current |
2440 | | /// insertion point. |
2441 | | /// |
2442 | | /// IsFinished - If true, indicates that the caller has finished emitting |
2443 | | /// branches to the given block and does not expect to emit code into it. This |
2444 | | /// means the block can be ignored if it is unreachable. |
2445 | | void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); |
2446 | | |
2447 | | /// EmitBlockAfterUses - Emit the given block somewhere hopefully |
2448 | | /// near its uses, and leave the insertion point in it. |
2449 | | void EmitBlockAfterUses(llvm::BasicBlock *BB); |
2450 | | |
2451 | | /// EmitBranch - Emit a branch to the specified basic block from the current |
2452 | | /// insert block, taking care to avoid creation of branches from dummy |
2453 | | /// blocks. It is legal to call this function even if there is no current |
2454 | | /// insertion point. |
2455 | | /// |
2456 | | /// This function clears the current insertion point. The caller should follow |
2457 | | /// calls to this function with calls to Emit*Block prior to generation new |
2458 | | /// code. |
2459 | | void EmitBranch(llvm::BasicBlock *Block); |
2460 | | |
2461 | | /// HaveInsertPoint - True if an insertion point is defined. If not, this |
2462 | | /// indicates that the current code being emitted is unreachable. |
2463 | 2.36M | bool HaveInsertPoint() const { |
2464 | 2.36M | return Builder.GetInsertBlock() != nullptr; |
2465 | 2.36M | } |
2466 | | |
2467 | | /// EnsureInsertPoint - Ensure that an insertion point is defined so that |
2468 | | /// emitted IR has a place to go. Note that by definition, if this function |
2469 | | /// creates a block then that block is unreachable; callers may do better to |
2470 | | /// detect when no insertion point is defined and simply skip IR generation. |
2471 | 22.1k | void EnsureInsertPoint() { |
2472 | 22.1k | if (!HaveInsertPoint()) |
2473 | 2.38k | EmitBlock(createBasicBlock()); |
2474 | 22.1k | } |
2475 | | |
2476 | | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
2477 | | /// specified stmt yet. |
2478 | | void ErrorUnsupported(const Stmt *S, const char *Type); |
2479 | | |
2480 | | //===--------------------------------------------------------------------===// |
2481 | | // Helpers |
2482 | | //===--------------------------------------------------------------------===// |
2483 | | |
2484 | | LValue MakeAddrLValue(Address Addr, QualType T, |
2485 | 2.30M | AlignmentSource Source = AlignmentSource::Type) { |
2486 | 2.30M | return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source), |
2487 | 2.30M | CGM.getTBAAAccessInfo(T)); |
2488 | 2.30M | } |
2489 | | |
2490 | | LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo, |
2491 | 725k | TBAAAccessInfo TBAAInfo) { |
2492 | 725k | return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo); |
2493 | 725k | } |
2494 | | |
2495 | | LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, |
2496 | 16.6k | AlignmentSource Source = AlignmentSource::Type) { |
2497 | 16.6k | Address Addr(V, ConvertTypeForMem(T), Alignment); |
2498 | 16.6k | return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source), |
2499 | 16.6k | CGM.getTBAAAccessInfo(T)); |
2500 | 16.6k | } |
2501 | | |
2502 | | LValue |
2503 | | MakeAddrLValueWithoutTBAA(Address Addr, QualType T, |
2504 | 30 | AlignmentSource Source = AlignmentSource::Type) { |
2505 | 30 | return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source), |
2506 | 30 | TBAAAccessInfo()); |
2507 | 30 | } |
2508 | | |
2509 | | LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T); |
2510 | | LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T); |
2511 | | |
2512 | | Address EmitLoadOfReference(LValue RefLVal, |
2513 | | LValueBaseInfo *PointeeBaseInfo = nullptr, |
2514 | | TBAAAccessInfo *PointeeTBAAInfo = nullptr); |
2515 | | LValue EmitLoadOfReferenceLValue(LValue RefLVal); |
2516 | | LValue EmitLoadOfReferenceLValue(Address RefAddr, QualType RefTy, |
2517 | | AlignmentSource Source = |
2518 | 59.5k | AlignmentSource::Type) { |
2519 | 59.5k | LValue RefLVal = MakeAddrLValue(RefAddr, RefTy, LValueBaseInfo(Source), |
2520 | 59.5k | CGM.getTBAAAccessInfo(RefTy)); |
2521 | 59.5k | return EmitLoadOfReferenceLValue(RefLVal); |
2522 | 59.5k | } |
2523 | | |
2524 | | /// Load a pointer with type \p PtrTy stored at address \p Ptr. |
2525 | | /// Note that \p PtrTy is the type of the loaded pointer, not the addresses |
2526 | | /// it is loaded from. |
2527 | | Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, |
2528 | | LValueBaseInfo *BaseInfo = nullptr, |
2529 | | TBAAAccessInfo *TBAAInfo = nullptr); |
2530 | | LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy); |
2531 | | |
2532 | | /// CreateTempAlloca - This creates an alloca and inserts it into the entry |
2533 | | /// block if \p ArraySize is nullptr, otherwise inserts it at the current |
2534 | | /// insertion point of the builder. The caller is responsible for setting an |
2535 | | /// appropriate alignment on |
2536 | | /// the alloca. |
2537 | | /// |
2538 | | /// \p ArraySize is the number of array elements to be allocated if it |
2539 | | /// is not nullptr. |
2540 | | /// |
2541 | | /// LangAS::Default is the address space of pointers to local variables and |
2542 | | /// temporaries, as exposed in the source language. In certain |
2543 | | /// configurations, this is not the same as the alloca address space, and a |
2544 | | /// cast is needed to lift the pointer from the alloca AS into |
2545 | | /// LangAS::Default. This can happen when the target uses a restricted |
2546 | | /// address space for the stack but the source language requires |
2547 | | /// LangAS::Default to be a generic address space. The latter condition is |
2548 | | /// common for most programming languages; OpenCL is an exception in that |
2549 | | /// LangAS::Default is the private address space, which naturally maps |
2550 | | /// to the stack. |
2551 | | /// |
2552 | | /// Because the address of a temporary is often exposed to the program in |
2553 | | /// various ways, this function will perform the cast. The original alloca |
2554 | | /// instruction is returned through \p Alloca if it is not nullptr. |
2555 | | /// |
2556 | | /// The cast is not performaed in CreateTempAllocaWithoutCast. This is |
2557 | | /// more efficient if the caller knows that the address will not be exposed. |
2558 | | llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, const Twine &Name = "tmp", |
2559 | | llvm::Value *ArraySize = nullptr); |
2560 | | Address CreateTempAlloca(llvm::Type *Ty, CharUnits align, |
2561 | | const Twine &Name = "tmp", |
2562 | | llvm::Value *ArraySize = nullptr, |
2563 | | Address *Alloca = nullptr); |
2564 | | Address CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, |
2565 | | const Twine &Name = "tmp", |
2566 | | llvm::Value *ArraySize = nullptr); |
2567 | | |
2568 | | /// CreateDefaultAlignedTempAlloca - This creates an alloca with the |
2569 | | /// default ABI alignment of the given LLVM type. |
2570 | | /// |
2571 | | /// IMPORTANT NOTE: This is *not* generally the right alignment for |
2572 | | /// any given AST type that happens to have been lowered to the |
2573 | | /// given IR type. This should only ever be used for function-local, |
2574 | | /// IR-driven manipulations like saving and restoring a value. Do |
2575 | | /// not hand this address off to arbitrary IRGen routines, and especially |
2576 | | /// do not pass it as an argument to a function that might expect a |
2577 | | /// properly ABI-aligned value. |
2578 | | Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, |
2579 | | const Twine &Name = "tmp"); |
2580 | | |
2581 | | /// CreateIRTemp - Create a temporary IR object of the given type, with |
2582 | | /// appropriate alignment. This routine should only be used when an temporary |
2583 | | /// value needs to be stored into an alloca (for example, to avoid explicit |
2584 | | /// PHI construction), but the type is the IR type, not the type appropriate |
2585 | | /// for storing in memory. |
2586 | | /// |
2587 | | /// That is, this is exactly equivalent to CreateMemTemp, but calling |
2588 | | /// ConvertType instead of ConvertTypeForMem. |
2589 | | Address CreateIRTemp(QualType T, const Twine &Name = "tmp"); |
2590 | | |
2591 | | /// CreateMemTemp - Create a temporary memory object of the given type, with |
2592 | | /// appropriate alignmen and cast it to the default address space. Returns |
2593 | | /// the original alloca instruction by \p Alloca if it is not nullptr. |
2594 | | Address CreateMemTemp(QualType T, const Twine &Name = "tmp", |
2595 | | Address *Alloca = nullptr); |
2596 | | Address CreateMemTemp(QualType T, CharUnits Align, const Twine &Name = "tmp", |
2597 | | Address *Alloca = nullptr); |
2598 | | |
2599 | | /// CreateMemTemp - Create a temporary memory object of the given type, with |
2600 | | /// appropriate alignmen without casting it to the default address space. |
2601 | | Address CreateMemTempWithoutCast(QualType T, const Twine &Name = "tmp"); |
2602 | | Address CreateMemTempWithoutCast(QualType T, CharUnits Align, |
2603 | | const Twine &Name = "tmp"); |
2604 | | |
2605 | | /// CreateAggTemp - Create a temporary memory object for the given |
2606 | | /// aggregate type. |
2607 | | AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp", |
2608 | 10.3k | Address *Alloca = nullptr) { |
2609 | 10.3k | return AggValueSlot::forAddr(CreateMemTemp(T, Name, Alloca), |
2610 | 10.3k | T.getQualifiers(), |
2611 | 10.3k | AggValueSlot::IsNotDestructed, |
2612 | 10.3k | AggValueSlot::DoesNotNeedGCBarriers, |
2613 | 10.3k | AggValueSlot::IsNotAliased, |
2614 | 10.3k | AggValueSlot::DoesNotOverlap); |
2615 | 10.3k | } |
2616 | | |
2617 | | /// Emit a cast to void* in the appropriate address space. |
2618 | | llvm::Value *EmitCastToVoidPtr(llvm::Value *value); |
2619 | | |
2620 | | /// EvaluateExprAsBool - Perform the usual unary conversions on the specified |
2621 | | /// expression and compare the result against zero, returning an Int1Ty value. |
2622 | | llvm::Value *EvaluateExprAsBool(const Expr *E); |
2623 | | |
2624 | | /// EmitIgnoredExpr - Emit an expression in a context which ignores the result. |
2625 | | void EmitIgnoredExpr(const Expr *E); |
2626 | | |
2627 | | /// EmitAnyExpr - Emit code to compute the specified expression which can have |
2628 | | /// any type. The result is returned as an RValue struct. If this is an |
2629 | | /// aggregate expression, the aggloc/agglocvolatile arguments indicate where |
2630 | | /// the result should be returned. |
2631 | | /// |
2632 | | /// \param ignoreResult True if the resulting value isn't used. |
2633 | | RValue EmitAnyExpr(const Expr *E, |
2634 | | AggValueSlot aggSlot = AggValueSlot::ignored(), |
2635 | | bool ignoreResult = false); |
2636 | | |
2637 | | // EmitVAListRef - Emit a "reference" to a va_list; this is either the address |
2638 | | // or the value of the expression, depending on how va_list is defined. |
2639 | | Address EmitVAListRef(const Expr *E); |
2640 | | |
2641 | | /// Emit a "reference" to a __builtin_ms_va_list; this is |
2642 | | /// always the value of the expression, because a __builtin_ms_va_list is a |
2643 | | /// pointer to a char. |
2644 | | Address EmitMSVAListRef(const Expr *E); |
2645 | | |
2646 | | /// EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will |
2647 | | /// always be accessible even if no aggregate location is provided. |
2648 | | RValue EmitAnyExprToTemp(const Expr *E); |
2649 | | |
2650 | | /// EmitAnyExprToMem - Emits the code necessary to evaluate an |
2651 | | /// arbitrary expression into the given memory location. |
2652 | | void EmitAnyExprToMem(const Expr *E, Address Location, |
2653 | | Qualifiers Quals, bool IsInitializer); |
2654 | | |
2655 | | void EmitAnyExprToExn(const Expr *E, Address Addr); |
2656 | | |
2657 | | /// EmitExprAsInit - Emits the code necessary to initialize a |
2658 | | /// location in memory with the given initializer. |
2659 | | void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, |
2660 | | bool capturedByInit); |
2661 | | |
2662 | | /// hasVolatileMember - returns true if aggregate type has a volatile |
2663 | | /// member. |
2664 | 4.65k | bool hasVolatileMember(QualType T) { |
2665 | 4.65k | if (const RecordType *RT = T->getAs<RecordType>()) { |
2666 | 3.17k | const RecordDecl *RD = cast<RecordDecl>(RT->getDecl()); |
2667 | 3.17k | return RD->hasVolatileMember(); |
2668 | 3.17k | } |
2669 | 1.48k | return false; |
2670 | 4.65k | } |
2671 | | |
2672 | | /// Determine whether a return value slot may overlap some other object. |
2673 | 6.75k | AggValueSlot::Overlap_t getOverlapForReturnValue() { |
2674 | | // FIXME: Assuming no overlap here breaks guaranteed copy elision for base |
2675 | | // class subobjects. These cases may need to be revisited depending on the |
2676 | | // resolution of the relevant core issue. |
2677 | 6.75k | return AggValueSlot::DoesNotOverlap; |
2678 | 6.75k | } |
2679 | | |
2680 | | /// Determine whether a field initialization may overlap some other object. |
2681 | | AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD); |
2682 | | |
2683 | | /// Determine whether a base class initialization may overlap some other |
2684 | | /// object. |
2685 | | AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *RD, |
2686 | | const CXXRecordDecl *BaseRD, |
2687 | | bool IsVirtual); |
2688 | | |
2689 | | /// Emit an aggregate assignment. |
2690 | 4.19k | void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy) { |
2691 | 4.19k | bool IsVolatile = hasVolatileMember(EltTy); |
2692 | 4.19k | EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile); |
2693 | 4.19k | } |
2694 | | |
2695 | | void EmitAggregateCopyCtor(LValue Dest, LValue Src, |
2696 | 6.03k | AggValueSlot::Overlap_t MayOverlap) { |
2697 | 6.03k | EmitAggregateCopy(Dest, Src, Src.getType(), MayOverlap); |
2698 | 6.03k | } |
2699 | | |
2700 | | /// EmitAggregateCopy - Emit an aggregate copy. |
2701 | | /// |
2702 | | /// \param isVolatile \c true iff either the source or the destination is |
2703 | | /// volatile. |
2704 | | /// \param MayOverlap Whether the tail padding of the destination might be |
2705 | | /// occupied by some other object. More efficient code can often be |
2706 | | /// generated if not. |
2707 | | void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, |
2708 | | AggValueSlot::Overlap_t MayOverlap, |
2709 | | bool isVolatile = false); |
2710 | | |
2711 | | /// GetAddrOfLocalVar - Return the address of a local variable. |
2712 | 198k | Address GetAddrOfLocalVar(const VarDecl *VD) { |
2713 | 198k | auto it = LocalDeclMap.find(VD); |
2714 | 198k | assert(it != LocalDeclMap.end() && |
2715 | 198k | "Invalid argument to GetAddrOfLocalVar(), no decl!"); |
2716 | 0 | return it->second; |
2717 | 198k | } |
2718 | | |
2719 | | /// Given an opaque value expression, return its LValue mapping if it exists, |
2720 | | /// otherwise create one. |
2721 | | LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e); |
2722 | | |
2723 | | /// Given an opaque value expression, return its RValue mapping if it exists, |
2724 | | /// otherwise create one. |
2725 | | RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e); |
2726 | | |
2727 | | /// Get the index of the current ArrayInitLoopExpr, if any. |
2728 | 78 | llvm::Value *getArrayInitIndex() { return ArrayInitIndex; } |
2729 | | |
2730 | | /// getAccessedFieldNo - Given an encoded value and a result number, return |
2731 | | /// the input field number being accessed. |
2732 | | static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); |
2733 | | |
2734 | | llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L); |
2735 | | llvm::BasicBlock *GetIndirectGotoBlock(); |
2736 | | |
2737 | | /// Check if \p E is a C++ "this" pointer wrapped in value-preserving casts. |
2738 | | static bool IsWrappedCXXThis(const Expr *E); |
2739 | | |
2740 | | /// EmitNullInitialization - Generate code to set a value of the given type to |
2741 | | /// null, If the type contains data member pointers, they will be initialized |
2742 | | /// to -1 in accordance with the Itanium C++ ABI. |
2743 | | void EmitNullInitialization(Address DestPtr, QualType Ty); |
2744 | | |
2745 | | /// Emits a call to an LLVM variable-argument intrinsic, either |
2746 | | /// \c llvm.va_start or \c llvm.va_end. |
2747 | | /// \param ArgValue A reference to the \c va_list as emitted by either |
2748 | | /// \c EmitVAListRef or \c EmitMSVAListRef. |
2749 | | /// \param IsStart If \c true, emits a call to \c llvm.va_start; otherwise, |
2750 | | /// calls \c llvm.va_end. |
2751 | | llvm::Value *EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart); |
2752 | | |
2753 | | /// Generate code to get an argument from the passed in pointer |
2754 | | /// and update it accordingly. |
2755 | | /// \param VE The \c VAArgExpr for which to generate code. |
2756 | | /// \param VAListAddr Receives a reference to the \c va_list as emitted by |
2757 | | /// either \c EmitVAListRef or \c EmitMSVAListRef. |
2758 | | /// \returns A pointer to the argument. |
2759 | | // FIXME: We should be able to get rid of this method and use the va_arg |
2760 | | // instruction in LLVM instead once it works well enough. |
2761 | | Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr); |
2762 | | |
2763 | | /// emitArrayLength - Compute the length of an array, even if it's a |
2764 | | /// VLA, and drill down to the base element type. |
2765 | | llvm::Value *emitArrayLength(const ArrayType *arrayType, |
2766 | | QualType &baseType, |
2767 | | Address &addr); |
2768 | | |
2769 | | /// EmitVLASize - Capture all the sizes for the VLA expressions in |
2770 | | /// the given variably-modified type and store them in the VLASizeMap. |
2771 | | /// |
2772 | | /// This function can be called with a null (unreachable) insert point. |
2773 | | void EmitVariablyModifiedType(QualType Ty); |
2774 | | |
2775 | | struct VlaSizePair { |
2776 | | llvm::Value *NumElts; |
2777 | | QualType Type; |
2778 | | |
2779 | 12.2k | VlaSizePair(llvm::Value *NE, QualType T) : NumElts(NE), Type(T) {} |
2780 | | }; |
2781 | | |
2782 | | /// Return the number of elements for a single dimension |
2783 | | /// for the given array type. |
2784 | | VlaSizePair getVLAElements1D(const VariableArrayType *vla); |
2785 | | VlaSizePair getVLAElements1D(QualType vla); |
2786 | | |
2787 | | /// Returns an LLVM value that corresponds to the size, |
2788 | | /// in non-variably-sized elements, of a variable length array type, |
2789 | | /// plus that largest non-variably-sized element type. Assumes that |
2790 | | /// the type has already been emitted with EmitVariablyModifiedType. |
2791 | | VlaSizePair getVLASize(const VariableArrayType *vla); |
2792 | | VlaSizePair getVLASize(QualType vla); |
2793 | | |
2794 | | /// LoadCXXThis - Load the value of 'this'. This function is only valid while |
2795 | | /// generating code for an C++ member function. |
2796 | 164k | llvm::Value *LoadCXXThis() { |
2797 | 164k | assert(CXXThisValue && "no 'this' value for this function"); |
2798 | 0 | return CXXThisValue; |
2799 | 164k | } |
2800 | | Address LoadCXXThisAddress(); |
2801 | | |
2802 | | /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have |
2803 | | /// virtual bases. |
2804 | | // FIXME: Every place that calls LoadCXXVTT is something |
2805 | | // that needs to be abstracted properly. |
2806 | 351 | llvm::Value *LoadCXXVTT() { |
2807 | 351 | assert(CXXStructorImplicitParamValue && "no VTT value for this function"); |
2808 | 0 | return CXXStructorImplicitParamValue; |
2809 | 351 | } |
2810 | | |
2811 | | /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a |
2812 | | /// complete class to the given direct base. |
2813 | | Address |
2814 | | GetAddressOfDirectBaseInCompleteClass(Address Value, |
2815 | | const CXXRecordDecl *Derived, |
2816 | | const CXXRecordDecl *Base, |
2817 | | bool BaseIsVirtual); |
2818 | | |
2819 | | static bool ShouldNullCheckClassCastValue(const CastExpr *Cast); |
2820 | | |
2821 | | /// GetAddressOfBaseClass - This function will add the necessary delta to the |
2822 | | /// load of 'this' and returns address of the base class. |
2823 | | Address GetAddressOfBaseClass(Address Value, |
2824 | | const CXXRecordDecl *Derived, |
2825 | | CastExpr::path_const_iterator PathBegin, |
2826 | | CastExpr::path_const_iterator PathEnd, |
2827 | | bool NullCheckValue, SourceLocation Loc); |
2828 | | |
2829 | | Address GetAddressOfDerivedClass(Address Value, |
2830 | | const CXXRecordDecl *Derived, |
2831 | | CastExpr::path_const_iterator PathBegin, |
2832 | | CastExpr::path_const_iterator PathEnd, |
2833 | | bool NullCheckValue); |
2834 | | |
2835 | | /// GetVTTParameter - Return the VTT parameter that should be passed to a |
2836 | | /// base constructor/destructor with virtual bases. |
2837 | | /// FIXME: VTTs are Itanium ABI-specific, so the definition should move |
2838 | | /// to ItaniumCXXABI.cpp together with all the references to VTT. |
2839 | | llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, |
2840 | | bool Delegating); |
2841 | | |
2842 | | void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, |
2843 | | CXXCtorType CtorType, |
2844 | | const FunctionArgList &Args, |
2845 | | SourceLocation Loc); |
2846 | | // It's important not to confuse this and the previous function. Delegating |
2847 | | // constructors are the C++0x feature. The constructor delegate optimization |
2848 | | // is used to reduce duplication in the base and complete consturctors where |
2849 | | // they are substantially the same. |
2850 | | void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, |
2851 | | const FunctionArgList &Args); |
2852 | | |
2853 | | /// Emit a call to an inheriting constructor (that is, one that invokes a |
2854 | | /// constructor inherited from a base class) by inlining its definition. This |
2855 | | /// is necessary if the ABI does not support forwarding the arguments to the |
2856 | | /// base class constructor (because they're variadic or similar). |
2857 | | void EmitInlinedInheritingCXXConstructorCall(const CXXConstructorDecl *Ctor, |
2858 | | CXXCtorType CtorType, |
2859 | | bool ForVirtualBase, |
2860 | | bool Delegating, |
2861 | | CallArgList &Args); |
2862 | | |
2863 | | /// Emit a call to a constructor inherited from a base class, passing the |
2864 | | /// current constructor's arguments along unmodified (without even making |
2865 | | /// a copy). |
2866 | | void EmitInheritedCXXConstructorCall(const CXXConstructorDecl *D, |
2867 | | bool ForVirtualBase, Address This, |
2868 | | bool InheritedFromVBase, |
2869 | | const CXXInheritedCtorInitExpr *E); |
2870 | | |
2871 | | void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, |
2872 | | bool ForVirtualBase, bool Delegating, |
2873 | | AggValueSlot ThisAVS, const CXXConstructExpr *E); |
2874 | | |
2875 | | void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, |
2876 | | bool ForVirtualBase, bool Delegating, |
2877 | | Address This, CallArgList &Args, |
2878 | | AggValueSlot::Overlap_t Overlap, |
2879 | | SourceLocation Loc, bool NewPointerIsChecked); |
2880 | | |
2881 | | /// Emit assumption load for all bases. Requires to be be called only on |
2882 | | /// most-derived class and not under construction of the object. |
2883 | | void EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This); |
2884 | | |
2885 | | /// Emit assumption that vptr load == global vtable. |
2886 | | void EmitVTableAssumptionLoad(const VPtr &vptr, Address This); |
2887 | | |
2888 | | void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, |
2889 | | Address This, Address Src, |
2890 | | const CXXConstructExpr *E); |
2891 | | |
2892 | | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
2893 | | const ArrayType *ArrayTy, |
2894 | | Address ArrayPtr, |
2895 | | const CXXConstructExpr *E, |
2896 | | bool NewPointerIsChecked, |
2897 | | bool ZeroInitialization = false); |
2898 | | |
2899 | | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
2900 | | llvm::Value *NumElements, |
2901 | | Address ArrayPtr, |
2902 | | const CXXConstructExpr *E, |
2903 | | bool NewPointerIsChecked, |
2904 | | bool ZeroInitialization = false); |
2905 | | |
2906 | | static Destroyer destroyCXXObject; |
2907 | | |
2908 | | void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, |
2909 | | bool ForVirtualBase, bool Delegating, Address This, |
2910 | | QualType ThisTy); |
2911 | | |
2912 | | void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, |
2913 | | llvm::Type *ElementTy, Address NewPtr, |
2914 | | llvm::Value *NumElements, |
2915 | | llvm::Value *AllocSizeWithoutCookie); |
2916 | | |
2917 | | void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, |
2918 | | Address Ptr); |
2919 | | |
2920 | | void EmitSehCppScopeBegin(); |
2921 | | void EmitSehCppScopeEnd(); |
2922 | | void EmitSehTryScopeBegin(); |
2923 | | void EmitSehTryScopeEnd(); |
2924 | | |
2925 | | llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr); |
2926 | | void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr); |
2927 | | |
2928 | | llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); |
2929 | | void EmitCXXDeleteExpr(const CXXDeleteExpr *E); |
2930 | | |
2931 | | void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, |
2932 | | QualType DeleteTy, llvm::Value *NumElements = nullptr, |
2933 | | CharUnits CookieSize = CharUnits()); |
2934 | | |
2935 | | RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, |
2936 | | const CallExpr *TheCallExpr, bool IsDelete); |
2937 | | |
2938 | | llvm::Value *EmitCXXTypeidExpr(const CXXTypeidExpr *E); |
2939 | | llvm::Value *EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE); |
2940 | | Address EmitCXXUuidofExpr(const CXXUuidofExpr *E); |
2941 | | |
2942 | | /// Situations in which we might emit a check for the suitability of a |
2943 | | /// pointer or glvalue. Needs to be kept in sync with ubsan_handlers.cpp in |
2944 | | /// compiler-rt. |
2945 | | enum TypeCheckKind { |
2946 | | /// Checking the operand of a load. Must be suitably sized and aligned. |
2947 | | TCK_Load, |
2948 | | /// Checking the destination of a store. Must be suitably sized and aligned. |
2949 | | TCK_Store, |
2950 | | /// Checking the bound value in a reference binding. Must be suitably sized |
2951 | | /// and aligned, but is not required to refer to an object (until the |
2952 | | /// reference is used), per core issue 453. |
2953 | | TCK_ReferenceBinding, |
2954 | | /// Checking the object expression in a non-static data member access. Must |
2955 | | /// be an object within its lifetime. |
2956 | | TCK_MemberAccess, |
2957 | | /// Checking the 'this' pointer for a call to a non-static member function. |
2958 | | /// Must be an object within its lifetime. |
2959 | | TCK_MemberCall, |
2960 | | /// Checking the 'this' pointer for a constructor call. |
2961 | | TCK_ConstructorCall, |
2962 | | /// Checking the operand of a static_cast to a derived pointer type. Must be |
2963 | | /// null or an object within its lifetime. |
2964 | | TCK_DowncastPointer, |
2965 | | /// Checking the operand of a static_cast to a derived reference type. Must |
2966 | | /// be an object within its lifetime. |
2967 | | TCK_DowncastReference, |
2968 | | /// Checking the operand of a cast to a base object. Must be suitably sized |
2969 | | /// and aligned. |
2970 | | TCK_Upcast, |
2971 | | /// Checking the operand of a cast to a virtual base object. Must be an |
2972 | | /// object within its lifetime. |
2973 | | TCK_UpcastToVirtualBase, |
2974 | | /// Checking the value assigned to a _Nonnull pointer. Must not be null. |
2975 | | TCK_NonnullAssign, |
2976 | | /// Checking the operand of a dynamic_cast or a typeid expression. Must be |
2977 | | /// null or an object within its lifetime. |
2978 | | TCK_DynamicOperation |
2979 | | }; |
2980 | | |
2981 | | /// Determine whether the pointer type check \p TCK permits null pointers. |
2982 | | static bool isNullPointerAllowed(TypeCheckKind TCK); |
2983 | | |
2984 | | /// Determine whether the pointer type check \p TCK requires a vptr check. |
2985 | | static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty); |
2986 | | |
2987 | | /// Whether any type-checking sanitizers are enabled. If \c false, |
2988 | | /// calls to EmitTypeCheck can be skipped. |
2989 | | bool sanitizePerformTypeCheck() const; |
2990 | | |
2991 | | /// Emit a check that \p V is the address of storage of the |
2992 | | /// appropriate size and alignment for an object of type \p Type |
2993 | | /// (or if ArraySize is provided, for an array of that bound). |
2994 | | void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, |
2995 | | QualType Type, CharUnits Alignment = CharUnits::Zero(), |
2996 | | SanitizerSet SkippedChecks = SanitizerSet(), |
2997 | | llvm::Value *ArraySize = nullptr); |
2998 | | |
2999 | | /// Emit a check that \p Base points into an array object, which |
3000 | | /// we can access at index \p Index. \p Accessed should be \c false if we |
3001 | | /// this expression is used as an lvalue, for instance in "&Arr[Idx]". |
3002 | | void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index, |
3003 | | QualType IndexType, bool Accessed); |
3004 | | |
3005 | | llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, |
3006 | | bool isInc, bool isPre); |
3007 | | ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, |
3008 | | bool isInc, bool isPre); |
3009 | | |
3010 | | /// Converts Location to a DebugLoc, if debug information is enabled. |
3011 | | llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location); |
3012 | | |
3013 | | /// Get the record field index as represented in debug info. |
3014 | | unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex); |
3015 | | |
3016 | | |
3017 | | //===--------------------------------------------------------------------===// |
3018 | | // Declaration Emission |
3019 | | //===--------------------------------------------------------------------===// |
3020 | | |
3021 | | /// EmitDecl - Emit a declaration. |
3022 | | /// |
3023 | | /// This function can be called with a null (unreachable) insert point. |
3024 | | void EmitDecl(const Decl &D); |
3025 | | |
3026 | | /// EmitVarDecl - Emit a local variable declaration. |
3027 | | /// |
3028 | | /// This function can be called with a null (unreachable) insert point. |
3029 | | void EmitVarDecl(const VarDecl &D); |
3030 | | |
3031 | | void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, |
3032 | | bool capturedByInit); |
3033 | | |
3034 | | typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, |
3035 | | llvm::Value *Address); |
3036 | | |
3037 | | /// Determine whether the given initializer is trivial in the sense |
3038 | | /// that it requires no code to be generated. |
3039 | | bool isTrivialInitializer(const Expr *Init); |
3040 | | |
3041 | | /// EmitAutoVarDecl - Emit an auto variable declaration. |
3042 | | /// |
3043 | | /// This function can be called with a null (unreachable) insert point. |
3044 | | void EmitAutoVarDecl(const VarDecl &D); |
3045 | | |
3046 | | class AutoVarEmission { |
3047 | | friend class CodeGenFunction; |
3048 | | |
3049 | | const VarDecl *Variable; |
3050 | | |
3051 | | /// The address of the alloca for languages with explicit address space |
3052 | | /// (e.g. OpenCL) or alloca casted to generic pointer for address space |
3053 | | /// agnostic languages (e.g. C++). Invalid if the variable was emitted |
3054 | | /// as a global constant. |
3055 | | Address Addr; |
3056 | | |
3057 | | llvm::Value *NRVOFlag; |
3058 | | |
3059 | | /// True if the variable is a __block variable that is captured by an |
3060 | | /// escaping block. |
3061 | | bool IsEscapingByRef; |
3062 | | |
3063 | | /// True if the variable is of aggregate type and has a constant |
3064 | | /// initializer. |
3065 | | bool IsConstantAggregate; |
3066 | | |
3067 | | /// Non-null if we should use lifetime annotations. |
3068 | | llvm::Value *SizeForLifetimeMarkers; |
3069 | | |
3070 | | /// Address with original alloca instruction. Invalid if the variable was |
3071 | | /// emitted as a global constant. |
3072 | | Address AllocaAddr; |
3073 | | |
3074 | | struct Invalid {}; |
3075 | | AutoVarEmission(Invalid) |
3076 | | : Variable(nullptr), Addr(Address::invalid()), |
3077 | 68 | AllocaAddr(Address::invalid()) {} |
3078 | | |
3079 | | AutoVarEmission(const VarDecl &variable) |
3080 | | : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr), |
3081 | | IsEscapingByRef(false), IsConstantAggregate(false), |
3082 | 257k | SizeForLifetimeMarkers(nullptr), AllocaAddr(Address::invalid()) {} |
3083 | | |
3084 | 497k | bool wasEmittedAsGlobal() const { return !Addr.isValid(); } |
3085 | | |
3086 | | public: |
3087 | 68 | static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); } |
3088 | | |
3089 | 261k | bool useLifetimeMarkers() const { |
3090 | 261k | return SizeForLifetimeMarkers != nullptr; |
3091 | 261k | } |
3092 | 3.94k | llvm::Value *getSizeForLifetimeMarkers() const { |
3093 | 3.94k | assert(useLifetimeMarkers()); |
3094 | 0 | return SizeForLifetimeMarkers; |
3095 | 3.94k | } |
3096 | | |
3097 | | /// Returns the raw, allocated address, which is not necessarily |
3098 | | /// the address of the object itself. It is casted to default |
3099 | | /// address space for address space agnostic languages. |
3100 | 36.3k | Address getAllocatedAddress() const { |
3101 | 36.3k | return Addr; |
3102 | 36.3k | } |
3103 | | |
3104 | | /// Returns the address for the original alloca instruction. |
3105 | 3.94k | Address getOriginalAllocatedAddress() const { return AllocaAddr; } |
3106 | | |
3107 | | /// Returns the address of the object within this declaration. |
3108 | | /// Note that this does not chase the forwarding pointer for |
3109 | | /// __block decls. |
3110 | 249k | Address getObjectAddress(CodeGenFunction &CGF) const { |
3111 | 249k | if (!IsEscapingByRef) return Addr249k ; |
3112 | | |
3113 | 257 | return CGF.emitBlockByrefAddress(Addr, Variable, /*forward*/ false); |
3114 | 249k | } |
3115 | | }; |
3116 | | AutoVarEmission EmitAutoVarAlloca(const VarDecl &var); |
3117 | | void EmitAutoVarInit(const AutoVarEmission &emission); |
3118 | | void EmitAutoVarCleanups(const AutoVarEmission &emission); |
3119 | | void emitAutoVarTypeCleanup(const AutoVarEmission &emission, |
3120 | | QualType::DestructionKind dtorKind); |
3121 | | |
3122 | | /// Emits the alloca and debug information for the size expressions for each |
3123 | | /// dimension of an array. It registers the association of its (1-dimensional) |
3124 | | /// QualTypes and size expression's debug node, so that CGDebugInfo can |
3125 | | /// reference this node when creating the DISubrange object to describe the |
3126 | | /// array types. |
3127 | | void EmitAndRegisterVariableArrayDimensions(CGDebugInfo *DI, |
3128 | | const VarDecl &D, |
3129 | | bool EmitDebugInfo); |
3130 | | |
3131 | | void EmitStaticVarDecl(const VarDecl &D, |
3132 | | llvm::GlobalValue::LinkageTypes Linkage); |
3133 | | |
3134 | | class ParamValue { |
3135 | | llvm::Value *Value; |
3136 | | llvm::Type *ElementType; |
3137 | | unsigned Alignment; |
3138 | | ParamValue(llvm::Value *V, llvm::Type *T, unsigned A) |
3139 | 529k | : Value(V), ElementType(T), Alignment(A) {} |
3140 | | public: |
3141 | 514k | static ParamValue forDirect(llvm::Value *value) { |
3142 | 514k | return ParamValue(value, nullptr, 0); |
3143 | 514k | } |
3144 | 14.7k | static ParamValue forIndirect(Address addr) { |
3145 | 14.7k | assert(!addr.getAlignment().isZero()); |
3146 | 0 | return ParamValue(addr.getPointer(), addr.getElementType(), |
3147 | 14.7k | addr.getAlignment().getQuantity()); |
3148 | 14.7k | } |
3149 | | |
3150 | 1.06M | bool isIndirect() const { return Alignment != 0; } |
3151 | 529k | llvm::Value *getAnyValue() const { return Value; } |
3152 | | |
3153 | 514k | llvm::Value *getDirectValue() const { |
3154 | 514k | assert(!isIndirect()); |
3155 | 0 | return Value; |
3156 | 514k | } |
3157 | | |
3158 | 14.7k | Address getIndirectAddress() const { |
3159 | 14.7k | assert(isIndirect()); |
3160 | 0 | return Address(Value, ElementType, CharUnits::fromQuantity(Alignment)); |
3161 | 14.7k | } |
3162 | | }; |
3163 | | |
3164 | | /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. |
3165 | | void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo); |
3166 | | |
3167 | | /// protectFromPeepholes - Protect a value that we're intending to |
3168 | | /// store to the side, but which will probably be used later, from |
3169 | | /// aggressive peepholing optimizations that might delete it. |
3170 | | /// |
3171 | | /// Pass the result to unprotectFromPeepholes to declare that |
3172 | | /// protection is no longer required. |
3173 | | /// |
3174 | | /// There's no particular reason why this shouldn't apply to |
3175 | | /// l-values, it's just that no existing peepholes work on pointers. |
3176 | | PeepholeProtection protectFromPeepholes(RValue rvalue); |
3177 | | void unprotectFromPeepholes(PeepholeProtection protection); |
3178 | | |
3179 | | void emitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty, |
3180 | | SourceLocation Loc, |
3181 | | SourceLocation AssumptionLoc, |
3182 | | llvm::Value *Alignment, |
3183 | | llvm::Value *OffsetValue, |
3184 | | llvm::Value *TheCheck, |
3185 | | llvm::Instruction *Assumption); |
3186 | | |
3187 | | void emitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, |
3188 | | SourceLocation Loc, SourceLocation AssumptionLoc, |
3189 | | llvm::Value *Alignment, |
3190 | | llvm::Value *OffsetValue = nullptr); |
3191 | | |
3192 | | void emitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E, |
3193 | | SourceLocation AssumptionLoc, |
3194 | | llvm::Value *Alignment, |
3195 | | llvm::Value *OffsetValue = nullptr); |
3196 | | |
3197 | | //===--------------------------------------------------------------------===// |
3198 | | // Statement Emission |
3199 | | //===--------------------------------------------------------------------===// |
3200 | | |
3201 | | /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. |
3202 | | void EmitStopPoint(const Stmt *S); |
3203 | | |
3204 | | /// EmitStmt - Emit the code for the statement \arg S. It is legal to call |
3205 | | /// this function even if there is no current insertion point. |
3206 | | /// |
3207 | | /// This function may clear the current insertion point; callers should use |
3208 | | /// EnsureInsertPoint if they wish to subsequently generate code without first |
3209 | | /// calling EmitBlock, EmitBranch, or EmitStmt. |
3210 | | void EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs = None); |
3211 | | |
3212 | | /// EmitSimpleStmt - Try to emit a "simple" statement which does not |
3213 | | /// necessarily require an insertion point or debug information; typically |
3214 | | /// because the statement amounts to a jump or a container of other |
3215 | | /// statements. |
3216 | | /// |
3217 | | /// \return True if the statement was handled. |
3218 | | bool EmitSimpleStmt(const Stmt *S, ArrayRef<const Attr *> Attrs); |
3219 | | |
3220 | | Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, |
3221 | | AggValueSlot AVS = AggValueSlot::ignored()); |
3222 | | Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, |
3223 | | bool GetLast = false, |
3224 | | AggValueSlot AVS = |
3225 | | AggValueSlot::ignored()); |
3226 | | |
3227 | | /// EmitLabel - Emit the block for the given label. It is legal to call this |
3228 | | /// function even if there is no current insertion point. |
3229 | | void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt. |
3230 | | |
3231 | | void EmitLabelStmt(const LabelStmt &S); |
3232 | | void EmitAttributedStmt(const AttributedStmt &S); |
3233 | | void EmitGotoStmt(const GotoStmt &S); |
3234 | | void EmitIndirectGotoStmt(const IndirectGotoStmt &S); |
3235 | | void EmitIfStmt(const IfStmt &S); |
3236 | | |
3237 | | void EmitWhileStmt(const WhileStmt &S, |
3238 | | ArrayRef<const Attr *> Attrs = None); |
3239 | | void EmitDoStmt(const DoStmt &S, ArrayRef<const Attr *> Attrs = None); |
3240 | | void EmitForStmt(const ForStmt &S, |
3241 | | ArrayRef<const Attr *> Attrs = None); |
3242 | | void EmitReturnStmt(const ReturnStmt &S); |
3243 | | void EmitDeclStmt(const DeclStmt &S); |
3244 | | void EmitBreakStmt(const BreakStmt &S); |
3245 | | void EmitContinueStmt(const ContinueStmt &S); |
3246 | | void EmitSwitchStmt(const SwitchStmt &S); |
3247 | | void EmitDefaultStmt(const DefaultStmt &S, ArrayRef<const Attr *> Attrs); |
3248 | | void EmitCaseStmt(const CaseStmt &S, ArrayRef<const Attr *> Attrs); |
3249 | | void EmitCaseStmtRange(const CaseStmt &S, ArrayRef<const Attr *> Attrs); |
3250 | | void EmitAsmStmt(const AsmStmt &S); |
3251 | | |
3252 | | void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); |
3253 | | void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); |
3254 | | void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); |
3255 | | void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); |
3256 | | void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S); |
3257 | | |
3258 | | void EmitCoroutineBody(const CoroutineBodyStmt &S); |
3259 | | void EmitCoreturnStmt(const CoreturnStmt &S); |
3260 | | RValue EmitCoawaitExpr(const CoawaitExpr &E, |
3261 | | AggValueSlot aggSlot = AggValueSlot::ignored(), |
3262 | | bool ignoreResult = false); |
3263 | | LValue EmitCoawaitLValue(const CoawaitExpr *E); |
3264 | | RValue EmitCoyieldExpr(const CoyieldExpr &E, |
3265 | | AggValueSlot aggSlot = AggValueSlot::ignored(), |
3266 | | bool ignoreResult = false); |
3267 | | LValue EmitCoyieldLValue(const CoyieldExpr *E); |
3268 | | RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID); |
3269 | | |
3270 | | void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
3271 | | void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
3272 | | |
3273 | | void EmitCXXTryStmt(const CXXTryStmt &S); |
3274 | | void EmitSEHTryStmt(const SEHTryStmt &S); |
3275 | | void EmitSEHLeaveStmt(const SEHLeaveStmt &S); |
3276 | | void EnterSEHTryStmt(const SEHTryStmt &S); |
3277 | | void ExitSEHTryStmt(const SEHTryStmt &S); |
3278 | | void VolatilizeTryBlocks(llvm::BasicBlock *BB, |
3279 | | llvm::SmallPtrSet<llvm::BasicBlock *, 10> &V); |
3280 | | |
3281 | | void pushSEHCleanup(CleanupKind kind, |
3282 | | llvm::Function *FinallyFunc); |
3283 | | void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, |
3284 | | const Stmt *OutlinedStmt); |
3285 | | |
3286 | | llvm::Function *GenerateSEHFilterFunction(CodeGenFunction &ParentCGF, |
3287 | | const SEHExceptStmt &Except); |
3288 | | |
3289 | | llvm::Function *GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF, |
3290 | | const SEHFinallyStmt &Finally); |
3291 | | |
3292 | | void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, |
3293 | | llvm::Value *ParentFP, |
3294 | | llvm::Value *EntryEBP); |
3295 | | llvm::Value *EmitSEHExceptionCode(); |
3296 | | llvm::Value *EmitSEHExceptionInfo(); |
3297 | | llvm::Value *EmitSEHAbnormalTermination(); |
3298 | | |
3299 | | /// Emit simple code for OpenMP directives in Simd-only mode. |
3300 | | void EmitSimpleOMPExecutableDirective(const OMPExecutableDirective &D); |
3301 | | |
3302 | | /// Scan the outlined statement for captures from the parent function. For |
3303 | | /// each capture, mark the capture as escaped and emit a call to |
3304 | | /// llvm.localrecover. Insert the localrecover result into the LocalDeclMap. |
3305 | | void EmitCapturedLocals(CodeGenFunction &ParentCGF, const Stmt *OutlinedStmt, |
3306 | | bool IsFilter); |
3307 | | |
3308 | | /// Recovers the address of a local in a parent function. ParentVar is the |
3309 | | /// address of the variable used in the immediate parent function. It can |
3310 | | /// either be an alloca or a call to llvm.localrecover if there are nested |
3311 | | /// outlined functions. ParentFP is the frame pointer of the outermost parent |
3312 | | /// frame. |
3313 | | Address recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, |
3314 | | Address ParentVar, |
3315 | | llvm::Value *ParentFP); |
3316 | | |
3317 | | void EmitCXXForRangeStmt(const CXXForRangeStmt &S, |
3318 | | ArrayRef<const Attr *> Attrs = None); |
3319 | | |
3320 | | /// Controls insertion of cancellation exit blocks in worksharing constructs. |
3321 | | class OMPCancelStackRAII { |
3322 | | CodeGenFunction &CGF; |
3323 | | |
3324 | | public: |
3325 | | OMPCancelStackRAII(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, |
3326 | | bool HasCancel) |
3327 | 4.42k | : CGF(CGF) { |
3328 | 4.42k | CGF.OMPCancelStack.enter(CGF, Kind, HasCancel); |
3329 | 4.42k | } |
3330 | 4.42k | ~OMPCancelStackRAII() { CGF.OMPCancelStack.exit(CGF); } |
3331 | | }; |
3332 | | |
3333 | | /// Returns calculated size of the specified type. |
3334 | | llvm::Value *getTypeSize(QualType Ty); |
3335 | | LValue InitCapturedStruct(const CapturedStmt &S); |
3336 | | llvm::Function *EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K); |
3337 | | llvm::Function *GenerateCapturedStmtFunction(const CapturedStmt &S); |
3338 | | Address GenerateCapturedStmtArgument(const CapturedStmt &S); |
3339 | | llvm::Function *GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S, |
3340 | | SourceLocation Loc); |
3341 | | void GenerateOpenMPCapturedVars(const CapturedStmt &S, |
3342 | | SmallVectorImpl<llvm::Value *> &CapturedVars); |
3343 | | void emitOMPSimpleStore(LValue LVal, RValue RVal, QualType RValTy, |
3344 | | SourceLocation Loc); |
3345 | | /// Perform element by element copying of arrays with type \a |
3346 | | /// OriginalType from \a SrcAddr to \a DestAddr using copying procedure |
3347 | | /// generated by \a CopyGen. |
3348 | | /// |
3349 | | /// \param DestAddr Address of the destination array. |
3350 | | /// \param SrcAddr Address of the source array. |
3351 | | /// \param OriginalType Type of destination and source arrays. |
3352 | | /// \param CopyGen Copying procedure that copies value of single array element |
3353 | | /// to another single array element. |
3354 | | void EmitOMPAggregateAssign( |
3355 | | Address DestAddr, Address SrcAddr, QualType OriginalType, |
3356 | | const llvm::function_ref<void(Address, Address)> CopyGen); |
3357 | | /// Emit proper copying of data from one variable to another. |
3358 | | /// |
3359 | | /// \param OriginalType Original type of the copied variables. |
3360 | | /// \param DestAddr Destination address. |
3361 | | /// \param SrcAddr Source address. |
3362 | | /// \param DestVD Destination variable used in \a CopyExpr (for arrays, has |
3363 | | /// type of the base array element). |
3364 | | /// \param SrcVD Source variable used in \a CopyExpr (for arrays, has type of |
3365 | | /// the base array element). |
3366 | | /// \param Copy Actual copygin expression for copying data from \a SrcVD to \a |
3367 | | /// DestVD. |
3368 | | void EmitOMPCopy(QualType OriginalType, |
3369 | | Address DestAddr, Address SrcAddr, |
3370 | | const VarDecl *DestVD, const VarDecl *SrcVD, |
3371 | | const Expr *Copy); |
3372 | | /// Emit atomic update code for constructs: \a X = \a X \a BO \a E or |
3373 | | /// \a X = \a E \a BO \a E. |
3374 | | /// |
3375 | | /// \param X Value to be updated. |
3376 | | /// \param E Update value. |
3377 | | /// \param BO Binary operation for update operation. |
3378 | | /// \param IsXLHSInRHSPart true if \a X is LHS in RHS part of the update |
3379 | | /// expression, false otherwise. |
3380 | | /// \param AO Atomic ordering of the generated atomic instructions. |
3381 | | /// \param CommonGen Code generator for complex expressions that cannot be |
3382 | | /// expressed through atomicrmw instruction. |
3383 | | /// \returns <true, OldAtomicValue> if simple 'atomicrmw' instruction was |
3384 | | /// generated, <false, RValue::get(nullptr)> otherwise. |
3385 | | std::pair<bool, RValue> EmitOMPAtomicSimpleUpdateExpr( |
3386 | | LValue X, RValue E, BinaryOperatorKind BO, bool IsXLHSInRHSPart, |
3387 | | llvm::AtomicOrdering AO, SourceLocation Loc, |
3388 | | const llvm::function_ref<RValue(RValue)> CommonGen); |
3389 | | bool EmitOMPFirstprivateClause(const OMPExecutableDirective &D, |
3390 | | OMPPrivateScope &PrivateScope); |
3391 | | void EmitOMPPrivateClause(const OMPExecutableDirective &D, |
3392 | | OMPPrivateScope &PrivateScope); |
3393 | | void EmitOMPUseDevicePtrClause( |
3394 | | const OMPUseDevicePtrClause &C, OMPPrivateScope &PrivateScope, |
3395 | | const llvm::DenseMap<const ValueDecl *, Address> &CaptureDeviceAddrMap); |
3396 | | void EmitOMPUseDeviceAddrClause( |
3397 | | const OMPUseDeviceAddrClause &C, OMPPrivateScope &PrivateScope, |
3398 | | const llvm::DenseMap<const ValueDecl *, Address> &CaptureDeviceAddrMap); |
3399 | | /// Emit code for copyin clause in \a D directive. The next code is |
3400 | | /// generated at the start of outlined functions for directives: |
3401 | | /// \code |
3402 | | /// threadprivate_var1 = master_threadprivate_var1; |
3403 | | /// operator=(threadprivate_var2, master_threadprivate_var2); |
3404 | | /// ... |
3405 | | /// __kmpc_barrier(&loc, global_tid); |
3406 | | /// \endcode |
3407 | | /// |
3408 | | /// \param D OpenMP directive possibly with 'copyin' clause(s). |
3409 | | /// \returns true if at least one copyin variable is found, false otherwise. |
3410 | | bool EmitOMPCopyinClause(const OMPExecutableDirective &D); |
3411 | | /// Emit initial code for lastprivate variables. If some variable is |
3412 | | /// not also firstprivate, then the default initialization is used. Otherwise |
3413 | | /// initialization of this variable is performed by EmitOMPFirstprivateClause |
3414 | | /// method. |
3415 | | /// |
3416 | | /// \param D Directive that may have 'lastprivate' directives. |
3417 | | /// \param PrivateScope Private scope for capturing lastprivate variables for |
3418 | | /// proper codegen in internal captured statement. |
3419 | | /// |
3420 | | /// \returns true if there is at least one lastprivate variable, false |
3421 | | /// otherwise. |
3422 | | bool EmitOMPLastprivateClauseInit(const OMPExecutableDirective &D, |
3423 | | OMPPrivateScope &PrivateScope); |
3424 | | /// Emit final copying of lastprivate values to original variables at |
3425 | | /// the end of the worksharing or simd directive. |
3426 | | /// |
3427 | | /// \param D Directive that has at least one 'lastprivate' directives. |
3428 | | /// \param IsLastIterCond Boolean condition that must be set to 'i1 true' if |
3429 | | /// it is the last iteration of the loop code in associated directive, or to |
3430 | | /// 'i1 false' otherwise. If this item is nullptr, no final check is required. |
3431 | | void EmitOMPLastprivateClauseFinal(const OMPExecutableDirective &D, |
3432 | | bool NoFinals, |
3433 | | llvm::Value *IsLastIterCond = nullptr); |
3434 | | /// Emit initial code for linear clauses. |
3435 | | void EmitOMPLinearClause(const OMPLoopDirective &D, |
3436 | | CodeGenFunction::OMPPrivateScope &PrivateScope); |
3437 | | /// Emit final code for linear clauses. |
3438 | | /// \param CondGen Optional conditional code for final part of codegen for |
3439 | | /// linear clause. |
3440 | | void EmitOMPLinearClauseFinal( |
3441 | | const OMPLoopDirective &D, |
3442 | | const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen); |
3443 | | /// Emit initial code for reduction variables. Creates reduction copies |
3444 | | /// and initializes them with the values according to OpenMP standard. |
3445 | | /// |
3446 | | /// \param D Directive (possibly) with the 'reduction' clause. |
3447 | | /// \param PrivateScope Private scope for capturing reduction variables for |
3448 | | /// proper codegen in internal captured statement. |
3449 | | /// |
3450 | | void EmitOMPReductionClauseInit(const OMPExecutableDirective &D, |
3451 | | OMPPrivateScope &PrivateScope, |
3452 | | bool ForInscan = false); |
3453 | | /// Emit final update of reduction values to original variables at |
3454 | | /// the end of the directive. |
3455 | | /// |
3456 | | /// \param D Directive that has at least one 'reduction' directives. |
3457 | | /// \param ReductionKind The kind of reduction to perform. |
3458 | | void EmitOMPReductionClauseFinal(const OMPExecutableDirective &D, |
3459 | | const OpenMPDirectiveKind ReductionKind); |
3460 | | /// Emit initial code for linear variables. Creates private copies |
3461 | | /// and initializes them with the values according to OpenMP standard. |
3462 | | /// |
3463 | | /// \param D Directive (possibly) with the 'linear' clause. |
3464 | | /// \return true if at least one linear variable is found that should be |
3465 | | /// initialized with the value of the original variable, false otherwise. |
3466 | | bool EmitOMPLinearClauseInit(const OMPLoopDirective &D); |
3467 | | |
3468 | | typedef const llvm::function_ref<void(CodeGenFunction & /*CGF*/, |
3469 | | llvm::Function * /*OutlinedFn*/, |
3470 | | const OMPTaskDataTy & /*Data*/)> |
3471 | | TaskGenTy; |
3472 | | void EmitOMPTaskBasedDirective(const OMPExecutableDirective &S, |
3473 | | const OpenMPDirectiveKind CapturedRegion, |
3474 | | const RegionCodeGenTy &BodyGen, |
3475 | | const TaskGenTy &TaskGen, OMPTaskDataTy &Data); |
3476 | | struct OMPTargetDataInfo { |
3477 | | Address BasePointersArray = Address::invalid(); |
3478 | | Address PointersArray = Address::invalid(); |
3479 | | Address SizesArray = Address::invalid(); |
3480 | | Address MappersArray = Address::invalid(); |
3481 | | unsigned NumberOfTargetItems = 0; |
3482 | 9.83k | explicit OMPTargetDataInfo() = default; |
3483 | | OMPTargetDataInfo(Address BasePointersArray, Address PointersArray, |
3484 | | Address SizesArray, Address MappersArray, |
3485 | | unsigned NumberOfTargetItems) |
3486 | | : BasePointersArray(BasePointersArray), PointersArray(PointersArray), |
3487 | | SizesArray(SizesArray), MappersArray(MappersArray), |
3488 | 0 | NumberOfTargetItems(NumberOfTargetItems) {} |
3489 | | }; |
3490 | | void EmitOMPTargetTaskBasedDirective(const OMPExecutableDirective &S, |
3491 | | const RegionCodeGenTy &BodyGen, |
3492 | | OMPTargetDataInfo &InputInfo); |
3493 | | void processInReduction(const OMPExecutableDirective &S, |
3494 | | OMPTaskDataTy &Data, |
3495 | | CodeGenFunction &CGF, |
3496 | | const CapturedStmt *CS, |
3497 | | OMPPrivateScope &Scope); |
3498 | | void EmitOMPMetaDirective(const OMPMetaDirective &S); |
3499 | | void EmitOMPParallelDirective(const OMPParallelDirective &S); |
3500 | | void EmitOMPSimdDirective(const OMPSimdDirective &S); |
3501 | | void EmitOMPTileDirective(const OMPTileDirective &S); |
3502 | | void EmitOMPUnrollDirective(const OMPUnrollDirective &S); |
3503 | | void EmitOMPForDirective(const OMPForDirective &S); |
3504 | | void EmitOMPForSimdDirective(const OMPForSimdDirective &S); |
3505 | | void EmitOMPSectionsDirective(const OMPSectionsDirective &S); |
3506 | | void EmitOMPSectionDirective(const OMPSectionDirective &S); |
3507 | | void EmitOMPSingleDirective(const OMPSingleDirective &S); |
3508 | | void EmitOMPMasterDirective(const OMPMasterDirective &S); |
3509 | | void EmitOMPMaskedDirective(const OMPMaskedDirective &S); |
3510 | | void EmitOMPCriticalDirective(const OMPCriticalDirective &S); |
3511 | | void EmitOMPParallelForDirective(const OMPParallelForDirective &S); |
3512 | | void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S); |
3513 | | void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S); |
3514 | | void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S); |
3515 | | void EmitOMPTaskDirective(const OMPTaskDirective &S); |
3516 | | void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S); |
3517 | | void EmitOMPBarrierDirective(const OMPBarrierDirective &S); |
3518 | | void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S); |
3519 | | void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S); |
3520 | | void EmitOMPFlushDirective(const OMPFlushDirective &S); |
3521 | | void EmitOMPDepobjDirective(const OMPDepobjDirective &S); |
3522 | | void EmitOMPScanDirective(const OMPScanDirective &S); |
3523 | | void EmitOMPOrderedDirective(const OMPOrderedDirective &S); |
3524 | | void EmitOMPAtomicDirective(const OMPAtomicDirective &S); |
3525 | | void EmitOMPTargetDirective(const OMPTargetDirective &S); |
3526 | | void EmitOMPTargetDataDirective(const OMPTargetDataDirective &S); |
3527 | | void EmitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &S); |
3528 | | void EmitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &S); |
3529 | | void EmitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &S); |
3530 | | void EmitOMPTargetParallelDirective(const OMPTargetParallelDirective &S); |
3531 | | void |
3532 | | EmitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &S); |
3533 | | void EmitOMPTeamsDirective(const OMPTeamsDirective &S); |
3534 | | void |
3535 | | EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S); |
3536 | | void EmitOMPCancelDirective(const OMPCancelDirective &S); |
3537 | | void EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S); |
3538 | | void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S); |
3539 | | void EmitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &S); |
3540 | | void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S); |
3541 | | void |
3542 | | EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S); |
3543 | | void EmitOMPParallelMasterTaskLoopDirective( |
3544 | | const OMPParallelMasterTaskLoopDirective &S); |
3545 | | void EmitOMPParallelMasterTaskLoopSimdDirective( |
3546 | | const OMPParallelMasterTaskLoopSimdDirective &S); |
3547 | | void EmitOMPDistributeDirective(const OMPDistributeDirective &S); |
3548 | | void EmitOMPDistributeParallelForDirective( |
3549 | | const OMPDistributeParallelForDirective &S); |
3550 | | void EmitOMPDistributeParallelForSimdDirective( |
3551 | | const OMPDistributeParallelForSimdDirective &S); |
3552 | | void EmitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &S); |
3553 | | void EmitOMPTargetParallelForSimdDirective( |
3554 | | const OMPTargetParallelForSimdDirective &S); |
3555 | | void EmitOMPTargetSimdDirective(const OMPTargetSimdDirective &S); |
3556 | | void EmitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &S); |
3557 | | void |
3558 | | EmitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &S); |
3559 | | void EmitOMPTeamsDistributeParallelForSimdDirective( |
3560 | | const OMPTeamsDistributeParallelForSimdDirective &S); |
3561 | | void EmitOMPTeamsDistributeParallelForDirective( |
3562 | | const OMPTeamsDistributeParallelForDirective &S); |
3563 | | void EmitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &S); |
3564 | | void EmitOMPTargetTeamsDistributeDirective( |
3565 | | const OMPTargetTeamsDistributeDirective &S); |
3566 | | void EmitOMPTargetTeamsDistributeParallelForDirective( |
3567 | | const OMPTargetTeamsDistributeParallelForDirective &S); |
3568 | | void EmitOMPTargetTeamsDistributeParallelForSimdDirective( |
3569 | | const OMPTargetTeamsDistributeParallelForSimdDirective &S); |
3570 | | void EmitOMPTargetTeamsDistributeSimdDirective( |
3571 | | const OMPTargetTeamsDistributeSimdDirective &S); |
3572 | | void EmitOMPGenericLoopDirective(const OMPGenericLoopDirective &S); |
3573 | | void EmitOMPInteropDirective(const OMPInteropDirective &S); |
3574 | | |
3575 | | /// Emit device code for the target directive. |
3576 | | static void EmitOMPTargetDeviceFunction(CodeGenModule &CGM, |
3577 | | StringRef ParentName, |
3578 | | const OMPTargetDirective &S); |
3579 | | static void |
3580 | | EmitOMPTargetParallelDeviceFunction(CodeGenModule &CGM, StringRef ParentName, |
3581 | | const OMPTargetParallelDirective &S); |
3582 | | /// Emit device code for the target parallel for directive. |
3583 | | static void EmitOMPTargetParallelForDeviceFunction( |
3584 | | CodeGenModule &CGM, StringRef ParentName, |
3585 | | const OMPTargetParallelForDirective &S); |
3586 | | /// Emit device code for the target parallel for simd directive. |
3587 | | static void EmitOMPTargetParallelForSimdDeviceFunction( |
3588 | | CodeGenModule &CGM, StringRef ParentName, |
3589 | | const OMPTargetParallelForSimdDirective &S); |
3590 | | /// Emit device code for the target teams directive. |
3591 | | static void |
3592 | | EmitOMPTargetTeamsDeviceFunction(CodeGenModule &CGM, StringRef ParentName, |
3593 | | const OMPTargetTeamsDirective &S); |
3594 | | /// Emit device code for the target teams distribute directive. |
3595 | | static void EmitOMPTargetTeamsDistributeDeviceFunction( |
3596 | | CodeGenModule &CGM, StringRef ParentName, |
3597 | | const OMPTargetTeamsDistributeDirective &S); |
3598 | | /// Emit device code for the target teams distribute simd directive. |
3599 | | static void EmitOMPTargetTeamsDistributeSimdDeviceFunction( |
3600 | | CodeGenModule &CGM, StringRef ParentName, |
3601 | | const OMPTargetTeamsDistributeSimdDirective &S); |
3602 | | /// Emit device code for the target simd directive. |
3603 | | static void EmitOMPTargetSimdDeviceFunction(CodeGenModule &CGM, |
3604 | | StringRef ParentName, |
3605 | | const OMPTargetSimdDirective &S); |
3606 | | /// Emit device code for the target teams distribute parallel for simd |
3607 | | /// directive. |
3608 | | static void EmitOMPTargetTeamsDistributeParallelForSimdDeviceFunction( |
3609 | | CodeGenModule &CGM, StringRef ParentName, |
3610 | | const OMPTargetTeamsDistributeParallelForSimdDirective &S); |
3611 | | |
3612 | | static void EmitOMPTargetTeamsDistributeParallelForDeviceFunction( |
3613 | | CodeGenModule &CGM, StringRef ParentName, |
3614 | | const OMPTargetTeamsDistributeParallelForDirective &S); |
3615 | | |
3616 | | /// Emit the Stmt \p S and return its topmost canonical loop, if any. |
3617 | | /// TODO: The \p Depth paramter is not yet implemented and must be 1. In the |
3618 | | /// future it is meant to be the number of loops expected in the loop nests |
3619 | | /// (usually specified by the "collapse" clause) that are collapsed to a |
3620 | | /// single loop by this function. |
3621 | | llvm::CanonicalLoopInfo *EmitOMPCollapsedCanonicalLoopNest(const Stmt *S, |
3622 | | int Depth); |
3623 | | |
3624 | | /// Emit an OMPCanonicalLoop using the OpenMPIRBuilder. |
3625 | | void EmitOMPCanonicalLoop(const OMPCanonicalLoop *S); |
3626 | | |
3627 | | /// Emit inner loop of the worksharing/simd construct. |
3628 | | /// |
3629 | | /// \param S Directive, for which the inner loop must be emitted. |
3630 | | /// \param RequiresCleanup true, if directive has some associated private |
3631 | | /// variables. |
3632 | | /// \param LoopCond Bollean condition for loop continuation. |
3633 | | /// \param IncExpr Increment expression for loop control variable. |
3634 | | /// \param BodyGen Generator for the inner body of the inner loop. |
3635 | | /// \param PostIncGen Genrator for post-increment code (required for ordered |
3636 | | /// loop directvies). |
3637 | | void EmitOMPInnerLoop( |
3638 | | const OMPExecutableDirective &S, bool RequiresCleanup, |
3639 | | const Expr *LoopCond, const Expr *IncExpr, |
3640 | | const llvm::function_ref<void(CodeGenFunction &)> BodyGen, |
3641 | | const llvm::function_ref<void(CodeGenFunction &)> PostIncGen); |
3642 | | |
3643 | | JumpDest getOMPCancelDestination(OpenMPDirectiveKind Kind); |
3644 | | /// Emit initial code for loop counters of loop-based directives. |
3645 | | void EmitOMPPrivateLoopCounters(const OMPLoopDirective &S, |
3646 | | OMPPrivateScope &LoopScope); |
3647 | | |
3648 | | /// Helper for the OpenMP loop directives. |
3649 | | void EmitOMPLoopBody(const OMPLoopDirective &D, JumpDest LoopExit); |
3650 | | |
3651 | | /// Emit code for the worksharing loop-based directive. |
3652 | | /// \return true, if this construct has any lastprivate clause, false - |
3653 | | /// otherwise. |
3654 | | bool EmitOMPWorksharingLoop(const OMPLoopDirective &S, Expr *EUB, |
3655 | | const CodeGenLoopBoundsTy &CodeGenLoopBounds, |
3656 | | const CodeGenDispatchBoundsTy &CGDispatchBounds); |
3657 | | |
3658 | | /// Emit code for the distribute loop-based directive. |
3659 | | void EmitOMPDistributeLoop(const OMPLoopDirective &S, |
3660 | | const CodeGenLoopTy &CodeGenLoop, Expr *IncExpr); |
3661 | | |
3662 | | /// Helpers for the OpenMP loop directives. |
3663 | | void EmitOMPSimdInit(const OMPLoopDirective &D); |
3664 | | void EmitOMPSimdFinal( |
3665 | | const OMPLoopDirective &D, |
3666 | | const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen); |
3667 | | |
3668 | | /// Emits the lvalue for the expression with possibly captured variable. |
3669 | | LValue EmitOMPSharedLValue(const Expr *E); |
3670 | | |
3671 | | private: |
3672 | | /// Helpers for blocks. |
3673 | | llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info); |
3674 | | |
3675 | | /// struct with the values to be passed to the OpenMP loop-related functions |
3676 | | struct OMPLoopArguments { |
3677 | | /// loop lower bound |
3678 | | Address LB = Address::invalid(); |
3679 | | /// loop upper bound |
3680 | | Address UB = Address::invalid(); |
3681 | | /// loop stride |
3682 | | Address ST = Address::invalid(); |
3683 | | /// isLastIteration argument for runtime functions |
3684 | | Address IL = Address::invalid(); |
3685 | | /// Chunk value generated by sema |
3686 | | llvm::Value *Chunk = nullptr; |
3687 | | /// EnsureUpperBound |
3688 | | Expr *EUB = nullptr; |
3689 | | /// IncrementExpression |
3690 | | Expr *IncExpr = nullptr; |
3691 | | /// Loop initialization |
3692 | | Expr *Init = nullptr; |
3693 | | /// Loop exit condition |
3694 | | Expr *Cond = nullptr; |
3695 | | /// Update of LB after a whole chunk has been executed |
3696 | | Expr *NextLB = nullptr; |
3697 | | /// Update of UB after a whole chunk has been executed |
3698 | | Expr *NextUB = nullptr; |
3699 | 164 | OMPLoopArguments() = default; |
3700 | | OMPLoopArguments(Address LB, Address UB, Address ST, Address IL, |
3701 | | llvm::Value *Chunk = nullptr, Expr *EUB = nullptr, |
3702 | | Expr *IncExpr = nullptr, Expr *Init = nullptr, |
3703 | | Expr *Cond = nullptr, Expr *NextLB = nullptr, |
3704 | | Expr *NextUB = nullptr) |
3705 | | : LB(LB), UB(UB), ST(ST), IL(IL), Chunk(Chunk), EUB(EUB), |
3706 | | IncExpr(IncExpr), Init(Init), Cond(Cond), NextLB(NextLB), |
3707 | 2.27k | NextUB(NextUB) {} |
3708 | | }; |
3709 | | void EmitOMPOuterLoop(bool DynamicOrOrdered, bool IsMonotonic, |
3710 | | const OMPLoopDirective &S, OMPPrivateScope &LoopScope, |
3711 | | const OMPLoopArguments &LoopArgs, |
3712 | | const CodeGenLoopTy &CodeGenLoop, |
3713 | | const CodeGenOrderedTy &CodeGenOrdered); |
3714 | | void EmitOMPForOuterLoop(const OpenMPScheduleTy &ScheduleKind, |
3715 | | bool IsMonotonic, const OMPLoopDirective &S, |
3716 | | OMPPrivateScope &LoopScope, bool Ordered, |
3717 | | const OMPLoopArguments &LoopArgs, |
3718 | | const CodeGenDispatchBoundsTy &CGDispatchBounds); |
3719 | | void EmitOMPDistributeOuterLoop(OpenMPDistScheduleClauseKind ScheduleKind, |
3720 | | const OMPLoopDirective &S, |
3721 | | OMPPrivateScope &LoopScope, |
3722 | | const OMPLoopArguments &LoopArgs, |
3723 | | const CodeGenLoopTy &CodeGenLoopContent); |
3724 | | /// Emit code for sections directive. |
3725 | | void EmitSections(const OMPExecutableDirective &S); |
3726 | | |
3727 | | public: |
3728 | | |
3729 | | //===--------------------------------------------------------------------===// |
3730 | | // LValue Expression Emission |
3731 | | //===--------------------------------------------------------------------===// |
3732 | | |
3733 | | /// Create a check that a scalar RValue is non-null. |
3734 | | llvm::Value *EmitNonNullRValueCheck(RValue RV, QualType T); |
3735 | | |
3736 | | /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. |
3737 | | RValue GetUndefRValue(QualType Ty); |
3738 | | |
3739 | | /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E |
3740 | | /// and issue an ErrorUnsupported style diagnostic (using the |
3741 | | /// provided Name). |
3742 | | RValue EmitUnsupportedRValue(const Expr *E, |
3743 | | const char *Name); |
3744 | | |
3745 | | /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue |
3746 | | /// an ErrorUnsupported style diagnostic (using the provided Name). |
3747 | | LValue EmitUnsupportedLValue(const Expr *E, |
3748 | | const char *Name); |
3749 | | |
3750 | | /// EmitLValue - Emit code to compute a designator that specifies the location |
3751 | | /// of the expression. |
3752 | | /// |
3753 | | /// This can return one of two things: a simple address or a bitfield |
3754 | | /// reference. In either case, the LLVM Value* in the LValue structure is |
3755 | | /// guaranteed to be an LLVM pointer type. |
3756 | | /// |
3757 | | /// If this returns a bitfield reference, nothing about the pointee type of |
3758 | | /// the LLVM value is known: For example, it may not be a pointer to an |
3759 | | /// integer. |
3760 | | /// |
3761 | | /// If this returns a normal address, and if the lvalue's C type is fixed |
3762 | | /// size, this method guarantees that the returned pointer type will point to |
3763 | | /// an LLVM type of the same size of the lvalue's type. If the lvalue has a |
3764 | | /// variable length type, this is not possible. |
3765 | | /// |
3766 | | LValue EmitLValue(const Expr *E); |
3767 | | |
3768 | | /// Same as EmitLValue but additionally we generate checking code to |
3769 | | /// guard against undefined behavior. This is only suitable when we know |
3770 | | /// that the address will be used to access the object. |
3771 | | LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK); |
3772 | | |
3773 | | RValue convertTempToRValue(Address addr, QualType type, |
3774 | | SourceLocation Loc); |
3775 | | |
3776 | | void EmitAtomicInit(Expr *E, LValue lvalue); |
3777 | | |
3778 | | bool LValueIsSuitableForInlineAtomic(LValue Src); |
3779 | | |
3780 | | RValue EmitAtomicLoad(LValue LV, SourceLocation SL, |
3781 | | AggValueSlot Slot = AggValueSlot::ignored()); |
3782 | | |
3783 | | RValue EmitAtomicLoad(LValue lvalue, SourceLocation loc, |
3784 | | llvm::AtomicOrdering AO, bool IsVolatile = false, |
3785 | | AggValueSlot slot = AggValueSlot::ignored()); |
3786 | | |
3787 | | void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit); |
3788 | | |
3789 | | void EmitAtomicStore(RValue rvalue, LValue lvalue, llvm::AtomicOrdering AO, |
3790 | | bool IsVolatile, bool isInit); |
3791 | | |
3792 | | std::pair<RValue, llvm::Value *> EmitAtomicCompareExchange( |
3793 | | LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc, |
3794 | | llvm::AtomicOrdering Success = |
3795 | | llvm::AtomicOrdering::SequentiallyConsistent, |
3796 | | llvm::AtomicOrdering Failure = |
3797 | | llvm::AtomicOrdering::SequentiallyConsistent, |
3798 | | bool IsWeak = false, AggValueSlot Slot = AggValueSlot::ignored()); |
3799 | | |
3800 | | void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO, |
3801 | | const llvm::function_ref<RValue(RValue)> &UpdateOp, |
3802 | | bool IsVolatile); |
3803 | | |
3804 | | /// EmitToMemory - Change a scalar value from its value |
3805 | | /// representation to its in-memory representation. |
3806 | | llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty); |
3807 | | |
3808 | | /// EmitFromMemory - Change a scalar value from its memory |
3809 | | /// representation to its value representation. |
3810 | | llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty); |
3811 | | |
3812 | | /// Check if the scalar \p Value is within the valid range for the given |
3813 | | /// type \p Ty. |
3814 | | /// |
3815 | | /// Returns true if a check is needed (even if the range is unknown). |
3816 | | bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty, |
3817 | | SourceLocation Loc); |
3818 | | |
3819 | | /// EmitLoadOfScalar - Load a scalar value from an address, taking |
3820 | | /// care to appropriately convert from the memory representation to |
3821 | | /// the LLVM value representation. |
3822 | | llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, |
3823 | | SourceLocation Loc, |
3824 | | AlignmentSource Source = AlignmentSource::Type, |
3825 | 4.79k | bool isNontemporal = false) { |
3826 | 4.79k | return EmitLoadOfScalar(Addr, Volatile, Ty, Loc, LValueBaseInfo(Source), |
3827 | 4.79k | CGM.getTBAAAccessInfo(Ty), isNontemporal); |
3828 | 4.79k | } |
3829 | | |
3830 | | llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, |
3831 | | SourceLocation Loc, LValueBaseInfo BaseInfo, |
3832 | | TBAAAccessInfo TBAAInfo, |
3833 | | bool isNontemporal = false); |
3834 | | |
3835 | | /// EmitLoadOfScalar - Load a scalar value from an address, taking |
3836 | | /// care to appropriately convert from the memory representation to |
3837 | | /// the LLVM value representation. The l-value must be a simple |
3838 | | /// l-value. |
3839 | | llvm::Value *EmitLoadOfScalar(LValue lvalue, SourceLocation Loc); |
3840 | | |
3841 | | /// EmitStoreOfScalar - Store a scalar value to an address, taking |
3842 | | /// care to appropriately convert from the memory representation to |
3843 | | /// the LLVM value representation. |
3844 | | void EmitStoreOfScalar(llvm::Value *Value, Address Addr, |
3845 | | bool Volatile, QualType Ty, |
3846 | | AlignmentSource Source = AlignmentSource::Type, |
3847 | 1.20k | bool isInit = false, bool isNontemporal = false) { |
3848 | 1.20k | EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source), |
3849 | 1.20k | CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal); |
3850 | 1.20k | } |
3851 | | |
3852 | | void EmitStoreOfScalar(llvm::Value *Value, Address Addr, |
3853 | | bool Volatile, QualType Ty, |
3854 | | LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo, |
3855 | | bool isInit = false, bool isNontemporal = false); |
3856 | | |
3857 | | /// EmitStoreOfScalar - Store a scalar value to an address, taking |
3858 | | /// care to appropriately convert from the memory representation to |
3859 | | /// the LLVM value representation. The l-value must be a simple |
3860 | | /// l-value. The isInit flag indicates whether this is an initialization. |
3861 | | /// If so, atomic qualifiers are ignored and the store is always non-atomic. |
3862 | | void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false); |
3863 | | |
3864 | | /// EmitLoadOfLValue - Given an expression that represents a value lvalue, |
3865 | | /// this method emits the address of the lvalue, then loads the result as an |
3866 | | /// rvalue, returning the rvalue. |
3867 | | RValue EmitLoadOfLValue(LValue V, SourceLocation Loc); |
3868 | | RValue EmitLoadOfExtVectorElementLValue(LValue V); |
3869 | | RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc); |
3870 | | RValue EmitLoadOfGlobalRegLValue(LValue LV); |
3871 | | |
3872 | | /// EmitStoreThroughLValue - Store the specified rvalue into the specified |
3873 | | /// lvalue, where both are guaranteed to the have the same type, and that type |
3874 | | /// is 'Ty'. |
3875 | | void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false); |
3876 | | void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst); |
3877 | | void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst); |
3878 | | |
3879 | | /// EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints |
3880 | | /// as EmitStoreThroughLValue. |
3881 | | /// |
3882 | | /// \param Result [out] - If non-null, this will be set to a Value* for the |
3883 | | /// bit-field contents after the store, appropriate for use as the result of |
3884 | | /// an assignment to the bit-field. |
3885 | | void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, |
3886 | | llvm::Value **Result=nullptr); |
3887 | | |
3888 | | /// Emit an l-value for an assignment (simple or compound) of complex type. |
3889 | | LValue EmitComplexAssignmentLValue(const BinaryOperator *E); |
3890 | | LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E); |
3891 | | LValue EmitScalarCompoundAssignWithComplex(const CompoundAssignOperator *E, |
3892 | | llvm::Value *&Result); |
3893 | | |
3894 | | // Note: only available for agg return types |
3895 | | LValue EmitBinaryOperatorLValue(const BinaryOperator *E); |
3896 | | LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E); |
3897 | | // Note: only available for agg return types |
3898 | | LValue EmitCallExprLValue(const CallExpr *E); |
3899 | | // Note: only available for agg return types |
3900 | | LValue EmitVAArgExprLValue(const VAArgExpr *E); |
3901 | | LValue EmitDeclRefLValue(const DeclRefExpr *E); |
3902 | | LValue EmitStringLiteralLValue(const StringLiteral *E); |
3903 | | LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); |
3904 | | LValue EmitPredefinedLValue(const PredefinedExpr *E); |
3905 | | LValue EmitUnaryOpLValue(const UnaryOperator *E); |
3906 | | LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, |
3907 | | bool Accessed = false); |
3908 | | LValue EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E); |
3909 | | LValue EmitOMPArraySectionExpr(const OMPArraySectionExpr *E, |
3910 | | bool IsLowerBound = true); |
3911 | | LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); |
3912 | | LValue EmitMemberExpr(const MemberExpr *E); |
3913 | | LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); |
3914 | | LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); |
3915 | | LValue EmitInitListLValue(const InitListExpr *E); |
3916 | | void EmitIgnoredConditionalOperator(const AbstractConditionalOperator *E); |
3917 | | LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E); |
3918 | | LValue EmitCastLValue(const CastExpr *E); |
3919 | | LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); |
3920 | | LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e); |
3921 | | |
3922 | | Address EmitExtVectorElementLValue(LValue V); |
3923 | | |
3924 | | RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc); |
3925 | | |
3926 | | Address EmitArrayToPointerDecay(const Expr *Array, |
3927 | | LValueBaseInfo *BaseInfo = nullptr, |
3928 | | TBAAAccessInfo *TBAAInfo = nullptr); |
3929 | | |
3930 | | class ConstantEmission { |
3931 | | llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference; |
3932 | | ConstantEmission(llvm::Constant *C, bool isReference) |
3933 | 6.96k | : ValueAndIsReference(C, isReference) {} |
3934 | | public: |
3935 | 1.04M | ConstantEmission() {} |
3936 | 60 | static ConstantEmission forReference(llvm::Constant *C) { |
3937 | 60 | return ConstantEmission(C, true); |
3938 | 60 | } |
3939 | 6.90k | static ConstantEmission forValue(llvm::Constant *C) { |
3940 | 6.90k | return ConstantEmission(C, false); |
3941 | 6.90k | } |
3942 | | |
3943 | 1.05M | explicit operator bool() const { |
3944 | 1.05M | return ValueAndIsReference.getOpaqueValue() != nullptr; |
3945 | 1.05M | } |
3946 | | |
3947 | 13.9k | bool isReference() const { return ValueAndIsReference.getInt(); } |
3948 | 60 | LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const { |
3949 | 60 | assert(isReference()); |
3950 | 0 | return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(), |
3951 | 60 | refExpr->getType()); |
3952 | 60 | } |
3953 | | |
3954 | 6.90k | llvm::Constant *getValue() const { |
3955 | 6.90k | assert(!isReference()); |
3956 | 0 | return ValueAndIsReference.getPointer(); |
3957 | 6.90k | } |
3958 | | }; |
3959 | | |
3960 | | ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr); |
3961 | | ConstantEmission tryEmitAsConstant(const MemberExpr *ME); |
3962 | | llvm::Value *emitScalarConstant(const ConstantEmission &Constant, Expr *E); |
3963 | | |
3964 | | RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, |
3965 | | AggValueSlot slot = AggValueSlot::ignored()); |
3966 | | LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e); |
3967 | | |
3968 | | llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, |
3969 | | const ObjCIvarDecl *Ivar); |
3970 | | LValue EmitLValueForField(LValue Base, const FieldDecl* Field); |
3971 | | LValue EmitLValueForLambdaField(const FieldDecl *Field); |
3972 | | |
3973 | | /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that |
3974 | | /// if the Field is a reference, this will return the address of the reference |
3975 | | /// and not the address of the value stored in the reference. |
3976 | | LValue EmitLValueForFieldInitialization(LValue Base, |
3977 | | const FieldDecl* Field); |
3978 | | |
3979 | | LValue EmitLValueForIvar(QualType ObjectTy, |
3980 | | llvm::Value* Base, const ObjCIvarDecl *Ivar, |
3981 | | unsigned CVRQualifiers); |
3982 | | |
3983 | | LValue EmitCXXConstructLValue(const CXXConstructExpr *E); |
3984 | | LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); |
3985 | | LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); |
3986 | | LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E); |
3987 | | |
3988 | | LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); |
3989 | | LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); |
3990 | | LValue EmitStmtExprLValue(const StmtExpr *E); |
3991 | | LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); |
3992 | | LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); |
3993 | | void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init); |
3994 | | |
3995 | | //===--------------------------------------------------------------------===// |
3996 | | // Scalar Expression Emission |
3997 | | //===--------------------------------------------------------------------===// |
3998 | | |
3999 | | /// EmitCall - Generate a call of the given function, expecting the given |
4000 | | /// result type, and using the given argument list which specifies both the |
4001 | | /// LLVM arguments and the types they were derived from. |
4002 | | RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, |
4003 | | ReturnValueSlot ReturnValue, const CallArgList &Args, |
4004 | | llvm::CallBase **callOrInvoke, bool IsMustTail, |
4005 | | SourceLocation Loc); |
4006 | | RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, |
4007 | | ReturnValueSlot ReturnValue, const CallArgList &Args, |
4008 | | llvm::CallBase **callOrInvoke = nullptr, |
4009 | 18.5k | bool IsMustTail = false) { |
4010 | 18.5k | return EmitCall(CallInfo, Callee, ReturnValue, Args, callOrInvoke, |
4011 | 18.5k | IsMustTail, SourceLocation()); |
4012 | 18.5k | } |
4013 | | RValue EmitCall(QualType FnType, const CGCallee &Callee, const CallExpr *E, |
4014 | | ReturnValueSlot ReturnValue, llvm::Value *Chain = nullptr); |
4015 | | RValue EmitCallExpr(const CallExpr *E, |
4016 | | ReturnValueSlot ReturnValue = ReturnValueSlot()); |
4017 | | RValue EmitSimpleCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); |
4018 | | CGCallee EmitCallee(const Expr *E); |
4019 | | |
4020 | | void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl); |
4021 | | void checkTargetFeatures(SourceLocation Loc, const FunctionDecl *TargetDecl); |
4022 | | |
4023 | | llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee, |
4024 | | const Twine &name = ""); |
4025 | | llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee, |
4026 | | ArrayRef<llvm::Value *> args, |
4027 | | const Twine &name = ""); |
4028 | | llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee, |
4029 | | const Twine &name = ""); |
4030 | | llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee, |
4031 | | ArrayRef<llvm::Value *> args, |
4032 | | const Twine &name = ""); |
4033 | | |
4034 | | SmallVector<llvm::OperandBundleDef, 1> |
4035 | | getBundlesForFunclet(llvm::Value *Callee); |
4036 | | |
4037 | | llvm::CallBase *EmitCallOrInvoke(llvm::FunctionCallee Callee, |
4038 | | ArrayRef<llvm::Value *> Args, |
4039 | | const Twine &Name = ""); |
4040 | | llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, |
4041 | | ArrayRef<llvm::Value *> args, |
4042 | | const Twine &name = ""); |
4043 | | llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, |
4044 | | const Twine &name = ""); |
4045 | | void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, |
4046 | | ArrayRef<llvm::Value *> args); |
4047 | | |
4048 | | CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, |
4049 | | NestedNameSpecifier *Qual, |
4050 | | llvm::Type *Ty); |
4051 | | |
4052 | | CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, |
4053 | | CXXDtorType Type, |
4054 | | const CXXRecordDecl *RD); |
4055 | | |
4056 | | // Return the copy constructor name with the prefix "__copy_constructor_" |
4057 | | // removed. |
4058 | | static std::string getNonTrivialCopyConstructorStr(QualType QT, |
4059 | | CharUnits Alignment, |
4060 | | bool IsVolatile, |
4061 | | ASTContext &Ctx); |
4062 | | |
4063 | | // Return the destructor name with the prefix "__destructor_" removed. |
4064 | | static std::string getNonTrivialDestructorStr(QualType QT, |
4065 | | CharUnits Alignment, |
4066 | | bool IsVolatile, |
4067 | | ASTContext &Ctx); |
4068 | | |
4069 | | // These functions emit calls to the special functions of non-trivial C |
4070 | | // structs. |
4071 | | void defaultInitNonTrivialCStructVar(LValue Dst); |
4072 | | void callCStructDefaultConstructor(LValue Dst); |
4073 | | void callCStructDestructor(LValue Dst); |
4074 | | void callCStructCopyConstructor(LValue Dst, LValue Src); |
4075 | | void callCStructMoveConstructor(LValue Dst, LValue Src); |
4076 | | void callCStructCopyAssignmentOperator(LValue Dst, LValue Src); |
4077 | | void callCStructMoveAssignmentOperator(LValue Dst, LValue Src); |
4078 | | |
4079 | | RValue |
4080 | | EmitCXXMemberOrOperatorCall(const CXXMethodDecl *Method, |
4081 | | const CGCallee &Callee, |
4082 | | ReturnValueSlot ReturnValue, llvm::Value *This, |
4083 | | llvm::Value *ImplicitParam, |
4084 | | QualType ImplicitParamTy, const CallExpr *E, |
4085 | | CallArgList *RtlArgs); |
4086 | | RValue EmitCXXDestructorCall(GlobalDecl Dtor, const CGCallee &Callee, |
4087 | | llvm::Value *This, QualType ThisTy, |
4088 | | llvm::Value *ImplicitParam, |
4089 | | QualType ImplicitParamTy, const CallExpr *E); |
4090 | | RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, |
4091 | | ReturnValueSlot ReturnValue); |
4092 | | RValue EmitCXXMemberOrOperatorMemberCallExpr(const CallExpr *CE, |
4093 | | const CXXMethodDecl *MD, |
4094 | | ReturnValueSlot ReturnValue, |
4095 | | bool HasQualifier, |
4096 | | NestedNameSpecifier *Qualifier, |
4097 | | bool IsArrow, const Expr *Base); |
4098 | | // Compute the object pointer. |
4099 | | Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, |
4100 | | llvm::Value *memberPtr, |
4101 | | const MemberPointerType *memberPtrType, |
4102 | | LValueBaseInfo *BaseInfo = nullptr, |
4103 | | TBAAAccessInfo *TBAAInfo = nullptr); |
4104 | | RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, |
4105 | | ReturnValueSlot ReturnValue); |
4106 | | |
4107 | | RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, |
4108 | | const CXXMethodDecl *MD, |
4109 | | ReturnValueSlot ReturnValue); |
4110 | | RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E); |
4111 | | |
4112 | | RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, |
4113 | | ReturnValueSlot ReturnValue); |
4114 | | |
4115 | | RValue EmitNVPTXDevicePrintfCallExpr(const CallExpr *E); |
4116 | | RValue EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E); |
4117 | | RValue EmitOpenMPDevicePrintfCallExpr(const CallExpr *E); |
4118 | | |
4119 | | RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, |
4120 | | const CallExpr *E, ReturnValueSlot ReturnValue); |
4121 | | |
4122 | | RValue emitRotate(const CallExpr *E, bool IsRotateRight); |
4123 | | |
4124 | | /// Emit IR for __builtin_os_log_format. |
4125 | | RValue emitBuiltinOSLogFormat(const CallExpr &E); |
4126 | | |
4127 | | /// Emit IR for __builtin_is_aligned. |
4128 | | RValue EmitBuiltinIsAligned(const CallExpr *E); |
4129 | | /// Emit IR for __builtin_align_up/__builtin_align_down. |
4130 | | RValue EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp); |
4131 | | |
4132 | | llvm::Function *generateBuiltinOSLogHelperFunction( |
4133 | | const analyze_os_log::OSLogBufferLayout &Layout, |
4134 | | CharUnits BufferAlignment); |
4135 | | |
4136 | | RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); |
4137 | | |
4138 | | /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call |
4139 | | /// is unhandled by the current target. |
4140 | | llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E, |
4141 | | ReturnValueSlot ReturnValue); |
4142 | | |
4143 | | llvm::Value *EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty, |
4144 | | const llvm::CmpInst::Predicate Fp, |
4145 | | const llvm::CmpInst::Predicate Ip, |
4146 | | const llvm::Twine &Name = ""); |
4147 | | llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E, |
4148 | | ReturnValueSlot ReturnValue, |
4149 | | llvm::Triple::ArchType Arch); |
4150 | | llvm::Value *EmitARMMVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, |
4151 | | ReturnValueSlot ReturnValue, |
4152 | | llvm::Triple::ArchType Arch); |
4153 | | llvm::Value *EmitARMCDEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, |
4154 | | ReturnValueSlot ReturnValue, |
4155 | | llvm::Triple::ArchType Arch); |
4156 | | llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::IntegerType *ITy, |
4157 | | QualType RTy); |
4158 | | llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::ArrayType *ATy, |
4159 | | QualType RTy); |
4160 | | |
4161 | | llvm::Value *EmitCommonNeonBuiltinExpr(unsigned BuiltinID, |
4162 | | unsigned LLVMIntrinsic, |
4163 | | unsigned AltLLVMIntrinsic, |
4164 | | const char *NameHint, |
4165 | | unsigned Modifier, |
4166 | | const CallExpr *E, |
4167 | | SmallVectorImpl<llvm::Value *> &Ops, |
4168 | | Address PtrOp0, Address PtrOp1, |
4169 | | llvm::Triple::ArchType Arch); |
4170 | | |
4171 | | llvm::Function *LookupNeonLLVMIntrinsic(unsigned IntrinsicID, |
4172 | | unsigned Modifier, llvm::Type *ArgTy, |
4173 | | const CallExpr *E); |
4174 | | llvm::Value *EmitNeonCall(llvm::Function *F, |
4175 | | SmallVectorImpl<llvm::Value*> &O, |
4176 | | const char *name, |
4177 | | unsigned shift = 0, bool rightshift = false); |
4178 | | llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx, |
4179 | | const llvm::ElementCount &Count); |
4180 | | llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx); |
4181 | | llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, |
4182 | | bool negateForRightShift); |
4183 | | llvm::Value *EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt, |
4184 | | llvm::Type *Ty, bool usgn, const char *name); |
4185 | | llvm::Value *vectorWrapScalar16(llvm::Value *Op); |
4186 | | /// SVEBuiltinMemEltTy - Returns the memory element type for this memory |
4187 | | /// access builtin. Only required if it can't be inferred from the base |
4188 | | /// pointer operand. |
4189 | | llvm::Type *SVEBuiltinMemEltTy(const SVETypeFlags &TypeFlags); |
4190 | | |
4191 | | SmallVector<llvm::Type *, 2> |
4192 | | getSVEOverloadTypes(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, |
4193 | | ArrayRef<llvm::Value *> Ops); |
4194 | | llvm::Type *getEltType(const SVETypeFlags &TypeFlags); |
4195 | | llvm::ScalableVectorType *getSVEType(const SVETypeFlags &TypeFlags); |
4196 | | llvm::ScalableVectorType *getSVEPredType(const SVETypeFlags &TypeFlags); |
4197 | | llvm::Value *EmitSVEAllTruePred(const SVETypeFlags &TypeFlags); |
4198 | | llvm::Value *EmitSVEDupX(llvm::Value *Scalar); |
4199 | | llvm::Value *EmitSVEDupX(llvm::Value *Scalar, llvm::Type *Ty); |
4200 | | llvm::Value *EmitSVEReinterpret(llvm::Value *Val, llvm::Type *Ty); |
4201 | | llvm::Value *EmitSVEPMull(const SVETypeFlags &TypeFlags, |
4202 | | llvm::SmallVectorImpl<llvm::Value *> &Ops, |
4203 | | unsigned BuiltinID); |
4204 | | llvm::Value *EmitSVEMovl(const SVETypeFlags &TypeFlags, |
4205 | | llvm::ArrayRef<llvm::Value *> Ops, |
4206 | | unsigned BuiltinID); |
4207 | | llvm::Value *EmitSVEPredicateCast(llvm::Value *Pred, |
4208 | | llvm::ScalableVectorType *VTy); |
4209 | | llvm::Value *EmitSVEGatherLoad(const SVETypeFlags &TypeFlags, |
4210 | | llvm::SmallVectorImpl<llvm::Value *> &Ops, |
4211 | | unsigned IntID); |
4212 | | llvm::Value *EmitSVEScatterStore(const SVETypeFlags &TypeFlags, |
4213 | | llvm::SmallVectorImpl<llvm::Value *> &Ops, |
4214 | | unsigned IntID); |
4215 | | llvm::Value *EmitSVEMaskedLoad(const CallExpr *, llvm::Type *ReturnTy, |
4216 | | SmallVectorImpl<llvm::Value *> &Ops, |
4217 | | unsigned BuiltinID, bool IsZExtReturn); |
4218 | | llvm::Value *EmitSVEMaskedStore(const CallExpr *, |
4219 | | SmallVectorImpl<llvm::Value *> &Ops, |
4220 | | unsigned BuiltinID); |
4221 | | llvm::Value *EmitSVEPrefetchLoad(const SVETypeFlags &TypeFlags, |
4222 | | SmallVectorImpl<llvm::Value *> &Ops, |
4223 | | unsigned BuiltinID); |
4224 | | llvm::Value *EmitSVEGatherPrefetch(const SVETypeFlags &TypeFlags, |
4225 | | SmallVectorImpl<llvm::Value *> &Ops, |
4226 | | unsigned IntID); |
4227 | | llvm::Value *EmitSVEStructLoad(const SVETypeFlags &TypeFlags, |
4228 | | SmallVectorImpl<llvm::Value *> &Ops, |
4229 | | unsigned IntID); |
4230 | | llvm::Value *EmitSVEStructStore(const SVETypeFlags &TypeFlags, |
4231 | | SmallVectorImpl<llvm::Value *> &Ops, |
4232 | | unsigned IntID); |
4233 | | llvm::Value *EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
4234 | | |
4235 | | llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E, |
4236 | | llvm::Triple::ArchType Arch); |
4237 | | llvm::Value *EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
4238 | | |
4239 | | llvm::Value *BuildVector(ArrayRef<llvm::Value*> Ops); |
4240 | | llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
4241 | | llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
4242 | | llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
4243 | | llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
4244 | | llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
4245 | | llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, |
4246 | | const CallExpr *E); |
4247 | | llvm::Value *EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
4248 | | llvm::Value *EmitRISCVBuiltinExpr(unsigned BuiltinID, const CallExpr *E, |
4249 | | ReturnValueSlot ReturnValue); |
4250 | | bool ProcessOrderScopeAMDGCN(llvm::Value *Order, llvm::Value *Scope, |
4251 | | llvm::AtomicOrdering &AO, |
4252 | | llvm::SyncScope::ID &SSID); |
4253 | | |
4254 | | enum class MSVCIntrin; |
4255 | | llvm::Value *EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E); |
4256 | | |
4257 | | llvm::Value *EmitBuiltinAvailable(const VersionTuple &Version); |
4258 | | |
4259 | | llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); |
4260 | | llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); |
4261 | | llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E); |
4262 | | llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E); |
4263 | | llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E); |
4264 | | llvm::Value *EmitObjCCollectionLiteral(const Expr *E, |
4265 | | const ObjCMethodDecl *MethodWithObjects); |
4266 | | llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); |
4267 | | RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, |
4268 | | ReturnValueSlot Return = ReturnValueSlot()); |
4269 | | |
4270 | | /// Retrieves the default cleanup kind for an ARC cleanup. |
4271 | | /// Except under -fobjc-arc-eh, ARC cleanups are normal-only. |
4272 | 1.13k | CleanupKind getARCCleanupKind() { |
4273 | 1.13k | return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions |
4274 | 1.13k | ? NormalAndEHCleanup84 : NormalCleanup1.05k ; |
4275 | 1.13k | } |
4276 | | |
4277 | | // ARC primitives. |
4278 | | void EmitARCInitWeak(Address addr, llvm::Value *value); |
4279 | | void EmitARCDestroyWeak(Address addr); |
4280 | | llvm::Value *EmitARCLoadWeak(Address addr); |
4281 | | llvm::Value *EmitARCLoadWeakRetained(Address addr); |
4282 | | llvm::Value *EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored); |
4283 | | void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr); |
4284 | | void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr); |
4285 | | void EmitARCCopyWeak(Address dst, Address src); |
4286 | | void EmitARCMoveWeak(Address dst, Address src); |
4287 | | llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value); |
4288 | | llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value); |
4289 | | llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value, |
4290 | | bool resultIgnored); |
4291 | | llvm::Value *EmitARCStoreStrongCall(Address addr, llvm::Value *value, |
4292 | | bool resultIgnored); |
4293 | | llvm::Value *EmitARCRetain(QualType type, llvm::Value *value); |
4294 | | llvm::Value *EmitARCRetainNonBlock(llvm::Value *value); |
4295 | | llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory); |
4296 | | void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise); |
4297 | | void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise); |
4298 | | llvm::Value *EmitARCAutorelease(llvm::Value *value); |
4299 | | llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value); |
4300 | | llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value); |
4301 | | llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value); |
4302 | | llvm::Value *EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value); |
4303 | | |
4304 | | llvm::Value *EmitObjCAutorelease(llvm::Value *value, llvm::Type *returnType); |
4305 | | llvm::Value *EmitObjCRetainNonBlock(llvm::Value *value, |
4306 | | llvm::Type *returnType); |
4307 | | void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise); |
4308 | | |
4309 | | std::pair<LValue,llvm::Value*> |
4310 | | EmitARCStoreAutoreleasing(const BinaryOperator *e); |
4311 | | std::pair<LValue,llvm::Value*> |
4312 | | EmitARCStoreStrong(const BinaryOperator *e, bool ignored); |
4313 | | std::pair<LValue,llvm::Value*> |
4314 | | EmitARCStoreUnsafeUnretained(const BinaryOperator *e, bool ignored); |
4315 | | |
4316 | | llvm::Value *EmitObjCAlloc(llvm::Value *value, |
4317 | | llvm::Type *returnType); |
4318 | | llvm::Value *EmitObjCAllocWithZone(llvm::Value *value, |
4319 | | llvm::Type *returnType); |
4320 | | llvm::Value *EmitObjCAllocInit(llvm::Value *value, llvm::Type *resultType); |
4321 | | |
4322 | | llvm::Value *EmitObjCThrowOperand(const Expr *expr); |
4323 | | llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr); |
4324 | | llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr); |
4325 | | |
4326 | | llvm::Value *EmitARCExtendBlockObject(const Expr *expr); |
4327 | | llvm::Value *EmitARCReclaimReturnedObject(const Expr *e, |
4328 | | bool allowUnsafeClaim); |
4329 | | llvm::Value *EmitARCRetainScalarExpr(const Expr *expr); |
4330 | | llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr); |
4331 | | llvm::Value *EmitARCUnsafeUnretainedScalarExpr(const Expr *expr); |
4332 | | |
4333 | | void EmitARCIntrinsicUse(ArrayRef<llvm::Value*> values); |
4334 | | |
4335 | | void EmitARCNoopIntrinsicUse(ArrayRef<llvm::Value *> values); |
4336 | | |
4337 | | static Destroyer destroyARCStrongImprecise; |
4338 | | static Destroyer destroyARCStrongPrecise; |
4339 | | static Destroyer destroyARCWeak; |
4340 | | static Destroyer emitARCIntrinsicUse; |
4341 | | static Destroyer destroyNonTrivialCStruct; |
4342 | | |
4343 | | void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr); |
4344 | | llvm::Value *EmitObjCAutoreleasePoolPush(); |
4345 | | llvm::Value *EmitObjCMRRAutoreleasePoolPush(); |
4346 | | void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr); |
4347 | | void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr); |
4348 | | |
4349 | | /// Emits a reference binding to the passed in expression. |
4350 | | RValue EmitReferenceBindingToExpr(const Expr *E); |
4351 | | |
4352 | | //===--------------------------------------------------------------------===// |
4353 | | // Expression Emission |
4354 | | //===--------------------------------------------------------------------===// |
4355 | | |
4356 | | // Expressions are broken into three classes: scalar, complex, aggregate. |
4357 | | |
4358 | | /// EmitScalarExpr - Emit the computation of the specified expression of LLVM |
4359 | | /// scalar type, returning the result. |
4360 | | llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); |
4361 | | |
4362 | | /// Emit a conversion from the specified type to the specified destination |
4363 | | /// type, both of which are LLVM scalar types. |
4364 | | llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, |
4365 | | QualType DstTy, SourceLocation Loc); |
4366 | | |
4367 | | /// Emit a conversion from the specified complex type to the specified |
4368 | | /// destination type, where the destination type is an LLVM scalar type. |
4369 | | llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, |
4370 | | QualType DstTy, |
4371 | | SourceLocation Loc); |
4372 | | |
4373 | | /// EmitAggExpr - Emit the computation of the specified expression |
4374 | | /// of aggregate type. The result is computed into the given slot, |
4375 | | /// which may be null to indicate that the value is not needed. |
4376 | | void EmitAggExpr(const Expr *E, AggValueSlot AS); |
4377 | | |
4378 | | /// EmitAggExprToLValue - Emit the computation of the specified expression of |
4379 | | /// aggregate type into a temporary LValue. |
4380 | | LValue EmitAggExprToLValue(const Expr *E); |
4381 | | |
4382 | | /// Build all the stores needed to initialize an aggregate at Dest with the |
4383 | | /// value Val. |
4384 | | void EmitAggregateStore(llvm::Value *Val, Address Dest, bool DestIsVolatile); |
4385 | | |
4386 | | /// EmitExtendGCLifetime - Given a pointer to an Objective-C object, |
4387 | | /// make sure it survives garbage collection until this point. |
4388 | | void EmitExtendGCLifetime(llvm::Value *object); |
4389 | | |
4390 | | /// EmitComplexExpr - Emit the computation of the specified expression of |
4391 | | /// complex type, returning the result. |
4392 | | ComplexPairTy EmitComplexExpr(const Expr *E, |
4393 | | bool IgnoreReal = false, |
4394 | | bool IgnoreImag = false); |
4395 | | |
4396 | | /// EmitComplexExprIntoLValue - Emit the given expression of complex |
4397 | | /// type and place its result into the specified l-value. |
4398 | | void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit); |
4399 | | |
4400 | | /// EmitStoreOfComplex - Store a complex number into the specified l-value. |
4401 | | void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit); |
4402 | | |
4403 | | /// EmitLoadOfComplex - Load a complex number from the specified l-value. |
4404 | | ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc); |
4405 | | |
4406 | | Address emitAddrOfRealComponent(Address complex, QualType complexType); |
4407 | | Address emitAddrOfImagComponent(Address complex, QualType complexType); |
4408 | | |
4409 | | /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the |
4410 | | /// global variable that has already been created for it. If the initializer |
4411 | | /// has a different type than GV does, this may free GV and return a different |
4412 | | /// one. Otherwise it just returns GV. |
4413 | | llvm::GlobalVariable * |
4414 | | AddInitializerToStaticVarDecl(const VarDecl &D, |
4415 | | llvm::GlobalVariable *GV); |
4416 | | |
4417 | | // Emit an @llvm.invariant.start call for the given memory region. |
4418 | | void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size); |
4419 | | |
4420 | | /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ |
4421 | | /// variable with global storage. |
4422 | | void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV, |
4423 | | bool PerformInit); |
4424 | | |
4425 | | llvm::Function *createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, |
4426 | | llvm::Constant *Addr); |
4427 | | |
4428 | | llvm::Function *createTLSAtExitStub(const VarDecl &VD, |
4429 | | llvm::FunctionCallee Dtor, |
4430 | | llvm::Constant *Addr, |
4431 | | llvm::FunctionCallee &AtExit); |
4432 | | |
4433 | | /// Call atexit() with a function that passes the given argument to |
4434 | | /// the given function. |
4435 | | void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn, |
4436 | | llvm::Constant *addr); |
4437 | | |
4438 | | /// Call atexit() with function dtorStub. |
4439 | | void registerGlobalDtorWithAtExit(llvm::Constant *dtorStub); |
4440 | | |
4441 | | /// Call unatexit() with function dtorStub. |
4442 | | llvm::Value *unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub); |
4443 | | |
4444 | | /// Emit code in this function to perform a guarded variable |
4445 | | /// initialization. Guarded initializations are used when it's not |
4446 | | /// possible to prove that an initialization will be done exactly |
4447 | | /// once, e.g. with a static local variable or a static data member |
4448 | | /// of a class template. |
4449 | | void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, |
4450 | | bool PerformInit); |
4451 | | |
4452 | | enum class GuardKind { VariableGuard, TlsGuard }; |
4453 | | |
4454 | | /// Emit a branch to select whether or not to perform guarded initialization. |
4455 | | void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit, |
4456 | | llvm::BasicBlock *InitBlock, |
4457 | | llvm::BasicBlock *NoInitBlock, |
4458 | | GuardKind Kind, const VarDecl *D); |
4459 | | |
4460 | | /// GenerateCXXGlobalInitFunc - Generates code for initializing global |
4461 | | /// variables. |
4462 | | void |
4463 | | GenerateCXXGlobalInitFunc(llvm::Function *Fn, |
4464 | | ArrayRef<llvm::Function *> CXXThreadLocals, |
4465 | | ConstantAddress Guard = ConstantAddress::invalid()); |
4466 | | |
4467 | | /// GenerateCXXGlobalCleanUpFunc - Generates code for cleaning up global |
4468 | | /// variables. |
4469 | | void GenerateCXXGlobalCleanUpFunc( |
4470 | | llvm::Function *Fn, |
4471 | | ArrayRef<std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH, |
4472 | | llvm::Constant *>> |
4473 | | DtorsOrStermFinalizers); |
4474 | | |
4475 | | void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, |
4476 | | const VarDecl *D, |
4477 | | llvm::GlobalVariable *Addr, |
4478 | | bool PerformInit); |
4479 | | |
4480 | | void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest); |
4481 | | |
4482 | | void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp); |
4483 | | |
4484 | | void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true); |
4485 | | |
4486 | | RValue EmitAtomicExpr(AtomicExpr *E); |
4487 | | |
4488 | | //===--------------------------------------------------------------------===// |
4489 | | // Annotations Emission |
4490 | | //===--------------------------------------------------------------------===// |
4491 | | |
4492 | | /// Emit an annotation call (intrinsic). |
4493 | | llvm::Value *EmitAnnotationCall(llvm::Function *AnnotationFn, |
4494 | | llvm::Value *AnnotatedVal, |
4495 | | StringRef AnnotationStr, |
4496 | | SourceLocation Location, |
4497 | | const AnnotateAttr *Attr); |
4498 | | |
4499 | | /// Emit local annotations for the local variable V, declared by D. |
4500 | | void EmitVarAnnotations(const VarDecl *D, llvm::Value *V); |
4501 | | |
4502 | | /// Emit field annotations for the given field & value. Returns the |
4503 | | /// annotation result. |
4504 | | Address EmitFieldAnnotations(const FieldDecl *D, Address V); |
4505 | | |
4506 | | //===--------------------------------------------------------------------===// |
4507 | | // Internal Helpers |
4508 | | //===--------------------------------------------------------------------===// |
4509 | | |
4510 | | /// ContainsLabel - Return true if the statement contains a label in it. If |
4511 | | /// this statement is not executed normally, it not containing a label means |
4512 | | /// that we can just remove the code. |
4513 | | static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); |
4514 | | |
4515 | | /// containsBreak - Return true if the statement contains a break out of it. |
4516 | | /// If the statement (recursively) contains a switch or loop with a break |
4517 | | /// inside of it, this is fine. |
4518 | | static bool containsBreak(const Stmt *S); |
4519 | | |
4520 | | /// Determine if the given statement might introduce a declaration into the |
4521 | | /// current scope, by being a (possibly-labelled) DeclStmt. |
4522 | | static bool mightAddDeclToScope(const Stmt *S); |
4523 | | |
4524 | | /// ConstantFoldsToSimpleInteger - If the specified expression does not fold |
4525 | | /// to a constant, or if it does but contains a label, return false. If it |
4526 | | /// constant folds return true and set the boolean result in Result. |
4527 | | bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, |
4528 | | bool AllowLabels = false); |
4529 | | |
4530 | | /// ConstantFoldsToSimpleInteger - If the specified expression does not fold |
4531 | | /// to a constant, or if it does but contains a label, return false. If it |
4532 | | /// constant folds return true and set the folded value. |
4533 | | bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result, |
4534 | | bool AllowLabels = false); |
4535 | | |
4536 | | /// isInstrumentedCondition - Determine whether the given condition is an |
4537 | | /// instrumentable condition (i.e. no "&&" or "||"). |
4538 | | static bool isInstrumentedCondition(const Expr *C); |
4539 | | |
4540 | | /// EmitBranchToCounterBlock - Emit a conditional branch to a new block that |
4541 | | /// increments a profile counter based on the semantics of the given logical |
4542 | | /// operator opcode. This is used to instrument branch condition coverage |
4543 | | /// for logical operators. |
4544 | | void EmitBranchToCounterBlock(const Expr *Cond, BinaryOperator::Opcode LOp, |
4545 | | llvm::BasicBlock *TrueBlock, |
4546 | | llvm::BasicBlock *FalseBlock, |
4547 | | uint64_t TrueCount = 0, |
4548 | | Stmt::Likelihood LH = Stmt::LH_None, |
4549 | | const Expr *CntrIdx = nullptr); |
4550 | | |
4551 | | /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an |
4552 | | /// if statement) to the specified blocks. Based on the condition, this might |
4553 | | /// try to simplify the codegen of the conditional based on the branch. |
4554 | | /// TrueCount should be the number of times we expect the condition to |
4555 | | /// evaluate to true based on PGO data. |
4556 | | void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, |
4557 | | llvm::BasicBlock *FalseBlock, uint64_t TrueCount, |
4558 | | Stmt::Likelihood LH = Stmt::LH_None); |
4559 | | |
4560 | | /// Given an assignment `*LHS = RHS`, emit a test that checks if \p RHS is |
4561 | | /// nonnull, if \p LHS is marked _Nonnull. |
4562 | | void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc); |
4563 | | |
4564 | | /// An enumeration which makes it easier to specify whether or not an |
4565 | | /// operation is a subtraction. |
4566 | | enum { NotSubtraction = false, IsSubtraction = true }; |
4567 | | |
4568 | | /// Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to |
4569 | | /// detect undefined behavior when the pointer overflow sanitizer is enabled. |
4570 | | /// \p SignedIndices indicates whether any of the GEP indices are signed. |
4571 | | /// \p IsSubtraction indicates whether the expression used to form the GEP |
4572 | | /// is a subtraction. |
4573 | | llvm::Value *EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr, |
4574 | | ArrayRef<llvm::Value *> IdxList, |
4575 | | bool SignedIndices, |
4576 | | bool IsSubtraction, |
4577 | | SourceLocation Loc, |
4578 | | const Twine &Name = ""); |
4579 | | |
4580 | | /// Specifies which type of sanitizer check to apply when handling a |
4581 | | /// particular builtin. |
4582 | | enum BuiltinCheckKind { |
4583 | | BCK_CTZPassedZero, |
4584 | | BCK_CLZPassedZero, |
4585 | | }; |
4586 | | |
4587 | | /// Emits an argument for a call to a builtin. If the builtin sanitizer is |
4588 | | /// enabled, a runtime check specified by \p Kind is also emitted. |
4589 | | llvm::Value *EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind); |
4590 | | |
4591 | | /// Emit a description of a type in a format suitable for passing to |
4592 | | /// a runtime sanitizer handler. |
4593 | | llvm::Constant *EmitCheckTypeDescriptor(QualType T); |
4594 | | |
4595 | | /// Convert a value into a format suitable for passing to a runtime |
4596 | | /// sanitizer handler. |
4597 | | llvm::Value *EmitCheckValue(llvm::Value *V); |
4598 | | |
4599 | | /// Emit a description of a source location in a format suitable for |
4600 | | /// passing to a runtime sanitizer handler. |
4601 | | llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc); |
4602 | | |
4603 | | /// Create a basic block that will either trap or call a handler function in |
4604 | | /// the UBSan runtime with the provided arguments, and create a conditional |
4605 | | /// branch to it. |
4606 | | void EmitCheck(ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked, |
4607 | | SanitizerHandler Check, ArrayRef<llvm::Constant *> StaticArgs, |
4608 | | ArrayRef<llvm::Value *> DynamicArgs); |
4609 | | |
4610 | | /// Emit a slow path cross-DSO CFI check which calls __cfi_slowpath |
4611 | | /// if Cond if false. |
4612 | | void EmitCfiSlowPathCheck(SanitizerMask Kind, llvm::Value *Cond, |
4613 | | llvm::ConstantInt *TypeId, llvm::Value *Ptr, |
4614 | | ArrayRef<llvm::Constant *> StaticArgs); |
4615 | | |
4616 | | /// Emit a reached-unreachable diagnostic if \p Loc is valid and runtime |
4617 | | /// checking is enabled. Otherwise, just emit an unreachable instruction. |
4618 | | void EmitUnreachable(SourceLocation Loc); |
4619 | | |
4620 | | /// Create a basic block that will call the trap intrinsic, and emit a |
4621 | | /// conditional branch to it, for the -ftrapv checks. |
4622 | | void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID); |
4623 | | |
4624 | | /// Emit a call to trap or debugtrap and attach function attribute |
4625 | | /// "trap-func-name" if specified. |
4626 | | llvm::CallInst *EmitTrapCall(llvm::Intrinsic::ID IntrID); |
4627 | | |
4628 | | /// Emit a stub for the cross-DSO CFI check function. |
4629 | | void EmitCfiCheckStub(); |
4630 | | |
4631 | | /// Emit a cross-DSO CFI failure handling function. |
4632 | | void EmitCfiCheckFail(); |
4633 | | |
4634 | | /// Create a check for a function parameter that may potentially be |
4635 | | /// declared as non-null. |
4636 | | void EmitNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc, |
4637 | | AbstractCallee AC, unsigned ParmNum); |
4638 | | |
4639 | | /// EmitCallArg - Emit a single call argument. |
4640 | | void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType); |
4641 | | |
4642 | | /// EmitDelegateCallArg - We are performing a delegate call; that |
4643 | | /// is, the current function is delegating to another one. Produce |
4644 | | /// a r-value suitable for passing the given parameter. |
4645 | | void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, |
4646 | | SourceLocation loc); |
4647 | | |
4648 | | /// SetFPAccuracy - Set the minimum required accuracy of the given floating |
4649 | | /// point operation, expressed as the maximum relative error in ulp. |
4650 | | void SetFPAccuracy(llvm::Value *Val, float Accuracy); |
4651 | | |
4652 | | /// Set the codegen fast-math flags. |
4653 | | void SetFastMathFlags(FPOptions FPFeatures); |
4654 | | |
4655 | | // Truncate or extend a boolean vector to the requested number of elements. |
4656 | | llvm::Value *emitBoolVecConversion(llvm::Value *SrcVec, |
4657 | | unsigned NumElementsDst, |
4658 | | const llvm::Twine &Name = ""); |
4659 | | |
4660 | | private: |
4661 | | llvm::MDNode *getRangeForLoadFromType(QualType Ty); |
4662 | | void EmitReturnOfRValue(RValue RV, QualType Ty); |
4663 | | |
4664 | | void deferPlaceholderReplacement(llvm::Instruction *Old, llvm::Value *New); |
4665 | | |
4666 | | llvm::SmallVector<std::pair<llvm::WeakTrackingVH, llvm::Value *>, 4> |
4667 | | DeferredReplacements; |
4668 | | |
4669 | | /// Set the address of a local variable. |
4670 | 800k | void setAddrOfLocalVar(const VarDecl *VD, Address Addr) { |
4671 | 800k | assert(!LocalDeclMap.count(VD) && "Decl already exists in LocalDeclMap!"); |
4672 | 0 | LocalDeclMap.insert({VD, Addr}); |
4673 | 800k | } |
4674 | | |
4675 | | /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty |
4676 | | /// from function arguments into \arg Dst. See ABIArgInfo::Expand. |
4677 | | /// |
4678 | | /// \param AI - The first function argument of the expansion. |
4679 | | void ExpandTypeFromArgs(QualType Ty, LValue Dst, |
4680 | | llvm::Function::arg_iterator &AI); |
4681 | | |
4682 | | /// ExpandTypeToArgs - Expand an CallArg \arg Arg, with the LLVM type for \arg |
4683 | | /// Ty, into individual arguments on the provided vector \arg IRCallArgs, |
4684 | | /// starting at index \arg IRCallArgPos. See ABIArgInfo::Expand. |
4685 | | void ExpandTypeToArgs(QualType Ty, CallArg Arg, llvm::FunctionType *IRFuncTy, |
4686 | | SmallVectorImpl<llvm::Value *> &IRCallArgs, |
4687 | | unsigned &IRCallArgPos); |
4688 | | |
4689 | | std::pair<llvm::Value *, llvm::Type *> |
4690 | | EmitAsmInput(const TargetInfo::ConstraintInfo &Info, const Expr *InputExpr, |
4691 | | std::string &ConstraintStr); |
4692 | | |
4693 | | std::pair<llvm::Value *, llvm::Type *> |
4694 | | EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info, LValue InputValue, |
4695 | | QualType InputType, std::string &ConstraintStr, |
4696 | | SourceLocation Loc); |
4697 | | |
4698 | | /// Attempts to statically evaluate the object size of E. If that |
4699 | | /// fails, emits code to figure the size of E out for us. This is |
4700 | | /// pass_object_size aware. |
4701 | | /// |
4702 | | /// If EmittedExpr is non-null, this will use that instead of re-emitting E. |
4703 | | llvm::Value *evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, |
4704 | | llvm::IntegerType *ResType, |
4705 | | llvm::Value *EmittedE, |
4706 | | bool IsDynamic); |
4707 | | |
4708 | | /// Emits the size of E, as required by __builtin_object_size. This |
4709 | | /// function is aware of pass_object_size parameters, and will act accordingly |
4710 | | /// if E is a parameter with the pass_object_size attribute. |
4711 | | llvm::Value *emitBuiltinObjectSize(const Expr *E, unsigned Type, |
4712 | | llvm::IntegerType *ResType, |
4713 | | llvm::Value *EmittedE, |
4714 | | bool IsDynamic); |
4715 | | |
4716 | | void emitZeroOrPatternForAutoVarInit(QualType type, const VarDecl &D, |
4717 | | Address Loc); |
4718 | | |
4719 | | public: |
4720 | | enum class EvaluationOrder { |
4721 | | ///! No language constraints on evaluation order. |
4722 | | Default, |
4723 | | ///! Language semantics require left-to-right evaluation. |
4724 | | ForceLeftToRight, |
4725 | | ///! Language semantics require right-to-left evaluation. |
4726 | | ForceRightToLeft |
4727 | | }; |
4728 | | |
4729 | | // Wrapper for function prototype sources. Wraps either a FunctionProtoType or |
4730 | | // an ObjCMethodDecl. |
4731 | | struct PrototypeWrapper { |
4732 | | llvm::PointerUnion<const FunctionProtoType *, const ObjCMethodDecl *> P; |
4733 | | |
4734 | 296k | PrototypeWrapper(const FunctionProtoType *FT) : P(FT) {} |
4735 | 11.9k | PrototypeWrapper(const ObjCMethodDecl *MD) : P(MD) {} |
4736 | | }; |
4737 | | |
4738 | | void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, |
4739 | | llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange, |
4740 | | AbstractCallee AC = AbstractCallee(), |
4741 | | unsigned ParamsToSkip = 0, |
4742 | | EvaluationOrder Order = EvaluationOrder::Default); |
4743 | | |
4744 | | /// EmitPointerWithAlignment - Given an expression with a pointer type, |
4745 | | /// emit the value and compute our best estimate of the alignment of the |
4746 | | /// pointee. |
4747 | | /// |
4748 | | /// \param BaseInfo - If non-null, this will be initialized with |
4749 | | /// information about the source of the alignment and the may-alias |
4750 | | /// attribute. Note that this function will conservatively fall back on |
4751 | | /// the type when it doesn't recognize the expression and may-alias will |
4752 | | /// be set to false. |
4753 | | /// |
4754 | | /// One reasonable way to use this information is when there's a language |
4755 | | /// guarantee that the pointer must be aligned to some stricter value, and |
4756 | | /// we're simply trying to ensure that sufficiently obvious uses of under- |
4757 | | /// aligned objects don't get miscompiled; for example, a placement new |
4758 | | /// into the address of a local variable. In such a case, it's quite |
4759 | | /// reasonable to just ignore the returned alignment when it isn't from an |
4760 | | /// explicit source. |
4761 | | Address EmitPointerWithAlignment(const Expr *Addr, |
4762 | | LValueBaseInfo *BaseInfo = nullptr, |
4763 | | TBAAAccessInfo *TBAAInfo = nullptr); |
4764 | | |
4765 | | /// If \p E references a parameter with pass_object_size info or a constant |
4766 | | /// array size modifier, emit the object size divided by the size of \p EltTy. |
4767 | | /// Otherwise return null. |
4768 | | llvm::Value *LoadPassedObjectSize(const Expr *E, QualType EltTy); |
4769 | | |
4770 | | void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK); |
4771 | | |
4772 | | struct MultiVersionResolverOption { |
4773 | | llvm::Function *Function; |
4774 | | struct Conds { |
4775 | | StringRef Architecture; |
4776 | | llvm::SmallVector<StringRef, 8> Features; |
4777 | | |
4778 | | Conds(StringRef Arch, ArrayRef<StringRef> Feats) |
4779 | 342 | : Architecture(Arch), Features(Feats.begin(), Feats.end()) {} |
4780 | | } Conditions; |
4781 | | |
4782 | | MultiVersionResolverOption(llvm::Function *F, StringRef Arch, |
4783 | | ArrayRef<StringRef> Feats) |
4784 | 342 | : Function(F), Conditions(Arch, Feats) {} |
4785 | | }; |
4786 | | |
4787 | | // Emits the body of a multiversion function's resolver. Assumes that the |
4788 | | // options are already sorted in the proper order, with the 'default' option |
4789 | | // last (if it exists). |
4790 | | void EmitMultiVersionResolver(llvm::Function *Resolver, |
4791 | | ArrayRef<MultiVersionResolverOption> Options); |
4792 | | |
4793 | | private: |
4794 | | QualType getVarArgType(const Expr *Arg); |
4795 | | |
4796 | | void EmitDeclMetadata(); |
4797 | | |
4798 | | BlockByrefHelpers *buildByrefHelpers(llvm::StructType &byrefType, |
4799 | | const AutoVarEmission &emission); |
4800 | | |
4801 | | void AddObjCARCExceptionMetadata(llvm::Instruction *Inst); |
4802 | | |
4803 | | llvm::Value *GetValueForARMHint(unsigned BuiltinID); |
4804 | | llvm::Value *EmitX86CpuIs(const CallExpr *E); |
4805 | | llvm::Value *EmitX86CpuIs(StringRef CPUStr); |
4806 | | llvm::Value *EmitX86CpuSupports(const CallExpr *E); |
4807 | | llvm::Value *EmitX86CpuSupports(ArrayRef<StringRef> FeatureStrs); |
4808 | | llvm::Value *EmitX86CpuSupports(uint64_t Mask); |
4809 | | llvm::Value *EmitX86CpuInit(); |
4810 | | llvm::Value *FormResolverCondition(const MultiVersionResolverOption &RO); |
4811 | | }; |
4812 | | |
4813 | | |
4814 | | inline DominatingLLVMValue::saved_type |
4815 | 247 | DominatingLLVMValue::save(CodeGenFunction &CGF, llvm::Value *value) { |
4816 | 247 | if (!needsSaving(value)) return saved_type(value, false)206 ; |
4817 | | |
4818 | | // Otherwise, we need an alloca. |
4819 | 41 | auto align = CharUnits::fromQuantity( |
4820 | 41 | CGF.CGM.getDataLayout().getPrefTypeAlignment(value->getType())); |
4821 | 41 | Address alloca = |
4822 | 41 | CGF.CreateTempAlloca(value->getType(), align, "cond-cleanup.save"); |
4823 | 41 | CGF.Builder.CreateStore(value, alloca); |
4824 | | |
4825 | 41 | return saved_type(alloca.getPointer(), true); |
4826 | 247 | } |
4827 | | |
4828 | | inline llvm::Value *DominatingLLVMValue::restore(CodeGenFunction &CGF, |
4829 | 258 | saved_type value) { |
4830 | | // If the value says it wasn't saved, trust that it's still dominating. |
4831 | 258 | if (!value.getInt()) return value.getPointer()231 ; |
4832 | | |
4833 | | // Otherwise, it should be an alloca instruction, as set up in save(). |
4834 | 27 | auto alloca = cast<llvm::AllocaInst>(value.getPointer()); |
4835 | 27 | return CGF.Builder.CreateAlignedLoad(alloca->getAllocatedType(), alloca, |
4836 | 27 | alloca->getAlign()); |
4837 | 258 | } |
4838 | | |
4839 | | } // end namespace CodeGen |
4840 | | |
4841 | | // Map the LangOption for floating point exception behavior into |
4842 | | // the corresponding enum in the IR. |
4843 | | llvm::fp::ExceptionBehavior |
4844 | | ToConstrainedExceptMD(LangOptions::FPExceptionModeKind Kind); |
4845 | | } // end namespace clang |
4846 | | |
4847 | | #endif |