From: Tobias Grosser Date: Mon, 27 Jul 2015 17:57:58 +0000 (+0000) Subject: Simplify code in BlockGenerator::generateScalarLoads [NFC] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4dd6ec74d0480f2a7c0e47051ded5ce91b9ebb0;p=platform%2Fupstream%2Fllvm.git 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. llvm-svn: 243291 --- diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index efe8281..b39059d 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -428,37 +428,26 @@ void BlockGenerator::handleOutsideUsers(const Region &R, Instruction *Inst, 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; + if (!MAL) + return; - Instruction *ScalarBase = cast(MA.getBaseAddr()); - Instruction *ScalarInst = MA.getAccessInstruction(); + for (MemoryAccess &MA : *MAL) { + AllocaInst *Address; + if (!MA.isScalar() || !MA.isRead()) + continue; - PHINode *ScalarBasePHI = dyn_cast(ScalarBase); + auto Base = cast(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 (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; - } - } + // This is either a common scalar use (second case) or the use of a phi + // operand by the PHI node (first case). + if (isa(Base) && Base == MA.getAccessInstruction()) + Address = getOrCreateAlloca(Base, PHIOpMap, ".phiops"); + else + Address = getOrCreateAlloca(Base, ScalarMap, ".s2a"); + + BBMap[Base] = Builder.CreateLoad(Address, Address->getName() + ".reload"); } }