Coverage Report

Created: 2018-02-20 12:54

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/Analysis/ScopDetectionDiagnostic.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ScopDetectionDiagnostic.cpp - Error diagnostics --------------------===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// Small set of diagnostic helper classes to encapsulate any errors occurred
11
// during the detection of Scops.
12
//
13
// The ScopDetection defines a set of error classes (via Statistic variables)
14
// that groups a number of individual errors into a group, e.g. non-affinity
15
// related errors.
16
// On error we generate an object that carries enough additional information
17
// to diagnose the error and generate a helpful error message.
18
//
19
//===----------------------------------------------------------------------===//
20
21
#include "polly/ScopDetectionDiagnostic.h"
22
#include "llvm/ADT/SmallPtrSet.h"
23
#include "llvm/ADT/SmallVector.h"
24
#include "llvm/ADT/Statistic.h"
25
#include "llvm/ADT/StringRef.h"
26
#include "llvm/ADT/Twine.h"
27
#include "llvm/Analysis/AliasSetTracker.h"
28
#include "llvm/Analysis/LoopInfo.h"
29
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
30
#include "llvm/Analysis/RegionInfo.h"
31
#include "llvm/Analysis/ScalarEvolution.h"
32
#include "llvm/IR/BasicBlock.h"
33
#include "llvm/IR/CFG.h"
34
#include "llvm/IR/DebugLoc.h"
35
#include "llvm/IR/DiagnosticInfo.h"
36
#include "llvm/IR/Instruction.h"
37
#include "llvm/IR/Value.h"
38
#include "llvm/Support/raw_ostream.h"
39
#include <algorithm>
40
#include <cassert>
41
#include <string>
42
#include <utility>
43
44
using namespace llvm;
45
46
1.40k
#define DEBUG_TYPE "polly-detect"
47
48
#define SCOP_STAT(NAME, DESC)                                                  \
49
  {                                                                            \
50
    "polly-detect", "NAME", "Number of rejected regions: " DESC, {0}, {        \
51
      false                                                                    \
52
    }                                                                          \
53
  }
