@@ -834,6 +834,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
834834 // / # of this BB)
835835 // / br x0 # Indirect jump instruction
836836 // /
837+ // / Return true on successful jump table instruction sequence match, false
838+ // / otherwise.
837839 bool analyzeIndirectBranchFragment (
838840 const MCInst &Inst,
839841 DenseMap<const MCInst *, SmallVector<MCInst *, 4 >> &UDChain,
@@ -842,6 +844,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
842844 // Expect AArch64 BR
843845 assert (Inst.getOpcode () == AArch64::BR && " Unexpected opcode" );
844846
847+ JumpTable = nullptr ;
848+
845849 // Match the indirect branch pattern for aarch64
846850 SmallVector<MCInst *, 4 > &UsesRoot = UDChain[&Inst];
847851 if (UsesRoot.size () == 0 || UsesRoot[0 ] == nullptr )
@@ -879,8 +883,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
879883 // Parsed as ADDXrs reg:x8 reg:x8 reg:x12 imm:0
880884 return false ;
881885 }
882- assert (DefAdd->getOpcode () == AArch64::ADDXrx &&
883- " Failed to match indirect branch! " ) ;
886+ if (DefAdd->getOpcode () != AArch64::ADDXrx)
887+ return false ;
884888
885889 // Validate ADD operands
886890 int64_t OperandExtension = DefAdd->getOperand (3 ).getImm ();
@@ -897,8 +901,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
897901 // ldr w7, [x6]
898902 // add x6, x6, w7, sxtw => no shift amount
899903 // 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 " ) ;
902906 return false ;
903907 }
904908
@@ -909,7 +913,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
909913 else if (ExtendType == AArch64_AM::SXTW)
910914 ScaleValue = 4LL ;
911915 else
912- llvm_unreachable ( " Failed to match indirect branch! (fragment 3) " ) ;
916+ return false ;
913917
914918 // Match an ADR to load base address to be used when addressing JT targets
915919 SmallVector<MCInst *, 4 > &UsesAdd = UDChain[DefAdd];
@@ -920,18 +924,15 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
920924 return false ;
921925 }
922926 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 ;
925929
926930 PCRelBase = DefBaseAddr;
927931 // Match LOAD to load the jump table (relative) target
928932 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 ;
935936
936937 // Match ADD that calculates the JumpTable Base Address (not the offset)
937938 SmallVector<MCInst *, 4 > &UsesLoad = UDChain[DefLoad];
@@ -941,7 +942,6 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
941942 isRegToRegMove (*DefJTBaseAdd, From, To)) {
942943 // Sometimes base address may have been defined in another basic block
943944 // (hoisted). Return with no jump table info.
944- JumpTable = nullptr ;
945945 return true ;
946946 }
947947
@@ -953,24 +953,27 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
953953 // adr x12, 0x247b30 <__gettextparse+0x5b0>
954954 // add x13, x12, w13, sxth #2
955955 // 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 " ) ;
958958 return false ;
959959 }
960960
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+ }
963966
964967 if (DefJTBaseAdd->getOperand (2 ).isImm ())
965968 Offset = DefJTBaseAdd->getOperand (2 ).getImm ();
966969 SmallVector<MCInst *, 4 > &UsesJTBaseAdd = UDChain[DefJTBaseAdd];
967970 const MCInst *DefJTBasePage = UsesJTBaseAdd[1 ];
968971 if (DefJTBasePage == nullptr || isLoadFromStack (*DefJTBasePage)) {
969- JumpTable = nullptr ;
970972 return true ;
971973 }
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+
974977 if (DefJTBasePage->getOperand (1 ).isExpr ())
975978 JumpTable = DefJTBasePage->getOperand (1 ).getExpr ();
976979 return true ;
@@ -1263,7 +1266,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
12631266 return true ;
12641267 }
12651268
1266- InstructionListType createIndirectPltCall ( const MCInst &DirectCall,
1269+ InstructionListType createIndirectPLTCall ( MCInst & &DirectCall,
12671270 const MCSymbol *TargetLocation,
12681271 MCContext *Ctx) override {
12691272 const bool IsTailCall = isTailCall (DirectCall);
@@ -1297,8 +1300,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
12971300 MCInst InstCall;
12981301 InstCall.setOpcode (IsTailCall ? AArch64::BR : AArch64::BLR);
12991302 InstCall.addOperand (MCOperand::createReg (AArch64::X17));
1300- if (IsTailCall)
1301- setTailCall (InstCall);
1303+ moveAnnotations (std::move (DirectCall), InstCall);
13021304 Code.emplace_back (InstCall);
13031305
13041306 return Code;
0 commit comments