forked from OSchip/llvm-project
Remove some code duplication when creating Allocas [NFC]
llvm-svn: 246364
This commit is contained in:
parent
e7708a84b9
commit
f8d55f7e4e
|
@ -133,6 +133,15 @@ public:
|
||||||
/// @returns The alloca for @p ScalarBase
|
/// @returns The alloca for @p ScalarBase
|
||||||
AllocaInst *getOrCreatePHIAlloca(Value *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.
|
/// @brief Finalize the code generation for the SCoP @p S.
|
||||||
///
|
///
|
||||||
/// This will initialize and finalize the scalar variables we demoted during
|
/// This will initialize and finalize the scalar variables we demoted during
|
||||||
|
|
|
@ -362,6 +362,13 @@ AllocaInst *BlockGenerator::getOrCreateAlloca(Value *ScalarBase,
|
||||||
return Addr;
|
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) {
|
AllocaInst *BlockGenerator::getOrCreateScalarAlloca(Value *ScalarBase) {
|
||||||
return getOrCreateAlloca(ScalarBase, ScalarMap, ".s2a");
|
return getOrCreateAlloca(ScalarBase, ScalarMap, ".s2a");
|
||||||
}
|
}
|
||||||
|
@ -427,14 +434,9 @@ void BlockGenerator::generateScalarLoads(ScopStmt &Stmt,
|
||||||
if (!MA.isScalar() || !MA.isRead())
|
if (!MA.isScalar() || !MA.isRead())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto Base = MA.getBaseAddr();
|
Address = getOrCreateAlloca(MA);
|
||||||
|
BBMap[MA.getBaseAddr()] =
|
||||||
if (MA.getScopArrayInfo()->isPHI())
|
Builder.CreateLoad(Address, Address->getName() + ".reload");
|
||||||
Address = getOrCreatePHIAlloca(Base);
|
|
||||||
else
|
|
||||||
Address = getOrCreateScalarAlloca(Base);
|
|
||||||
|
|
||||||
BBMap[Base] = Builder.CreateLoad(Address, Address->getName() + ".reload");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,14 +492,8 @@ void BlockGenerator::generateScalarStores(ScopStmt &Stmt, BasicBlock *BB,
|
||||||
if (!MA->isScalar() || MA->isRead())
|
if (!MA->isScalar() || MA->isRead())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Instruction *Base = cast<Instruction>(MA->getBaseAddr());
|
|
||||||
Value *Val = MA->getAccessValue();
|
Value *Val = MA->getAccessValue();
|
||||||
|
auto *Address = getOrCreateAlloca(*MA);
|
||||||
AllocaInst *Address = nullptr;
|
|
||||||
if (MA->getScopArrayInfo()->isPHI())
|
|
||||||
Address = getOrCreatePHIAlloca(Base);
|
|
||||||
else
|
|
||||||
Address = getOrCreateScalarAlloca(Base);
|
|
||||||
|
|
||||||
Val = getNewScalarValue(Val, R, ScalarMap, BBMap, GlobalMap);
|
Val = getNewScalarValue(Val, R, ScalarMap, BBMap, GlobalMap);
|
||||||
Builder.CreateStore(Val, Address);
|
Builder.CreateStore(Val, Address);
|
||||||
|
@ -1119,7 +1115,6 @@ void RegionGenerator::generateScalarStores(ScopStmt &Stmt, BasicBlock *BB,
|
||||||
if (!MA->isScalar() || MA->isRead())
|
if (!MA->isScalar() || MA->isRead())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Instruction *ScalarBase = cast<Instruction>(MA->getBaseAddr());
|
|
||||||
Instruction *ScalarInst = MA->getAccessInstruction();
|
Instruction *ScalarInst = MA->getAccessInstruction();
|
||||||
|
|
||||||
// Only generate accesses that belong to this basic block.
|
// Only generate accesses that belong to this basic block.
|
||||||
|
@ -1127,15 +1122,11 @@ void RegionGenerator::generateScalarStores(ScopStmt &Stmt, BasicBlock *BB,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Value *Val = MA->getAccessValue();
|
Value *Val = MA->getAccessValue();
|
||||||
AllocaInst *ScalarAddr = nullptr;
|
|
||||||
|
|
||||||
if (MA->getScopArrayInfo()->isPHI())
|
auto Address = getOrCreateAlloca(*MA);
|
||||||
ScalarAddr = getOrCreatePHIAlloca(ScalarBase);
|
|
||||||
else
|
|
||||||
ScalarAddr = getOrCreateScalarAlloca(ScalarBase);
|
|
||||||
|
|
||||||
Val = getNewScalarValue(Val, R, ScalarMap, BBMap, GlobalMap);
|
Val = getNewScalarValue(Val, R, ScalarMap, BBMap, GlobalMap);
|
||||||
Builder.CreateStore(Val, ScalarAddr);
|
Builder.CreateStore(Val, Address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue