Coverage Report

Created: 2018-04-23 18:20

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