Skip to content

Commit

Permalink
driver, gen: gate LoongArch support behind LLVM >= 16
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuyu committed Sep 24, 2023
1 parent 0665f68 commit 7a53134
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ void registerPredefinedTargetVersions() {
case llvm::Triple::wasm64:
VersionCondition::addPredefinedGlobalIdent("WebAssembly");
break;
#if LDC_LLVM_VER >= 1600
case llvm::Triple::loongarch32:
VersionCondition::addPredefinedGlobalIdent("LoongArch32");
registerPredefinedFloatABI("LoongArch_SoftFloat", "LoongArch_HardFloat");
Expand All @@ -773,6 +774,7 @@ void registerPredefinedTargetVersions() {
VersionCondition::addPredefinedGlobalIdent("LoongArch64");
registerPredefinedFloatABI("LoongArch_SoftFloat", "LoongArch_HardFloat");
break;
#endif // LDC_LLVM_VER >= 1600
default:
warning(Loc(), "unknown target CPU architecture: %s",
triple.getArchName().str().c_str());
Expand Down
8 changes: 8 additions & 0 deletions driver/targetmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const char *getABI(const llvm::Triple &triple, const llvm::SmallVectorImpl<llvm:
if (ABIName.startswith("ilp32"))
return "ilp32";
break;
#if LDC_LLVM_VER >= 1600
case llvm::Triple::loongarch32:
if (ABIName.startswith("ilp32s"))
return "ilp32s";
Expand All @@ -133,6 +134,7 @@ const char *getABI(const llvm::Triple &triple, const llvm::SmallVectorImpl<llvm:
if (ABIName.startswith("lp64s"))
return "lp64s";
break;
#endif // LDC_LLVM_VER >= 1600
default:
break;
}
Expand All @@ -156,6 +158,7 @@ const char *getABI(const llvm::Triple &triple, const llvm::SmallVectorImpl<llvm:
return "lp64";
case llvm::Triple::riscv32:
return "ilp32";
#if LDC_LLVM_VER >= 1600
case llvm::Triple::loongarch32:
if (isFeatureEnabled(features, "d"))
return "ilp32d";
Expand All @@ -168,6 +171,7 @@ const char *getABI(const llvm::Triple &triple, const llvm::SmallVectorImpl<llvm:
if (isFeatureEnabled(features, "f"))
return "lp64f";
return "lp64d";
#endif // LDC_LLVM_VER >= 1600
default:
return "";
}
Expand Down Expand Up @@ -294,10 +298,12 @@ static std::string getTargetCPU(const llvm::Triple &triple) {
return getRiscv32TargetCPU(triple);
case llvm::Triple::riscv64:
return getRiscv64TargetCPU(triple);
#if LDC_LLVM_VER >= 1600
case llvm::Triple::loongarch32:
return getLoongArch32TargetCPU(triple);
case llvm::Triple::loongarch64:
return getLoongArch64TargetCPU(triple);
#endif // LDC_LLVM_VER >= 1600
}
}

Expand Down Expand Up @@ -510,9 +516,11 @@ createTargetMachine(const std::string targetTriple, const std::string arch,

// For LoongArch 64-bit target default to la64 if nothing has been selected
// All current LoongArch targets have 64-bit floating point registers.
#if LDC_LLVM_VER >= 1600
if (triple.getArch() == llvm::Triple::loongarch64 && features.empty()) {
features = {"+d"};
}
#endif

// Handle cases where LLVM picks wrong default relocModel
#if LDC_LLVM_VER >= 1600
Expand Down
2 changes: 2 additions & 0 deletions gen/abi/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,10 @@ TargetABI *TargetABI::getTarget() {
case llvm::Triple::thumb:
case llvm::Triple::thumbeb:
return getArmTargetABI();
#if LDC_LLVM_VER >= 1600
case llvm::Triple::loongarch64:
return getLoongArch64TargetABI();
#endif // LDC_LLVM_VER >= 1600
default:
Logger::cout() << "WARNING: Unknown ABI, guessing...\n";
return new UnknownTargetABI;
Expand Down
2 changes: 2 additions & 0 deletions gen/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ llvm::Type *getRealType(const llvm::Triple &triple) {

case Triple::riscv32:
case Triple::riscv64:
#if LDC_LLVM_VER >= 1600
case Triple::loongarch32:
case Triple::loongarch64:
#endif // LDC_LLVM_VER >= 1600
return LLType::getFP128Ty(ctx);

default:
Expand Down

0 comments on commit 7a53134

Please sign in to comment.