Skip to content

Commit

Permalink
Manually merged master:9868ea764f31 into amd-gfx:3e9081ae5006
Browse files Browse the repository at this point in the history
Local branch amd-gfx 3e9081a Merged master:412b417bfa79 into amd-gfx:ea7744e97a5c
Remote branch master 9868ea7 [XCOFF][AIX] Handle TOC entries that could not be reached by positive range in small code model

Change-Id: I49fe256025d290fa21c02c4d14384c24f4ae174c
  • Loading branch information
perlfu committed Sep 15, 2020
2 parents 3e9081a + 9868ea7 commit 6277d98
Show file tree
Hide file tree
Showing 39 changed files with 1,979 additions and 2,189 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5476,9 +5476,9 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
bool UseNegInf = IID == Intrinsic::minnum || IID == Intrinsic::minimum;
const APFloat *C;
if ((match(Op0, m_APFloat(C)) && C->isInfinity() &&
C->isNegative() == UseNegInf) ||
C->isNegative() == UseNegInf && !PropagateNaN) ||
(match(Op1, m_APFloat(C)) && C->isInfinity() &&
C->isNegative() == UseNegInf))
C->isNegative() == UseNegInf && !PropagateNaN))
return ConstantFP::getInfinity(ReturnType, UseNegInf);

