Skip to content

Commit bd4bf85

Browse files
author
Wael Yehia
committed
support large code model
1 parent a25cbf1 commit bd4bf85

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,18 +3576,35 @@ void PPCAIXAsmPrinter::emitGlobalIFunc(Module &M, const GlobalIFunc &GI) {
35763576
return;
35773577
}
35783578

3579-
// lwz 12, L..foo_desc(2)
35803579
auto FnDescTOCEntryType = getTOCEntryTypeForLinkage(GI.getLinkage());
3581-
auto *FnDescTOCEntrySym =
3582-
lookUpOrCreateTOCEntry(CurrentFnDescSym, FnDescTOCEntryType);
3583-
auto *Exp = MCSymbolRefExpr::create(FnDescTOCEntrySym, OutContext);
3584-
// Exp = getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp, VK);// TODO: need this?
3585-
// need this uncommented
3586-
OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::LD : PPC::LWZ)
3587-
.addReg(PPC::X12)
3588-
.addExpr(Exp)
3589-
.addReg(PPC::X2),
3590-
*Subtarget);
3580+
auto *FnDescTOCEntrySym = lookUpOrCreateTOCEntry(CurrentFnDescSym, FnDescTOCEntryType);
3581+
3582+
if (TM.getCodeModel() == CodeModel::Large) {
3583+
// addis 12, L..foo_desc@u(2)
3584+
// lwz 12, L..foo_desc@l(12)
3585+
auto *Exp_U = symbolWithSpecifier(FnDescTOCEntrySym, PPC::S_U);
3586+
OutStreamer->emitInstruction(MCInstBuilder(PPC::ADDIS)
3587+
.addReg(PPC::X12)
3588+
.addReg(PPC::X2)
3589+
.addExpr(Exp_U),
3590+
*Subtarget);
3591+
auto *Exp_L = symbolWithSpecifier(FnDescTOCEntrySym, PPC::S_L);
3592+
OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::LD : PPC::LWZ)
3593+
.addReg(PPC::X12)
3594+
.addExpr(Exp_L)
3595+
.addReg(PPC::X12),
3596+
*Subtarget);
3597+
} else {
3598+
// lwz 12, L..foo_desc(2)
3599+
auto *Exp = MCSymbolRefExpr::create(FnDescTOCEntrySym, OutContext);
3600+
// Exp = getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp, VK);
3601+
// TODO: do we need to uncomment this?
3602+
OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::LD : PPC::LWZ)
3603+
.addReg(PPC::X12)
3604+
.addExpr(Exp)
3605+
.addReg(PPC::X2),
3606+
*Subtarget);
3607+
}
35913608
// lwz 11, 8(12)
35923609
OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::LD : PPC::LWZ)
35933610
.addReg(PPC::X11)

llvm/test/CodeGen/PowerPC/aix-ifunc.ll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
; RUN: llc -mtriple=powerpc64-ibm-aix-xcoff --function-sections %s -o - | FileCheck %s --check-prefixes=COMMON,FUNCSECT -DALIGN=3 -DPTR_SIZE=8 -DLOAD=ld -DOFF=16
55
; RUN: llc -mtriple=powerpc-ibm-aix-xcoff --function-sections %s -o - | FileCheck %s --check-prefixes=COMMON,FUNCSECT -DALIGN=2 -DPTR_SIZE=4 -DLOAD=lwz -DOFF=8
66

7+
; RUN: llc -mtriple=powerpc64-ibm-aix-xcoff --function-sections --code-model=large %s -o - | FileCheck %s --check-prefixes=LARGE -DALIGN=3 -DPTR_SIZE=8 -DLOAD=ld -DOFF=16
8+
; RUN: llc -mtriple=powerpc-ibm-aix-xcoff --function-sections --code-model=large %s -o - | FileCheck %s --check-prefixes=LARGE -DALIGN=2 -DPTR_SIZE=4 -DLOAD=lwz -DOFF=8
9+
710
;;;; section __ifunc_sec holding the [foo:foo_resolver] pairs
811
; COMMON: .csect __ifunc_sec[RW],2
912
; COMMON-NEXT: .align [[ALIGN]]
@@ -46,10 +49,18 @@
4649
; COMMON-NEXT: mtctr 12
4750
; COMMON-NEXT: bctr
4851

52+
; -mcmodel=large:
53+
; LARGE: .csect .foo[PR],5
54+
; LARGE: addis 12, [[FOO_TOC:.*]]@u(2)
55+
; LARGE-NEXT: [[LOAD]] 12, [[FOO_TOC]]@l(12)
56+
; LARGE-NEXT: [[LOAD]] 11, [[OFF]](12)
57+
; LARGE-NEXT: [[LOAD]] 12, 0(12)
58+
4959
;;;; foo's TOC entry
5060
; COMMON: [[FOO_TOC]]:
5161
; COMMON-NEXT: .tc foo[TC],foo[DS]
52-
62+
; LARGE: [[FOO_TOC]]:
63+
; LARGE-NEXT: .tc foo[TE],foo[DS]
5364

5465
@foo = ifunc i32 (...), ptr @foo.resolver
5566

0 commit comments

Comments
 (0)