54
55
Statistic RejectStatistics[] = {
56
    SCOP_STAT(CFG, ""),
57
    SCOP_STAT(InvalidTerminator, "Unsupported terminator instruction"),
58
    SCOP_STAT(UnreachableInExit, "Unreachable in exit block"),
59
    SCOP_STAT(IrreducibleRegion, "Irreducible loops"),
60
    SCOP_STAT(LastCFG, ""),
61
    SCOP_STAT(AffFunc, ""),
62
    SCOP_STAT(UndefCond, "Undefined branch condition"),
63
    SCOP_STAT(InvalidCond, "Non-integer branch condition"),
64
    SCOP_STAT(UndefOperand, "Undefined operands in comparison"),
65
    SCOP_STAT(NonAffBranch, "Non-affine branch condition"),
66
    SCOP_STAT(NoBasePtr, "No base pointer"),
67
    SCOP_STAT(UndefBasePtr, "Undefined base pointer"),
68
    SCOP_STAT(VariantBasePtr, "Variant base pointer"),
69
    SCOP_STAT(NonAffineAccess, "Non-affine memory accesses"),
70
    SCOP_STAT(DifferentElementSize, "Accesses with differing sizes"),
71
    SCOP_STAT(LastAffFunc, ""),
72
    SCOP_STAT(LoopBound, "Uncomputable loop bounds"),
73
    SCOP_STAT(LoopHasNoExit, "Loop without exit"),
74
    SCOP_STAT(LoopOnlySomeLatches, "Not all loop latches in scop"),
75
    SCOP_STAT(FuncCall, "Function call with side effects"),
76
    SCOP_STAT(NonSimpleMemoryAccess,
77
              "Compilated access semantics (volatile or atomic)"),
78
    SCOP_STAT(Alias, "Base address aliasing"),
79
    SCOP_STAT(Other, ""),
80
    SCOP_STAT(IntToPtr, "Integer to pointer conversions"),
81
    SCOP_STAT(Alloca, "Stack allocations"),
82
    SCOP_STAT(UnknownInst, "Unknown Instructions"),
83
    SCOP_STAT(Entry, "Contains entry block"),
84
    SCOP_STAT(Unprofitable, "Assumed to be unprofitable"),
85
    SCOP_STAT(LastOther, ""),
86
};
87
88
namespace polly {
89
90
/// Small string conversion via raw_string_stream.
91
0
template <typename T> std::string operator+(Twine LHS, const T &RHS) {
92
0
  std::string Buf;
93
0
  raw_string_ostream fmt(Buf);
94
0
  fmt << RHS;
95
0
  fmt.flush();
96
0
97
0
  return LHS.concat(Buf).str();
98
0
}
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > polly::operator+<llvm::SCEV>(llvm::Twine, llvm::SCEV const&)
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > polly::operator+<llvm::Value>(llvm::Twine, llvm::Value const&)
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > polly::operator+<llvm::StringRef>(llvm::Twine, llvm::StringRef const&)
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > polly::operator+<char [14]>(llvm::Twine, char const (&) [14])
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > polly::operator+<char [15]>(llvm::Twine, char const (&) [15])
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > polly::operator+<llvm::Instruction>(llvm::Twine, llvm::Instruction const&)
99
100
} // namespace polly
101
102
namespace llvm {
103
104
// Lexicographic order on (line, col) of our debug locations.
105
846
static bool operator<(const DebugLoc &LHS, const DebugLoc &RHS) {
106
846
  return LHS.getLine() < RHS.getLine() ||
107
846
         
(784
LHS.getLine() == RHS.getLine()784
&&
LHS.getCol() < RHS.getCol()303
);
108
846
}
109
110
} // namespace llvm
111
112
namespace polly {
113
114
10.2k
BBPair getBBPairForRegion(const Region *R) {
115
10.2k
  return std::make_pair(R->getEntry(), R->getExit());
116
10.2k
}
117
118
1.62k
void getDebugLocations(const BBPair &P, DebugLoc &Begin, DebugLoc &End) {
119
1.62k
  SmallPtrSet<BasicBlock *, 32> Seen;
120
1.62k
  SmallVector<BasicBlock *, 32> Todo;
121
1.62k
  Todo.push_back(P.first);
122
14.7k
  while (!Todo.empty()) {
123
13.1k
    auto *BB = Todo.pop_back_val();
124
13.1k
    if (BB == P.second)
125
2.21k
      continue;
126
10.9k
    if (!Seen.insert(BB).second)
127
2.90k
      continue;
128
8.02k
    Todo.append(succ_begin(BB), succ_end(BB));
129
27.7k
    for (const Instruction &Inst : *BB) {
130
27.7k
      DebugLoc DL = Inst.getDebugLoc();
131
27.7k
      if (!DL)
132
27.2k
        continue;
133
448
134
448
      Begin = Begin ? 
std::min(Begin, DL)423
:
DL25
;
135
448
      End = End ? 
std::max(End, DL)423
:
DL25
;
136
448
    }
137
8.02k
  }
138
1.62k
}
139
140
void emitRejectionRemarks(const BBPair &P, const RejectLog &Log,
141
432
                          OptimizationRemarkEmitter &ORE) {
142
432
  DebugLoc Begin, End;
143
432
  getDebugLocations(P, Begin, End);
144
432
145
432
  ORE.emit(
146
432
      OptimizationRemarkMissed(DEBUG_TYPE, "RejectionErrors", Begin, P.first)
147
432
      << "The following errors keep this region from being a Scop.");
148
432
149
538
  for (RejectReasonPtr RR : Log) {
150
538
151
538
    if (const DebugLoc &Loc = RR->getDebugLoc())
152
30
      ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, RR->getRemarkName(), Loc,
153
30
                                        RR->getRemarkBB())
154
30
               << RR->getEndUserMessage());
155
508
    else
156
508
      ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, RR->getRemarkName(), Begin,
157
508
                                        RR->getRemarkBB())
158
508
               << RR->getEndUserMessage());
159
538
  }
160
432
161
432
  /* Check to see if Region is a top level region, getExit = NULL*/
162
432
  if (P.second)
163
431
    ORE.emit(
164
431
        OptimizationRemarkMissed(DEBUG_TYPE, "InvalidScopEnd", End, P.second)
165
431
        << "Invalid Scop candidate ends here.");
166
1
  else
