Skip to content

Commit 087c7eb

Browse files
committed
[BPF] Refactor BPFSubtarget::initSubtargetFeatures() (NFC)
Refactor it to make it match the style of BPFTargetInfo::getTargetDefines(), so that when we add -mcpu=v5 in the future, we can simply append e.g.: if (CpuVerNum >= 5) HasFoo = true; instead of saying: if (CPU == "v5") { HasJmpExt = true; HasJmp32 = true; HasAlu32 = true; HasLdsx = !Disable_ldsx; HasMovsx = !Disable_movsx; HasBswap = !Disable_bswap; HasSdivSmod = !Disable_sdiv_smod; HasGotol = !Disable_gotol; HasStoreImm = !Disable_StoreImm; HasFoo = true; } This also makes it clearer that newer "CPU"s always support older features. No functional changes intended.
1 parent d7c69c2 commit 087c7eb

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

llvm/lib/Target/BPF/BPFSubtarget.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,23 @@ void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
7171
CPU = sys::detail::getHostCPUNameForBPF();
7272
if (CPU == "generic" || CPU == "v1")
7373
return;
74-
if (CPU == "v2") {
75-
HasJmpExt = true;
76-
return;
77-
}
78-
if (CPU == "v3") {
74+
75+
int CpuVerNum = CPU.back() - '0';
76+
if (CpuVerNum >= 2)
7977
HasJmpExt = true;
78+
79+
if (CpuVerNum >= 3) {
8080
HasJmp32 = true;
8181
HasAlu32 = true;
82-
return;
8382
}
84-
if (CPU == "v4") {
85-
HasJmpExt = true;
86-
HasJmp32 = true;
87-
HasAlu32 = true;
83+
84+
if (CpuVerNum >= 4) {
8885
HasLdsx = !Disable_ldsx;
8986
HasMovsx = !Disable_movsx;
9087
HasBswap = !Disable_bswap;
9188
HasSdivSmod = !Disable_sdiv_smod;
9289
HasGotol = !Disable_gotol;
9390
HasStoreImm = !Disable_StoreImm;
94-
return;
9591
}
9692
}
9793

0 commit comments

Comments
 (0)