[cfe-commits] r149928 - /cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Chris Lattner
sabre at nondot.org
Mon Feb 6 14:52:04 PST 2012
Author: lattner
Date: Mon Feb 6 16:52:04 2012
New Revision: 149928
URL: http://llvm.org/viewvc/llvm-project?rev=149928&view=rev
Log:
build wide strings with ConstantDataArray, just because we can.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=149928&r1=149927&r2=149928&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Feb 6 16:52:04 2012
@@ -2072,20 +2072,26 @@
cast<llvm::ArrayType>(getTypes().ConvertType(E->getType()));
llvm::Type *ElemTy = AType->getElementType();
unsigned NumElements = AType->getNumElements();
- std::vector<llvm::Constant*> Elts;
- Elts.reserve(NumElements);
-
- for(unsigned i=0;i<E->getLength();++i) {
- unsigned value = E->getCodeUnit(i);
- llvm::Constant *C = llvm::ConstantInt::get(ElemTy,value,false);
- Elts.push_back(C);
- }
- for(unsigned i=E->getLength();i<NumElements;++i) {
- llvm::Constant *C = llvm::ConstantInt::get(ElemTy,0,false);
- Elts.push_back(C);
+
+ // Wide strings have either 2-byte or 4-byte elements.
+ if (ElemTy->getPrimitiveSizeInBits() == 16) {
+ SmallVector<uint16_t, 32> Elements;
+ Elements.reserve(NumElements);
+
+ for(unsigned i = 0, e = E->getLength(); i != e; ++i)
+ Elements.push_back(E->getCodeUnit(i));
+ Elements.resize(NumElements);
+ return llvm::ConstantDataArray::get(VMContext, Elements);
}
- return llvm::ConstantArray::get(AType, Elts);
+ assert(ElemTy->getPrimitiveSizeInBits() == 32);
+ SmallVector<uint32_t, 32> Elements;
+ Elements.reserve(NumElements);
+
+ for(unsigned i = 0, e = E->getLength(); i != e; ++i)
+ Elements.push_back(E->getCodeUnit(i));
+ Elements.resize(NumElements);
+ return llvm::ConstantDataArray::get(VMContext, Elements);
}
/// GetAddrOfConstantStringFromLiteral - Return a pointer to a
More information about the cfe-commits
mailing list