-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathSideEffectAnalysis.cpp
637 lines (568 loc) · 21.7 KB
/
SideEffectAnalysis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
//===--- SideEffectAnalysis.cpp - SIL Side Effect Analysis ----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "sil-sea"
#include "swift/SILOptimizer/Analysis/SideEffectAnalysis.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SILOptimizer/Analysis/AccessStorageAnalysis.h"
#include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
#include "swift/SILOptimizer/Analysis/FunctionOrder.h"
#include "swift/SILOptimizer/PassManager/PassManager.h"
using namespace swift;
// -----------------------------------------------------------------------------
// GenericFunctionEffectAnalysis
// -----------------------------------------------------------------------------
template <typename FunctionEffects>
void GenericFunctionEffectAnalysis<FunctionEffects>::initialize(
SILPassManager *PM) {
BCA = PM->getAnalysis<BasicCalleeAnalysis>();
}
template <typename FunctionEffects>
void GenericFunctionEffectAnalysis<FunctionEffects>::invalidate() {
functionInfoMap.clear();
allocator.DestroyAll();
LLVM_DEBUG(llvm::dbgs() << "invalidate all\n");
}
template <typename FunctionEffects>
void GenericFunctionEffectAnalysis<FunctionEffects>::invalidate(
SILFunction *F, InvalidationKind K) {
if (FunctionInfo *FInfo = functionInfoMap.lookup(F)) {
LLVM_DEBUG(llvm::dbgs() << " invalidate " << FInfo->F->getName() << '\n');
invalidateIncludingAllCallers(FInfo);
}
}
template <typename FunctionEffects>
void GenericFunctionEffectAnalysis<FunctionEffects>::getCalleeEffects(
FunctionEffects &calleeEffects, FullApplySite fullApply) {
if (calleeEffects.summarizeCall(fullApply))
return;
auto callees = BCA->getCalleeList(fullApply);
if (!callees.allCalleesVisible() ||
// @callee_owned function calls implicitly release the context, which
// may call deinits of boxed values.
// TODO: be less conservative about what destructors might be called.
fullApply.getOrigCalleeType()->isCalleeConsumed()) {
calleeEffects.setWorstEffects();
return;
}
// We can see all the callees, so merge the effects from all of them.
for (auto *callee : callees)
calleeEffects.mergeFrom(getEffects(callee));
}
template <typename FunctionEffects>
void GenericFunctionEffectAnalysis<FunctionEffects>::analyzeFunction(
FunctionInfo *functionInfo, FunctionOrder &bottomUpOrder,
int recursionDepth) {
functionInfo->needUpdateCallers = true;
if (bottomUpOrder.prepareForVisiting(functionInfo))
return;
auto *F = functionInfo->F;
if (functionInfo->functionEffects.summarizeFunction(F))
return;
LLVM_DEBUG(llvm::dbgs() << " >> analyze " << F->getName() << '\n');
// Check all instructions of the function
for (auto &BB : *F) {
for (auto &I : BB) {
if (auto fullApply = FullApplySite::isa(&I))
analyzeCall(functionInfo, fullApply, bottomUpOrder, recursionDepth);
else
functionInfo->functionEffects.analyzeInstruction(&I);
}
}
LLVM_DEBUG(llvm::dbgs() << " << finished " << F->getName() << '\n');
}
template <typename FunctionEffects>
void GenericFunctionEffectAnalysis<FunctionEffects>::analyzeCall(
FunctionInfo *functionInfo, FullApplySite fullApply,
FunctionOrder &bottomUpOrder, int recursionDepth) {
FunctionEffects applyEffects;
if (applyEffects.summarizeCall(fullApply)) {
functionInfo->functionEffects.mergeFromApply(applyEffects, fullApply);
return;
}
if (recursionDepth >= MaxRecursionDepth) {
functionInfo->functionEffects.setWorstEffects();
return;
}
CalleeList callees = BCA->getCalleeList(fullApply);
if (!callees.allCalleesVisible() ||
// @callee_owned function calls implicitly release the context, which
// may call deinits of boxed values.
// TODO: be less conservative about what destructors might be called.
fullApply.getOrigCalleeType()->isCalleeConsumed()) {
functionInfo->functionEffects.setWorstEffects();
return;
}
// Derive the effects of the apply from the known callees.
// Defer merging callee effects until the callee is scheduled
for (SILFunction *callee : callees) {
FunctionInfo *calleeInfo = getFunctionInfo(callee);
calleeInfo->addCaller(functionInfo, fullApply);
if (!calleeInfo->isVisited()) {
// Recursively visit the called function.
analyzeFunction(calleeInfo, bottomUpOrder, recursionDepth + 1);
bottomUpOrder.tryToSchedule(calleeInfo);
}
}
}
template <typename FunctionEffects>
void GenericFunctionEffectAnalysis<FunctionEffects>::recompute(
FunctionInfo *initialInfo) {
allocNewUpdateID();
LLVM_DEBUG(llvm::dbgs() << "recompute function-effect analysis with UpdateID "
<< getCurrentUpdateID() << '\n');
// Collect and analyze all functions to recompute, starting at initialInfo.
FunctionOrder bottomUpOrder(getCurrentUpdateID());
analyzeFunction(initialInfo, bottomUpOrder, 0);
// Build the bottom-up order.
bottomUpOrder.tryToSchedule(initialInfo);
bottomUpOrder.finishScheduling();
// Second step: propagate the side-effect information up the call-graph until
// it stabilizes.
bool needAnotherIteration;
do {
LLVM_DEBUG(llvm::dbgs() << "new iteration\n");
needAnotherIteration = false;
for (FunctionInfo *functionInfo : bottomUpOrder) {
if (!functionInfo->needUpdateCallers)
continue;
LLVM_DEBUG(llvm::dbgs() << " update callers of "
<< functionInfo->F->getName() << '\n');
functionInfo->needUpdateCallers = false;
// Propagate the function effects to all callers.
for (const auto &E : functionInfo->getCallers()) {
assert(E.isValid());
// Only include callers which we are actually recomputing.
if (!bottomUpOrder.wasRecomputedWithCurrentUpdateID(E.Caller))
continue;
LLVM_DEBUG(llvm::dbgs() << " merge into caller "
<< E.Caller->F->getName() << '\n');
if (E.Caller->functionEffects.mergeFromApply(
functionInfo->functionEffects, FullApplySite(E.FAS))) {
E.Caller->needUpdateCallers = true;
if (!E.Caller->isScheduledAfter(functionInfo)) {
// This happens if we have a cycle in the call-graph.
needAnotherIteration = true;
}
}
}
}
} while (needAnotherIteration);
}
// Instantiate template members.
template class swift::GenericFunctionEffectAnalysis<FunctionSideEffects>;
template class swift::GenericFunctionEffectAnalysis<FunctionAccessStorage>;
// -----------------------------------------------------------------------------
// FunctionSideEffects
// -----------------------------------------------------------------------------
using MemoryBehavior = SILInstruction::MemoryBehavior;
MemoryBehavior
FunctionSideEffects::getMemBehavior(RetainObserveKind ScanKind) const {
bool Observe = (ScanKind == RetainObserveKind::ObserveRetains);
if ((Observe && mayAllocObjects()) || mayReadRC())
return MemoryBehavior::MayHaveSideEffects;
// Start with the global effects.
auto Behavior = GlobalEffects.getMemBehavior(ScanKind);
// Add effects from the parameters.
for (auto &ParamEffect : ParamEffects) {
MemoryBehavior ArgBehavior = ParamEffect.getMemBehavior(ScanKind);
Behavior = combineMemoryBehavior(Behavior, ArgBehavior);
// Stop the scan if we've reached the highest level of side effect.
if (Behavior == MemoryBehavior::MayHaveSideEffects)
break;
}
return Behavior;
}
MemoryBehavior
FunctionSideEffects::getArgumentBehavior(FullApplySite applySite,
unsigned argIdx) {
// The overall argument effect is the combination of the argument and the
// global effects.
MemoryBehavior behavior =
GlobalEffects.getMemBehavior(RetainObserveKind::IgnoreRetains);
MemoryBehavior argBehavior =
ParamEffects[argIdx].getMemBehavior(RetainObserveKind::IgnoreRetains);
behavior = combineMemoryBehavior(behavior, argBehavior);
if (behavior > MemoryBehavior::MayRead &&
applySite.getArgumentConvention(applySite.getArgumentRef(argIdx)) ==
SILArgumentConvention::Indirect_In_Guaranteed) {
// Even if side-effect analysis doesn't know anything about the called
// called function, the in_guaranteed convention guarantees that the
// argument is never written to.
return MemoryBehavior::MayRead;
}
return behavior;
}
bool FunctionSideEffects::mergeFrom(const FunctionSideEffects &RHS) {
bool Changed = mergeFlags(RHS);
Changed |= GlobalEffects.mergeFrom(RHS.GlobalEffects);
Changed |= LocalEffects.mergeFrom(RHS.LocalEffects);
// In case of an external function, the RHS may have 0 arguments.
unsigned NumArgs = RHS.ParamEffects.size();
for (unsigned Idx = 0; Idx < NumArgs; Idx++) {
// In case of a partial_apply, the RHS (= callee) may have more arguments
// than the apply instruction.
if (Idx < ParamEffects.size()) {
Changed |= ParamEffects[Idx].mergeFrom(RHS.ParamEffects[Idx]);
} else {
Changed |= GlobalEffects.mergeFrom(RHS.ParamEffects[Idx]);
}
}
return Changed;
}
bool FunctionSideEffects::mergeFromApply(
const FunctionSideEffects &ApplyEffects, FullApplySite FAS) {
bool Changed = mergeFlags(ApplyEffects);
Changed |= GlobalEffects.mergeFrom(ApplyEffects.GlobalEffects);
unsigned numCallerArgs = FAS.getNumArguments();
unsigned numCalleeArgs = ApplyEffects.ParamEffects.size();
assert(numCalleeArgs >= numCallerArgs);
for (unsigned Idx = 0; Idx < numCalleeArgs; Idx++) {
// Map the callee argument effects to parameters of this function.
// If there are more callee parameters than arguments it means that the
// callee is the result of a partial_apply.
FunctionSideEffectFlags *E = (Idx < numCallerArgs
? getEffectsOn(FAS.getArgument(Idx))
: &GlobalEffects);
Changed |= E->mergeFrom(ApplyEffects.ParamEffects[Idx]);
}
return Changed;
}
void FunctionSideEffects::dump() const { llvm::errs() << *this << '\n'; }
static SILValue skipAddrProjections(SILValue V) {
for (;;) {
switch (V->getKind()) {
case ValueKind::IndexAddrInst:
case ValueKind::IndexRawPointerInst:
case ValueKind::StructElementAddrInst:
case ValueKind::TupleElementAddrInst:
case ValueKind::RefElementAddrInst:
case ValueKind::RefTailAddrInst:
case ValueKind::ProjectBoxInst:
case ValueKind::UncheckedTakeEnumDataAddrInst:
case ValueKind::PointerToAddressInst:
V = cast<SingleValueInstruction>(V)->getOperand(0);
break;
default:
return V;
}
}
llvm_unreachable("there is no escape from an infinite loop");
}
static SILValue skipValueProjections(SILValue V) {
for (;;) {
switch (V->getKind()) {
case ValueKind::StructExtractInst:
case ValueKind::TupleExtractInst:
case ValueKind::UncheckedEnumDataInst:
case ValueKind::UncheckedTrivialBitCastInst:
case ValueKind::UncheckedRefCastInst:
V = cast<SingleValueInstruction>(V)->getOperand(0);
break;
default:
return V;
}
}
llvm_unreachable("there is no escape from an infinite loop");
}
FunctionSideEffectFlags *FunctionSideEffects::getEffectsOn(SILValue Addr) {
SILValue BaseAddr = skipValueProjections(skipAddrProjections(Addr));
switch (BaseAddr->getKind()) {
case swift::ValueKind::SILFunctionArgument: {
// Can we associate the address to a function parameter?
auto *Arg = cast<SILFunctionArgument>(BaseAddr);
return &ParamEffects[Arg->getIndex()];
break;
}
case ValueKind::AllocStackInst:
case ValueKind::AllocRefInst:
case ValueKind::AllocRefDynamicInst:
case ValueKind::AllocBoxInst:
// Effects on locally allocated storage.
return &LocalEffects;
default:
break;
}
// Everything else.
return &GlobalEffects;
}
// Return true if the given function has defined effects that were successfully
// recorded in this FunctionSideEffects object.
bool FunctionSideEffects::setDefinedEffects(SILFunction *F) {
if (F->hasSemanticsAttr(SEMANTICS_PROGRAMTERMINATION_POINT)) {
Traps = true;
return true;
}
switch (F->getEffectsKind()) {
case EffectsKind::ReleaseNone:
GlobalEffects.Reads = true;
GlobalEffects.Writes = true;
GlobalEffects.Releases = false;
return true;
case EffectsKind::ReadNone:
return true;
case EffectsKind::ReadOnly:
// @_effects(readonly) is worthless if we have owned parameters, because
// the release inside the callee may call a deinit, which itself can do
// anything.
if (!F->hasOwnedParameters()) {
GlobalEffects.Reads = true;
return true;
}
break;
default:
break;
}
return false;
}
// Return true if this function's effects have been fully summarized in this
// FunctionSideEffects object without visiting its body.
bool FunctionSideEffects::summarizeFunction(SILFunction *F) {
assert(ParamEffects.empty() && "Expect uninitialized effects.");
if (F->isDynamicallyReplaceable()) {
LLVM_DEBUG(llvm::dbgs()
<< " -- is dynamically_replaceable " << F->getName() << '\n');
setWorstEffects();
return true;
}
if (!F->empty())
ParamEffects.resize(F->getArguments().size());
// Handle @_effects attributes
if (setDefinedEffects(F)) {
LLVM_DEBUG(llvm::dbgs() << " -- has defined effects " << F->getName()
<< '\n');
return true;
}
if (!F->isDefinition()) {
// We can't assume anything about external functions.
LLVM_DEBUG(llvm::dbgs() << " -- is external " << F->getName() << '\n');
setWorstEffects();
return true;
}
return false;
}
// Return true if the side effects of this semantic call are fully known without
// visiting the callee and have been recorded in this FunctionSideEffects
// object.
bool FunctionSideEffects::setSemanticEffects(ArraySemanticsCall ASC) {
assert(ASC.hasSelf());
auto &SelfEffects = ParamEffects[ParamEffects.size() - 1];
// Currently we only handle array semantics.
// TODO: also handle other semantic functions.
switch (ASC.getKind()) {
case ArrayCallKind::kGetCount:
case ArrayCallKind::kGetCapacity:
if (!ASC.mayHaveBridgedObjectElementType()) {
SelfEffects.Reads = true;
SelfEffects.Releases |= !ASC.hasGuaranteedSelf();
return true;
}
return false;
case ArrayCallKind::kCheckSubscript:
case ArrayCallKind::kCheckIndex:
if (!ASC.mayHaveBridgedObjectElementType()) {
SelfEffects.Reads = true;
SelfEffects.Releases |= !ASC.hasGuaranteedSelf();
Traps = true;
return true;
}
return false;
case ArrayCallKind::kGetElement:
if (!ASC.mayHaveBridgedObjectElementType()) {
SelfEffects.Reads = true;
SelfEffects.Releases |= !ASC.hasGuaranteedSelf();
for (auto i : range(((ApplyInst *)ASC)
->getOrigCalleeConv()
.getNumIndirectSILResults())) {
assert(!ASC.hasGetElementDirectResult());
ParamEffects[i].Writes = true;
}
return true;
}
return false;
case ArrayCallKind::kArrayPropsIsNativeTypeChecked:
SelfEffects.Releases |= !ASC.hasGuaranteedSelf();
// The isNative checks evaluate to a constant (no read!) if the array
// cannot be bridged.
if (ASC.mayHaveBridgedObjectElementType())
SelfEffects.Reads = true;
return true;
case ArrayCallKind::kGetElementAddress:
SelfEffects.Reads = true;
SelfEffects.Releases |= !ASC.hasGuaranteedSelf();
return true;
case ArrayCallKind::kMakeMutable:
if (!ASC.mayHaveBridgedObjectElementType()) {
SelfEffects.Writes = true;
GlobalEffects.Releases = true;
AllocsObjects = true;
ReadsRC = true;
return true;
}
return false;
default:
return false;
}
}
// Summarize the callee side effects of a call instruction using this
// FunctionSideEffects object without analyzing the callee function bodies or
// scheduling the callees for bottom-up propagation.
//
// Return true if this call-site's effects are summarized without visiting the
// callee.
bool FunctionSideEffects::summarizeCall(FullApplySite fullApply) {
assert(ParamEffects.empty() && "Expect uninitialized effects.");
ParamEffects.resize(fullApply.getNumArguments());
// Is this a call to a semantics function?
if (auto apply = dyn_cast<ApplyInst>(fullApply.getInstruction())) {
ArraySemanticsCall ASC(apply);
if (ASC && ASC.hasSelf()) {
if (setSemanticEffects(ASC))
return true;
}
}
if (SILFunction *SingleCallee = fullApply.getReferencedFunctionOrNull()) {
// Does the function have any @_effects?
if (setDefinedEffects(SingleCallee))
return true;
}
return false;
}
void FunctionSideEffects::analyzeInstruction(SILInstruction *I) {
// Handle some kind of instructions specially.
switch (I->getKind()) {
case SILInstructionKind::FixLifetimeInst:
// A fix_lifetime instruction acts like a read on the operand. Retains can
// move after it but the last release can't move before it.
getEffectsOn(I->getOperand(0))->Reads = true;
return;
case SILInstructionKind::AllocStackInst:
case SILInstructionKind::DeallocStackInst:
return;
#define UNCHECKED_REF_CAST(Name, ...) \
case SILInstructionKind::Name##RetainValueInst: \
case SILInstructionKind::StrongCopy##Name##ValueInst:
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
case SILInstructionKind::Name##RetainInst: \
case SILInstructionKind::StrongRetain##Name##Inst: \
case SILInstructionKind::StrongCopy##Name##ValueInst:
#include "swift/AST/ReferenceStorage.def"
case SILInstructionKind::StrongRetainInst:
case SILInstructionKind::RetainValueInst:
getEffectsOn(I->getOperand(0))->Retains = true;
return;
#define UNCHECKED_REF_STORAGE(Name, ...) \
case SILInstructionKind::Name##ReleaseValueInst:
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
case SILInstructionKind::Name##ReleaseInst:
#include "swift/AST/ReferenceStorage.def"
case SILInstructionKind::StrongReleaseInst:
case SILInstructionKind::ReleaseValueInst:
getEffectsOn(I->getOperand(0))->Releases = true;
return;
case SILInstructionKind::UnconditionalCheckedCastInst:
getEffectsOn(cast<UnconditionalCheckedCastInst>(I)->getOperand())->Reads =
true;
Traps = true;
return;
case SILInstructionKind::LoadBorrowInst: {
auto *effects = getEffectsOn(cast<LoadBorrowInst>(I)->getOperand());
effects->Reads = true;
return;
}
case SILInstructionKind::LoadInst: {
auto *li = cast<LoadInst>(I);
auto *effects = getEffectsOn(cast<LoadInst>(I)->getOperand());
effects->Reads = true;
if (li->getOwnershipQualifier() == LoadOwnershipQualifier::Take)
effects->Writes = true;
if (li->getOwnershipQualifier() == LoadOwnershipQualifier::Copy)
effects->Retains = true;
return;
}
case SILInstructionKind::StoreInst: {
auto *si = cast<StoreInst>(I);
auto *effects = getEffectsOn(si->getDest());
effects->Writes = true;
if (si->getOwnershipQualifier() == StoreOwnershipQualifier::Assign)
effects->Releases = true;
return;
}
case SILInstructionKind::CondFailInst:
Traps = true;
return;
case SILInstructionKind::PartialApplyInst: {
AllocsObjects = true;
auto *PAI = cast<PartialApplyInst>(I);
auto Args = PAI->getArguments();
auto Params = PAI->getSubstCalleeType()->getParameters();
Params = Params.slice(Params.size() - Args.size(), Args.size());
for (unsigned Idx : indices(Args)) {
if (isIndirectFormalParameter(Params[Idx].getConvention()))
getEffectsOn(Args[Idx])->Reads = true;
}
return;
}
case SILInstructionKind::BuiltinInst: {
auto *BInst = cast<BuiltinInst>(I);
auto &BI = BInst->getBuiltinInfo();
switch (BI.ID) {
case BuiltinValueKind::IsUnique:
// TODO: derive this information in a more general way, e.g. add it
// to Builtins.def
ReadsRC = true;
break;
case BuiltinValueKind::CondUnreachable:
Traps = true;
return;
default:
break;
}
const IntrinsicInfo &IInfo = BInst->getIntrinsicInfo();
if (IInfo.ID == llvm::Intrinsic::trap) {
Traps = true;
return;
}
// Detailed memory effects of builtins are handled below by checking the
// memory behavior of the instruction.
break;
}
default:
break;
}
if (isa<AllocationInst>(I)) {
// Excluding AllocStackInst (which is handled above).
AllocsObjects = true;
}
// Check the general memory behavior for instructions we didn't handle above.
switch (I->getMemoryBehavior()) {
case MemoryBehavior::None:
break;
case MemoryBehavior::MayRead:
GlobalEffects.Reads = true;
break;
case MemoryBehavior::MayWrite:
GlobalEffects.Writes = true;
break;
case MemoryBehavior::MayReadWrite:
GlobalEffects.Reads = true;
GlobalEffects.Writes = true;
break;
case MemoryBehavior::MayHaveSideEffects:
setWorstEffects();
break;
}
if (I->mayTrap())
Traps = true;
}
SILAnalysis *swift::createSideEffectAnalysis(SILModule *M) {
return new SideEffectAnalysis();
}