llvm.org GIT mirror llvm / 2119513
Merging rr220959: ------------------------------------------------------------------------ r220959 | uweigand | 2014-10-31 10:33:14 +0000 (Fri, 31 Oct 2014) | 13 lines [PowerPC] Load BlockAddress values from the TOC in 64-bit SVR4 code Since block address values can be larger than 2GB in 64-bit code, they cannot be loaded simply using an @l / @ha pair, but instead must be loaded from the TOC, just like GlobalAddress, ConstantPool, and JumpTable values are. The commit also fixes a bug in PPCLinuxAsmPrinter::doFinalization where temporary labels could not be used as TOC values, since code would attempt (and fail) to use GetOrCreateSymbol to create a symbol of the same name as the temporary label. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_35@223741 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 5 years ago
5 changed file(s) with 64 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
372372 const MachineOperand &MO = MI->getOperand(1);
373373
374374 // Map symbol -> label of TOC entry
375 assert(MO.isGlobal() || MO.isCPI() || MO.isJTI());
375 assert(MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isBlockAddress());
376376 MCSymbol *MOSymbol = nullptr;
377377 if (MO.isGlobal())
378378 MOSymbol = getSymbol(MO.getGlobal());
380380 MOSymbol = GetCPISymbol(MO.getIndex());
381381 else if (MO.isJTI())
382382 MOSymbol = GetJTISymbol(MO.getIndex());
383 else if (MO.isBlockAddress())
384 MOSymbol = GetBlockAddressSymbol(MO.getBlockAddress());
383385
384386 MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(MOSymbol);
385387
396398 }
397399 case PPC::LDtocJTI:
398400 case PPC::LDtocCPT:
401 case PPC::LDtocBA:
399402 case PPC::LDtoc: {
400403 // Transform %X3 = LDtoc , %X2
401404 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this, Subtarget.isDarwin());
406409 const MachineOperand &MO = MI->getOperand(1);
407410
408411 // Map symbol -> label of TOC entry
409 assert(MO.isGlobal() || MO.isCPI() || MO.isJTI());
412 assert(MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isBlockAddress());
410413 MCSymbol *MOSymbol = nullptr;
411414 if (MO.isGlobal())
412415 MOSymbol = getSymbol(MO.getGlobal());
414417 MOSymbol = GetCPISymbol(MO.getIndex());
415418 else if (MO.isJTI())
416419 MOSymbol = GetJTISymbol(MO.getIndex());
420 else if (MO.isBlockAddress())
421 MOSymbol = GetBlockAddressSymbol(MO.getBlockAddress());
417422
418423 MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(MOSymbol);
419424
435440 // reference the symbol directly.
436441 TmpInst.setOpcode(PPC::ADDIS8);
437442 const MachineOperand &MO = MI->getOperand(2);
438 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI()) &&
443 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() ||
444 MO.isBlockAddress()) &&
439445 "Invalid operand for ADDIStocHA!");
440446 MCSymbol *MOSymbol = nullptr;
441447 bool IsExternal = false;
455461 MOSymbol = GetCPISymbol(MO.getIndex());
456462 else if (MO.isJTI())
457463 MOSymbol = GetJTISymbol(MO.getIndex());
464 else if (MO.isBlockAddress())
465 MOSymbol = GetBlockAddressSymbol(MO.getBlockAddress());
458466
459467 if (IsExternal || IsNonLocalFunction || IsCommon || IsAvailExt ||
460 MO.isJTI() || TM.getCodeModel() == CodeModel::Large)
468 MO.isJTI() || MO.isBlockAddress() ||
469 TM.getCodeModel() == CodeModel::Large)
461470 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol);
462471
463472 const MCExpr *Exp =
476485 // associated TOC entry. Otherwise reference the symbol directly.
477486 TmpInst.setOpcode(PPC::LD);
478487 const MachineOperand &MO = MI->getOperand(1);
479 assert((MO.isGlobal() || MO.isJTI() || MO.isCPI()) &&
488 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() ||
489 MO.isBlockAddress()) &&
480490 "Invalid operand for LDtocL!");
481491 MCSymbol *MOSymbol = nullptr;
482492
483493 if (MO.isJTI())
484494 MOSymbol = lookUpOrCreateTOCEntry(GetJTISymbol(MO.getIndex()));
495 else if (MO.isBlockAddress()) {
496 MOSymbol = GetBlockAddressSymbol(MO.getBlockAddress());
497 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol);
498 }
485499 else if (MO.isCPI()) {
486500 MOSymbol = GetCPISymbol(MO.getIndex());
487501 if (TM.getCodeModel() == CodeModel::Large)
965979 for (MapVector::iterator I = TOC.begin(),
966980 E = TOC.end(); I != E; ++I) {
967981 OutStreamer.EmitLabel(I->second);
968 MCSymbol *S = OutContext.GetOrCreateSymbol(I->first->getName());
982 MCSymbol *S = I->first;
969983 if (isPPC64)
970984 TS.emitTCEntry(*S);
971985 else
14381438
14391439 // For medium and large code model, we generate two instructions as
14401440 // described below. Otherwise we allow SelectCodeCommon to handle this,
1441 // selecting one of LDtoc, LDtocJTI, and LDtocCPT.
1441 // selecting one of LDtoc, LDtocJTI, LDtocCPT, and LDtocBA.
14421442 CodeModel::Model CModel = TM.getCodeModel();
14431443 if (CModel != CodeModel::Medium && CModel != CodeModel::Large)
14441444 break;
14551455 SDNode *Tmp = CurDAG->getMachineNode(PPC::ADDIStocHA, dl, MVT::i64,
14561456 TOCbase, GA);
14571457
1458 if (isa(GA) || CModel == CodeModel::Large)
1458 if (isa(GA) || isa(GA) ||
1459 CModel == CodeModel::Large)
14591460 return CurDAG->getMachineNode(PPC::LDtocL, dl, MVT::i64, GA,
14601461 SDValue(Tmp, 0));
14611462
16301630 SDValue PPCTargetLowering::LowerBlockAddress(SDValue Op,
16311631 SelectionDAG &DAG) const {
16321632 EVT PtrVT = Op.getValueType();
1633
1634 const BlockAddress *BA = cast(Op)->getBlockAddress();
1633 BlockAddressSDNode *BASDN = cast(Op);
1634 const BlockAddress *BA = BASDN->getBlockAddress();
1635
1636 // 64-bit SVR4 ABI code is always position-independent.
1637 // The actual BlockAddress is stored in the TOC.
1638 if (Subtarget.isSVR4ABI() && Subtarget.isPPC64()) {
1639 SDValue GA = DAG.getTargetBlockAddress(BA, PtrVT, BASDN->getOffset());
1640 return DAG.getNode(PPCISD::TOC_ENTRY, SDLoc(BASDN), MVT::i64, GA,
1641 DAG.getRegister(PPC::X2, MVT::i64));
1642 }
16351643
16361644 unsigned MOHiFlag, MOLoFlag;
16371645 bool isPIC = GetLabelAccessInfo(DAG.getTarget(), MOHiFlag, MOLoFlag);
785785 def LD : DSForm_1<58, 0, (outs g8rc:$rD), (ins memrix:$src),
786786 "ld $rD, $src", IIC_LdStLD,
787787 [(set i64:$rD, (aligned4load ixaddr:$src))]>, isPPC64;
788 // The following three definitions are selected for small code model only.
788 // The following four definitions are selected for small code model only.
789789 // Otherwise, we need to create two instructions to form a 32-bit offset,
790790 // so we have a custom matcher for TOC_ENTRY in PPCDAGToDAGIsel::Select().
791791 def LDtoc: Pseudo<(outs g8rc:$rD), (ins tocentry:$disp, g8rc:$reg),
800800 "#LDtocCPT",
801801 [(set i64:$rD,
802802 (PPCtoc_entry tconstpool:$disp, i64:$reg))]>, isPPC64;
803 def LDtocBA: Pseudo<(outs g8rc:$rD), (ins tocentry:$disp, g8rc:$reg),
804 "#LDtocCPT",
805 [(set i64:$rD,
806 (PPCtoc_entry tblockaddress:$disp, i64:$reg))]>, isPPC64;
803807
804808 let hasSideEffects = 1, isCodeGenOnly = 1, RST = 2, Defs = [X2] in
805809 def LDinto_toc: DSForm_1<58, 0, (outs), (ins memrix:$src),
0 ; RUN: llc < %s -code-model=small -march=ppc64 -mtriple=powerpc64-unknown-linux-gnu | FileCheck %s -check-prefix=SMALL
1 ; RUN: llc < %s -code-model=medium -march=ppc64 -mtriple=powerpc64-unknown-linux-gnu | FileCheck %s -check-prefix=MEDIUM
2 ; RUN: llc < %s -code-model=large -march=ppc64 -mtriple=powerpc64-unknown-linux-gnu | FileCheck %s -check-prefix=MEDIUM
3 ; RUN: llc < %s -code-model=small -march=ppc64 -mtriple=powerpc64le-unknown-linux-gnu | FileCheck %s -check-prefix=SMALL
4 ; RUN: llc < %s -code-model=medium -march=ppc64 -mtriple=powerpc64le-unknown-linux-gnu | FileCheck %s -check-prefix=MEDIUM
5 ; RUN: llc < %s -code-model=large -march=ppc64 -mtriple=powerpc64le-unknown-linux-gnu | FileCheck %s -check-prefix=MEDIUM
6
7 define i8* @test() {
8 entry:
9 br label %here
10
11 here: ; preds = %entry
12 ; MEDIUM: .Ltmp[[TMP0:[0-9]+]]:
13 ; MEDIUM: addis [[R0:[0-9]+]], 2, .LC[[LC0:[0-9]+]]@toc@ha
14 ; MEDIUM: ld 3, .LC[[LC0]]@toc@l([[R0]])
15 ; MEDIUM: blr
16 ; MEDIUM: .LC[[LC0]]:
17 ; MEDIUM: .tc .Ltmp[[TMP0]][TC],.Ltmp[[TMP0]]
18 ; SMALL: .Ltmp[[TMP0:[0-9]+]]:
19 ; SMALL: ld 3, .LC[[LC0:[0-9]+]]@toc(2)
20 ; SMALL: blr
21 ; SMALL: .LC[[LC0]]:
22 ; SMALL: .tc .Ltmp[[TMP0]][TC],.Ltmp[[TMP0]]
23 ret i8* blockaddress(@test, %here)
24 }
25