[polly] r243291 - Simplify code in BlockGenerator::generateScalarLoads [NFC]
Tobias Grosser
tobias at grosser.es
Mon Jul 27 10:57:58 PDT 2015
Author: grosser
Date: Mon Jul 27 12:57:58 2015
New Revision: 243291
URL: http://llvm.org/viewvc/llvm-project?rev=243291&view=rev
Log:
Simplify code in BlockGenerator::generateScalarLoads [NFC]
We hoist statements that are used on both branches of an if-condition, shorten
and unify some variable names and fold some variable declarations into their
only uses. We also drop a comment which just describes the elements the loop
iterates over.
No functional change intended.
Modified:
polly/trunk/lib/CodeGen/BlockGenerators.cpp
Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=243291&r1=243290&r2=243291&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Mon Jul 27 12:57:58 2015
@@ -428,37 +428,26 @@ void BlockGenerator::handleOutsideUsers(
void BlockGenerator::generateScalarLoads(ScopStmt &Stmt,
const Instruction *Inst,
ValueMapT &BBMap) {
+ auto *MAL = Stmt.lookupAccessesFor(Inst);
- // Iterate over all memory accesses for the given instruction and handle all
- // scalar reads.
- if (ScopStmt::MemoryAccessList *MAL = Stmt.lookupAccessesFor(Inst)) {
- for (MemoryAccess &MA : *MAL) {
- if (!MA.isScalar() || !MA.isRead())
- continue;
-
- Instruction *ScalarBase = cast<Instruction>(MA.getBaseAddr());
- Instruction *ScalarInst = MA.getAccessInstruction();
-
- PHINode *ScalarBasePHI = dyn_cast<PHINode>(ScalarBase);
-
- // This is either a common scalar use (second case) or the use of a phi
- // operand by the PHI node (first case).
- if (ScalarBasePHI == ScalarInst) {
- AllocaInst *PHIOpAddr =
- getOrCreateAlloca(ScalarBase, PHIOpMap, ".phiops");
- LoadInst *LI =
- Builder.CreateLoad(PHIOpAddr, PHIOpAddr->getName() + ".reload");
- BBMap[ScalarBase] = LI;
- } else {
- // For non-PHI operand uses we look up the alloca in the ScalarMap,
- // reload it and add the mapping to the ones in the current basic block.
- AllocaInst *ScalarAddr =
- getOrCreateAlloca(ScalarBase, ScalarMap, ".s2a");
- LoadInst *LI =
- Builder.CreateLoad(ScalarAddr, ScalarAddr->getName() + ".reload");
- BBMap[ScalarBase] = LI;
- }
- }
+ if (!MAL)
+ return;
+
+ for (MemoryAccess &MA : *MAL) {
+ AllocaInst *Address;
+ if (!MA.isScalar() || !MA.isRead())
+ continue;
+
+ auto Base = cast<Instruction>(MA.getBaseAddr());
+
+ // This is either a common scalar use (second case) or the use of a phi
+ // operand by the PHI node (first case).
+ if (isa<PHINode>(Base) && Base == MA.getAccessInstruction())
+ Address = getOrCreateAlloca(Base, PHIOpMap, ".phiops");
+ else
+ Address = getOrCreateAlloca(Base, ScalarMap, ".s2a");
+
+ BBMap[Base] = Builder.CreateLoad(Address, Address->getName() + ".reload");
}
}
More information about the llvm-commits
mailing list