#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/PtrUseVisitor.h"
#include "llvm/Analysis/ValueTracking.h"
-#include "llvm/Constants.h"
#include "llvm/DIBuilder.h"
-#include "llvm/DataLayout.h"
#include "llvm/DebugInfo.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Function.h"
-#include "llvm/IRBuilder.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Operator.h"
#include "llvm/InstVisitor.h"
-#include "llvm/Instructions.h"
-#include "llvm/IntrinsicInst.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Module.h"
-#include "llvm/Operator.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
/// \brief Compute a vector splat for a given element value.
Value *getVectorSplat(IRBuilder<> &IRB, Value *V, unsigned NumElements) {
- assert(NumElements > 0 && "Cannot splat to an empty vector.");
-
- // First insert it into a one-element vector so we can shuffle it. It is
- // really silly that LLVM's IR requires this in order to form a splat.
- Value *Undef = UndefValue::get(VectorType::get(V->getType(), 1));
- V = IRB.CreateInsertElement(Undef, V, IRB.getInt32(0),
- getName(".splatinsert"));
-
- // Shuffle the value across the desired number of elements.
- SmallVector<Constant*, 8> Mask(NumElements, IRB.getInt32(0));
- V = IRB.CreateShuffleVector(V, Undef, ConstantVector::get(Mask),
- getName(".splat"));
+ V = IRB.CreateVectorSplat(NumElements, V, NamePrefix);
DEBUG(dbgs() << " splat: " << *V << "\n");
return V;
}