llvm.org GIT mirror llvm / bf2712a
To allow the X86 verbose assembly to print its informative comments when used with symbolic disassembly, add a check that the operand is an immediate and has not been symbolicated to MCExpr operand. I’m trying to enable the ‘C’ disassembly API option LLVMDisassembler_Option_SetInstrComments for darwin’s otool(1) that uses the llvm disassembler API. The problem is that the disassembler API can change an immediate operand to an MCExpr operand if it symbolicates it with the call backs. And if it does the code in llvm::EmitAnyX86InstComments() will crash when it assumes these operands are immediates. The fix for this is very straight forward to just protect the call to getImm() with a check of isImm(). So if the immediate for an instruction is symbolicated it simply doesn’t get the X86 verbose assembly comments: % otool -tV test_asm.o test_asm.o: (__TEXT,__text) section _t1: 0000000000000000 vpshufd $_t1, %xmm1, %xmm0 0000000000000005 retq 0000000000000006 nopw %cs:_t1(%rax,%rax) _t2: 0000000000000010 vpshufd $-0x1, %xmm0, %xmm0 ## xmm0 = xmm0[3,3,3,3] 0000000000000015 retq 0000000000000016 nopw %cs:_t1(%rax,%rax) _t3: 0000000000000020 vpshufd $_t1, %xmm1, %xmm0 0000000000000025 retq 0000000000000026 nopw %cs:_t1(%rax,%rax) _t4: 0000000000000030 vpshufd $0x2d, %xmm0, %xmm0 ## xmm0 = xmm0[1,3,2,0] 0000000000000035 retq The fact that the immediate $0x0 is being symbolicated at all in this case is a different problem which my next patch will address. rdar://10989286 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199697 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 6 years ago
1 changed file(s) with 73 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
3737 DestName = getRegName(MI->getOperand(0).getReg());
3838 Src1Name = getRegName(MI->getOperand(1).getReg());
3939 Src2Name = getRegName(MI->getOperand(2).getReg());
40 DecodeINSERTPSMask(MI->getOperand(3).getImm(), ShuffleMask);
40 if(MI->getOperand(3).isImm())
41 DecodeINSERTPSMask(MI->getOperand(3).getImm(), ShuffleMask);
4142 break;
4243
4344 case X86::MOVLHPSrr:
6465 case X86::VPALIGNR128rm:
6566 Src2Name = getRegName(MI->getOperand(1).getReg());
6667 DestName = getRegName(MI->getOperand(0).getReg());
67 DecodePALIGNRMask(MVT::v16i8,
68 MI->getOperand(MI->getNumOperands()-1).getImm(),
69 ShuffleMask);
68 if(MI->getOperand(MI->getNumOperands()-1).isImm())
69 DecodePALIGNRMask(MVT::v16i8,
70 MI->getOperand(MI->getNumOperands()-1).getImm(),
71 ShuffleMask);
7072 break;
7173 case X86::VPALIGNR256rr:
7274 Src1Name = getRegName(MI->getOperand(2).getReg());
7476 case X86::VPALIGNR256rm:
7577 Src2Name = getRegName(MI->getOperand(1).getReg());
7678 DestName = getRegName(MI->getOperand(0).getReg());
77 DecodePALIGNRMask(MVT::v32i8,
78 MI->getOperand(MI->getNumOperands()-1).getImm(),
79 ShuffleMask);
79 if(MI->getOperand(MI->getNumOperands()-1).isImm())
80 DecodePALIGNRMask(MVT::v32i8,
81 MI->getOperand(MI->getNumOperands()-1).getImm(),
82 ShuffleMask);
8083 break;
8184
8285 case X86::PSHUFDri:
8689 case X86::PSHUFDmi:
8790 case X86::VPSHUFDmi:
8891 DestName = getRegName(MI->getOperand(0).getReg());
89 DecodePSHUFMask(MVT::v4i32, MI->getOperand(MI->getNumOperands()-1).getImm(),
90 ShuffleMask);
92 if(MI->getOperand(MI->getNumOperands()-1).isImm())
93 DecodePSHUFMask(MVT::v4i32,
94 MI->getOperand(MI->getNumOperands()-1).getImm(),
95 ShuffleMask);
9196 break;
9297 case X86::VPSHUFDYri:
9398 Src1Name = getRegName(MI->getOperand(1).getReg());
9499 // FALL THROUGH.
95100 case X86::VPSHUFDYmi:
96101 DestName = getRegName(MI->getOperand(0).getReg());
97 DecodePSHUFMask(MVT::v8i32, MI->getOperand(MI->getNumOperands()-1).getImm(),
98 ShuffleMask);
102 if(MI->getOperand(MI->getNumOperands()-1).isImm())
103 DecodePSHUFMask(MVT::v8i32,
104 MI->getOperand(MI->getNumOperands()-1).getImm(),
105 ShuffleMask);
99106 break;
100107
101108
106113 case X86::PSHUFHWmi:
107114 case X86::VPSHUFHWmi:
108115 DestName = getRegName(MI->getOperand(0).getReg());
109 DecodePSHUFHWMask(MVT::v8i16,
110 MI->getOperand(MI->getNumOperands()-1).getImm(),
111 ShuffleMask);
116 if(MI->getOperand(MI->getNumOperands()-1).isImm())
117 DecodePSHUFHWMask(MVT::v8i16,
118 MI->getOperand(MI->getNumOperands()-1).getImm(),
119 ShuffleMask);
112120 break;
113121 case X86::VPSHUFHWYri:
114122 Src1Name = getRegName(MI->getOperand(1).getReg());
115123 // FALL THROUGH.
116124 case X86::VPSHUFHWYmi:
117125 DestName = getRegName(MI->getOperand(0).getReg());
118 DecodePSHUFHWMask(MVT::v16i16,
119 MI->getOperand(MI->getNumOperands()-1).getImm(),
120 ShuffleMask);
126 if(MI->getOperand(MI->getNumOperands()-1).isImm())
127 DecodePSHUFHWMask(MVT::v16i16,
128 MI->getOperand(MI->getNumOperands()-1).getImm(),
129 ShuffleMask);
121130 break;
122131 case X86::PSHUFLWri:
123132 case X86::VPSHUFLWri:
126135 case X86::PSHUFLWmi:
127136 case X86::VPSHUFLWmi:
128137 DestName = getRegName(MI->getOperand(0).getReg());
129 DecodePSHUFLWMask(MVT::v8i16,
130 MI->getOperand(MI->getNumOperands()-1).getImm(),
131 ShuffleMask);
138 if(MI->getOperand(MI->getNumOperands()-1).isImm())
139 DecodePSHUFLWMask(MVT::v8i16,
140 MI->getOperand(MI->getNumOperands()-1).getImm(),
141 ShuffleMask);
132142 break;
133143 case X86::VPSHUFLWYri:
134144 Src1Name = getRegName(MI->getOperand(1).getReg());
135145 // FALL THROUGH.
136146 case X86::VPSHUFLWYmi:
137147 DestName = getRegName(MI->getOperand(0).getReg());
138 DecodePSHUFLWMask(MVT::v16i16,
139 MI->getOperand(MI->getNumOperands()-1).getImm(),
140 ShuffleMask);
148 if(MI->getOperand(MI->getNumOperands()-1).isImm())
149 DecodePSHUFLWMask(MVT::v16i16,
150 MI->getOperand(MI->getNumOperands()-1).getImm(),
151 ShuffleMask);
141152 break;
142153
143154 case X86::PUNPCKHBWrr:
292303 // FALL THROUGH.
293304 case X86::SHUFPDrmi:
294305 case X86::VSHUFPDrmi:
295 DecodeSHUFPMask(MVT::v2f64, MI->getOperand(MI->getNumOperands()-1).getImm(),
296 ShuffleMask);
306 if(MI->getOperand(MI->getNumOperands()-1).isImm())
307 DecodeSHUFPMask(MVT::v2f64,
308 MI->getOperand(MI->getNumOperands()-1).getImm(),
309 ShuffleMask);
297310 Src1Name = getRegName(MI->getOperand(1).getReg());
298311 DestName = getRegName(MI->getOperand(0).getReg());
299312 break;
301314 Src2Name = getRegName(MI->getOperand(2).getReg());
302315 // FALL THROUGH.
303316 case X86::VSHUFPDYrmi:
304 DecodeSHUFPMask(MVT::v4f64, MI->getOperand(MI->getNumOperands()-1).getImm(),
305 ShuffleMask);
317 if(MI->getOperand(MI->getNumOperands()-1).isImm())
318 DecodeSHUFPMask(MVT::v4f64,
319 MI->getOperand(MI->getNumOperands()-1).getImm(),
320 ShuffleMask);
306321 Src1Name = getRegName(MI->getOperand(1).getReg());
307322 DestName = getRegName(MI->getOperand(0).getReg());
308323 break;
313328 // FALL THROUGH.
314329 case X86::SHUFPSrmi:
315330 case X86::VSHUFPSrmi:
316 DecodeSHUFPMask(MVT::v4f32, MI->getOperand(MI->getNumOperands()-1).getImm(),
317 ShuffleMask);
331 if(MI->getOperand(MI->getNumOperands()-1).isImm())
332 DecodeSHUFPMask(MVT::v4f32,
333 MI->getOperand(MI->getNumOperands()-1).getImm(),
334 ShuffleMask);
318335 Src1Name = getRegName(MI->getOperand(1).getReg());
319336 DestName = getRegName(MI->getOperand(0).getReg());
320337 break;
322339 Src2Name = getRegName(MI->getOperand(2).getReg());
323340 // FALL THROUGH.
324341 case X86::VSHUFPSYrmi:
325 DecodeSHUFPMask(MVT::v8f32, MI->getOperand(MI->getNumOperands()-1).getImm(),
326 ShuffleMask);
342 if(MI->getOperand(MI->getNumOperands()-1).isImm())
343 DecodeSHUFPMask(MVT::v8f32,
344 MI->getOperand(MI->getNumOperands()-1).getImm(),
345 ShuffleMask);
327346 Src1Name = getRegName(MI->getOperand(1).getReg());
328347 DestName = getRegName(MI->getOperand(0).getReg());
329348 break;
404423 Src1Name = getRegName(MI->getOperand(1).getReg());
405424 // FALL THROUGH.
406425 case X86::VPERMILPSmi:
407 DecodePSHUFMask(MVT::v4f32, MI->getOperand(MI->getNumOperands()-1).getImm(),
408 ShuffleMask);
426 if(MI->getOperand(MI->getNumOperands()-1).isImm())
427 DecodePSHUFMask(MVT::v4f32,
428 MI->getOperand(MI->getNumOperands()-1).getImm(),
429 ShuffleMask);
409430 DestName = getRegName(MI->getOperand(0).getReg());
410431 break;
411432 case X86::VPERMILPSYri:
412433 Src1Name = getRegName(MI->getOperand(1).getReg());
413434 // FALL THROUGH.
414435 case X86::VPERMILPSYmi:
415 DecodePSHUFMask(MVT::v8f32, MI->getOperand(MI->getNumOperands()-1).getImm(),
416 ShuffleMask);
436 if(MI->getOperand(MI->getNumOperands()-1).isImm())
437 DecodePSHUFMask(MVT::v8f32,
438 MI->getOperand(MI->getNumOperands()-1).getImm(),
439 ShuffleMask);
417440 DestName = getRegName(MI->getOperand(0).getReg());
418441 break;
419442 case X86::VPERMILPDri:
420443 Src1Name = getRegName(MI->getOperand(1).getReg());
421444 // FALL THROUGH.
422445 case X86::VPERMILPDmi:
423 DecodePSHUFMask(MVT::v2f64, MI->getOperand(MI->getNumOperands()-1).getImm(),
424 ShuffleMask);
446 if(MI->getOperand(MI->getNumOperands()-1).isImm())
447 DecodePSHUFMask(MVT::v2f64,
448 MI->getOperand(MI->getNumOperands()-1).getImm(),
449 ShuffleMask);
425450 DestName = getRegName(MI->getOperand(0).getReg());
426451 break;
427452 case X86::VPERMILPDYri:
428453 Src1Name = getRegName(MI->getOperand(1).getReg());
429454 // FALL THROUGH.
430455 case X86::VPERMILPDYmi:
431 DecodePSHUFMask(MVT::v4f64, MI->getOperand(MI->getNumOperands()-1).getImm(),
432 ShuffleMask);
456 if(MI->getOperand(MI->getNumOperands()-1).isImm())
457 DecodePSHUFMask(MVT::v4f64,
458 MI->getOperand(MI->getNumOperands()-1).getImm(),
459 ShuffleMask);
433460 DestName = getRegName(MI->getOperand(0).getReg());
434461 break;
435462 case X86::VPERM2F128rr:
439466 case X86::VPERM2F128rm:
440467 case X86::VPERM2I128rm:
441468 // For instruction comments purpose, assume the 256-bit vector is v4i64.
442 DecodeVPERM2X128Mask(MVT::v4i64,
443 MI->getOperand(MI->getNumOperands()-1).getImm(),
444 ShuffleMask);
469 if(MI->getOperand(MI->getNumOperands()-1).isImm())
470 DecodeVPERM2X128Mask(MVT::v4i64,
471 MI->getOperand(MI->getNumOperands()-1).getImm(),
472 ShuffleMask);
445473 Src1Name = getRegName(MI->getOperand(1).getReg());
446474 DestName = getRegName(MI->getOperand(0).getReg());
447475 break;
451479 // FALL THROUGH.
452480 case X86::VPERMQYmi:
453481 case X86::VPERMPDYmi:
454 DecodeVPERMMask(MI->getOperand(MI->getNumOperands()-1).getImm(),
455 ShuffleMask);
482 if(MI->getOperand(MI->getNumOperands()-1).isImm())
483 DecodeVPERMMask(MI->getOperand(MI->getNumOperands()-1).getImm(),
484 ShuffleMask);
456485 DestName = getRegName(MI->getOperand(0).getReg());
457486 break;
458487 }