167
1
    ORE.emit(
168
1
        OptimizationRemarkMissed(DEBUG_TYPE, "InvalidScopEnd", End, P.first)
169
1
        << "Invalid Scop candidate ends here.");
170
432
}
171
172
//===----------------------------------------------------------------------===//
173
// RejectReason.
174
175
594
RejectReason::RejectReason(RejectReasonKind K) : Kind(K) {
176
594
  RejectStatistics[static_cast<int>(K)]++;
177
594
}
178
179
const DebugLoc RejectReason::Unknown = DebugLoc();
180
181
0
const DebugLoc &RejectReason::getDebugLoc() const {
182
0
  // Allocate an empty DebugLoc and return it a reference to it.
183
0
  return Unknown;
184
0
}
185
186
// RejectLog.
187
0
void RejectLog::print(raw_ostream &OS, int level) const {
188
0
  int j = 0;
189
0
  for (auto Reason : ErrorReports)
190
0
    OS.indent(level) << "[" << j++ << "] " << Reason->getMessage() << "\n";
191
0
}
192
193
//===----------------------------------------------------------------------===//
194
// ReportCFG.
195
196
27
ReportCFG::ReportCFG(const RejectReasonKind K) : RejectReason(K) {}
197
198
0
bool ReportCFG::classof(const RejectReason *RR) {
199
0
  return RR->getKind() >= RejectReasonKind::CFG &&
200
0
         RR->getKind() <= RejectReasonKind::LastCFG;
201
0
}
202
203
//===----------------------------------------------------------------------===//
204
// ReportInvalidTerminator.
205
206
0
std::string ReportInvalidTerminator::getRemarkName() const {
207
0
  return "InvalidTerminator";
208
0
}
209
210
0
const Value *ReportInvalidTerminator::getRemarkBB() const { return BB; }
211
212
0
std::string ReportInvalidTerminator::getMessage() const {
213
0
  return ("Invalid instruction terminates BB: " + BB->getName()).str();
214
0
}
215
216
0
const DebugLoc &ReportInvalidTerminator::getDebugLoc() const {
217
0
  return BB->getTerminator()->getDebugLoc();
218
0
}
219
220
0
bool ReportInvalidTerminator::classof(const RejectReason *RR) {
221
0
  return RR->getKind() == RejectReasonKind::InvalidTerminator;
222
0
}
223
224
//===----------------------------------------------------------------------===//
225
// UnreachableInExit.
226
227
22
std::string ReportUnreachableInExit::getRemarkName() const {
228
22
  return "UnreachableInExit";
229
22
}
230
231
22
const Value *ReportUnreachableInExit::getRemarkBB() const { return BB; }
232
233
0
std::string ReportUnreachableInExit::getMessage() const {
234
0
  std::string BBName = BB->getName();
235
0
  return "Unreachable in exit block" + BBName;
236
0
}
237
238
22
const DebugLoc &ReportUnreachableInExit::getDebugLoc() const { return DbgLoc; }
239
240
22
std::string ReportUnreachableInExit::getEndUserMessage() const {
241
22
  return "Unreachable in exit block.";
242
22
}
243
244
0
bool ReportUnreachableInExit::classof(const RejectReason *RR) {
245
0
  return RR->getKind() == RejectReasonKind::UnreachableInExit;
246
0
}
247
248
//===----------------------------------------------------------------------===//
249
// ReportIrreducibleRegion.
250
251
3
std::string ReportIrreducibleRegion::getRemarkName() const {
252
3
  return "IrreducibleRegion";
253
3
}
254
255
3
const Value *ReportIrreducibleRegion::getRemarkBB() const {
256
3
  return R->getEntry();
257
3
}
258
259
0
std::string ReportIrreducibleRegion::getMessage() const {
260
0
  return "Irreducible region encountered: " + R->getNameStr();
261
0
}
262
263
3
const DebugLoc &ReportIrreducibleRegion::getDebugLoc() const { return DbgLoc; }
264
265
3
std::string ReportIrreducibleRegion::getEndUserMessage() const {
266
3
  return "Irreducible region encountered in control flow.";
267
3
}
268
269
0
bool ReportIrreducibleRegion::classof(const RejectReason *RR) {
270
0
  return RR->getKind() == RejectReasonKind::IrreducibleRegion;
271
0
}
272
273
//===----------------------------------------------------------------------===//
274
// ReportAffFunc.
275
276
ReportAffFunc::ReportAffFunc(const RejectReasonKind K, const Instruction *Inst)
277
244
    : RejectReason(K), Inst(Inst) {}
