Return a StringRef from getSection.

This is similar to how getName is handled.

llvm-svn: 269218
This commit is contained in:
Rafael Espindola 2016-05-11 18:21:59 +00:00
parent 3f61c1ab5e
commit 83658d6e7a
10 changed files with 20 additions and 19 deletions

View File

@ -54,8 +54,8 @@ public:
unsigned getGlobalObjectSubClassData() const;
void setGlobalObjectSubClassData(unsigned Val);
bool hasSection() const { return !StringRef(getSection()).empty(); }
const char *getSection() const { return Section.c_str(); }
bool hasSection() const { return !getSection().empty(); }
StringRef getSection() const { return Section; }
void setSection(StringRef S);
bool hasComdat() const { return getComdat() != nullptr; }

View File

@ -198,14 +198,8 @@ public:
}
void setDLLStorageClass(DLLStorageClassTypes C) { DllStorageClass = C; }
bool hasSection() const { return !StringRef(getSection()).empty(); }
// It is unfortunate that we have to use "char *" in here since this is
// always non NULL, but:
// * The C API expects a null terminated string, so we cannot use StringRef.
// * The C API expects us to own it, so we cannot use a std:string.
// * For GlobalAliases we can fail to find the section and we have to
// return "", so we cannot use a "const std::string &".
const char *getSection() const;
bool hasSection() const { return !getSection().empty(); }
StringRef getSection() const;
/// Global values are always pointers.
PointerType *getType() const { return cast<PointerType>(User::getType()); }

View File

@ -1528,7 +1528,7 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
}
// Ignore debug and non-emitted data. This handles llvm.compiler.used.
if (StringRef(GV->getSection()) == "llvm.metadata" ||
if (GV->getSection() == "llvm.metadata" ||
GV->hasAvailableExternallyLinkage())
return true;

View File

@ -1485,7 +1485,9 @@ void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
}
const char *LLVMGetSection(LLVMValueRef Global) {
return unwrap<GlobalValue>(Global)->getSection();
// Using .data() is safe because of how GlobalObject::setSection is
// implemented.
return unwrap<GlobalValue>(Global)->getSection().data();
}
void LLVMSetSection(LLVMValueRef Global, const char *Section) {

View File

@ -128,7 +128,7 @@ std::string GlobalValue::getGlobalIdentifier() const {
getParent()->getSourceFileName());
}
const char *GlobalValue::getSection() const {
StringRef GlobalValue::getSection() const {
if (auto *GA = dyn_cast<GlobalAlias>(this)) {
// In general we cannot compute this at the IR level, but we try.
if (const GlobalObject *GO = GA->getBaseObject())
@ -151,7 +151,12 @@ Comdat *GlobalValue::getComdat() {
return cast<GlobalObject>(this)->getComdat();
}
void GlobalObject::setSection(StringRef S) { Section = S; }
void GlobalObject::setSection(StringRef S) {
Section = S;
// The C api requires this to be null terminated.
Section.c_str();
}
bool GlobalValue::isDeclaration() const {
// Globals are definitions if they have an initializer.

View File

@ -786,7 +786,7 @@ Constant *IRLinker::linkAppendingVarProto(GlobalVariable *DstGV,
return nullptr;
}
if (StringRef(DstGV->getSection()) != SrcGV->getSection()) {
if (DstGV->getSection() != SrcGV->getSection()) {
emitError(
"Appending variables with different section name need to be linked!");
return nullptr;

View File

@ -248,7 +248,7 @@ uint32_t IRObjectFile::getSymbolFlags(DataRefImpl Symb) const {
if (GV->getName().startswith("llvm."))
Res |= BasicSymbolRef::SF_FormatSpecific;
else if (auto *Var = dyn_cast<GlobalVariable>(GV)) {
if (Var->getSection() == StringRef("llvm.metadata"))
if (Var->getSection() == "llvm.metadata")
Res |= BasicSymbolRef::SF_FormatSpecific;
}

View File

@ -1041,7 +1041,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
// Skip meta data
if (GVar->hasSection()) {
if (GVar->getSection() == StringRef("llvm.metadata"))
if (GVar->getSection() == "llvm.metadata")
return;
}

View File

@ -258,7 +258,7 @@ SDValue XCoreTargetLowering::getGlobalAddressWrapper(SDValue GA,
return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA);
const auto *GVar = dyn_cast<GlobalVariable>(GV);
if ((GV->hasSection() && StringRef(GV->getSection()).startswith(".cp.")) ||
if ((GV->hasSection() && GV->getSection().startswith(".cp.")) ||
(GVar && GVar->isConstant() && GV->hasLocalLinkage()))
return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, GA);

View File

@ -1242,7 +1242,7 @@ bool AddressSanitizerModule::ShouldInstrumentGlobal(GlobalVariable *G) {
if (G->getAlignment() > MinRedzoneSizeForGlobal()) return false;
if (G->hasSection()) {
StringRef Section(G->getSection());
StringRef Section = G->getSection();
// Globals from llvm.metadata aren't emitted, do not instrument them.
if (Section == "llvm.metadata") return false;