Polly 20.0.0git
BlockGenerators.cpp
Go to the documentation of this file.
1//===--- BlockGenerators.cpp - Generate code for statements -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the BlockGenerator and VectorBlockGenerator classes,
10// which generate sequential code and vectorized code for a polyhedral
11// statement, respectively.
12//
13//===----------------------------------------------------------------------===//
14
18#include "polly/Options.h"
19#include "polly/ScopInfo.h"
23#include "llvm/Analysis/DomTreeUpdater.h"
24#include "llvm/Analysis/LoopInfo.h"
25#include "llvm/Analysis/RegionInfo.h"
26#include "llvm/Analysis/ScalarEvolution.h"
27#include "llvm/Transforms/Utils/BasicBlockUtils.h"
28#include "llvm/Transforms/Utils/Local.h"
29#include "isl/ast.h"
30#include <deque>
31
32using namespace llvm;
33using namespace polly;
34
35static cl::opt<bool> Aligned("enable-polly-aligned",
36 cl::desc("Assumed aligned memory accesses."),
37 cl::Hidden, cl::cat(PollyCategory));
38
40static cl::opt<bool, true> DebugPrintingX(
41 "polly-codegen-add-debug-printing",
42 cl::desc("Add printf calls that show the values loaded/stored."),
43 cl::location(PollyDebugPrinting), cl::Hidden, cl::cat(PollyCategory));
44
45static cl::opt<bool> TraceStmts(
46 "polly-codegen-trace-stmts",
47 cl::desc("Add printf calls that print the statement being executed"),
48 cl::Hidden, cl::cat(PollyCategory));
49
50static cl::opt<bool> TraceScalars(
51 "polly-codegen-trace-scalars",
52 cl::desc("Add printf calls that print the values of all scalar values "
53 "used in a statement. Requires -polly-codegen-trace-stmts."),
54 cl::Hidden, cl::cat(PollyCategory));
55
57 PollyIRBuilder &B, LoopInfo &LI, ScalarEvolution &SE, DominatorTree &DT,
58 AllocaMapTy &ScalarMap, EscapeUsersAllocaMapTy &EscapeMap,
59 ValueMapT &GlobalMap, IslExprBuilder *ExprBuilder, BasicBlock *StartBlock)
60 : Builder(B), LI(LI), SE(SE), ExprBuilder(ExprBuilder), DT(DT), GenDT(&DT),
61 GenLI(&LI), GenSE(&SE), ScalarMap(ScalarMap), EscapeMap(EscapeMap),
62 GlobalMap(GlobalMap), StartBlock(StartBlock) {}
63
65 ValueMapT &BBMap,
66 LoopToScevMapT &LTS,
67 Loop *L) const {
68 if (!SE.isSCEVable(Old->getType()))
69 return nullptr;
70
71 const SCEV *Scev = SE.getSCEVAtScope(Old, L);
72 if (!Scev)
73 return nullptr;
74
75 if (isa<SCEVCouldNotCompute>(Scev))
76 return nullptr;
77
78 ValueMapT VTV;
79 VTV.insert(BBMap.begin(), BBMap.end());
80 VTV.insert(GlobalMap.begin(), GlobalMap.end());
81
82 Scop &S = *Stmt.getParent();
83 const DataLayout &DL = S.getFunction().getDataLayout();
84 auto IP = Builder.GetInsertPoint();
85
86 assert(IP != Builder.GetInsertBlock()->end() &&
87 "Only instructions can be insert points for SCEVExpander");
88 Value *Expanded = expandCodeFor(
89 S, SE, Builder.GetInsertBlock()->getParent(), *GenSE, DL, "polly", Scev,
90 Old->getType(), &*IP, &VTV, &LTS, StartBlock->getSinglePredecessor());
91
92 BBMap[Old] = Expanded;
93 return Expanded;
94}
95
97 LoopToScevMapT &LTS, Loop *L) const {
98
99 auto lookupGlobally = [this](Value *Old) -> Value * {
100 Value *New = GlobalMap.lookup(Old);
101 if (!New)
102 return nullptr;
103
104 // Required by:
105 // * Isl/CodeGen/OpenMP/invariant_base_pointer_preloaded.ll
106 // * Isl/CodeGen/OpenMP/invariant_base_pointer_preloaded_different_bb.ll
107 // * Isl/CodeGen/OpenMP/invariant_base_pointer_preloaded_pass_only_needed.ll
108 // * Isl/CodeGen/OpenMP/invariant_base_pointers_preloaded.ll
109 // * Isl/CodeGen/OpenMP/loop-body-references-outer-values-3.ll
110 // * Isl/CodeGen/OpenMP/single_loop_with_loop_invariant_baseptr.ll
111 // GlobalMap should be a mapping from (value in original SCoP) to (copied
112 // value in generated SCoP), without intermediate mappings, which might
113 // easily require transitiveness as well.
114 if (Value *NewRemapped = GlobalMap.lookup(New))
115 New = NewRemapped;
116
117 // No test case for this code.
118 if (Old->getType()->getScalarSizeInBits() <
119 New->getType()->getScalarSizeInBits())
120 New = Builder.CreateTruncOrBitCast(New, Old->getType());
121
122 return New;
123 };
124
125 Value *New = nullptr;
126 auto VUse = VirtualUse::create(&Stmt, L, Old, true);
127 switch (VUse.getKind()) {
129 // BasicBlock are constants, but the BlockGenerator copies them.
130 New = BBMap.lookup(Old);
131 break;
132
134 // Used by:
135 // * Isl/CodeGen/OpenMP/reference-argument-from-non-affine-region.ll
136 // Constants should not be redefined. In this case, the GlobalMap just
137 // contains a mapping to the same constant, which is unnecessary, but
138 // harmless.
139 if ((New = lookupGlobally(Old)))
140 break;
141
142 assert(!BBMap.count(Old));
143 New = Old;
144 break;
145
147 assert(!GlobalMap.count(Old));
148
149 // Required for:
150 // * Isl/CodeGen/MemAccess/create_arrays.ll
151 // * Isl/CodeGen/read-only-scalars.ll
152 // * ScheduleOptimizer/pattern-matching-based-opts_10.ll
153 // For some reason these reload a read-only value. The reloaded value ends
154 // up in BBMap, buts its value should be identical.
155 //
156 // Required for:
157 // * Isl/CodeGen/OpenMP/single_loop_with_param.ll
158 // The parallel subfunctions need to reference the read-only value from the
159 // parent function, this is done by reloading them locally.
160 if ((New = BBMap.lookup(Old)))
161 break;
162
163 New = Old;
164 break;
165
167 // Used by:
168 // * Isl/CodeGen/OpenMP/loop-body-references-outer-values-3.ll
169 // * Isl/CodeGen/OpenMP/recomputed-srem.ll
170 // * Isl/CodeGen/OpenMP/reference-other-bb.ll
171 // * Isl/CodeGen/OpenMP/two-parallel-loops-reference-outer-indvar.ll
172 // For some reason synthesizable values end up in GlobalMap. Their values
173 // are the same as trySynthesizeNewValue would return. The legacy
174 // implementation prioritized GlobalMap, so this is what we do here as well.
175 // Ideally, synthesizable values should not end up in GlobalMap.
176 if ((New = lookupGlobally(Old)))
177 break;
178
179 // Required for:
180 // * Isl/CodeGen/RuntimeDebugBuilder/combine_different_values.ll
181 // * Isl/CodeGen/getNumberOfIterations.ll
182 // * Isl/CodeGen/non_affine_float_compare.ll
183 // * ScheduleOptimizer/pattern-matching-based-opts_10.ll
184 // Ideally, synthesizable values are synthesized by trySynthesizeNewValue,
185 // not precomputed (SCEVExpander has its own caching mechanism).
186 // These tests fail without this, but I think trySynthesizeNewValue would
187 // just re-synthesize the same instructions.
188 if ((New = BBMap.lookup(Old)))
189 break;
190
191 New = trySynthesizeNewValue(Stmt, Old, BBMap, LTS, L);
192 break;
193
195 // TODO: Hoisted invariant loads should be found in GlobalMap only, but not
196 // redefined locally (which will be ignored anyway). That is, the following
197 // assertion should apply: assert(!BBMap.count(Old))
198
199 New = lookupGlobally(Old);
200 break;
201
204 assert(!GlobalMap.count(Old) &&
205 "Intra and inter-stmt values are never global");
206 New = BBMap.lookup(Old);
207 break;
208 }
209 assert(New && "Unexpected scalar dependence in region!");
210 return New;
211}
212
213void BlockGenerator::copyInstScalar(ScopStmt &Stmt, Instruction *Inst,
214 ValueMapT &BBMap, LoopToScevMapT &LTS) {
215 // We do not generate debug intrinsics as we did not investigate how to
216 // copy them correctly. At the current state, they just crash the code
217 // generation as the meta-data operands are not correctly copied.
218 if (isa<DbgInfoIntrinsic>(Inst))
219 return;
220
221 Instruction *NewInst = Inst->clone();
222
223 // Replace old operands with the new ones.
224 for (Value *OldOperand : Inst->operands()) {
225 Value *NewOperand =
226 getNewValue(Stmt, OldOperand, BBMap, LTS, getLoopForStmt(Stmt));
227
228 if (!NewOperand) {
229 assert(!isa<StoreInst>(NewInst) &&
230 "Store instructions are always needed!");
231 NewInst->deleteValue();
232 return;
233 }
234
235 // FIXME: We will encounter "NewOperand" again if used twice. getNewValue()
236 // is meant to be called on old values only.
237 NewInst->replaceUsesOfWith(OldOperand, NewOperand);
238 }
239
240 Builder.Insert(NewInst);
241 BBMap[Inst] = NewInst;
242
243 assert(NewInst->getModule() == Inst->getModule() &&
244 "Expecting instructions to be in the same module");
245
246 if (!NewInst->getType()->isVoidTy())
247 NewInst->setName("p_" + Inst->getName());
248}
249
250Value *
252 ValueMapT &BBMap, LoopToScevMapT &LTS,
253 isl_id_to_ast_expr *NewAccesses) {
254 const MemoryAccess &MA = Stmt.getArrayAccessFor(Inst);
256 Stmt, getLoopForStmt(Stmt),
257 Inst.isNull() ? nullptr : Inst.getPointerOperand(), BBMap, LTS,
258 NewAccesses, MA.getId().release(), MA.getAccessValue()->getType());
259}
260
262 ScopStmt &Stmt, Loop *L, Value *Pointer, ValueMapT &BBMap,
263 LoopToScevMapT &LTS, isl_id_to_ast_expr *NewAccesses, __isl_take isl_id *Id,
264 Type *ExpectedType) {
265 isl_ast_expr *AccessExpr = isl_id_to_ast_expr_get(NewAccesses, Id);
266
267 if (AccessExpr) {
268 AccessExpr = isl_ast_expr_address_of(AccessExpr);
269 return ExprBuilder->create(AccessExpr);
270 }
271 assert(
272 Pointer &&
273 "If expression was not generated, must use the original pointer value");
274 return getNewValue(Stmt, Pointer, BBMap, LTS, L);
275}
276
277Value *
279 LoopToScevMapT &LTS, ValueMapT &BBMap,
280 __isl_keep isl_id_to_ast_expr *NewAccesses) {
281 if (Access.isLatestArrayKind())
282 return generateLocationAccessed(*Access.getStatement(), L, nullptr, BBMap,
283 LTS, NewAccesses, Access.getId().release(),
284 Access.getAccessValue()->getType());
285
286 return getOrCreateAlloca(Access);
287}
288
289Loop *BlockGenerator::getLoopForStmt(const ScopStmt &Stmt) const {
290 auto *StmtBB = Stmt.getEntryBlock();
291 return LI.getLoopFor(StmtBB);
292}
293
295 ValueMapT &BBMap, LoopToScevMapT &LTS,
296 isl_id_to_ast_expr *NewAccesses) {
297 if (Value *PreloadLoad = GlobalMap.lookup(Load))
298 return PreloadLoad;
299
300 Value *NewPointer =
301 generateLocationAccessed(Stmt, Load, BBMap, LTS, NewAccesses);
302 Value *ScalarLoad =
303 Builder.CreateAlignedLoad(Load->getType(), NewPointer, Load->getAlign(),
304 Load->getName() + "_p_scalar_");
305
307 RuntimeDebugBuilder::createCPUPrinter(Builder, "Load from ", NewPointer,
308 ": ", ScalarLoad, "\n");
309
310 return ScalarLoad;
311}
312
313void BlockGenerator::generateArrayStore(ScopStmt &Stmt, StoreInst *Store,
314 ValueMapT &BBMap, LoopToScevMapT &LTS,
315 isl_id_to_ast_expr *NewAccesses) {
316 MemoryAccess &MA = Stmt.getArrayAccessFor(Store);
317 isl::set AccDom = MA.getAccessRelation().domain();
318 std::string Subject = MA.getId().get_name();
319
320 generateConditionalExecution(Stmt, AccDom, Subject.c_str(), [&, this]() {
321 Value *NewPointer =
322 generateLocationAccessed(Stmt, Store, BBMap, LTS, NewAccesses);
323 Value *ValueOperand = getNewValue(Stmt, Store->getValueOperand(), BBMap,
324 LTS, getLoopForStmt(Stmt));
325
326 if (PollyDebugPrinting)
327 RuntimeDebugBuilder::createCPUPrinter(Builder, "Store to ", NewPointer,
328 ": ", ValueOperand, "\n");
329
330 Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlign());
331 });
332}
333
334bool BlockGenerator::canSyntheziseInStmt(ScopStmt &Stmt, Instruction *Inst) {
335 Loop *L = getLoopForStmt(Stmt);
336 return (Stmt.isBlockStmt() || !Stmt.getRegion()->contains(L)) &&
337 canSynthesize(Inst, *Stmt.getParent(), &SE, L);
338}
339
340void BlockGenerator::copyInstruction(ScopStmt &Stmt, Instruction *Inst,
341 ValueMapT &BBMap, LoopToScevMapT &LTS,
342 isl_id_to_ast_expr *NewAccesses) {
343 // Terminator instructions control the control flow. They are explicitly
344 // expressed in the clast and do not need to be copied.
345 if (Inst->isTerminator())
346 return;
347
348 // Synthesizable statements will be generated on-demand.
349 if (canSyntheziseInStmt(Stmt, Inst))
350 return;
351
352 if (auto *Load = dyn_cast<LoadInst>(Inst)) {
353 Value *NewLoad = generateArrayLoad(Stmt, Load, BBMap, LTS, NewAccesses);
354 // Compute NewLoad before its insertion in BBMap to make the insertion
355 // deterministic.
356 BBMap[Load] = NewLoad;
357 return;
358 }
359
360 if (auto *Store = dyn_cast<StoreInst>(Inst)) {
361 // Identified as redundant by -polly-simplify.
362 if (!Stmt.getArrayAccessOrNULLFor(Store))
363 return;
364
365 generateArrayStore(Stmt, Store, BBMap, LTS, NewAccesses);
366 return;
367 }
368
369 if (auto *PHI = dyn_cast<PHINode>(Inst)) {
370 copyPHIInstruction(Stmt, PHI, BBMap, LTS);
371 return;
372 }
373
374 // Skip some special intrinsics for which we do not adjust the semantics to
375 // the new schedule. All others are handled like every other instruction.
376 if (isIgnoredIntrinsic(Inst))
377 return;
378
379 copyInstScalar(Stmt, Inst, BBMap, LTS);
380}
381
383 auto NewBB = Builder.GetInsertBlock();
384 for (auto I = NewBB->rbegin(); I != NewBB->rend(); I++) {
385 Instruction *NewInst = &*I;
386
387 if (!isInstructionTriviallyDead(NewInst))
388 continue;
389
390 for (auto Pair : BBMap)
391 if (Pair.second == NewInst) {
392 BBMap.erase(Pair.first);
393 }
394
395 NewInst->eraseFromParent();
396 I = NewBB->rbegin();
397 }
398}
399
401 __isl_keep isl_id_to_ast_expr *NewAccesses) {
402 assert(Stmt.isBlockStmt() &&
403 "Only block statements can be copied by the block generator");
404
405 ValueMapT BBMap;
406
407 BasicBlock *BB = Stmt.getBasicBlock();
408 copyBB(Stmt, BB, BBMap, LTS, NewAccesses);
409 removeDeadInstructions(BB, BBMap);
410}
411
412BasicBlock *BlockGenerator::splitBB(BasicBlock *BB) {
413 BasicBlock *CopyBB = SplitBlock(Builder.GetInsertBlock(),
414 &*Builder.GetInsertPoint(), GenDT, GenLI);
415 CopyBB->setName("polly.stmt." + BB->getName());
416 return CopyBB;
417}
418
419BasicBlock *BlockGenerator::copyBB(ScopStmt &Stmt, BasicBlock *BB,
420 ValueMapT &BBMap, LoopToScevMapT &LTS,
421 isl_id_to_ast_expr *NewAccesses) {
422 BasicBlock *CopyBB = splitBB(BB);
423 Builder.SetInsertPoint(&CopyBB->front());
424 generateScalarLoads(Stmt, LTS, BBMap, NewAccesses);
425 generateBeginStmtTrace(Stmt, LTS, BBMap);
426
427 copyBB(Stmt, BB, CopyBB, BBMap, LTS, NewAccesses);
428
429 // After a basic block was copied store all scalars that escape this block in
430 // their alloca.
431 generateScalarStores(Stmt, LTS, BBMap, NewAccesses);
432 return CopyBB;
433}
434
435void BlockGenerator::switchGeneratedFunc(Function *GenFn, DominatorTree *GenDT,
436 LoopInfo *GenLI,
437 ScalarEvolution *GenSE) {
438 assert(GenFn == GenDT->getRoot()->getParent());
439 assert(GenLI->getTopLevelLoops().empty() ||
440 GenFn == GenLI->getTopLevelLoops().front()->getHeader()->getParent());
441 this->GenDT = GenDT;
442 this->GenLI = GenLI;
443 this->GenSE = GenSE;
444}
445
446void BlockGenerator::copyBB(ScopStmt &Stmt, BasicBlock *BB, BasicBlock *CopyBB,
447 ValueMapT &BBMap, LoopToScevMapT &LTS,
448 isl_id_to_ast_expr *NewAccesses) {
449 // Block statements and the entry blocks of region statement are code
450 // generated from instruction lists. This allow us to optimize the
451 // instructions that belong to a certain scop statement. As the code
452 // structure of region statements might be arbitrary complex, optimizing the
453 // instruction list is not yet supported.
454 if (Stmt.isBlockStmt() || (Stmt.isRegionStmt() && Stmt.getEntryBlock() == BB))
455 for (Instruction *Inst : Stmt.getInstructions())
456 copyInstruction(Stmt, Inst, BBMap, LTS, NewAccesses);
457 else
458 for (Instruction &Inst : *BB)
459 copyInstruction(Stmt, &Inst, BBMap, LTS, NewAccesses);
460}
461
463 assert(!Access.isLatestArrayKind() && "Trying to get alloca for array kind");
464
466}
467
469 assert(!Array->isArrayKind() && "Trying to get alloca for array kind");
470
471 auto &Addr = ScalarMap[Array];
472
473 if (Addr) {
474 // Allow allocas to be (temporarily) redirected once by adding a new
475 // old-alloca-addr to new-addr mapping to GlobalMap. This functionality
476 // is used for example by the OpenMP code generation where a first use
477 // of a scalar while still in the host code allocates a normal alloca with
478 // getOrCreateAlloca. When the values of this scalar are accessed during
479 // the generation of the parallel subfunction, these values are copied over
480 // to the parallel subfunction and each request for a scalar alloca slot
481 // must be forwarded to the temporary in-subfunction slot. This mapping is
482 // removed when the subfunction has been generated and again normal host
483 // code is generated. Due to the following reasons it is not possible to
484 // perform the GlobalMap lookup right after creating the alloca below, but
485 // instead we need to check GlobalMap at each call to getOrCreateAlloca:
486 //
487 // 1) GlobalMap may be changed multiple times (for each parallel loop),
488 // 2) The temporary mapping is commonly only known after the initial
489 // alloca has already been generated, and
490 // 3) The original alloca value must be restored after leaving the
491 // sub-function.
492 if (Value *NewAddr = GlobalMap.lookup(&*Addr))
493 return NewAddr;
494 return Addr;
495 }
496
497 Type *Ty = Array->getElementType();
498 Value *ScalarBase = Array->getBasePtr();
499 std::string NameExt;
500 if (Array->isPHIKind())
501 NameExt = ".phiops";
502 else
503 NameExt = ".s2a";
504
505 const DataLayout &DL = Builder.GetInsertBlock()->getDataLayout();
506
507 Addr =
508 new AllocaInst(Ty, DL.getAllocaAddrSpace(), nullptr,
509 DL.getPrefTypeAlign(Ty), ScalarBase->getName() + NameExt);
510 BasicBlock *EntryBB = &Builder.GetInsertBlock()->getParent()->getEntryBlock();
511 Addr->insertBefore(&*EntryBB->getFirstInsertionPt());
512
513 return Addr;
514}
515
517 Instruction *Inst = cast<Instruction>(Array->getBasePtr());
518
519 // If there are escape users we get the alloca for this instruction and put it
520 // in the EscapeMap for later finalization. Lastly, if the instruction was
521 // copied multiple times we already did this and can exit.
522 if (EscapeMap.count(Inst))
523 return;
524
525 EscapeUserVectorTy EscapeUsers;
526 for (User *U : Inst->users()) {
527
528 // Non-instruction user will never escape.
529 Instruction *UI = dyn_cast<Instruction>(U);
530 if (!UI)
531 continue;
532
533 if (S.contains(UI))
534 continue;
535
536 EscapeUsers.push_back(UI);
537 }
538
539 // Exit if no escape uses were found.
540 if (EscapeUsers.empty())
541 return;
542
543 // Get or create an escape alloca for this instruction.
544 auto *ScalarAddr = getOrCreateAlloca(Array);
545
546 // Remember that this instruction has escape uses and the escape alloca.
547 EscapeMap[Inst] = std::make_pair(ScalarAddr, std::move(EscapeUsers));
548}
549
551 ScopStmt &Stmt, LoopToScevMapT &LTS, ValueMapT &BBMap,
552 __isl_keep isl_id_to_ast_expr *NewAccesses) {
553 for (MemoryAccess *MA : Stmt) {
554 if (MA->isOriginalArrayKind() || MA->isWrite())
555 continue;
556
557#ifndef NDEBUG
558 auto StmtDom =
560 auto AccDom = MA->getAccessRelation().domain();
561 assert(!StmtDom.is_subset(AccDom).is_false() &&
562 "Scalar must be loaded in all statement instances");
563#endif
564
565 auto *Address =
566 getImplicitAddress(*MA, getLoopForStmt(Stmt), LTS, BBMap, NewAccesses);
567 BBMap[MA->getAccessValue()] = Builder.CreateLoad(
568 MA->getElementType(), Address, Address->getName() + ".reload");
569 }
570}
571
573 const isl::set &Subdomain) {
574 isl::ast_build AstBuild = Stmt.getAstBuild();
575 isl::set Domain = Stmt.getDomain();
576
577 isl::union_map USchedule = AstBuild.get_schedule();
578 USchedule = USchedule.intersect_domain(Domain);
579
580 assert(!USchedule.is_empty());
581 isl::map Schedule = isl::map::from_union_map(USchedule);
582
583 isl::set ScheduledDomain = Schedule.range();
584 isl::set ScheduledSet = Subdomain.apply(Schedule);
585
586 isl::ast_build RestrictedBuild = AstBuild.restrict(ScheduledDomain);
587
588 isl::ast_expr IsInSet = RestrictedBuild.expr_from(ScheduledSet);
589 Value *IsInSetExpr = ExprBuilder->create(IsInSet.copy());
590 IsInSetExpr = Builder.CreateICmpNE(
591 IsInSetExpr, ConstantInt::get(IsInSetExpr->getType(), 0));
592
593 return IsInSetExpr;
594}
595
597 ScopStmt &Stmt, const isl::set &Subdomain, StringRef Subject,
598 const std::function<void()> &GenThenFunc) {
599 isl::set StmtDom = Stmt.getDomain();
600
601 // If the condition is a tautology, don't generate a condition around the
602 // code.
603 bool IsPartialWrite =
604 !StmtDom.intersect_params(Stmt.getParent()->getContext())
605 .is_subset(Subdomain);
606 if (!IsPartialWrite) {
607 GenThenFunc();
608 return;
609 }
610
611 // Generate the condition.
612 Value *Cond = buildContainsCondition(Stmt, Subdomain);
613
614 // Don't call GenThenFunc if it is never executed. An ast index expression
615 // might not be defined in this case.
616 if (auto *Const = dyn_cast<ConstantInt>(Cond))
617 if (Const->isZero())
618 return;
619
620 BasicBlock *HeadBlock = Builder.GetInsertBlock();
621 StringRef BlockName = HeadBlock->getName();
622
623 // Generate the conditional block.
624 DomTreeUpdater DTU(GenDT, DomTreeUpdater::UpdateStrategy::Eager);
625 SplitBlockAndInsertIfThen(Cond, &*Builder.GetInsertPoint(), false, nullptr,
626 &DTU, GenLI);
627 BranchInst *Branch = cast<BranchInst>(HeadBlock->getTerminator());
628 BasicBlock *ThenBlock = Branch->getSuccessor(0);
629 BasicBlock *TailBlock = Branch->getSuccessor(1);
630
631 // Assign descriptive names.
632 if (auto *CondInst = dyn_cast<Instruction>(Cond))
633 CondInst->setName("polly." + Subject + ".cond");
634 ThenBlock->setName(BlockName + "." + Subject + ".partial");
635 TailBlock->setName(BlockName + ".cont");
636
637 // Put the client code into the conditional block and continue in the merge
638 // block afterwards.
639 Builder.SetInsertPoint(ThenBlock, ThenBlock->getFirstInsertionPt());
640 GenThenFunc();
641 Builder.SetInsertPoint(TailBlock, TailBlock->getFirstInsertionPt());
642}
643
644static std::string getInstName(Value *Val) {
645 std::string Result;
646 raw_string_ostream OS(Result);
647 Val->printAsOperand(OS, false);
648 return OS.str();
649}
650
652 ValueMapT &BBMap) {
653 if (!TraceStmts)
654 return;
655
656 Scop *S = Stmt.getParent();
657 const char *BaseName = Stmt.getBaseName();
658
659 isl::ast_build AstBuild = Stmt.getAstBuild();
660 isl::set Domain = Stmt.getDomain();
661
662 isl::union_map USchedule = AstBuild.get_schedule().intersect_domain(Domain);
663 isl::map Schedule = isl::map::from_union_map(USchedule);
664 assert(Schedule.is_empty().is_false() &&
665 "The stmt must have a valid instance");
666
667 isl::multi_pw_aff ScheduleMultiPwAff =
669 isl::ast_build RestrictedBuild = AstBuild.restrict(Schedule.range());
670
671 // Sequence of strings to print.
672 SmallVector<llvm::Value *, 8> Values;
673
674 // Print the name of the statement.
675 // TODO: Indent by the depth of the statement instance in the schedule tree.
676 Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, BaseName));
677 Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "("));
678
679 // Add the coordinate of the statement instance.
680 for (unsigned i : rangeIslSize(0, ScheduleMultiPwAff.dim(isl::dim::out))) {
681 if (i > 0)
682 Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, ","));
683
684 isl::ast_expr IsInSet = RestrictedBuild.expr_from(ScheduleMultiPwAff.at(i));
685 Values.push_back(ExprBuilder->create(IsInSet.copy()));
686 }
687
688 if (TraceScalars) {
689 Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, ")"));
690 DenseSet<Instruction *> Encountered;
691
692 // Add the value of each scalar (and the result of PHIs) used in the
693 // statement.
694 // TODO: Values used in region-statements.
695 for (Instruction *Inst : Stmt.insts()) {
696 if (!RuntimeDebugBuilder::isPrintable(Inst->getType()))
697 continue;
698
699 if (isa<PHINode>(Inst)) {
700 Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, " "));
702 Builder, getInstName(Inst)));
703 Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "="));
704 Values.push_back(getNewValue(Stmt, Inst, BBMap, LTS,
705 LI.getLoopFor(Inst->getParent())));
706 } else {
707 for (Value *Op : Inst->operand_values()) {
708 // Do not print values that cannot change during the execution of the
709 // SCoP.
710 auto *OpInst = dyn_cast<Instruction>(Op);
711 if (!OpInst)
712 continue;
713 if (!S->contains(OpInst))
714 continue;
715
716 // Print each scalar at most once, and exclude values defined in the
717 // statement itself.
718 if (Encountered.count(OpInst))
719 continue;
720
721 Values.push_back(
724 Builder, getInstName(OpInst)));
725 Values.push_back(
727 Values.push_back(getNewValue(Stmt, OpInst, BBMap, LTS,
728 LI.getLoopFor(Inst->getParent())));
729 Encountered.insert(OpInst);
730 }
731 }
732
733 Encountered.insert(Inst);
734 }
735
736 Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "\n"));
737 } else {
738 Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, ")\n"));
739 }
740
741 RuntimeDebugBuilder::createCPUPrinter(Builder, ArrayRef<Value *>(Values));
742}
743
745 ScopStmt &Stmt, LoopToScevMapT &LTS, ValueMapT &BBMap,
746 __isl_keep isl_id_to_ast_expr *NewAccesses) {
747 Loop *L = LI.getLoopFor(Stmt.getBasicBlock());
748
749 assert(Stmt.isBlockStmt() &&
750 "Region statements need to use the generateScalarStores() function in "
751 "the RegionGenerator");
752
753 for (MemoryAccess *MA : Stmt) {
754 if (MA->isOriginalArrayKind() || MA->isRead())
755 continue;
756
757 isl::set AccDom = MA->getAccessRelation().domain();
758 std::string Subject = MA->getId().get_name();
759
761 Stmt, AccDom, Subject.c_str(), [&, this, MA]() {
762 Value *Val = MA->getAccessValue();
763 if (MA->isAnyPHIKind()) {
764 assert(MA->getIncoming().size() >= 1 &&
765 "Block statements have exactly one exiting block, or "
766 "multiple but "
767 "with same incoming block and value");
768 assert(std::all_of(MA->getIncoming().begin(),
769 MA->getIncoming().end(),
770 [&](std::pair<BasicBlock *, Value *> p) -> bool {
771 return p.first == Stmt.getBasicBlock();
772 }) &&
773 "Incoming block must be statement's block");
774 Val = MA->getIncoming()[0].second;
775 }
776 auto Address = getImplicitAddress(*MA, getLoopForStmt(Stmt), LTS,
777 BBMap, NewAccesses);
778
779 Val = getNewValue(Stmt, Val, BBMap, LTS, L);
780 assert((!isa<Instruction>(Val) ||
781 DT.dominates(cast<Instruction>(Val)->getParent(),
782 Builder.GetInsertBlock())) &&
783 "Domination violation");
784 assert((!isa<Instruction>(Address) ||
785 DT.dominates(cast<Instruction>(Address)->getParent(),
786 Builder.GetInsertBlock())) &&
787 "Domination violation");
788
789 // The new Val might have a different type than the old Val due to
790 // ScalarEvolution looking through bitcasts.
791 Address = Builder.CreateBitOrPointerCast(
792 Address, Val->getType()->getPointerTo(
793 Address->getType()->getPointerAddressSpace()));
794
795 Builder.CreateStore(Val, Address);
796 });
797 }
798}
799
801 BasicBlock *ExitBB = S.getExit();
802 BasicBlock *PreEntryBB = S.getEnteringBlock();
803
804 Builder.SetInsertPoint(&*StartBlock->begin());
805
806 for (auto &Array : S.arrays()) {
807 if (Array->getNumberOfDimensions() != 0)
808 continue;
809 if (Array->isPHIKind()) {
810 // For PHI nodes, the only values we need to store are the ones that
811 // reach the PHI node from outside the region. In general there should
812 // only be one such incoming edge and this edge should enter through
813 // 'PreEntryBB'.
814 auto PHI = cast<PHINode>(Array->getBasePtr());
815
816 for (auto BI = PHI->block_begin(), BE = PHI->block_end(); BI != BE; BI++)
817 if (!S.contains(*BI) && *BI != PreEntryBB)
818 llvm_unreachable("Incoming edges from outside the scop should always "
819 "come from PreEntryBB");
820
821 int Idx = PHI->getBasicBlockIndex(PreEntryBB);
822 if (Idx < 0)
823 continue;
824
825 Value *ScalarValue = PHI->getIncomingValue(Idx);
826
827 Builder.CreateStore(ScalarValue, getOrCreateAlloca(Array));
828 continue;
829 }
830
831 auto *Inst = dyn_cast<Instruction>(Array->getBasePtr());
832
833 if (Inst && S.contains(Inst))
834 continue;
835
836 // PHI nodes that are not marked as such in their SAI object are either exit
837 // PHI nodes we model as common scalars but without initialization, or
838 // incoming phi nodes that need to be initialized. Check if the first is the
839 // case for Inst and do not create and initialize memory if so.
840 if (auto *PHI = dyn_cast_or_null<PHINode>(Inst))
841 if (!S.hasSingleExitEdge() && PHI->getBasicBlockIndex(ExitBB) >= 0)
842 continue;
843
844 Builder.CreateStore(Array->getBasePtr(), getOrCreateAlloca(Array));
845 }
846}
847
849 // The exit block of the __unoptimized__ region.
850 BasicBlock *ExitBB = S.getExitingBlock();
851 // The merge block __just after__ the region and the optimized region.
852 BasicBlock *MergeBB = S.getExit();
853
854 // The exit block of the __optimized__ region.
855 BasicBlock *OptExitBB = *(pred_begin(MergeBB));
856 if (OptExitBB == ExitBB)
857 OptExitBB = *(++pred_begin(MergeBB));
858
859 Builder.SetInsertPoint(OptExitBB->getTerminator());
860 for (const auto &EscapeMapping : EscapeMap) {
861 // Extract the escaping instruction and the escaping users as well as the
862 // alloca the instruction was demoted to.
863 Instruction *EscapeInst = EscapeMapping.first;
864 const auto &EscapeMappingValue = EscapeMapping.second;
865 const EscapeUserVectorTy &EscapeUsers = EscapeMappingValue.second;
866 auto *ScalarAddr = cast<AllocaInst>(&*EscapeMappingValue.first);
867
868 // Reload the demoted instruction in the optimized version of the SCoP.
869 Value *EscapeInstReload =
870 Builder.CreateLoad(ScalarAddr->getAllocatedType(), ScalarAddr,
871 EscapeInst->getName() + ".final_reload");
872 EscapeInstReload =
873 Builder.CreateBitOrPointerCast(EscapeInstReload, EscapeInst->getType());
874
875 // Create the merge PHI that merges the optimized and unoptimized version.
876 PHINode *MergePHI = PHINode::Create(EscapeInst->getType(), 2,
877 EscapeInst->getName() + ".merge");
878 MergePHI->insertBefore(&*MergeBB->getFirstInsertionPt());
879
880 // Add the respective values to the merge PHI.
881 MergePHI->addIncoming(EscapeInstReload, OptExitBB);
882 MergePHI->addIncoming(EscapeInst, ExitBB);
883
884 // The information of scalar evolution about the escaping instruction needs
885 // to be revoked so the new merged instruction will be used.
886 if (SE.isSCEVable(EscapeInst->getType()))
887 SE.forgetValue(EscapeInst);
888
889 // Replace all uses of the demoted instruction with the merge PHI.
890 for (Instruction *EUser : EscapeUsers)
891 EUser->replaceUsesOfWith(EscapeInst, MergePHI);
892 }
893}
894
896 for (auto &Array : S.arrays()) {
897
898 if (Array->getNumberOfDimensions() != 0)
899 continue;
900
901 if (Array->isPHIKind())
902 continue;
903
904 auto *Inst = dyn_cast<Instruction>(Array->getBasePtr());
905
906 if (!Inst)
907 continue;
908
909 // Scop invariant hoisting moves some of the base pointers out of the scop.
910 // We can ignore these, as the invariant load hoisting already registers the
911 // relevant outside users.
912 if (!S.contains(Inst))
913 continue;
914
916 }
917}
918
920 if (S.hasSingleExitEdge())
921 return;
922
923 auto *ExitBB = S.getExitingBlock();
924 auto *MergeBB = S.getExit();
925 auto *AfterMergeBB = MergeBB->getSingleSuccessor();
926 BasicBlock *OptExitBB = *(pred_begin(MergeBB));
927 if (OptExitBB == ExitBB)
928 OptExitBB = *(++pred_begin(MergeBB));
929
930 Builder.SetInsertPoint(OptExitBB->getTerminator());
931
932 for (auto &SAI : S.arrays()) {
933 auto *Val = SAI->getBasePtr();
934
935 // Only Value-like scalars need a merge PHI. Exit block PHIs receive either
936 // the original PHI's value or the reloaded incoming values from the
937 // generated code. An llvm::Value is merged between the original code's
938 // value or the generated one.
939 if (!SAI->isExitPHIKind())
940 continue;
941
942 PHINode *PHI = dyn_cast<PHINode>(Val);
943 if (!PHI)
944 continue;
945
946 if (PHI->getParent() != AfterMergeBB)
947 continue;
948
949 std::string Name = PHI->getName().str();
950 Value *ScalarAddr = getOrCreateAlloca(SAI);
951 Value *Reload = Builder.CreateLoad(SAI->getElementType(), ScalarAddr,
952 Name + ".ph.final_reload");
953 Reload = Builder.CreateBitOrPointerCast(Reload, PHI->getType());
954 Value *OriginalValue = PHI->getIncomingValueForBlock(MergeBB);
955 assert((!isa<Instruction>(OriginalValue) ||
956 cast<Instruction>(OriginalValue)->getParent() != MergeBB) &&
957 "Original value must no be one we just generated.");
958 auto *MergePHI = PHINode::Create(PHI->getType(), 2, Name + ".ph.merge");
959 MergePHI->insertBefore(&*MergeBB->getFirstInsertionPt());
960 MergePHI->addIncoming(Reload, OptExitBB);
961 MergePHI->addIncoming(OriginalValue, ExitBB);
962 int Idx = PHI->getBasicBlockIndex(MergeBB);
963 PHI->setIncomingValue(Idx, MergePHI);
964 }
965}
966
968 for (auto &Stmt : S)
969 if (Stmt.isCopyStmt())
970 continue;
971 else if (Stmt.isBlockStmt())
972 for (auto &Inst : *Stmt.getBasicBlock())
973 SE.forgetValue(&Inst);
974 else if (Stmt.isRegionStmt())
975 for (auto *BB : Stmt.getRegion()->blocks())
976 for (auto &Inst : *BB)
977 SE.forgetValue(&Inst);
978 else
979 llvm_unreachable("Unexpected statement type found");
980
981 // Invalidate SCEV of loops surrounding the EscapeUsers.
982 for (const auto &EscapeMapping : EscapeMap) {
983 const EscapeUserVectorTy &EscapeUsers = EscapeMapping.second.second;
984 for (Instruction *EUser : EscapeUsers) {
985 if (Loop *L = LI.getLoopFor(EUser->getParent()))
986 while (L) {
987 SE.forgetLoop(L);
988 L = L->getParentLoop();
989 }
990 }
991 }
992}
993
1000}
1001
1002BasicBlock *RegionGenerator::repairDominance(BasicBlock *BB,
1003 BasicBlock *BBCopy) {
1004
1005 BasicBlock *BBIDom = DT.getNode(BB)->getIDom()->getBlock();
1006 BasicBlock *BBCopyIDom = EndBlockMap.lookup(BBIDom);
1007
1008 if (BBCopyIDom)
1009 DT.changeImmediateDominator(BBCopy, BBCopyIDom);
1010
1011 return StartBlockMap.lookup(BBIDom);
1012}
1013
1014// This is to determine whether an llvm::Value (defined in @p BB) is usable when
1015// leaving a subregion. The straight-forward DT.dominates(BB, R->getExitBlock())
1016// does not work in cases where the exit block has edges from outside the
1017// region. In that case the llvm::Value would never be usable in in the exit
1018// block. The RegionGenerator however creates an new exit block ('ExitBBCopy')
1019// for the subregion's exiting edges only. We need to determine whether an
1020// llvm::Value is usable in there. We do this by checking whether it dominates
1021// all exiting blocks individually.
1022static bool isDominatingSubregionExit(const DominatorTree &DT, Region *R,
1023 BasicBlock *BB) {
1024 for (auto ExitingBB : predecessors(R->getExit())) {
1025 // Check for non-subregion incoming edges.
1026 if (!R->contains(ExitingBB))
1027 continue;
1028
1029 if (!DT.dominates(BB, ExitingBB))
1030 return false;
1031 }
1032
1033 return true;
1034}
1035
1036// Find the direct dominator of the subregion's exit block if the subregion was
1037// simplified.
1038static BasicBlock *findExitDominator(DominatorTree &DT, Region *R) {
1039 BasicBlock *Common = nullptr;
1040 for (auto ExitingBB : predecessors(R->getExit())) {
1041 // Check for non-subregion incoming edges.
1042 if (!R->contains(ExitingBB))
1043 continue;
1044
1045 // First exiting edge.
1046 if (!Common) {
1047 Common = ExitingBB;
1048 continue;
1049 }
1050
1051 Common = DT.findNearestCommonDominator(Common, ExitingBB);
1052 }
1053
1054 assert(Common && R->contains(Common));
1055 return Common;
1056}
1057
1059 __isl_keep isl_id_to_ast_expr *IdToAstExp) {
1060 assert(Stmt.isRegionStmt() &&
1061 "Only region statements can be copied by the region generator");
1062
1063 // Forget all old mappings.
1064 StartBlockMap.clear();
1065 EndBlockMap.clear();
1066 RegionMaps.clear();
1067 IncompletePHINodeMap.clear();
1068
1069 // Collection of all values related to this subregion.
1070 ValueMapT ValueMap;
1071
1072 // The region represented by the statement.
1073 Region *R = Stmt.getRegion();
1074
1075 // Create a dedicated entry for the region where we can reload all demoted
1076 // inputs.
1077 BasicBlock *EntryBB = R->getEntry();
1078 BasicBlock *EntryBBCopy = SplitBlock(Builder.GetInsertBlock(),
1079 &*Builder.GetInsertPoint(), &DT, &LI);
1080 EntryBBCopy->setName("polly.stmt." + EntryBB->getName() + ".entry");
1081 Builder.SetInsertPoint(&EntryBBCopy->front());
1082
1083 ValueMapT &EntryBBMap = RegionMaps[EntryBBCopy];
1084 generateScalarLoads(Stmt, LTS, EntryBBMap, IdToAstExp);
1085 generateBeginStmtTrace(Stmt, LTS, EntryBBMap);
1086
1087 for (auto PI = pred_begin(EntryBB), PE = pred_end(EntryBB); PI != PE; ++PI)
1088 if (!R->contains(*PI)) {
1089 StartBlockMap[*PI] = EntryBBCopy;
1090 EndBlockMap[*PI] = EntryBBCopy;
1091 }
1092
1093 // Iterate over all blocks in the region in a breadth-first search.
1094 std::deque<BasicBlock *> Blocks;
1095 SmallSetVector<BasicBlock *, 8> SeenBlocks;
1096 Blocks.push_back(EntryBB);
1097 SeenBlocks.insert(EntryBB);
1098
1099 while (!Blocks.empty()) {
1100 BasicBlock *BB = Blocks.front();
1101 Blocks.pop_front();
1102
1103 // First split the block and update dominance information.
1104 BasicBlock *BBCopy = splitBB(BB);
1105 BasicBlock *BBCopyIDom = repairDominance(BB, BBCopy);
1106
1107 // Get the mapping for this block and initialize it with either the scalar
1108 // loads from the generated entering block (which dominates all blocks of
1109 // this subregion) or the maps of the immediate dominator, if part of the
1110 // subregion. The latter necessarily includes the former.
1111 ValueMapT *InitBBMap;
1112 if (BBCopyIDom) {
1113 assert(RegionMaps.count(BBCopyIDom));
1114 InitBBMap = &RegionMaps[BBCopyIDom];
1115 } else
1116 InitBBMap = &EntryBBMap;
1117 auto Inserted = RegionMaps.insert(std::make_pair(BBCopy, *InitBBMap));
1118 ValueMapT &RegionMap = Inserted.first->second;
1119
1120 // Copy the block with the BlockGenerator.
1121 Builder.SetInsertPoint(&BBCopy->front());
1122 copyBB(Stmt, BB, BBCopy, RegionMap, LTS, IdToAstExp);
1123
1124 // In order to remap PHI nodes we store also basic block mappings.
1125 StartBlockMap[BB] = BBCopy;
1126 EndBlockMap[BB] = Builder.GetInsertBlock();
1127
1128 // Add values to incomplete PHI nodes waiting for this block to be copied.
1129 for (const PHINodePairTy &PHINodePair : IncompletePHINodeMap[BB])
1130 addOperandToPHI(Stmt, PHINodePair.first, PHINodePair.second, BB, LTS);
1131 IncompletePHINodeMap[BB].clear();
1132
1133 // And continue with new successors inside the region.
1134 for (auto SI = succ_begin(BB), SE = succ_end(BB); SI != SE; SI++)
1135 if (R->contains(*SI) && SeenBlocks.insert(*SI))
1136 Blocks.push_back(*SI);
1137
1138 // Remember value in case it is visible after this subregion.
1139 if (isDominatingSubregionExit(DT, R, BB))
1140 ValueMap.insert(RegionMap.begin(), RegionMap.end());
1141 }
1142
1143 // Now create a new dedicated region exit block and add it to the region map.
1144 BasicBlock *ExitBBCopy = SplitBlock(Builder.GetInsertBlock(),
1145 &*Builder.GetInsertPoint(), &DT, &LI);
1146 ExitBBCopy->setName("polly.stmt." + R->getExit()->getName() + ".exit");
1147 StartBlockMap[R->getExit()] = ExitBBCopy;
1148 EndBlockMap[R->getExit()] = ExitBBCopy;
1149
1150 BasicBlock *ExitDomBBCopy = EndBlockMap.lookup(findExitDominator(DT, R));
1151 assert(ExitDomBBCopy &&
1152 "Common exit dominator must be within region; at least the entry node "
1153 "must match");
1154 DT.changeImmediateDominator(ExitBBCopy, ExitDomBBCopy);
1155
1156 // As the block generator doesn't handle control flow we need to add the
1157 // region control flow by hand after all blocks have been copied.
1158 for (BasicBlock *BB : SeenBlocks) {
1159
1160 BasicBlock *BBCopyStart = StartBlockMap[BB];
1161 BasicBlock *BBCopyEnd = EndBlockMap[BB];
1162 Instruction *TI = BB->getTerminator();
1163 if (isa<UnreachableInst>(TI)) {
1164 while (!BBCopyEnd->empty())
1165 BBCopyEnd->begin()->eraseFromParent();
1166 new UnreachableInst(BBCopyEnd->getContext(), BBCopyEnd);
1167 continue;
1168 }
1169
1170 Instruction *BICopy = BBCopyEnd->getTerminator();
1171
1172 ValueMapT &RegionMap = RegionMaps[BBCopyStart];
1173 RegionMap.insert(StartBlockMap.begin(), StartBlockMap.end());
1174
1175 Builder.SetInsertPoint(BICopy);
1176 copyInstScalar(Stmt, TI, RegionMap, LTS);
1177 BICopy->eraseFromParent();
1178 }
1179
1180 // Add counting PHI nodes to all loops in the region that can be used as
1181 // replacement for SCEVs referring to the old loop.
1182 for (BasicBlock *BB : SeenBlocks) {
1183 Loop *L = LI.getLoopFor(BB);
1184 if (L == nullptr || L->getHeader() != BB || !R->contains(L))
1185 continue;
1186
1187 BasicBlock *BBCopy = StartBlockMap[BB];
1188 Value *NullVal = Builder.getInt32(0);
1189 PHINode *LoopPHI =
1190 PHINode::Create(Builder.getInt32Ty(), 2, "polly.subregion.iv");
1191 Instruction *LoopPHIInc = BinaryOperator::CreateAdd(
1192 LoopPHI, Builder.getInt32(1), "polly.subregion.iv.inc");
1193 LoopPHI->insertBefore(&BBCopy->front());
1194 LoopPHIInc->insertBefore(BBCopy->getTerminator());
1195
1196 for (auto *PredBB : predecessors(BB)) {
1197 if (!R->contains(PredBB))
1198 continue;
1199 if (L->contains(PredBB))
1200 LoopPHI->addIncoming(LoopPHIInc, EndBlockMap[PredBB]);
1201 else
1202 LoopPHI->addIncoming(NullVal, EndBlockMap[PredBB]);
1203 }
1204
1205 for (auto *PredBBCopy : predecessors(BBCopy))
1206 if (LoopPHI->getBasicBlockIndex(PredBBCopy) < 0)
1207 LoopPHI->addIncoming(NullVal, PredBBCopy);
1208
1209 LTS[L] = SE.getUnknown(LoopPHI);
1210 }
1211
1212 // Continue generating code in the exit block.
1213 Builder.SetInsertPoint(&*ExitBBCopy->getFirstInsertionPt());
1214
1215 // Write values visible to other statements.
1216 generateScalarStores(Stmt, LTS, ValueMap, IdToAstExp);
1217 StartBlockMap.clear();
1218 EndBlockMap.clear();
1219 RegionMaps.clear();
1220 IncompletePHINodeMap.clear();
1221}
1222
1224 ValueMapT &BBMap, Loop *L) {
1225 ScopStmt *Stmt = MA->getStatement();
1226 Region *SubR = Stmt->getRegion();
1227 auto Incoming = MA->getIncoming();
1228
1229 PollyIRBuilder::InsertPointGuard IPGuard(Builder);
1230 PHINode *OrigPHI = cast<PHINode>(MA->getAccessInstruction());
1231 BasicBlock *NewSubregionExit = Builder.GetInsertBlock();
1232
1233 // This can happen if the subregion is simplified after the ScopStmts
1234 // have been created; simplification happens as part of CodeGeneration.
1235 if (OrigPHI->getParent() != SubR->getExit()) {
1236 BasicBlock *FormerExit = SubR->getExitingBlock();
1237 if (FormerExit)
1238 NewSubregionExit = StartBlockMap.lookup(FormerExit);
1239 }
1240
1241 PHINode *NewPHI = PHINode::Create(OrigPHI->getType(), Incoming.size(),
1242 "polly." + OrigPHI->getName(),
1243 NewSubregionExit->getFirstNonPHIIt());
1244
1245 // Add the incoming values to the PHI.
1246 for (auto &Pair : Incoming) {
1247 BasicBlock *OrigIncomingBlock = Pair.first;
1248 BasicBlock *NewIncomingBlockStart = StartBlockMap.lookup(OrigIncomingBlock);
1249 BasicBlock *NewIncomingBlockEnd = EndBlockMap.lookup(OrigIncomingBlock);
1250 Builder.SetInsertPoint(NewIncomingBlockEnd->getTerminator());
1251 assert(RegionMaps.count(NewIncomingBlockStart));
1252 assert(RegionMaps.count(NewIncomingBlockEnd));
1253 ValueMapT *LocalBBMap = &RegionMaps[NewIncomingBlockStart];
1254
1255 Value *OrigIncomingValue = Pair.second;
1256 Value *NewIncomingValue =
1257 getNewValue(*Stmt, OrigIncomingValue, *LocalBBMap, LTS, L);
1258 NewPHI->addIncoming(NewIncomingValue, NewIncomingBlockEnd);
1259 }
1260
1261 return NewPHI;
1262}
1263
1265 ValueMapT &BBMap) {
1266 ScopStmt *Stmt = MA->getStatement();
1267
1268 // TODO: Add some test cases that ensure this is really the right choice.
1269 Loop *L = LI.getLoopFor(Stmt->getRegion()->getExit());
1270
1271 if (MA->isAnyPHIKind()) {
1272 auto Incoming = MA->getIncoming();
1273 assert(!Incoming.empty() &&
1274 "PHI WRITEs must have originate from at least one incoming block");
1275
1276 // If there is only one incoming value, we do not need to create a PHI.
1277 if (Incoming.size() == 1) {
1278 Value *OldVal = Incoming[0].second;
1279 return getNewValue(*Stmt, OldVal, BBMap, LTS, L);
1280 }
1281
1282 return buildExitPHI(MA, LTS, BBMap, L);
1283 }
1284
1285 // MemoryKind::Value accesses leaving the subregion must dominate the exit
1286 // block; just pass the copied value.
1287 Value *OldVal = MA->getAccessValue();
1288 return getNewValue(*Stmt, OldVal, BBMap, LTS, L);
1289}
1290
1292 ScopStmt &Stmt, LoopToScevMapT &LTS, ValueMapT &BBMap,
1293 __isl_keep isl_id_to_ast_expr *NewAccesses) {
1294 assert(Stmt.getRegion() &&
1295 "Block statements need to use the generateScalarStores() "
1296 "function in the BlockGenerator");
1297
1298 // Get the exit scalar values before generating the writes.
1299 // This is necessary because RegionGenerator::getExitScalar may insert
1300 // PHINodes that depend on the region's exiting blocks. But
1301 // BlockGenerator::generateConditionalExecution may insert a new basic block
1302 // such that the current basic block is not a direct successor of the exiting
1303 // blocks anymore. Hence, build the PHINodes while the current block is still
1304 // the direct successor.
1305 SmallDenseMap<MemoryAccess *, Value *> NewExitScalars;
1306 for (MemoryAccess *MA : Stmt) {
1307 if (MA->isOriginalArrayKind() || MA->isRead())
1308 continue;
1309
1310 Value *NewVal = getExitScalar(MA, LTS, BBMap);
1311 NewExitScalars[MA] = NewVal;
1312 }
1313
1314 for (MemoryAccess *MA : Stmt) {
1315 if (MA->isOriginalArrayKind() || MA->isRead())
1316 continue;
1317
1318 isl::set AccDom = MA->getAccessRelation().domain();
1319 std::string Subject = MA->getId().get_name();
1321 Stmt, AccDom, Subject.c_str(), [&, this, MA]() {
1322 Value *NewVal = NewExitScalars.lookup(MA);
1323 assert(NewVal && "The exit scalar must be determined before");
1324 Value *Address = getImplicitAddress(*MA, getLoopForStmt(Stmt), LTS,
1325 BBMap, NewAccesses);
1326 assert((!isa<Instruction>(NewVal) ||
1327 DT.dominates(cast<Instruction>(NewVal)->getParent(),
1328 Builder.GetInsertBlock())) &&
1329 "Domination violation");
1330 assert((!isa<Instruction>(Address) ||
1331 DT.dominates(cast<Instruction>(Address)->getParent(),
1332 Builder.GetInsertBlock())) &&
1333 "Domination violation");
1334 Builder.CreateStore(NewVal, Address);
1335 });
1336 }
1337}
1338
1340 PHINode *PHICopy, BasicBlock *IncomingBB,
1341 LoopToScevMapT &LTS) {
1342 // If the incoming block was not yet copied mark this PHI as incomplete.
1343 // Once the block will be copied the incoming value will be added.
1344 BasicBlock *BBCopyStart = StartBlockMap[IncomingBB];
1345 BasicBlock *BBCopyEnd = EndBlockMap[IncomingBB];
1346 if (!BBCopyStart) {
1347 assert(!BBCopyEnd);
1348 assert(Stmt.represents(IncomingBB) &&
1349 "Bad incoming block for PHI in non-affine region");
1350 IncompletePHINodeMap[IncomingBB].push_back(std::make_pair(PHI, PHICopy));
1351 return;
1352 }
1353
1354 assert(RegionMaps.count(BBCopyStart) &&
1355 "Incoming PHI block did not have a BBMap");
1356 ValueMapT &BBCopyMap = RegionMaps[BBCopyStart];
1357
1358 Value *OpCopy = nullptr;
1359
1360 if (Stmt.represents(IncomingBB)) {
1361 Value *Op = PHI->getIncomingValueForBlock(IncomingBB);
1362
1363 // If the current insert block is different from the PHIs incoming block
1364 // change it, otherwise do not.
1365 auto IP = Builder.GetInsertPoint();
1366 if (IP->getParent() != BBCopyEnd)
1367 Builder.SetInsertPoint(BBCopyEnd->getTerminator());
1368 OpCopy = getNewValue(Stmt, Op, BBCopyMap, LTS, getLoopForStmt(Stmt));
1369 if (IP->getParent() != BBCopyEnd)
1370 Builder.SetInsertPoint(&*IP);
1371 } else {
1372 // All edges from outside the non-affine region become a single edge
1373 // in the new copy of the non-affine region. Make sure to only add the
1374 // corresponding edge the first time we encounter a basic block from
1375 // outside the non-affine region.
1376 if (PHICopy->getBasicBlockIndex(BBCopyEnd) >= 0)
1377 return;
1378
1379 // Get the reloaded value.
1380 OpCopy = getNewValue(Stmt, PHI, BBCopyMap, LTS, getLoopForStmt(Stmt));
1381 }
1382
1383 assert(OpCopy && "Incoming PHI value was not copied properly");
1384 PHICopy->addIncoming(OpCopy, BBCopyEnd);
1385}
1386
1388 ValueMapT &BBMap,
1389 LoopToScevMapT &LTS) {
1390 unsigned NumIncoming = PHI->getNumIncomingValues();
1391 PHINode *PHICopy =
1392 Builder.CreatePHI(PHI->getType(), NumIncoming, "polly." + PHI->getName());
1393 PHICopy->moveBefore(PHICopy->getParent()->getFirstNonPHI());
1394 BBMap[PHI] = PHICopy;
1395
1396 for (BasicBlock *IncomingBB : PHI->blocks())
1397 addOperandToPHI(Stmt, PHI, PHICopy, IncomingBB, LTS);
1398}
static cl::opt< bool > Aligned("enable-polly-aligned", cl::desc("Assumed aligned memory accesses."), cl::Hidden, cl::cat(PollyCategory))
static bool isDominatingSubregionExit(const DominatorTree &DT, Region *R, BasicBlock *BB)
static BasicBlock * findExitDominator(DominatorTree &DT, Region *R)
static cl::opt< bool, true > DebugPrintingX("polly-codegen-add-debug-printing", cl::desc("Add printf calls that show the values loaded/stored."), cl::location(PollyDebugPrinting), cl::Hidden, cl::cat(PollyCategory))
static std::string getInstName(Value *Val)
static cl::opt< bool > TraceStmts("polly-codegen-trace-stmts", cl::desc("Add printf calls that print the statement being executed"), cl::Hidden, cl::cat(PollyCategory))
bool PollyDebugPrinting
static cl::opt< bool > TraceScalars("polly-codegen-trace-scalars", cl::desc("Add printf calls that print the values of all scalar values " "used in a statement. Requires -polly-codegen-trace-stmts."), cl::Hidden, cl::cat(PollyCategory))
llvm::cl::OptionCategory PollyCategory
bool PollyDebugPrinting
__isl_give isl_ast_expr * isl_ast_expr_address_of(__isl_take isl_ast_expr *expr)
Definition: isl_ast.c:649
isl::ast_expr expr_from(isl::pw_aff pa) const
isl::union_map get_schedule() const
isl::ast_build restrict(isl::set set) const
__isl_give isl_ast_expr * copy() const &
bool is_false() const
__isl_give isl_id * release()
std::string get_name() const
isl::map reverse() const
isl::set range() const
static isl::map from_union_map(isl::union_map umap)
isl::set domain() const
boolean is_empty() const
isl::pw_aff at(int pos) const
class size dim(isl::dim type) const
static isl::pw_multi_aff from_map(isl::map map)
boolean is_subset(const isl::set &set2) const
isl::set intersect_params(isl::set params) const
isl::set apply(isl::map map) const
boolean is_empty() const
isl::union_map intersect_domain(isl::space space) const
Loop * getLoopForStmt(const ScopStmt &Stmt) const
Get the innermost loop that surrounds the statement Stmt.
EscapeUsersAllocaMapTy & EscapeMap
Map from instructions to their escape users as well as the alloca.
Value * getImplicitAddress(MemoryAccess &Access, Loop *L, LoopToScevMapT &LTS, ValueMapT &BBMap, __isl_keep isl_id_to_ast_expr *NewAccesses)
Generate the pointer value that is accesses by Access.
DominatorTree & DT
The dominator tree of this function.
BasicBlock * splitBB(BasicBlock *BB)
Split BB to create a new one we can use to clone BB in.
void generateBeginStmtTrace(ScopStmt &Stmt, LoopToScevMapT &LTS, ValueMapT &BBMap)
When statement tracing is enabled, build the print instructions for printing the current statement in...
Value * trySynthesizeNewValue(ScopStmt &Stmt, Value *Old, ValueMapT &BBMap, LoopToScevMapT &LTS, Loop *L) const
Try to synthesize a new value.
void generateScalarLoads(ScopStmt &Stmt, LoopToScevMapT &LTS, ValueMapT &BBMap, __isl_keep isl_id_to_ast_expr *NewAccesses)
Generate reload of scalars demoted to memory and needed by Stmt.
AllocaMapTy & ScalarMap
Map to resolve scalar dependences for PHI operands and scalars.
DenseMap< const ScopArrayInfo *, AssertingVH< AllocaInst > > AllocaMapTy
Map types to resolve scalar dependences.
PollyIRBuilder & Builder
void createExitPHINodeMerges(Scop &S)
Create exit PHI node merges for PHI nodes with more than two edges from inside the scop.
void copyInstScalar(ScopStmt &Stmt, Instruction *Inst, ValueMapT &BBMap, LoopToScevMapT &LTS)
Value * generateArrayLoad(ScopStmt &Stmt, LoadInst *load, ValueMapT &BBMap, LoopToScevMapT &LTS, isl_id_to_ast_expr *NewAccesses)
Value * buildContainsCondition(ScopStmt &Stmt, const isl::set &Subdomain)
Generate instructions that compute whether one instance of Set is executed.
void finalizeSCoP(Scop &S)
Finalize the code generation for the SCoP S.
void createScalarInitialization(Scop &S)
Initialize the memory of demoted scalars.
SmallVector< Instruction *, 4 > EscapeUserVectorTy
Simple vector of instructions to store escape users.
bool canSyntheziseInStmt(ScopStmt &Stmt, Instruction *Inst)
Helper to determine if Inst can be synthesized in Stmt.
virtual void generateScalarStores(ScopStmt &Stmt, LoopToScevMapT &LTS, ValueMapT &BBMap, __isl_keep isl_id_to_ast_expr *NewAccesses)
Generate the scalar stores for the given statement.
ScalarEvolution & SE
IslExprBuilder * ExprBuilder
void handleOutsideUsers(const Scop &S, ScopArrayInfo *Array)
Handle users of Array outside the SCoP.
void createScalarFinalization(Scop &S)
Promote the values of demoted scalars after the SCoP.
void switchGeneratedFunc(Function *GenFn, DominatorTree *GenDT, LoopInfo *GenLI, ScalarEvolution *GenSE)
Change the function that code is emitted into.
Value * getNewValue(ScopStmt &Stmt, Value *Old, ValueMapT &BBMap, LoopToScevMapT &LTS, Loop *L) const
Get the new version of a value.
ValueMapT & GlobalMap
A map from llvm::Values referenced in the old code to a new set of llvm::Values, which is used to rep...
void findOutsideUsers(Scop &S)
Find scalar statements that have outside users.
void generateArrayStore(ScopStmt &Stmt, StoreInst *store, ValueMapT &BBMap, LoopToScevMapT &LTS, isl_id_to_ast_expr *NewAccesses)
DominatorTree * GenDT
Relates to the region where the code is emitted into.
BasicBlock * copyBB(ScopStmt &Stmt, BasicBlock *BB, ValueMapT &BBMap, LoopToScevMapT &LTS, isl_id_to_ast_expr *NewAccesses)
Copy the given basic block.
MapVector< Instruction *, std::pair< AssertingVH< Value >, EscapeUserVectorTy > > EscapeUsersAllocaMapTy
Map type to resolve escaping users for scalar instructions.
virtual void copyPHIInstruction(ScopStmt &, PHINode *, ValueMapT &, LoopToScevMapT &)
Copy a single PHI instruction.
void copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS, isl_id_to_ast_expr *NewAccesses)
Copy the basic block.
BasicBlock * StartBlock
The first basic block after the RTC.
void copyInstruction(ScopStmt &Stmt, Instruction *Inst, ValueMapT &BBMap, LoopToScevMapT &LTS, isl_id_to_ast_expr *NewAccesses)
Copy a single Instruction.
void invalidateScalarEvolution(Scop &S)
Invalidate the scalar evolution expressions for a scop.
BlockGenerator(PollyIRBuilder &Builder, LoopInfo &LI, ScalarEvolution &SE, DominatorTree &DT, AllocaMapTy &ScalarMap, EscapeUsersAllocaMapTy &EscapeMap, ValueMapT &GlobalMap, IslExprBuilder *ExprBuilder, BasicBlock *StartBlock)
Create a generator for basic blocks.
ScalarEvolution * GenSE
void removeDeadInstructions(BasicBlock *BB, ValueMapT &BBMap)
Remove dead instructions generated for BB.
Value * generateLocationAccessed(ScopStmt &Stmt, MemAccInst Inst, ValueMapT &BBMap, LoopToScevMapT &LTS, isl_id_to_ast_expr *NewAccesses)
Generate the operand address.
Value * getOrCreateAlloca(const MemoryAccess &Access)
Return the alloca for Access.
void generateConditionalExecution(ScopStmt &Stmt, const isl::set &Subdomain, StringRef Subject, const std::function< void()> &GenThenFunc)
Generate code that executes in a subset of Stmt's domain.
LLVM-IR generator for isl_ast_expr[essions].
llvm::Value * create(__isl_take isl_ast_expr *Expr)
Create LLVM-IR for an isl_ast_expr[ession].
Utility proxy to wrap the common members of LoadInst and StoreInst.
Definition: ScopHelper.h:140
bool isNull() const
Definition: ScopHelper.h:305
llvm::Value * getPointerOperand() const
Definition: ScopHelper.h:248
Represent memory accesses in statements.
Definition: ScopInfo.h:431
const ScopArrayInfo * getLatestScopArrayInfo() const
Get the ScopArrayInfo object for the base address, or the one set by setNewAccessRelation().
Definition: ScopInfo.cpp:560
bool isAnyPHIKind() const
Old name of isOriginalAnyPHIKind().
Definition: ScopInfo.h:1028
bool isLatestArrayKind() const
Whether storage memory is either an custom .s2a/.phiops alloca (false) or an existing pointer into an...
Definition: ScopInfo.h:950
Instruction * getAccessInstruction() const
Return the access instruction of this memory access.
Definition: ScopInfo.h:885
isl::id getId() const
Get identifier for the memory access.
Definition: ScopInfo.cpp:917
ArrayRef< std::pair< BasicBlock *, Value * > > getIncoming() const
Return the list of possible PHI/ExitPHI values.
Definition: ScopInfo.h:748
ScopStmt * getStatement() const
Get the statement that contains this memory access.
Definition: ScopInfo.h:1031
isl::map getAccessRelation() const
Old name of getLatestAccessRelation().
Definition: ScopInfo.h:795
Value * getAccessValue() const
Return the access value of this memory access.
Definition: ScopInfo.h:867
std::pair< PHINode *, PHINode * > PHINodePairTy
Mapping to remember PHI nodes that still need incoming values.
void copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS, __isl_keep isl_id_to_ast_expr *IdToAstExp)
Copy the region statement Stmt.
DenseMap< BasicBlock *, SmallVector< PHINodePairTy, 4 > > IncompletePHINodeMap
void addOperandToPHI(ScopStmt &Stmt, PHINode *PHI, PHINode *PHICopy, BasicBlock *IncomingBB, LoopToScevMapT &LTS)
Add the new operand from the copy of IncomingBB to PHICopy.
void copyPHIInstruction(ScopStmt &Stmt, PHINode *Inst, ValueMapT &BBMap, LoopToScevMapT &LTS) override
Copy a single PHI instruction.
DenseMap< BasicBlock *, BasicBlock * > EndBlockMap
A map from old to the last new block in the region, that was created to model the old basic block.
Value * getExitScalar(MemoryAccess *MA, LoopToScevMapT &LTS, ValueMapT &BBMap)
DenseMap< BasicBlock *, BasicBlock * > StartBlockMap
A map from old to the first new block in the region, that was created to model the old basic block.
void generateScalarStores(ScopStmt &Stmt, LoopToScevMapT &LTS, ValueMapT &BBMAp, __isl_keep isl_id_to_ast_expr *NewAccesses) override
Generate the scalar stores for the given statement.
DenseMap< BasicBlock *, ValueMapT > RegionMaps
The "BBMaps" for the whole region (one for each block).
PHINode * buildExitPHI(MemoryAccess *MA, LoopToScevMapT &LTS, ValueMapT &BBMap, Loop *L)
Create a PHI that combines the incoming values from all incoming blocks that are in the subregion.
BasicBlock * repairDominance(BasicBlock *BB, BasicBlock *BBCopy)
Repair the dominance tree after we created a copy block for BB.
A class to store information about arrays in the SCoP.
Definition: ScopInfo.h:219
Statement of the Scop.
Definition: ScopInfo.h:1140
MemoryAccess & getArrayAccessFor(const Instruction *Inst) const
Return the only array access for Inst.
Definition: ScopInfo.h:1434
Scop * getParent()
Definition: ScopInfo.h:1528
BasicBlock * getEntryBlock() const
Return a BasicBlock from this statement.
Definition: ScopInfo.cpp:1221
const std::vector< Instruction * > & getInstructions() const
Definition: ScopInfo.h:1531
bool isBlockStmt() const
Return true if this statement represents a single basic block.
Definition: ScopInfo.h:1321
Region * getRegion() const
Get the region represented by this ScopStmt (if any).
Definition: ScopInfo.h:1330
bool represents(BasicBlock *BB) const
Return whether this statement represents BB.
Definition: ScopInfo.h:1351
iterator_range< std::vector< Instruction * >::const_iterator > insts() const
The range of instructions in this statement.
Definition: ScopInfo.h:1550
BasicBlock * getBasicBlock() const
Get the BasicBlock represented by this ScopStmt (if any).
Definition: ScopInfo.h:1318
const char * getBaseName() const
Definition: ScopInfo.cpp:1229
isl::ast_build getAstBuild() const
Get the isl AST build.
Definition: ScopInfo.h:1565
MemoryAccess * getArrayAccessOrNULLFor(const Instruction *Inst) const
Return the only array access for Inst, if existing.
Definition: ScopInfo.h:1411
bool isRegionStmt() const
Return true if this statement represents a whole region.
Definition: ScopInfo.h:1333
isl::set getDomain() const
Get the iteration domain of this ScopStmt.
Definition: ScopInfo.cpp:1237
Static Control Part.
Definition: ScopInfo.h:1630
isl::set getContext() const
Get the constraint on parameter of this Scop.
Definition: ScopInfo.cpp:1832
static VirtualUse create(Scop *S, const Use &U, LoopInfo *LI, bool Virtual)
Get a VirtualUse for an llvm::Use.
#define __isl_take
Definition: ctx.h:22
#define __isl_keep
Definition: ctx.h:25
B()
#define assert(exp)
This file contains the declaration of the PolyhedralInfo class, which will provide an interface to ex...
@ Array
MemoryKind::Array: Models a one or multi-dimensional array.
@ Value
MemoryKind::Value: Models an llvm::Value.
@ PHI
MemoryKind::PHI: Models PHI nodes within the SCoP.
llvm::iota_range< unsigned > rangeIslSize(unsigned Begin, isl::size End)
Check that End is valid and return an iterator from Begin to End.
Definition: ISLTools.cpp:597
llvm::Value * expandCodeFor(Scop &S, llvm::ScalarEvolution &SE, llvm::Function *GenFn, llvm::ScalarEvolution &GenSE, const llvm::DataLayout &DL, const char *Name, const llvm::SCEV *E, llvm::Type *Ty, llvm::Instruction *IP, ValueMapT *VMap, LoopToScevMapT *LoopMap, llvm::BasicBlock *RTCBB)
Wrapper for SCEVExpander extended to all Polly features.
llvm::IRBuilder< llvm::ConstantFolder, IRInserter > PollyIRBuilder
Definition: IRBuilder.h:140
llvm::DenseMap< llvm::AssertingVH< llvm::Value >, llvm::AssertingVH< llvm::Value > > ValueMapT
Type to remap values.
Definition: ScopHelper.h:106
llvm::DenseMap< const llvm::Loop *, const llvm::SCEV * > LoopToScevMapT
Same as llvm/Analysis/ScalarEvolutionExpressions.h.
Definition: ScopHelper.h:40
bool isIgnoredIntrinsic(const llvm::Value *V)
Return true iff V is an intrinsic that we ignore during code generation.
bool canSynthesize(const llvm::Value *V, const Scop &S, llvm::ScalarEvolution *SE, llvm::Loop *Scope)
Check whether a value an be synthesized by the code generator.
static void createCPUPrinter(PollyIRBuilder &Builder, Args... args)
Print a set of LLVM-IR Values or StringRefs via printf.
static bool isPrintable(llvm::Type *Ty)
Return whether an llvm::Value of the type Ty is printable for debugging.
static llvm::Value * getPrintableString(PollyIRBuilder &Builder, llvm::StringRef Str)
Generate a constant string into the builder's llvm::Module which can be passed to createCPUPrinter().
static TupleKindPtr Domain("Domain")