136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===- AutoUpgrade.h - AutoUpgrade Helpers ----------------------*- C++ -*-===//
26994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth//
36994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth//                     The LLVM Compiler Infrastructure
46994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
76994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth//
86994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth//===----------------------------------------------------------------------===//
96994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth//
103f49322818a3f2b9ca6fe75f49c7541c8dfb538dMatt Arsenault//  These functions are implemented by lib/IR/AutoUpgrade.cpp.
116994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth//
126994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth//===----------------------------------------------------------------------===//
136994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth
1436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#ifndef LLVM_IR_AUTOUPGRADE_H
1536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#define LLVM_IR_AUTOUPGRADE_H
166994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth
17cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines#include <string>
18cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
196994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruthnamespace llvm {
201572ba716bad4944a83040adef76c186c4841e95Matt Arsenault  class CallInst;
2159d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  class Constant;
226994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth  class Function;
23804f034bd18789e9bbf4c70c10189dd6dbf04128Manman Ren  class Instruction;
241572ba716bad4944a83040adef76c186c4841e95Matt Arsenault  class Module;
251572ba716bad4944a83040adef76c186c4841e95Matt Arsenault  class GlobalVariable;
2659d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  class Type;
271572ba716bad4944a83040adef76c186c4841e95Matt Arsenault  class Value;
286994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth
293f49322818a3f2b9ca6fe75f49c7541c8dfb538dMatt Arsenault  /// This is a more granular function that simply checks an intrinsic function
30f9b83fcf95e8a280d7b117af8858596fe5b10d94Evan Cheng  /// for upgrading, and returns true if it requires upgrading. It may return
31f9b83fcf95e8a280d7b117af8858596fe5b10d94Evan Cheng  /// null in NewFn if the all calls to the original intrinsic function
32f9b83fcf95e8a280d7b117af8858596fe5b10d94Evan Cheng  /// should be transformed to non-function-call instructions.
33f9b83fcf95e8a280d7b117af8858596fe5b10d94Evan Cheng  bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn);
346994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth
353f49322818a3f2b9ca6fe75f49c7541c8dfb538dMatt Arsenault  /// This is the complement to the above, replacing a specific call to an
366994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth  /// intrinsic function with a call to the specified new function.
376994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth  void UpgradeIntrinsicCall(CallInst *CI, Function *NewFn);
383f49322818a3f2b9ca6fe75f49c7541c8dfb538dMatt Arsenault
393f49322818a3f2b9ca6fe75f49c7541c8dfb538dMatt Arsenault  /// This is an auto-upgrade hook for any old intrinsic function syntaxes
403f49322818a3f2b9ca6fe75f49c7541c8dfb538dMatt Arsenault  /// which need to have both the function updated as well as all calls updated
413f49322818a3f2b9ca6fe75f49c7541c8dfb538dMatt Arsenault  /// to the new function. This should only be run in a post-processing fashion
426994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth  /// so that it can update all calls to the old function.
436994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth  void UpgradeCallsToIntrinsic(Function* F);
446994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth
45de49f360ec4780acb382a3ae923d1716fdb0dc03Bill Wendling  /// This checks for global variables which should be upgraded. It returns true
46de49f360ec4780acb382a3ae923d1716fdb0dc03Bill Wendling  /// if it requires upgrading.
47de49f360ec4780acb382a3ae923d1716fdb0dc03Bill Wendling  bool UpgradeGlobalVariable(GlobalVariable *GV);
48804f034bd18789e9bbf4c70c10189dd6dbf04128Manman Ren
49804f034bd18789e9bbf4c70c10189dd6dbf04128Manman Ren  /// If the TBAA tag for the given instruction uses the scalar TBAA format,
50804f034bd18789e9bbf4c70c10189dd6dbf04128Manman Ren  /// we upgrade it to the struct-path aware TBAA format.
51804f034bd18789e9bbf4c70c10189dd6dbf04128Manman Ren  void UpgradeInstWithTBAATag(Instruction *I);
5259d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault
5359d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  /// This is an auto-upgrade for bitcast between pointers with different
5459d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  /// address spaces: the instruction is replaced by a pair ptrtoint+inttoptr.
5559d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  Instruction *UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy,
5659d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault                                  Instruction *&Temp);
5759d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault
5859d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  /// This is an auto-upgrade for bitcast constant expression between pointers
5959d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  /// with different address spaces: the instruction is replaced by a pair
6059d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  /// ptrtoint+inttoptr.
6159d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  Value *UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy);
6227457ac42f7a9267ab7e0190424a95fecf0ea201Manman Ren
6327457ac42f7a9267ab7e0190424a95fecf0ea201Manman Ren  /// Check the debug info version number, if it is out-dated, drop the debug
6427457ac42f7a9267ab7e0190424a95fecf0ea201Manman Ren  /// info. Return true if module is modified.
6527457ac42f7a9267ab7e0190424a95fecf0ea201Manman Ren  bool UpgradeDebugInfo(Module &M);
66cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
67cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// Upgrade a metadata string constant in place.
68cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  void UpgradeMDStringConstant(std::string &String);
696994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth} // End llvm namespace
706994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth
716994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth#endif
72