-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[PowerPC][X86] Make cpu id builtins target independent and lower for PPC #68919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
65c84f2
60e1aba
dd421e7
eef7dd6
b121664
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14053,11 +14053,11 @@ CodeGenFunction::EmitAArch64CpuSupports(ArrayRef<StringRef> FeaturesStrs) { | |
|
||
Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, | ||
const CallExpr *E) { | ||
if (BuiltinID == X86::BI__builtin_cpu_is) | ||
if (BuiltinID == Builtin::BI__builtin_cpu_is) | ||
return EmitX86CpuIs(E); | ||
if (BuiltinID == X86::BI__builtin_cpu_supports) | ||
if (BuiltinID == Builtin::BI__builtin_cpu_supports) | ||
return EmitX86CpuSupports(E); | ||
if (BuiltinID == X86::BI__builtin_cpu_init) | ||
if (BuiltinID == Builtin::BI__builtin_cpu_init) | ||
return EmitX86CpuInit(); | ||
|
||
// Handle MSVC intrinsics before argument evaluation to prevent double | ||
|
@@ -16545,6 +16545,43 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, | |
switch (BuiltinID) { | ||
default: return nullptr; | ||
|
||
case Builtin::BI__builtin_cpu_is: { | ||
const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts(); | ||
StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString(); | ||
unsigned NumCPUID = StringSwitch<unsigned>(CPUStr) | ||
#define PPC_LNX_CPU(Name, NumericID) .Case(Name, NumericID) | ||
#include "llvm/TargetParser/PPCTargetParser.def" | ||
.Default(-1U); | ||
assert(NumCPUID < -1U && "Invalid CPU name. Missed by SemaChecking?"); | ||
Value *Op0 = llvm::ConstantInt::get(Int32Ty, PPC_FAWORD_CPUID); | ||
llvm::Function *F = CGM.getIntrinsic(Intrinsic::ppc_fixed_addr_ld); | ||
Value *TheCall = Builder.CreateCall(F, {Op0}, "cpu_is"); | ||
return Builder.CreateICmpEQ(TheCall, | ||
llvm::ConstantInt::get(Int32Ty, NumCPUID)); | ||
} | ||
case Builtin::BI__builtin_cpu_supports: { | ||
unsigned FeatureWord; | ||
unsigned BitMask; | ||
const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts(); | ||
StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString(); | ||
std::tie(FeatureWord, BitMask) = | ||
StringSwitch<std::pair<unsigned, unsigned>>(CPUStr) | ||
#define PPC_LNX_FEATURE(Name, Description, EnumName, Bitmask, FA_WORD) \ | ||
.Case(Name, {FA_WORD, Bitmask}) | ||
#include "llvm/TargetParser/PPCTargetParser.def" | ||
.Default({0, 0}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want a default here? without a default it will hit an assert here if fell off the end of the string-switch.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a good point. If we somehow have a string argument that would produce the What do you think about keeping the
|
||
assert(BitMask && "Invalid target feature string. Missed by SemaChecking?"); | ||
Value *Op0 = llvm::ConstantInt::get(Int32Ty, FeatureWord); | ||
llvm::Function *F = CGM.getIntrinsic(Intrinsic::ppc_fixed_addr_ld); | ||
Value *TheCall = Builder.CreateCall(F, {Op0}, "cpu_supports"); | ||
Value *Mask = | ||
Builder.CreateAnd(TheCall, llvm::ConstantInt::get(Int32Ty, BitMask)); | ||
return Builder.CreateICmpNE(Mask, llvm::Constant::getNullValue(Int32Ty)); | ||
#undef PPC_FAWORD_HWCAP | ||
#undef PPC_FAWORD_HWCAP2 | ||
#undef PPC_FAWORD_CPUID | ||
} | ||
|
||
// __builtin_ppc_get_timebase is GCC 4.8+'s PowerPC-specific name for what we | ||
// call __builtin_readcyclecounter. | ||
case PPC::BI__builtin_ppc_get_timebase: | ||
|
Uh oh!
There was an error while loading. Please reload this page.