[llvm-commits] [polly] r151916 - in /polly/trunk: lib/CodeGeneration.cpp test/CodeGen/simple_vec_assign_scalar_2.ll
Tobias Grosser
grosser at fim.uni-passau.de
Fri Mar 2 07:20:35 PST 2012
Author: grosser
Date: Fri Mar 2 09:20:35 2012
New Revision: 151916
URL: http://llvm.org/viewvc/llvm-project?rev=151916&view=rev
Log:
CodeGen: Pass the scalar maps properly
Modified:
polly/trunk/lib/CodeGeneration.cpp
polly/trunk/test/CodeGen/simple_vec_assign_scalar_2.ll
Modified: polly/trunk/lib/CodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGeneration.cpp?rev=151916&r1=151915&r2=151916&view=diff
==============================================================================
--- polly/trunk/lib/CodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGeneration.cpp Fri Mar 2 09:20:35 2012
@@ -234,7 +234,7 @@
protected:
IRBuilder<> &Builder;
- ValueMapT &VMap;
+ ValueMapT &GlobalMap;
Scop &S;
ScopStmt &Statement;
@@ -242,9 +242,11 @@
BlockGenerator(IRBuilder<> &B, ValueMapT &vmap, ScopStmt &Stmt, Pass *P);
- Value *getOperand(const Value *oldOperand, ValueMapT &BBMap);
+ Value *getOperand(const Value *OldOperand, ValueMapT &BBMap,
+ ValueMapT &GlobalMap);
- void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap);
+ void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap,
+ ValueMapT &GlobalMap);
/// @brief Get the memory access offset to be added to the base address
std::vector<Value*> getMemoryAccessIndex(__isl_keep isl_map *AccessRelation,
@@ -258,28 +260,32 @@
/// @brief Generate the operand address
Value *generateLocationAccessed(const Instruction *Inst,
- const Value *Pointer, ValueMapT &BBMap);
+ const Value *Pointer, ValueMapT &BBMap,
+ ValueMapT &GlobalMap);
- Value *generateScalarLoad(const LoadInst *load, ValueMapT &BBMap);
+ Value *generateScalarLoad(const LoadInst *load, ValueMapT &BBMap,
+ ValueMapT &GlobalMap);
- void copyInstruction(const Instruction *Inst, ValueMapT &ScalarMap);
+ void copyInstruction(const Instruction *Inst, ValueMapT &ScalarMap,
+ ValueMapT &GlobalMap);
void copyBB();
};
BlockGenerator::BlockGenerator(IRBuilder<> &B, ValueMapT &vmap, ScopStmt &Stmt,
Pass *P) :
- Builder(B), VMap(vmap), S(*Stmt.getParent()), Statement(Stmt), P(P) {}
+ Builder(B), GlobalMap(vmap), S(*Stmt.getParent()), Statement(Stmt), P(P) {}
-Value *BlockGenerator::getOperand(const Value *OldOperand, ValueMapT &BBMap) {
+Value *BlockGenerator::getOperand(const Value *OldOperand, ValueMapT &BBMap,
+ ValueMapT &GlobalMap) {
const Instruction *OpInst = dyn_cast<Instruction>(OldOperand);
if (!OpInst)
return const_cast<Value*>(OldOperand);
// OldOperand was redefined outside of this BasicBlock.
- if (VMap.count(OldOperand)) {
- Value *NewOperand = VMap[OldOperand];
+ if (GlobalMap.count(OldOperand)) {
+ Value *NewOperand = GlobalMap[OldOperand];
if (OldOperand->getType()->getScalarSizeInBits()
< NewOperand->getType()->getScalarSizeInBits())
@@ -302,14 +308,15 @@
return NULL;
}
-void BlockGenerator::copyInstScalar(const Instruction *Inst, ValueMapT &BBMap) {
+void BlockGenerator::copyInstScalar(const Instruction *Inst, ValueMapT &BBMap,
+ ValueMapT &GlobalMap) {
Instruction *NewInst = Inst->clone();
// Replace old operands with the new ones.
for (Instruction::const_op_iterator OI = Inst->op_begin(),
OE = Inst->op_end(); OI != OE; ++OI) {
Value *OldOperand = *OI;
- Value *NewOperand = getOperand(OldOperand, BBMap);
+ Value *NewOperand = getOperand(OldOperand, BBMap, GlobalMap);
if (!NewOperand) {
assert(!isa<StoreInst>(NewInst)
@@ -362,7 +369,8 @@
Value *BlockGenerator::generateLocationAccessed(const Instruction *Inst,
const Value *Pointer,
- ValueMapT &BBMap ) {
+ ValueMapT &BBMap,
+ ValueMapT &GlobalMap) {
MemoryAccess &Access = Statement.getAccessFor(Inst);
isl_map *CurrentAccessRelation = Access.getAccessRelation();
isl_map *NewAccessRelation = Access.getNewAccessRelation();
@@ -373,7 +381,7 @@
Value *NewPointer;
if (!NewAccessRelation) {
- NewPointer = getOperand(Pointer, BBMap);
+ NewPointer = getOperand(Pointer, BBMap, GlobalMap);
} else {
Value *BaseAddress = const_cast<Value*>(Access.getBaseAddr());
NewPointer = getNewAccessOperand(NewAccessRelation, BaseAddress, Pointer,
@@ -386,28 +394,29 @@
}
Value *BlockGenerator::generateScalarLoad(const LoadInst *Load,
- ValueMapT &BBMap) {
+ ValueMapT &BBMap,
+ ValueMapT &GlobalMap) {
const Value *Pointer = Load->getPointerOperand();
const Instruction *Inst = dyn_cast<Instruction>(Load);
- Value *NewPointer = generateLocationAccessed(Inst, Pointer, BBMap);
+ Value *NewPointer = generateLocationAccessed(Inst, Pointer, BBMap, GlobalMap);
Value *ScalarLoad = Builder.CreateLoad(NewPointer,
Load->getName() + "_p_scalar_");
return ScalarLoad;
}
void BlockGenerator::copyInstruction(const Instruction *Inst,
- ValueMapT &ScalarMap) {
+ ValueMapT &BBMap, ValueMapT &GlobalMap) {
// Terminator instructions control the control flow. They are explicitly
// expressed in the clast and do not need to be copied.
if (Inst->isTerminator())
return;
if (const LoadInst *Load = dyn_cast<LoadInst>(Inst)) {
- ScalarMap[Load] = generateScalarLoad(Load, ScalarMap);
+ BBMap[Load] = generateScalarLoad(Load, BBMap, GlobalMap);
return;
}
- copyInstScalar(Inst, ScalarMap);
+ copyInstScalar(Inst, BBMap, GlobalMap);
}
@@ -418,11 +427,11 @@
CopyBB->setName("polly.stmt." + BB->getName());
Builder.SetInsertPoint(CopyBB->begin());
- ValueMapT ScalarBlockMap;
+ ValueMapT BBMap;
for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end(); II != IE;
++II)
- copyInstruction(II, ScalarBlockMap);
+ copyInstruction(II, BBMap, GlobalMap);
}
class VectorBlockGenerator : BlockGenerator {
@@ -435,7 +444,7 @@
}
private:
- VectorValueMapT &ValueMaps;
+ VectorValueMapT &GlobalMaps;
isl_set *Domain;
@@ -444,10 +453,8 @@
int getVectorWidth();
- Value *makeVectorOperand(Value *Operand);
-
- Value *getOperand(const Value *oldOperand, ValueMapT &BBMap,
- ValueMapT *VectorMap = 0);
+ Value *getVectorOperand(const Value *OldOperand, ValueMapT &VectorMap,
+ VectorValueMapT &ScalarMaps);
Type *getVectorPtrTy(const Value *V, int Width);
@@ -490,13 +497,13 @@
void generateLoad(const LoadInst *Load, ValueMapT &VectorMap,
VectorValueMapT &ScalarMaps);
- void copyUnaryInst(const UnaryInstruction *Inst, ValueMapT &BBMap,
- ValueMapT &VectorMap);
+ void copyUnaryInst(const UnaryInstruction *Inst, ValueMapT &VectorMap,
+ VectorValueMapT &ScalarMaps);
- void copyBinaryInst(const BinaryOperator *Inst, ValueMapT &BBMap,
- ValueMapT &VectorMap);
+ void copyBinaryInst(const BinaryOperator *Inst, ValueMapT &VectorMap,
+ VectorValueMapT &ScalarMaps);
- void copyStore(const StoreInst *Store, ValueMapT &BBMap, ValueMapT &VectorMap,
+ void copyStore(const StoreInst *Store, ValueMapT &VectorMap,
VectorValueMapT &ScalarMaps);
bool hasVectorOperands(const Instruction *Inst, ValueMapT &VectorMap);
@@ -511,35 +518,32 @@
VectorBlockGenerator::VectorBlockGenerator(IRBuilder<> &B, ValueMapT &vmap,
VectorValueMapT &vmaps, ScopStmt &Stmt,
__isl_keep isl_set *Domain, Pass *P)
- : BlockGenerator(B, vmap, Stmt, P), ValueMaps(vmaps), Domain(Domain) {
- assert(ValueMaps.size() > 1 && "Only one vector lane found");
+ : BlockGenerator(B, vmap, Stmt, P), GlobalMaps(vmaps), Domain(Domain) {
+ assert(GlobalMaps.size() > 1 && "Only one vector lane found");
assert(Domain && "No statement domain provided");
}
-Value *VectorBlockGenerator::makeVectorOperand(Value *Operand) {
- int VectorWidth = getVectorWidth();
- if (Operand->getType()->isVectorTy())
- return Operand;
-
- Value *Vector = UndefValue::get(VectorType::get(Operand->getType(), 1));
- Vector = Builder.CreateInsertElement(Vector, Operand, Builder.getInt32(0));
- Constant *SplatVector = ConstantVector::getSplat(VectorWidth,
- Builder.getInt32(0));
- return Builder.CreateShuffleVector(Vector, Vector, SplatVector);
-}
-
-Value *VectorBlockGenerator::getOperand(const Value *OldOperand,
- ValueMapT &BBMap,
- ValueMapT *VectorMap) {
- const Instruction *OpInst = dyn_cast<Instruction>(OldOperand);
- if (!OpInst)
- return const_cast<Value*>(OldOperand);
+Value *VectorBlockGenerator::getVectorOperand(const Value *Operand,
+ ValueMapT &VectorMap,
+ VectorValueMapT &ScalarMaps) {
+ if (VectorMap.count(Operand))
+ return VectorMap[Operand];
+
+ int Width = getVectorWidth();
+
+ Value *Vector = UndefValue::get(VectorType::get(Operand->getType(), Width));
+
+ for (int Lane = 0; Lane < Width; Lane++)
+ Vector = Builder.CreateInsertElement(Vector,
+ getOperand(Operand,
+ ScalarMaps[Lane],
+ GlobalMaps[Lane]),
+ Builder.getInt32(Lane));
- if (VectorMap && VectorMap->count(OldOperand))
- return (*VectorMap)[OldOperand];
+ VectorMap[Operand] = Vector;
- return BlockGenerator::getOperand(OldOperand, BBMap);
+ return Vector;
}
Type *VectorBlockGenerator::getVectorPtrTy(const Value *Val, int Width) {
@@ -556,7 +560,7 @@
ValueMapT &BBMap) {
const Value *Pointer = Load->getPointerOperand();
Type *VectorPtrType = getVectorPtrTy(Pointer, getVectorWidth());
- Value *NewPointer = getOperand(Pointer, BBMap);
+ Value *NewPointer = getOperand(Pointer, BBMap, GlobalMaps[0]);
Value *VectorPtr = Builder.CreateBitCast(NewPointer, VectorPtrType,
"vector_ptr");
LoadInst *VecLoad = Builder.CreateLoad(VectorPtr,
@@ -571,7 +575,7 @@
ValueMapT &BBMap) {
const Value *Pointer = Load->getPointerOperand();
Type *VectorPtrType = getVectorPtrTy(Pointer, 1);
- Value *NewPointer = getOperand(Pointer, BBMap);
+ Value *NewPointer = getOperand(Pointer, BBMap, GlobalMaps[0]);
Value *VectorPtr = Builder.CreateBitCast(NewPointer, VectorPtrType,
Load->getName() + "_p_vec_p");
LoadInst *ScalarLoad= Builder.CreateLoad(VectorPtr,
@@ -601,7 +605,7 @@
Value *Vector = UndefValue::get(VectorType);
for (int i = 0; i < VectorWidth; i++) {
- Value *NewPointer = getOperand(Pointer, ScalarMaps[i]);
+ Value *NewPointer = getOperand(Pointer, ScalarMaps[i], GlobalMaps[i]);
Value *ScalarLoad = Builder.CreateLoad(NewPointer,
Load->getName() + "_p_scalar_");
Vector = Builder.CreateInsertElement(Vector, ScalarLoad,
@@ -630,11 +634,11 @@
}
void VectorBlockGenerator::copyUnaryInst(const UnaryInstruction *Inst,
- ValueMapT &BBMap,
- ValueMapT &VectorMap) {
+ ValueMapT &VectorMap,
+ VectorValueMapT &ScalarMaps) {
int VectorWidth = getVectorWidth();
- Value *NewOperand = getOperand(Inst->getOperand(0), BBMap, &VectorMap);
- NewOperand = makeVectorOperand(NewOperand);
+ Value *NewOperand = getVectorOperand(Inst->getOperand(0), VectorMap,
+ ScalarMaps);
assert(isa<CastInst>(Inst) && "Can not generate vector code for instruction");
@@ -644,17 +648,14 @@
}
void VectorBlockGenerator::copyBinaryInst(const BinaryOperator *Inst,
- ValueMapT &BBMap,
- ValueMapT &VectorMap) {
+ ValueMapT &VectorMap,
+ VectorValueMapT &ScalarMaps) {
Value *OpZero = Inst->getOperand(0);
Value *OpOne = Inst->getOperand(1);
Value *NewOpZero, *NewOpOne;
- NewOpZero = getOperand(OpZero, BBMap, &VectorMap);
- NewOpOne = getOperand(OpOne, BBMap, &VectorMap);
-
- NewOpZero = makeVectorOperand(NewOpZero);
- NewOpOne = makeVectorOperand(NewOpOne);
+ NewOpZero = getVectorOperand(OpZero, VectorMap, ScalarMaps);
+ NewOpOne = getVectorOperand(OpOne, VectorMap, ScalarMaps);
Value *NewInst = Builder.CreateBinOp(Inst->getOpcode(), NewOpZero,
NewOpOne,
@@ -662,7 +663,7 @@
VectorMap[Inst] = NewInst;
}
-void VectorBlockGenerator::copyStore(const StoreInst *Store, ValueMapT &BBMap,
+void VectorBlockGenerator::copyStore(const StoreInst *Store,
ValueMapT &VectorMap,
VectorValueMapT &ScalarMaps) {
int VectorWidth = getVectorWidth();
@@ -670,11 +671,12 @@
MemoryAccess &Access = Statement.getAccessFor(Store);
const Value *Pointer = Store->getPointerOperand();
- Value *Vector = getOperand(Store->getValueOperand(), BBMap, &VectorMap);
+ Value *Vector = getVectorOperand(Store->getValueOperand(), VectorMap,
+ ScalarMaps);
if (Access.isStrideOne(isl_set_copy(Domain))) {
Type *VectorPtrType = getVectorPtrTy(Pointer, VectorWidth);
- Value *NewPointer = getOperand(Pointer, BBMap, &VectorMap);
+ Value *NewPointer = getOperand(Pointer, ScalarMaps[0], GlobalMaps[0]);
Value *VectorPtr = Builder.CreateBitCast(NewPointer, VectorPtrType,
"vector_ptr");
@@ -686,7 +688,7 @@
for (unsigned i = 0; i < ScalarMaps.size(); i++) {
Value *Scalar = Builder.CreateExtractElement(Vector,
Builder.getInt32(i));
- Value *NewPointer = getOperand(Pointer, ScalarMaps[i]);
+ Value *NewPointer = getOperand(Pointer, ScalarMaps[i], GlobalMaps[i]);
Builder.CreateStore(Scalar, NewPointer);
}
}
@@ -702,7 +704,7 @@
}
int VectorBlockGenerator::getVectorWidth() {
- return ValueMaps.size();
+ return GlobalMaps.size();
}
void VectorBlockGenerator::copyInstruction(const Instruction *Inst,
@@ -720,17 +722,17 @@
if (hasVectorOperands(Inst, VectorMap)) {
if (const StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
- copyStore(Store, ScalarMaps[0], VectorMap, ScalarMaps);
+ copyStore(Store, VectorMap, ScalarMaps);
return;
}
if (const UnaryInstruction *Unary = dyn_cast<UnaryInstruction>(Inst)) {
- copyUnaryInst(Unary, ScalarMaps[0], VectorMap);
+ copyUnaryInst(Unary, VectorMap, ScalarMaps);
return;
}
if (const BinaryOperator *Binary = dyn_cast<BinaryOperator>(Inst)) {
- copyBinaryInst(Binary, ScalarMaps[0], VectorMap);
+ copyBinaryInst(Binary, VectorMap, ScalarMaps);
return;
}
@@ -738,7 +740,7 @@
}
for (int VectorLane = 0; VectorLane < getVectorWidth(); VectorLane++)
- copyInstScalar(Inst, ScalarMaps[VectorLane]);
+ copyInstScalar(Inst, ScalarMaps[VectorLane], GlobalMaps[VectorLane]);
}
void VectorBlockGenerator::copyBB() {
Modified: polly/trunk/test/CodeGen/simple_vec_assign_scalar_2.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/CodeGen/simple_vec_assign_scalar_2.ll?rev=151916&r1=151915&r2=151916&view=diff
==============================================================================
--- polly/trunk/test/CodeGen/simple_vec_assign_scalar_2.ll (original)
+++ polly/trunk/test/CodeGen/simple_vec_assign_scalar_2.ll Fri Mar 2 09:20:35 2012
@@ -41,7 +41,9 @@
ret i32 %tmp1
}
-; CHECK: insertelement <1 x float> undef, float %p_tmp4, i32 0
-; CHECK: shufflevector <1 x float> %0, <1 x float> %0, <4 x i32> zeroinitializer
-; CHECK: fadd <4 x float> %tmp_p_vec_full, %1
+; CHECK: insertelement <4 x float> undef, float %p_tmp4, i32 0
+; CHECK: insertelement <4 x float> %0, float %p_tmp410, i32 1
+; CHECK: insertelement <4 x float> %1, float %p_tmp411, i32 2
+; CHECK: insertelement <4 x float> %2, float %p_tmp412, i32 3
+; CHECK: fadd <4 x float> %tmp_p_vec_full, %3
More information about the llvm-commits
mailing list