aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/LowerPacked.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/Scalar/LowerPacked.cpp')
-rw-r--r--lib/Transforms/Scalar/LowerPacked.cpp88
1 files changed, 44 insertions, 44 deletions
diff --git a/lib/Transforms/Scalar/LowerPacked.cpp b/lib/Transforms/Scalar/LowerPacked.cpp
index e2242223a2..725a4ba8eb 100644
--- a/lib/Transforms/Scalar/LowerPacked.cpp
+++ b/lib/Transforms/Scalar/LowerPacked.cpp
@@ -1,10 +1,10 @@
//===- LowerPacked.cpp - Implementation of LowerPacked Transform ---------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by Brad Jones and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This file implements lowering Packed datatypes into more primitive
@@ -38,7 +38,7 @@ namespace {
///
class LowerPacked : public FunctionPass, public InstVisitor<LowerPacked> {
public:
- /// @brief Lowers packed operations to scalar operations.
+ /// @brief Lowers packed operations to scalar operations.
/// @param F The fuction to process
virtual bool runOnFunction(Function &F);
@@ -60,13 +60,13 @@ public:
/// This function asserts if the instruction is a PackedType but
/// is handled by another function.
- ///
+ ///
/// @brief Asserts if PackedType instruction is not handled elsewhere.
/// @param I the unhandled instruction
void visitInstruction(Instruction &I)
{
if(isa<PackedType>(I.getType())) {
- std::cerr << "Unhandled Instruction with Packed ReturnType: " <<
+ std::cerr << "Unhandled Instruction with Packed ReturnType: " <<
I << '\n';
}
}
@@ -82,7 +82,7 @@ private:
void setValues(Value* val,const std::vector<Value*>& values);
// Data Members
- /// @brief whether we changed the function or not
+ /// @brief whether we changed the function or not
bool Changed;
/// @brief a map from old packed values to new smaller packed values
@@ -91,27 +91,27 @@ private:
/// Instructions in the source program to get rid of
/// after we do a pass (the old packed instructions)
std::vector<Instruction*> instrsToRemove;
-};
+};
-RegisterOpt<LowerPacked>
-X("lower-packed",
+RegisterOpt<LowerPacked>
+X("lower-packed",
"lowers packed operations to operations on smaller packed datatypes");
-} // end namespace
+} // end namespace
FunctionPass *llvm::createLowerPackedPass() { return new LowerPacked(); }
// This function sets lowered values for a corresponding
// packed value. Note, in the case of a forward reference
-// getValues(Value*) will have already been called for
-// the packed parameter. This function will then replace
-// all references in the in the function of the "dummy"
-// value the previous getValues(Value*) call
+// getValues(Value*) will have already been called for
+// the packed parameter. This function will then replace
+// all references in the in the function of the "dummy"
+// value the previous getValues(Value*) call
// returned with actual references.
void LowerPacked::setValues(Value* value,const std::vector<Value*>& values)
{
- std::map<Value*,std::vector<Value*> >::iterator it =
+ std::map<Value*,std::vector<Value*> >::iterator it =
packedToScalarMap.lower_bound(value);
if (it == packedToScalarMap.end() || it->first != value) {
// there was not a forward reference to this element
@@ -119,7 +119,7 @@ void LowerPacked::setValues(Value* value,const std::vector<Value*>& values)
}
else {
// replace forward declarations with actual definitions
- assert(it->second.size() == values.size() &&
+ assert(it->second.size() == values.size() &&
"Error forward refences and actual definition differ in size");
for (unsigned i = 0, e = values.size(); i != e; ++i) {
// replace and get rid of old forward references
@@ -133,8 +133,8 @@ void LowerPacked::setValues(Value* value,const std::vector<Value*>& values)
// This function will examine the packed value parameter
// and if it is a packed constant or a forward reference
// properly create the lowered values needed. Otherwise
-// it will simply retreive values from a
-// setValues(Value*,const std::vector<Value*>&)
+// it will simply retreive values from a
+// setValues(Value*,const std::vector<Value*>&)
// call. Failing both of these cases, it will abort
// the program.
std::vector<Value*>& LowerPacked::getValues(Value* value)
@@ -144,7 +144,7 @@ std::vector<Value*>& LowerPacked::getValues(Value* value)
// reject further processing if this one has
// already been handled
- std::map<Value*,std::vector<Value*> >::iterator it =
+ std::map<Value*,std::vector<Value*> >::iterator it =
packedToScalarMap.lower_bound(value);
if (it != packedToScalarMap.end() && it->first == value) {
return it->second;
@@ -162,11 +162,11 @@ std::vector<Value*>& LowerPacked::getValues(Value* value)
}
else if (ConstantAggregateZero* CAZ =
dyn_cast<ConstantAggregateZero>(value)) {
- // zero constant
+ // zero constant
const PackedType* PKT = cast<PackedType>(CAZ->getType());
std::vector<Value*> results;
results.reserve(PKT->getNumElements());
-
+
Constant* C = Constant::getNullValue(PKT->getElementType());
for (unsigned i = 0, e = PKT->getNumElements(); i != e; ++i) {
results.push_back(C);
@@ -179,7 +179,7 @@ std::vector<Value*>& LowerPacked::getValues(Value* value)
const PackedType* PKT = cast<PackedType>(value->getType());
std::vector<Value*> results;
results.reserve(PKT->getNumElements());
-
+
for (unsigned i = 0, e = PKT->getNumElements(); i != e; ++i) {
results.push_back(new Argument(PKT->getElementType()));
}
@@ -221,19 +221,19 @@ void LowerPacked::visitLoadInst(LoadInst& LI)
Idx[1] = ConstantUInt::get(Type::UIntTy,i);
// Get the pointer
- Value* val = new GetElementPtrInst(array,
+ Value* val = new GetElementPtrInst(array,
Idx,
- LI.getName() +
+ LI.getName() +
".ge." + utostr(i),
&LI);
// generate the new load and save the result in packedToScalar map
- values.push_back(new LoadInst(val,
+ values.push_back(new LoadInst(val,
LI.getName()+"."+utostr(i),
LI.isVolatile(),
&LI));
}
-
+
setValues(&LI,values);
Changed = true;
instrsToRemove.push_back(&LI);
@@ -251,13 +251,13 @@ void LowerPacked::visitBinaryOperator(BinaryOperator& BO)
"The two packed operand to scalar maps must be equal in size.");
result.reserve(op0Vals.size());
-
+
// generate the new binary op and save the result
for (unsigned i = 0; i != op0Vals.size(); ++i) {
- result.push_back(BinaryOperator::create(BO.getOpcode(),
- op0Vals[i],
+ result.push_back(BinaryOperator::create(BO.getOpcode(),
+ op0Vals[i],
op1Vals[i],
- BO.getName() +
+ BO.getName() +
"." + utostr(i),
&BO));
}
@@ -270,12 +270,12 @@ void LowerPacked::visitBinaryOperator(BinaryOperator& BO)
void LowerPacked::visitStoreInst(StoreInst& SI)
{
- if (const PackedType* PKT =
+ if (const PackedType* PKT =
dyn_cast<PackedType>(SI.getOperand(0)->getType())) {
// We will need this for getelementptr
std::vector<Value*> Idx(2);
Idx[0] = ConstantUInt::get(Type::UIntTy,0);
-
+
ArrayType* AT = ArrayType::get(PKT->getContainedType(0),
PKT->getNumElements());
PointerType* APT = PointerType::get(AT);
@@ -286,21 +286,21 @@ void LowerPacked::visitStoreInst(StoreInst& SI)
"store.ge.a.",
&SI);
std::vector<Value*>& values = getValues(SI.getOperand(0));
-
+
assert((values.size() == PKT->getNumElements()) &&
"Scalar must have the same number of elements as Packed Type");
for (unsigned i = 0, e = PKT->getNumElements(); i != e; ++i) {
// Generate the indices for getelementptr
Idx[1] = ConstantUInt::get(Type::UIntTy,i);
- Value* val = new GetElementPtrInst(array,
+ Value* val = new GetElementPtrInst(array,
Idx,
"store.ge." +
utostr(i) + ".",
&SI);
new StoreInst(values[i], val, SI.isVolatile(),&SI);
}
-
+
Changed = true;
instrsToRemove.push_back(&SI);
}
@@ -319,12 +319,12 @@ void LowerPacked::visitSelectInst(SelectInst& SELI)
for (unsigned i = 0; i != op0Vals.size(); ++i) {
result.push_back(new SelectInst(SELI.getCondition(),
- op0Vals[i],
+ op0Vals[i],
op1Vals[i],
SELI.getName()+ "." + utostr(i),
&SELI));
}
-
+
setValues(&SELI,result);
Changed = true;
instrsToRemove.push_back(&SELI);
@@ -334,24 +334,24 @@ void LowerPacked::visitSelectInst(SelectInst& SELI)
bool LowerPacked::runOnFunction(Function& F)
{
// initialize
- Changed = false;
-
+ Changed = false;
+
// Does three passes:
- // Pass 1) Converts Packed Operations to
+ // Pass 1) Converts Packed Operations to
// new Packed Operations on smaller
// datatypes
visit(F);
-
+
// Pass 2) Drop all references
std::for_each(instrsToRemove.begin(),
instrsToRemove.end(),
std::mem_fun(&Instruction::dropAllReferences));
// Pass 3) Delete the Instructions to remove aka packed instructions
- for (std::vector<Instruction*>::iterator i = instrsToRemove.begin(),
- e = instrsToRemove.end();
+ for (std::vector<Instruction*>::iterator i = instrsToRemove.begin(),
+ e = instrsToRemove.end();
i != e; ++i) {
- (*i)->getParent()->getInstList().erase(*i);
+ (*i)->getParent()->getInstList().erase(*i);
}
// clean-up