Skip to content

Commit

Permalink
Target option DisableJumpTables is a gross hack. Move it to TargetLow…
Browse files Browse the repository at this point in the history
…ering instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159611 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Evan Cheng committed Jul 2, 2012
1 parent 1b055ce commit 769951f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 29 deletions.
16 changes: 16 additions & 0 deletions include/llvm/Target/TargetLowering.h
Expand Up @@ -677,6 +677,12 @@ class TargetLowering {
return UseUnderscoreLongJmp; return UseUnderscoreLongJmp;
} }


/// supportJumpTables - return whether the target can generate code for
/// jump tables.
bool supportJumpTables() const {
return SupportJumpTables;
}

/// getStackPointerRegisterToSaveRestore - If a physical register, this /// getStackPointerRegisterToSaveRestore - If a physical register, this
/// specifies the register that llvm.savestack/llvm.restorestack should save /// specifies the register that llvm.savestack/llvm.restorestack should save
/// and restore. /// and restore.
Expand Down Expand Up @@ -991,6 +997,12 @@ class TargetLowering {
UseUnderscoreLongJmp = Val; UseUnderscoreLongJmp = Val;
} }


/// setSupportJumpTables - Indicate whether the target can generate code for
/// jump tables.
void setSupportJumpTables(bool Val) {
SupportJumpTables = Val;
}

