Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -352,6 +352,19 @@ MCContext &Context); }; +/// Helper method for getting the code model, returning Default if +/// CM does not have a value. +inline CodeModel::Model +getEffectiveCodeModel(Optional CM, + CodeModel::Model Default = CodeModel::Small) { + if (CM) { + if (*CM == CodeModel::Tiny) + report_fatal_error("Target does not support the Tiny CodeModel"); + return *CM; + } + return Default; +} + } // end namespace llvm #endif // LLVM_TARGET_TARGETMACHINE_H Index: lib/Target/AArch64/AArch64TargetMachine.cpp =================================================================== --- lib/Target/AArch64/AArch64TargetMachine.cpp +++ lib/Target/AArch64/AArch64TargetMachine.cpp @@ -206,9 +206,9 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(const Triple &TT, - Optional CM, - bool JIT) { +static CodeModel::Model +getEffectiveAArch64CodeModel(const Triple &TT, Optional CM, + bool JIT) { if (CM) { if (*CM != CodeModel::Small && *CM != CodeModel::Tiny && *CM != CodeModel::Large) { @@ -242,7 +242,7 @@ : LLVMTargetMachine(T, computeDataLayout(TT, Options.MCOptions, LittleEndian), TT, CPU, FS, Options, getEffectiveRelocModel(TT, RM), - getEffectiveCodeModel(TT, CM, JIT), OL), + getEffectiveAArch64CodeModel(TT, CM, JIT), OL), TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) { initAsmInfo(); Index: lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -292,12 +292,6 @@ return Reloc::PIC_; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - AMDGPUTargetMachine::AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, TargetOptions Options, Index: lib/Target/ARC/ARCTargetMachine.cpp =================================================================== --- lib/Target/ARC/ARCTargetMachine.cpp +++ lib/Target/ARC/ARCTargetMachine.cpp @@ -26,12 +26,6 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - /// ARCTargetMachine ctor - Create an ILP32 architecture model ARCTargetMachine::ARCTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, Index: lib/Target/ARM/ARMTargetMachine.cpp =================================================================== --- lib/Target/ARM/ARMTargetMachine.cpp +++ lib/Target/ARM/ARMTargetMachine.cpp @@ -194,12 +194,6 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - /// Create an ARM architecture model. /// ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, const Triple &TT, Index: lib/Target/AVR/AVRTargetMachine.cpp =================================================================== --- lib/Target/AVR/AVRTargetMachine.cpp +++ lib/Target/AVR/AVRTargetMachine.cpp @@ -40,12 +40,6 @@ return RM.hasValue() ? *RM : Reloc::Static; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - AVRTargetMachine::AVRTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Index: lib/Target/BPF/BPFTargetMachine.cpp =================================================================== --- lib/Target/BPF/BPFTargetMachine.cpp +++ lib/Target/BPF/BPFTargetMachine.cpp @@ -51,12 +51,6 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Index: lib/Target/Hexagon/HexagonTargetMachine.cpp =================================================================== --- lib/Target/Hexagon/HexagonTargetMachine.cpp +++ lib/Target/Hexagon/HexagonTargetMachine.cpp @@ -177,12 +177,6 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - extern "C" void LLVMInitializeHexagonTarget() { // Register the target. RegisterTargetMachine X(getTheHexagonTarget()); Index: lib/Target/Lanai/LanaiTargetMachine.cpp =================================================================== --- lib/Target/Lanai/LanaiTargetMachine.cpp +++ lib/Target/Lanai/LanaiTargetMachine.cpp @@ -53,12 +53,6 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Medium; -} - LanaiTargetMachine::LanaiTargetMachine(const Target &T, const Triple &TT, StringRef Cpu, StringRef FeatureString, const TargetOptions &Options, @@ -67,7 +61,8 @@ CodeGenOpt::Level OptLevel, bool JIT) : LLVMTargetMachine(T, computeDataLayout(), TT, Cpu, FeatureString, Options, getEffectiveRelocModel(RM), - getEffectiveCodeModel(CodeModel), OptLevel), + getEffectiveCodeModel(CodeModel, CodeModel::Medium), + OptLevel), Subtarget(TT, Cpu, FeatureString, *this, Options, getCodeModel(), OptLevel), TLOF(new LanaiTargetObjectFile()) { Index: lib/Target/MSP430/MSP430TargetMachine.cpp =================================================================== --- lib/Target/MSP430/MSP430TargetMachine.cpp +++ lib/Target/MSP430/MSP430TargetMachine.cpp @@ -32,12 +32,6 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - static std::string computeDataLayout(const Triple &TT, StringRef CPU, const TargetOptions &Options) { return "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"; Index: lib/Target/Mips/MipsTargetMachine.cpp =================================================================== --- lib/Target/Mips/MipsTargetMachine.cpp +++ lib/Target/Mips/MipsTargetMachine.cpp @@ -101,12 +101,6 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - // On function prologue, the stack is created by decrementing // its pointer. Once decremented, all references are done with positive // offset from the stack/frame pointer, using StackGrowsUp enables Index: lib/Target/NVPTX/NVPTXTargetMachine.cpp =================================================================== --- lib/Target/NVPTX/NVPTXTargetMachine.cpp +++ lib/Target/NVPTX/NVPTXTargetMachine.cpp @@ -102,12 +102,6 @@ return Ret; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - NVPTXTargetMachine::NVPTXTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Index: lib/Target/Nios2/Nios2TargetMachine.cpp =================================================================== --- lib/Target/Nios2/Nios2TargetMachine.cpp +++ lib/Target/Nios2/Nios2TargetMachine.cpp @@ -37,23 +37,15 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM, - Reloc::Model RM, bool JIT) { - if (CM) - return *CM; - return CodeModel::Small; -} - Nios2TargetMachine::Nios2TargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional RM, Optional CM, CodeGenOpt::Level OL, bool JIT) - : LLVMTargetMachine( - T, computeDataLayout(), TT, CPU, FS, Options, - getEffectiveRelocModel(RM), - getEffectiveCodeModel(CM, getEffectiveRelocModel(RM), JIT), OL), + : LLVMTargetMachine(T, computeDataLayout(), TT, CPU, FS, Options, + getEffectiveRelocModel(RM), getEffectiveCodeModel(CM), + OL), TLOF(make_unique()), Subtarget(TT, CPU, FS, *this) { initAsmInfo(); Index: lib/Target/PowerPC/PPCTargetMachine.cpp =================================================================== --- lib/Target/PowerPC/PPCTargetMachine.cpp +++ lib/Target/PowerPC/PPCTargetMachine.cpp @@ -219,11 +219,14 @@ return Reloc::Static; } -static CodeModel::Model getEffectiveCodeModel(const Triple &TT, - Optional CM, - bool JIT) { - if (CM) +static CodeModel::Model getEffectivePPCCodeModel(const Triple &TT, + Optional CM, + bool JIT) { + if (CM) { + if (*CM == CodeModel::Tiny) + report_fatal_error("Target does not support the Tiny CodeModel"); return *CM; + } if (!TT.isOSDarwin() && !JIT && (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le)) return CodeModel::Medium; @@ -243,7 +246,7 @@ : LLVMTargetMachine(T, getDataLayoutString(TT), TT, CPU, computeFSAdditions(FS, OL, TT), Options, getEffectiveRelocModel(TT, RM), - getEffectiveCodeModel(TT, CM, JIT), OL), + getEffectivePPCCodeModel(TT, CM, JIT), OL), TLOF(createTLOF(getTargetTriple())), TargetABI(computeTargetABI(TT, Options)) { initAsmInfo(); Index: lib/Target/RISCV/RISCVTargetMachine.cpp =================================================================== --- lib/Target/RISCV/RISCVTargetMachine.cpp +++ lib/Target/RISCV/RISCVTargetMachine.cpp @@ -45,12 +45,6 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { - if (CM) - return *CM; - return CodeModel::Small; -} - RISCVTargetMachine::RISCVTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Index: lib/Target/Sparc/SparcTargetMachine.cpp =================================================================== --- lib/Target/Sparc/SparcTargetMachine.cpp +++ lib/Target/Sparc/SparcTargetMachine.cpp @@ -70,11 +70,14 @@ // pic32 PIC_ Medium GOT < 2^32 bytes // // All code models require that the text segment is smaller than 2GB. -static CodeModel::Model getEffectiveCodeModel(Optional CM, - Reloc::Model RM, bool Is64Bit, - bool JIT) { - if (CM) +static CodeModel::Model +getEffectiveSparcCodeModel(Optional CM, Reloc::Model RM, + bool Is64Bit, bool JIT) { + if (CM) { + if (*CM == CodeModel::Tiny) + report_fatal_error("Target does not support the Tiny CodeModel"); return *CM; + } if (Is64Bit) { if (JIT) return CodeModel::Large; @@ -88,11 +91,11 @@ const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional RM, Optional CM, CodeGenOpt::Level OL, bool JIT, bool is64bit) - : LLVMTargetMachine( - T, computeDataLayout(TT, is64bit), TT, CPU, FS, Options, - getEffectiveRelocModel(RM), - getEffectiveCodeModel(CM, getEffectiveRelocModel(RM), is64bit, JIT), - OL), + : LLVMTargetMachine(T, computeDataLayout(TT, is64bit), TT, CPU, FS, Options, + getEffectiveRelocModel(RM), + getEffectiveSparcCodeModel( + CM, getEffectiveRelocModel(RM), is64bit, JIT), + OL), TLOF(make_unique()), Subtarget(TT, CPU, FS, *this, is64bit), is64Bit(is64bit) { initAsmInfo(); Index: lib/Target/SystemZ/SystemZTargetMachine.cpp =================================================================== --- lib/Target/SystemZ/SystemZTargetMachine.cpp +++ lib/Target/SystemZ/SystemZTargetMachine.cpp @@ -128,10 +128,14 @@ // in range of LARL. However, the JIT environment has no equivalent // of copy relocs, so locally-binding data symbols might not be in // the range of LARL. We need the Medium model in that case. -static CodeModel::Model getEffectiveCodeModel(Optional CM, - Reloc::Model RM, bool JIT) { - if (CM) +static CodeModel::Model +getEffectiveSystemZCodeModel(Optional CM, Reloc::Model RM, + bool JIT) { + if (CM) { + if (*CM == CodeModel::Tiny) + report_fatal_error("Target does not support the Tiny CodeModel"); return *CM; + } if (JIT) return RM == Reloc::PIC_ ? CodeModel::Small : CodeModel::Medium; return CodeModel::Small; @@ -146,7 +150,8 @@ : LLVMTargetMachine( T, computeDataLayout(TT, CPU, FS), TT, CPU, FS, Options, getEffectiveRelocModel(RM), - getEffectiveCodeModel(CM, getEffectiveRelocModel(RM), JIT), OL), + getEffectiveSystemZCodeModel(CM, getEffectiveRelocModel(RM), JIT), + OL), TLOF(llvm::make_unique()), Subtarget(TT, CPU, FS, *this) { initAsmInfo(); Index: lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -96,7 +96,7 @@ TT.isArch64Bit() ? "e-m:e-p:64:64-i64:64-n32:64-S128" : "e-m:e-p:32:32-i64:64-n32:64-S128", TT, CPU, FS, Options, getEffectiveRelocModel(RM), - CM ? *CM : CodeModel::Large, OL), + getEffectiveCodeModel(CM, CodeModel::Large), OL), TLOF(new WebAssemblyTargetObjectFile()) { // WebAssembly type-checks instructions, but a noreturn function with a return // type that doesn't match the context will cause a check failure. So we lower Index: lib/Target/X86/X86TargetMachine.cpp =================================================================== --- lib/Target/X86/X86TargetMachine.cpp +++ lib/Target/X86/X86TargetMachine.cpp @@ -201,10 +201,13 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM, - bool JIT, bool Is64Bit) { - if (CM) +static CodeModel::Model getEffectiveX86CodeModel(Optional CM, + bool JIT, bool Is64Bit) { + if (CM) { + if (*CM == CodeModel::Tiny) + report_fatal_error("Target does not support the Tiny CodeModel"); return *CM; + } if (JIT) return Is64Bit ? CodeModel::Large : CodeModel::Small; return CodeModel::Small; @@ -221,7 +224,8 @@ : LLVMTargetMachine( T, computeDataLayout(TT), TT, CPU, FS, Options, getEffectiveRelocModel(TT, JIT, RM), - getEffectiveCodeModel(CM, JIT, TT.getArch() == Triple::x86_64), OL), + getEffectiveX86CodeModel(CM, JIT, TT.getArch() == Triple::x86_64), + OL), TLOF(createTLOF(getTargetTriple())) { // Windows stack unwinder gets confused when execution flow "falls through" // after a call to 'noreturn' function. Index: lib/Target/XCore/XCoreTargetMachine.cpp =================================================================== --- lib/Target/XCore/XCoreTargetMachine.cpp +++ lib/Target/XCore/XCoreTargetMachine.cpp @@ -31,7 +31,8 @@ return *RM; } -static CodeModel::Model getEffectiveCodeModel(Optional CM) { +static CodeModel::Model +getEffectiveXCoreCodeModel(Optional CM) { if (CM) { if (*CM != CodeModel::Small && *CM != CodeModel::Large) report_fatal_error("Target only supports CodeModel Small or Large"); @@ -51,7 +52,7 @@ : LLVMTargetMachine( T, "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32-f64:32-a:0:32-n32", TT, CPU, FS, Options, getEffectiveRelocModel(RM), - getEffectiveCodeModel(CM), OL), + getEffectiveXCoreCodeModel(CM), OL), TLOF(llvm::make_unique()), Subtarget(TT, CPU, FS, *this) { initAsmInfo(); Index: test/CodeGen/ARM/tiny_codemodel.ll =================================================================== --- /dev/null +++ test/CodeGen/ARM/tiny_codemodel.ll @@ -0,0 +1,7 @@ +; RUN: not llc -verify-machineinstrs -o - -mtriple=arm-none-eabi -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=NOTINY + +; NOTINY: Target does not support the Tiny CodeModel + +define void @foo() { + ret void +} Index: test/CodeGen/PowerPC/tiny_codemodel.ll =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/tiny_codemodel.ll @@ -0,0 +1,7 @@ +; RUN: not llc -verify-machineinstrs -o - -mtriple=powerpc-linux-gnu -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=NOTINY + +; NOTINY: Target does not support the Tiny CodeModel + +define void @foo() { + ret void +} Index: test/CodeGen/SPARC/tiny_codemodel.ll =================================================================== --- /dev/null +++ test/CodeGen/SPARC/tiny_codemodel.ll @@ -0,0 +1,7 @@ +; RUN: not llc -verify-machineinstrs -o - -mtriple=sparc-unknown-linux-gnu -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=NOTINY + +; NOTINY: Target does not support the Tiny CodeModel + +define void @foo() { + ret void +} Index: test/CodeGen/SystemZ/tiny_codemodel.ll =================================================================== --- /dev/null +++ test/CodeGen/SystemZ/tiny_codemodel.ll @@ -0,0 +1,7 @@ +; RUN: not llc -verify-machineinstrs -o - -mtriple=systemz-unknown-linux-gnu -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=NOTINY + +; NOTINY: Target does not support the Tiny CodeModel + +define void @foo() { + ret void +} Index: test/CodeGen/X86/tiny_codemodel.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/tiny_codemodel.ll @@ -0,0 +1,7 @@ +; RUN: not llc -verify-machineinstrs -o - -mtriple=x86_64-linux-gnu -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=NOTINY + +; NOTINY: Target does not support the Tiny CodeModel + +define void @foo() { + ret void +}