278
279
0
bool ReportAffFunc::classof(const RejectReason *RR) {
280
0
  return RR->getKind() >= RejectReasonKind::AffFunc &&
281
0
         RR->getKind() <= RejectReasonKind::LastAffFunc;
282
0
}
283
284
//===----------------------------------------------------------------------===//
285
// ReportUndefCond.
286
287
146
std::string ReportUndefCond::getRemarkName() const { return "UndefCond"; }
288
289
146
const Value *ReportUndefCond::getRemarkBB() const { return BB; }
290
291
0
std::string ReportUndefCond::getMessage() const {
292
0
  return ("Condition based on 'undef' value in BB: " + BB->getName()).str();
293
0
}
294
295
0
bool ReportUndefCond::classof(const RejectReason *RR) {
296
0
  return RR->getKind() == RejectReasonKind::UndefCond;
297
0
}
298
299
//===----------------------------------------------------------------------===//
300
// ReportInvalidCond.
301
302
1
std::string ReportInvalidCond::getRemarkName() const { return "InvalidCond"; }
303
304
1
const Value *ReportInvalidCond::getRemarkBB() const { return BB; }
305
306
0
std::string ReportInvalidCond::getMessage() const {
307
0
  return ("Condition in BB '" + BB->getName()).str() +
308
0
         "' neither constant nor an icmp instruction";
309
0
}
310
311
0
bool ReportInvalidCond::classof(const RejectReason *RR) {
312
0
  return RR->getKind() == RejectReasonKind::InvalidCond;
313
0
}
314
315
//===----------------------------------------------------------------------===//
316
// ReportUndefOperand.
317
318
5
std::string ReportUndefOperand::getRemarkName() const { return "UndefOperand"; }
319
320
5
const Value *ReportUndefOperand::getRemarkBB() const { return BB; }
321
322
0
std::string ReportUndefOperand::getMessage() const {
323
0
  return ("undef operand in branch at BB: " + BB->getName()).str();
324
0
}
325
326
0
bool ReportUndefOperand::classof(const RejectReason *RR) {
327
0
  return RR->getKind() == RejectReasonKind::UndefOperand;
328
0
}
329
330
//===----------------------------------------------------------------------===//
331
// ReportNonAffBranch.
332
333
4
std::string ReportNonAffBranch::getRemarkName() const { return "NonAffBranch"; }
334
335
4
const Value *ReportNonAffBranch::getRemarkBB() const { return BB; }
336
337
0
std::string ReportNonAffBranch::getMessage() const {
338
0
  return ("Non affine branch in BB '" + BB->getName()).str() +
339
0
         "' with LHS: " + *LHS + " and RHS: " + *RHS;
340
0
}
341
342
0
bool ReportNonAffBranch::classof(const RejectReason *RR) {
343
0
  return RR->getKind() == RejectReasonKind::NonAffBranch;
344
0
}
345
346
//===----------------------------------------------------------------------===//
347
// ReportNoBasePtr.
348
349
0
std::string ReportNoBasePtr::getRemarkName() const { return "NoBasePtr"; }
350
351
0
const Value *ReportNoBasePtr::getRemarkBB() const { return Inst->getParent(); }
352
353
0
std::string ReportNoBasePtr::getMessage() const { return "No base pointer"; }
354
355
0
bool ReportNoBasePtr::classof(const RejectReason *RR) {
356
0
  return RR->getKind() == RejectReasonKind::NoBasePtr;
357
0
}
358
359
//===----------------------------------------------------------------------===//
360
// ReportUndefBasePtr.
361
362
4
std::string ReportUndefBasePtr::getRemarkName() const { return "UndefBasePtr"; }
363
364
4
const Value *ReportUndefBasePtr::getRemarkBB() const {
365
4
  return Inst->getParent();
366
4
}
367
368
0
std::string ReportUndefBasePtr::getMessage() const {
369
0
  return "Undefined base pointer";
370
0
}
371
372
0
bool ReportUndefBasePtr::classof(const RejectReason *RR) {
373
0
  return RR->getKind() == RejectReasonKind::UndefBasePtr;
374
0
}
375
376
//===----------------------------------------------------------------------===//
377
// ReportVariantBasePtr.
378
379
10
std::string ReportVariantBasePtr::getRemarkName() const {
380
10
  return "VariantBasePtr";
381
10
}
382
383
10
const Value *ReportVariantBasePtr::getRemarkBB() const {
384
10
  return Inst->getParent();
385
10
}
386
387
0
std::string ReportVariantBasePtr::getMessage() const {
388
0
  return "Base address not invariant in current region:" + *BaseValue;
389
0
}
390
391
10
std::string ReportVariantBasePtr::getEndUserMessage() const {
392
10
  return "The base address of this array is not invariant inside the loop";
393
10
}
394
395
0
bool ReportVariantBasePtr::classof(const RejectReason *RR) {
396
0
  return RR->getKind() == RejectReasonKind::VariantBasePtr;
397
0
}
398
399
//===----------------------------------------------------------------------===//
400
// ReportDifferentArrayElementSize
401
402
0
std::string ReportDifferentArrayElementSize::getRemarkName() const {
403
0
  return "DifferentArrayElementSize";
404
0
}
405
406
0
const Value *ReportDifferentArrayElementSize::getRemarkBB() const {
407
0
  return Inst->getParent();
408
0
}
409
410
0
std::string ReportDifferentArrayElementSize::getMessage() const {
411
0
  return "Access to one array through data types of different size";
412
0
}
413
414
0
bool ReportDifferentArrayElementSize::classof(const RejectReason *RR) {
415
0
  return RR->getKind() == RejectReasonKind::DifferentElementSize;
416
0
}
417
418
0
std::string ReportDifferentArrayElementSize::getEndUserMessage() const {
419
0
  StringRef BaseName = BaseValue->getName();
420
0
  std::string Name = BaseName.empty() ? "UNKNOWN" : BaseName;
421
0
  return "The array \"" + Name +
422
0
         "\" is accessed through elements that differ "
423
0
         "in size";
424
0
}
425
426
//===----------------------------------------------------------------------===//
427
// ReportNonAffineAccess.
428
429
54
std::string ReportNonAffineAccess::getRemarkName() const {
430
54
  return "NonAffineAccess";
431
54
}
432
433
54
const Value *ReportNonAffineAccess::getRemarkBB() const {
434
54
  return Inst->getParent();
435
54
}
436
437
0
std::string ReportNonAffineAccess::getMessage() const {
438
0
  return "Non affine access function: " + *AccessFunction;
439
0
}
440
441
0
bool ReportNonAffineAccess::classof(const RejectReason *RR) {
442
0
  return RR->getKind() == RejectReasonKind::NonAffineAccess;
443
0
}
444
445
54
std::string ReportNonAffineAccess::getEndUserMessage() const {
446
54
  StringRef BaseName = BaseValue->getName();
447
54
  std::string Name = BaseName.empty() ? 
"UNKNOWN"0
: BaseName;
448
54
  return "The array subscript of \"" + Name + "\" is not affine";
449
54
}
450
451
//===----------------------------------------------------------------------===//
452
// ReportLoopBound.
453
454
ReportLoopBound::ReportLoopBound(Loop *L, const SCEV *LoopCount)
455
    : RejectReason(RejectReasonKind::LoopBound), L(L), LoopCount(LoopCount),
