Polly 22.0.0git
CodeGeneration.cpp File Reference
#include "polly/CodeGen/CodeGeneration.h"
#include "polly/CodeGen/IRBuilder.h"
#include "polly/CodeGen/IslAst.h"
#include "polly/CodeGen/IslNodeBuilder.h"
#include "polly/CodeGen/PerfMonitor.h"
#include "polly/CodeGen/Utils.h"
#include "polly/DependenceInfo.h"
#include "polly/LinkAllPasses.h"
#include "polly/Options.h"
#include "polly/ScopInfo.h"
#include "polly/Support/ScopHelper.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Verifier.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "isl/ast.h"
#include <cassert>
#include "polly/Support/PollyDebug.h"

Go to the source code of this file.

Namespaces

namespace  polly

Macros

#define DEBUG_TYPE   "polly-codegen"

Functions

static cl::opt< bool > Verify ("polly-codegen-verify", cl::desc("Verify the function generated by Polly"), cl::Hidden, cl::cat(PollyCategory))
static cl::opt< bool, true > XPerfMonitoring ("polly-codegen-perf-monitoring", cl::desc("Add run-time performance monitoring"), cl::Hidden, cl::location(polly::PerfMonitoring), cl::cat(PollyCategory))
 STATISTIC (ScopsProcessed, "Number of SCoP processed")
 STATISTIC (CodegenedScops, "Number of successfully generated SCoPs")
 STATISTIC (CodegenedAffineLoops, "Number of original affine loops in SCoPs that have been generated")
 STATISTIC (CodegenedBoxedLoops, "Number of original boxed loops in SCoPs that have been generated")
void polly::markBlockUnreachable (BasicBlock &Block, PollyIRBuilder &Builder)
 Mark a basic block unreachable.
static void verifyGeneratedFunction (Scop &S, Function &F, IslAstInfo &AI)
static void fixRegionInfo (Function &F, Region &ParentRegion, RegionInfo &RI)
static void removeLifetimeMarkers (Region *R)
 Remove all lifetime markers (llvm.lifetime.start, llvm.lifetime.end) from @R.
static bool generateCode (Scop &S, IslAstInfo &AI, LoopInfo &LI, DominatorTree &DT, ScalarEvolution &SE, RegionInfo &RI)
 INITIALIZE_PASS_BEGIN (CodeGeneration, "polly-codegen", "Polly - Create LLVM-IR from SCoPs", false, false)
 INITIALIZE_PASS_DEPENDENCY (DependenceInfo)
 INITIALIZE_PASS_DEPENDENCY (DominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY (LoopInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY (RegionInfoPass)
 INITIALIZE_PASS_DEPENDENCY (ScalarEvolutionWrapperPass)
 INITIALIZE_PASS_DEPENDENCY (ScopDetectionWrapperPass)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "polly-codegen"

Definition at line 52 of file CodeGeneration.cpp.

Function Documentation

◆ fixRegionInfo()

void fixRegionInfo ( Function & F,
Region & ParentRegion,
RegionInfo & RI )
static

Definition at line 108 of file CodeGeneration.cpp.

References Function.

Referenced by generateCode().

◆ generateCode()

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( CodeGeneration ,
"polly-codegen" ,
"Polly - Create LLVM-IR from SCoPs" ,
false ,
false  )

◆ INITIALIZE_PASS_DEPENDENCY() [1/6]

INITIALIZE_PASS_DEPENDENCY ( DependenceInfo )

◆ INITIALIZE_PASS_DEPENDENCY() [2/6]

INITIALIZE_PASS_DEPENDENCY ( DominatorTreeWrapperPass )

◆ INITIALIZE_PASS_DEPENDENCY() [3/6]

INITIALIZE_PASS_DEPENDENCY ( LoopInfoWrapperPass )

◆ INITIALIZE_PASS_DEPENDENCY() [4/6]

INITIALIZE_PASS_DEPENDENCY ( RegionInfoPass )

◆ INITIALIZE_PASS_DEPENDENCY() [5/6]

INITIALIZE_PASS_DEPENDENCY ( ScalarEvolutionWrapperPass )

◆ INITIALIZE_PASS_DEPENDENCY() [6/6]

INITIALIZE_PASS_DEPENDENCY ( ScopDetectionWrapperPass )

◆ removeLifetimeMarkers()

void removeLifetimeMarkers ( Region * R)
static

Remove all lifetime markers (llvm.lifetime.start, llvm.lifetime.end) from @R.

CodeGeneration does not copy lifetime markers into the optimized SCoP, which would leave the them only in the original path. This can transform code such as

llvm.lifetime.start(%p)
llvm.lifetime.end(%p)

into

if (RTC) {
  // generated code
} else {
  // original code
  llvm.lifetime.start(%p)
}
llvm.lifetime.end(%p)

The current StackColoring algorithm cannot handle if some, but not all, paths from the end marker to the entry block cross the start marker. Same for start markers that do not always cross the end markers. We avoid any issues by removing all lifetime markers, even from the original code.

A better solution could be to hoist all llvm.lifetime.start to the split node and all llvm.lifetime.end to the merge node, which should be conservatively correct.

Definition at line 145 of file CodeGeneration.cpp.

Referenced by generateCode().

◆ STATISTIC() [1/4]

STATISTIC ( CodegenedAffineLoops ,
"Number of original affine loops in SCoPs that have been generated"  )

◆ STATISTIC() [2/4]

STATISTIC ( CodegenedBoxedLoops ,
"Number of original boxed loops in SCoPs that have been generated"  )

◆ STATISTIC() [3/4]

STATISTIC ( CodegenedScops ,
"Number of successfully generated SCoPs"  )

◆ STATISTIC() [4/4]

STATISTIC ( ScopsProcessed ,
"Number of SCoP processed"  )

◆ Verify()

cl::opt< bool > Verify ( "polly-codegen-verify" ,
cl::desc("Verify the function generated by Polly") ,
cl::Hidden ,
cl::cat(PollyCategory)  )
static

◆ verifyGeneratedFunction()

void verifyGeneratedFunction ( Scop & S,
Function & F,
IslAstInfo & AI )
static

Definition at line 87 of file CodeGeneration.cpp.

References Function, POLLY_DEBUG, polly::IslAstInfo::print(), S, and Verify().

Referenced by generateCode().

◆ XPerfMonitoring()

cl::opt< bool, true > XPerfMonitoring ( "polly-codegen-perf-monitoring" ,
cl::desc("Add run-time performance monitoring") ,
cl::Hidden ,
cl::location(polly::PerfMonitoring) ,
cl::cat(PollyCategory)  )
static