Skip to content

Commit

Permalink
[OHOS] Add support for OpenHarmony
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kpdev committed Feb 27, 2023
1 parent a9df627 commit c417b7a
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/BinaryFormat/MinidumpConstants.def
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 15 additions & 4 deletions llvm/include/llvm/TargetParser/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ class Triple {
WASI, // Experimental WebAssembly OS
Emscripten,
ShaderModel, // DirectX ShaderModel
LastOSType = ShaderModel
LiteOS,
LastOSType = LiteOS
};
enum EnvironmentType {
UnknownEnvironment,
Expand Down Expand Up @@ -273,8 +274,8 @@ class Triple {
Callable,
Mesh,
Amplification,

LastEnvironmentType = Amplification
OpenHOS,
LastEnvironmentType = OpenHOS
};
enum ObjectFormatType {
UnknownObjectFormat,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -789,6 +799,7 @@ class Triple {
getEnvironment() == Triple::MuslEABI ||
getEnvironment() == Triple::EABIHF ||
getEnvironment() == Triple::GNUEABIHF ||
getEnvironment() == Triple::OpenHOS ||
getEnvironment() == Triple::MuslEABIHF || isAndroid()) &&
isOSBinFormatELF();
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/ARM/ARMSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/ARM/ARMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/TargetParser/AArch64TargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/TargetParser/ARMTargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/TargetParser/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/AArch64/arm64-platform-reg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions llvm/unittests/TargetParser/TripleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

2 comments on commit c417b7a

@brad0
Copy link
Contributor

@brad0 brad0 commented on c417b7a Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the contents of this there is a spot missed in clang/lib/Basic/Targets/ARM.cpp around line 324.

In llvm/include/llvm/TargetParser/Triple.h for EnvironmentType OpenHOS is in the wrong spot based on the comment at the top.

For isMusl() it would probably be better to use isOHOSFamily().

@kpdev
Copy link
Member Author

@kpdev kpdev commented on c417b7a Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the contents of this there is a spot missed in clang/lib/Basic/Targets/ARM.cpp around line 324.

In llvm/include/llvm/TargetParser/Triple.h for EnvironmentType OpenHOS is in the wrong spot based on the comment at the top.

For isMusl() it would probably be better to use isOHOSFamily().

Thank you, for clang part of these changes please take a look at this patch: https://reviews.llvm.org/D145227

Please sign in to comment.