[llvm-commits] [polly] r151907 - /polly/trunk/lib/CodeGeneration.cpp
Tobias Grosser
grosser at fim.uni-passau.de
Fri Mar 2 03:27:28 PST 2012
Author: grosser
Date: Fri Mar 2 05:27:28 2012
New Revision: 151907
URL: http://llvm.org/viewvc/llvm-project?rev=151907&view=rev
Log:
CodeGen: Create separate VectorBlockGenerator
Modified:
polly/trunk/lib/CodeGeneration.cpp
Modified: polly/trunk/lib/CodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGeneration.cpp?rev=151907&r1=151906&r2=151907&view=diff
==============================================================================
--- polly/trunk/lib/CodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGeneration.cpp Fri Mar 2 05:27:28 2012
@@ -224,29 +224,228 @@
return User.Result;
}
-
class BlockGenerator {
public:
- /// @brief Generate code for single basic block.
static void generate(IRBuilder<> &B, ValueMapT &ValueMap,
- VectorValueMapT &VectorMaps, ScopStmt &Stmt,
- __isl_keep isl_set *Domain, Pass *P) {
- BlockGenerator Generator(B, ValueMap, VectorMaps, Stmt, Domain, P);
+ ScopStmt &Stmt, __isl_keep isl_set *Domain, Pass *P) {
+ BlockGenerator Generator(B, ValueMap, Stmt, Domain, P);
Generator.copyBB();
}
-private:
- BlockGenerator(IRBuilder<> &B, ValueMapT &vmap, VectorValueMapT &vmaps,
- ScopStmt &Stmt, __isl_keep isl_set *domain, Pass *p);
-
+protected:
IRBuilder<> &Builder;
ValueMapT &VMap;
- VectorValueMapT &ValueMaps;
Scop &S;
ScopStmt &Statement;
isl_set *ScatteringDomain;
Pass *P;
+ BlockGenerator(IRBuilder<> &B, ValueMapT &vmap, ScopStmt &Stmt,
+ __isl_keep isl_set *Domain, Pass *p);
+
+ Value *getOperand(const Value *oldOperand, ValueMapT &BBMap);
+
+ void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap);
+
+ /// @brief Get the memory access offset to be added to the base address
+ std::vector<Value*> getMemoryAccessIndex(__isl_keep isl_map *AccessRelation,
+ Value *BaseAddress);
+
+ /// @brief Get the new operand address according to the changed access in
+ /// JSCOP file.
+ Value *getNewAccessOperand(__isl_keep isl_map *NewAccessRelation,
+ Value *BaseAddress, const Value *OldOperand,
+ ValueMapT &BBMap);
+
+ /// @brief Generate the operand address
+ Value *generateLocationAccessed(const Instruction *Inst,
+ const Value *Pointer, ValueMapT &BBMap);
+
+ Value *generateScalarLoad(const LoadInst *load, ValueMapT &BBMap);
+
+ void copyInstruction(const Instruction *Inst, ValueMapT &ScalarMap);
+
+ void copyBB();
+};
+
+BlockGenerator::BlockGenerator(IRBuilder<> &B, ValueMapT &vmap, ScopStmt &Stmt,
+ __isl_keep isl_set *domain, Pass *P) :
+ Builder(B), VMap(vmap), S(*Stmt.getParent()), Statement(Stmt),
+ ScatteringDomain(domain), P(P) {}
+
+Value *BlockGenerator::getOperand(const Value *OldOperand, ValueMapT &BBMap) {
+ const Instruction *OpInst = dyn_cast<Instruction>(OldOperand);
+
+ if (!OpInst)
+ return const_cast<Value*>(OldOperand);
+
+ // IVS and Parameters.
+ if (VMap.count(OldOperand)) {
+ Value *NewOperand = VMap[OldOperand];
+
+ // Insert a cast if types are different
+ if (OldOperand->getType()->getScalarSizeInBits()
+ < NewOperand->getType()->getScalarSizeInBits())
+ NewOperand = Builder.CreateTruncOrBitCast(NewOperand,
+ OldOperand->getType());
+
+ return NewOperand;
+ }
+
+ // Instructions calculated in the current BB.
+ if (BBMap.count(OldOperand)) {
+ return BBMap[OldOperand];
+ }
+
+ // Ignore instructions that are referencing ops in the old BB. These
+ // instructions are unused. They where replace by new ones during
+ // createIndependentBlocks().
+ if (S.getRegion().contains(OpInst->getParent()))
+ return NULL;
+
+ return const_cast<Value*>(OldOperand);
+}
+
+void BlockGenerator::copyInstScalar(const Instruction *Inst, ValueMapT &BBMap) {
+ 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);
+
+ if (!NewOperand) {
+ assert(!isa<StoreInst>(NewInst)
+ && "Store instructions are always needed!");
+ delete NewInst;
+ return;
+ }
+
+ NewInst->replaceUsesOfWith(OldOperand, NewOperand);
+ }
+
+ Builder.Insert(NewInst);
+ BBMap[Inst] = NewInst;
+
+ if (!NewInst->getType()->isVoidTy())
+ NewInst->setName("p_" + Inst->getName());
+}
+
+std::vector <Value*> BlockGenerator::getMemoryAccessIndex(
+ __isl_keep isl_map *AccessRelation, Value *BaseAddress) {
+ assert((isl_map_dim(AccessRelation, isl_dim_out) == 1)
+ && "Only single dimensional access functions supported");
+
+ isl_pw_aff *PwAff = isl_map_dim_max(isl_map_copy(AccessRelation), 0);
+ IslGenerator IslGen(Builder);
+ Value *OffsetValue = IslGen.generateIslPwAff(PwAff);
+
+ PointerType *BaseAddressType = dyn_cast<PointerType>(
+ BaseAddress->getType());
+ Type *ArrayTy = BaseAddressType->getElementType();
+ Type *ArrayElementType = dyn_cast<ArrayType>(ArrayTy)->getElementType();
+ OffsetValue = Builder.CreateSExtOrBitCast(OffsetValue, ArrayElementType);
+
+ std::vector<Value*> IndexArray;
+ Value *NullValue = Constant::getNullValue(ArrayElementType);
+ IndexArray.push_back(NullValue);
+ IndexArray.push_back(OffsetValue);
+ return IndexArray;
+}
+
+Value *BlockGenerator::getNewAccessOperand(
+ __isl_keep isl_map *NewAccessRelation, Value *BaseAddress, const Value
+ *OldOperand, ValueMapT &BBMap) {
+ std::vector<Value*> IndexArray = getMemoryAccessIndex(NewAccessRelation,
+ BaseAddress);
+ Value *NewOperand = Builder.CreateGEP(BaseAddress, IndexArray,
+ "p_newarrayidx_");
+ return NewOperand;
+}
+
+Value *BlockGenerator::generateLocationAccessed(const Instruction *Inst,
+ const Value *Pointer,
+ ValueMapT &BBMap ) {
+ MemoryAccess &Access = Statement.getAccessFor(Inst);
+ isl_map *CurrentAccessRelation = Access.getAccessRelation();
+ isl_map *NewAccessRelation = Access.getNewAccessRelation();
+
+ assert(isl_map_has_equal_space(CurrentAccessRelation, NewAccessRelation)
+ && "Current and new access function use different spaces");
+
+ Value *NewPointer;
+
+ if (!NewAccessRelation) {
+ NewPointer = getOperand(Pointer, BBMap);
+ } else {
+ Value *BaseAddress = const_cast<Value*>(Access.getBaseAddr());
+ NewPointer = getNewAccessOperand(NewAccessRelation, BaseAddress, Pointer,
+ BBMap);
+ }
+
+ isl_map_free(CurrentAccessRelation);
+ isl_map_free(NewAccessRelation);
+ return NewPointer;
+}
+
+Value *BlockGenerator::generateScalarLoad(const LoadInst *Load,
+ ValueMapT &BBMap) {
+ const Value *Pointer = Load->getPointerOperand();
+ const Instruction *Inst = dyn_cast<Instruction>(Load);
+ Value *NewPointer = generateLocationAccessed(Inst, Pointer, BBMap);
+ Value *ScalarLoad = Builder.CreateLoad(NewPointer,
+ Load->getName() + "_p_scalar_");
+ return ScalarLoad;
+}
+
+void BlockGenerator::copyInstruction(const Instruction *Inst,
+ ValueMapT &ScalarMap) {
+ // 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);
+ return;
+ }
+
+ copyInstScalar(Inst, ScalarMap);
+}
+
+
+void BlockGenerator::copyBB() {
+ BasicBlock *BB = Statement.getBasicBlock();
+ BasicBlock *CopyBB = SplitBlock(Builder.GetInsertBlock(),
+ Builder.GetInsertPoint(), P);
+ CopyBB->setName("polly.stmt." + BB->getName());
+ Builder.SetInsertPoint(CopyBB->begin());
+
+ ValueMapT ScalarBlockMap;
+
+ for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end(); II != IE;
+ ++II)
+ copyInstruction(II, ScalarBlockMap);
+}
+
+class VectorBlockGenerator : BlockGenerator {
+public:
+ static void generate(IRBuilder<> &B, ValueMapT &ValueMap,
+ VectorValueMapT &VectorMaps, ScopStmt &Stmt,
+ __isl_keep isl_set *Domain, Pass *P) {
+ VectorBlockGenerator Generator(B, ValueMap, VectorMaps, Stmt, Domain, P);
+ Generator.copyBB();
+ }
+
+private:
+ VectorValueMapT &ValueMaps;
+
+ VectorBlockGenerator(IRBuilder<> &B, ValueMapT &vmap, VectorValueMapT &vmaps,
+ ScopStmt &Stmt, __isl_keep isl_set *domain, Pass *p);
+
+ int getVectorWidth();
+
Value *makeVectorOperand(Value *Operand);
Value *getOperand(const Value *oldOperand, ValueMapT &BBMap,
@@ -290,65 +489,36 @@
Value *generateUnknownStrideLoad(const LoadInst *Load,
VectorValueMapT &ScalarMaps);
- /// @brief Get the memory access offset to be added to the base address
- std::vector <Value*> getMemoryAccessIndex(__isl_keep isl_map *AccessRelation,
- Value *BaseAddress);
- /// @brief Get the new operand address according to the changed access in
- /// JSCOP file.
- Value *getNewAccessOperand(__isl_keep isl_map *NewAccessRelation,
- Value *BaseAddress, const Value *OldOperand,
- ValueMapT &BBMap);
-
- /// @brief Generate the operand address
- Value *generateLocationAccessed(const Instruction *Inst,
- const Value *Pointer, ValueMapT &BBMap );
+ void generateLoad(const LoadInst *Load, ValueMapT &VectorMap,
+ VectorValueMapT &ScalarMaps);
- Value *generateScalarLoad(const LoadInst *load, ValueMapT &BBMap);
-
- void generateVectorLoad(const LoadInst *Load, ValueMapT &VectorMap,
- VectorValueMapT &ScalarMaps);
-
- void copyVectorUnaryInst(const UnaryInstruction *Inst, ValueMapT &BBMap,
+ void copyUnaryInst(const UnaryInstruction *Inst, ValueMapT &BBMap,
ValueMapT &VectorMap);
- void copyVectorBinInst(const BinaryOperator *Inst, ValueMapT &BBMap,
+ void copyBinaryInst(const BinaryOperator *Inst, ValueMapT &BBMap,
ValueMapT &VectorMap);
- void copyVectorStore(const StoreInst *Store, ValueMapT &BBMap,
+ void copyStore(const StoreInst *Store, ValueMapT &BBMap,
ValueMapT &VectorMap, VectorValueMapT &ScalarMaps);
- void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap);
-
bool hasVectorOperands(const Instruction *Inst, ValueMapT &VectorMap);
- int getVectorWidth();
-
- bool isVectorBlock();
-
- void copyVectorInstruction(const Instruction *Inst, ValueMapT &VectorMap,
- VectorValueMapT &ScalarMaps);
void copyInstruction(const Instruction *Inst, ValueMapT &VectorMap,
VectorValueMapT &ScalarMaps);
// Insert a copy of a basic block in the newly generated code.
- //
- // @param Builder The builder used to insert the code. It also specifies
- // where to insert the code.
- // @param VMap A map returning for any old value its new equivalent. This
- // is used to update the operands of the statements.
- // For new statements a relation old->new is inserted in this
- // map.
void copyBB();
};
-BlockGenerator::BlockGenerator(IRBuilder<> &B, ValueMapT &vmap,
+VectorBlockGenerator::VectorBlockGenerator(IRBuilder<> &B, ValueMapT &vmap,
VectorValueMapT &vmaps, ScopStmt &Stmt,
__isl_keep isl_set *domain, Pass *P)
- : Builder(B), VMap(vmap), ValueMaps(vmaps), S(*Stmt.getParent()),
- Statement(Stmt), ScatteringDomain(domain), P(P) {}
+ : BlockGenerator(B, vmap, Stmt, domain, P), ValueMaps(vmaps) {
+ assert(ValueMaps.size() > 1 && "Only one vector lane found");
+ }
-Value *BlockGenerator::makeVectorOperand(Value *Operand) {
+Value *VectorBlockGenerator::makeVectorOperand(Value *Operand) {
int VectorWidth = getVectorWidth();
if (Operand->getType()->isVectorTy())
return Operand;
@@ -367,8 +537,9 @@
return Builder.CreateShuffleVector(Vector, Vector, SplatVector);
}
-Value *BlockGenerator::getOperand(const Value *OldOperand, ValueMapT &BBMap,
- ValueMapT *VectorMap) {
+Value *VectorBlockGenerator::getOperand(const Value *OldOperand,
+ ValueMapT &BBMap,
+ ValueMapT *VectorMap) {
const Instruction *OpInst = dyn_cast<Instruction>(OldOperand);
if (!OpInst)
@@ -377,34 +548,10 @@
if (VectorMap && VectorMap->count(OldOperand))
return (*VectorMap)[OldOperand];
- // IVS and Parameters.
- if (VMap.count(OldOperand)) {
- Value *NewOperand = VMap[OldOperand];
-
- // Insert a cast if types are different
- if (OldOperand->getType()->getScalarSizeInBits()
- < NewOperand->getType()->getScalarSizeInBits())
- NewOperand = Builder.CreateTruncOrBitCast(NewOperand,
- OldOperand->getType());
-
- return NewOperand;
- }
-
- // Instructions calculated in the current BB.
- if (BBMap.count(OldOperand)) {
- return BBMap[OldOperand];
- }
-
- // Ignore instructions that are referencing ops in the old BB. These
- // instructions are unused. They where replace by new ones during
- // createIndependentBlocks().
- if (S.getRegion().contains(OpInst->getParent()))
- return NULL;
-
- return const_cast<Value*>(OldOperand);
+ return BlockGenerator::getOperand(OldOperand, BBMap);
}
-Type *BlockGenerator::getVectorPtrTy(const Value *Val, int Width) {
+Type *VectorBlockGenerator::getVectorPtrTy(const Value *Val, int Width) {
PointerType *PointerTy = dyn_cast<PointerType>(Val->getType());
assert(PointerTy && "PointerType expected");
@@ -414,8 +561,8 @@
return PointerType::getUnqual(VectorType);
}
-Value *BlockGenerator::generateStrideOneLoad(const LoadInst *Load,
- ValueMapT &BBMap) {
+Value *VectorBlockGenerator::generateStrideOneLoad(const LoadInst *Load,
+ ValueMapT &BBMap) {
const Value *Pointer = Load->getPointerOperand();
Type *VectorPtrType = getVectorPtrTy(Pointer, getVectorWidth());
Value *NewPointer = getOperand(Pointer, BBMap);
@@ -429,8 +576,8 @@
return VecLoad;
}
-Value *BlockGenerator::generateStrideZeroLoad(const LoadInst *Load,
- ValueMapT &BBMap) {
+Value *VectorBlockGenerator::generateStrideZeroLoad(const LoadInst *Load,
+ ValueMapT &BBMap) {
const Value *Pointer = Load->getPointerOperand();
Type *VectorPtrType = getVectorPtrTy(Pointer, 1);
Value *NewPointer = getOperand(Pointer, BBMap);
@@ -453,8 +600,8 @@
return VectorLoad;
}
-Value *BlockGenerator::generateUnknownStrideLoad(const LoadInst *Load,
- VectorValueMapT &ScalarMaps) {
+Value *VectorBlockGenerator::generateUnknownStrideLoad(const LoadInst *Load,
+ VectorValueMapT &ScalarMaps) {
int VectorWidth = getVectorWidth();
const Value *Pointer = Load->getPointerOperand();
VectorType *VectorType = VectorType::get(
@@ -474,76 +621,9 @@
return Vector;
}
-std::vector <Value*> BlockGenerator::getMemoryAccessIndex(
- __isl_keep isl_map *AccessRelation, Value *BaseAddress) {
- assert((isl_map_dim(AccessRelation, isl_dim_out) == 1)
- && "Only single dimensional access functions supported");
-
- isl_pw_aff *PwAff = isl_map_dim_max(isl_map_copy(AccessRelation), 0);
- IslGenerator IslGen(Builder);
- Value *OffsetValue = IslGen.generateIslPwAff(PwAff);
-
- PointerType *BaseAddressType = dyn_cast<PointerType>(
- BaseAddress->getType());
- Type *ArrayTy = BaseAddressType->getElementType();
- Type *ArrayElementType = dyn_cast<ArrayType>(ArrayTy)->getElementType();
- OffsetValue = Builder.CreateSExtOrBitCast(OffsetValue, ArrayElementType);
-
- std::vector<Value*> IndexArray;
- Value *NullValue = Constant::getNullValue(ArrayElementType);
- IndexArray.push_back(NullValue);
- IndexArray.push_back(OffsetValue);
- return IndexArray;
-}
-
-Value *BlockGenerator::getNewAccessOperand(
- __isl_keep isl_map *NewAccessRelation, Value *BaseAddress, const Value
- *OldOperand, ValueMapT &BBMap) {
- std::vector<Value*> IndexArray = getMemoryAccessIndex(NewAccessRelation,
- BaseAddress);
- Value *NewOperand = Builder.CreateGEP(BaseAddress, IndexArray,
- "p_newarrayidx_");
- return NewOperand;
-}
-
-Value *BlockGenerator::generateLocationAccessed(const Instruction *Inst,
- const Value *Pointer,
- ValueMapT &BBMap ) {
- MemoryAccess &Access = Statement.getAccessFor(Inst);
- isl_map *CurrentAccessRelation = Access.getAccessRelation();
- isl_map *NewAccessRelation = Access.getNewAccessRelation();
-
- assert(isl_map_has_equal_space(CurrentAccessRelation, NewAccessRelation)
- && "Current and new access function use different spaces");
-
- Value *NewPointer;
-
- if (!NewAccessRelation) {
- NewPointer = getOperand(Pointer, BBMap);
- } else {
- Value *BaseAddress = const_cast<Value*>(Access.getBaseAddr());
- NewPointer = getNewAccessOperand(NewAccessRelation, BaseAddress, Pointer,
- BBMap);
- }
-
- isl_map_free(CurrentAccessRelation);
- isl_map_free(NewAccessRelation);
- return NewPointer;
-}
-
-Value *BlockGenerator::generateScalarLoad(const LoadInst *Load,
- ValueMapT &BBMap) {
- const Value *Pointer = Load->getPointerOperand();
- const Instruction *Inst = dyn_cast<Instruction>(Load);
- Value *NewPointer = generateLocationAccessed(Inst, Pointer, BBMap);
- Value *ScalarLoad = Builder.CreateLoad(NewPointer,
- Load->getName() + "_p_scalar_");
- return ScalarLoad;
-}
-
-void BlockGenerator::generateVectorLoad(const LoadInst *Load,
- ValueMapT &VectorMap,
- VectorValueMapT &ScalarMaps) {
+void VectorBlockGenerator::generateLoad(const LoadInst *Load,
+ ValueMapT &VectorMap,
+ VectorValueMapT &ScalarMaps) {
Value *NewLoad;
MemoryAccess &Access = Statement.getAccessFor(Load);
@@ -560,7 +640,7 @@
VectorMap[Load] = NewLoad;
}
-void BlockGenerator::copyVectorUnaryInst(const UnaryInstruction *Inst,
+void VectorBlockGenerator::copyUnaryInst(const UnaryInstruction *Inst,
ValueMapT &BBMap,
ValueMapT &VectorMap) {
int VectorWidth = getVectorWidth();
@@ -574,8 +654,9 @@
VectorMap[Inst] = Builder.CreateCast(Cast->getOpcode(), NewOperand, DestType);
}
-void BlockGenerator::copyVectorBinInst(const BinaryOperator *Inst,
- ValueMapT &BBMap, ValueMapT &VectorMap) {
+void VectorBlockGenerator::copyBinaryInst(const BinaryOperator *Inst,
+ ValueMapT &BBMap,
+ ValueMapT &VectorMap) {
Value *OpZero = Inst->getOperand(0);
Value *OpOne = Inst->getOperand(1);
@@ -592,7 +673,7 @@
VectorMap[Inst] = NewInst;
}
-void BlockGenerator::copyVectorStore(const StoreInst *Store, ValueMapT &BBMap,
+void VectorBlockGenerator::copyStore(const StoreInst *Store, ValueMapT &BBMap,
ValueMapT &VectorMap,
VectorValueMapT &ScalarMaps) {
int VectorWidth = getVectorWidth();
@@ -624,34 +705,8 @@
}
}
-void BlockGenerator::copyInstScalar(const Instruction *Inst, ValueMapT &BBMap) {
- 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);
-
- if (!NewOperand) {
- assert(!isa<StoreInst>(NewInst)
- && "Store instructions are always needed!");
- delete NewInst;
- return;
- }
-
- NewInst->replaceUsesOfWith(OldOperand, NewOperand);
- }
-
- Builder.Insert(NewInst);
- BBMap[Inst] = NewInst;
-
- if (!NewInst->getType()->isVoidTy())
- NewInst->setName("p_" + Inst->getName());
-}
-
-bool BlockGenerator::hasVectorOperands(const Instruction *Inst,
- ValueMapT &VectorMap) {
+bool VectorBlockGenerator::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))
@@ -659,35 +714,36 @@
return false;
}
-int BlockGenerator::getVectorWidth() {
+int VectorBlockGenerator::getVectorWidth() {
return ValueMaps.size();
}
-bool BlockGenerator::isVectorBlock() {
- return getVectorWidth() > 1;
-}
-
-void BlockGenerator::copyVectorInstruction(const Instruction *Inst,
+void VectorBlockGenerator::copyInstruction(const Instruction *Inst,
ValueMapT &VectorMap,
VectorValueMapT &ScalarMaps) {
+ // 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)) {
- generateVectorLoad(Load, VectorMap, ScalarMaps);
+ generateLoad(Load, VectorMap, ScalarMaps);
return;
}
if (hasVectorOperands(Inst, VectorMap)) {
if (const StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
- copyVectorStore(Store, ScalarMaps[0], VectorMap, ScalarMaps);
+ copyStore(Store, ScalarMaps[0], VectorMap, ScalarMaps);
return;
}
if (const UnaryInstruction *Unary = dyn_cast<UnaryInstruction>(Inst)) {
- copyVectorUnaryInst(Unary, ScalarMaps[0], VectorMap);
+ copyUnaryInst(Unary, ScalarMaps[0], VectorMap);
return;
}
if (const BinaryOperator *Binary = dyn_cast<BinaryOperator>(Inst)) {
- copyVectorBinInst(Binary, ScalarMaps[0], VectorMap);
+ copyBinaryInst(Binary, ScalarMaps[0], VectorMap);
return;
}
@@ -698,28 +754,7 @@
copyInstScalar(Inst, ScalarMaps[VectorLane]);
}
-void BlockGenerator::copyInstruction(const Instruction *Inst,
- ValueMapT &VectorMap,
- VectorValueMapT &ScalarMaps) {
- // 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 (isVectorBlock()) {
- copyVectorInstruction(Inst, VectorMap, ScalarMaps);
- return;
- }
-
- if (const LoadInst *Load = dyn_cast<LoadInst>(Inst)) {
- ScalarMaps[0][Load] = generateScalarLoad(Load, ScalarMaps[0]);
- return;
- }
-
- copyInstScalar(Inst, ScalarMaps[0]);
-}
-
-void BlockGenerator::copyBB() {
+void VectorBlockGenerator::copyBB() {
BasicBlock *BB = Statement.getBasicBlock();
BasicBlock *CopyBB = SplitBlock(Builder.GetInsertBlock(),
Builder.GetInsertPoint(), P);
@@ -1067,9 +1102,14 @@
if (u->substitutions)
codegenSubstitutions(u->substitutions, Statement);
- int vectorDimensions = IVS ? IVS->size() : 1;
+ int VectorDimensions = IVS ? IVS->size() : 1;
+
+ if (VectorDimensions == 1) {
+ BlockGenerator::generate(Builder, ValueMap, *Statement, Domain, P);
+ return;
+ }
- VectorValueMapT VectorMap(vectorDimensions);
+ VectorValueMapT VectorMap(VectorDimensions);
if (IVS) {
assert (u->substitutions && "Substitutions expected!");
@@ -1082,7 +1122,8 @@
}
}
- BlockGenerator::generate(Builder, ValueMap, VectorMap, *Statement, Domain, P);
+ VectorBlockGenerator::generate(Builder, ValueMap, VectorMap, *Statement,
+ Domain, P);
}
void ClastStmtCodeGen::codegen(const clast_block *b) {
More information about the llvm-commits
mailing list