From 0164b8ff70e814cd60621b0fcfbc5b86637efbb3 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Thu, 13 Aug 2015 08:07:39 +0000 Subject: [PATCH] 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. llvm-svn: 244874 --- polly/include/polly/CodeGen/BlockGenerators.h | 8 +++---- polly/lib/CodeGen/BlockGenerators.cpp | 4 ++-- polly/test/Isl/CodeGen/read-only-scalars.ll | 33 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 polly/test/Isl/CodeGen/read-only-scalars.ll diff --git a/polly/include/polly/CodeGen/BlockGenerators.h b/polly/include/polly/CodeGen/BlockGenerators.h index 8c18f0c..b787234 100644 --- a/polly/include/polly/CodeGen/BlockGenerators.h +++ b/polly/include/polly/CodeGen/BlockGenerators.h @@ -67,7 +67,7 @@ public: ///@{ /// @see The ScalarMap and PHIOpMap member. - using ScalarAllocaMapTy = DenseMap; + using ScalarAllocaMapTy = DenseMap; /// @brief Simple vector of instructions to store escape users. using EscapeUserVectorTy = SmallVector; @@ -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); diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 8e8e40c..fb46b09 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -352,7 +352,7 @@ void BlockGenerator::copyBB(ScopStmt &Stmt, BasicBlock *BB, BasicBlock *CopyBB, 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(ScopStmt &Stmt, if (!MA.isScalar() || !MA.isRead()) continue; - auto Base = cast(MA.getBaseAddr()); + auto Base = MA.getBaseAddr(); if (MA.getScopArrayInfo()->isPHI()) Address = getOrCreateAlloca(Base, PHIOpMap, ".phiops"); diff --git a/polly/test/Isl/CodeGen/read-only-scalars.ll b/polly/test/Isl/CodeGen/read-only-scalars.ll new file mode 100644 index 0000000..f42d07e --- /dev/null +++ b/polly/test/Isl/CodeGen/read-only-scalars.ll @@ -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 +} -- 2.7.4