[llvm-commits] [polly] r139095 - in /polly/trunk: lib/CodeGeneration.cpp test/CodeGen/simple_vec_stride_x.ll
Tobias Grosser
grosser at fim.uni-passau.de
Sun Sep 4 04:45:41 PDT 2011
Author: grosser
Date: Sun Sep 4 06:45:41 2011
New Revision: 139095
URL: http://llvm.org/viewvc/llvm-project?rev=139095&view=rev
Log:
CodeGen: Better separate scalar and vector code generation.
Modified:
polly/trunk/lib/CodeGeneration.cpp
polly/trunk/test/CodeGen/simple_vec_stride_x.ll
Modified: polly/trunk/lib/CodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGeneration.cpp?rev=139095&r1=139094&r2=139095&view=diff
==============================================================================
--- polly/trunk/lib/CodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGeneration.cpp Sun Sep 4 06:45:41 2011
@@ -419,29 +419,17 @@
if (!opZero && !opOne)
return;
- bool isVectorOp = vectorMap.count(opZero) || vectorMap.count(opOne);
-
- if (isVectorOp && vectorDimension > 0)
- return;
-
Value *newOpZero, *newOpOne;
newOpZero = getOperand(opZero, BBMap, &vectorMap);
newOpOne = getOperand(opOne, BBMap, &vectorMap);
- std::string name;
- if (isVectorOp) {
- newOpZero = makeVectorOperand(newOpZero, vectorWidth);
- newOpOne = makeVectorOperand(newOpOne, vectorWidth);
- name = Inst->getNameStr() + "p_vec";
- } else
- name = Inst->getNameStr() + "p_sca";
+ newOpZero = makeVectorOperand(newOpZero, vectorWidth);
+ newOpOne = makeVectorOperand(newOpOne, vectorWidth);
Value *newInst = Builder.CreateBinOp(Inst->getOpcode(), newOpZero,
- newOpOne, name);
- if (isVectorOp)
- vectorMap[Inst] = newInst;
- else
- BBMap[Inst] = newInst;
+ newOpOne,
+ Inst->getNameStr() + "p_vec");
+ vectorMap[Inst] = newInst;
return;
}
@@ -482,8 +470,7 @@
return;
}
- void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap,
- ValueMapT &VectorMap) {
+ void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap) {
Instruction *NewInst = Inst->clone();
// Replace old operands with the new ones.
@@ -509,49 +496,58 @@
NewInst->setName("p_" + Inst->getName());
}
+ bool hasVectorOperands(const Instruction *Inst, ValueMapT &VectorMap) {
+ for (Instruction::const_op_iterator OI = Inst->op_begin(),
+ OE = Inst->op_end(); OI != OE; ++OI)
+ if (VectorMap.count(*OI))
+ return true;
+ return false;
+ }
+
+ int getVectorSize() {
+ return ValueMaps.size();
+ }
+
+ bool isVectorBlock() {
+ return getVectorSize() > 1;
+ }
+
void copyInstruction(const Instruction *Inst, ValueMapT &BBMap,
ValueMapT &vectorMap, VectorValueMapT &scalarMaps,
int vectorDimension, int vectorWidth) {
- // If this instruction is already in the vectorMap, a vector instruction
- // was already issued, that calculates the values of all dimensions. No
- // need to create any more instructions.
- if (vectorMap.count(Inst))
- return;
-
// Terminator instructions control the control flow. They are explicitally
// expressed in the clast and do not need to be copied.
if (Inst->isTerminator())
return;
- if (const LoadInst *load = dyn_cast<LoadInst>(Inst)) {
- generateLoad(load, vectorMap, scalarMaps, vectorWidth);
- return;
+ if (isVectorBlock()) {
+ // If this instruction is already in the vectorMap, a vector instruction
+ // was already issued, that calculates the values of all dimensions. No
+ // need to create any more instructions.
+ if (vectorMap.count(Inst))
+ return;
}
- if (const BinaryOperator *binaryInst = dyn_cast<BinaryOperator>(Inst)) {
- copyBinInst(binaryInst, BBMap, vectorMap, scalarMaps, vectorDimension,
- vectorWidth);
+ if (const LoadInst *load = dyn_cast<LoadInst>(Inst)) {
+ generateLoad(load, vectorMap, scalarMaps, vectorWidth);
return;
}
- if (const StoreInst *store = dyn_cast<StoreInst>(Inst))
- if (vectorMap.count(store->getValueOperand()) > 0) {
+ if (isVectorBlock() && hasVectorOperands(Inst, vectorMap)) {
+ if (const BinaryOperator *binaryInst = dyn_cast<BinaryOperator>(Inst))
+ copyBinInst(binaryInst, BBMap, vectorMap, scalarMaps, vectorDimension,
+ vectorWidth);
+ else if (const StoreInst *store = dyn_cast<StoreInst>(Inst))
copyVectorStore(store, BBMap, vectorMap, scalarMaps, vectorDimension,
- vectorWidth);
- return;
- }
-
- copyInstScalar(Inst, BBMap, vectorMap);
- }
+ vectorWidth);
+ else
+ llvm_unreachable("Cannot issue vector code for this instruction");
- int getVectorSize() {
- return ValueMaps.size();
- }
+ return;
+ }
- bool isVectorBlock() {
- return getVectorSize() > 1;
+ copyInstScalar(Inst, BBMap);
}
-
// Insert a copy of a basic block in the newly generated code.
//
// @param Builder The builder used to insert the code. It also specifies
Modified: polly/trunk/test/CodeGen/simple_vec_stride_x.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/CodeGen/simple_vec_stride_x.ll?rev=139095&r1=139094&r2=139095&view=diff
==============================================================================
--- polly/trunk/test/CodeGen/simple_vec_stride_x.ll (original)
+++ polly/trunk/test/CodeGen/simple_vec_stride_x.ll Sun Sep 4 06:45:41 2011
@@ -41,19 +41,19 @@
; CHECK: load float* %p_scevgep1.moved.to.bb3
; CHECK: insertelement <4 x float> undef, float %tmp4_p_scalar_, i32 0
-; CHECK: load float* %p_scevgep1.moved.to.bb31
-; CHECK: insertelement <4 x float> %tmp4_p_vec_, float %tmp4_p_scalar_7, i32 1
-; CHECK: load float* %p_scevgep1.moved.to.bb32
-; CHECK: insertelement <4 x float> %tmp4_p_vec_8, float %tmp4_p_scalar_9, i32 2
-; CHECK: load float* %p_scevgep1.moved.to.bb33
-; CHECK: insertelement <4 x float> %tmp4_p_vec_10, float %tmp4_p_scalar_11, i32 3
-; CHECK: extractelement <4 x float> %tmp4_p_vec_12, i32 0
+; CHECK: load float* %p_scevgep1.moved.to.bb34
+; CHECK: insertelement <4 x float> %tmp4_p_vec_, float %tmp4_p_scalar_10, i32 1
+; CHECK: load float* %p_scevgep1.moved.to.bb35
+; CHECK: insertelement <4 x float> %tmp4_p_vec_11, float %tmp4_p_scalar_12, i32 2
+; CHECK: load float* %p_scevgep1.moved.to.bb36
+; CHECK: insertelement <4 x float> %tmp4_p_vec_13, float %tmp4_p_scalar_14, i32 3
+; CHECK: extractelement <4 x float> %tmp4_p_vec_15, i32 0
; CHECK: store float %0, float* %p_scevgep.moved.to.bb3
-; CHECK: extractelement <4 x float> %tmp4_p_vec_12, i32 1
-; CHECK: store float %1, float* %p_scevgep.moved.to.bb34
-; CHECK: extractelement <4 x float> %tmp4_p_vec_12, i32 2
-; CHECK: store float %2, float* %p_scevgep.moved.to.bb35
-; CHECK: extractelement <4 x float> %tmp4_p_vec_12, i32 3
-; CHECK: store float %3, float* %p_scevgep.moved.to.bb36
+; CHECK: extractelement <4 x float> %tmp4_p_vec_15, i32 1
+; CHECK: store float %1, float* %p_scevgep.moved.to.bb37
+; CHECK: extractelement <4 x float> %tmp4_p_vec_15, i32 2
+; CHECK: store float %2, float* %p_scevgep.moved.to.bb38
+; CHECK: extractelement <4 x float> %tmp4_p_vec_15, i32 3
+; CHECK: store float %3, float* %p_scevgep.moved.to.bb39
More information about the llvm-commits
mailing list