[polly] r244874 - Enable code generation of scalar dependences from function arguments

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 01:07:39 PDT 2015


Author: grosser
Date: Thu Aug 13 03:07:39 2015
New Revision: 244874

URL: http://llvm.org/viewvc/llvm-project?rev=244874&view=rev
Log:
Enable code generation of scalar dependences from function arguments

This change extends the BlockGenerator to not only allow Instructions as
base elements of scalar dependences, but any llvm::Value. This allows
us to code-generate scalar dependences which reference function arguments, as
they arise when moddeling read-only scalar dependences.

Added:
    polly/trunk/test/Isl/CodeGen/read-only-scalars.ll
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=244874&r1=244873&r2=244874&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Thu Aug 13 03:07:39 2015
@@ -67,7 +67,7 @@ public:
   ///@{
 
   /// @see The ScalarMap and PHIOpMap member.
-  using ScalarAllocaMapTy = DenseMap<Instruction *, AllocaInst *>;
+  using ScalarAllocaMapTy = DenseMap<Value *, AllocaInst *>;
 
   /// @brief Simple vector of instructions to store escape users.
   using EscapeUserVectorTy = SmallVector<Instruction *, 4>;
@@ -302,13 +302,13 @@ protected:
   /// If no alloca was mapped to @p ScalarBase in @p Map a new one is created
   /// and named after @p ScalarBase with the suffix @p NameExt.
   ///
-  /// @param ScalarBase The demoted scalar instruction.
-  /// @param Map        The map we should look for a mapped alloca instruction.
+  /// @param ScalarBase The demoted scalar value.
+  /// @param Map        The map we should look for a mapped alloca value.
   /// @param NameExt    The suffix we add to the name of a new created alloca.
   /// @param IsNew      If set it will hold true iff the alloca was created.
   ///
   /// @returns The alloca for @p ScalarBase in @p Map.
-  AllocaInst *getOrCreateAlloca(Instruction *ScalarBase, ScalarAllocaMapTy &Map,
+  AllocaInst *getOrCreateAlloca(Value *ScalarBase, ScalarAllocaMapTy &Map,
                                 const char *NameExt = ".s2a",
                                 bool *IsNew = nullptr);
 

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=244874&r1=244873&r2=244874&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Thu Aug 13 03:07:39 2015
@@ -352,7 +352,7 @@ void BlockGenerator::copyBB(ScopStmt &St
     handleOutsideUsers(R, &Inst, BBMap[&Inst]);
 }
 
-AllocaInst *BlockGenerator::getOrCreateAlloca(Instruction *ScalarBase,
+AllocaInst *BlockGenerator::getOrCreateAlloca(Value *ScalarBase,
                                               ScalarAllocaMapTy &Map,
                                               const char *NameExt,
                                               bool *IsNew) {
@@ -433,7 +433,7 @@ void BlockGenerator::generateScalarLoads
     if (!MA.isScalar() || !MA.isRead())
       continue;
 
-    auto Base = cast<Instruction>(MA.getBaseAddr());
+    auto Base = MA.getBaseAddr();
 
     if (MA.getScopArrayInfo()->isPHI())
       Address = getOrCreateAlloca(Base, PHIOpMap, ".phiops");

Added: polly/trunk/test/Isl/CodeGen/read-only-scalars.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/read-only-scalars.ll?rev=244874&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/read-only-scalars.ll (added)
+++ polly/trunk/test/Isl/CodeGen/read-only-scalars.ll Thu Aug 13 03:07:39 2015
@@ -0,0 +1,33 @@
+; RUN: opt %loadPolly -polly-analyze-read-only-scalars=false -polly-codegen -polly-no-early-exit -S < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-analyze-read-only-scalars=true -polly-codegen -polly-no-early-exit -S < %s | FileCheck %s -check-prefix=SCALAR
+
+; CHECK-NOT: alloca
+
+; SCALAR-LABEL: entry:
+; SCALAR-NEXT: %scalar.s2a = alloca float
+
+; SCALAR:  %scalar.s2a.reload = load float, float* %scalar.s2a
+; SCALAR-NEXT:  %p_sum = fadd float %val_p_scalar_, %scalar.s2a.reload
+
+define void @foo(float* noalias %A, float %scalar) {
+entry:
+  br label %loop
+
+loop:
+  %indvar = phi i64 [0, %entry], [%indvar.next, %loop.backedge]
+  br label %stmt1
+
+stmt1:
+  %val = load float, float* %A
+  %sum = fadd float %val, %scalar
+  store float %sum, float* %A
+  br label %loop.backedge
+
+loop.backedge:
+  %indvar.next = add i64 %indvar, 1
+  %cond = icmp sle i64 %indvar, 100
+  br i1 %cond, label %loop, label %exit
+
+exit:
+  ret void
+}




More information about the llvm-commits mailing list