1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
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/ExprCXX.h" |
26 | #include "clang/AST/ExprObjC.h" |
27 | #include "clang/AST/ExprOpenMP.h" |
28 | #include "clang/AST/Type.h" |
29 | #include "clang/Basic/ABI.h" |
30 | #include "clang/Basic/CapturedStmt.h" |
31 | #include "clang/Basic/CodeGenOptions.h" |
32 | #include "clang/Basic/OpenMPKinds.h" |
33 | #include "clang/Basic/TargetInfo.h" |
34 | #include "llvm/ADT/ArrayRef.h" |
35 | #include "llvm/ADT/DenseMap.h" |
36 | #include "llvm/ADT/MapVector.h" |
37 | #include "llvm/ADT/SmallVector.h" |
38 | #include "llvm/IR/ValueHandle.h" |
39 | #include "llvm/Support/Debug.h" |
40 | #include "llvm/Transforms/Utils/SanitizerStats.h" |
41 | |
42 | namespace llvm { |
43 | class BasicBlock; |
44 | class LLVMContext; |
45 | class MDNode; |
46 | class Module; |
47 | class SwitchInst; |
48 | class Twine; |
49 | class Value; |
50 | } |
51 | |
52 | namespace clang { |
53 | class ASTContext; |
54 | class BlockDecl; |
55 | class CXXDestructorDecl; |
56 | class CXXForRangeStmt; |
57 | class CXXTryStmt; |
58 | class Decl; |
59 | class LabelDecl; |
60 | class EnumConstantDecl; |
61 | class FunctionDecl; |
62 | class FunctionProtoType; |
63 | class LabelStmt; |
64 | class ObjCContainerDecl; |
65 | class ObjCInterfaceDecl; |
66 | class ObjCIvarDecl; |
67 | class ObjCMethodDecl; |
68 | class ObjCImplementationDecl; |
69 | class ObjCPropertyImplDecl; |
70 | class TargetInfo; |
71 | class VarDecl; |
72 | class ObjCForCollectionStmt; |
73 | class ObjCAtTryStmt; |
74 | class ObjCAtThrowStmt; |
75 | class ObjCAtSynchronizedStmt; |
76 | class ObjCAutoreleasePoolStmt; |
77 | |
78 | namespace analyze_os_log { |
79 | class OSLogBufferLayout; |
80 | } |
81 | |
82 | namespace CodeGen { |
83 | class CodeGenTypes; |
84 | class CGCallee; |
85 | class CGFunctionInfo; |
86 | class CGRecordLayout; |
87 | class CGBlockInfo; |
88 | class CGCXXABI; |
89 | class BlockByrefHelpers; |
90 | class BlockByrefInfo; |
91 | class BlockFlags; |
92 | class BlockFieldFlags; |
93 | class RegionCodeGenTy; |
94 | class TargetCodeGenInfo; |
95 | struct OMPTaskDataTy; |
96 | struct CGCoroData; |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | enum TypeEvaluationKind { |
104 | TEK_Scalar, |
105 | TEK_Complex, |
106 | TEK_Aggregate |
107 | }; |
108 | |
109 | #define LIST_SANITIZER_CHECKS \ |
110 | SANITIZER_CHECK(AddOverflow, add_overflow, 0) \ |
111 | SANITIZER_CHECK(BuiltinUnreachable, builtin_unreachable, 0) \ |
112 | SANITIZER_CHECK(CFICheckFail, cfi_check_fail, 0) \ |
113 | SANITIZER_CHECK(DivremOverflow, divrem_overflow, 0) \ |
114 | SANITIZER_CHECK(DynamicTypeCacheMiss, dynamic_type_cache_miss, 0) \ |
115 | SANITIZER_CHECK(FloatCastOverflow, float_cast_overflow, 0) \ |
116 | SANITIZER_CHECK(FunctionTypeMismatch, function_type_mismatch, 0) \ |
117 | SANITIZER_CHECK(ImplicitConversion, implicit_conversion, 0) \ |
118 | SANITIZER_CHECK(InvalidBuiltin, invalid_builtin, 0) \ |
119 | SANITIZER_CHECK(LoadInvalidValue, load_invalid_value, 0) \ |
120 | SANITIZER_CHECK(MissingReturn, missing_return, 0) \ |
121 | SANITIZER_CHECK(MulOverflow, mul_overflow, 0) \ |
122 | SANITIZER_CHECK(NegateOverflow, negate_overflow, 0) \ |
123 | SANITIZER_CHECK(NullabilityArg, nullability_arg, 0) \ |
124 | SANITIZER_CHECK(NullabilityReturn, nullability_return, 1) \ |
125 | SANITIZER_CHECK(NonnullArg, nonnull_arg, 0) \ |
126 | SANITIZER_CHECK(NonnullReturn, nonnull_return, 1) \ |
127 | SANITIZER_CHECK(OutOfBounds, out_of_bounds, 0) \ |
128 | SANITIZER_CHECK(PointerOverflow, pointer_overflow, 0) \ |
129 | SANITIZER_CHECK(ShiftOutOfBounds, shift_out_of_bounds, 0) \ |
130 | SANITIZER_CHECK(SubOverflow, sub_overflow, 0) \ |
131 | SANITIZER_CHECK(TypeMismatch, type_mismatch, 1) \ |
132 | SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0) \ |
133 | SANITIZER_CHECK(VLABoundNotPositive, vla_bound_not_positive, 0) |
134 | |
135 | enum SanitizerHandler { |
136 | #define SANITIZER_CHECK(Enum, Name, Version) Enum, |
137 | LIST_SANITIZER_CHECKS |
138 | #undef SANITIZER_CHECK |
139 | }; |
140 | |
141 | |
142 | |
143 | struct DominatingLLVMValue { |
144 | typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type; |
145 | |
146 | |
147 | static bool needsSaving(llvm::Value *value) { |
148 | |
149 | if (!isa<llvm::Instruction>(value)) return false; |
150 | |
151 | |
152 | llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent(); |
153 | return (block != &block->getParent()->getEntryBlock()); |
154 | } |
155 | |
156 | static saved_type save(CodeGenFunction &CGF, llvm::Value *value); |
157 | static llvm::Value *restore(CodeGenFunction &CGF, saved_type value); |
158 | }; |
159 | |
160 | |
161 | |
162 | template <class T> struct DominatingPointer<T,true> : DominatingLLVMValue { |
163 | typedef T *type; |
164 | static type restore(CodeGenFunction &CGF, saved_type value) { |
165 | return static_cast<T*>(DominatingLLVMValue::restore(CGF, value)); |
166 | } |
167 | }; |
168 | |
169 | |
170 | template <> struct DominatingValue<Address> { |
171 | typedef Address type; |
172 | |
173 | struct saved_type { |
174 | DominatingLLVMValue::saved_type SavedValue; |
175 | CharUnits Alignment; |
176 | }; |
177 | |
178 | static bool needsSaving(type value) { |
179 | return DominatingLLVMValue::needsSaving(value.getPointer()); |
180 | } |
181 | static saved_type save(CodeGenFunction &CGF, type value) { |
182 | return { DominatingLLVMValue::save(CGF, value.getPointer()), |
183 | value.getAlignment() }; |
184 | } |
185 | static type restore(CodeGenFunction &CGF, saved_type value) { |
186 | return Address(DominatingLLVMValue::restore(CGF, value.SavedValue), |
187 | value.Alignment); |
188 | } |
189 | }; |
190 | |
191 | |
192 | template <> struct DominatingValue<RValue> { |
193 | typedef RValue type; |
194 | class saved_type { |
195 | enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral, |
196 | AggregateAddress, ComplexAddress }; |
197 | |
198 | llvm::Value *Value; |
199 | unsigned K : 3; |
200 | unsigned Align : 29; |
201 | saved_type(llvm::Value *v, Kind k, unsigned a = 0) |
202 | : Value(v), K(k), Align(a) {} |
203 | |
204 | public: |
205 | static bool needsSaving(RValue value); |
206 | static saved_type save(CodeGenFunction &CGF, RValue value); |
207 | RValue restore(CodeGenFunction &CGF); |
208 | |
209 | |
210 | }; |
211 | |
212 | static bool needsSaving(type value) { |
213 | return saved_type::needsSaving(value); |
214 | } |
215 | static saved_type save(CodeGenFunction &CGF, type value) { |
216 | return saved_type::save(CGF, value); |
217 | } |
218 | static type restore(CodeGenFunction &CGF, saved_type value) { |
219 | return value.restore(CGF); |
220 | } |
221 | }; |
222 | |
223 | |
224 | |
225 | class CodeGenFunction : public CodeGenTypeCache { |
226 | CodeGenFunction(const CodeGenFunction &) = delete; |
227 | void operator=(const CodeGenFunction &) = delete; |
228 | |
229 | friend class CGCXXABI; |
230 | public: |
231 | |
232 | |
233 | struct JumpDest { |
234 | JumpDest() : Block(nullptr), ScopeDepth(), Index(0) {} |
235 | JumpDest(llvm::BasicBlock *Block, |
236 | EHScopeStack::stable_iterator Depth, |
237 | unsigned Index) |
238 | : Block(Block), ScopeDepth(Depth), Index(Index) {} |
239 | |
240 | bool isValid() const { return Block != nullptr; } |
241 | llvm::BasicBlock *getBlock() const { return Block; } |
242 | EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; } |
243 | unsigned getDestIndex() const { return Index; } |
244 | |
245 | |
246 | void setScopeDepth(EHScopeStack::stable_iterator depth) { |
247 | ScopeDepth = depth; |
248 | } |
249 | |
250 | private: |
251 | llvm::BasicBlock *Block; |
252 | EHScopeStack::stable_iterator ScopeDepth; |
253 | unsigned Index; |
254 | }; |
255 | |
256 | CodeGenModule &CGM; |
257 | const TargetInfo &Target; |
258 | |
259 | typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; |
260 | LoopInfoStack LoopStack; |
261 | CGBuilderTy Builder; |
262 | |
263 | |
264 | |
265 | VarBypassDetector Bypasses; |
266 | |
267 | |
268 | typedef llvm::function_ref<void(CodeGenFunction &, const OMPLoopDirective &, |
269 | JumpDest)> |
270 | CodeGenLoopTy; |
271 | typedef llvm::function_ref<void(CodeGenFunction &, SourceLocation, |
272 | const unsigned, const bool)> |
273 | CodeGenOrderedTy; |
274 | |
275 | |
276 | typedef llvm::function_ref<std::pair<LValue, LValue>( |
277 | CodeGenFunction &, const OMPExecutableDirective &S)> |
278 | CodeGenLoopBoundsTy; |
279 | |
280 | |
281 | typedef llvm::function_ref<std::pair<llvm::Value *, llvm::Value *>( |
282 | CodeGenFunction &, const OMPExecutableDirective &S, Address LB, |
283 | Address UB)> |
284 | CodeGenDispatchBoundsTy; |
285 | |
286 | |
287 | |
288 | void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, |
289 | llvm::BasicBlock *BB, |
290 | llvm::BasicBlock::iterator InsertPt) const; |
291 | |
292 | |
293 | |
294 | const Decl *CurFuncDecl; |
295 | |
296 | const Decl *CurCodeDecl; |
297 | const CGFunctionInfo *CurFnInfo; |
298 | QualType FnRetTy; |
299 | llvm::Function *CurFn = nullptr; |
300 | |
301 | |
302 | |
303 | |
304 | struct CGCoroInfo { |
305 | std::unique_ptr<CGCoroData> Data; |
306 | CGCoroInfo(); |
307 | ~CGCoroInfo(); |
308 | }; |
309 | CGCoroInfo CurCoro; |
310 | |
311 | bool isCoroutine() const { |
312 | return CurCoro.Data != nullptr; |
313 | } |
314 | |
315 | |
316 | GlobalDecl CurGD; |
317 | |
318 | |
319 | |
320 | EHScopeStack::stable_iterator PrologueCleanupDepth; |
321 | |
322 | |
323 | JumpDest ReturnBlock; |
324 | |
325 | |
326 | |
327 | Address ReturnValue = Address::invalid(); |
328 | |
329 | |
330 | bool hasLabelBeenSeenInCurrentScope() const { |
331 | if (CurLexicalScope) |
332 | return CurLexicalScope->hasLabels(); |
333 | return !LabelMap.empty(); |
334 | } |
335 | |
336 | |
337 | |
338 | llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; |
339 | |
340 | |
341 | class CGCapturedStmtInfo { |
342 | public: |
343 | explicit CGCapturedStmtInfo(CapturedRegionKind K = CR_Default) |
344 | : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {} |
345 | explicit CGCapturedStmtInfo(const CapturedStmt &S, |
346 | CapturedRegionKind K = CR_Default) |
347 | : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) { |
348 | |
349 | RecordDecl::field_iterator Field = |
350 | S.getCapturedRecordDecl()->field_begin(); |
351 | for (CapturedStmt::const_capture_iterator I = S.capture_begin(), |
352 | E = S.capture_end(); |
353 | I != E; ++I, ++Field) { |
354 | if (I->capturesThis()) |
355 | CXXThisFieldDecl = *Field; |
356 | else if (I->capturesVariable()) |
357 | CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field; |
358 | else if (I->capturesVariableByCopy()) |
359 | CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field; |
360 | } |
361 | } |
362 | |
363 | virtual ~CGCapturedStmtInfo(); |
364 | |
365 | CapturedRegionKind getKind() const { return Kind; } |
366 | |
367 | virtual void setContextValue(llvm::Value *V) { ThisValue = V; } |
368 | |
369 | virtual llvm::Value *getContextValue() const { return ThisValue; } |
370 | |
371 | |
372 | virtual const FieldDecl *lookup(const VarDecl *VD) const { |
373 | return CaptureFields.lookup(VD->getCanonicalDecl()); |
374 | } |
375 | |
376 | bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; } |
377 | virtual FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; } |
378 | |
379 | static bool classof(const CGCapturedStmtInfo *) { |
380 | return true; |
381 | } |
382 | |
383 | |
384 | virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S) { |
385 | CGF.incrementProfileCounter(S); |
386 | CGF.EmitStmt(S); |
387 | } |
388 | |
389 | |
390 | virtual StringRef getHelperName() const { return "__captured_stmt"; } |
391 | |
392 | private: |
393 | |
394 | CapturedRegionKind Kind; |
395 | |
396 | |
397 | llvm::SmallDenseMap<const VarDecl *, FieldDecl *> CaptureFields; |
398 | |
399 | |
400 | |
401 | llvm::Value *ThisValue; |
402 | |
403 | |
404 | FieldDecl *CXXThisFieldDecl; |
405 | }; |
406 | CGCapturedStmtInfo *CapturedStmtInfo = nullptr; |
407 | |
408 | |
409 | class CGCapturedStmtRAII { |
410 | private: |
411 | CodeGenFunction &CGF; |
412 | CGCapturedStmtInfo *PrevCapturedStmtInfo; |
413 | public: |
414 | CGCapturedStmtRAII(CodeGenFunction &CGF, |
415 | CGCapturedStmtInfo *NewCapturedStmtInfo) |
416 | : CGF(CGF), PrevCapturedStmtInfo(CGF.CapturedStmtInfo) { |
417 | CGF.CapturedStmtInfo = NewCapturedStmtInfo; |
418 | } |
419 | ~CGCapturedStmtRAII() { CGF.CapturedStmtInfo = PrevCapturedStmtInfo; } |
420 | }; |
421 | |
422 | |
423 | class AbstractCallee { |
424 | |
425 | const Decl *CalleeDecl; |
426 | |
427 | public: |
428 | AbstractCallee() : CalleeDecl(nullptr) {} |
429 | AbstractCallee(const FunctionDecl *FD) : CalleeDecl(FD) {} |
430 | AbstractCallee(const ObjCMethodDecl *OMD) : CalleeDecl(OMD) {} |
431 | bool hasFunctionDecl() const { |
432 | return dyn_cast_or_null<FunctionDecl>(CalleeDecl); |
433 | } |
434 | const Decl *getDecl() const { return CalleeDecl; } |
435 | unsigned getNumParams() const { |
436 | if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) |
437 | return FD->getNumParams(); |
438 | return cast<ObjCMethodDecl>(CalleeDecl)->param_size(); |
439 | } |
440 | const ParmVarDecl *getParamDecl(unsigned I) const { |
441 | if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) |
442 | return FD->getParamDecl(I); |
443 | return *(cast<ObjCMethodDecl>(CalleeDecl)->param_begin() + I); |
444 | } |
445 | }; |
446 | |
447 | |
448 | SanitizerSet SanOpts; |
449 | |
450 | |
451 | bool IsSanitizerScope = false; |
452 | |
453 | |
454 | class SanitizerScope { |
455 | CodeGenFunction *CGF; |
456 | public: |
457 | SanitizerScope(CodeGenFunction *CGF); |
458 | ~SanitizerScope(); |
459 | }; |
460 | |
461 | |
462 | |
463 | bool CurFuncIsThunk = false; |
464 | |
465 | |
466 | bool AutoreleaseResult = false; |
467 | |
468 | |
469 | |
470 | bool SawAsmBlock = false; |
471 | |
472 | const NamedDecl *CurSEHParent = nullptr; |
473 | |
474 | |
475 | |
476 | bool IsOutlinedSEHHelper = false; |
477 | |
478 | const CodeGen::CGBlockInfo *BlockInfo = nullptr; |
479 | llvm::Value *BlockPointer = nullptr; |
480 | |
481 | llvm::DenseMap<const VarDecl *, FieldDecl *> LambdaCaptureFields; |
482 | FieldDecl *LambdaThisCaptureField = nullptr; |
483 | |
484 | |
485 | |
486 | llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags; |
487 | |
488 | EHScopeStack EHStack; |
489 | llvm::SmallVector<char, 256> LifetimeExtendedCleanupStack; |
490 | llvm::SmallVector<const JumpDest *, 2> SEHTryEpilogueStack; |
491 | |
492 | llvm::Instruction *CurrentFuncletPad = nullptr; |
493 | |
494 | class CallLifetimeEnd final : public EHScopeStack::Cleanup { |
495 | llvm::Value *Addr; |
496 | llvm::Value *Size; |
497 | |
498 | public: |
499 | CallLifetimeEnd(Address addr, llvm::Value *size) |
500 | : Addr(addr.getPointer()), Size(size) {} |
501 | |
502 | void Emit(CodeGenFunction &CGF, Flags flags) override { |
503 | CGF.EmitLifetimeEnd(Size, Addr); |
504 | } |
505 | }; |
506 | |
507 | |
508 | struct { |
509 | |
510 | unsigned ; |
511 | |
512 | unsigned : 31; |
513 | |
514 | unsigned : 1; |
515 | |
516 | size_t () const { return Size; } |
517 | CleanupKind () const { return (CleanupKind)Kind; } |
518 | bool () const { return IsConditional; } |
519 | }; |
520 | |
521 | |
522 | Address NormalCleanupDest = Address::invalid(); |
523 | |
524 | unsigned NextCleanupDestIndex = 1; |
525 | |
526 | |
527 | CGBlockInfo *FirstBlockInfo = nullptr; |
528 | |
529 | |
530 | llvm::BasicBlock *EHResumeBlock = nullptr; |
531 | |
532 | |
533 | |
534 | llvm::Value *ExceptionSlot = nullptr; |
535 | |
536 | |
537 | |
538 | llvm::AllocaInst *EHSelectorSlot = nullptr; |
539 | |
540 | |
541 | |
542 | |
543 | SmallVector<Address, 1> SEHCodeSlotStack; |
544 | |
545 | |
546 | llvm::Value *SEHInfo = nullptr; |
547 | |
548 | |
549 | llvm::BasicBlock *EmitLandingPad(); |
550 | |
551 | llvm::BasicBlock *getInvokeDestImpl(); |
552 | |
553 | template <class T> |
554 | typename DominatingValue<T>::saved_type saveValueInCond(T value) { |
555 | return DominatingValue<T>::save(*this, value); |
556 | } |
557 | |
558 | public: |
559 | |
560 | |
561 | SmallVector<llvm::Value*, 8> ObjCEHValueStack; |
562 | |
563 | |
564 | class FinallyInfo { |
565 | |
566 | JumpDest RethrowDest; |
567 | |
568 | |
569 | llvm::FunctionCallee BeginCatchFn; |
570 | |
571 | |
572 | |
573 | llvm::AllocaInst *ForEHVar; |
574 | |
575 | |
576 | |
577 | llvm::AllocaInst *SavedExnVar; |
578 | |
579 | public: |
580 | void enter(CodeGenFunction &CGF, const Stmt *Finally, |
581 | llvm::FunctionCallee beginCatchFn, |
582 | llvm::FunctionCallee endCatchFn, llvm::FunctionCallee rethrowFn); |
583 | void exit(CodeGenFunction &CGF); |
584 | }; |
585 | |
586 | |
587 | bool isSEHTryScope() const { return !SEHTryEpilogueStack.empty(); } |
588 | |
589 | |
590 | bool isCleanupPadScope() const { |
591 | return CurrentFuncletPad && isa<llvm::CleanupPadInst>(CurrentFuncletPad); |
592 | } |
593 | |
594 | |
595 | |
596 | |
597 | template <class T, class... As> |
598 | void pushFullExprCleanup(CleanupKind kind, As... A) { |
599 | |
600 | |
601 | if (!isInConditionalBranch()) |
602 | return EHStack.pushCleanup<T>(kind, A...); |
603 | |
604 | |
605 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; |
606 | SavedTuple Saved{saveValueInCond(A)...}; |
607 | |
608 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; |
609 | EHStack.pushCleanupTuple<CleanupType>(kind, Saved); |
610 | initFullExprCleanup(); |
611 | } |
612 | |
613 | |
614 | |
615 | template <class T, class... As> |
616 | void pushCleanupAfterFullExpr(CleanupKind Kind, As... A) { |
617 | if (!isInConditionalBranch()) |
618 | return pushCleanupAfterFullExprImpl<T>(Kind, Address::invalid(), A...); |
619 | |
620 | Address ActiveFlag = createCleanupActiveFlag(); |
621 | (0) . __assert_fail ("!DominatingValue..needsSaving(ActiveFlag) && \"cleanup active flag should never need saving\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 622, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!DominatingValue<Address>::needsSaving(ActiveFlag) && |
622 | (0) . __assert_fail ("!DominatingValue..needsSaving(ActiveFlag) && \"cleanup active flag should never need saving\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 622, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "cleanup active flag should never need saving"); |
623 | |
624 | typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; |
625 | SavedTuple Saved{saveValueInCond(A)...}; |
626 | |
627 | typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; |
628 | pushCleanupAfterFullExprImpl<CleanupType>(Kind, ActiveFlag, Saved); |
629 | } |
630 | |
631 | template <class T, class... As> |
632 | void pushCleanupAfterFullExprImpl(CleanupKind Kind, Address ActiveFlag, |
633 | As... A) { |
634 | LifetimeExtendedCleanupHeader = {sizeof(T), Kind, |
635 | ActiveFlag.isValid()}; |
636 | |
637 | size_t OldSize = LifetimeExtendedCleanupStack.size(); |
638 | LifetimeExtendedCleanupStack.resize( |
639 | LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size + |
640 | (Header.IsConditional ? sizeof(ActiveFlag) : 0)); |
641 | |
642 | static_assert(sizeof(Header) % alignof(T) == 0, |
643 | "Cleanup will be allocated on misaligned address"); |
644 | char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; |
645 | new (Buffer) LifetimeExtendedCleanupHeader(Header); |
646 | new (Buffer + sizeof(Header)) T(A...); |
647 | if (Header.IsConditional) |
648 | new (Buffer + sizeof(Header) + sizeof(T)) Address(ActiveFlag); |
649 | } |
650 | |
651 | |
652 | |
653 | void initFullExprCleanup() { |
654 | initFullExprCleanupWithFlag(createCleanupActiveFlag()); |
655 | } |
656 | |
657 | void initFullExprCleanupWithFlag(Address ActiveFlag); |
658 | Address createCleanupActiveFlag(); |
659 | |
660 | |
661 | |
662 | |
663 | |
664 | void PushDestructorCleanup(QualType T, Address Addr); |
665 | |
666 | |
667 | |
668 | |
669 | void PushDestructorCleanup(const CXXDestructorDecl *Dtor, Address Addr); |
670 | |
671 | |
672 | |
673 | void PopCleanupBlock(bool FallThroughIsBranchThrough = false); |
674 | |
675 | |
676 | |
677 | |
678 | |
679 | |
680 | |
681 | |
682 | |
683 | void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, |
684 | llvm::Instruction *DominatingIP); |
685 | |
686 | |
687 | |
688 | |
689 | |
690 | |
691 | |
692 | |
693 | void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, |
694 | llvm::Instruction *DominatingIP); |
695 | |
696 | |
697 | |
698 | class RunCleanupsScope { |
699 | EHScopeStack::stable_iterator CleanupStackDepth, OldCleanupScopeDepth; |
700 | size_t LifetimeExtendedCleanupStackSize; |
701 | bool OldDidCallStackSave; |
702 | protected: |
703 | bool PerformCleanup; |
704 | private: |
705 | |
706 | RunCleanupsScope(const RunCleanupsScope &) = delete; |
707 | void operator=(const RunCleanupsScope &) = delete; |
708 | |
709 | protected: |
710 | CodeGenFunction& CGF; |
711 | |
712 | public: |
713 | |
714 | explicit RunCleanupsScope(CodeGenFunction &CGF) |
715 | : PerformCleanup(true), CGF(CGF) |
716 | { |
717 | CleanupStackDepth = CGF.EHStack.stable_begin(); |
718 | LifetimeExtendedCleanupStackSize = |
719 | CGF.LifetimeExtendedCleanupStack.size(); |
720 | OldDidCallStackSave = CGF.DidCallStackSave; |
721 | CGF.DidCallStackSave = false; |
722 | OldCleanupScopeDepth = CGF.CurrentCleanupScopeDepth; |
723 | CGF.CurrentCleanupScopeDepth = CleanupStackDepth; |
724 | } |
725 | |
726 | |
727 | ~RunCleanupsScope() { |
728 | if (PerformCleanup) |
729 | ForceCleanup(); |
730 | } |
731 | |
732 | |
733 | bool requiresCleanups() const { |
734 | return CGF.EHStack.stable_begin() != CleanupStackDepth; |
735 | } |
736 | |
737 | |
738 | |
739 | |
740 | |
741 | |
742 | |
743 | void ForceCleanup(std::initializer_list<llvm::Value**> ValuesToReload = {}) { |
744 | (0) . __assert_fail ("PerformCleanup && \"Already forced cleanup\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 744, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PerformCleanup && "Already forced cleanup"); |
745 | CGF.DidCallStackSave = OldDidCallStackSave; |
746 | CGF.PopCleanupBlocks(CleanupStackDepth, LifetimeExtendedCleanupStackSize, |
747 | ValuesToReload); |
748 | PerformCleanup = false; |
749 | CGF.CurrentCleanupScopeDepth = OldCleanupScopeDepth; |
750 | } |
751 | }; |
752 | |
753 | |
754 | EHScopeStack::stable_iterator CurrentCleanupScopeDepth = |
755 | EHScopeStack::stable_end(); |
756 | |
757 | class LexicalScope : public RunCleanupsScope { |
758 | SourceRange Range; |
759 | SmallVector<const LabelDecl*, 4> Labels; |
760 | LexicalScope *ParentScope; |
761 | |
762 | LexicalScope(const LexicalScope &) = delete; |
763 | void operator=(const LexicalScope &) = delete; |
764 | |
765 | public: |
766 | |
767 | explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range) |
768 | : RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) { |
769 | CGF.CurLexicalScope = this; |
770 | if (CGDebugInfo *DI = CGF.getDebugInfo()) |
771 | DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin()); |
772 | } |
773 | |
774 | void addLabel(const LabelDecl *label) { |
775 | (0) . __assert_fail ("PerformCleanup && \"adding label to dead scope?\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 775, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PerformCleanup && "adding label to dead scope?"); |
776 | Labels.push_back(label); |
777 | } |
778 | |
779 | |
780 | |
781 | ~LexicalScope() { |
782 | if (CGDebugInfo *DI = CGF.getDebugInfo()) |
783 | DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd()); |
784 | |
785 | |
786 | |
787 | if (PerformCleanup) { |
788 | ApplyDebugLocation DL(CGF, Range.getEnd()); |
789 | ForceCleanup(); |
790 | } |
791 | } |
792 | |
793 | |
794 | |
795 | void ForceCleanup() { |
796 | CGF.CurLexicalScope = ParentScope; |
797 | RunCleanupsScope::ForceCleanup(); |
798 | |
799 | if (!Labels.empty()) |
800 | rescopeLabels(); |
801 | } |
802 | |
803 | bool hasLabels() const { |
804 | return !Labels.empty(); |
805 | } |
806 | |
807 | void rescopeLabels(); |
808 | }; |
809 | |
810 | typedef llvm::DenseMap<const Decl *, Address> DeclMapTy; |
811 | |
812 | |
813 | class OMPMapVars { |
814 | DeclMapTy SavedLocals; |
815 | DeclMapTy SavedTempAddresses; |
816 | OMPMapVars(const OMPMapVars &) = delete; |
817 | void operator=(const OMPMapVars &) = delete; |
818 | |
819 | public: |
820 | explicit OMPMapVars() = default; |
821 | ~OMPMapVars() { |
822 | (0) . __assert_fail ("SavedLocals.empty() && \"Did not restored original addresses.\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 822, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(SavedLocals.empty() && "Did not restored original addresses."); |
823 | }; |
824 | |
825 | |
826 | |
827 | |
828 | bool setVarAddr(CodeGenFunction &CGF, const VarDecl *LocalVD, |
829 | Address TempAddr) { |
830 | LocalVD = LocalVD->getCanonicalDecl(); |
831 | |
832 | if (SavedLocals.count(LocalVD)) return false; |
833 | |
834 | |
835 | auto it = CGF.LocalDeclMap.find(LocalVD); |
836 | if (it != CGF.LocalDeclMap.end()) |
837 | SavedLocals.try_emplace(LocalVD, it->second); |
838 | else |
839 | SavedLocals.try_emplace(LocalVD, Address::invalid()); |
840 | |
841 | |
842 | QualType VarTy = LocalVD->getType(); |
843 | if (VarTy->isReferenceType()) { |
844 | Address Temp = CGF.CreateMemTemp(VarTy); |
845 | CGF.Builder.CreateStore(TempAddr.getPointer(), Temp); |
846 | TempAddr = Temp; |
847 | } |
848 | SavedTempAddresses.try_emplace(LocalVD, TempAddr); |
849 | |
850 | return true; |
851 | } |
852 | |
853 | |
854 | |
855 | |
856 | bool apply(CodeGenFunction &CGF) { |
857 | copyInto(SavedTempAddresses, CGF.LocalDeclMap); |
858 | SavedTempAddresses.clear(); |
859 | return !SavedLocals.empty(); |
860 | } |
861 | |
862 | |
863 | void restore(CodeGenFunction &CGF) { |
864 | if (!SavedLocals.empty()) { |
865 | copyInto(SavedLocals, CGF.LocalDeclMap); |
866 | SavedLocals.clear(); |
867 | } |
868 | } |
869 | |
870 | private: |
871 | |
872 | |
873 | static void copyInto(const DeclMapTy &Src, DeclMapTy &Dest) { |
874 | for (auto &Pair : Src) { |
875 | if (!Pair.second.isValid()) { |
876 | Dest.erase(Pair.first); |
877 | continue; |
878 | } |
879 | |
880 | auto I = Dest.find(Pair.first); |
881 | if (I != Dest.end()) |
882 | I->second = Pair.second; |
883 | else |
884 | Dest.insert(Pair); |
885 | } |
886 | } |
887 | }; |
888 | |
889 | |
890 | |
891 | |
892 | class OMPPrivateScope : public RunCleanupsScope { |
893 | OMPMapVars MappedVars; |
894 | OMPPrivateScope(const OMPPrivateScope &) = delete; |
895 | void operator=(const OMPPrivateScope &) = delete; |
896 | |
897 | public: |
898 | |
899 | explicit OMPPrivateScope(CodeGenFunction &CGF) : RunCleanupsScope(CGF) {} |
900 | |
901 | |
902 | |
903 | |
904 | |
905 | |
906 | bool addPrivate(const VarDecl *LocalVD, |
907 | const llvm::function_ref<Address()> PrivateGen) { |
908 | (0) . __assert_fail ("PerformCleanup && \"adding private to dead scope\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 908, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PerformCleanup && "adding private to dead scope"); |
909 | return MappedVars.setVarAddr(CGF, LocalVD, PrivateGen()); |
910 | } |
911 | |
912 | |
913 | |
914 | |
915 | |
916 | |
917 | |
918 | |
919 | |
920 | bool Privatize() { return MappedVars.apply(CGF); } |
921 | |
922 | void ForceCleanup() { |
923 | RunCleanupsScope::ForceCleanup(); |
924 | MappedVars.restore(CGF); |
925 | } |
926 | |
927 | |
928 | ~OMPPrivateScope() { |
929 | if (PerformCleanup) |
930 | ForceCleanup(); |
931 | } |
932 | |
933 | |
934 | bool isGlobalVarCaptured(const VarDecl *VD) const { |
935 | VD = VD->getCanonicalDecl(); |
936 | return !VD->isLocalVarDeclOrParm() && CGF.LocalDeclMap.count(VD) > 0; |
937 | } |
938 | }; |
939 | |
940 | |
941 | |
942 | void |
943 | PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, |
944 | std::initializer_list<llvm::Value **> ValuesToReload = {}); |
945 | |
946 | |
947 | |
948 | |
949 | void |
950 | PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, |
951 | size_t OldLifetimeExtendedStackSize, |
952 | std::initializer_list<llvm::Value **> ValuesToReload = {}); |
953 | |
954 | void ResolveBranchFixups(llvm::BasicBlock *Target); |
955 | |
956 | |
957 | |
958 | |
959 | JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { |
960 | return JumpDest(Target, |
961 | EHStack.getInnermostNormalCleanup(), |
962 | NextCleanupDestIndex++); |
963 | } |
964 | |
965 | |
966 | |
967 | |
968 | JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) { |
969 | return getJumpDestInCurrentScope(createBasicBlock(Name)); |
970 | } |
971 | |
972 | |
973 | |
974 | |
975 | void EmitBranchThroughCleanup(JumpDest Dest); |
976 | |
977 | |
978 | |
979 | |
980 | bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const; |
981 | |
982 | |
983 | |
984 | |
985 | void popCatchScope(); |
986 | |
987 | llvm::BasicBlock *getEHResumeBlock(bool isCleanup); |
988 | llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope); |
989 | llvm::BasicBlock * |
990 | getFuncletEHDispatchBlock(EHScopeStack::stable_iterator scope); |
991 | |
992 | |
993 | class ConditionalEvaluation { |
994 | llvm::BasicBlock *StartBB; |
995 | |
996 | public: |
997 | ConditionalEvaluation(CodeGenFunction &CGF) |
998 | : StartBB(CGF.Builder.GetInsertBlock()) {} |
999 | |
1000 | void begin(CodeGenFunction &CGF) { |
1001 | assert(CGF.OutermostConditional != this); |
1002 | if (!CGF.OutermostConditional) |
1003 | CGF.OutermostConditional = this; |
1004 | } |
1005 | |
1006 | void end(CodeGenFunction &CGF) { |
1007 | assert(CGF.OutermostConditional != nullptr); |
1008 | if (CGF.OutermostConditional == this) |
1009 | CGF.OutermostConditional = nullptr; |
1010 | } |
1011 | |
1012 | |
1013 | |
1014 | llvm::BasicBlock *getStartingBlock() const { |
1015 | return StartBB; |
1016 | } |
1017 | }; |
1018 | |
1019 | |
1020 | |
1021 | bool isInConditionalBranch() const { return OutermostConditional != nullptr; } |
1022 | |
1023 | void setBeforeOutermostConditional(llvm::Value *value, Address addr) { |
1024 | assert(isInConditionalBranch()); |
1025 | llvm::BasicBlock *block = OutermostConditional->getStartingBlock(); |
1026 | auto store = new llvm::StoreInst(value, addr.getPointer(), &block->back()); |
1027 | store->setAlignment(addr.getAlignment().getQuantity()); |
1028 | } |
1029 | |
1030 | |
1031 | |
1032 | class StmtExprEvaluation { |
1033 | CodeGenFunction &CGF; |
1034 | |
1035 | |
1036 | |
1037 | |
1038 | ConditionalEvaluation *SavedOutermostConditional; |
1039 | |
1040 | public: |
1041 | StmtExprEvaluation(CodeGenFunction &CGF) |
1042 | : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) { |
1043 | CGF.OutermostConditional = nullptr; |
1044 | } |
1045 | |
1046 | ~StmtExprEvaluation() { |
1047 | CGF.OutermostConditional = SavedOutermostConditional; |
1048 | CGF.EnsureInsertPoint(); |
1049 | } |
1050 | }; |
1051 | |
1052 | |
1053 | |
1054 | |
1055 | class PeepholeProtection { |
1056 | llvm::Instruction *Inst; |
1057 | friend class CodeGenFunction; |
1058 | |
1059 | public: |
1060 | PeepholeProtection() : Inst(nullptr) {} |
1061 | }; |
1062 | |
1063 | |
1064 | |
1065 | |
1066 | |
1067 | |
1068 | |
1069 | class OpaqueValueMappingData { |
1070 | const OpaqueValueExpr *OpaqueValue; |
1071 | bool BoundLValue; |
1072 | CodeGenFunction::PeepholeProtection Protection; |
1073 | |
1074 | OpaqueValueMappingData(const OpaqueValueExpr *ov, |
1075 | bool boundLValue) |
1076 | : OpaqueValue(ov), BoundLValue(boundLValue) {} |
1077 | public: |
1078 | OpaqueValueMappingData() : OpaqueValue(nullptr) {} |
1079 | |
1080 | static bool shouldBindAsLValue(const Expr *expr) { |
1081 | |
1082 | |
1083 | |
1084 | |
1085 | |
1086 | return expr->isGLValue() || |
1087 | expr->getType()->isFunctionType() || |
1088 | hasAggregateEvaluationKind(expr->getType()); |
1089 | } |
1090 | |
1091 | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
1092 | const OpaqueValueExpr *ov, |
1093 | const Expr *e) { |
1094 | if (shouldBindAsLValue(ov)) |
1095 | return bind(CGF, ov, CGF.EmitLValue(e)); |
1096 | return bind(CGF, ov, CGF.EmitAnyExpr(e)); |
1097 | } |
1098 | |
1099 | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
1100 | const OpaqueValueExpr *ov, |
1101 | const LValue &lv) { |
1102 | assert(shouldBindAsLValue(ov)); |
1103 | CGF.OpaqueLValues.insert(std::make_pair(ov, lv)); |
1104 | return OpaqueValueMappingData(ov, true); |
1105 | } |
1106 | |
1107 | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
1108 | const OpaqueValueExpr *ov, |
1109 | const RValue &rv) { |
1110 | assert(!shouldBindAsLValue(ov)); |
1111 | CGF.OpaqueRValues.insert(std::make_pair(ov, rv)); |
1112 | |
1113 | OpaqueValueMappingData data(ov, false); |
1114 | |
1115 | |
1116 | |
1117 | |
1118 | data.Protection = CGF.protectFromPeepholes(rv); |
1119 | |
1120 | return data; |
1121 | } |
1122 | |
1123 | bool isValid() const { return OpaqueValue != nullptr; } |
1124 | void clear() { OpaqueValue = nullptr; } |
1125 | |
1126 | void unbind(CodeGenFunction &CGF) { |
1127 | (0) . __assert_fail ("OpaqueValue && \"no data to unbind!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 1127, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(OpaqueValue && "no data to unbind!"); |
1128 | |
1129 | if (BoundLValue) { |
1130 | CGF.OpaqueLValues.erase(OpaqueValue); |
1131 | } else { |
1132 | CGF.OpaqueRValues.erase(OpaqueValue); |
1133 | CGF.unprotectFromPeepholes(Protection); |
1134 | } |
1135 | } |
1136 | }; |
1137 | |
1138 | |
1139 | class OpaqueValueMapping { |
1140 | CodeGenFunction &CGF; |
1141 | OpaqueValueMappingData Data; |
1142 | |
1143 | public: |
1144 | static bool shouldBindAsLValue(const Expr *expr) { |
1145 | return OpaqueValueMappingData::shouldBindAsLValue(expr); |
1146 | } |
1147 | |
1148 | |
1149 | |
1150 | |
1151 | |
1152 | |
1153 | OpaqueValueMapping(CodeGenFunction &CGF, |
1154 | const AbstractConditionalOperator *op) : CGF(CGF) { |
1155 | if (isa<ConditionalOperator>(op)) |
1156 | |
1157 | return; |
1158 | |
1159 | const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op); |
1160 | Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(), |
1161 | e->getCommon()); |
1162 | } |
1163 | |
1164 | |
1165 | |
1166 | OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *OV) |
1167 | : CGF(CGF) { |
1168 | if (OV) { |
1169 | (0) . __assert_fail ("OV->getSourceExpr() && \"wrong form of OpaqueValueMapping used \" \"for OVE with no source expression\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 1170, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(OV->getSourceExpr() && "wrong form of OpaqueValueMapping used " |
1170 | (0) . __assert_fail ("OV->getSourceExpr() && \"wrong form of OpaqueValueMapping used \" \"for OVE with no source expression\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 1170, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "for OVE with no source expression"); |
1171 | Data = OpaqueValueMappingData::bind(CGF, OV, OV->getSourceExpr()); |
1172 | } |
1173 | } |
1174 | |
1175 | OpaqueValueMapping(CodeGenFunction &CGF, |
1176 | const OpaqueValueExpr *opaqueValue, |
1177 | LValue lvalue) |
1178 | : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) { |
1179 | } |
1180 | |
1181 | OpaqueValueMapping(CodeGenFunction &CGF, |
1182 | const OpaqueValueExpr *opaqueValue, |
1183 | RValue rvalue) |
1184 | : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) { |
1185 | } |
1186 | |
1187 | void pop() { |
1188 | Data.unbind(CGF); |
1189 | Data.clear(); |
1190 | } |
1191 | |
1192 | ~OpaqueValueMapping() { |
1193 | if (Data.isValid()) Data.unbind(CGF); |
1194 | } |
1195 | }; |
1196 | |
1197 | private: |
1198 | CGDebugInfo *DebugInfo; |
1199 | |
1200 | unsigned VLAExprCounter = 0; |
1201 | bool DisableDebugInfo = false; |
1202 | |
1203 | |
1204 | |
1205 | bool DidCallStackSave = false; |
1206 | |
1207 | |
1208 | |
1209 | |
1210 | |
1211 | llvm::IndirectBrInst *IndirectBranch = nullptr; |
1212 | |
1213 | |
1214 | |
1215 | DeclMapTy LocalDeclMap; |
1216 | |
1217 | |
1218 | |
1219 | llvm::DenseMap<const ParmVarDecl *, EHScopeStack::stable_iterator> |
1220 | CalleeDestructedParamCleanups; |
1221 | |
1222 | |
1223 | |
1224 | |
1225 | llvm::SmallDenseMap<const ParmVarDecl *, const ImplicitParamDecl *, 2> |
1226 | SizeArguments; |
1227 | |
1228 | |
1229 | |
1230 | llvm::DenseMap<llvm::AllocaInst *, int> EscapedLocals; |
1231 | |
1232 | |
1233 | llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap; |
1234 | |
1235 | |
1236 | |
1237 | struct BreakContinue { |
1238 | BreakContinue(JumpDest Break, JumpDest Continue) |
1239 | : BreakBlock(Break), ContinueBlock(Continue) {} |
1240 | |
1241 | JumpDest BreakBlock; |
1242 | JumpDest ContinueBlock; |
1243 | }; |
1244 | SmallVector<BreakContinue, 8> BreakContinueStack; |
1245 | |
1246 | |
1247 | class OpenMPCancelExitStack { |
1248 | |
1249 | |
1250 | struct CancelExit { |
1251 | CancelExit() = default; |
1252 | CancelExit(OpenMPDirectiveKind Kind, JumpDest ExitBlock, |
1253 | JumpDest ContBlock) |
1254 | : Kind(Kind), ExitBlock(ExitBlock), ContBlock(ContBlock) {} |
1255 | OpenMPDirectiveKind Kind = OMPD_unknown; |
1256 | |
1257 | |
1258 | bool HasBeenEmitted = false; |
1259 | JumpDest ExitBlock; |
1260 | JumpDest ContBlock; |
1261 | }; |
1262 | |
1263 | SmallVector<CancelExit, 8> Stack; |
1264 | |
1265 | public: |
1266 | OpenMPCancelExitStack() : Stack(1) {} |
1267 | ~OpenMPCancelExitStack() = default; |
1268 | |
1269 | JumpDest getExitBlock() const { return Stack.back().ExitBlock; } |
1270 | |
1271 | |
1272 | void emitExit(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, |
1273 | const llvm::function_ref<void(CodeGenFunction &)> CodeGen) { |
1274 | if (Stack.back().Kind == Kind && getExitBlock().isValid()) { |
1275 | assert(CGF.getOMPCancelDestination(Kind).isValid()); |
1276 | assert(CGF.HaveInsertPoint()); |
1277 | assert(!Stack.back().HasBeenEmitted); |
1278 | auto IP = CGF.Builder.saveAndClearIP(); |
1279 | CGF.EmitBlock(Stack.back().ExitBlock.getBlock()); |
1280 | CodeGen(CGF); |
1281 | CGF.EmitBranch(Stack.back().ContBlock.getBlock()); |
1282 | CGF.Builder.restoreIP(IP); |
1283 | Stack.back().HasBeenEmitted = true; |
1284 | } |
1285 | CodeGen(CGF); |
1286 | } |
1287 | |
1288 | |
1289 | |
1290 | |
1291 | void enter(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, bool HasCancel) { |
1292 | Stack.push_back({Kind, |
1293 | HasCancel ? CGF.getJumpDestInCurrentScope("cancel.exit") |
1294 | : JumpDest(), |
1295 | HasCancel ? CGF.getJumpDestInCurrentScope("cancel.cont") |
1296 | : JumpDest()}); |
1297 | } |
1298 | |
1299 | |
1300 | void exit(CodeGenFunction &CGF) { |
1301 | if (getExitBlock().isValid()) { |
1302 | assert(CGF.getOMPCancelDestination(Stack.back().Kind).isValid()); |
1303 | bool HaveIP = CGF.HaveInsertPoint(); |
1304 | if (!Stack.back().HasBeenEmitted) { |
1305 | if (HaveIP) |
1306 | CGF.EmitBranchThroughCleanup(Stack.back().ContBlock); |
1307 | CGF.EmitBlock(Stack.back().ExitBlock.getBlock()); |
1308 | CGF.EmitBranchThroughCleanup(Stack.back().ContBlock); |
1309 | } |
1310 | CGF.EmitBlock(Stack.back().ContBlock.getBlock()); |
1311 | if (!HaveIP) { |
1312 | CGF.Builder.CreateUnreachable(); |
1313 | CGF.Builder.ClearInsertionPoint(); |
1314 | } |
1315 | } |
1316 | Stack.pop_back(); |
1317 | } |
1318 | }; |
1319 | OpenMPCancelExitStack OMPCancelStack; |
1320 | |
1321 | CodeGenPGO PGO; |
1322 | |
1323 | |
1324 | llvm::MDNode *createProfileWeights(uint64_t TrueCount, uint64_t FalseCount); |
1325 | llvm::MDNode *createProfileWeights(ArrayRef<uint64_t> Weights); |
1326 | llvm::MDNode *createProfileWeightsForLoop(const Stmt *Cond, |
1327 | uint64_t LoopCount); |
1328 | |
1329 | public: |
1330 | |
1331 | |
1332 | void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { |
1333 | if (CGM.getCodeGenOpts().hasProfileClangInstr()) |
1334 | PGO.emitCounterIncrement(Builder, S, StepV); |
1335 | PGO.setCurrentStmt(S); |
1336 | } |
1337 | |
1338 | |
1339 | uint64_t getProfileCount(const Stmt *S) { |
1340 | Optional<uint64_t> Count = PGO.getStmtCount(S); |
1341 | if (!Count.hasValue()) |
1342 | return 0; |
1343 | return *Count; |
1344 | } |
1345 | |
1346 | |
1347 | void setCurrentProfileCount(uint64_t Count) { |
1348 | PGO.setCurrentRegionCount(Count); |
1349 | } |
1350 | |
1351 | |
1352 | |
1353 | uint64_t getCurrentProfileCount() { |
1354 | return PGO.getCurrentRegionCount(); |
1355 | } |
1356 | |
1357 | private: |
1358 | |
1359 | |
1360 | |
1361 | llvm::SwitchInst *SwitchInsn = nullptr; |
1362 | |
1363 | SmallVector<uint64_t, 16> *SwitchWeights = nullptr; |
1364 | |
1365 | |
1366 | |
1367 | llvm::BasicBlock *CaseRangeBlock = nullptr; |
1368 | |
1369 | |
1370 | |
1371 | llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues; |
1372 | llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues; |
1373 | |
1374 | |
1375 | |
1376 | |
1377 | |
1378 | |
1379 | |
1380 | llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; |
1381 | |
1382 | |
1383 | |
1384 | llvm::BasicBlock *UnreachableBlock = nullptr; |
1385 | |
1386 | |
1387 | unsigned NumReturnExprs = 0; |
1388 | |
1389 | |
1390 | unsigned NumSimpleReturnExprs = 0; |
1391 | |
1392 | |
1393 | SourceLocation LastStopPoint; |
1394 | |
1395 | public: |
1396 | |
1397 | |
1398 | |
1399 | class FieldConstructionScope { |
1400 | public: |
1401 | FieldConstructionScope(CodeGenFunction &CGF, Address This) |
1402 | : CGF(CGF), OldCXXDefaultInitExprThis(CGF.CXXDefaultInitExprThis) { |
1403 | CGF.CXXDefaultInitExprThis = This; |
1404 | } |
1405 | ~FieldConstructionScope() { |
1406 | CGF.CXXDefaultInitExprThis = OldCXXDefaultInitExprThis; |
1407 | } |
1408 | |
1409 | private: |
1410 | CodeGenFunction &CGF; |
1411 | Address OldCXXDefaultInitExprThis; |
1412 | }; |
1413 | |
1414 | |
1415 | |
1416 | class CXXDefaultInitExprScope { |
1417 | public: |
1418 | CXXDefaultInitExprScope(CodeGenFunction &CGF) |
1419 | : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue), |
1420 | OldCXXThisAlignment(CGF.CXXThisAlignment) { |
1421 | CGF.CXXThisValue = CGF.CXXDefaultInitExprThis.getPointer(); |
1422 | CGF.CXXThisAlignment = CGF.CXXDefaultInitExprThis.getAlignment(); |
1423 | } |
1424 | ~CXXDefaultInitExprScope() { |
1425 | CGF.CXXThisValue = OldCXXThisValue; |
1426 | CGF.CXXThisAlignment = OldCXXThisAlignment; |
1427 | } |
1428 | |
1429 | public: |
1430 | CodeGenFunction &CGF; |
1431 | llvm::Value *OldCXXThisValue; |
1432 | CharUnits OldCXXThisAlignment; |
1433 | }; |
1434 | |
1435 | |
1436 | |
1437 | class ArrayInitLoopExprScope { |
1438 | public: |
1439 | ArrayInitLoopExprScope(CodeGenFunction &CGF, llvm::Value *Index) |
1440 | : CGF(CGF), OldArrayInitIndex(CGF.ArrayInitIndex) { |
1441 | CGF.ArrayInitIndex = Index; |
1442 | } |
1443 | ~ArrayInitLoopExprScope() { |
1444 | CGF.ArrayInitIndex = OldArrayInitIndex; |
1445 | } |
1446 | |
1447 | private: |
1448 | CodeGenFunction &CGF; |
1449 | llvm::Value *OldArrayInitIndex; |
1450 | }; |
1451 | |
1452 | class InlinedInheritingConstructorScope { |
1453 | public: |
1454 | InlinedInheritingConstructorScope(CodeGenFunction &CGF, GlobalDecl GD) |
1455 | : CGF(CGF), OldCurGD(CGF.CurGD), OldCurFuncDecl(CGF.CurFuncDecl), |
1456 | OldCurCodeDecl(CGF.CurCodeDecl), |
1457 | OldCXXABIThisDecl(CGF.CXXABIThisDecl), |
1458 | OldCXXABIThisValue(CGF.CXXABIThisValue), |
1459 | OldCXXThisValue(CGF.CXXThisValue), |
1460 | OldCXXABIThisAlignment(CGF.CXXABIThisAlignment), |
1461 | OldCXXThisAlignment(CGF.CXXThisAlignment), |
1462 | OldReturnValue(CGF.ReturnValue), OldFnRetTy(CGF.FnRetTy), |
1463 | OldCXXInheritedCtorInitExprArgs( |
1464 | std::move(CGF.CXXInheritedCtorInitExprArgs)) { |
1465 | CGF.CurGD = GD; |
1466 | CGF.CurFuncDecl = CGF.CurCodeDecl = |
1467 | cast<CXXConstructorDecl>(GD.getDecl()); |
1468 | CGF.CXXABIThisDecl = nullptr; |
1469 | CGF.CXXABIThisValue = nullptr; |
1470 | CGF.CXXThisValue = nullptr; |
1471 | CGF.CXXABIThisAlignment = CharUnits(); |
1472 | CGF.CXXThisAlignment = CharUnits(); |
1473 | CGF.ReturnValue = Address::invalid(); |
1474 | CGF.FnRetTy = QualType(); |
1475 | CGF.CXXInheritedCtorInitExprArgs.clear(); |
1476 | } |
1477 | ~InlinedInheritingConstructorScope() { |
1478 | CGF.CurGD = OldCurGD; |
1479 | CGF.CurFuncDecl = OldCurFuncDecl; |
1480 | CGF.CurCodeDecl = OldCurCodeDecl; |
1481 | CGF.CXXABIThisDecl = OldCXXABIThisDecl; |
1482 | CGF.CXXABIThisValue = OldCXXABIThisValue; |
1483 | CGF.CXXThisValue = OldCXXThisValue; |
1484 | CGF.CXXABIThisAlignment = OldCXXABIThisAlignment; |
1485 | CGF.CXXThisAlignment = OldCXXThisAlignment; |
1486 | CGF.ReturnValue = OldReturnValue; |
1487 | CGF.FnRetTy = OldFnRetTy; |
1488 | CGF.CXXInheritedCtorInitExprArgs = |
1489 | std::move(OldCXXInheritedCtorInitExprArgs); |
1490 | } |
1491 | |
1492 | private: |
1493 | CodeGenFunction &CGF; |
1494 | GlobalDecl OldCurGD; |
1495 | const Decl *OldCurFuncDecl; |
1496 | const Decl *OldCurCodeDecl; |
1497 | ImplicitParamDecl *OldCXXABIThisDecl; |
1498 | llvm::Value *OldCXXABIThisValue; |
1499 | llvm::Value *OldCXXThisValue; |
1500 | CharUnits OldCXXABIThisAlignment; |
1501 | CharUnits OldCXXThisAlignment; |
1502 | Address OldReturnValue; |
1503 | QualType OldFnRetTy; |
1504 | CallArgList OldCXXInheritedCtorInitExprArgs; |
1505 | }; |
1506 | |
1507 | private: |
1508 | |
1509 | |
1510 | ImplicitParamDecl *CXXABIThisDecl = nullptr; |
1511 | llvm::Value *CXXABIThisValue = nullptr; |
1512 | llvm::Value *CXXThisValue = nullptr; |
1513 | CharUnits CXXABIThisAlignment; |
1514 | CharUnits CXXThisAlignment; |
1515 | |
1516 | |
1517 | |
1518 | Address CXXDefaultInitExprThis = Address::invalid(); |
1519 | |
1520 | |
1521 | |
1522 | llvm::Value *ArrayInitIndex = nullptr; |
1523 | |
1524 | |
1525 | |
1526 | CallArgList CXXInheritedCtorInitExprArgs; |
1527 | |
1528 | |
1529 | |
1530 | ImplicitParamDecl *CXXStructorImplicitParamDecl = nullptr; |
1531 | llvm::Value *CXXStructorImplicitParamValue = nullptr; |
1532 | |
1533 | |
1534 | |
1535 | |
1536 | ConditionalEvaluation *OutermostConditional = nullptr; |
1537 | |
1538 | |
1539 | LexicalScope *CurLexicalScope = nullptr; |
1540 | |
1541 | |
1542 | |
1543 | SourceLocation CurEHLocation; |
1544 | |
1545 | |
1546 | |
1547 | llvm::DenseMap<const ValueDecl *, BlockByrefInfo> BlockByrefInfos; |
1548 | |
1549 | |
1550 | |
1551 | llvm::Value *RetValNullabilityPrecondition = nullptr; |
1552 | |
1553 | |
1554 | |
1555 | bool requiresReturnValueNullabilityCheck() const { |
1556 | return RetValNullabilityPrecondition; |
1557 | } |
1558 | |
1559 | |
1560 | |
1561 | Address ReturnLocation = Address::invalid(); |
1562 | |
1563 | |
1564 | bool requiresReturnValueCheck() const { |
1565 | return requiresReturnValueNullabilityCheck() || |
1566 | (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute) && |
1567 | CurCodeDecl && CurCodeDecl->getAttr<ReturnsNonNullAttr>()); |
1568 | } |
1569 | |
1570 | llvm::BasicBlock *TerminateLandingPad = nullptr; |
1571 | llvm::BasicBlock *TerminateHandler = nullptr; |
1572 | llvm::BasicBlock *TrapBB = nullptr; |
1573 | |
1574 | |
1575 | llvm::MapVector<llvm::Value *, llvm::BasicBlock *> TerminateFunclets; |
1576 | |
1577 | |
1578 | |
1579 | unsigned LargestVectorWidth = 0; |
1580 | |
1581 | |
1582 | const bool ShouldEmitLifetimeMarkers; |
1583 | |
1584 | |
1585 | |
1586 | void EmitOpenCLKernelMetadata(const FunctionDecl *FD, |
1587 | llvm::Function *Fn); |
1588 | |
1589 | public: |
1590 | CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false); |
1591 | ~CodeGenFunction(); |
1592 | |
1593 | CodeGenTypes &getTypes() const { return CGM.getTypes(); } |
1594 | ASTContext &getContext() const { return CGM.getContext(); } |
1595 | CGDebugInfo *getDebugInfo() { |
1596 | if (DisableDebugInfo) |
1597 | return nullptr; |
1598 | return DebugInfo; |
1599 | } |
1600 | void disableDebugInfo() { DisableDebugInfo = true; } |
1601 | void enableDebugInfo() { DisableDebugInfo = false; } |
1602 | |
1603 | bool shouldUseFusedARCCalls() { |
1604 | return CGM.getCodeGenOpts().OptimizationLevel == 0; |
1605 | } |
1606 | |
1607 | const LangOptions &getLangOpts() const { return CGM.getLangOpts(); } |
1608 | |
1609 | |
1610 | |
1611 | Address getExceptionSlot(); |
1612 | Address getEHSelectorSlot(); |
1613 | |
1614 | |
1615 | |
1616 | llvm::Value *getExceptionFromSlot(); |
1617 | llvm::Value *getSelectorFromSlot(); |
1618 | |
1619 | Address getNormalCleanupDestSlot(); |
1620 | |
1621 | llvm::BasicBlock *getUnreachableBlock() { |
1622 | if (!UnreachableBlock) { |
1623 | UnreachableBlock = createBasicBlock("unreachable"); |
1624 | new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock); |
1625 | } |
1626 | return UnreachableBlock; |
1627 | } |
1628 | |
1629 | llvm::BasicBlock *getInvokeDest() { |
1630 | if (!EHStack.requiresLandingPad()) return nullptr; |
1631 | return getInvokeDestImpl(); |
1632 | } |
1633 | |
1634 | bool currentFunctionUsesSEHTry() const { return CurSEHParent != nullptr; } |
1635 | |
1636 | const TargetInfo &getTarget() const { return Target; } |
1637 | llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); } |
1638 | const TargetCodeGenInfo &getTargetHooks() const { |
1639 | return CGM.getTargetCodeGenInfo(); |
1640 | } |
1641 | |
1642 | |
1643 | |
1644 | |
1645 | |
1646 | typedef void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty); |
1647 | |
1648 | void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, |
1649 | Address arrayEndPointer, |
1650 | QualType elementType, |
1651 | CharUnits elementAlignment, |
1652 | Destroyer *destroyer); |
1653 | void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, |
1654 | llvm::Value *arrayEnd, |
1655 | QualType elementType, |
1656 | CharUnits elementAlignment, |
1657 | Destroyer *destroyer); |
1658 | |
1659 | void pushDestroy(QualType::DestructionKind dtorKind, |
1660 | Address addr, QualType type); |
1661 | void pushEHDestroy(QualType::DestructionKind dtorKind, |
1662 | Address addr, QualType type); |
1663 | void pushDestroy(CleanupKind kind, Address addr, QualType type, |
1664 | Destroyer *destroyer, bool useEHCleanupForArray); |
1665 | void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, |
1666 | QualType type, Destroyer *destroyer, |
1667 | bool useEHCleanupForArray); |
1668 | void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, |
1669 | llvm::Value *CompletePtr, |
1670 | QualType ElementType); |
1671 | void pushStackRestore(CleanupKind kind, Address SPMem); |
1672 | void emitDestroy(Address addr, QualType type, Destroyer *destroyer, |
1673 | bool useEHCleanupForArray); |
1674 | llvm::Function *generateDestroyHelper(Address addr, QualType type, |
1675 | Destroyer *destroyer, |
1676 | bool useEHCleanupForArray, |
1677 | const VarDecl *VD); |
1678 | void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, |
1679 | QualType elementType, CharUnits elementAlign, |
1680 | Destroyer *destroyer, |
1681 | bool checkZeroLength, bool useEHCleanup); |
1682 | |
1683 | Destroyer *getDestroyer(QualType::DestructionKind destructionKind); |
1684 | |
1685 | |
1686 | |
1687 | bool needsEHCleanup(QualType::DestructionKind kind) { |
1688 | switch (kind) { |
1689 | case QualType::DK_none: |
1690 | return false; |
1691 | case QualType::DK_cxx_destructor: |
1692 | case QualType::DK_objc_weak_lifetime: |
1693 | case QualType::DK_nontrivial_c_struct: |
1694 | return getLangOpts().Exceptions; |
1695 | case QualType::DK_objc_strong_lifetime: |
1696 | return getLangOpts().Exceptions && |
1697 | CGM.getCodeGenOpts().ObjCAutoRefCountExceptions; |
1698 | } |
1699 | llvm_unreachable("bad destruction kind"); |
1700 | } |
1701 | |
1702 | CleanupKind getCleanupKind(QualType::DestructionKind kind) { |
1703 | return (needsEHCleanup(kind) ? NormalAndEHCleanup : NormalCleanup); |
1704 | } |
1705 | |
1706 | |
1707 | |
1708 | |
1709 | |
1710 | void GenerateObjCMethod(const ObjCMethodDecl *OMD); |
1711 | |
1712 | void StartObjCMethod(const ObjCMethodDecl *MD, const ObjCContainerDecl *CD); |
1713 | |
1714 | |
1715 | void GenerateObjCGetter(ObjCImplementationDecl *IMP, |
1716 | const ObjCPropertyImplDecl *PID); |
1717 | void generateObjCGetterBody(const ObjCImplementationDecl *classImpl, |
1718 | const ObjCPropertyImplDecl *propImpl, |
1719 | const ObjCMethodDecl *GetterMothodDecl, |
1720 | llvm::Constant *AtomicHelperFn); |
1721 | |
1722 | void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, |
1723 | ObjCMethodDecl *MD, bool ctor); |
1724 | |
1725 | |
1726 | |
1727 | void GenerateObjCSetter(ObjCImplementationDecl *IMP, |
1728 | const ObjCPropertyImplDecl *PID); |
1729 | void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, |
1730 | const ObjCPropertyImplDecl *propImpl, |
1731 | llvm::Constant *AtomicHelperFn); |
1732 | |
1733 | |
1734 | |
1735 | |
1736 | |
1737 | |
1738 | |
1739 | |
1740 | |
1741 | llvm::Value *EmitBlockLiteral(const BlockExpr *); |
1742 | static void destroyBlockInfos(CGBlockInfo *info); |
1743 | |
1744 | llvm::Function *GenerateBlockFunction(GlobalDecl GD, |
1745 | const CGBlockInfo &Info, |
1746 | const DeclMapTy &ldm, |
1747 | bool IsLambdaConversionToBlock, |
1748 | bool BuildGlobalBlock); |
1749 | |
1750 | |
1751 | static bool cxxDestructorCanThrow(QualType T); |
1752 | |
1753 | llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo); |
1754 | llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo); |
1755 | llvm::Constant *GenerateObjCAtomicSetterCopyHelperFunction( |
1756 | const ObjCPropertyImplDecl *PID); |
1757 | llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction( |
1758 | const ObjCPropertyImplDecl *PID); |
1759 | llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty); |
1760 | |
1761 | void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags, |
1762 | bool CanThrow); |
1763 | |
1764 | class AutoVarEmission; |
1765 | |
1766 | void emitByrefStructureInit(const AutoVarEmission &emission); |
1767 | |
1768 | |
1769 | |
1770 | |
1771 | |
1772 | |
1773 | |
1774 | |
1775 | |
1776 | |
1777 | |
1778 | |
1779 | |
1780 | |
1781 | |
1782 | |
1783 | |
1784 | void enterByrefCleanup(CleanupKind Kind, Address Addr, BlockFieldFlags Flags, |
1785 | bool LoadBlockVarAddr, bool CanThrow); |
1786 | |
1787 | void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, |
1788 | llvm::Value *ptr); |
1789 | |
1790 | Address LoadBlockStruct(); |
1791 | Address GetAddrOfBlockDecl(const VarDecl *var); |
1792 | |
1793 | |
1794 | |
1795 | Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, |
1796 | bool followForward = true); |
1797 | Address emitBlockByrefAddress(Address baseAddr, |
1798 | const BlockByrefInfo &info, |
1799 | bool followForward, |
1800 | const llvm::Twine &name); |
1801 | |
1802 | const BlockByrefInfo &getBlockByrefInfo(const VarDecl *var); |
1803 | |
1804 | QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args); |
1805 | |
1806 | void GenerateCode(GlobalDecl GD, llvm::Function *Fn, |
1807 | const CGFunctionInfo &FnInfo); |
1808 | |
1809 | |
1810 | |
1811 | void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn); |
1812 | |
1813 | |
1814 | |
1815 | |
1816 | void StartFunction(GlobalDecl GD, |
1817 | QualType RetTy, |
1818 | llvm::Function *Fn, |
1819 | const CGFunctionInfo &FnInfo, |
1820 | const FunctionArgList &Args, |
1821 | SourceLocation Loc = SourceLocation(), |
1822 | SourceLocation StartLoc = SourceLocation()); |
1823 | |
1824 | static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor); |
1825 | |
1826 | void EmitConstructorBody(FunctionArgList &Args); |
1827 | void EmitDestructorBody(FunctionArgList &Args); |
1828 | void emitImplicitAssignmentOperatorBody(FunctionArgList &Args); |
1829 | void EmitFunctionBody(const Stmt *Body); |
1830 | void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S); |
1831 | |
1832 | void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator, |
1833 | CallArgList &CallArgs); |
1834 | void EmitLambdaBlockInvokeBody(); |
1835 | void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD); |
1836 | void EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD); |
1837 | void EmitLambdaVLACapture(const VariableArrayType *VAT, LValue LV) { |
1838 | EmitStoreThroughLValue(RValue::get(VLASizeMap[VAT->getSizeExpr()]), LV); |
1839 | } |
1840 | void EmitAsanPrologueOrEpilogue(bool Prologue); |
1841 | |
1842 | |
1843 | |
1844 | |
1845 | |
1846 | llvm::DebugLoc EmitReturnBlock(); |
1847 | |
1848 | |
1849 | |
1850 | void FinishFunction(SourceLocation EndLoc=SourceLocation()); |
1851 | |
1852 | void StartThunk(llvm::Function *Fn, GlobalDecl GD, |
1853 | const CGFunctionInfo &FnInfo, bool IsUnprototyped); |
1854 | |
1855 | void EmitCallAndReturnForThunk(llvm::FunctionCallee Callee, |
1856 | const ThunkInfo *Thunk, bool IsUnprototyped); |
1857 | |
1858 | void FinishThunk(); |
1859 | |
1860 | |
1861 | void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr, |
1862 | llvm::FunctionCallee Callee); |
1863 | |
1864 | |
1865 | void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, |
1866 | GlobalDecl GD, const ThunkInfo &Thunk, |
1867 | bool IsUnprototyped); |
1868 | |
1869 | llvm::Function *GenerateVarArgsThunk(llvm::Function *Fn, |
1870 | const CGFunctionInfo &FnInfo, |
1871 | GlobalDecl GD, const ThunkInfo &Thunk); |
1872 | |
1873 | void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, |
1874 | FunctionArgList &Args); |
1875 | |
1876 | void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init); |
1877 | |
1878 | |
1879 | struct VPtr { |
1880 | BaseSubobject Base; |
1881 | const CXXRecordDecl *NearestVBase; |
1882 | CharUnits OffsetFromNearestVBase; |
1883 | const CXXRecordDecl *VTableClass; |
1884 | }; |
1885 | |
1886 | |
1887 | void InitializeVTablePointer(const VPtr &vptr); |
1888 | |
1889 | typedef llvm::SmallVector<VPtr, 4> VPtrsVector; |
1890 | |
1891 | typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy; |
1892 | VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass); |
1893 | |
1894 | void getVTablePointers(BaseSubobject Base, const CXXRecordDecl *NearestVBase, |
1895 | CharUnits OffsetFromNearestVBase, |
1896 | bool BaseIsNonVirtualPrimaryBase, |
1897 | const CXXRecordDecl *VTableClass, |
1898 | VisitedVirtualBasesSetTy &VBases, VPtrsVector &vptrs); |
1899 | |
1900 | void InitializeVTablePointers(const CXXRecordDecl *ClassDecl); |
1901 | |
1902 | |
1903 | |
1904 | llvm::Value *GetVTablePtr(Address This, llvm::Type *VTableTy, |
1905 | const CXXRecordDecl *VTableClass); |
1906 | |
1907 | enum CFITypeCheckKind { |
1908 | CFITCK_VCall, |
1909 | CFITCK_NVCall, |
1910 | CFITCK_DerivedCast, |
1911 | CFITCK_UnrelatedCast, |
1912 | CFITCK_ICall, |
1913 | CFITCK_NVMFCall, |
1914 | CFITCK_VMFCall, |
1915 | }; |
1916 | |
1917 | |
1918 | |
1919 | |
1920 | void EmitVTablePtrCheckForCast(QualType T, llvm::Value *Derived, |
1921 | bool MayBeNull, CFITypeCheckKind TCK, |
1922 | SourceLocation Loc); |
1923 | |
1924 | |
1925 | |
1926 | void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable, |
1927 | CFITypeCheckKind TCK, SourceLocation Loc); |
1928 | |
1929 | |
1930 | |
1931 | void EmitVTablePtrCheck(const CXXRecordDecl *RD, llvm::Value *VTable, |
1932 | CFITypeCheckKind TCK, SourceLocation Loc); |
1933 | |
1934 | |
1935 | |
1936 | |
1937 | void EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, |
1938 | llvm::Value *VTable, SourceLocation Loc); |
1939 | |
1940 | |
1941 | |
1942 | |
1943 | bool ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD); |
1944 | |
1945 | |
1946 | llvm::Value *EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, llvm::Value *VTable, |
1947 | uint64_t VTableByteOffset); |
1948 | |
1949 | |
1950 | |
1951 | |
1952 | |
1953 | void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type); |
1954 | |
1955 | |
1956 | |
1957 | bool ShouldInstrumentFunction(); |
1958 | |
1959 | |
1960 | |
1961 | bool ShouldXRayInstrumentFunction() const; |
1962 | |
1963 | |
1964 | |
1965 | bool AlwaysEmitXRayCustomEvents() const; |
1966 | |
1967 | |
1968 | |
1969 | bool AlwaysEmitXRayTypedEvents() const; |
1970 | |
1971 | |
1972 | llvm::Constant *EncodeAddrForUseInPrologue(llvm::Function *F, |
1973 | llvm::Constant *Addr); |
1974 | |
1975 | |
1976 | |
1977 | llvm::Value *DecodeAddrUsedInPrologue(llvm::Value *F, |
1978 | llvm::Value *EncodedAddr); |
1979 | |
1980 | |
1981 | |
1982 | |
1983 | void EmitFunctionProlog(const CGFunctionInfo &FI, |
1984 | llvm::Function *Fn, |
1985 | const FunctionArgList &Args); |
1986 | |
1987 | |
1988 | |
1989 | void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, |
1990 | SourceLocation EndLoc); |
1991 | |
1992 | |
1993 | void EmitReturnValueCheck(llvm::Value *RV); |
1994 | |
1995 | |
1996 | void EmitStartEHSpec(const Decl *D); |
1997 | |
1998 | |
1999 | void EmitEndEHSpec(const Decl *D); |
2000 | |
2001 | |
2002 | llvm::BasicBlock *getTerminateLandingPad(); |
2003 | |
2004 | |
2005 | |
2006 | llvm::BasicBlock *getTerminateFunclet(); |
2007 | |
2008 | |
2009 | |
2010 | |
2011 | llvm::BasicBlock *getTerminateHandler(); |
2012 | |
2013 | llvm::Type *ConvertTypeForMem(QualType T); |
2014 | llvm::Type *ConvertType(QualType T); |
2015 | llvm::Type *ConvertType(const TypeDecl *T) { |
2016 | return ConvertType(getContext().getTypeDeclType(T)); |
2017 | } |
2018 | |
2019 | |
2020 | |
2021 | llvm::Value *LoadObjCSelf(); |
2022 | |
2023 | |
2024 | QualType TypeOfSelfObject(); |
2025 | |
2026 | |
2027 | static TypeEvaluationKind getEvaluationKind(QualType T); |
2028 | |
2029 | static bool hasScalarEvaluationKind(QualType T) { |
2030 | return getEvaluationKind(T) == TEK_Scalar; |
2031 | } |
2032 | |
2033 | static bool hasAggregateEvaluationKind(QualType T) { |
2034 | return getEvaluationKind(T) == TEK_Aggregate; |
2035 | } |
2036 | |
2037 | |
2038 | llvm::BasicBlock *createBasicBlock(const Twine &name = "", |
2039 | llvm::Function *parent = nullptr, |
2040 | llvm::BasicBlock *before = nullptr) { |
2041 | return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before); |
2042 | } |
2043 | |
2044 | |
2045 | |
2046 | JumpDest getJumpDestForLabel(const LabelDecl *S); |
2047 | |
2048 | |
2049 | |
2050 | |
2051 | void SimplifyForwardingBlocks(llvm::BasicBlock *BB); |
2052 | |
2053 | |
2054 | |
2055 | |
2056 | |
2057 | |
2058 | |
2059 | |
2060 | |
2061 | void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); |
2062 | |
2063 | |
2064 | |
2065 | void EmitBlockAfterUses(llvm::BasicBlock *BB); |
2066 | |
2067 | |
2068 | |
2069 | |
2070 | |
2071 | |
2072 | |
2073 | |
2074 | |
2075 | void EmitBranch(llvm::BasicBlock *Block); |
2076 | |
2077 | |
2078 | |
2079 | bool HaveInsertPoint() const { |
2080 | return Builder.GetInsertBlock() != nullptr; |
2081 | } |
2082 | |
2083 | |
2084 | |
2085 | |
2086 | |
2087 | void EnsureInsertPoint() { |
2088 | if (!HaveInsertPoint()) |
2089 | EmitBlock(createBasicBlock()); |
2090 | } |
2091 | |
2092 | |
2093 | |
2094 | void ErrorUnsupported(const Stmt *S, const char *Type); |
2095 | |
2096 | |
2097 | |
2098 | |
2099 | |
2100 | LValue MakeAddrLValue(Address Addr, QualType T, |
2101 | AlignmentSource Source = AlignmentSource::Type) { |
2102 | return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source), |
2103 | CGM.getTBAAAccessInfo(T)); |
2104 | } |
2105 | |
2106 | LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo, |
2107 | TBAAAccessInfo TBAAInfo) { |
2108 | return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo); |
2109 | } |
2110 | |
2111 | LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, |
2112 | AlignmentSource Source = AlignmentSource::Type) { |
2113 | return LValue::MakeAddr(Address(V, Alignment), T, getContext(), |
2114 | LValueBaseInfo(Source), CGM.getTBAAAccessInfo(T)); |
2115 | } |
2116 | |
2117 | LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, |
2118 | LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) { |
2119 | return LValue::MakeAddr(Address(V, Alignment), T, getContext(), |
2120 | BaseInfo, TBAAInfo); |
2121 | } |
2122 | |
2123 | LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T); |
2124 | LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T); |
2125 | CharUnits getNaturalTypeAlignment(QualType T, |
2126 | LValueBaseInfo *BaseInfo = nullptr, |
2127 | TBAAAccessInfo *TBAAInfo = nullptr, |
2128 | bool forPointeeType = false); |
2129 | CharUnits getNaturalPointeeTypeAlignment(QualType T, |
2130 | LValueBaseInfo *BaseInfo = nullptr, |
2131 | TBAAAccessInfo *TBAAInfo = nullptr); |
2132 | |
2133 | Address EmitLoadOfReference(LValue RefLVal, |
2134 | LValueBaseInfo *PointeeBaseInfo = nullptr, |
2135 | TBAAAccessInfo *PointeeTBAAInfo = nullptr); |
2136 | LValue EmitLoadOfReferenceLValue(LValue RefLVal); |
2137 | LValue EmitLoadOfReferenceLValue(Address RefAddr, QualType RefTy, |
2138 | AlignmentSource Source = |
2139 | AlignmentSource::Type) { |
2140 | LValue RefLVal = MakeAddrLValue(RefAddr, RefTy, LValueBaseInfo(Source), |
2141 | CGM.getTBAAAccessInfo(RefTy)); |
2142 | return EmitLoadOfReferenceLValue(RefLVal); |
2143 | } |
2144 | |
2145 | Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, |
2146 | LValueBaseInfo *BaseInfo = nullptr, |
2147 | TBAAAccessInfo *TBAAInfo = nullptr); |
2148 | LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy); |
2149 | |
2150 | |
2151 | |
2152 | |
2153 | |
2154 | |
2155 | |
2156 | |
2157 | |
2158 | |
2159 | |
2160 | |
2161 | |
2162 | |
2163 | |
2164 | |
2165 | |
2166 | |
2167 | |
2168 | |
2169 | |
2170 | |
2171 | |
2172 | |
2173 | |
2174 | |
2175 | |
2176 | llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, const Twine &Name = "tmp", |
2177 | llvm::Value *ArraySize = nullptr); |
2178 | Address CreateTempAlloca(llvm::Type *Ty, CharUnits align, |
2179 | const Twine &Name = "tmp", |
2180 | llvm::Value *ArraySize = nullptr, |
2181 | Address *Alloca = nullptr); |
2182 | Address CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, |
2183 | const Twine &Name = "tmp", |
2184 | llvm::Value *ArraySize = nullptr); |
2185 | |
2186 | |
2187 | |
2188 | |
2189 | |
2190 | |
2191 | |
2192 | |
2193 | |
2194 | |
2195 | |
2196 | Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, |
2197 | const Twine &Name = "tmp"); |
2198 | |
2199 | |
2200 | |
2201 | |
2202 | |
2203 | |
2204 | |
2205 | |
2206 | void InitTempAlloca(Address Alloca, llvm::Value *Value); |
2207 | |
2208 | |
2209 | |
2210 | |
2211 | |
2212 | |
2213 | |
2214 | |
2215 | |
2216 | Address CreateIRTemp(QualType T, const Twine &Name = "tmp"); |
2217 | |
2218 | |
2219 | |
2220 | |
2221 | Address CreateMemTemp(QualType T, const Twine &Name = "tmp", |
2222 | Address *Alloca = nullptr); |
2223 | Address CreateMemTemp(QualType T, CharUnits Align, const Twine &Name = "tmp", |
2224 | Address *Alloca = nullptr); |
2225 | |
2226 | |
2227 | |
2228 | Address CreateMemTempWithoutCast(QualType T, const Twine &Name = "tmp"); |
2229 | Address CreateMemTempWithoutCast(QualType T, CharUnits Align, |
2230 | const Twine &Name = "tmp"); |
2231 | |
2232 | |
2233 | |
2234 | AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp") { |
2235 | return AggValueSlot::forAddr(CreateMemTemp(T, Name), |
2236 | T.getQualifiers(), |
2237 | AggValueSlot::IsNotDestructed, |
2238 | AggValueSlot::DoesNotNeedGCBarriers, |
2239 | AggValueSlot::IsNotAliased, |
2240 | AggValueSlot::DoesNotOverlap); |
2241 | } |
2242 | |
2243 | |
2244 | llvm::Value *EmitCastToVoidPtr(llvm::Value *value); |
2245 | |
2246 | |
2247 | |
2248 | llvm::Value *EvaluateExprAsBool(const Expr *E); |
2249 | |
2250 | |
2251 | void EmitIgnoredExpr(const Expr *E); |
2252 | |
2253 | |
2254 | |
2255 | |
2256 | |
2257 | |
2258 | |
2259 | RValue EmitAnyExpr(const Expr *E, |
2260 | AggValueSlot aggSlot = AggValueSlot::ignored(), |
2261 | bool ignoreResult = false); |
2262 | |
2263 | |
2264 | |
2265 | Address EmitVAListRef(const Expr *E); |
2266 | |
2267 | |
2268 | |
2269 | |
2270 | Address EmitMSVAListRef(const Expr *E); |
2271 | |
2272 | |
2273 | |
2274 | RValue EmitAnyExprToTemp(const Expr *E); |
2275 | |
2276 | |
2277 | |
2278 | void EmitAnyExprToMem(const Expr *E, Address Location, |
2279 | Qualifiers Quals, bool IsInitializer); |
2280 | |
2281 | void EmitAnyExprToExn(const Expr *E, Address Addr); |
2282 | |
2283 | |
2284 | |
2285 | void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, |
2286 | bool capturedByInit); |
2287 | |
2288 | |
2289 | |
2290 | bool hasVolatileMember(QualType T) { |
2291 | if (const RecordType *RT = T->getAs<RecordType>()) { |
2292 | const RecordDecl *RD = cast<RecordDecl>(RT->getDecl()); |
2293 | return RD->hasVolatileMember(); |
2294 | } |
2295 | return false; |
2296 | } |
2297 | |
2298 | |
2299 | AggValueSlot::Overlap_t overlapForReturnValue() { |
2300 | |
2301 | |
2302 | |
2303 | return AggValueSlot::DoesNotOverlap; |
2304 | } |
2305 | |
2306 | |
2307 | AggValueSlot::Overlap_t overlapForFieldInit(const FieldDecl *FD) { |
2308 | |
2309 | |
2310 | |
2311 | |
2312 | |
2313 | return AggValueSlot::DoesNotOverlap; |
2314 | } |
2315 | |
2316 | |
2317 | |
2318 | AggValueSlot::Overlap_t overlapForBaseInit(const CXXRecordDecl *RD, |
2319 | const CXXRecordDecl *BaseRD, |
2320 | bool IsVirtual); |
2321 | |
2322 | |
2323 | void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy) { |
2324 | bool IsVolatile = hasVolatileMember(EltTy); |
2325 | EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile); |
2326 | } |
2327 | |
2328 | void EmitAggregateCopyCtor(LValue Dest, LValue Src, |
2329 | AggValueSlot::Overlap_t MayOverlap) { |
2330 | EmitAggregateCopy(Dest, Src, Src.getType(), MayOverlap); |
2331 | } |
2332 | |
2333 | |
2334 | |
2335 | |
2336 | |
2337 | |
2338 | |
2339 | |
2340 | void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, |
2341 | AggValueSlot::Overlap_t MayOverlap, |
2342 | bool isVolatile = false); |
2343 | |
2344 | |
2345 | Address GetAddrOfLocalVar(const VarDecl *VD) { |
2346 | auto it = LocalDeclMap.find(VD); |
2347 | (0) . __assert_fail ("it != LocalDeclMap.end() && \"Invalid argument to GetAddrOfLocalVar(), no decl!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 2348, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(it != LocalDeclMap.end() && |
2348 | (0) . __assert_fail ("it != LocalDeclMap.end() && \"Invalid argument to GetAddrOfLocalVar(), no decl!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 2348, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Invalid argument to GetAddrOfLocalVar(), no decl!"); |
2349 | return it->second; |
2350 | } |
2351 | |
2352 | |
2353 | |
2354 | LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e); |
2355 | |
2356 | |
2357 | |
2358 | RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e); |
2359 | |
2360 | |
2361 | llvm::Value *getArrayInitIndex() { return ArrayInitIndex; } |
2362 | |
2363 | |
2364 | |
2365 | static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); |
2366 | |
2367 | llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L); |
2368 | llvm::BasicBlock *GetIndirectGotoBlock(); |
2369 | |
2370 | |
2371 | static bool IsWrappedCXXThis(const Expr *E); |
2372 | |
2373 | |
2374 | |
2375 | |
2376 | void EmitNullInitialization(Address DestPtr, QualType Ty); |
2377 | |
2378 | |
2379 | |
2380 | |
2381 | |
2382 | |
2383 | |
2384 | llvm::Value *EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart); |
2385 | |
2386 | |
2387 | |
2388 | |
2389 | |
2390 | |
2391 | |
2392 | |
2393 | |
2394 | Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr); |
2395 | |
2396 | |
2397 | |
2398 | llvm::Value *emitArrayLength(const ArrayType *arrayType, |
2399 | QualType &baseType, |
2400 | Address &addr); |
2401 | |
2402 | |
2403 | |
2404 | |
2405 | |
2406 | void EmitVariablyModifiedType(QualType Ty); |
2407 | |
2408 | struct VlaSizePair { |
2409 | llvm::Value *NumElts; |
2410 | QualType Type; |
2411 | |
2412 | VlaSizePair(llvm::Value *NE, QualType T) : NumElts(NE), Type(T) {} |
2413 | }; |
2414 | |
2415 | |
2416 | |
2417 | VlaSizePair getVLAElements1D(const VariableArrayType *vla); |
2418 | VlaSizePair getVLAElements1D(QualType vla); |
2419 | |
2420 | |
2421 | |
2422 | |
2423 | |
2424 | VlaSizePair getVLASize(const VariableArrayType *vla); |
2425 | VlaSizePair getVLASize(QualType vla); |
2426 | |
2427 | |
2428 | |
2429 | llvm::Value *LoadCXXThis() { |
2430 | (0) . __assert_fail ("CXXThisValue && \"no 'this' value for this function\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 2430, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CXXThisValue && "no 'this' value for this function"); |
2431 | return CXXThisValue; |
2432 | } |
2433 | Address LoadCXXThisAddress(); |
2434 | |
2435 | |
2436 | |
2437 | |
2438 | |
2439 | llvm::Value *LoadCXXVTT() { |
2440 | (0) . __assert_fail ("CXXStructorImplicitParamValue && \"no VTT value for this function\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 2440, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CXXStructorImplicitParamValue && "no VTT value for this function"); |
2441 | return CXXStructorImplicitParamValue; |
2442 | } |
2443 | |
2444 | |
2445 | |
2446 | Address |
2447 | GetAddressOfDirectBaseInCompleteClass(Address Value, |
2448 | const CXXRecordDecl *Derived, |
2449 | const CXXRecordDecl *Base, |
2450 | bool BaseIsVirtual); |
2451 | |
2452 | static bool ShouldNullCheckClassCastValue(const CastExpr *Cast); |
2453 | |
2454 | |
2455 | |
2456 | Address GetAddressOfBaseClass(Address Value, |
2457 | const CXXRecordDecl *Derived, |
2458 | CastExpr::path_const_iterator PathBegin, |
2459 | CastExpr::path_const_iterator PathEnd, |
2460 | bool NullCheckValue, SourceLocation Loc); |
2461 | |
2462 | Address GetAddressOfDerivedClass(Address Value, |
2463 | const CXXRecordDecl *Derived, |
2464 | CastExpr::path_const_iterator PathBegin, |
2465 | CastExpr::path_const_iterator PathEnd, |
2466 | bool NullCheckValue); |
2467 | |
2468 | |
2469 | |
2470 | |
2471 | |
2472 | llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, |
2473 | bool Delegating); |
2474 | |
2475 | void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, |
2476 | CXXCtorType CtorType, |
2477 | const FunctionArgList &Args, |
2478 | SourceLocation Loc); |
2479 | |
2480 | |
2481 | |
2482 | |
2483 | void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, |
2484 | const FunctionArgList &Args); |
2485 | |
2486 | |
2487 | |
2488 | |
2489 | |
2490 | void EmitInlinedInheritingCXXConstructorCall(const CXXConstructorDecl *Ctor, |
2491 | CXXCtorType CtorType, |
2492 | bool ForVirtualBase, |
2493 | bool Delegating, |
2494 | CallArgList &Args); |
2495 | |
2496 | |
2497 | |
2498 | |
2499 | void EmitInheritedCXXConstructorCall(const CXXConstructorDecl *D, |
2500 | bool ForVirtualBase, Address This, |
2501 | bool InheritedFromVBase, |
2502 | const CXXInheritedCtorInitExpr *E); |
2503 | |
2504 | void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, |
2505 | bool ForVirtualBase, bool Delegating, |
2506 | Address This, const CXXConstructExpr *E, |
2507 | AggValueSlot::Overlap_t Overlap, |
2508 | bool NewPointerIsChecked); |
2509 | |
2510 | void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, |
2511 | bool ForVirtualBase, bool Delegating, |
2512 | Address This, CallArgList &Args, |
2513 | AggValueSlot::Overlap_t Overlap, |
2514 | SourceLocation Loc, |
2515 | bool NewPointerIsChecked); |
2516 | |
2517 | |
2518 | |
2519 | void EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This); |
2520 | |
2521 | |
2522 | void EmitVTableAssumptionLoad(const VPtr &vptr, Address This); |
2523 | |
2524 | void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, |
2525 | Address This, Address Src, |
2526 | const CXXConstructExpr *E); |
2527 | |
2528 | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
2529 | const ArrayType *ArrayTy, |
2530 | Address ArrayPtr, |
2531 | const CXXConstructExpr *E, |
2532 | bool NewPointerIsChecked, |
2533 | bool ZeroInitialization = false); |
2534 | |
2535 | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
2536 | llvm::Value *NumElements, |
2537 | Address ArrayPtr, |
2538 | const CXXConstructExpr *E, |
2539 | bool NewPointerIsChecked, |
2540 | bool ZeroInitialization = false); |
2541 | |
2542 | static Destroyer destroyCXXObject; |
2543 | |
2544 | void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, |
2545 | bool ForVirtualBase, bool Delegating, |
2546 | Address This); |
2547 | |
2548 | void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, |
2549 | llvm::Type *ElementTy, Address NewPtr, |
2550 | llvm::Value *NumElements, |
2551 | llvm::Value *AllocSizeWithoutCookie); |
2552 | |
2553 | void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, |
2554 | Address Ptr); |
2555 | |
2556 | llvm::Value *EmitLifetimeStart(uint64_t Size, llvm::Value *Addr); |
2557 | void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr); |
2558 | |
2559 | llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); |
2560 | void EmitCXXDeleteExpr(const CXXDeleteExpr *E); |
2561 | |
2562 | void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, |
2563 | QualType DeleteTy, llvm::Value *NumElements = nullptr, |
2564 | CharUnits CookieSize = CharUnits()); |
2565 | |
2566 | RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, |
2567 | const CallExpr *TheCallExpr, bool IsDelete); |
2568 | |
2569 | llvm::Value *EmitCXXTypeidExpr(const CXXTypeidExpr *E); |
2570 | llvm::Value *EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE); |
2571 | Address EmitCXXUuidofExpr(const CXXUuidofExpr *E); |
2572 | |
2573 | |
2574 | |
2575 | enum TypeCheckKind { |
2576 | |
2577 | TCK_Load, |
2578 | |
2579 | TCK_Store, |
2580 | |
2581 | |
2582 | |
2583 | TCK_ReferenceBinding, |
2584 | |
2585 | |
2586 | TCK_MemberAccess, |
2587 | |
2588 | |
2589 | TCK_MemberCall, |
2590 | |
2591 | TCK_ConstructorCall, |
2592 | |
2593 | |
2594 | TCK_DowncastPointer, |
2595 | |
2596 | |
2597 | TCK_DowncastReference, |
2598 | |
2599 | |
2600 | TCK_Upcast, |
2601 | |
2602 | |
2603 | TCK_UpcastToVirtualBase, |
2604 | |
2605 | TCK_NonnullAssign, |
2606 | |
2607 | |
2608 | TCK_DynamicOperation |
2609 | }; |
2610 | |
2611 | |
2612 | static bool isNullPointerAllowed(TypeCheckKind TCK); |
2613 | |
2614 | |
2615 | static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty); |
2616 | |
2617 | |
2618 | |
2619 | bool sanitizePerformTypeCheck() const; |
2620 | |
2621 | |
2622 | |
2623 | |
2624 | void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, |
2625 | QualType Type, CharUnits Alignment = CharUnits::Zero(), |
2626 | SanitizerSet SkippedChecks = SanitizerSet(), |
2627 | llvm::Value *ArraySize = nullptr); |
2628 | |
2629 | |
2630 | |
2631 | |
2632 | void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index, |
2633 | QualType IndexType, bool Accessed); |
2634 | |
2635 | llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, |
2636 | bool isInc, bool isPre); |
2637 | ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, |
2638 | bool isInc, bool isPre); |
2639 | |
2640 | |
2641 | llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location); |
2642 | |
2643 | |
2644 | |
2645 | |
2646 | |
2647 | |
2648 | |
2649 | |
2650 | |
2651 | void EmitDecl(const Decl &D); |
2652 | |
2653 | |
2654 | |
2655 | |
2656 | void EmitVarDecl(const VarDecl &D); |
2657 | |
2658 | void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, |
2659 | bool capturedByInit); |
2660 | |
2661 | typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, |
2662 | llvm::Value *Address); |
2663 | |
2664 | |
2665 | |
2666 | bool isTrivialInitializer(const Expr *Init); |
2667 | |
2668 | |
2669 | |
2670 | |
2671 | void EmitAutoVarDecl(const VarDecl &D); |
2672 | |
2673 | class AutoVarEmission { |
2674 | friend class CodeGenFunction; |
2675 | |
2676 | const VarDecl *Variable; |
2677 | |
2678 | |
2679 | |
2680 | |
2681 | |
2682 | Address Addr; |
2683 | |
2684 | llvm::Value *NRVOFlag; |
2685 | |
2686 | |
2687 | |
2688 | bool IsEscapingByRef; |
2689 | |
2690 | |
2691 | |
2692 | bool IsConstantAggregate; |
2693 | |
2694 | |
2695 | llvm::Value *SizeForLifetimeMarkers; |
2696 | |
2697 | |
2698 | |
2699 | Address AllocaAddr; |
2700 | |
2701 | struct Invalid {}; |
2702 | AutoVarEmission(Invalid) |
2703 | : Variable(nullptr), Addr(Address::invalid()), |
2704 | AllocaAddr(Address::invalid()) {} |
2705 | |
2706 | AutoVarEmission(const VarDecl &variable) |
2707 | : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr), |
2708 | IsEscapingByRef(false), IsConstantAggregate(false), |
2709 | SizeForLifetimeMarkers(nullptr), AllocaAddr(Address::invalid()) {} |
2710 | |
2711 | bool wasEmittedAsGlobal() const { return !Addr.isValid(); } |
2712 | |
2713 | public: |
2714 | static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); } |
2715 | |
2716 | bool useLifetimeMarkers() const { |
2717 | return SizeForLifetimeMarkers != nullptr; |
2718 | } |
2719 | llvm::Value *getSizeForLifetimeMarkers() const { |
2720 | assert(useLifetimeMarkers()); |
2721 | return SizeForLifetimeMarkers; |
2722 | } |
2723 | |
2724 | |
2725 | |
2726 | |
2727 | Address getAllocatedAddress() const { |
2728 | return Addr; |
2729 | } |
2730 | |
2731 | |
2732 | Address getOriginalAllocatedAddress() const { return AllocaAddr; } |
2733 | |
2734 | |
2735 | |
2736 | |
2737 | Address getObjectAddress(CodeGenFunction &CGF) const { |
2738 | if (!IsEscapingByRef) return Addr; |
2739 | |
2740 | return CGF.emitBlockByrefAddress(Addr, Variable, false); |
2741 | } |
2742 | }; |
2743 | AutoVarEmission EmitAutoVarAlloca(const VarDecl &var); |
2744 | void EmitAutoVarInit(const AutoVarEmission &emission); |
2745 | void EmitAutoVarCleanups(const AutoVarEmission &emission); |
2746 | void emitAutoVarTypeCleanup(const AutoVarEmission &emission, |
2747 | QualType::DestructionKind dtorKind); |
2748 | |
2749 | |
2750 | |
2751 | |
2752 | |
2753 | |
2754 | void EmitAndRegisterVariableArrayDimensions(CGDebugInfo *DI, |
2755 | const VarDecl &D, |
2756 | bool EmitDebugInfo); |
2757 | |
2758 | void EmitStaticVarDecl(const VarDecl &D, |
2759 | llvm::GlobalValue::LinkageTypes Linkage); |
2760 | |
2761 | class ParamValue { |
2762 | llvm::Value *Value; |
2763 | unsigned Alignment; |
2764 | ParamValue(llvm::Value *V, unsigned A) : Value(V), Alignment(A) {} |
2765 | public: |
2766 | static ParamValue forDirect(llvm::Value *value) { |
2767 | return ParamValue(value, 0); |
2768 | } |
2769 | static ParamValue forIndirect(Address addr) { |
2770 | assert(!addr.getAlignment().isZero()); |
2771 | return ParamValue(addr.getPointer(), addr.getAlignment().getQuantity()); |
2772 | } |
2773 | |
2774 | bool isIndirect() const { return Alignment != 0; } |
2775 | llvm::Value *getAnyValue() const { return Value; } |
2776 | |
2777 | llvm::Value *getDirectValue() const { |
2778 | assert(!isIndirect()); |
2779 | return Value; |
2780 | } |
2781 | |
2782 | Address getIndirectAddress() const { |
2783 | assert(isIndirect()); |
2784 | return Address(Value, CharUnits::fromQuantity(Alignment)); |
2785 | } |
2786 | }; |
2787 | |
2788 | |
2789 | void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo); |
2790 | |
2791 | |
2792 | |
2793 | |
2794 | |
2795 | |
2796 | |
2797 | |
2798 | |
2799 | |
2800 | PeepholeProtection protectFromPeepholes(RValue rvalue); |
2801 | void unprotectFromPeepholes(PeepholeProtection protection); |
2802 | |
2803 | void EmitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty, |
2804 | SourceLocation Loc, |
2805 | SourceLocation AssumptionLoc, |
2806 | llvm::Value *Alignment, |
2807 | llvm::Value *OffsetValue, |
2808 | llvm::Value *TheCheck, |
2809 | llvm::Instruction *Assumption); |
2810 | |
2811 | void EmitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, |
2812 | SourceLocation Loc, SourceLocation AssumptionLoc, |
2813 | llvm::Value *Alignment, |
2814 | llvm::Value *OffsetValue = nullptr); |
2815 | |
2816 | void EmitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, |
2817 | SourceLocation Loc, SourceLocation AssumptionLoc, |
2818 | unsigned Alignment, |
2819 | llvm::Value *OffsetValue = nullptr); |
2820 | |
2821 | void EmitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E, |
2822 | SourceLocation AssumptionLoc, unsigned Alignment, |
2823 | llvm::Value *OffsetValue = nullptr); |
2824 | |
2825 | |
2826 | |
2827 | |
2828 | |
2829 | |
2830 | void EmitStopPoint(const Stmt *S); |
2831 | |
2832 | |
2833 | |
2834 | |
2835 | |
2836 | |
2837 | |
2838 | void EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs = None); |
2839 | |
2840 | |
2841 | |
2842 | |
2843 | |
2844 | |
2845 | |
2846 | bool EmitSimpleStmt(const Stmt *S); |
2847 | |
2848 | Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, |
2849 | AggValueSlot AVS = AggValueSlot::ignored()); |
2850 | Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, |
2851 | bool GetLast = false, |
2852 | AggValueSlot AVS = |
2853 | AggValueSlot::ignored()); |
2854 | |
2855 | |
2856 | |
2857 | void EmitLabel(const LabelDecl *D); |
2858 | |
2859 | void EmitLabelStmt(const LabelStmt &S); |
2860 | void EmitAttributedStmt(const AttributedStmt &S); |
2861 | void EmitGotoStmt(const GotoStmt &S); |
2862 | void EmitIndirectGotoStmt(const IndirectGotoStmt &S); |
2863 | void EmitIfStmt(const IfStmt &S); |
2864 | |
2865 | void EmitWhileStmt(const WhileStmt &S, |
2866 | ArrayRef<const Attr *> Attrs = None); |
2867 | void EmitDoStmt(const DoStmt &S, ArrayRef<const Attr *> Attrs = None); |
2868 | void EmitForStmt(const ForStmt &S, |
2869 | ArrayRef<const Attr *> Attrs = None); |
2870 | void EmitReturnStmt(const ReturnStmt &S); |
2871 | void EmitDeclStmt(const DeclStmt &S); |
2872 | void EmitBreakStmt(const BreakStmt &S); |
2873 | void EmitContinueStmt(const ContinueStmt &S); |
2874 | void EmitSwitchStmt(const SwitchStmt &S); |
2875 | void EmitDefaultStmt(const DefaultStmt &S); |
2876 | void EmitCaseStmt(const CaseStmt &S); |
2877 | void EmitCaseStmtRange(const CaseStmt &S); |
2878 | void EmitAsmStmt(const AsmStmt &S); |
2879 | |
2880 | void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); |
2881 | void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); |
2882 | void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); |
2883 | void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); |
2884 | void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S); |
2885 | |
2886 | void EmitCoroutineBody(const CoroutineBodyStmt &S); |
2887 | void EmitCoreturnStmt(const CoreturnStmt &S); |
2888 | RValue EmitCoawaitExpr(const CoawaitExpr &E, |
2889 | AggValueSlot aggSlot = AggValueSlot::ignored(), |
2890 | bool ignoreResult = false); |
2891 | LValue EmitCoawaitLValue(const CoawaitExpr *E); |
2892 | RValue EmitCoyieldExpr(const CoyieldExpr &E, |
2893 | AggValueSlot aggSlot = AggValueSlot::ignored(), |
2894 | bool ignoreResult = false); |
2895 | LValue EmitCoyieldLValue(const CoyieldExpr *E); |
2896 | RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID); |
2897 | |
2898 | void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
2899 | void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
2900 | |
2901 | void EmitCXXTryStmt(const CXXTryStmt &S); |
2902 | void EmitSEHTryStmt(const SEHTryStmt &S); |
2903 | void EmitSEHLeaveStmt(const SEHLeaveStmt &S); |
2904 | void EnterSEHTryStmt(const SEHTryStmt &S); |
2905 | void ExitSEHTryStmt(const SEHTryStmt &S); |
2906 | |
2907 | void pushSEHCleanup(CleanupKind kind, |
2908 | llvm::Function *FinallyFunc); |
2909 | void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, |
2910 | const Stmt *OutlinedStmt); |
2911 | |
2912 | llvm::Function *GenerateSEHFilterFunction(CodeGenFunction &ParentCGF, |
2913 | const SEHExceptStmt &Except); |
2914 | |
2915 | llvm::Function *GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF, |
2916 | const SEHFinallyStmt &Finally); |
2917 | |
2918 | void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, |
2919 | llvm::Value *ParentFP, |
2920 | llvm::Value *EntryEBP); |
2921 | llvm::Value *EmitSEHExceptionCode(); |
2922 | llvm::Value *EmitSEHExceptionInfo(); |
2923 | llvm::Value *EmitSEHAbnormalTermination(); |
2924 | |
2925 | |
2926 | void EmitSimpleOMPExecutableDirective(const OMPExecutableDirective &D); |
2927 | |
2928 | |
2929 | |
2930 | |
2931 | void EmitCapturedLocals(CodeGenFunction &ParentCGF, const Stmt *OutlinedStmt, |
2932 | bool IsFilter); |
2933 | |
2934 | |
2935 | |
2936 | |
2937 | |
2938 | |
2939 | Address recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, |
2940 | Address ParentVar, |
2941 | llvm::Value *ParentFP); |
2942 | |
2943 | void EmitCXXForRangeStmt(const CXXForRangeStmt &S, |
2944 | ArrayRef<const Attr *> Attrs = None); |
2945 | |
2946 | |
2947 | class OMPCancelStackRAII { |
2948 | CodeGenFunction &CGF; |
2949 | |
2950 | public: |
2951 | OMPCancelStackRAII(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, |
2952 | bool HasCancel) |
2953 | : CGF(CGF) { |
2954 | CGF.OMPCancelStack.enter(CGF, Kind, HasCancel); |
2955 | } |
2956 | ~OMPCancelStackRAII() { CGF.OMPCancelStack.exit(CGF); } |
2957 | }; |
2958 | |
2959 | |
2960 | llvm::Value *getTypeSize(QualType Ty); |
2961 | LValue InitCapturedStruct(const CapturedStmt &S); |
2962 | llvm::Function *EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K); |
2963 | llvm::Function *GenerateCapturedStmtFunction(const CapturedStmt &S); |
2964 | Address GenerateCapturedStmtArgument(const CapturedStmt &S); |
2965 | llvm::Function *GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S); |
2966 | void GenerateOpenMPCapturedVars(const CapturedStmt &S, |
2967 | SmallVectorImpl<llvm::Value *> &CapturedVars); |
2968 | void emitOMPSimpleStore(LValue LVal, RValue RVal, QualType RValTy, |
2969 | SourceLocation Loc); |
2970 | |
2971 | |
2972 | |
2973 | |
2974 | |
2975 | |
2976 | |
2977 | |
2978 | |
2979 | void EmitOMPAggregateAssign( |
2980 | Address DestAddr, Address SrcAddr, QualType OriginalType, |
2981 | const llvm::function_ref<void(Address, Address)> CopyGen); |
2982 | |
2983 | |
2984 | |
2985 | |
2986 | |
2987 | |
2988 | |
2989 | |
2990 | |
2991 | |
2992 | |
2993 | void EmitOMPCopy(QualType OriginalType, |
2994 | Address DestAddr, Address SrcAddr, |
2995 | const VarDecl *DestVD, const VarDecl *SrcVD, |
2996 | const Expr *Copy); |
2997 | |
2998 | |
2999 | |
3000 | |
3001 | |
3002 | |
3003 | |
3004 | |
3005 | |
3006 | |
3007 | |
3008 | |
3009 | |
3010 | std::pair<bool, RValue> EmitOMPAtomicSimpleUpdateExpr( |
3011 | LValue X, RValue E, BinaryOperatorKind BO, bool IsXLHSInRHSPart, |
3012 | llvm::AtomicOrdering AO, SourceLocation Loc, |
3013 | const llvm::function_ref<RValue(RValue)> CommonGen); |
3014 | bool EmitOMPFirstprivateClause(const OMPExecutableDirective &D, |
3015 | OMPPrivateScope &PrivateScope); |
3016 | void EmitOMPPrivateClause(const OMPExecutableDirective &D, |
3017 | OMPPrivateScope &PrivateScope); |
3018 | void EmitOMPUseDevicePtrClause( |
3019 | const OMPClause &C, OMPPrivateScope &PrivateScope, |
3020 | const llvm::DenseMap<const ValueDecl *, Address> &CaptureDeviceAddrMap); |
3021 | |
3022 | |
3023 | |
3024 | |
3025 | |
3026 | |
3027 | |
3028 | |
3029 | |
3030 | |
3031 | |
3032 | bool EmitOMPCopyinClause(const OMPExecutableDirective &D); |
3033 | |
3034 | |
3035 | |
3036 | |
3037 | |
3038 | |
3039 | |
3040 | |
3041 | |
3042 | |
3043 | |
3044 | bool EmitOMPLastprivateClauseInit(const OMPExecutableDirective &D, |
3045 | OMPPrivateScope &PrivateScope); |
3046 | |
3047 | |
3048 | |
3049 | |
3050 | |
3051 | |
3052 | |
3053 | void EmitOMPLastprivateClauseFinal(const OMPExecutableDirective &D, |
3054 | bool NoFinals, |
3055 | llvm::Value *IsLastIterCond = nullptr); |
3056 | |
3057 | void EmitOMPLinearClause(const OMPLoopDirective &D, |
3058 | CodeGenFunction::OMPPrivateScope &PrivateScope); |
3059 | |
3060 | |
3061 | |
3062 | void EmitOMPLinearClauseFinal( |
3063 | const OMPLoopDirective &D, |
3064 | const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen); |
3065 | |
3066 | |
3067 | |
3068 | |
3069 | |
3070 | |
3071 | |
3072 | void EmitOMPReductionClauseInit(const OMPExecutableDirective &D, |
3073 | OMPPrivateScope &PrivateScope); |
3074 | |
3075 | |
3076 | |
3077 | |
3078 | |
3079 | void EmitOMPReductionClauseFinal(const OMPExecutableDirective &D, |
3080 | const OpenMPDirectiveKind ReductionKind); |
3081 | |
3082 | |
3083 | |
3084 | |
3085 | |
3086 | |
3087 | bool EmitOMPLinearClauseInit(const OMPLoopDirective &D); |
3088 | |
3089 | typedef const llvm::function_ref<void(CodeGenFunction & , |
3090 | llvm::Function * , |
3091 | const OMPTaskDataTy & )> |
3092 | TaskGenTy; |
3093 | void EmitOMPTaskBasedDirective(const OMPExecutableDirective &S, |
3094 | const OpenMPDirectiveKind CapturedRegion, |
3095 | const RegionCodeGenTy &BodyGen, |
3096 | const TaskGenTy &TaskGen, OMPTaskDataTy &Data); |
3097 | struct OMPTargetDataInfo { |
3098 | Address BasePointersArray = Address::invalid(); |
3099 | Address PointersArray = Address::invalid(); |
3100 | Address SizesArray = Address::invalid(); |
3101 | unsigned NumberOfTargetItems = 0; |
3102 | explicit OMPTargetDataInfo() = default; |
3103 | OMPTargetDataInfo(Address BasePointersArray, Address PointersArray, |
3104 | Address SizesArray, unsigned NumberOfTargetItems) |
3105 | : BasePointersArray(BasePointersArray), PointersArray(PointersArray), |
3106 | SizesArray(SizesArray), NumberOfTargetItems(NumberOfTargetItems) {} |
3107 | }; |
3108 | void EmitOMPTargetTaskBasedDirective(const OMPExecutableDirective &S, |
3109 | const RegionCodeGenTy &BodyGen, |
3110 | OMPTargetDataInfo &InputInfo); |
3111 | |
3112 | void EmitOMPParallelDirective(const OMPParallelDirective &S); |
3113 | void EmitOMPSimdDirective(const OMPSimdDirective &S); |
3114 | void EmitOMPForDirective(const OMPForDirective &S); |
3115 | void EmitOMPForSimdDirective(const OMPForSimdDirective &S); |
3116 | void EmitOMPSectionsDirective(const OMPSectionsDirective &S); |
3117 | void EmitOMPSectionDirective(const OMPSectionDirective &S); |
3118 | void EmitOMPSingleDirective(const OMPSingleDirective &S); |
3119 | void EmitOMPMasterDirective(const OMPMasterDirective &S); |
3120 | void EmitOMPCriticalDirective(const OMPCriticalDirective &S); |
3121 | void EmitOMPParallelForDirective(const OMPParallelForDirective &S); |
3122 | void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S); |
3123 | void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S); |
3124 | void EmitOMPTaskDirective(const OMPTaskDirective &S); |
3125 | void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S); |
3126 | void EmitOMPBarrierDirective(const OMPBarrierDirective &S); |
3127 | void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S); |
3128 | void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S); |
3129 | void EmitOMPFlushDirective(const OMPFlushDirective &S); |
3130 | void EmitOMPOrderedDirective(const OMPOrderedDirective &S); |
3131 | void EmitOMPAtomicDirective(const OMPAtomicDirective &S); |
3132 | void EmitOMPTargetDirective(const OMPTargetDirective &S); |
3133 | void EmitOMPTargetDataDirective(const OMPTargetDataDirective &S); |
3134 | void EmitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &S); |
3135 | void EmitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &S); |
3136 | void EmitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &S); |
3137 | void EmitOMPTargetParallelDirective(const OMPTargetParallelDirective &S); |
3138 | void |
3139 | EmitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &S); |
3140 | void EmitOMPTeamsDirective(const OMPTeamsDirective &S); |
3141 | void |
3142 | EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S); |
3143 | void EmitOMPCancelDirective(const OMPCancelDirective &S); |
3144 | void EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S); |
3145 | void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S); |
3146 | void EmitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &S); |
3147 | void EmitOMPDistributeDirective(const OMPDistributeDirective &S); |
3148 | void EmitOMPDistributeParallelForDirective( |
3149 | const OMPDistributeParallelForDirective &S); |
3150 | void EmitOMPDistributeParallelForSimdDirective( |
3151 | const OMPDistributeParallelForSimdDirective &S); |
3152 | void EmitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &S); |
3153 | void EmitOMPTargetParallelForSimdDirective( |
3154 | const OMPTargetParallelForSimdDirective &S); |
3155 | void EmitOMPTargetSimdDirective(const OMPTargetSimdDirective &S); |
3156 | void EmitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &S); |
3157 | void |
3158 | EmitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &S); |
3159 | void EmitOMPTeamsDistributeParallelForSimdDirective( |
3160 | const OMPTeamsDistributeParallelForSimdDirective &S); |
3161 | void EmitOMPTeamsDistributeParallelForDirective( |
3162 | const OMPTeamsDistributeParallelForDirective &S); |
3163 | void EmitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &S); |
3164 | void EmitOMPTargetTeamsDistributeDirective( |
3165 | const OMPTargetTeamsDistributeDirective &S); |
3166 | void EmitOMPTargetTeamsDistributeParallelForDirective( |
3167 | const OMPTargetTeamsDistributeParallelForDirective &S); |
3168 | void EmitOMPTargetTeamsDistributeParallelForSimdDirective( |
3169 | const OMPTargetTeamsDistributeParallelForSimdDirective &S); |
3170 | void EmitOMPTargetTeamsDistributeSimdDirective( |
3171 | const OMPTargetTeamsDistributeSimdDirective &S); |
3172 | |
3173 | |
3174 | static void EmitOMPTargetDeviceFunction(CodeGenModule &CGM, |
3175 | StringRef ParentName, |
3176 | const OMPTargetDirective &S); |
3177 | static void |
3178 | EmitOMPTargetParallelDeviceFunction(CodeGenModule &CGM, StringRef ParentName, |
3179 | const OMPTargetParallelDirective &S); |
3180 | |
3181 | static void EmitOMPTargetParallelForDeviceFunction( |
3182 | CodeGenModule &CGM, StringRef ParentName, |
3183 | const OMPTargetParallelForDirective &S); |
3184 | |
3185 | static void EmitOMPTargetParallelForSimdDeviceFunction( |
3186 | CodeGenModule &CGM, StringRef ParentName, |
3187 | const OMPTargetParallelForSimdDirective &S); |
3188 | |
3189 | static void |
3190 | EmitOMPTargetTeamsDeviceFunction(CodeGenModule &CGM, StringRef ParentName, |
3191 | const OMPTargetTeamsDirective &S); |
3192 | |
3193 | static void EmitOMPTargetTeamsDistributeDeviceFunction( |
3194 | CodeGenModule &CGM, StringRef ParentName, |
3195 | const OMPTargetTeamsDistributeDirective &S); |
3196 | |
3197 | static void EmitOMPTargetTeamsDistributeSimdDeviceFunction( |
3198 | CodeGenModule &CGM, StringRef ParentName, |
3199 | const OMPTargetTeamsDistributeSimdDirective &S); |
3200 | |
3201 | static void EmitOMPTargetSimdDeviceFunction(CodeGenModule &CGM, |
3202 | StringRef ParentName, |
3203 | const OMPTargetSimdDirective &S); |
3204 | |
3205 | |
3206 | static void EmitOMPTargetTeamsDistributeParallelForSimdDeviceFunction( |
3207 | CodeGenModule &CGM, StringRef ParentName, |
3208 | const OMPTargetTeamsDistributeParallelForSimdDirective &S); |
3209 | |
3210 | static void EmitOMPTargetTeamsDistributeParallelForDeviceFunction( |
3211 | CodeGenModule &CGM, StringRef ParentName, |
3212 | const OMPTargetTeamsDistributeParallelForDirective &S); |
3213 | |
3214 | |
3215 | |
3216 | |
3217 | |
3218 | |
3219 | |
3220 | |
3221 | |
3222 | |
3223 | void EmitOMPInnerLoop( |
3224 | const Stmt &S, bool RequiresCleanup, const Expr *LoopCond, |
3225 | const Expr *IncExpr, |
3226 | const llvm::function_ref<void(CodeGenFunction &)> BodyGen, |
3227 | const llvm::function_ref<void(CodeGenFunction &)> PostIncGen); |
3228 | |
3229 | JumpDest getOMPCancelDestination(OpenMPDirectiveKind Kind); |
3230 | |
3231 | void EmitOMPPrivateLoopCounters(const OMPLoopDirective &S, |
3232 | OMPPrivateScope &LoopScope); |
3233 | |
3234 | |
3235 | void EmitOMPLoopBody(const OMPLoopDirective &D, JumpDest LoopExit); |
3236 | |
3237 | |
3238 | |
3239 | |
3240 | bool EmitOMPWorksharingLoop(const OMPLoopDirective &S, Expr *EUB, |
3241 | const CodeGenLoopBoundsTy &CodeGenLoopBounds, |
3242 | const CodeGenDispatchBoundsTy &CGDispatchBounds); |
3243 | |
3244 | |
3245 | void EmitOMPDistributeLoop(const OMPLoopDirective &S, |
3246 | const CodeGenLoopTy &CodeGenLoop, Expr *IncExpr); |
3247 | |
3248 | |
3249 | void EmitOMPSimdInit(const OMPLoopDirective &D, bool IsMonotonic = false); |
3250 | void EmitOMPSimdFinal( |
3251 | const OMPLoopDirective &D, |
3252 | const llvm::function_ref<llvm::Value *(CodeGenFunction &)> CondGen); |
3253 | |
3254 | |
3255 | LValue EmitOMPSharedLValue(const Expr *E); |
3256 | |
3257 | private: |
3258 | |
3259 | llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info); |
3260 | |
3261 | |
3262 | struct OMPLoopArguments { |
3263 | |
3264 | Address LB = Address::invalid(); |
3265 | |
3266 | Address UB = Address::invalid(); |
3267 | |
3268 | Address ST = Address::invalid(); |
3269 | |
3270 | Address IL = Address::invalid(); |
3271 | |
3272 | llvm::Value *Chunk = nullptr; |
3273 | |
3274 | Expr *EUB = nullptr; |
3275 | |
3276 | Expr *IncExpr = nullptr; |
3277 | |
3278 | Expr *Init = nullptr; |
3279 | |
3280 | Expr *Cond = nullptr; |
3281 | |
3282 | Expr *NextLB = nullptr; |
3283 | |
3284 | Expr *NextUB = nullptr; |
3285 | OMPLoopArguments() = default; |
3286 | OMPLoopArguments(Address LB, Address UB, Address ST, Address IL, |
3287 | llvm::Value *Chunk = nullptr, Expr *EUB = nullptr, |
3288 | Expr *IncExpr = nullptr, Expr *Init = nullptr, |
3289 | Expr *Cond = nullptr, Expr *NextLB = nullptr, |
3290 | Expr *NextUB = nullptr) |
3291 | : LB(LB), UB(UB), ST(ST), IL(IL), Chunk(Chunk), EUB(EUB), |
3292 | IncExpr(IncExpr), Init(Init), Cond(Cond), NextLB(NextLB), |
3293 | NextUB(NextUB) {} |
3294 | }; |
3295 | void EmitOMPOuterLoop(bool DynamicOrOrdered, bool IsMonotonic, |
3296 | const OMPLoopDirective &S, OMPPrivateScope &LoopScope, |
3297 | const OMPLoopArguments &LoopArgs, |
3298 | const CodeGenLoopTy &CodeGenLoop, |
3299 | const CodeGenOrderedTy &CodeGenOrdered); |
3300 | void EmitOMPForOuterLoop(const OpenMPScheduleTy &ScheduleKind, |
3301 | bool IsMonotonic, const OMPLoopDirective &S, |
3302 | OMPPrivateScope &LoopScope, bool Ordered, |
3303 | const OMPLoopArguments &LoopArgs, |
3304 | const CodeGenDispatchBoundsTy &CGDispatchBounds); |
3305 | void EmitOMPDistributeOuterLoop(OpenMPDistScheduleClauseKind ScheduleKind, |
3306 | const OMPLoopDirective &S, |
3307 | OMPPrivateScope &LoopScope, |
3308 | const OMPLoopArguments &LoopArgs, |
3309 | const CodeGenLoopTy &CodeGenLoopContent); |
3310 | |
3311 | void EmitSections(const OMPExecutableDirective &S); |
3312 | |
3313 | public: |
3314 | |
3315 | |
3316 | |
3317 | |
3318 | |
3319 | |
3320 | RValue GetUndefRValue(QualType Ty); |
3321 | |
3322 | |
3323 | |
3324 | |
3325 | RValue EmitUnsupportedRValue(const Expr *E, |
3326 | const char *Name); |
3327 | |
3328 | |
3329 | |
3330 | LValue EmitUnsupportedLValue(const Expr *E, |
3331 | const char *Name); |
3332 | |
3333 | |
3334 | |
3335 | |
3336 | |
3337 | |
3338 | |
3339 | |
3340 | |
3341 | |
3342 | |
3343 | |
3344 | |
3345 | |
3346 | |
3347 | |
3348 | |
3349 | LValue EmitLValue(const Expr *E); |
3350 | |
3351 | |
3352 | |
3353 | |
3354 | LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK); |
3355 | |
3356 | RValue convertTempToRValue(Address addr, QualType type, |
3357 | SourceLocation Loc); |
3358 | |
3359 | void EmitAtomicInit(Expr *E, LValue lvalue); |
3360 | |
3361 | bool LValueIsSuitableForInlineAtomic(LValue Src); |
3362 | |
3363 | RValue EmitAtomicLoad(LValue LV, SourceLocation SL, |
3364 | AggValueSlot Slot = AggValueSlot::ignored()); |
3365 | |
3366 | RValue EmitAtomicLoad(LValue lvalue, SourceLocation loc, |
3367 | llvm::AtomicOrdering AO, bool IsVolatile = false, |
3368 | AggValueSlot slot = AggValueSlot::ignored()); |
3369 | |
3370 | void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit); |
3371 | |
3372 | void EmitAtomicStore(RValue rvalue, LValue lvalue, llvm::AtomicOrdering AO, |
3373 | bool IsVolatile, bool isInit); |
3374 | |
3375 | std::pair<RValue, llvm::Value *> EmitAtomicCompareExchange( |
3376 | LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc, |
3377 | llvm::AtomicOrdering Success = |
3378 | llvm::AtomicOrdering::SequentiallyConsistent, |
3379 | llvm::AtomicOrdering Failure = |
3380 | llvm::AtomicOrdering::SequentiallyConsistent, |
3381 | bool IsWeak = false, AggValueSlot Slot = AggValueSlot::ignored()); |
3382 | |
3383 | void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO, |
3384 | const llvm::function_ref<RValue(RValue)> &UpdateOp, |
3385 | bool IsVolatile); |
3386 | |
3387 | |
3388 | |
3389 | llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty); |
3390 | |
3391 | |
3392 | |
3393 | llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty); |
3394 | |
3395 | |
3396 | |
3397 | |
3398 | |
3399 | bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty, |
3400 | SourceLocation Loc); |
3401 | |
3402 | |
3403 | |
3404 | |
3405 | llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, |
3406 | SourceLocation Loc, |
3407 | AlignmentSource Source = AlignmentSource::Type, |
3408 | bool isNontemporal = false) { |
3409 | return EmitLoadOfScalar(Addr, Volatile, Ty, Loc, LValueBaseInfo(Source), |
3410 | CGM.getTBAAAccessInfo(Ty), isNontemporal); |
3411 | } |
3412 | |
3413 | llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, |
3414 | SourceLocation Loc, LValueBaseInfo BaseInfo, |
3415 | TBAAAccessInfo TBAAInfo, |
3416 | bool isNontemporal = false); |
3417 | |
3418 | |
3419 | |
3420 | |
3421 | |
3422 | llvm::Value *EmitLoadOfScalar(LValue lvalue, SourceLocation Loc); |
3423 | |
3424 | |
3425 | |
3426 | |
3427 | void EmitStoreOfScalar(llvm::Value *Value, Address Addr, |
3428 | bool Volatile, QualType Ty, |
3429 | AlignmentSource Source = AlignmentSource::Type, |
3430 | bool isInit = false, bool isNontemporal = false) { |
3431 | EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source), |
3432 | CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal); |
3433 | } |
3434 | |
3435 | void EmitStoreOfScalar(llvm::Value *Value, Address Addr, |
3436 | bool Volatile, QualType Ty, |
3437 | LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo, |
3438 | bool isInit = false, bool isNontemporal = false); |
3439 | |
3440 | |
3441 | |
3442 | |
3443 | |
3444 | |
3445 | void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false); |
3446 | |
3447 | |
3448 | |
3449 | |
3450 | RValue EmitLoadOfLValue(LValue V, SourceLocation Loc); |
3451 | RValue EmitLoadOfExtVectorElementLValue(LValue V); |
3452 | RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc); |
3453 | RValue EmitLoadOfGlobalRegLValue(LValue LV); |
3454 | |
3455 | |
3456 | |
3457 | |
3458 | void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false); |
3459 | void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst); |
3460 | void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst); |
3461 | |
3462 | |
3463 | |
3464 | |
3465 | |
3466 | |
3467 | |
3468 | void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, |
3469 | llvm::Value **Result=nullptr); |
3470 | |
3471 | |
3472 | LValue EmitComplexAssignmentLValue(const BinaryOperator *E); |
3473 | LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E); |
3474 | LValue EmitScalarCompoundAssignWithComplex(const CompoundAssignOperator *E, |
3475 | llvm::Value *&Result); |
3476 | |
3477 | |
3478 | LValue EmitBinaryOperatorLValue(const BinaryOperator *E); |
3479 | LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E); |
3480 | |
3481 | LValue EmitCallExprLValue(const CallExpr *E); |
3482 | |
3483 | LValue EmitVAArgExprLValue(const VAArgExpr *E); |
3484 | LValue EmitDeclRefLValue(const DeclRefExpr *E); |
3485 | LValue EmitStringLiteralLValue(const StringLiteral *E); |
3486 | LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); |
3487 | LValue EmitPredefinedLValue(const PredefinedExpr *E); |
3488 | LValue EmitUnaryOpLValue(const UnaryOperator *E); |
3489 | LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, |
3490 | bool Accessed = false); |
3491 | LValue EmitOMPArraySectionExpr(const OMPArraySectionExpr *E, |
3492 | bool IsLowerBound = true); |
3493 | LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); |
3494 | LValue EmitMemberExpr(const MemberExpr *E); |
3495 | LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); |
3496 | LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); |
3497 | LValue EmitInitListLValue(const InitListExpr *E); |
3498 | LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E); |
3499 | LValue EmitCastLValue(const CastExpr *E); |
3500 | LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); |
3501 | LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e); |
3502 | |
3503 | Address EmitExtVectorElementLValue(LValue V); |
3504 | |
3505 | RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc); |
3506 | |
3507 | Address EmitArrayToPointerDecay(const Expr *Array, |
3508 | LValueBaseInfo *BaseInfo = nullptr, |
3509 | TBAAAccessInfo *TBAAInfo = nullptr); |
3510 | |
3511 | class ConstantEmission { |
3512 | llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference; |
3513 | ConstantEmission(llvm::Constant *C, bool isReference) |
3514 | : ValueAndIsReference(C, isReference) {} |
3515 | public: |
3516 | ConstantEmission() {} |
3517 | static ConstantEmission forReference(llvm::Constant *C) { |
3518 | return ConstantEmission(C, true); |
3519 | } |
3520 | static ConstantEmission forValue(llvm::Constant *C) { |
3521 | return ConstantEmission(C, false); |
3522 | } |
3523 | |
3524 | explicit operator bool() const { |
3525 | return ValueAndIsReference.getOpaqueValue() != nullptr; |
3526 | } |
3527 | |
3528 | bool isReference() const { return ValueAndIsReference.getInt(); } |
3529 | LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const { |
3530 | assert(isReference()); |
3531 | return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(), |
3532 | refExpr->getType()); |
3533 | } |
3534 | |
3535 | llvm::Constant *getValue() const { |
3536 | assert(!isReference()); |
3537 | return ValueAndIsReference.getPointer(); |
3538 | } |
3539 | }; |
3540 | |
3541 | ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr); |
3542 | ConstantEmission tryEmitAsConstant(const MemberExpr *ME); |
3543 | llvm::Value *emitScalarConstant(const ConstantEmission &Constant, Expr *E); |
3544 | |
3545 | RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, |
3546 | AggValueSlot slot = AggValueSlot::ignored()); |
3547 | LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e); |
3548 | |
3549 | llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, |
3550 | const ObjCIvarDecl *Ivar); |
3551 | LValue EmitLValueForField(LValue Base, const FieldDecl* Field); |
3552 | LValue EmitLValueForLambdaField(const FieldDecl *Field); |
3553 | |
3554 | |
3555 | |
3556 | |
3557 | LValue EmitLValueForFieldInitialization(LValue Base, |
3558 | const FieldDecl* Field); |
3559 | |
3560 | LValue EmitLValueForIvar(QualType ObjectTy, |
3561 | llvm::Value* Base, const ObjCIvarDecl *Ivar, |
3562 | unsigned CVRQualifiers); |
3563 | |
3564 | LValue EmitCXXConstructLValue(const CXXConstructExpr *E); |
3565 | LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); |
3566 | LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); |
3567 | LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E); |
3568 | |
3569 | LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); |
3570 | LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); |
3571 | LValue EmitStmtExprLValue(const StmtExpr *E); |
3572 | LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); |
3573 | LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); |
3574 | void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init); |
3575 | |
3576 | |
3577 | |
3578 | |
3579 | |
3580 | |
3581 | |
3582 | |
3583 | RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, |
3584 | ReturnValueSlot ReturnValue, const CallArgList &Args, |
3585 | llvm::CallBase **callOrInvoke, SourceLocation Loc); |
3586 | RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, |
3587 | ReturnValueSlot ReturnValue, const CallArgList &Args, |
3588 | llvm::CallBase **callOrInvoke = nullptr) { |
3589 | return EmitCall(CallInfo, Callee, ReturnValue, Args, callOrInvoke, |
3590 | SourceLocation()); |
3591 | } |
3592 | RValue EmitCall(QualType FnType, const CGCallee &Callee, const CallExpr *E, |
3593 | ReturnValueSlot ReturnValue, llvm::Value *Chain = nullptr); |
3594 | RValue EmitCallExpr(const CallExpr *E, |
3595 | ReturnValueSlot ReturnValue = ReturnValueSlot()); |
3596 | RValue EmitSimpleCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); |
3597 | CGCallee EmitCallee(const Expr *E); |
3598 | |
3599 | void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl); |
3600 | |
3601 | llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee, |
3602 | const Twine &name = ""); |
3603 | llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee, |
3604 | ArrayRef<llvm::Value *> args, |
3605 | const Twine &name = ""); |
3606 | llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee, |
3607 | const Twine &name = ""); |
3608 | llvm::CallInst *EmitNounwindRuntimeCall(llvm::FunctionCallee callee, |
3609 | ArrayRef<llvm::Value *> args, |
3610 | const Twine &name = ""); |
3611 | |
3612 | SmallVector<llvm::OperandBundleDef, 1> |
3613 | getBundlesForFunclet(llvm::Value *Callee); |
3614 | |
3615 | llvm::CallBase *EmitCallOrInvoke(llvm::FunctionCallee Callee, |
3616 | ArrayRef<llvm::Value *> Args, |
3617 | const Twine &Name = ""); |
3618 | llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, |
3619 | ArrayRef<llvm::Value *> args, |
3620 | const Twine &name = ""); |
3621 | llvm::CallBase *EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, |
3622 | const Twine &name = ""); |
3623 | void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, |
3624 | ArrayRef<llvm::Value *> args); |
3625 | |
3626 | CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, |
3627 | NestedNameSpecifier *Qual, |
3628 | llvm::Type *Ty); |
3629 | |
3630 | CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, |
3631 | CXXDtorType Type, |
3632 | const CXXRecordDecl *RD); |
3633 | |
3634 | |
3635 | |
3636 | static std::string getNonTrivialCopyConstructorStr(QualType QT, |
3637 | CharUnits Alignment, |
3638 | bool IsVolatile, |
3639 | ASTContext &Ctx); |
3640 | |
3641 | |
3642 | static std::string getNonTrivialDestructorStr(QualType QT, |
3643 | CharUnits Alignment, |
3644 | bool IsVolatile, |
3645 | ASTContext &Ctx); |
3646 | |
3647 | |
3648 | |
3649 | void defaultInitNonTrivialCStructVar(LValue Dst); |
3650 | void callCStructDefaultConstructor(LValue Dst); |
3651 | void callCStructDestructor(LValue Dst); |
3652 | void callCStructCopyConstructor(LValue Dst, LValue Src); |
3653 | void callCStructMoveConstructor(LValue Dst, LValue Src); |
3654 | void callCStructCopyAssignmentOperator(LValue Dst, LValue Src); |
3655 | void callCStructMoveAssignmentOperator(LValue Dst, LValue Src); |
3656 | |
3657 | RValue |
3658 | EmitCXXMemberOrOperatorCall(const CXXMethodDecl *Method, |
3659 | const CGCallee &Callee, |
3660 | ReturnValueSlot ReturnValue, llvm::Value *This, |
3661 | llvm::Value *ImplicitParam, |
3662 | QualType ImplicitParamTy, const CallExpr *E, |
3663 | CallArgList *RtlArgs); |
3664 | RValue EmitCXXDestructorCall(GlobalDecl Dtor, |
3665 | const CGCallee &Callee, |
3666 | llvm::Value *This, llvm::Value *ImplicitParam, |
3667 | QualType ImplicitParamTy, const CallExpr *E); |
3668 | RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, |
3669 | ReturnValueSlot ReturnValue); |
3670 | RValue EmitCXXMemberOrOperatorMemberCallExpr(const CallExpr *CE, |
3671 | const CXXMethodDecl *MD, |
3672 | ReturnValueSlot ReturnValue, |
3673 | bool HasQualifier, |
3674 | NestedNameSpecifier *Qualifier, |
3675 | bool IsArrow, const Expr *Base); |
3676 | |
3677 | Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, |
3678 | llvm::Value *memberPtr, |
3679 | const MemberPointerType *memberPtrType, |
3680 | LValueBaseInfo *BaseInfo = nullptr, |
3681 | TBAAAccessInfo *TBAAInfo = nullptr); |
3682 | RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, |
3683 | ReturnValueSlot ReturnValue); |
3684 | |
3685 | RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, |
3686 | const CXXMethodDecl *MD, |
3687 | ReturnValueSlot ReturnValue); |
3688 | RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E); |
3689 | |
3690 | RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, |
3691 | ReturnValueSlot ReturnValue); |
3692 | |
3693 | RValue EmitNVPTXDevicePrintfCallExpr(const CallExpr *E, |
3694 | ReturnValueSlot ReturnValue); |
3695 | |
3696 | RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, |
3697 | const CallExpr *E, ReturnValueSlot ReturnValue); |
3698 | |
3699 | RValue emitRotate(const CallExpr *E, bool IsRotateRight); |
3700 | |
3701 | |
3702 | RValue emitBuiltinOSLogFormat(const CallExpr &E); |
3703 | |
3704 | llvm::Function *generateBuiltinOSLogHelperFunction( |
3705 | const analyze_os_log::OSLogBufferLayout &Layout, |
3706 | CharUnits BufferAlignment); |
3707 | |
3708 | RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); |
3709 | |
3710 | |
3711 | |
3712 | llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
3713 | |
3714 | llvm::Value *EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty, |
3715 | const llvm::CmpInst::Predicate Fp, |
3716 | const llvm::CmpInst::Predicate Ip, |
3717 | const llvm::Twine &Name = ""); |
3718 | llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E, |
3719 | llvm::Triple::ArchType Arch); |
3720 | |
3721 | llvm::Value *EmitCommonNeonBuiltinExpr(unsigned BuiltinID, |
3722 | unsigned LLVMIntrinsic, |
3723 | unsigned AltLLVMIntrinsic, |
3724 | const char *NameHint, |
3725 | unsigned Modifier, |
3726 | const CallExpr *E, |
3727 | SmallVectorImpl<llvm::Value *> &Ops, |
3728 | Address PtrOp0, Address PtrOp1, |
3729 | llvm::Triple::ArchType Arch); |
3730 | |
3731 | llvm::Function *LookupNeonLLVMIntrinsic(unsigned IntrinsicID, |
3732 | unsigned Modifier, llvm::Type *ArgTy, |
3733 | const CallExpr *E); |
3734 | llvm::Value *EmitNeonCall(llvm::Function *F, |
3735 | SmallVectorImpl<llvm::Value*> &O, |
3736 | const char *name, |
3737 | unsigned shift = 0, bool rightshift = false); |
3738 | llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx); |
3739 | llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, |
3740 | bool negateForRightShift); |
3741 | llvm::Value *EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt, |
3742 | llvm::Type *Ty, bool usgn, const char *name); |
3743 | llvm::Value *vectorWrapScalar16(llvm::Value *Op); |
3744 | llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E, |
3745 | llvm::Triple::ArchType Arch); |
3746 | |
3747 | llvm::Value *BuildVector(ArrayRef<llvm::Value*> Ops); |
3748 | llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
3749 | llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
3750 | llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
3751 | llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
3752 | llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
3753 | llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, |
3754 | const CallExpr *E); |
3755 | llvm::Value *EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
3756 | |
3757 | private: |
3758 | enum class MSVCIntrin; |
3759 | |
3760 | public: |
3761 | llvm::Value *EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E); |
3762 | |
3763 | llvm::Value *EmitBuiltinAvailable(ArrayRef<llvm::Value *> Args); |
3764 | |
3765 | llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); |
3766 | llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); |
3767 | llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E); |
3768 | llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E); |
3769 | llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E); |
3770 | llvm::Value *EmitObjCCollectionLiteral(const Expr *E, |
3771 | const ObjCMethodDecl *MethodWithObjects); |
3772 | llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); |
3773 | RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, |
3774 | ReturnValueSlot Return = ReturnValueSlot()); |
3775 | |
3776 | |
3777 | |
3778 | CleanupKind getARCCleanupKind() { |
3779 | return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions |
3780 | ? NormalAndEHCleanup : NormalCleanup; |
3781 | } |
3782 | |
3783 | |
3784 | void EmitARCInitWeak(Address addr, llvm::Value *value); |
3785 | void EmitARCDestroyWeak(Address addr); |
3786 | llvm::Value *EmitARCLoadWeak(Address addr); |
3787 | llvm::Value *EmitARCLoadWeakRetained(Address addr); |
3788 | llvm::Value *EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored); |
3789 | void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr); |
3790 | void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr); |
3791 | void EmitARCCopyWeak(Address dst, Address src); |
3792 | void EmitARCMoveWeak(Address dst, Address src); |
3793 | llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value); |
3794 | llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value); |
3795 | llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value, |
3796 | bool resultIgnored); |
3797 | llvm::Value *EmitARCStoreStrongCall(Address addr, llvm::Value *value, |
3798 | bool resultIgnored); |
3799 | llvm::Value *EmitARCRetain(QualType type, llvm::Value *value); |
3800 | llvm::Value *EmitARCRetainNonBlock(llvm::Value *value); |
3801 | llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory); |
3802 | void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise); |
3803 | void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise); |
3804 | llvm::Value *EmitARCAutorelease(llvm::Value *value); |
3805 | llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value); |
3806 | llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value); |
3807 | llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value); |
3808 | llvm::Value *EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value); |
3809 | |
3810 | llvm::Value *EmitObjCAutorelease(llvm::Value *value, llvm::Type *returnType); |
3811 | llvm::Value *EmitObjCRetainNonBlock(llvm::Value *value, |
3812 | llvm::Type *returnType); |
3813 | void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise); |
3814 | |
3815 | std::pair<LValue,llvm::Value*> |
3816 | EmitARCStoreAutoreleasing(const BinaryOperator *e); |
3817 | std::pair<LValue,llvm::Value*> |
3818 | EmitARCStoreStrong(const BinaryOperator *e, bool ignored); |
3819 | std::pair<LValue,llvm::Value*> |
3820 | EmitARCStoreUnsafeUnretained(const BinaryOperator *e, bool ignored); |
3821 | |
3822 | llvm::Value *EmitObjCAlloc(llvm::Value *value, |
3823 | llvm::Type *returnType); |
3824 | llvm::Value *EmitObjCAllocWithZone(llvm::Value *value, |
3825 | llvm::Type *returnType); |
3826 | llvm::Value *EmitObjCAllocInit(llvm::Value *value, llvm::Type *resultType); |
3827 | |
3828 | llvm::Value *EmitObjCThrowOperand(const Expr *expr); |
3829 | llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr); |
3830 | llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr); |
3831 | |
3832 | llvm::Value *EmitARCExtendBlockObject(const Expr *expr); |
3833 | llvm::Value *EmitARCReclaimReturnedObject(const Expr *e, |
3834 | bool allowUnsafeClaim); |
3835 | llvm::Value *EmitARCRetainScalarExpr(const Expr *expr); |
3836 | llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr); |
3837 | llvm::Value *EmitARCUnsafeUnretainedScalarExpr(const Expr *expr); |
3838 | |
3839 | void EmitARCIntrinsicUse(ArrayRef<llvm::Value*> values); |
3840 | |
3841 | static Destroyer destroyARCStrongImprecise; |
3842 | static Destroyer destroyARCStrongPrecise; |
3843 | static Destroyer destroyARCWeak; |
3844 | static Destroyer emitARCIntrinsicUse; |
3845 | static Destroyer destroyNonTrivialCStruct; |
3846 | |
3847 | void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr); |
3848 | llvm::Value *EmitObjCAutoreleasePoolPush(); |
3849 | llvm::Value *EmitObjCMRRAutoreleasePoolPush(); |
3850 | void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr); |
3851 | void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr); |
3852 | |
3853 | |
3854 | RValue EmitReferenceBindingToExpr(const Expr *E); |
3855 | |
3856 | |
3857 | |
3858 | |
3859 | |
3860 | |
3861 | |
3862 | |
3863 | |
3864 | llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); |
3865 | |
3866 | |
3867 | |
3868 | llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, |
3869 | QualType DstTy, SourceLocation Loc); |
3870 | |
3871 | |
3872 | |
3873 | llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, |
3874 | QualType DstTy, |
3875 | SourceLocation Loc); |
3876 | |
3877 | |
3878 | |
3879 | |
3880 | void EmitAggExpr(const Expr *E, AggValueSlot AS); |
3881 | |
3882 | |
3883 | |
3884 | LValue EmitAggExprToLValue(const Expr *E); |
3885 | |
3886 | |
3887 | |
3888 | void EmitExtendGCLifetime(llvm::Value *object); |
3889 | |
3890 | |
3891 | |
3892 | ComplexPairTy EmitComplexExpr(const Expr *E, |
3893 | bool IgnoreReal = false, |
3894 | bool IgnoreImag = false); |
3895 | |
3896 | |
3897 | |
3898 | void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit); |
3899 | |
3900 | |
3901 | void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit); |
3902 | |
3903 | |
3904 | ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc); |
3905 | |
3906 | Address emitAddrOfRealComponent(Address complex, QualType complexType); |
3907 | Address emitAddrOfImagComponent(Address complex, QualType complexType); |
3908 | |
3909 | |
3910 | |
3911 | |
3912 | |
3913 | llvm::GlobalVariable * |
3914 | AddInitializerToStaticVarDecl(const VarDecl &D, |
3915 | llvm::GlobalVariable *GV); |
3916 | |
3917 | |
3918 | void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size); |
3919 | |
3920 | |
3921 | |
3922 | void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr, |
3923 | bool PerformInit); |
3924 | |
3925 | llvm::Function *createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, |
3926 | llvm::Constant *Addr); |
3927 | |
3928 | |
3929 | |
3930 | void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn, |
3931 | llvm::Constant *addr); |
3932 | |
3933 | |
3934 | void registerGlobalDtorWithAtExit(llvm::Constant *dtorStub); |
3935 | |
3936 | |
3937 | |
3938 | |
3939 | |
3940 | |
3941 | void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, |
3942 | bool PerformInit); |
3943 | |
3944 | enum class GuardKind { VariableGuard, TlsGuard }; |
3945 | |
3946 | |
3947 | void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit, |
3948 | llvm::BasicBlock *InitBlock, |
3949 | llvm::BasicBlock *NoInitBlock, |
3950 | GuardKind Kind, const VarDecl *D); |
3951 | |
3952 | |
3953 | |
3954 | void |
3955 | GenerateCXXGlobalInitFunc(llvm::Function *Fn, |
3956 | ArrayRef<llvm::Function *> CXXThreadLocals, |
3957 | ConstantAddress Guard = ConstantAddress::invalid()); |
3958 | |
3959 | |
3960 | |
3961 | void GenerateCXXGlobalDtorsFunc( |
3962 | llvm::Function *Fn, |
3963 | const std::vector<std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH, |
3964 | llvm::Constant *>> &DtorsAndObjects); |
3965 | |
3966 | void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, |
3967 | const VarDecl *D, |
3968 | llvm::GlobalVariable *Addr, |
3969 | bool PerformInit); |
3970 | |
3971 | void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest); |
3972 | |
3973 | void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp); |
3974 | |
3975 | void enterFullExpression(const FullExpr *E) { |
3976 | if (const auto *EWC = dyn_cast<ExprWithCleanups>(E)) |
3977 | if (EWC->getNumObjects() == 0) |
3978 | return; |
3979 | enterNonTrivialFullExpression(E); |
3980 | } |
3981 | void enterNonTrivialFullExpression(const FullExpr *E); |
3982 | |
3983 | void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true); |
3984 | |
3985 | RValue EmitAtomicExpr(AtomicExpr *E); |
3986 | |
3987 | |
3988 | |
3989 | |
3990 | |
3991 | |
3992 | llvm::Value *EmitAnnotationCall(llvm::Function *AnnotationFn, |
3993 | llvm::Value *AnnotatedVal, |
3994 | StringRef AnnotationStr, |
3995 | SourceLocation Location); |
3996 | |
3997 | |
3998 | void EmitVarAnnotations(const VarDecl *D, llvm::Value *V); |
3999 | |
4000 | |
4001 | |
4002 | Address EmitFieldAnnotations(const FieldDecl *D, Address V); |
4003 | |
4004 | |
4005 | |
4006 | |
4007 | |
4008 | |
4009 | |
4010 | |
4011 | static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); |
4012 | |
4013 | |
4014 | |
4015 | |
4016 | static bool containsBreak(const Stmt *S); |
4017 | |
4018 | |
4019 | |
4020 | static bool mightAddDeclToScope(const Stmt *S); |
4021 | |
4022 | |
4023 | |
4024 | |
4025 | bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, |
4026 | bool AllowLabels = false); |
4027 | |
4028 | |
4029 | |
4030 | |
4031 | bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result, |
4032 | bool AllowLabels = false); |
4033 | |
4034 | |
4035 | |
4036 | |
4037 | |
4038 | |
4039 | void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, |
4040 | llvm::BasicBlock *FalseBlock, uint64_t TrueCount); |
4041 | |
4042 | |
4043 | |
4044 | void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc); |
4045 | |
4046 | |
4047 | |
4048 | enum { NotSubtraction = false, IsSubtraction = true }; |
4049 | |
4050 | |
4051 | |
4052 | |
4053 | |
4054 | |
4055 | llvm::Value *EmitCheckedInBoundsGEP(llvm::Value *Ptr, |
4056 | ArrayRef<llvm::Value *> IdxList, |
4057 | bool SignedIndices, |
4058 | bool IsSubtraction, |
4059 | SourceLocation Loc, |
4060 | const Twine &Name = ""); |
4061 | |
4062 | |
4063 | |
4064 | enum BuiltinCheckKind { |
4065 | BCK_CTZPassedZero, |
4066 | BCK_CLZPassedZero, |
4067 | }; |
4068 | |
4069 | |
4070 | |
4071 | llvm::Value *EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind); |
4072 | |
4073 | |
4074 | |
4075 | llvm::Constant *EmitCheckTypeDescriptor(QualType T); |
4076 | |
4077 | |
4078 | |
4079 | llvm::Value *EmitCheckValue(llvm::Value *V); |
4080 | |
4081 | |
4082 | |
4083 | llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc); |
4084 | |
4085 | |
4086 | |
4087 | |
4088 | void EmitCheck(ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked, |
4089 | SanitizerHandler Check, ArrayRef<llvm::Constant *> StaticArgs, |
4090 | ArrayRef<llvm::Value *> DynamicArgs); |
4091 | |
4092 | |
4093 | |
4094 | void EmitCfiSlowPathCheck(SanitizerMask Kind, llvm::Value *Cond, |
4095 | llvm::ConstantInt *TypeId, llvm::Value *Ptr, |
4096 | ArrayRef<llvm::Constant *> StaticArgs); |
4097 | |
4098 | |
4099 | |
4100 | void EmitUnreachable(SourceLocation Loc); |
4101 | |
4102 | |
4103 | |
4104 | void EmitTrapCheck(llvm::Value *Checked); |
4105 | |
4106 | |
4107 | |
4108 | llvm::CallInst *EmitTrapCall(llvm::Intrinsic::ID IntrID); |
4109 | |
4110 | |
4111 | void EmitCfiCheckStub(); |
4112 | |
4113 | |
4114 | void EmitCfiCheckFail(); |
4115 | |
4116 | |
4117 | |
4118 | void EmitNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc, |
4119 | AbstractCallee AC, unsigned ParmNum); |
4120 | |
4121 | |
4122 | void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType); |
4123 | |
4124 | |
4125 | |
4126 | |
4127 | void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, |
4128 | SourceLocation loc); |
4129 | |
4130 | |
4131 | |
4132 | void SetFPAccuracy(llvm::Value *Val, float Accuracy); |
4133 | |
4134 | private: |
4135 | llvm::MDNode *getRangeForLoadFromType(QualType Ty); |
4136 | void EmitReturnOfRValue(RValue RV, QualType Ty); |
4137 | |
4138 | void deferPlaceholderReplacement(llvm::Instruction *Old, llvm::Value *New); |
4139 | |
4140 | llvm::SmallVector<std::pair<llvm::Instruction *, llvm::Value *>, 4> |
4141 | DeferredReplacements; |
4142 | |
4143 | |
4144 | void setAddrOfLocalVar(const VarDecl *VD, Address Addr) { |
4145 | (0) . __assert_fail ("!LocalDeclMap.count(VD) && \"Decl already exists in LocalDeclMap!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4145, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!LocalDeclMap.count(VD) && "Decl already exists in LocalDeclMap!"); |
4146 | LocalDeclMap.insert({VD, Addr}); |
4147 | } |
4148 | |
4149 | |
4150 | |
4151 | |
4152 | |
4153 | void ExpandTypeFromArgs(QualType Ty, LValue Dst, |
4154 | SmallVectorImpl<llvm::Value *>::iterator &AI); |
4155 | |
4156 | |
4157 | |
4158 | |
4159 | void ExpandTypeToArgs(QualType Ty, CallArg Arg, llvm::FunctionType *IRFuncTy, |
4160 | SmallVectorImpl<llvm::Value *> &IRCallArgs, |
4161 | unsigned &IRCallArgPos); |
4162 | |
4163 | llvm::Value* EmitAsmInput(const TargetInfo::ConstraintInfo &Info, |
4164 | const Expr *InputExpr, std::string &ConstraintStr); |
4165 | |
4166 | llvm::Value* EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info, |
4167 | LValue InputValue, QualType InputType, |
4168 | std::string &ConstraintStr, |
4169 | SourceLocation Loc); |
4170 | |
4171 | |
4172 | |
4173 | |
4174 | |
4175 | |
4176 | llvm::Value *evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, |
4177 | llvm::IntegerType *ResType, |
4178 | llvm::Value *EmittedE, |
4179 | bool IsDynamic); |
4180 | |
4181 | |
4182 | |
4183 | |
4184 | llvm::Value *emitBuiltinObjectSize(const Expr *E, unsigned Type, |
4185 | llvm::IntegerType *ResType, |
4186 | llvm::Value *EmittedE, |
4187 | bool IsDynamic); |
4188 | |
4189 | public: |
4190 | #ifndef NDEBUG |
4191 | |
4192 | |
4193 | static bool isObjCMethodWithTypeParams(const ObjCMethodDecl *method) { |
4194 | const DeclContext *dc = method->getDeclContext(); |
4195 | if (const ObjCInterfaceDecl *classDecl= dyn_cast<ObjCInterfaceDecl>(dc)) { |
4196 | return classDecl->getTypeParamListAsWritten(); |
4197 | } |
4198 | |
4199 | if (const ObjCCategoryDecl *catDecl = dyn_cast<ObjCCategoryDecl>(dc)) { |
4200 | return catDecl->getTypeParamList(); |
4201 | } |
4202 | |
4203 | return false; |
4204 | } |
4205 | |
4206 | template<typename T> |
4207 | static bool isObjCMethodWithTypeParams(const T *) { return false; } |
4208 | #endif |
4209 | |
4210 | enum class EvaluationOrder { |
4211 | |
4212 | Default, |
4213 | |
4214 | ForceLeftToRight, |
4215 | |
4216 | ForceRightToLeft |
4217 | }; |
4218 | |
4219 | |
4220 | template <typename T> |
4221 | void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, |
4222 | llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange, |
4223 | AbstractCallee AC = AbstractCallee(), |
4224 | unsigned ParamsToSkip = 0, |
4225 | EvaluationOrder Order = EvaluationOrder::Default) { |
4226 | SmallVector<QualType, 16> ArgTypes; |
4227 | CallExpr::const_arg_iterator Arg = ArgRange.begin(); |
4228 | |
4229 | (0) . __assert_fail ("(ParamsToSkip == 0 || CallArgTypeInfo) && \"Can't skip parameters if type info is not provided\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4230, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((ParamsToSkip == 0 || CallArgTypeInfo) && |
4230 | (0) . __assert_fail ("(ParamsToSkip == 0 || CallArgTypeInfo) && \"Can't skip parameters if type info is not provided\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4230, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Can't skip parameters if type info is not provided"); |
4231 | if (CallArgTypeInfo) { |
4232 | #ifndef NDEBUG |
4233 | bool isGenericMethod = isObjCMethodWithTypeParams(CallArgTypeInfo); |
4234 | #endif |
4235 | |
4236 | |
4237 | for (auto I = CallArgTypeInfo->param_type_begin() + ParamsToSkip, |
4238 | E = CallArgTypeInfo->param_type_end(); |
4239 | I != E; ++I, ++Arg) { |
4240 | (0) . __assert_fail ("Arg != ArgRange.end() && \"Running over edge of argument list!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4240, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Arg != ArgRange.end() && "Running over edge of argument list!"); |
4241 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((isGenericMethod || |
4242 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> ((*I)->isVariablyModifiedType() || |
4243 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> (*I).getNonReferenceType()->isObjCRetainableType() || |
4244 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> getContext() |
4245 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> .getCanonicalType((*I).getNonReferenceType()) |
4246 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> .getTypePtr() == |
4247 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> getContext() |
4248 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> .getCanonicalType((*Arg)->getType()) |
4249 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> .getTypePtr())) && |
4250 | (0) . __assert_fail ("(isGenericMethod || ((*I)->isVariablyModifiedType() || (*I).getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType((*I).getNonReferenceType()) .getTypePtr() == getContext() .getCanonicalType((*Arg)->getType()) .getTypePtr())) && \"type mismatch in call argument!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4250, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "type mismatch in call argument!"); |
4251 | ArgTypes.push_back(*I); |
4252 | } |
4253 | } |
4254 | |
4255 | |
4256 | |
4257 | (0) . __assert_fail ("(Arg == ArgRange.end() || !CallArgTypeInfo || CallArgTypeInfo->isVariadic()) && \"Extra arguments in non-variadic function!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4259, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Arg == ArgRange.end() || !CallArgTypeInfo || |
4258 | (0) . __assert_fail ("(Arg == ArgRange.end() || !CallArgTypeInfo || CallArgTypeInfo->isVariadic()) && \"Extra arguments in non-variadic function!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4259, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> CallArgTypeInfo->isVariadic()) && |
4259 | (0) . __assert_fail ("(Arg == ArgRange.end() || !CallArgTypeInfo || CallArgTypeInfo->isVariadic()) && \"Extra arguments in non-variadic function!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CodeGenFunction.h", 4259, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Extra arguments in non-variadic function!"); |
4260 | |
4261 | |
4262 | for (auto *A : llvm::make_range(Arg, ArgRange.end())) |
4263 | ArgTypes.push_back(CallArgTypeInfo ? getVarArgType(A) : A->getType()); |
4264 | |
4265 | EmitCallArgs(Args, ArgTypes, ArgRange, AC, ParamsToSkip, Order); |
4266 | } |
4267 | |
4268 | void EmitCallArgs(CallArgList &Args, ArrayRef<QualType> ArgTypes, |
4269 | llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange, |
4270 | AbstractCallee AC = AbstractCallee(), |
4271 | unsigned ParamsToSkip = 0, |
4272 | EvaluationOrder Order = EvaluationOrder::Default); |
4273 | |
4274 | |
4275 | |
4276 | |
4277 | |
4278 | |
4279 | |
4280 | |
4281 | |
4282 | |
4283 | |
4284 | |
4285 | |
4286 | |
4287 | |
4288 | |
4289 | |
4290 | |
4291 | Address EmitPointerWithAlignment(const Expr *Addr, |
4292 | LValueBaseInfo *BaseInfo = nullptr, |
4293 | TBAAAccessInfo *TBAAInfo = nullptr); |
4294 | |
4295 | |
4296 | |
4297 | |
4298 | llvm::Value *LoadPassedObjectSize(const Expr *E, QualType EltTy); |
4299 | |
4300 | void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK); |
4301 | |
4302 | struct MultiVersionResolverOption { |
4303 | llvm::Function *Function; |
4304 | FunctionDecl *FD; |
4305 | struct Conds { |
4306 | StringRef Architecture; |
4307 | llvm::SmallVector<StringRef, 8> Features; |
4308 | |
4309 | Conds(StringRef Arch, ArrayRef<StringRef> Feats) |
4310 | : Architecture(Arch), Features(Feats.begin(), Feats.end()) {} |
4311 | } Conditions; |
4312 | |
4313 | MultiVersionResolverOption(llvm::Function *F, StringRef Arch, |
4314 | ArrayRef<StringRef> Feats) |
4315 | : Function(F), Conditions(Arch, Feats) {} |
4316 | }; |
4317 | |
4318 | |
4319 | |
4320 | |
4321 | void EmitMultiVersionResolver(llvm::Function *Resolver, |
4322 | ArrayRef<MultiVersionResolverOption> Options); |
4323 | |
4324 | static uint64_t GetX86CpuSupportsMask(ArrayRef<StringRef> FeatureStrs); |
4325 | |
4326 | private: |
4327 | QualType getVarArgType(const Expr *Arg); |
4328 | |
4329 | void EmitDeclMetadata(); |
4330 | |
4331 | BlockByrefHelpers *buildByrefHelpers(llvm::StructType &byrefType, |
4332 | const AutoVarEmission &emission); |
4333 | |
4334 | void AddObjCARCExceptionMetadata(llvm::Instruction *Inst); |
4335 | |
4336 | llvm::Value *GetValueForARMHint(unsigned BuiltinID); |
4337 | llvm::Value *EmitX86CpuIs(const CallExpr *E); |
4338 | llvm::Value *EmitX86CpuIs(StringRef CPUStr); |
4339 | llvm::Value *EmitX86CpuSupports(const CallExpr *E); |
4340 | llvm::Value *EmitX86CpuSupports(ArrayRef<StringRef> FeatureStrs); |
4341 | llvm::Value *EmitX86CpuSupports(uint64_t Mask); |
4342 | llvm::Value *EmitX86CpuInit(); |
4343 | llvm::Value *FormResolverCondition(const MultiVersionResolverOption &RO); |
4344 | }; |
4345 | |
4346 | inline DominatingLLVMValue::saved_type |
4347 | DominatingLLVMValue::save(CodeGenFunction &CGF, llvm::Value *value) { |
4348 | if (!needsSaving(value)) return saved_type(value, false); |
4349 | |
4350 | |
4351 | auto align = CharUnits::fromQuantity( |
4352 | CGF.CGM.getDataLayout().getPrefTypeAlignment(value->getType())); |
4353 | Address alloca = |
4354 | CGF.CreateTempAlloca(value->getType(), align, "cond-cleanup.save"); |
4355 | CGF.Builder.CreateStore(value, alloca); |
4356 | |
4357 | return saved_type(alloca.getPointer(), true); |
4358 | } |
4359 | |
4360 | inline llvm::Value *DominatingLLVMValue::restore(CodeGenFunction &CGF, |
4361 | saved_type value) { |
4362 | |
4363 | if (!value.getInt()) return value.getPointer(); |
4364 | |
4365 | |
4366 | auto alloca = cast<llvm::AllocaInst>(value.getPointer()); |
4367 | return CGF.Builder.CreateAlignedLoad(alloca, alloca->getAlignment()); |
4368 | } |
4369 | |
4370 | } |
4371 | } |
4372 | |
4373 | #endif |
4374 | |