456
153
      Loc(L->getStartLoc()) {}
457
458
144
std::string ReportLoopBound::getRemarkName() const { return "LoopBound"; }
459
460
144
const Value *ReportLoopBound::getRemarkBB() const { return L->getHeader(); }
461
462
0
std::string ReportLoopBound::getMessage() const {
463
0
  return "Non affine loop bound '" + *LoopCount +
464
0
         "' in loop: " + L->getHeader()->getName();
465
0
}
466
467
144
const DebugLoc &ReportLoopBound::getDebugLoc() const { return Loc; }
468
469
0
bool ReportLoopBound::classof(const RejectReason *RR) {
470
0
  return RR->getKind() == RejectReasonKind::LoopBound;
471
0
}
472
473
144
std::string ReportLoopBound::getEndUserMessage() const {
474
144
  return "Failed to derive an affine function from the loop bounds.";
475
144
}
476
477
//===----------------------------------------------------------------------===//
478
// ReportLoopHasNoExit.
479
480
0
std::string ReportLoopHasNoExit::getRemarkName() const {
481
0
  return "LoopHasNoExit";
482
0
}
483
484
0
const Value *ReportLoopHasNoExit::getRemarkBB() const { return L->getHeader(); }
485
486
0
std::string ReportLoopHasNoExit::getMessage() const {
487
0
  return "Loop " + L->getHeader()->getName() + " has no exit.";
488
0
}
489
490
0
bool ReportLoopHasNoExit::classof(const RejectReason *RR) {
491
0
  return RR->getKind() == RejectReasonKind::LoopHasNoExit;
492
0
}
493
494
0
const DebugLoc &ReportLoopHasNoExit::getDebugLoc() const { return Loc; }
495
496
0
std::string ReportLoopHasNoExit::getEndUserMessage() const {
497
0
  return "Loop cannot be handled because it has no exit.";
498
0
}
499
500
//===----------------------------------------------------------------------===//
501
// ReportLoopOnlySomeLatches
502
503
5
std::string ReportLoopOnlySomeLatches::getRemarkName() const {
504
5
  return "LoopHasNoExit";
505
5
}
506
507
5
const Value *ReportLoopOnlySomeLatches::getRemarkBB() const {
508
5
  return L->getHeader();
509
5
}
510
511
0
std::string ReportLoopOnlySomeLatches::getMessage() const {
512
0
  return "Not all latches of loop " + L->getHeader()->getName() +
513
0
         " part of scop.";
514
0
}
515
516
0
bool ReportLoopOnlySomeLatches::classof(const RejectReason *RR) {
517
0
  return RR->getKind() == RejectReasonKind::LoopHasNoExit;
518
0
}
519
520
5
const DebugLoc &ReportLoopOnlySomeLatches::getDebugLoc() const { return Loc; }
521
522
5
std::string ReportLoopOnlySomeLatches::getEndUserMessage() const {
523
5
  return "Loop cannot be handled because not all latches are part of loop "
524
5
         "region.";
525
5
}
526
527
//===----------------------------------------------------------------------===//
528
// ReportFuncCall.
529
530
ReportFuncCall::ReportFuncCall(Instruction *Inst)
531
13
    : RejectReason(RejectReasonKind::FuncCall), Inst(Inst) {}
