Skip to content

Commit bbef383

Browse files
committed
Revert "[LowerTypeTests] Support generating Armv6-M jump tables."
This reverts commit f6ddf77. Eight buildbots reported that the two test files changed by that commit had started failing. The buildbots in question all had in common that they build with a very restricted `LLVM_TARGETS_TO_BUILD`, such as only X86 or AArch64 or Hexagon. I didn't notice this before commit because my own build has the full default set of targets, and in that circumstance, the tests pass. I assume the problem has something to do with the attempt to query TargetTransformInfo: if you can't make a valid TTI for the target triple then you can't ask it what kind of inline assembler you should be emitting, and so `opt` without the Arm backend can't get the Arm cases of these tests right. I don't have time to fix this until next week, so I'll revert the change for now to keep the buildbots happy.
1 parent 9305b63 commit bbef383

File tree

8 files changed

+43
-170
lines changed

8 files changed

+43
-170
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,17 +1570,6 @@ class TargetTransformInfo {
15701570
VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const;
15711571
/// @}
15721572

1573-
/// \returns Whether a 32-bit branch instruction is available in Arm or Thumb
1574-
/// state.
1575-
///
1576-
/// Used by the LowerTypeTests pass, which constructs an IR inline assembler
1577-
/// node containing a jump table in a format suitable for the target, so it
1578-
/// needs to know what format of jump table it can legally use.
1579-
///
1580-
/// For non-Arm targets, this function isn't used. It defaults to returning
1581-
/// false, but it shouldn't matter what it returns anyway.
1582-
bool hasArmWideBranch(bool Thumb) const;
1583-
15841573
/// @}
15851574

15861575
private:
@@ -1938,7 +1927,6 @@ class TargetTransformInfo::Concept {
19381927
Align Alignment) const = 0;
19391928
virtual VPLegalization
19401929
getVPLegalizationStrategy(const VPIntrinsic &PI) const = 0;
1941-
virtual bool hasArmWideBranch(bool Thumb) const = 0;
19421930
};
19431931

19441932
template <typename T>
@@ -2618,10 +2606,6 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
26182606
getVPLegalizationStrategy(const VPIntrinsic &PI) const override {
26192607
return Impl.getVPLegalizationStrategy(PI);
26202608
}
2621-
2622-
bool hasArmWideBranch(bool Thumb) const override {
2623-
return Impl.hasArmWideBranch(Thumb);
2624-
}
26252609
};
26262610

26272611
template <typename T>

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,6 @@ class TargetTransformInfoImplBase {
862862
/* OperatorStrategy */ TargetTransformInfo::VPLegalization::Convert);
863863
}
864864

865-
bool hasArmWideBranch(bool) const { return false; }
866-
867865
protected:
868866
// Obtain the minimum required size to hold the value (without the sign)
869867
// In case of a vector it returns the min required size for one element.

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,10 +1170,6 @@ TargetTransformInfo::getVPLegalizationStrategy(const VPIntrinsic &VPI) const {
11701170
return TTIImpl->getVPLegalizationStrategy(VPI);
11711171
}
11721172

1173-
bool TargetTransformInfo::hasArmWideBranch(bool Thumb) const {
1174-
return TTIImpl->hasArmWideBranch(Thumb);
1175-
}
1176-
11771173
bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
11781174
return TTIImpl->shouldExpandReduction(II);
11791175
}

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,16 +2441,3 @@ InstructionCost ARMTTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
24412441
}
24422442
return -1;
24432443
}
2444-
2445-
bool ARMTTIImpl::hasArmWideBranch(bool Thumb) const {
2446-
if (Thumb) {
2447-
// B.W is available in any Thumb2-supporting target, and also in every
2448-
// version of Armv8-M, even Baseline which does not include the rest of
2449-
// Thumb2.
2450-
return ST->isThumb2() || ST->hasV8MBaselineOps();
2451-
} else {
2452-
// B is available in all versions of the Arm ISA, so the only question is
2453-
// whether that ISA is available at all.
2454-
return ST->hasARMOps();
2455-
}
2456-
}

