Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -2085,11 +2085,18 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForJumpTable( const Function &F, const TargetMachine &TM) const { - assert (!TM.getFunctionSections() && "Unique sections not supported on XCOFF" - " yet."); assert (!F.getComdat() && "Comdat not supported on XCOFF."); - //TODO: Enable emiting jump table to unique sections when we support it. - return ReadOnlySection; + + if (!TM.getFunctionSections()) + return ReadOnlySection; + + // If the function can be removed, produce a unique section so that + // the table doesn't prevent the removal. + SmallString<128> NameStr(".rodata.jmp.."); + getNameWithPrefix(NameStr, &F, TM); + return getContext().getXCOFFSection(NameStr, XCOFF::XMC_RO, XCOFF::XTY_SD, + XCOFF::C_HIDEXT, + SectionKind::getReadOnly()); } bool TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection( Index: llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll =================================================================== --- llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll +++ llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll @@ -26,6 +26,12 @@ ; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -code-model=large < %s | FileCheck \ ; RUN: --check-prefixes=64LARGE-ASM,CHECK %s +; RUN: llc -mtriple powerpc-ibm-aix-xcoff -function-sections < %s | FileCheck \ +; RUN: --check-prefixes=FUNC-ASM,CHECK %s + +; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -function-sections < %s | FileCheck \ +; RUN: --check-prefixes=FUNC-ASM,CHECK %s + define i32 @jump_table(i32 %a) { entry: switch i32 %a, label %sw.epilog [ @@ -184,5 +190,21 @@ ; 64LARGE-ASM: .vbyte 4, L..BB0_4-L..JTI0_0 ; 64LARGE-ASM: .vbyte 4, L..BB0_5-L..JTI0_0 +; FUNC-ASM: .csect .jump_table[PR],2 +; FUNC-ASM: L..BB0_2: +; FUNC-ASM: L..BB0_3: +; FUNC-ASM: L..BB0_4: +; FUNC-ASM: L..BB0_5: +; FUNC-ASM: L..BB0_6: +; FUNC-ASM: li 3, 0 +; FUNC-ASM: blr +; FUNC-ASM: .csect .rodata.jmp..jump_table[RO],2 +; FUNC-ASM: .align 2 +; FUNC-ASM: L..JTI0_0: +; FUNC-ASM: .vbyte 4, L..BB0_2-L..JTI0_0 +; FUNC-ASM: .vbyte 4, L..BB0_3-L..JTI0_0 +; FUNC-ASM: .vbyte 4, L..BB0_4-L..JTI0_0 +; FUNC-ASM: .vbyte 4, L..BB0_5-L..JTI0_0 + ; CHECK: .toc ; CHECK: .tc L..JTI0_0[TC],L..JTI0_0