532
533
11
std::string ReportFuncCall::getRemarkName() const { return "FuncCall"; }
534
535
11
const Value *ReportFuncCall::getRemarkBB() const { return Inst->getParent(); }
536
537
0
std::string ReportFuncCall::getMessage() const {
538
0
  return "Call instruction: " + *Inst;
539
0
}
540
541
11
const DebugLoc &ReportFuncCall::getDebugLoc() const {
542
11
  return Inst->getDebugLoc();
543
11
}
544
545
11
std::string ReportFuncCall::getEndUserMessage() const {
546
11
  return "This function call cannot be handled. "
547
11
         "Try to inline it.";
548
11
}
549
550
0
bool ReportFuncCall::classof(const RejectReason *RR) {
551
0
  return RR->getKind() == RejectReasonKind::FuncCall;
552
0
}
553
554
//===----------------------------------------------------------------------===//
555
// ReportNonSimpleMemoryAccess
556
557
ReportNonSimpleMemoryAccess::ReportNonSimpleMemoryAccess(Instruction *Inst)
558
0
    : ReportOther(RejectReasonKind::NonSimpleMemoryAccess), Inst(Inst) {}
559
560
0
std::string ReportNonSimpleMemoryAccess::getRemarkName() const {
561
0
  return "NonSimpleMemoryAccess";
562
0
}
563
564
0
const Value *ReportNonSimpleMemoryAccess::getRemarkBB() const {
565
0
  return Inst->getParent();
566
0
}
567
568
0
std::string ReportNonSimpleMemoryAccess::getMessage() const {
569
0
  return "Non-simple memory access: " + *Inst;
570
0
}
571
572
0
const DebugLoc &ReportNonSimpleMemoryAccess::getDebugLoc() const {
573
0
  return Inst->getDebugLoc();
574
0
}
575
576
0
std::string ReportNonSimpleMemoryAccess::getEndUserMessage() const {
577
0
  return "Volatile memory accesses or memory accesses for atomic types "
578
0
         "are not supported.";
579
0
}
580
581
0
bool ReportNonSimpleMemoryAccess::classof(const RejectReason *RR) {
582
0
  return RR->getKind() == RejectReasonKind::NonSimpleMemoryAccess;
583
0
}
584
585
//===----------------------------------------------------------------------===//
586
// ReportAlias.
587
588
ReportAlias::ReportAlias(Instruction *Inst, AliasSet &AS)
589
3
    : RejectReason(RejectReasonKind::Alias), Inst(Inst) {
590
3
  for (const auto &I : AS)
591
6
    Pointers.push_back(I.getValue());
592
3
}
593
594
std::string ReportAlias::formatInvalidAlias(std::string Prefix,
595
3
                                            std::string Suffix) const {
596
3
  std::string Message;
597
3
  raw_string_ostream OS(Message);
598
3
599
3
  OS << Prefix;
600
3
601
3
  for (PointerSnapshotTy::const_iterator PI = Pointers.begin(),
602
3
                                         PE = Pointers.end();
603
6
       ;) {
604
6
    const Value *V = *PI;
605
6
    assert(V && "Diagnostic info does not match found LLVM-IR anymore.");
606
6
607
6
    if (V->getName().empty())
608
1
      OS << "\" <unknown> \"";
609
5
    else
610
5
      OS << "\"" << V->getName() << "\"";
611
6
612
6
    ++PI;
613
6
614
6
    if (PI != PE)
615
3
      OS << ", ";
616
3
    else
617
3
      break;
618
6
  }
619
3
620
3
  OS << Suffix;
621
3
622
3
  return OS.str();
623
3
}
624
625
3
std::string ReportAlias::getRemarkName() const { return "Alias"; }
626
627
3
const Value *ReportAlias::getRemarkBB() const { return Inst->getParent(); }
628
629
0
std::string ReportAlias::getMessage() const {
630
0
  return formatInvalidAlias("Possible aliasing: ");
631
0
}
632
633
3
std::string ReportAlias::getEndUserMessage() const {
634
3
  return formatInvalidAlias("Accesses to the arrays ",
635
3
                            " may access the same memory.");
636
3
}
637
638
3
const DebugLoc &ReportAlias::getDebugLoc() const { return Inst->getDebugLoc(); }
639
640
0
bool ReportAlias::classof(const RejectReason *RR) {
641
0
  return RR->getKind() == RejectReasonKind::Alias;
642
0
}
643
644
//===----------------------------------------------------------------------===//
645
// ReportOther.
646
647
0
std::string ReportOther::getRemarkName() const { return "UnknownRejectReason"; }
648
649
0
std::string ReportOther::getMessage() const { return "Unknown reject reason"; }
650
651
149
ReportOther::ReportOther(const RejectReasonKind K) : RejectReason(K) {}
652
653
0
bool ReportOther::classof(const RejectReason *RR) {
654
0
  return RR->getKind() >= RejectReasonKind::Other &&
655
0
         RR->getKind() <= RejectReasonKind::LastOther;
656
0
}
657
658
//===----------------------------------------------------------------------===//
659
// ReportIntToPtr.
660
ReportIntToPtr::ReportIntToPtr(Instruction *BaseValue)
661
1
    : ReportOther(RejectReasonKind::IntToPtr), BaseValue(BaseValue) {}
