-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Implement a subset of builtin_cpu_supports() features #82809
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
557e716
Implement a subset of builtin_cpu_supports() features
diggerlin 814011f
rebased the code and add 4 new features
diggerlin 3867877
address comment
diggerlin 17ce0be
address comment
diggerlin 29b5ecb
Update llvm/include/llvm/TargetParser/PPCTargetParser.def
diggerlin 079c30d
address comment
diggerlin a8f1b2f
darn is supported since power9
diggerlin 3ecb115
address lei's comment
diggerlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16570,32 +16570,53 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, | |
|
||
#include "llvm/TargetParser/PPCTargetParser.def" | ||
auto GenAIXPPCBuiltinCpuExpr = [&](unsigned SupportMethod, unsigned FieldIdx, | ||
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. This is now a very large lambda function AFAICT. Please extract it into a static function to aid readability. 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 am prefer to keep as lambda
|
||
unsigned CompOp, | ||
unsigned Mask, CmpInst::Predicate CompOp, | ||
unsigned OpValue) -> Value * { | ||
if (SupportMethod == AIX_BUILTIN_PPC_FALSE) | ||
return llvm::ConstantInt::getFalse(ConvertType(E->getType())); | ||
|
||
if (SupportMethod == AIX_BUILTIN_PPC_TRUE) | ||
return llvm::ConstantInt::getTrue(ConvertType(E->getType())); | ||
|
||
assert(SupportMethod <= USE_SYS_CONF && "Invalid value for SupportMethod."); | ||
assert((CompOp == COMP_EQ) && "Only equal comparisons are supported."); | ||
assert(SupportMethod <= SYS_CALL && "Invalid value for SupportMethod."); | ||
|
||
llvm::Value *FieldValue = nullptr; | ||
if (SupportMethod == USE_SYS_CONF) { | ||
llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE); | ||
llvm::Constant *SysConf = | ||
CGM.CreateRuntimeVariable(STy, "_system_configuration"); | ||
|
||
// Grab the appropriate field from _system_configuration. | ||
llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0), | ||
ConstantInt::get(Int32Ty, FieldIdx)}; | ||
|
||
FieldValue = Builder.CreateGEP(STy, SysConf, Idxs); | ||
FieldValue = Builder.CreateAlignedLoad(Int32Ty, FieldValue, | ||
CharUnits::fromQuantity(4)); | ||
} else if (SupportMethod == SYS_CALL) { | ||
llvm::FunctionType *FTy = | ||
llvm::FunctionType::get(Int64Ty, Int32Ty, false); | ||
llvm::FunctionCallee Func = | ||
CGM.CreateRuntimeFunction(FTy, "getsystemcfg"); | ||
|
||
FieldValue = | ||
Builder.CreateCall(Func, {ConstantInt::get(Int32Ty, FieldIdx)}); | ||
} | ||
assert(FieldValue && | ||
"SupportMethod value is not defined in PPCTargetParser.def."); | ||
|
||
llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE); | ||
llvm::Constant *SysConf = | ||
CGM.CreateRuntimeVariable(STy, "_system_configuration"); | ||
if (Mask) | ||
FieldValue = Builder.CreateAnd(FieldValue, Mask); | ||
|
||
// Grab the appropriate field from _system_configuration. | ||
llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0), | ||
ConstantInt::get(Int32Ty, FieldIdx)}; | ||
llvm::Type *ValueType = FieldValue->getType(); | ||
amy-kwan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool IsValueType64Bit = ValueType->isIntegerTy(64); | ||
assert( | ||
(IsValueType64Bit || ValueType->isIntegerTy(32)) && | ||
"Only 32/64-bit integers are supported in GenAIXPPCBuiltinCpuExpr()."); | ||
|
||
llvm::Value *FieldValue = Builder.CreateGEP(STy, SysConf, Idxs); | ||
FieldValue = Builder.CreateAlignedLoad(Int32Ty, FieldValue, | ||
CharUnits::fromQuantity(4)); | ||
assert(FieldValue->getType()->isIntegerTy(32) && | ||
"Only 32-bit integers are supported in GenAIXPPCBuiltinCpuExpr()."); | ||
return Builder.CreateICmp(ICmpInst::ICMP_EQ, FieldValue, | ||
ConstantInt::get(Int32Ty, OpValue)); | ||
return Builder.CreateICmp( | ||
CompOp, FieldValue, | ||
ConstantInt::get(IsValueType64Bit ? Int64Ty : Int32Ty, OpValue)); | ||
}; | ||
|
||
switch (BuiltinID) { | ||
|
@@ -16607,15 +16628,18 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, | |
llvm::Triple Triple = getTarget().getTriple(); | ||
|
||
if (Triple.isOSAIX()) { | ||
unsigned IsCpuSupport, FieldIdx, CompareOp, CpuIdValue; | ||
typedef std::tuple<unsigned, unsigned, unsigned, unsigned> CPUType; | ||
std::tie(IsCpuSupport, FieldIdx, CompareOp, CpuIdValue) = | ||
unsigned SupportMethod, FieldIdx, CpuIdValue; | ||
CmpInst::Predicate CompareOp; | ||
typedef std::tuple<unsigned, unsigned, CmpInst::Predicate, unsigned> | ||
CPUType; | ||
std::tie(SupportMethod, FieldIdx, CompareOp, CpuIdValue) = | ||
static_cast<CPUType>(StringSwitch<CPUType>(CPUStr) | ||
#define PPC_AIX_CPU(NAME, SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE) \ | ||
.Case(NAME, {SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE}) | ||
#define PPC_AIX_CPU(NAME, SUPPORT_METHOD, INDEX, COMPARE_OP, VALUE) \ | ||
.Case(NAME, {SUPPORT_METHOD, INDEX, COMPARE_OP, VALUE}) | ||
#include "llvm/TargetParser/PPCTargetParser.def" | ||
); | ||
return GenAIXPPCBuiltinCpuExpr(IsCpuSupport, FieldIdx, CompareOp, | ||
.Default({AIX_BUILTIN_PPC_FALSE, 0, | ||
CmpInst::Predicate(), 0})); | ||
return GenAIXPPCBuiltinCpuExpr(SupportMethod, FieldIdx, 0, CompareOp, | ||
CpuIdValue); | ||
} | ||
|
||
|
@@ -16633,10 +16657,31 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, | |
llvm::ConstantInt::get(Int32Ty, NumCPUID)); | ||
} | ||
case Builtin::BI__builtin_cpu_supports: { | ||
unsigned FeatureWord; | ||
unsigned BitMask; | ||
llvm::Triple Triple = getTarget().getTriple(); | ||
const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts(); | ||
StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString(); | ||
if (Triple.isOSAIX()) { | ||
unsigned SupportMethod, FieldIdx, Mask, Value; | ||
CmpInst::Predicate CompOp; | ||
typedef std::tuple<unsigned, unsigned, unsigned, CmpInst::Predicate, | ||
unsigned> | ||
CPUSupportType; | ||
std::tie(SupportMethod, FieldIdx, Mask, CompOp, Value) = | ||
static_cast<CPUSupportType>(StringSwitch<CPUSupportType>(CPUStr) | ||
#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, COMP_OP, \ | ||
VALUE) \ | ||
.Case(NAME, {SUPPORT_METHOD, INDEX, MASK, COMP_OP, VALUE}) | ||
#include "llvm/TargetParser/PPCTargetParser.def" | ||
.Default({AIX_BUILTIN_PPC_FALSE, 0, 0, | ||
CmpInst::Predicate(), 0})); | ||
return GenAIXPPCBuiltinCpuExpr(SupportMethod, FieldIdx, Mask, CompOp, | ||
Value); | ||
} | ||
|
||
assert(Triple.isOSLinux() && | ||
"__builtin_cpu_supports() is only supported for AIX and Linux."); | ||
unsigned FeatureWord; | ||
unsigned BitMask; | ||
std::tie(FeatureWord, BitMask) = | ||
StringSwitch<std::pair<unsigned, unsigned>>(CPUStr) | ||
#define PPC_LNX_FEATURE(Name, Description, EnumName, Bitmask, FA_WORD) \ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.