blob: 46794256c27bde1d6d4154ab6b6cc1a9a231af82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
//===-- AutoUpgrade.cpp - Implement auto-upgrade helper functions ---------===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Reid Spencer and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the auto-upgrade helper functions
//
//===----------------------------------------------------------------------===//
#include "llvm/Assembly/AutoUpgrade.h"
#include "llvm/Function.h"
#include "llvm/Type.h"
#include <iostream>
using namespace llvm;
// UpgradeIntrinsicFunction - Convert overloaded intrinsic function names to
// their non-overloaded variants by appending the appropriate suffix based on
// the argument types.
bool llvm::UpgradeIntrinsicFunction(Function* F) {
// Get the Function's name.
const std::string& Name = F->getName();
// Quickly eliminate it, if it's not a candidate.
if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' || Name[2] !=
'v' || Name[3] != 'm' || Name[4] != '.')
return false;
// See if its one of the name's we're interested in.
switch (Name[5]) {
case 'b':
if (Name == "llvm.bswap") {
const Type* Ty = F->getReturnType();
std::string new_name = Name;
if (Ty == Type::UShortTy || Ty == Type::ShortTy)
new_name += ".i16";
else if (Ty == Type::UIntTy || Ty == Type::IntTy)
new_name += ".i32";
else if (Ty == Type::ULongTy || Ty == Type::LongTy)
new_name += ".i64";
std::cerr << "WARNING: change " << Name << " to "
<< new_name << "\n";
F->setName(new_name);
return true;
}
break;
case 'c':
if (Name == "llvm.ctpop" || Name == "llvm.ctlz" ||
Name == "llvm.cttz") {
const Type* Ty = F->getReturnType();
std::string new_name = Name;
if (Ty == Type::UByteTy || Ty == Type::SByteTy)
new_name += ".i8";
else if (Ty == Type::UShortTy || Ty == Type::ShortTy)
new_name += ".i16";
else if (Ty == Type::UIntTy || Ty == Type::IntTy)
new_name += ".i32";
else if (Ty == Type::ULongTy || Ty == Type::LongTy)
new_name += ".i64";
std::cerr << "WARNING: change " << Name << " to "
<< new_name << "\n";
F->setName(new_name);
return true;
}
break;
case 'i':
if (Name == "llvm.isunordered") {
Function::const_arg_iterator ArgIt = F->arg_begin();
const Type* Ty = ArgIt->getType();
std::string new_name = Name;
if (Ty == Type::FloatTy)
new_name += ".f32";
else if (Ty == Type::DoubleTy)
new_name += ".f64";
std::cerr << "WARNING: change " << Name << " to "
<< new_name << "\n";
F->setName(new_name);
return true;
}
break;
case 's':
if (Name == "llvm.sqrt") {
const Type* Ty = F->getReturnType();
std::string new_name = Name;
if (Ty == Type::FloatTy)
new_name += ".f32";
else if (Ty == Type::DoubleTy) {
new_name += ".f64";
}
std::cerr << "WARNING: change " << Name << " to "
<< new_name << "\n";
F->setName(new_name);
return true;
}
break;
default:
break;
}
return false;
}
|