[llvm] c417b7a - [OHOS] Add support for OpenHarmony
Pavel Kosov via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 06:17:02 PST 2023
Author: Pavel Kosov
Date: 2023-02-27T17:15:45+03:00
New Revision: c417b7a695704d5bc3be23f34d1bfa505f5172de
URL: https://github.com/llvm/llvm-project/commit/c417b7a695704d5bc3be23f34d1bfa505f5172de
DIFF: https://github.com/llvm/llvm-project/commit/c417b7a695704d5bc3be23f34d1bfa505f5172de.diff
LOG: [OHOS] Add support for OpenHarmony
Add support for OpenHarmony OS
General OpenHarmony OS discussion on discourse thread "[RFC] Add support for OpenHarmony OS"
https://discourse.llvm.org/t/rfc-add-support-for-openharmony-os/66656
Reviewed By: DavidSpickett
Differential Revision: https://reviews.llvm.org/D138202
Added:
Modified:
llvm/include/llvm/BinaryFormat/MinidumpConstants.def
llvm/include/llvm/TargetParser/Triple.h
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/lib/Target/ARM/ARMTargetMachine.cpp
llvm/lib/TargetParser/AArch64TargetParser.cpp
llvm/lib/TargetParser/ARMTargetParser.cpp
llvm/lib/TargetParser/Triple.cpp
llvm/test/CodeGen/AArch64/arm64-platform-reg.ll
llvm/unittests/TargetParser/TripleTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/MinidumpConstants.def b/llvm/include/llvm/BinaryFormat/MinidumpConstants.def
index 543305feea77..5226da3e8412 100644
--- a/llvm/include/llvm/BinaryFormat/MinidumpConstants.def
+++ b/llvm/include/llvm/BinaryFormat/MinidumpConstants.def
@@ -115,6 +115,7 @@ HANDLE_MDMP_PLATFORM(0x8202, Solaris) // Solaris
HANDLE_MDMP_PLATFORM(0x8203, Android) // Android
HANDLE_MDMP_PLATFORM(0x8204, PS3) // PS3
HANDLE_MDMP_PLATFORM(0x8205, NaCl) // Native Client (NaCl)
+HANDLE_MDMP_PLATFORM(0x8206, OpenHOS) // OpenHarmony OS
HANDLE_MDMP_PROTECT(0x01, NoAccess, PAGE_NO_ACCESS)
HANDLE_MDMP_PROTECT(0x02, ReadOnly, PAGE_READ_ONLY)
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 311665305e07..c15e9266a513 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -223,7 +223,8 @@ class Triple {
WASI, // Experimental WebAssembly OS
Emscripten,
ShaderModel, // DirectX ShaderModel
- LastOSType = ShaderModel
+ LiteOS,
+ LastOSType = LiteOS
};
enum EnvironmentType {
UnknownEnvironment,
@@ -273,8 +274,8 @@ class Triple {
Callable,
Mesh,
Amplification,
-
- LastEnvironmentType = Amplification
+ OpenHOS,
+ LastEnvironmentType = OpenHOS
};
enum ObjectFormatType {
UnknownObjectFormat,
@@ -740,9 +741,18 @@ class Triple {
return getEnvironment() == Triple::Musl ||
getEnvironment() == Triple::MuslEABI ||
getEnvironment() == Triple::MuslEABIHF ||
- getEnvironment() == Triple::MuslX32;
+ getEnvironment() == Triple::MuslX32 ||
+ getEnvironment() == Triple::OpenHOS || isOSLiteOS();
}
+ /// Tests whether the target is OHOS
+ /// LiteOS default enviroment is also OHOS, but omited on triple.
+ bool isOHOSFamily() const { return isOpenHOS() || isOSLiteOS(); }
+
+ bool isOpenHOS() const { return getEnvironment() == Triple::OpenHOS; }
+
+ bool isOSLiteOS() const { return getOS() == Triple::LiteOS; }
+
/// Tests whether the target is DXIL.
bool isDXIL() const {
return getArch() == Triple::dxil;
@@ -789,6 +799,7 @@ class Triple {
getEnvironment() == Triple::MuslEABI ||
getEnvironment() == Triple::EABIHF ||
getEnvironment() == Triple::GNUEABIHF ||
+ getEnvironment() == Triple::OpenHOS ||
getEnvironment() == Triple::MuslEABIHF || isAndroid()) &&
isOSBinFormatELF();
}
diff --git a/llvm/lib/Target/ARM/ARMSubtarget.h b/llvm/lib/Target/ARM/ARMSubtarget.h
index 5074ec9893cf..7e4d7a9b841a 100644
--- a/llvm/lib/Target/ARM/ARMSubtarget.h
+++ b/llvm/lib/Target/ARM/ARMSubtarget.h
@@ -391,7 +391,8 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
}
bool isTargetMuslAEABI() const {
return (TargetTriple.getEnvironment() == Triple::MuslEABI ||
- TargetTriple.getEnvironment() == Triple::MuslEABIHF) &&
+ TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
+ TargetTriple.getEnvironment() == Triple::OpenHOS) &&
!isTargetDarwin() && !isTargetWindows();
}
diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
index c5eeb9820cd0..39d8607818f7 100644
--- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
@@ -242,7 +242,8 @@ ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, const Triple &TT,
if ((TargetTriple.getEnvironment() == Triple::GNUEABI ||
TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
TargetTriple.getEnvironment() == Triple::MuslEABI ||
- TargetTriple.getEnvironment() == Triple::MuslEABIHF) &&
+ TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
+ TargetTriple.getEnvironment() == Triple::OpenHOS) &&
!(TargetTriple.isOSWindows() || TargetTriple.isOSDarwin()))
this->Options.EABIVersion = EABI::GNU;
else
diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index 0fea5f77b868..a53559247869 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -97,7 +97,7 @@ void AArch64::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values) {
bool AArch64::isX18ReservedByDefault(const Triple &TT) {
return TT.isAndroid() || TT.isOSDarwin() || TT.isOSFuchsia() ||
- TT.isOSWindows();
+ TT.isOSWindows() || TT.isOHOSFamily();
}
// Allows partial match, ex. "v8a" matches "armv8a".
diff --git a/llvm/lib/TargetParser/ARMTargetParser.cpp b/llvm/lib/TargetParser/ARMTargetParser.cpp
index af98ecb122d6..740219d85268 100644
--- a/llvm/lib/TargetParser/ARMTargetParser.cpp
+++ b/llvm/lib/TargetParser/ARMTargetParser.cpp
@@ -523,7 +523,7 @@ StringRef ARM::computeDefaultTargetABI(const Triple &TT, StringRef CPU) {
default:
if (TT.isOSNetBSD())
return "apcs-gnu";
- if (TT.isOSOpenBSD())
+ if (TT.isOSOpenBSD() || TT.isOHOSFamily())
return "aapcs-linux";
return "aapcs";
}
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index a68035989a93..c586122ebdfc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -243,6 +243,7 @@ StringRef Triple::getOSTypeName(OSType Kind) {
case Win32: return "windows";
case ZOS: return "zos";
case ShaderModel: return "shadermodel";
+ case LiteOS: return "liteos";
}
llvm_unreachable("Invalid OSType");
@@ -290,6 +291,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
case Callable: return "callable";
case Mesh: return "mesh";
case Amplification: return "amplification";
+ case OpenHOS: return "ohos";
}
llvm_unreachable("Invalid EnvironmentType!");
@@ -596,6 +598,7 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("wasi", Triple::WASI)
.StartsWith("emscripten", Triple::Emscripten)
.StartsWith("shadermodel", Triple::ShaderModel)
+ .StartsWith("liteos", Triple::LiteOS)
.Default(Triple::UnknownOS);
}
@@ -640,6 +643,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
.StartsWith("callable", Triple::Callable)
.StartsWith("mesh", Triple::Mesh)
.StartsWith("amplification", Triple::Amplification)
+ .StartsWith("ohos", Triple::OpenHOS)
.Default(Triple::UnknownEnvironment);
}
diff --git a/llvm/test/CodeGen/AArch64/arm64-platform-reg.ll b/llvm/test/CodeGen/AArch64/arm64-platform-reg.ll
index 713c9e859235..c598306c2de3 100644
--- a/llvm/test/CodeGen/AArch64/arm64-platform-reg.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-platform-reg.ll
@@ -2,6 +2,7 @@
; RUN: llc -mtriple=arm64-freebsd-gnu -mattr=+reserve-x18 -o - %s | FileCheck %s --check-prefix=CHECK-RESERVE --check-prefix=CHECK-RESERVE-X18
; RUN: llc -mtriple=arm64-linux-gnu -o - %s | FileCheck %s
; RUN: llc -mtriple=aarch64-linux-android -o - %s | FileCheck %s --check-prefix=CHECK-RESERVE --check-prefix=CHECK-RESERVE-X18
+; RUN: llc -mtriple=aarch64-linux-ohos -o - %s | FileCheck %s --check-prefix=CHECK-RESERVE --check-prefix=CHECK-RESERVE-X18
; RUN: llc -mtriple=aarch64-fuchsia -o - %s | FileCheck %s --check-prefix=CHECK-RESERVE --check-prefix=CHECK-RESERVE-X18
; RUN: llc -mtriple=aarch64-windows -o - %s | FileCheck %s --check-prefix=CHECK-RESERVE --check-prefix=CHECK-RESERVE-X18
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index 77de43a16d0a..b4ef21e261f8 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -876,6 +876,18 @@ TEST(TripleTest, ParsedIDs) {
EXPECT_EQ(Triple::UnknownOS, T.getOS());
EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+ T = Triple("arm-unknown-linux-ohos");
+ EXPECT_EQ(Triple::arm, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::OpenHOS, T.getEnvironment());
+
+ T = Triple("arm-unknown-liteos");
+ EXPECT_EQ(Triple::arm, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::LiteOS, T.getOS());
+ EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+
T = Triple("huh");
EXPECT_EQ(Triple::UnknownArch, T.getArch());
}
More information about the llvm-commits
mailing list