//===-- 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) {