662
663
1
std::string ReportIntToPtr::getRemarkName() const { return "IntToPtr"; }
664
665
1
const Value *ReportIntToPtr::getRemarkBB() const {
666
1
  return BaseValue->getParent();
667
1
}
668
669
0
std::string ReportIntToPtr::getMessage() const {
670
0
  return "Find bad intToptr prt: " + *BaseValue;
671
0
}
672
673
1
const DebugLoc &ReportIntToPtr::getDebugLoc() const {
674
1
  return BaseValue->getDebugLoc();
675
1
}
676
677
0
bool ReportIntToPtr::classof(const RejectReason *RR) {
678
0
  return RR->getKind() == RejectReasonKind::IntToPtr;
679
0
}
680
681
//===----------------------------------------------------------------------===//
682
// ReportAlloca.
683
684
ReportAlloca::ReportAlloca(Instruction *Inst)
685
0
    : ReportOther(RejectReasonKind::Alloca), Inst(Inst) {}
686
687
0
std::string ReportAlloca::getRemarkName() const { return "Alloca"; }
688
689
0
const Value *ReportAlloca::getRemarkBB() const { return Inst->getParent(); }
690
691
0
std::string ReportAlloca::getMessage() const {
692
0
  return "Alloca instruction: " + *Inst;
693
0
}
694
695
0
const DebugLoc &ReportAlloca::getDebugLoc() const {
696
0
  return Inst->getDebugLoc();
697
0
}
698
699
0
bool ReportAlloca::classof(const RejectReason *RR) {
700
0
  return RR->getKind() == RejectReasonKind::Alloca;
701
0
}
702
703
//===----------------------------------------------------------------------===//
704
// ReportUnknownInst.
705
706
ReportUnknownInst::ReportUnknownInst(Instruction *Inst)
707
49
    : ReportOther(RejectReasonKind::UnknownInst), Inst(Inst) {}
