From 86b1a7d61413aed40a68f98f1e8f17fd79ebd7a2 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 12 Jan 2012 23:05:03 +0000 Subject: [PATCH] Fix the code that was WRONG. The registers are placed into the saved registers list in the reverse order, which is why the original loop was written to loop backwards. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148064 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/LangRef.html | 137 ++++++++++++++++++++++++++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 65 ++++++++++++ lib/Target/X86/X86FrameLowering.cpp | 19 ++-- 3 files changed, 208 insertions(+), 13 deletions(-) diff --git a/docs/LangRef.html b/docs/LangRef.html index 27990837487..6881620cbc0 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -106,6 +106,11 @@
  • 'fpaccuracy' Metadata
  • +
  • Module Flags Metadata +
      +
    1. Objective-C Metadata
    2. +
    +
  • Intrinsic Global Variables @@ -3024,6 +3029,138 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25) + + + +

    + Module Flags Metadata +

    + +
    + +

    Occasionally, the front-end needs to transmit data to the linker which + affects its behavior. The LLVM IR isn't sufficient to transmit this + information, so one should use the llvm.module.flags named + metadata.

    + +

    The llvm.module.flags metadata is a named metadata, whose elements + consist of metadata triplets. For example:

    + +
    +!0 = metadata !{ i32 0, metadata !"foo", i32 1 }
    +!1 = metadata !{ i32 1, metadata !"bar", i32 37 }
    +
    +!llvm.module.flags = !{ !0, !1 }
    +
    + +

    The first field specifies the behavior of the linker upon encountering two of + the same values. Behavior could range from: emitting an error if some of the + modules' flags disagree, emitting a warning, etc. The second field is the + name of the metadata. The third field is the value of the metadata.

    + +

    When two modules are linked together, the llvm.module.flags metadata + are unioned together.

    + +
    + + +

    + Objective-C Metadata +

    + +
    + +

    The following module flags are used to convey Objective-C metadata to the + linker.

    + + + + + + + + + + + + + + + + + + + + +
    ValueBehavior
    1 +
    +
    Error
    +
    Causes the linker to emit an error when two values disagree.
    +
    +
    2 +
    +
    Require
    +
    Causes the linker to emit an error when the specified value is not + present.
    +
    +
    3 +
    +
    Override
    +
    Causes the linker to use the specified value if the two values + disagree. It's an error if two pieces of the same metadata have + the Override behavior but different values.
    +
    +
    + +

    The names are:

    + +
      +
    • Objective-C Version
    • +
    • Objective-C Garbage Collection
    • +
    • Objective-C GC Only
    • +
    • Objective-C Image Info Section
    • +
    + +

    + +

    Here is an example of how to use the Objective-C metadata:

    + +
    +Module A
    +!0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 }
    +!1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 }
    +!2 = metadata !{ i32 1, metadata !"Objective-C Image Info Section",
    +                 metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" }
    +!llvm.module.flags = !{ !0, !1, !2 }
    +
    +Module B
    +!0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 }
    +!1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 }
    +!2 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 }
    +!3 = metadata !{ i32 1, metadata !"Objective-C Image Info Section",
    +                 metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" }
    +!4 = metadata !{ i32 2, metadata !"Objective-C GC Only",
    +  metadata !{
    +    metadata !"Objective-C Garbage Collection", i32 2
    +  }
    +}
    +!llvm.module.flags = !{ !0, !1, !2, !3, !4 }
    +
    +Linked Module
    +!0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 }
    +!1 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", i32 2 }
    +!2 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 }
    +!3 = metadata !{ i32 1, metadata !"Objective-C Image Info Section",
    +                 metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" }
    +!4 = metadata !{ i32 2, metadata !"Objective-C GC Only",
    +  metadata !{
    +    metadata !"Objective-C Garbage Collection", i32 2
    +  }
    +}
    +!llvm.module.flags = !{ !0, !1, !2, !3, !4 }
    +
    + +
    diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 82860c26574..1b15cdcc810 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -930,6 +930,71 @@ bool AsmPrinter::doFinalization(Module &M) { if (const MCSection *S = MAI->getNonexecutableStackSection(OutContext)) OutStreamer.SwitchSection(S); + // If we have module flags, then emit them. + NamedMDNode *ModFlags = M.getNamedMetadata("llvm.module.flags"); + if (ModFlags) { + const char *ObjCGCName = "Objective-C Garbage Collection"; + const char *ObjCGCOnlyName = "Objective-C GC Only"; + const char *ObjCImageInfoVersion = "Objective-C Image Info Version"; + const char *ObjCImageInfoSec = "Objective-C Image Info Section"; + + MDNode *GC = 0; + MDNode *GCOnly = 0; + MDNode *ImageInfoVersion = 0; + MDNode *ImageInfoSec = 0; + + for (unsigned I = 0, E = ModFlags->getNumOperands(); I != E; ++I) { + MDNode *MD = ModFlags->getOperand(I); + unsigned Behavior = cast(MD->getOperand(0))->getZExtValue(); + (void) Behavior; + MDString *Str = cast(MD->getOperand(1)); + + if (Str->getString() == ObjCImageInfoVersion) { + assert(Behavior == 1 && "Invalid behavior for module flag!"); + ImageInfoVersion = MD; + } else if (Str->getString() == ObjCGCName) { + assert((Behavior == 1 || Behavior == 3) && + "Invalid behavior for module flag!"); + GC = MD; + } else if (Str->getString() == ObjCGCOnlyName) { + if (Behavior == 2) continue; // Ignore the 'require' clause. + GCOnly = MD; + } else if (Str->getString() == ObjCImageInfoSec) { + assert(Behavior == 1 && "Invalid behavior for module flag!"); + ImageInfoSec = MD; + } + } + + if (ImageInfoVersion || GC || GCOnly || ImageInfoSec) { + // FIXME: Duh! + unsigned version = 0; + unsigned flags = 0; + + version = + cast(ImageInfoVersion->getOperand(2))->getZExtValue(); + if (GC) + flags |= cast(GC->getOperand(2))->getZExtValue(); + if (GCOnly) + flags |= cast(GCOnly->getOperand(2))->getZExtValue(); + + Type *Int32Ty = Type::getInt32Ty(M.getContext()); + Constant *values[2] = { + ConstantInt::get(Int32Ty, version), + ConstantInt::get(Int32Ty, flags) + }; + ArrayType *AT = ArrayType::get(Int32Ty, 2); + StringRef Sec = cast(ImageInfoSec->getOperand(2))->getString(); + + GlobalVariable *GV = + cast(M.getOrInsertGlobal("L_OBJC_IMAGE_INFO", AT)); + GV->setConstant(true); + GV->setSection(Sec); + GV->setInitializer(ConstantArray::get(AT, values)); + + EmitGlobalVariable(GV); + } + } + // Allow the target to emit any magic that it wants at the end of the file, // after everything else has gone out. EmitEndOfAsmFile(M); diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index e5f67526143..5dfc0bb85d8 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -455,26 +455,19 @@ encodeCompactUnwindRegistersWithFrame(unsigned SavedRegs[CU_NUM_SAVED_REGS], }; const unsigned *CURegs = (Is64Bit ? CU64BitRegs : CU32BitRegs); - // FIXME: The code below is WRONG and breaks tests on i386, see - // SingleSource/Regression/C++/EH/ctor_dtor_count.exec - // SingleSource/Regression/C++/EH/exception_spec_test.exec - // SingleSource/Regression/C++/EH/function_try_block.exec - // SingleSource/Regression/C++/EH/throw_rethrow_test.exec - return ~0U; - // Encode the registers in the order they were saved, 3-bits per register. The - // registers are numbered from 1 to 6. + // registers are numbered from 1 to CU_NUM_SAVED_REGS. uint32_t RegEnc = 0; - for (int I = 0; I != 6; ++I) { + for (int I = CU_NUM_SAVED_REGS, Idx = 0; I != -1; --I) { unsigned Reg = SavedRegs[I]; - if (Reg == 0) break; + if (Reg == 0) continue; + int CURegNum = getCompactUnwindRegNum(CURegs, Reg); - if (CURegNum == -1) - return ~0U; + if (CURegNum == -1) return ~0U; // Encode the 3-bit register number in order, skipping over 3-bits for each // register. - RegEnc |= (CURegNum & 0x7) << ((5 - I) * 3); + RegEnc |= (CURegNum & 0x7) << (Idx++ * 3); } assert((RegEnc & 0x3FFFF) == RegEnc && "Invalid compact register encoding!");