mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-23 02:29:18 +00:00
XCore target: fix handling of unsized global arrays in large code model
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198609 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8e27a6b1d3
commit
e452d6e547
@ -268,6 +268,18 @@ getGlobalAddressWrapper(SDValue GA, const GlobalValue *GV,
|
||||
return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA);
|
||||
}
|
||||
|
||||
static bool IsSmallObject(const GlobalValue *GV, const XCoreTargetLowering &XTL) {
|
||||
if (XTL.getTargetMachine().getCodeModel() == CodeModel::Small)
|
||||
return true;
|
||||
|
||||
Type *ObjType = GV->getType()->getPointerElementType();
|
||||
if (!ObjType->isSized())
|
||||
return false;
|
||||
|
||||
unsigned ObjSize = XTL.getDataLayout()->getTypeAllocSize(ObjType);
|
||||
return ObjSize < CodeModelLargeSize && ObjSize != 0;
|
||||
}
|
||||
|
||||
SDValue XCoreTargetLowering::
|
||||
LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
|
||||
{
|
||||
@ -275,10 +287,7 @@ LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
|
||||
const GlobalValue *GV = GN->getGlobal();
|
||||
SDLoc DL(GN);
|
||||
int64_t Offset = GN->getOffset();
|
||||
Type *ObjType = GV->getType()->getPointerElementType();
|
||||
if (getTargetMachine().getCodeModel() == CodeModel::Small ||
|
||||
!ObjType->isSized() ||
|
||||
getDataLayout()->getTypeAllocSize(ObjType) < CodeModelLargeSize) {
|
||||
if (IsSmallObject(GV, *this)) {
|
||||
// We can only fold positive offsets that are a multiple of the word size.
|
||||
int64_t FoldedOffset = std::max(Offset & ~3, (int64_t)0);
|
||||
SDValue GA = DAG.getTargetGlobalAddress(GV, DL, MVT::i32, FoldedOffset);
|
||||
|
@ -35,6 +35,7 @@ entry:
|
||||
ret [50000 x i32]* %Addr
|
||||
}
|
||||
|
||||
|
||||
; CHECK: .section .cp.rodata.cst4,"aMc",@progbits,4
|
||||
; CHECK: .long 65536
|
||||
; CHECK: .text
|
||||
@ -115,6 +116,46 @@ entry:
|
||||
ret i32 %16
|
||||
}
|
||||
|
||||
|
||||
; CHECK-LABEL: UnknownSize:
|
||||
; CHECK: ldw r0, dp[NoSize+40]
|
||||
; CHECK-NEXT: retsp 0
|
||||
;
|
||||
; LARGE: .section .cp.rodata,"ac",@progbits
|
||||
; LARGE: .LCPI{{[0-9_]*}}
|
||||
; LARGE-NEXT: .long NoSize
|
||||
; LARGE-NEXT: .text
|
||||
; LARGE-LABEL: UnknownSize:
|
||||
; LARGE: ldw r0, cp[.LCPI{{[0-9_]*}}]
|
||||
; LARGE-NEXT: ldw r0, r0[0]
|
||||
; LARGE-NEXT: retsp 0
|
||||
@NoSize = external global [0 x i32]
|
||||
define i32 @UnknownSize() nounwind {
|
||||
entry:
|
||||
%0 = load i32* getelementptr inbounds ([0 x i32]* @NoSize, i32 0, i32 10)
|
||||
ret i32 %0
|
||||
}
|
||||
|
||||
|
||||
; CHECK-LABEL: UnknownStruct:
|
||||
; CHECK: ldaw r0, dp[Unknown]
|
||||
; CHECK-NEXT: retsp 0
|
||||
;
|
||||
; LARGE: .section .cp.rodata,"ac",@progbits
|
||||
; LARGE: .LCPI{{[0-9_]*}}
|
||||
; LARGE-NEXT: .long Unknown
|
||||
; LARGE-NEXT: .text
|
||||
; LARGE-LABEL: UnknownStruct:
|
||||
; LARGE: ldw r0, cp[.LCPI{{[0-9_]*}}]
|
||||
; LARGE-NEXT: retsp 0
|
||||
%Struct = type opaque
|
||||
@Unknown = external global %Struct
|
||||
define %Struct* @UnknownStruct() nounwind {
|
||||
entry:
|
||||
ret %Struct* @Unknown
|
||||
}
|
||||
|
||||
|
||||
; CHECK: .section .dp.bss,"awd",@nobits
|
||||
; CHECK-LABEL: l:
|
||||
; CHECK: .space 400
|
||||
|
Loading…
Reference in New Issue
Block a user