1 //===-- AutoUpgrade.cpp - Implement auto-upgrade helper functions ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the auto-upgrade helper functions
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Assembly/AutoUpgrade.h"
15 #include "llvm/Function.h"
16 #include "llvm/Type.h"
21 // UpgradeIntrinsicFunction - Convert overloaded intrinsic function names to
22 // their non-overloaded variants by appending the appropriate suffix based on
23 // the argument types.
24 bool llvm::UpgradeIntrinsicFunction(Function* F) {
26 // Get the Function's name.
27 const std::string& Name = F->getName();
29 // Quickly eliminate it, if it's not a candidate.
30 if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' || Name[2] !=
31 'v' || Name[3] != 'm' || Name[4] != '.')
34 // See if its one of the name's we're interested in.
37 if (Name == "llvm.bswap") {
38 const Type* Ty = F->getReturnType();
39 std::string new_name = Name;
40 if (Ty == Type::UShortTy || Ty == Type::ShortTy)
42 else if (Ty == Type::UIntTy || Ty == Type::IntTy)
44 else if (Ty == Type::ULongTy || Ty == Type::LongTy)
46 std::cerr << "WARNING: change " << Name << " to "
53 if (Name == "llvm.ctpop" || Name == "llvm.ctlz" ||
54 Name == "llvm.cttz") {
55 const Type* Ty = F->getReturnType();
56 std::string new_name = Name;
57 if (Ty == Type::UByteTy || Ty == Type::SByteTy)
59 else if (Ty == Type::UShortTy || Ty == Type::ShortTy)
61 else if (Ty == Type::UIntTy || Ty == Type::IntTy)
63 else if (Ty == Type::ULongTy || Ty == Type::LongTy)
65 std::cerr << "WARNING: change " << Name << " to "
72 if (Name == "llvm.isunordered") {
73 Function::const_arg_iterator ArgIt = F->arg_begin();
74 const Type* Ty = ArgIt->getType();
75 std::string new_name = Name;
76 if (Ty == Type::FloatTy)
78 else if (Ty == Type::DoubleTy)
80 std::cerr << "WARNING: change " << Name << " to "
87 if (Name == "llvm.sqrt") {
88 const Type* Ty = F->getReturnType();
89 std::string new_name = Name;
90 if (Ty == Type::FloatTy)
92 else if (Ty == Type::DoubleTy) {
95 std::cerr << "WARNING: change " << Name << " to "