/// setStackPointerRegisterToSaveRestore - If set to a physical register, this /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
/// specifies the register that llvm.savestack/llvm.restorestack should save /// specifies the register that llvm.savestack/llvm.restorestack should save
/// and restore. /// and restore.
Expand Down Expand Up @@ -1764,6 +1776,10 @@ class TargetLowering {
/// llvm.longjmp. Defaults to false. /// llvm.longjmp. Defaults to false.
bool UseUnderscoreLongJmp; bool UseUnderscoreLongJmp;


/// SupportJumpTables - Whether the target can generate code for jumptables.
/// If it's not true, then each jumptable must be lowered into if-then-else's.
bool SupportJumpTables;

/// BooleanContents - Information about the contents of the high-bits in /// BooleanContents - Information about the contents of the high-bits in
/// boolean values held in a type wider than i1. See getBooleanContents. /// boolean values held in a type wider than i1. See getBooleanContents.
BooleanContent BooleanContents; BooleanContent BooleanContents;
Expand Down
7 changes: 1 addition & 6 deletions include/llvm/Target/TargetOptions.h
Expand Up @@ -48,8 +48,7 @@ namespace llvm {
UseSoftFloat(false), NoZerosInBSS(false), JITExceptionHandling(false), UseSoftFloat(false), NoZerosInBSS(false), JITExceptionHandling(false),
JITEmitDebugInfo(false), JITEmitDebugInfoToDisk(false), JITEmitDebugInfo(false), JITEmitDebugInfoToDisk(false),
GuaranteedTailCallOpt(false), DisableTailCalls(false), GuaranteedTailCallOpt(false), DisableTailCalls(false),
StackAlignmentOverride(0), RealignStack(true), StackAlignmentOverride(0), RealignStack(true), EnableFastISel(false),
DisableJumpTables(false), EnableFastISel(false),
PositionIndependentExecutable(false), EnableSegmentedStacks(false), PositionIndependentExecutable(false), EnableSegmentedStacks(false),
UseInitArray(false), TrapFuncName(""), FloatABIType(FloatABI::Default), UseInitArray(false), TrapFuncName(""), FloatABIType(FloatABI::Default),
AllowFPOpFusion(FPOpFusion::Standard) AllowFPOpFusion(FPOpFusion::Standard)
Expand Down Expand Up @@ -156,10 +155,6 @@ namespace llvm {
/// automatically realigned, if needed. /// automatically realigned, if needed.
unsigned RealignStack : 1; unsigned RealignStack : 1;


/// DisableJumpTables - This flag indicates jump tables should not be
/// generated.
unsigned DisableJumpTables : 1;

/// EnableFastISel - This flag enables fast-path instruction selection /// EnableFastISel - This flag enables fast-path instruction selection
/// which trades away generated code quality in favor of reducing /// which trades away generated code quality in favor of reducing
/// compile time. /// compile time.
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Expand Up @@ -2052,7 +2052,7 @@ bool SelectionDAGBuilder::handleSmallSwitchRange(CaseRec& CR,
} }


static inline bool areJTsAllowed(const TargetLowering &TLI) { static inline bool areJTsAllowed(const TargetLowering &TLI) {
return !TLI.getTargetMachine().Options.DisableJumpTables && return TLI.supportJumpTables() &&
(TLI.isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) || (TLI.isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
TLI.isOperationLegalOrCustom(ISD::BRIND, MVT::Other)); TLI.isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
} }
Expand Down
1 change: 1 addition & 0 deletions lib/CodeGen/SelectionDAG/TargetLowering.cpp
Expand Up @@ -612,6 +612,7 @@ TargetLowering::TargetLowering(const TargetMachine &tm,
MinStackArgumentAlignment = 1; MinStackArgumentAlignment = 1;
ShouldFoldAtomicFences = false; ShouldFoldAtomicFences = false;
InsertFencesForAtomic = false; InsertFencesForAtomic = false;
SupportJumpTables = true;


InitLibcallNames(LibcallRoutineNames); InitLibcallNames(LibcallRoutineNames);
InitCmpLibcallCCs(CmpLibcallCCs); InitCmpLibcallCCs(CmpLibcallCCs);
Expand Down
27 changes: 17 additions & 10 deletions lib/Target/PowerPC/PPCISelLowering.cpp
Expand Up @@ -66,6 +66,7 @@ static TargetLoweringObjectFile *CreateTLOF(const PPCTargetMachine &TM) {


PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM) PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
: TargetLowering(TM, CreateTLOF(TM)), PPCSubTarget(*TM.getSubtargetImpl()) { : TargetLowering(TM, CreateTLOF(TM)), PPCSubTarget(*TM.getSubtargetImpl()) {
const PPCSubtarget *Subtarget = &TM.getSubtarget<PPCSubtarget>();


setPow2DivIsCheap(); setPow2DivIsCheap();


Expand All @@ -75,7 +76,8 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)


// On PPC32/64, arguments smaller than 4/8 bytes are extended, so all // On PPC32/64, arguments smaller than 4/8 bytes are extended, so all
// arguments are at least 4/8 bytes aligned. // arguments are at least 4/8 bytes aligned.
setMinStackArgumentAlignment(TM.getSubtarget<PPCSubtarget>().isPPC64() ? 8:4); bool isPPC64 = Subtarget->isPPC64();
setMinStackArgumentAlignment(isPPC64 ? 8:4);


// Set up the register classes. // Set up the register classes.
addRegisterClass(MVT::i32, &PPC::GPRCRegClass); addRegisterClass(MVT::i32, &PPC::GPRCRegClass);
Expand Down Expand Up @@ -142,7 +144,7 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom);


// If we're enabling GP optimizations, use hardware square root // If we're enabling GP optimizations, use hardware square root
if (!TM.getSubtarget<PPCSubtarget>().hasFSQRT()) { if (!Subtarget->hasFSQRT()) {
setOperationAction(ISD::FSQRT, MVT::f64, Expand); setOperationAction(ISD::FSQRT, MVT::f64, Expand);
setOperationAction(ISD::FSQRT, MVT::f32, Expand); setOperationAction(ISD::FSQRT, MVT::f32, Expand);
} }
Expand Down Expand Up @@ -228,8 +230,8 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
// VASTART needs to be custom lowered to use the VarArgsFrameIndex // VASTART needs to be custom lowered to use the VarArgsFrameIndex
setOperationAction(ISD::VASTART , MVT::Other, Custom); setOperationAction(ISD::VASTART , MVT::Other, Custom);


if (TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) { if (Subtarget->isSVR4ABI()) {
if (TM.getSubtarget<PPCSubtarget>().isPPC64()) { if (isPPC64) {
// VAARG always uses double-word chunks, so promote anything smaller. // VAARG always uses double-word chunks, so promote anything smaller.
setOperationAction(ISD::VAARG, MVT::i1, Promote); setOperationAction(ISD::VAARG, MVT::i1, Promote);
AddPromotedToType (ISD::VAARG, MVT::i1, MVT::i64); AddPromotedToType (ISD::VAARG, MVT::i1, MVT::i64);
Expand Down Expand Up @@ -273,7 +275,7 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
setCondCodeAction(ISD::SETONE, MVT::f32, Expand); setCondCodeAction(ISD::SETONE, MVT::f32, Expand);
setCondCodeAction(ISD::SETONE, MVT::f64, Expand); setCondCodeAction(ISD::SETONE, MVT::f64, Expand);


if (TM.getSubtarget<PPCSubtarget>().has64BitSupport()) { if (Subtarget->has64BitSupport()) {
// They also have instructions for converting between i64 and fp. // They also have instructions for converting between i64 and fp.
setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand); setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
Expand All @@ -292,7 +294,7 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand);
} }


if (TM.getSubtarget<PPCSubtarget>().use64BitRegs()) { if (Subtarget->use64BitRegs()) {
// 64-bit PowerPC implementations can support i64 types directly // 64-bit PowerPC implementations can support i64 types directly
addRegisterClass(MVT::i64, &PPC::G8RCRegClass); addRegisterClass(MVT::i64, &PPC::G8RCRegClass);
// BUILD_PAIR can't be handled natively, and should be expanded to shl/or // BUILD_PAIR can't be handled natively, and should be expanded to shl/or
Expand All @@ -308,7 +310,7 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom);
} }


if (TM.getSubtarget<PPCSubtarget>().hasAltivec()) { if (Subtarget->hasAltivec()) {
// First set operation action for all vector types to expand. Then we // First set operation action for all vector types to expand. Then we
// will selectively turn on ones that can be effectively codegen'd. // will selectively turn on ones that can be effectively codegen'd.
for (unsigned i = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; for (unsigned i = (unsigned)MVT::FIRST_VECTOR_VALUETYPE;
Expand Down Expand Up @@ -392,7 +394,7 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom); setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom);
} }


if (TM.getSubtarget<PPCSubtarget>().has64BitSupport()) if (Subtarget->has64BitSupport())
setOperationAction(ISD::PREFETCH, MVT::Other, Legal); setOperationAction(ISD::PREFETCH, MVT::Other, Legal);


setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Expand); setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Expand);
Expand All @@ -401,7 +403,7 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
setBooleanContents(ZeroOrOneBooleanContent); setBooleanContents(ZeroOrOneBooleanContent);
setBooleanVectorContents(ZeroOrOneBooleanContent); // FIXME: Is this correct? setBooleanVectorContents(ZeroOrOneBooleanContent); // FIXME: Is this correct?


if (TM.getSubtarget<PPCSubtarget>().isPPC64()) { if (isPPC64) {
setStackPointerRegisterToSaveRestore(PPC::X1); setStackPointerRegisterToSaveRestore(PPC::X1);
setExceptionPointerRegister(PPC::X3); setExceptionPointerRegister(PPC::X3);
setExceptionSelectorRegister(PPC::X4); setExceptionSelectorRegister(PPC::X4);
Expand All @@ -418,7 +420,7 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
setTargetDAGCombine(ISD::BSWAP); setTargetDAGCombine(ISD::BSWAP);


// Darwin long double math library functions have $LDBL128 appended. // Darwin long double math library functions have $LDBL128 appended.
if (TM.getSubtarget<PPCSubtarget>().isDarwin()) { if (Subtarget->isDarwin()) {
setLibcallName(RTLIB::COS_PPCF128, "cosl$LDBL128"); setLibcallName(RTLIB::COS_PPCF128, "cosl$LDBL128");
setLibcallName(RTLIB::POW_PPCF128, "powl$LDBL128"); setLibcallName(RTLIB::POW_PPCF128, "powl$LDBL128");
setLibcallName(RTLIB::REM_PPCF128, "fmodl$LDBL128"); setLibcallName(RTLIB::REM_PPCF128, "fmodl$LDBL128");
Expand All @@ -435,6 +437,11 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM)
if (PPCSubTarget.isDarwin()) if (PPCSubTarget.isDarwin())
setPrefFunctionAlignment(4); setPrefFunctionAlignment(4);


if (isPPC64 && Subtarget->isJITCodeModel())
// Temporary workaround for the inability of PPC64 JIT to handle jump
// tables.
setSupportJumpTables(false);

setInsertFencesForAtomic(true); setInsertFencesForAtomic(true);


setSchedulingPreference(Sched::Hybrid); setSchedulingPreference(Sched::Hybrid);
Expand Down
6 changes: 0 additions & 6 deletions lib/Target/PowerPC/PPCTargetMachine.cpp
Expand Up @@ -117,12 +117,6 @@ bool PPCPassConfig::addPreEmitPass() {


bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
JITCodeEmitter &JCE) { JITCodeEmitter &JCE) {
// FIXME: This should be moved to TargetJITInfo!!
if (Subtarget.isPPC64())
// Temporary workaround for the inability of PPC64 JIT to handle jump
// tables.
Options.DisableJumpTables = true;

// Inform the subtarget that we are in JIT mode. FIXME: does this break macho // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
// writing? // writing?
Subtarget.SetJITMode(); Subtarget.SetJITMode();
Expand Down
6 changes: 0 additions & 6 deletions tools/llc/llc.cpp
Expand Up @@ -233,11 +233,6 @@ EnableRealignStack("realign-stack",
cl::desc("Realign stack if needed"), cl::desc("Realign stack if needed"),
cl::init(true)); cl::init(true));


static cl::opt<bool>
DisableSwitchTables(cl::Hidden, "disable-jump-tables",
cl::desc("Do not generate jump tables."),
cl::init(false));

static cl::opt<std::string> static cl::opt<std::string>
TrapFuncName("trap-func", cl::Hidden, TrapFuncName("trap-func", cl::Hidden,
cl::desc("Emit a call to trap function rather than a trap instruction"), cl::desc("Emit a call to trap function rather than a trap instruction"),
Expand Down Expand Up @@ -454,7 +449,6 @@ int main(int argc, char **argv) {
Options.DisableTailCalls = DisableTailCalls; Options.DisableTailCalls = DisableTailCalls;
Options.StackAlignmentOverride = OverrideStackAlignment; Options.StackAlignmentOverride = OverrideStackAlignment;
Options.RealignStack = EnableRealignStack; Options.RealignStack = EnableRealignStack;
Options.DisableJumpTables = DisableSwitchTables;
Options.TrapFuncName = TrapFuncName; Options.TrapFuncName = TrapFuncName;
Options.PositionIndependentExecutable = EnablePIE; Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks; Options.EnableSegmentedStacks = SegmentedStacks;
Expand Down

0 comments on commit 769951f

Please sign in to comment.