codegen string literals using private linkage now like llvm-gcc, eliminating

some target hooks.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75895 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-07-16 05:03:48 +00:00
Родитель 9797a8760b
Коммит 95b851e55c
5 изменённых файлов: 22 добавлений и 41 удалений

Просмотреть файл

@ -300,18 +300,6 @@ public:
virtual bool useGlobalsForAutomaticVariables() const { return false; }
/// getStringSymbolPrefix - Get the default symbol prefix to
/// use for string literals.
virtual const char *getStringSymbolPrefix(bool IsConstant) const {
return ".str";
}
/// getCFStringSymbolPrefix - Get the default symbol prefix
/// to use for CFString literals.
virtual const char *getCFStringSymbolPrefix() const {
return "";
}
/// getUnicodeStringSymbolPrefix - Get the default symbol prefix to
/// use for string literals.
virtual const char *getUnicodeStringSymbolPrefix() const {

Просмотреть файл

@ -238,14 +238,6 @@ public:
this->TLSSupported = false;
}
virtual const char *getCFStringSymbolPrefix() const {
return "\01L_unnamed_cfstring_";
}
virtual const char *getStringSymbolPrefix(bool IsConstant) const {
return IsConstant ? "\01LC" : "\01lC";
}
virtual const char *getUnicodeStringSymbolPrefix() const {
return "__utf16_string_";
}

Просмотреть файл

@ -494,16 +494,15 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
// Get the two global values corresponding to the ConstantArrays we just
// created to hold the bytes of the strings.
const char *StringPrefix = getContext().Target.getStringSymbolPrefix(true);
llvm::GlobalValue *annoGV =
new llvm::GlobalVariable(*M, anno->getType(), false,
llvm::GlobalValue::InternalLinkage, anno,
GV->getName() + StringPrefix);
new llvm::GlobalVariable(*M, anno->getType(), false,
llvm::GlobalValue::PrivateLinkage, anno,
GV->getName());
// translation unit name string, emitted into the llvm.metadata section.
llvm::GlobalValue *unitGV =
new llvm::GlobalVariable(*M, unit->getType(), false,
llvm::GlobalValue::InternalLinkage, unit,
StringPrefix);
new llvm::GlobalVariable(*M, unit->getType(), false,
llvm::GlobalValue::PrivateLinkage, unit,
".str");
// Create the ConstantStruct for the global annotation.
llvm::Constant *Fields[4] = {
@ -1287,22 +1286,25 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) {
const char *Sect, *Prefix;
bool isConstant;
llvm::GlobalValue::LinkageTypes Linkage;
if (isUTF16) {
Prefix = getContext().Target.getUnicodeStringSymbolPrefix();
Sect = getContext().Target.getUnicodeStringSection();
// FIXME: why do utf strings get "l" labels instead of "L" labels?
Linkage = llvm::GlobalValue::InternalLinkage;
// FIXME: Why does GCC not set constant here?
isConstant = false;
} else {
Prefix = getContext().Target.getStringSymbolPrefix(true);
Prefix = ".str";
Sect = getContext().Target.getCFStringDataSection();
Linkage = llvm::GlobalValue::PrivateLinkage;
// FIXME: -fwritable-strings should probably affect this, but we
// are following gcc here.
isConstant = true;
}
llvm::GlobalVariable *GV =
new llvm::GlobalVariable(getModule(), C->getType(), isConstant,
llvm::GlobalValue::InternalLinkage,
C, Prefix);
Linkage, C, Prefix);
if (Sect)
GV->setSection(Sect);
if (isUTF16) {
@ -1323,8 +1325,8 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) {
// The struct.
C = VMContext.getConstantStruct(STy, Fields);
GV = new llvm::GlobalVariable(getModule(), C->getType(), true,
llvm::GlobalVariable::InternalLinkage, C,
getContext().Target.getCFStringSymbolPrefix());
llvm::GlobalVariable::PrivateLinkage, C,
"_unnamed_cfstring_");
if (const char *Sect = getContext().Target.getCFStringSection())
GV->setSection(Sect);
Entry.setValue(GV);
@ -1383,7 +1385,7 @@ static llvm::Constant *GenerateStringLiteral(const std::string &str,
// Create a global variable for this string
return new llvm::GlobalVariable(CGM.getModule(), C->getType(), constant,
llvm::GlobalValue::InternalLinkage,
llvm::GlobalValue::PrivateLinkage,
C, GlobalName);
}
@ -1401,14 +1403,14 @@ llvm::Constant *CodeGenModule::GetAddrOfConstantString(const std::string &str,
// Get the default prefix if a name wasn't specified.
if (!GlobalName)
GlobalName = getContext().Target.getStringSymbolPrefix(IsConstant);
GlobalName = ".str";
// Don't share any string literals if strings aren't constant.
if (!IsConstant)
return GenerateStringLiteral(str, false, *this, GlobalName);
llvm::StringMapEntry<llvm::Constant *> &Entry =
ConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
ConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
if (Entry.getValue())
return Entry.getValue();

Просмотреть файл

@ -1,9 +1,8 @@
// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm %s -o %t &&
// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck %s
// RUN: grep -F '@"\01LC" = internal constant [8 x i8] c"string0\00"' %t &&
// RUN: grep -F '@"\01LC1" = internal constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"' %t &&
// RUN: grep -F '@__utf16_string_ = internal global [35 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2' %t &&
// RUN: true
// CHECK: @.str = private constant [8 x i8] c"string0\00"
// CHECK: @.str1 = private constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"
// CHECK: @__utf16_string_ = internal global [35 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2
const char *g0 = "string0";
const void *g1 = __builtin___CFStringMakeConstantString("string1");

Просмотреть файл

@ -1,5 +1,5 @@
// RUN: clang-cc -emit-llvm %s -o %t &&
// RUN: grep 'internal constant \[10 x i8\]' %t &&
// RUN: grep 'private constant \[10 x i8\]' %t &&
// RUN: not grep -F "[5 x i8]" %t &&
// RUN: not grep "store " %t