[polly] r246285 - BlockGenerator: Make scalar memory locations accessible

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 01:23:36 PDT 2015


Author: grosser
Date: Fri Aug 28 03:23:35 2015
New Revision: 246285

URL: http://llvm.org/viewvc/llvm-project?rev=246285&view=rev
Log:
BlockGenerator: Make scalar memory locations accessible

For external users, the memory locations into which we generate scalar values
may be of interest. This change introduces two functions that allow to obtain
(or create) the AllocInsts for a given BasePointer.

We use this change to simplify the code in BlockGenerators.

Modified:
    polly/trunk/include/polly/CodeGen/BlockGenerators.h
    polly/trunk/lib/CodeGen/BlockGenerators.cpp

Modified: polly/trunk/include/polly/CodeGen/BlockGenerators.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/BlockGenerators.h?rev=246285&r1=246284&r2=246285&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Fri Aug 28 03:23:35 2015
@@ -115,6 +115,24 @@ public:
   void copyStmt(ScopStmt &Stmt, ValueMapT &GlobalMap, LoopToScevMapT &LTS,
                 isl_id_to_ast_expr *NewAccesses);
 
+  /// @brief Return the scalar alloca for @p ScalarBase
+  ///
+  /// If no alloca was mapped to @p ScalarBase a new one is created.
+  ///
+  /// @param ScalarBase The demoted scalar value.
+  ///
+  /// @returns The alloca for @p ScalarBase
+  AllocaInst *getOrCreateScalarAlloca(Value *ScalarBase);
+
+  /// @brief Return the PHi-node alloca for @p ScalarBase
+  ///
+  /// If no alloca was mapped to @p ScalarBase a new one is created.
+  ///
+  /// @param ScalarBase The demoted scalar value.
+  ///
+  /// @returns The alloca for @p ScalarBase
+  AllocaInst *getOrCreatePHIAlloca(Value *ScalarBase);
+
   /// @brief Finalize the code generation for the SCoP @p S.
   ///
   /// This will initialize and finalize the scalar variables we demoted during

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=246285&r1=246284&r2=246285&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Fri Aug 28 03:23:35 2015
@@ -362,6 +362,14 @@ AllocaInst *BlockGenerator::getOrCreateA
   return Addr;
 }
 
+AllocaInst *BlockGenerator::getOrCreateScalarAlloca(Value *ScalarBase) {
+  return getOrCreateAlloca(ScalarBase, ScalarMap, ".s2a");
+}
+
+AllocaInst *BlockGenerator::getOrCreatePHIAlloca(Value *ScalarBase) {
+  return getOrCreateAlloca(ScalarBase, PHIOpMap, ".phiops");
+}
+
 void BlockGenerator::handleOutsideUsers(const Region &R, Instruction *Inst,
                                         Value *InstCopy) {
   // If there are escape users we get the alloca for this instruction and put
@@ -422,9 +430,9 @@ void BlockGenerator::generateScalarLoads
     auto Base = MA.getBaseAddr();
 
     if (MA.getScopArrayInfo()->isPHI())
-      Address = getOrCreateAlloca(Base, PHIOpMap, ".phiops");
+      Address = getOrCreatePHIAlloca(Base);
     else
-      Address = getOrCreateAlloca(Base, ScalarMap, ".s2a");
+      Address = getOrCreateScalarAlloca(Base);
 
     BBMap[Base] = Builder.CreateLoad(Address, Address->getName() + ".reload");
   }
@@ -487,9 +495,9 @@ void BlockGenerator::generateScalarStore
 
     AllocaInst *Address = nullptr;
     if (MA->getScopArrayInfo()->isPHI())
-      Address = getOrCreateAlloca(Base, PHIOpMap, ".phiops");
+      Address = getOrCreatePHIAlloca(Base);
     else
-      Address = getOrCreateAlloca(Base, ScalarMap, ".s2a");
+      Address = getOrCreateScalarAlloca(Base);
 
     Val = getNewScalarValue(Val, R, ScalarMap, BBMap, GlobalMap);
     Builder.CreateStore(Val, Address);
@@ -1122,9 +1130,9 @@ void RegionGenerator::generateScalarStor
     AllocaInst *ScalarAddr = nullptr;
 
     if (MA->getScopArrayInfo()->isPHI())
-      ScalarAddr = getOrCreateAlloca(ScalarBase, PHIOpMap, ".phiops");
+      ScalarAddr = getOrCreatePHIAlloca(ScalarBase);
     else
-      ScalarAddr = getOrCreateAlloca(ScalarBase, ScalarMap, ".s2a");
+      ScalarAddr = getOrCreateScalarAlloca(ScalarBase);
 
     Val = getNewScalarValue(Val, R, ScalarMap, BBMap, GlobalMap);
     Builder.CreateStore(Val, ScalarAddr);
@@ -1161,8 +1169,7 @@ void RegionGenerator::addOperandToPHI(Sc
     if (PHICopy->getBasicBlockIndex(BBCopy) >= 0)
       return;
 
-    AllocaInst *PHIOpAddr =
-        getOrCreateAlloca(const_cast<PHINode *>(PHI), PHIOpMap, ".phiops");
+    AllocaInst *PHIOpAddr = getOrCreatePHIAlloca(const_cast<PHINode *>(PHI));
     OpCopy = new LoadInst(PHIOpAddr, PHIOpAddr->getName() + ".reload",
                           BlockMap[IncomingBB]->getTerminator());
   }




More information about the llvm-commits mailing list