[Hexagon] Make sure not to use GP-relative addressing with PIC

Make sure that -relocation-model=pic prevents use of GP-relative
addressing modes.

llvm-svn: 345731
This commit is contained in:
Krzysztof Parzyszek 2018-10-31 15:54:31 +00:00
parent 52578ac67c
commit 977a1fe507
4 changed files with 47 additions and 4 deletions

View File

@ -63,7 +63,7 @@ bool HexagonSplitConst32AndConst64::runOnMachineFunction(MachineFunction &Fn) {
auto &HST = Fn.getSubtarget<HexagonSubtarget>();
auto &HTM = static_cast<const HexagonTargetMachine&>(Fn.getTarget());
auto &TLOF = *HTM.getObjFileLowering();
if (HST.useSmallData() && TLOF.isSmallDataEnabled())
if (HST.useSmallData() && TLOF.isSmallDataEnabled(HTM))
return false;
const TargetInstrInfo *TII = HST.getInstrInfo();

View File

@ -199,6 +199,11 @@ MCSection *HexagonTargetObjectFile::getExplicitSectionGlobal(
/// section.
bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO,
const TargetMachine &TM) const {
if (!isSmallDataEnabled(TM)) {
LLVM_DEBUG(dbgs() << "Small data is not available.\n");
return false;
}
// Only global variables, not functions.
LLVM_DEBUG(dbgs() << "Checking if value is in small-data, -G"
<< SmallDataThreshold << ": \"" << GO->getName() << "\": ");
@ -263,8 +268,9 @@ bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO,
return true;
}
bool HexagonTargetObjectFile::isSmallDataEnabled() const {
return SmallDataThreshold > 0;
bool HexagonTargetObjectFile::isSmallDataEnabled(const TargetMachine &TM)
const {
return SmallDataThreshold > 0 && !TM.isPositionIndependent();
}
unsigned HexagonTargetObjectFile::getSmallDataSize() const {

View File

@ -29,7 +29,7 @@ namespace llvm {
bool isGlobalInSmallSection(const GlobalObject *GO,
const TargetMachine &TM) const;
bool isSmallDataEnabled() const;
bool isSmallDataEnabled(const TargetMachine &TM) const;
unsigned getSmallDataSize() const;

View File

@ -0,0 +1,37 @@
; RUN: llc -march=hexagon -hexagon-small-data-threshold=8 -relocation-model=static < %s | FileCheck --check-prefixes=CHECK,STATIC %s
; RUN: llc -march=hexagon -hexagon-small-data-threshold=8 -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s
; If a global has a specified section, it should probably be placed in that
; section, but with PIC any accesses to globals in small data should still
; go through GOT.
@g0 = global i32 zeroinitializer
@g1 = global i32 zeroinitializer, section ".sdata"
; CHECK-LABEL: f0:
; STATIC: memw(gp+#g0)
; PIC: r[[R0:[0-9]+]] = add(pc,##_GLOBAL_OFFSET_TABLE_@PCREL)
; PIC: = memw(r[[R0]]+##g0@GOT)
define i32 @f0() #0 {
%v0 = load i32, i32* @g0
ret i32 %v0
}
; CHECK-LABEL: f1:
; STATIC: memw(gp+#g1)
; PIC: r[[R1:[0-9]+]] = add(pc,##_GLOBAL_OFFSET_TABLE_@PCREL)
; PIC: = memw(r[[R1]]+##g1@GOT)
define i32 @f1() #0 {
%v0 = load i32, i32* @g1
ret i32 %v0
}
; CHECK-LABEL: f2:
; STATIC: CONST64(#123456789012345678)
; PIC: r0 = ##-1506741426
; PIC: r1 = ##28744523
define i64 @f2() #0 {
ret i64 123456789012345678
}
attributes #0 = { nounwind "target-cpu"="hexagonv60" }