[X86-64] Fix bugs in return type deduction analysis.
[Test] Add test from Issue 169.
This commit is contained in:
Родитель
b3f59f8929
Коммит
b5a458ff19
|
@ -166,17 +166,6 @@ Type *X86MachineInstructionRaiser::getFunctionReturnType() {
|
|||
returnType = getReachingReturnType(*MBB);
|
||||
}
|
||||
|
||||
// If we are unable to discover the return type, check if return register is
|
||||
// defined.
|
||||
if (returnType == nullptr) {
|
||||
for (MachineBasicBlock &MBB : MF) {
|
||||
auto DiscoveredReturnType = getReachingReturnType(MBB);
|
||||
if (DiscoveredReturnType != nullptr) {
|
||||
returnType = DiscoveredReturnType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If return type is still not discovered, assume it to be void
|
||||
if (returnType == nullptr)
|
||||
returnType = Type::getVoidTy(MF.getFunction().getContext());
|
||||
|
@ -561,12 +550,16 @@ Type *X86MachineInstructionRaiser::getReachingReturnType(
|
|||
BlockVisited.set(CurPredMBBNo);
|
||||
// Get function return type from MBB
|
||||
ReturnTypeOnPath = getReturnTypeFromMBB(*PredMBB, HasCall);
|
||||
// Check out whether the ReturnType get from called instruction.
|
||||
// Only keep the first find called function return type, continue
|
||||
// to find other reach tree which has not call instruction.
|
||||
// If the MBB has no call instruction and return type is not found,
|
||||
// continue traversal up its predecessors.
|
||||
// If PredMBB has no call and has no return register definition,
|
||||
// continue traversal.
|
||||
if (!HasCall && ReturnTypeOnPath == nullptr) {
|
||||
// If PredMBB is the entry block and return type is not found, it
|
||||
// implies that there is at least one path that doesn't set return
|
||||
// register. Hence, there is no further need for further traversal.
|
||||
if (PredMBB->isEntryBlock()) {
|
||||
ReturnType = nullptr;
|
||||
break;
|
||||
}
|
||||
// Continue traversal
|
||||
for (auto Pred : PredMBB->predecessors()) {
|
||||
if (!BlockVisited[Pred->getNumber()])
|
||||
|
@ -631,11 +624,11 @@ X86MachineInstructionRaiser::getReturnTypeFromMBB(const MachineBasicBlock &MBB,
|
|||
if (I->isReturn())
|
||||
continue;
|
||||
|
||||
// No need to inspect padding instructions. ld uses nop and lld uses int3 for
|
||||
// alignment padding in text section.
|
||||
// No need to inspect padding instructions. ld uses nop and lld uses int3
|
||||
// for alignment padding in text section.
|
||||
auto Opcode = I->getOpcode();
|
||||
if (isNoop(Opcode) || (Opcode == X86::INT3))
|
||||
continue;
|
||||
continue;
|
||||
|
||||
unsigned DefReg = X86::NoRegister;
|
||||
const TargetRegisterInfo *TRI = MF.getRegInfo().getTargetRegisterInfo();
|
||||
|
|
|
@ -251,7 +251,8 @@ Value *X86MachineInstructionRaiser::loadMemoryRefValue(
|
|||
bool X86MachineInstructionRaiser::deleteNOOPInstrMI(
|
||||
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
|
||||
MachineInstr &MI = *MBBI;
|
||||
if (isNoop(MI.getOpcode())) {
|
||||
auto Opcode = MI.getOpcode();
|
||||
if (isNoop(Opcode) || Opcode == X86::INT3) {
|
||||
MBB.remove(&MI);
|
||||
return true;
|
||||
}
|
||||
|
@ -939,8 +940,9 @@ StoreInst *X86MachineInstructionRaiser::promotePhysregToStackSlot(
|
|||
StackLocTy = Type::getIntNTy(Ctxt, StackLocSzInBits);
|
||||
} else if (ReachingValue->getType()->isFloatingPointTy() ||
|
||||
ReachingValue->getType()->isVectorTy()) {
|
||||
assert(StackLocSzInBits == 128 &&
|
||||
"Expected FP types and vectors to be stored in 128 bit stack location");
|
||||
assert(
|
||||
StackLocSzInBits == 128 &&
|
||||
"Expected FP types and vectors to be stored in 128 bit stack location");
|
||||
StackLocTy = VectorType::get(Type::getInt32Ty(Ctxt), 4, false);
|
||||
} else {
|
||||
llvm_unreachable("Unhandled type");
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// REQUIRES: system-linux
|
||||
// RUN: clang -O3 -o %t %s
|
||||
// RUN: llvm-mctoll -d -I /usr/include/stdio.h %t
|
||||
// RUN: clang -o %t-dis %t-dis.ll
|
||||
// RUN: %t-dis 2>&1 | FileCheck %s
|
||||
// CHECK: 0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999
|
||||
// CHECK-EMPTY
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void foo() {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
printf("%d", i);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
int main() {
|
||||
foo();
|
||||
return 0;
|
||||
}
|
Загрузка…
Ссылка в новой задаче