// TODO: minnum(nnan x, inf) -> x
Expand Down
16 changes: 9 additions & 7 deletions llvm/lib/MC/XCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace {

constexpr unsigned DefaultSectionAlign = 4;
constexpr int16_t MaxSectionIndex = INT16_MAX;
constexpr uint16_t MaxTOCSizeInARegion = UINT16_MAX;

// Packs the csect's alignment and type into a byte.
uint8_t getEncodedType(const MCSectionXCOFF *);
Expand Down Expand Up @@ -431,12 +430,15 @@ void XCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
FixedValue = getVirtualAddress(SymA, SymASec) + Target.getConstant();
else if (Type == XCOFF::RelocationType::R_TOC ||
Type == XCOFF::RelocationType::R_TOCL) {
// The FixedValue should be the TC entry offset from TOC-base.
FixedValue = SectionMap[SymASec]->Address - TOCCsects.front().Address;
if (FixedValue >= MaxTOCSizeInARegion)
report_fatal_error(
"handling of TOC entries could not fit in the initial TOC "
"entry region is not yet supported");
// The FixedValue should be the TOC entry offset from the TOC-base plus any
// constant offset value.
const int64_t TOCEntryOffset = SectionMap[SymASec]->Address -
TOCCsects.front().Address +
Target.getConstant();
if (Type == XCOFF::RelocationType::R_TOC && !isInt<16>(TOCEntryOffset))
report_fatal_error("TOCEntryOffset overflows in small code model mode");

FixedValue = TOCEntryOffset;
}

assert(
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ createGCNMaxOccupancyMachineScheduler(MachineSchedContext *C) {
ScheduleDAGMILive *DAG =
new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
return DAG;
Expand All @@ -299,7 +298,6 @@ createIterativeGCNMaxOccupancyMachineScheduler(MachineSchedContext *C) {
auto DAG = new GCNIterativeScheduler(C,
GCNIterativeScheduler::SCHEDULE_LEGACYMAXOCCUPANCY);
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
return DAG;
}

Expand All @@ -313,7 +311,6 @@ createIterativeILPMachineScheduler(MachineSchedContext *C) {
auto DAG = new GCNIterativeScheduler(C,
GCNIterativeScheduler::SCHEDULE_ILP);
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
return DAG;
}
Expand Down Expand Up @@ -609,7 +606,6 @@ class AMDGPUPassConfig : public TargetPassConfig {
createMachineScheduler(MachineSchedContext *C) const override {
ScheduleDAGMILive *DAG = createGenericSchedLive(C);
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
return DAG;
}

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/ARM/MVEGatherScatterLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ static Value *CheckAndCreateOffsetAdd(Value *X, Value *Y, Value *GEP,
FixSummands(YElType, X);
XElType = cast<FixedVectorType>(X->getType());
}
assert(XElType && YElType && "Unknown vector types");
// Check that the summands are of compatible types
if (XElType != YElType) {
LLVM_DEBUG(dbgs() << "masked gathers/scatters: incompatible gep offsets\n");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AVR/AsmParser/AVRAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ class AVROperand : public MCParsedAsmOperand {
assert(N == 1 && "Invalid number of operands!");
// The operand is actually a imm8, but we have its bitwise
// negation in the assembly source, so twiddle it here.
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
const auto *CE = cast<MCConstantExpr>(getImm());
Inst.addOperand(MCOperand::createImm(~(uint8_t)CE->getValue()));
}

bool isImmCom8() const {
if (!isImm()) return false;
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
const auto *CE = dyn_cast<MCConstantExpr>(getImm());
if (!CE) return false;
int64_t Value = CE->getValue();
return isUInt<8>(Value);
Expand Down
52 changes: 39 additions & 13 deletions llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,38 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
}
}
#endif

auto getTOCRelocAdjustedExprForXCOFF = [this](const MCExpr *Expr,
ptrdiff_t OriginalOffset) {
// Apply an offset to the TOC-based expression such that the adjusted
// notional offset from the TOC base (to be encoded into the instruction's D
// or DS field) is the signed 16-bit truncation of the original notional
// offset from the TOC base.
// This is consistent with the treatment used both by XL C/C++ and
// by AIX ld -r.
ptrdiff_t Adjustment =
OriginalOffset - llvm::SignExtend32<16>(OriginalOffset);
return MCBinaryExpr::createAdd(
Expr, MCConstantExpr::create(-Adjustment, OutContext), OutContext);
};

auto getTOCEntryLoadingExprForXCOFF =
[IsPPC64, getTOCRelocAdjustedExprForXCOFF,
this](const MCSymbol *MOSymbol, const MCExpr *Expr) -> const MCExpr * {
const unsigned EntryByteSize = IsPPC64 ? 8 : 4;
const auto TOCEntryIter = TOC.find(MOSymbol);
assert(TOCEntryIter != TOC.end() &&
"Could not find the TOC entry for this symbol.");
const ptrdiff_t EntryDistanceFromTOCBase =
(TOCEntryIter - TOC.begin()) * EntryByteSize;
constexpr int16_t PositiveTOCRange = INT16_MAX;

if (EntryDistanceFromTOCBase > PositiveTOCRange)
return getTOCRelocAdjustedExprForXCOFF(Expr, EntryDistanceFromTOCBase);

return Expr;
};

// Lower multi-instruction pseudo operations.
switch (MI->getOpcode()) {
default: break;
Expand Down Expand Up @@ -725,6 +757,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
assert(
TM.getCodeModel() == CodeModel::Small &&
"This pseudo should only be selected for 32-bit small code model.");
Exp = getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp);
TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
EmitToStreamer(*OutStreamer, TmpInst);
return;
Expand Down Expand Up @@ -753,17 +786,20 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isBlockAddress()) &&
"Invalid operand!");

// Map the operand to its corresponding MCSymbol.
const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);

// Map the machine operand to its corresponding MCSymbol, then map the
// global address operand to be a reference to the TOC entry we will
// synthesize later.
MCSymbol *TOCEntry =
lookUpOrCreateTOCEntry(getMCSymbolForTOCPseudoMO(MO, *this));
MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(MOSymbol);

const MCSymbolRefExpr::VariantKind VK =
IsAIX ? MCSymbolRefExpr::VK_None : MCSymbolRefExpr::VK_PPC_TOC;
const MCExpr *Exp =
MCSymbolRefExpr::create(TOCEntry, VK, OutContext);
TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
TmpInst.getOperand(1) = MCOperand::createExpr(
IsAIX ? getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp) : Exp);
EmitToStreamer(*OutStreamer, TmpInst);
return;
}
Expand Down Expand Up @@ -1821,16 +1857,6 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
PPCTargetStreamer *TS =
static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());

const unsigned EntryByteSize = Subtarget->isPPC64() ? 8 : 4;
const unsigned TOCEntriesByteSize = TOC.size() * EntryByteSize;
// TODO: If TOC entries' size is larger than 32768, then we run out of
// positive displacement to reach the TOC entry. We need to decide how to
// handle entries' size larger than that later.
if (TOCEntriesByteSize > 32767) {
report_fatal_error("Handling of TOC entry displacement larger than 32767 "
"is not yet implemented.");
}

for (auto &I : TOC) {
// Setup the csect for the current TC entry.
MCSectionXCOFF *TCEntry = cast<MCSectionXCOFF>(
Expand Down
Loading

0 comments on commit 6277d98

Please sign in to comment.