llvm/lib/Target/ARM/ARMTargetTransformInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,6 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
325325

326326
return true;
327327
}
328-
329-
bool hasArmWideBranch(bool Thumb) const;
330-
331328
/// @}
332329
};
333330

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 38 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "llvm/ADT/Statistic.h"
2525
#include "llvm/ADT/StringRef.h"
2626
#include "llvm/ADT/TinyPtrVector.h"
27-
#include "llvm/Analysis/TargetTransformInfo.h"
2827
#include "llvm/Analysis/TypeMetadataUtils.h"
2928
#include "llvm/Analysis/ValueTracking.h"
3029
#include "llvm/IR/Attributes.h"
@@ -407,15 +406,6 @@ class LowerTypeTestsModule {
407406
Triple::OSType OS;
408407
Triple::ObjectFormatType ObjectFormat;
409408

410-
// Determines which kind of Thumb jump table we generate. If arch is
411-
// either 'arm' or 'thumb' we need to find this out, because
412-
// selectJumpTableArmEncoding may decide to use Thumb in either case.
413-
bool CanUseArmJumpTable = false, CanUseThumbBWJumpTable = false;
414-
415-
// The jump table type we ended up deciding on. (Usually the same as
416-
// Arch, except that 'arm' and 'thumb' are often interchangeable.)
417-
Triple::ArchType JumpTableArch = Triple::UnknownArch;
418-
419409
IntegerType *Int1Ty = Type::getInt1Ty(M.getContext());
420410
IntegerType *Int8Ty = Type::getInt8Ty(M.getContext());
421411
PointerType *Int8PtrTy = Type::getInt8PtrTy(M.getContext());
@@ -491,8 +481,6 @@ class LowerTypeTestsModule {
491481

492482
void buildBitSetsFromGlobalVariables(ArrayRef<Metadata *> TypeIds,
493483
ArrayRef<GlobalTypeMember *> Globals);
494-
Triple::ArchType
495-
selectJumpTableArmEncoding(ArrayRef<GlobalTypeMember *> Functions);
496484
unsigned getJumpTableEntrySize();
497485
Type *getJumpTableEntryType();
498486
void createJumpTableEntry(raw_ostream &AsmOS, raw_ostream &ConstraintOS,
@@ -530,16 +518,15 @@ class LowerTypeTestsModule {
530518
void replaceDirectCalls(Value *Old, Value *New);
531519

532520
public:
533-
LowerTypeTestsModule(Module &M, ModuleAnalysisManager &AM,
534-
ModuleSummaryIndex *ExportSummary,
521+
LowerTypeTestsModule(Module &M, ModuleSummaryIndex *ExportSummary,
535522
const ModuleSummaryIndex *ImportSummary,
536523
bool DropTypeTests);
537524

538525
bool lower();
539526

540527
// Lower the module using the action and summary passed as command line
541528
// arguments. For testing purposes only.
542-
static bool runForTesting(Module &M, ModuleAnalysisManager &AM);
529+
static bool runForTesting(Module &M);
543530
};
544531
} // end anonymous namespace
545532

@@ -1195,36 +1182,31 @@ static const unsigned kX86JumpTableEntrySize = 8;
11951182
static const unsigned kX86IBTJumpTableEntrySize = 16;
11961183
static const unsigned kARMJumpTableEntrySize = 4;
11971184
static const unsigned kARMBTIJumpTableEntrySize = 8;
1198-
static const unsigned kARMv6MJumpTableEntrySize = 16;
11991185
static const unsigned kRISCVJumpTableEntrySize = 8;
12001186

12011187
unsigned LowerTypeTestsModule::getJumpTableEntrySize() {
1202-
switch (JumpTableArch) {
1203-
case Triple::x86:
1204-
case Triple::x86_64:
1205-
if (const auto *MD = mdconst::extract_or_null<ConstantInt>(
1188+
switch (Arch) {
1189+
case Triple::x86:
1190+
case Triple::x86_64:
1191+
if (const auto *MD = mdconst::extract_or_null<ConstantInt>(
12061192
M.getModuleFlag("cf-protection-branch")))
1207-
if (MD->getZExtValue())
1208-
return kX86IBTJumpTableEntrySize;
1209-
return kX86JumpTableEntrySize;
1210-
case Triple::arm:
1211-
return kARMJumpTableEntrySize;
1212-
case Triple::thumb:
1213-
if (CanUseThumbBWJumpTable)
1193+
if (MD->getZExtValue())
1194+
return kX86IBTJumpTableEntrySize;
1195+
return kX86JumpTableEntrySize;
1196+
case Triple::arm:
1197+
case Triple::thumb:
12141198
return kARMJumpTableEntrySize;
1215-
else
1216-
return kARMv6MJumpTableEntrySize;
1217-
case Triple::aarch64:
1218-
if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
1199+
case Triple::aarch64:
1200+
if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
12191201
M.getModuleFlag("branch-target-enforcement")))
1220-
if (BTE->getZExtValue())
1221-
return kARMBTIJumpTableEntrySize;
1222-
return kARMJumpTableEntrySize;
1223-
case Triple::riscv32:
1224-
case Triple::riscv64:
1225-
return kRISCVJumpTableEntrySize;
1226-
default:
1227-
report_fatal_error("Unsupported architecture for jump tables");
1202+
if (BTE->getZExtValue())
1203+
return kARMBTIJumpTableEntrySize;
1204+
return kARMJumpTableEntrySize;
1205+
case Triple::riscv32:
1206+
case Triple::riscv64:
1207+
return kRISCVJumpTableEntrySize;
1208+
default:
1209+
report_fatal_error("Unsupported architecture for jump tables");
12281210
}
12291211
}
12301212

@@ -1258,32 +1240,7 @@ void LowerTypeTestsModule::createJumpTableEntry(
12581240
AsmOS << "bti c\n";
12591241
AsmOS << "b $" << ArgIndex << "\n";
12601242
} else if (JumpTableArch == Triple::thumb) {
1261-
if (!CanUseThumbBWJumpTable) {
1262-
// In Armv6-M, this sequence will generate a branch without corrupting
1263-
// any registers. We use two stack words; in the second, we construct the
1264-
// address we'll pop into pc, and the first is used to save and restore
1265-
// r0 which we use as a temporary register.
1266-
//
1267-
// To support position-independent use cases, the offset of the target
1268-
// function is stored as a relative offset (which will expand into an
1269-
// R_ARM_REL32 relocation in ELF, and presumably the equivalent in other
1270-
// object file types), and added to pc after we load it. (The alternative
1271-
// B.W is automatically pc-relative.)
1272-
//
1273-
// There are five 16-bit Thumb instructions here, so the .balign 4 adds a
1274-
// sixth halfword of padding, and then the offset consumes a further 4
1275-
// bytes, for a total of 16, which is very convenient since entries in
1276-
// this jump table need to have power-of-two size.
1277-
AsmOS << "push {r0,r1}\n"
1278-
<< "ldr r0, 1f\n"
1279-
<< "0: add r0, r0, pc\n"
1280-
<< "str r0, [sp, #4]\n"
1281-
<< "pop {r0,pc}\n"
1282-
<< ".balign 4\n"
1283-
<< "1: .word $" << ArgIndex << " - (0b + 4)\n";
1284-
} else {
1285-
AsmOS << "b.w $" << ArgIndex << "\n";
1286-
}
1243+
AsmOS << "b.w $" << ArgIndex << "\n";
12871244
} else if (JumpTableArch == Triple::riscv32 ||
12881245
JumpTableArch == Triple::riscv64) {
12891246
AsmOS << "tail $" << ArgIndex << "@plt\n";
@@ -1395,19 +1352,12 @@ static bool isThumbFunction(Function *F, Triple::ArchType ModuleArch) {
13951352
// Each jump table must be either ARM or Thumb as a whole for the bit-test math
13961353
// to work. Pick one that matches the majority of members to minimize interop
13971354
// veneers inserted by the linker.
1398-
Triple::ArchType LowerTypeTestsModule::selectJumpTableArmEncoding(
1399-
ArrayRef<GlobalTypeMember *> Functions) {
1400-
if (Arch != Triple::arm && Arch != Triple::thumb)
1401-
return Arch;
1402-
1403-
if (!CanUseThumbBWJumpTable && CanUseArmJumpTable) {
1404-
// In architectures that provide Arm and Thumb-1 but not Thumb-2,
1405-
// we should always prefer the Arm jump table format, because the
1406-
// Thumb-1 one is larger and slower.
1407-
return Triple::arm;
1408-
}
1355+
static Triple::ArchType
1356+
selectJumpTableArmEncoding(ArrayRef<GlobalTypeMember *> Functions,
1357+
Triple::ArchType ModuleArch) {
1358+
if (ModuleArch != Triple::arm && ModuleArch != Triple::thumb)
1359+
return ModuleArch;
14091360

1410-
// Otherwise, go with majority vote.
14111361
unsigned ArmCount = 0, ThumbCount = 0;
14121362
for (const auto GTM : Functions) {
14131363
if (!GTM->isJumpTableCanonical()) {
@@ -1418,7 +1368,7 @@ Triple::ArchType LowerTypeTestsModule::selectJumpTableArmEncoding(
14181368
}
14191369

14201370
Function *F = cast<Function>(GTM->getGlobal());
1421-
++(isThumbFunction(F, Arch) ? ThumbCount : ArmCount);
1371+
++(isThumbFunction(F, ModuleArch) ? ThumbCount : ArmCount);
14221372
}
14231373

14241374
return ArmCount > ThumbCount ? Triple::arm : Triple::thumb;
@@ -1431,6 +1381,8 @@ void LowerTypeTestsModule::createJumpTable(
14311381
SmallVector<Value *, 16> AsmArgs;
14321382
AsmArgs.reserve(Functions.size() * 2);
14331383

1384+
Triple::ArchType JumpTableArch = selectJumpTableArmEncoding(Functions, Arch);
1385+
14341386
for (GlobalTypeMember *GTM : Functions)
14351387
createJumpTableEntry(AsmOS, ConstraintOS, JumpTableArch, AsmArgs,
14361388
cast<Function>(GTM->getGlobal()));
@@ -1447,11 +1399,9 @@ void LowerTypeTestsModule::createJumpTable(
14471399
F->addFnAttr("target-features", "-thumb-mode");
14481400
if (JumpTableArch == Triple::thumb) {
14491401
F->addFnAttr("target-features", "+thumb-mode");
1450-
if (CanUseThumbBWJumpTable) {
1451-
// Thumb jump table assembly needs Thumb2. The following attribute is
1452-
// added by Clang for -march=armv7.
1453-
F->addFnAttr("target-cpu", "cortex-a8");
1454-
}
1402+
// Thumb jump table assembly needs Thumb2. The following attribute is added
1403+
// by Clang for -march=armv7.
1404+
F->addFnAttr("target-cpu", "cortex-a8");
14551405
}
14561406
// When -mbranch-protection= is used, the inline asm adds a BTI. Suppress BTI
14571407
// for the function to avoid double BTI. This is a no-op without
@@ -1571,10 +1521,6 @@ void LowerTypeTestsModule::buildBitSetsFromFunctionsNative(
15711521
// FIXME: find a better way to represent the jumptable in the IR.
15721522
assert(!Functions.empty());
15731523

1574-
// Decide on the jump table encoding, so that we know how big the
1575-
// entries will be.
1576-
JumpTableArch = selectJumpTableArmEncoding(Functions);
1577-
15781524
// Build a simple layout based on the regular layout of jump tables.
15791525
DenseMap<GlobalTypeMember *, uint64_t> GlobalLayout;
15801526
unsigned EntrySize = getJumpTableEntrySize();
@@ -1760,31 +1706,18 @@ void LowerTypeTestsModule::buildBitSetsFromDisjointSet(
17601706

17611707
/// Lower all type tests in this module.
17621708
LowerTypeTestsModule::LowerTypeTestsModule(
1763-
Module &M, ModuleAnalysisManager &AM, ModuleSummaryIndex *ExportSummary,
1709+
Module &M, ModuleSummaryIndex *ExportSummary,
17641710
const ModuleSummaryIndex *ImportSummary, bool DropTypeTests)
17651711
: M(M), ExportSummary(ExportSummary), ImportSummary(ImportSummary),
17661712
DropTypeTests(DropTypeTests || ClDropTypeTests) {
17671713
assert(!(ExportSummary && ImportSummary));
17681714
Triple TargetTriple(M.getTargetTriple());
17691715
Arch = TargetTriple.getArch();
1770-
if (Arch == Triple::arm)
1771-
CanUseArmJumpTable = true;
1772-
if (Arch == Triple::arm || Arch == Triple::thumb) {
1773-
auto &FAM =
1774-
AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
1775-
for (Function &F : M) {
1776-
auto &TTI = FAM.getResult<TargetIRAnalysis>(F);
1777-
if (TTI.hasArmWideBranch(false))
1778-
CanUseArmJumpTable = true;
1779-
if (TTI.hasArmWideBranch(true))
1780-
CanUseThumbBWJumpTable = true;
1781-
}
1782-
}
17831716
OS = TargetTriple.getOS();
17841717
ObjectFormat = TargetTriple.getObjectFormat();
17851718
}
17861719

1787-
bool LowerTypeTestsModule::runForTesting(Module &M, ModuleAnalysisManager &AM) {
1720+
bool LowerTypeTestsModule::runForTesting(Module &M) {
17881721
ModuleSummaryIndex Summary(/*HaveGVs=*/false);
17891722

17901723
// Handle the command-line summary arguments. This code is for testing
@@ -1802,8 +1735,7 @@ bool LowerTypeTestsModule::runForTesting(Module &M, ModuleAnalysisManager &AM) {
18021735

18031736
bool Changed =
18041737
LowerTypeTestsModule(
1805-
M, AM,
1806-
ClSummaryAction == PassSummaryAction::Export ? &Summary : nullptr,
1738+
M, ClSummaryAction == PassSummaryAction::Export ? &Summary : nullptr,
18071739
ClSummaryAction == PassSummaryAction::Import ? &Summary : nullptr,
18081740
/*DropTypeTests*/ false)
18091741
.lower();
@@ -2366,10 +2298,10 @@ PreservedAnalyses LowerTypeTestsPass::run(Module &M,
23662298
ModuleAnalysisManager &AM) {
23672299
bool Changed;
23682300
if (UseCommandLine)
2369-
Changed = LowerTypeTestsModule::runForTesting(M, AM);
2301+
Changed = LowerTypeTestsModule::runForTesting(M);
23702302
else
23712303
Changed =
2372-
LowerTypeTestsModule(M, AM, ExportSummary, ImportSummary, DropTypeTests)
2304+
LowerTypeTestsModule(M, ExportSummary, ImportSummary, DropTypeTests)
23732305
.lower();
23742306
if (!Changed)
23752307
return PreservedAnalyses::all();

llvm/test/Transforms/LowerTypeTests/function-arm-thumb.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
target datalayout = "e-p:64:64"
44

5-
define void @f1() "target-features"="+thumb-mode,+v6t2" !type !0 {
5+
define void @f1() "target-features"="+thumb-mode" !type !0 {
66
ret void
77
}
88

0 commit comments

Comments
 (0)