//===-- AutoUpgrade.cpp - Implement auto-upgrade helper functions ---------===//
//
// The LLVM Compiler Infrastructure
//
// This file 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/AutoUpgrade.h"
#include "llvm/Constants.h"
#include "llvm/Function.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/CallSite.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/IRBuilder.h"
#include <cstring>
using namespace llvm;
static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
assert(F && "Illegal to upgrade a non-existent Function.");
// Get the Function's name.
const std::string& Name = F->getName();
// Convenience
const FunctionType *FTy = F->getFunctionType();
// Quickly eliminate it, if it's not a candidate.
if (Name.length() <= 8 || Name[0] != 'l' || Name[1] != 'l' ||
Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
return false;
Module *M = F->getParent();
switch (Name[5]) {
default: break;
case 'a':
// This upgrades the llvm.atomic.lcs, llvm.atomic.las, llvm.atomic.lss,
// and atomics with default address spaces to their new names to their new
// function name (e.g. llvm.atomic.add.i32 => llvm.atomic.add.i32.p0i32)
if (Name.compare(5,7,"atomic.",7) == 0) {
if (Name.compare(12,3,"lcs",3) == 0) {
std::string::size_type delim = Name.find('.',12);
F->setName("llvm.atomic.cmp.swap" + Name.substr(delim) +
".p0" + Name.substr(delim+1));
NewFn = F;
return true;
}
else if (Name.compare(12,3,"las",3) == 0) {
std::string::size_type delim = Name.find('.',12);
F->setName("llvm.atomic.load.add"+Name.substr(delim)
+ ".p0" + Name.substr(delim+1));
NewFn = F;
return true;
}
else if (Name.compare(12,3,"lss",3) == 0) {
std::string::size_type delim = Name.find('.',12);
F->setName("llvm.atomic.load.sub"+Name.substr(delim)
+ ".p0" + Name.substr(delim+1));
NewFn = F;
return true;
}
else if (Name.rfind(".p") == std::string::npos) {
// We don't have an address space qualifier so this has be upgraded
// to the new name. Copy the type name at the end of the intrinsic
// and add to it
std::string::size_type delim = Name.find_last_of('.');
assert(delim != std::string::npos && "can not find type");
F->setName(Name + ".p0" + Name.substr(delim+1));
NewFn = F;
return true;
}
} else if (Name.compare(5, 9, "arm.neon.", 9) == 0) {
if (((Name.compare(14, 5, "vmovl", 5) == 0 ||
Name.compare(14, 5, "vaddl", 5) == 0 ||
Name.compare(14, 5, "vsubl", 5) == 0 ||
Name.compare(14, 5, "vaddw", 5) == 0 ||
Name.compare(14, 5, "vsubw", 5) == 0 ||
Name.compare(14, 5, "vmull", 5) == 0 ||
Name.compare(14, 5, "vmlal", 5) == 0 ||
Name.compare(14, 5, "vmlsl", 5) == 0 ||
Name.compare(14, 5, "vabdl", 5) ==