708
709
26
std::string ReportUnknownInst::getRemarkName() const { return "UnknownInst"; }
710
711
26
const Value *ReportUnknownInst::getRemarkBB() const {
712
26
  return Inst->getParent();
713
26
}
714
715
0
std::string ReportUnknownInst::getMessage() const {
716
0
  return "Unknown instruction: " + *Inst;
717
0
}
718
719
26
const DebugLoc &ReportUnknownInst::getDebugLoc() const {
720
26
  return Inst->getDebugLoc();
721
26
}
722
723
0
bool ReportUnknownInst::classof(const RejectReason *RR) {
724
0
  return RR->getKind() == RejectReasonKind::UnknownInst;
725
0
}
726
727
//===----------------------------------------------------------------------===//
728
// ReportEntry.
729
730
ReportEntry::ReportEntry(BasicBlock *BB)
731
83
    : ReportOther(RejectReasonKind::Entry), BB(BB) {}
732
733
83
std::string ReportEntry::getRemarkName() const { return "Entry"; }
734
735
83
const Value *ReportEntry::getRemarkBB() const { return BB; }
736
737
0
std::string ReportEntry::getMessage() const {
738
0
  return "Region containing entry block of function is invalid!";
739
0
}
740
741
83
std::string ReportEntry::getEndUserMessage() const {
742
83
  return "Scop contains function entry (not yet supported).";
743
83
}
744
745
83
const DebugLoc &ReportEntry::getDebugLoc() const {
746
83
  return BB->getTerminator()->getDebugLoc();
747
83
}
748
749
0
bool ReportEntry::classof(const RejectReason *RR) {
750
0
  return RR->getKind() == RejectReasonKind::Entry;
751
0
}
752
753
//===----------------------------------------------------------------------===//
754
// ReportUnprofitable.
755
756
ReportUnprofitable::ReportUnprofitable(Region *R)
757
16
    : ReportOther(RejectReasonKind::Unprofitable), R(R) {}
758
759
16
std::string ReportUnprofitable::getRemarkName() const { return "Unprofitable"; }
760
761
16
const Value *ReportUnprofitable::getRemarkBB() const { return R->getEntry(); }
762
763
0
std::string ReportUnprofitable::getMessage() const {
764
0
  return "Region can not profitably be optimized!";
765
0
}
766
767
16
std::string ReportUnprofitable::getEndUserMessage() const {
768
16
  return "No profitable polyhedral optimization found";
769
16
}
770
771
16
const DebugLoc &ReportUnprofitable::getDebugLoc() const {
772
16
  for (const BasicBlock *BB : R->blocks())
773
62
    for (const Instruction &Inst : *BB)
774
230
      if (const DebugLoc &DL = Inst.getDebugLoc())
775
5
        return DL;
776
16
777
16
  
return R->getEntry()->getTerminator()->getDebugLoc()11
;
778
16
}
779
780
0
bool ReportUnprofitable::classof(const RejectReason *RR) {
781
0
  return RR->getKind() == RejectReasonKind::Unprofitable;
782
0
}
783
784
} // namespace polly