@@ -834,6 +834,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
834
834
// / # of this BB)
835
835
// / br x0 # Indirect jump instruction
836
836
// /
837
+ // / Return true on successful jump table instruction sequence match, false
838
+ // / otherwise.
837
839
bool analyzeIndirectBranchFragment (
838
840
const MCInst &Inst,
839
841
DenseMap<const MCInst *, SmallVector<MCInst *, 4 >> &UDChain,
@@ -842,6 +844,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
842
844
// Expect AArch64 BR
843
845
assert (Inst.getOpcode () == AArch64::BR && " Unexpected opcode" );
844
846
847
+ JumpTable = nullptr ;
848
+
845
849
// Match the indirect branch pattern for aarch64
846
850
SmallVector<MCInst *, 4 > &UsesRoot = UDChain[&Inst];
847
851
if (UsesRoot.size () == 0 || UsesRoot[0 ] == nullptr )
@@ -879,8 +883,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
879
883
// Parsed as ADDXrs reg:x8 reg:x8 reg:x12 imm:0
880
884
return false ;
881
885
}
882
- assert (DefAdd->getOpcode () == AArch64::ADDXrx &&
883
- " Failed to match indirect branch! " ) ;
886
+ if (DefAdd->getOpcode () != AArch64::ADDXrx)
887
+ return false ;
884
888
885
889
// Validate ADD operands
886
890
int64_t OperandExtension = DefAdd->getOperand (3 ).getImm ();
@@ -897,8 +901,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
897
901
// ldr w7, [x6]
898
902
// add x6, x6, w7, sxtw => no shift amount
899
903
// br x6
900
- errs ( ) << " BOLT-WARNING : "
901
- " Failed to match indirect branch: ShiftVAL != 2 \n " ;
904
+ LLVM_DEBUG ( dbgs ( ) << " BOLT-DEBUG : "
905
+ " failed to match indirect branch: ShiftVAL != 2\n " ) ;
902
906
return false ;
903
907
}
904
908
@@ -909,7 +913,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
909
913
else if (ExtendType == AArch64_AM::SXTW)
910
914
ScaleValue = 4LL ;
911
915
else
912
- llvm_unreachable ( " Failed to match indirect branch! (fragment 3) " ) ;
916
+ return false ;
913
917
914
918
// Match an ADR to load base address to be used when addressing JT targets
915
919
SmallVector<MCInst *, 4 > &UsesAdd = UDChain[DefAdd];
@@ -920,18 +924,15 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
920
924
return false ;
921
925
}
922
926
MCInst *DefBaseAddr = UsesAdd[1 ];
923
- assert (DefBaseAddr->getOpcode () == AArch64::ADR &&
924
- " Failed to match indirect branch pattern! (fragment 3) " ) ;
927
+ if (DefBaseAddr->getOpcode () != AArch64::ADR)
928
+ return false ;
925
929
926
930
PCRelBase = DefBaseAddr;
927
931
// Match LOAD to load the jump table (relative) target
928
932
const MCInst *DefLoad = UsesAdd[2 ];
929
- assert (mayLoad (*DefLoad) &&
930
- " Failed to match indirect branch load pattern! (1)" );
931
- assert ((ScaleValue != 1LL || isLDRB (*DefLoad)) &&
932
- " Failed to match indirect branch load pattern! (2)" );
933
- assert ((ScaleValue != 2LL || isLDRH (*DefLoad)) &&
934
- " Failed to match indirect branch load pattern! (3)" );
933
+ if (!mayLoad (*DefLoad) || (ScaleValue == 1LL && !isLDRB (*DefLoad)) ||
934
+ (ScaleValue == 2LL && !isLDRH (*DefLoad)))
935
+ return false ;
935
936
936
937
// Match ADD that calculates the JumpTable Base Address (not the offset)
937
938
SmallVector<MCInst *, 4 > &UsesLoad = UDChain[DefLoad];
@@ -941,7 +942,6 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
941
942
isRegToRegMove (*DefJTBaseAdd, From, To)) {
942
943
// Sometimes base address may have been defined in another basic block
943
944
// (hoisted). Return with no jump table info.
944
- JumpTable = nullptr ;
945
945
return true ;
946
946
}
947
947
@@ -953,24 +953,27 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
953
953
// adr x12, 0x247b30 <__gettextparse+0x5b0>
954
954
// add x13, x12, w13, sxth #2
955
955
// br x13
956
- errs ( ) << " BOLT-WARNING: Failed to match indirect branch: "
957
- " nop/adr instead of adrp/add \n " ;
956
+ LLVM_DEBUG ( dbgs ( ) << " BOLT-DEBUG: failed to match indirect branch: "
957
+ " nop/adr instead of adrp/add\n " ) ;
958
958
return false ;
959
959
}
960
960
961
- assert (DefJTBaseAdd->getOpcode () == AArch64::ADDXri &&
962
- " Failed to match jump table base address pattern! (1)" );
961
+ if (DefJTBaseAdd->getOpcode () != AArch64::ADDXri) {
962
+ LLVM_DEBUG (dbgs () << " BOLT-DEBUG: failed to match jump table base "
963
+ " address pattern! (1)\n " );
964
+ return false ;
965
+ }
963
966
964
967
if (DefJTBaseAdd->getOperand (2 ).isImm ())
965
968
Offset = DefJTBaseAdd->getOperand (2 ).getImm ();
966
969
SmallVector<MCInst *, 4 > &UsesJTBaseAdd = UDChain[DefJTBaseAdd];
967
970
const MCInst *DefJTBasePage = UsesJTBaseAdd[1 ];
968
971
if (DefJTBasePage == nullptr || isLoadFromStack (*DefJTBasePage)) {
969
- JumpTable = nullptr ;
970
972
return true ;
971
973
}
972
- assert (DefJTBasePage->getOpcode () == AArch64::ADRP &&
973
- " Failed to match jump table base page pattern! (2)" );
974
+ if (DefJTBasePage->getOpcode () != AArch64::ADRP)
975
+ return false ;
976
+
974
977
if (DefJTBasePage->getOperand (1 ).isExpr ())
975
978
JumpTable = DefJTBasePage->getOperand (1 ).getExpr ();
976
979
return true ;
0 commit comments