summaryrefslogtreecommitdiff
path: root/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-02-15 22:36:15 +0000
committerBill Wendling <isanbard@gmail.com>2012-02-15 22:36:15 +0000
commit057d521e3d91a894f6c38fcbc21ee5950fbdf7b1 (patch)
tree1e35fc4f93a73a0bc8ed0d7ec9fbcef61323bb90 /lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parentf20f281368f75239c852fe99c3b3a19278ba38fd (diff)
downloadllvm-057d521e3d91a894f6c38fcbc21ee5950fbdf7b1.tar.gz
llvm-057d521e3d91a894f6c38fcbc21ee5950fbdf7b1.tar.bz2
llvm-057d521e3d91a894f6c38fcbc21ee5950fbdf7b1.tar.xz
Modify the code that emits the module flags to use the new module flags accessor
method. This allows the target lowering code to not have to deal with MDNodes. Also, avoid leaking memory like a sieve by not creating a global variable for the image info section, but just emitting the code directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150624 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--lib/CodeGen/TargetLoweringObjectFileImpl.cpp70
1 files changed, 34 insertions, 36 deletions
diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 1b62419aab..90487d9166 100644
--- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -374,57 +374,55 @@ TargetLoweringObjectFileELF::getStaticDtorSection(unsigned Priority) const {
/// emitModuleFlags - Emit the module flags that specify the garbage collection
/// information.
void TargetLoweringObjectFileMachO::
-emitModuleFlags(MCStreamer &Streamer, NamedMDNode *ModFlags,
+emitModuleFlags(MCStreamer &Streamer,
+ ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
Mangler *Mang, const TargetMachine &TM) const {
- StringRef Version("Objective-C Image Info Version");
- StringRef SectionSpec("Objective-C Image Info Section");
- StringRef GC("Objective-C Garbage Collection");
- StringRef GCOnly("Objective-C GC Only");
-
unsigned VersionVal = 0;
unsigned GCFlags = 0;
- StringRef Section;
+ StringRef SectionVal;
- for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) {
- MDNode *Flag = ModFlags->getOperand(i);
- Value *Behavior = Flag->getOperand(0);
+ for (ArrayRef<Module::ModuleFlagEntry>::iterator
+ i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) {
+ const Module::ModuleFlagEntry &MFE = *i;
// Ignore flags with 'Require' behavior.
- if (cast<ConstantInt>(Behavior)->getZExtValue() == Module::Require)
+ if (MFE.Behavior == Module::Require)
continue;
- Value *Key = Flag->getOperand(1);
- Value *Val = Flag->getOperand(2);
-
- StringRef KeyStr = cast<MDString>(Key)->getString();
+ StringRef Key = MFE.Key->getString();
+ Value *Val = MFE.Val;
- if (KeyStr == Version)
+ if (Key == "Objective-C Image Info Version")
VersionVal = cast<ConstantInt>(Val)->getZExtValue();
- else if (KeyStr == GC || KeyStr == GCOnly)
+ else if (Key == "Objective-C Garbage Collection" ||
+ Key == "Objective-C GC Only")
GCFlags |= cast<ConstantInt>(Val)->getZExtValue();
- else if (KeyStr == SectionSpec)
- Section = cast<MDString>(Val)->getString();
+ else if (Key == "Objective-C Image Info Section")
+ SectionVal = cast<MDString>(Val)->getString();
}
- // The section is mandatory. If we don't have it, then we don't have image
- // info information.
- if (Section.empty()) return;
-
- uint32_t Values[2] = { VersionVal, GCFlags };
- Module *M = ModFlags->getParent();
- Constant *Init = ConstantDataArray::get(M->getContext(), Values);
- GlobalVariable *GV = new GlobalVariable(*M, Init->getType(), false,
- GlobalValue::InternalLinkage, Init,
- "\01L_OBJC_IMAGE_INFO");
- GV->setSection(Section);
-
- MCSymbol *GVSym = Mang->getSymbol(GV);
- SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
- const MCSection *TheSection = SectionForGlobal(GV, GVKind, Mang, TM);
+ // The section is mandatory. If we don't have it, then we don't have GC info.
+ if (SectionVal.empty()) return;
- Streamer.SwitchSection(TheSection);
- Streamer.EmitLabel(GVSym);
+ StringRef Segment, Section;
+ unsigned TAA = 0, StubSize = 0;
+ bool TAAParsed;
+ std::string ErrorCode =
+ MCSectionMachO::ParseSectionSpecifier(SectionVal, Segment, Section,
+ TAA, TAAParsed, StubSize);
+ if (!ErrorCode.empty()) {
+ // If invalid, report the error with report_fatal_error.
+ report_fatal_error("Invalid section specifier '" +
+ Section + "': " + ErrorCode + ".");
+ }
+ // Get the section.
+ const MCSectionMachO *S =
+ getContext().getMachOSection(Segment, Section, TAA, StubSize,
+ SectionKind::getDataRel());
+ Streamer.SwitchSection(S);
+ Streamer.EmitLabel(getContext().
+ GetOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
Streamer.EmitIntValue(VersionVal, 4);
Streamer.EmitIntValue(GCFlags, 4);
Streamer.AddBlankLine();