[polly] r246364 - Remove some code duplication when creating Allocas [NFC]
Tobias Grosser via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 29 11:12:03 PDT 2015
Author: grosser
Date: Sat Aug 29 13:12:03 2015
New Revision: 246364
URL: http://llvm.org/viewvc/llvm-project?rev=246364&view=rev
Log:
Remove some code duplication when creating Allocas [NFC]
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=246364&r1=246363&r2=246364&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Sat Aug 29 13:12:03 2015
@@ -133,6 +133,15 @@ public:
/// @returns The alloca for @p ScalarBase
AllocaInst *getOrCreatePHIAlloca(Value *ScalarBase);
+ /// @brief Return the alloca for @p Access
+ ///
+ /// If no alloca was mapped for @p Access a new one is created.
+ ///
+ /// @param Access The memory access for which to generate the alloca
+ ///
+ /// @returns The alloca for @p Access
+ AllocaInst *getOrCreateAlloca(MemoryAccess &Access);
+
/// @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=246364&r1=246363&r2=246364&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Sat Aug 29 13:12:03 2015
@@ -362,6 +362,13 @@ AllocaInst *BlockGenerator::getOrCreateA
return Addr;
}
+AllocaInst *BlockGenerator::getOrCreateAlloca(MemoryAccess &Access) {
+ if (Access.getScopArrayInfo()->isPHI())
+ return getOrCreatePHIAlloca(Access.getBaseAddr());
+ else
+ return getOrCreateScalarAlloca(Access.getBaseAddr());
+}
+
AllocaInst *BlockGenerator::getOrCreateScalarAlloca(Value *ScalarBase) {
return getOrCreateAlloca(ScalarBase, ScalarMap, ".s2a");
}
@@ -427,14 +434,9 @@ void BlockGenerator::generateScalarLoads
if (!MA.isScalar() || !MA.isRead())
continue;
- auto Base = MA.getBaseAddr();
-
- if (MA.getScopArrayInfo()->isPHI())
- Address = getOrCreatePHIAlloca(Base);
- else
- Address = getOrCreateScalarAlloca(Base);
-
- BBMap[Base] = Builder.CreateLoad(Address, Address->getName() + ".reload");
+ Address = getOrCreateAlloca(MA);
+ BBMap[MA.getBaseAddr()] =
+ Builder.CreateLoad(Address, Address->getName() + ".reload");
}
}
@@ -490,14 +492,8 @@ void BlockGenerator::generateScalarStore
if (!MA->isScalar() || MA->isRead())
continue;
- Instruction *Base = cast<Instruction>(MA->getBaseAddr());
Value *Val = MA->getAccessValue();
-
- AllocaInst *Address = nullptr;
- if (MA->getScopArrayInfo()->isPHI())
- Address = getOrCreatePHIAlloca(Base);
- else
- Address = getOrCreateScalarAlloca(Base);
+ auto *Address = getOrCreateAlloca(*MA);
Val = getNewScalarValue(Val, R, ScalarMap, BBMap, GlobalMap);
Builder.CreateStore(Val, Address);
@@ -1119,7 +1115,6 @@ void RegionGenerator::generateScalarStor
if (!MA->isScalar() || MA->isRead())
continue;
- Instruction *ScalarBase = cast<Instruction>(MA->getBaseAddr());
Instruction *ScalarInst = MA->getAccessInstruction();
// Only generate accesses that belong to this basic block.
@@ -1127,15 +1122,11 @@ void RegionGenerator::generateScalarStor
continue;
Value *Val = MA->getAccessValue();
- AllocaInst *ScalarAddr = nullptr;
- if (MA->getScopArrayInfo()->isPHI())
- ScalarAddr = getOrCreatePHIAlloca(ScalarBase);
- else
- ScalarAddr = getOrCreateScalarAlloca(ScalarBase);
+ auto Address = getOrCreateAlloca(*MA);
Val = getNewScalarValue(Val, R, ScalarMap, BBMap, GlobalMap);
- Builder.CreateStore(Val, ScalarAddr);
+ Builder.CreateStore(Val, Address);
}
}
More information about the llvm-commits
mailing list