summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/CodeGen/IntrinsicLowering.h4
-rw-r--r--llvm/include/llvm/IR/DerivedTypes.h33
-rw-r--r--llvm/include/llvm/IR/IRBuilder.h23
-rw-r--r--llvm/include/llvm/IR/InstrTypes.h5
-rw-r--r--llvm/include/llvm/IR/Instructions.h59
-rw-r--r--llvm/include/llvm/IR/Module.h35
-rw-r--r--llvm/include/llvm/Transforms/Utils/ModuleUtils.h17
7 files changed, 62 insertions, 114 deletions
diff --git a/llvm/include/llvm/CodeGen/IntrinsicLowering.h b/llvm/include/llvm/CodeGen/IntrinsicLowering.h
index daf2d9a4780..5f8da028783 100644
--- a/llvm/include/llvm/CodeGen/IntrinsicLowering.h
+++ b/llvm/include/llvm/CodeGen/IntrinsicLowering.h
@@ -30,6 +30,10 @@ class IntrinsicLowering {
public:
explicit IntrinsicLowering(const DataLayout &DL) : DL(DL), Warned(false) {}
+ /// Add all of the prototypes that might be needed by an intrinsic lowering
+ /// implementation to be inserted into the module specified.
+ void AddPrototypes(Module &M);
+
/// Replace a call to the specified intrinsic function.
/// If an intrinsic function must be implemented by the code generator
/// (such as va_start), this function should print a message and abort.
diff --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index afea34d7d7a..f70f14e4901 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -157,39 +157,6 @@ unsigned Type::getFunctionNumParams() const {
return cast<FunctionType>(this)->getNumParams();
}
-/// A handy container for a FunctionType+Callee-pointer pair, which can be
-/// passed around as a single entity. This assists in replacing the use of
-/// PointerType::getElementType() to access the function's type, since that's
-/// slated for removal as part of the [opaque pointer types] project.
-class FunctionCallee {
-public:
- // Allow implicit conversion from types which have a getFunctionType member
- // (e.g. Function and InlineAsm).
- template <typename T,
- typename U = std::enable_if<(&T::getFunctionType != nullptr), void>>
- FunctionCallee(T *Fn)
- : FnTy(Fn ? Fn->getFunctionType() : nullptr), Callee(Fn) {}
-
- FunctionCallee(FunctionType *FnTy, Value *Callee)
- : FnTy(FnTy), Callee(Callee) {
- assert((FnTy == nullptr) == (Callee == nullptr));
- }
-
- FunctionCallee(std::nullptr_t) {}
-
- FunctionCallee() = default;
-
- FunctionType *getFunctionType() { return FnTy; }
-
- Value *getCallee() { return Callee; }
-
- explicit operator bool() { return Callee; }
-
-private:
- FunctionType *FnTy = nullptr;
- Value *Callee = nullptr;
-};
-
/// Common super class of ArrayType, StructType and VectorType.
class CompositeType : public Type {
protected:
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 863171ad741..c7cfee6e093 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -905,20 +905,20 @@ public:
Name);
}
- InvokeInst *CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest,
+ InvokeInst *CreateInvoke(Function *Callee, BasicBlock *NormalDest,
BasicBlock *UnwindDest, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> OpBundles,
const Twine &Name = "") {
- return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
- NormalDest, UnwindDest, Args, OpBundles, Name);
+ return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
+ UnwindDest, Args, OpBundles, Name);
}
- InvokeInst *CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest,
+ InvokeInst *CreateInvoke(Function *Callee, BasicBlock *NormalDest,
BasicBlock *UnwindDest,
ArrayRef<Value *> Args = None,
const Twine &Name = "") {
- return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
- NormalDest, UnwindDest, Args, Name);
+ return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
+ UnwindDest, Args, Name);
}
// Deprecated [opaque pointer types]
@@ -1988,17 +1988,16 @@ public:
return Insert(CI, Name);
}
- CallInst *CreateCall(FunctionCallee Callee, ArrayRef<Value *> Args = None,
+ CallInst *CreateCall(Function *Callee, ArrayRef<Value *> Args = None,
const Twine &Name = "", MDNode *FPMathTag = nullptr) {
- return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
- FPMathTag);
+ return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag);
}
- CallInst *CreateCall(FunctionCallee Callee, ArrayRef<Value *> Args,
+ CallInst *CreateCall(Function *Callee, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> OpBundles,
const Twine &Name = "", MDNode *FPMathTag = nullptr) {
- return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
- OpBundles, Name, FPMathTag);
+ return CreateCall(Callee->getFunctionType(), Callee, Args, OpBundles, Name,
+ FPMathTag);
}
// Deprecated [opaque pointer types]
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 71dd9ece506..68c82eb135b 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1232,11 +1232,6 @@ public:
Fn);
}
- /// Sets the function called, including updating the function type.
- void setCalledFunction(FunctionCallee Fn) {
- setCalledFunction(Fn.getFunctionType(), Fn.getCallee());
- }
-
/// Sets the function called, including updating to the specified function
/// type.
void setCalledFunction(FunctionType *FTy, Value *Fn) {
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index f9f3ff373ca..dfd11c5e97b 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -1543,44 +1543,25 @@ public:
CallInst(Ty, Func, Args, Bundles, NameStr, InsertAtEnd);
}
- static CallInst *Create(FunctionCallee Func, const Twine &NameStr = "",
+ static CallInst *Create(Function *Func, const Twine &NameStr = "",
Instruction *InsertBefore = nullptr) {
- return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
- InsertBefore);
+ return Create(Func->getFunctionType(), Func, NameStr, InsertBefore);
}
- static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles = None,
+ static CallInst *Create(Function *Func, ArrayRef<Value *> Args,
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr) {
- return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
- NameStr, InsertBefore);
- }
-
- static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
- const Twine &NameStr,
- Instruction *InsertBefore = nullptr) {
- return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
- InsertBefore);
+ return Create(Func->getFunctionType(), Func, Args, NameStr, InsertBefore);
}
- static CallInst *Create(FunctionCallee Func, const Twine &NameStr,
+ static CallInst *Create(Function *Func, const Twine &NameStr,
BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
- InsertAtEnd);
+ return Create(Func->getFunctionType(), Func, NameStr, InsertAtEnd);
}
- static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
+ static CallInst *Create(Function *Func, ArrayRef<Value *> Args,
const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
- InsertAtEnd);
- }
-
- static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
- NameStr, InsertAtEnd);
+ return Create(Func->getFunctionType(), Func, Args, NameStr, InsertAtEnd);
}
// Deprecated [opaque pointer types]
@@ -3723,36 +3704,36 @@ public:
NameStr, InsertAtEnd);
}
- static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
+ static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
const Twine &NameStr,
Instruction *InsertBefore = nullptr) {
- return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
- IfException, Args, None, NameStr, InsertBefore);
+ return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
+ None, NameStr, InsertBefore);
}
- static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
+ static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles = None,
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr) {
- return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
- IfException, Args, Bundles, NameStr, InsertBefore);
+ return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
+ Bundles, NameStr, InsertBefore);
}
- static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
+ static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
- IfException, Args, NameStr, InsertAtEnd);
+ return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
+ NameStr, InsertAtEnd);
}
- static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
+ static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
- IfException, Args, Bundles, NameStr, InsertAtEnd);
+ return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
+ Bundles, NameStr, InsertAtEnd);
}
// Deprecated [opaque pointer types]
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 7373b848541..4abab1d7bf0 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -332,18 +332,16 @@ public:
/// Look up the specified function in the module symbol table. Four
/// possibilities:
/// 1. If it does not exist, add a prototype for the function and return it.
- /// 2. Otherwise, if the existing function has the correct prototype, return
+ /// 2. If it exists, and has a local linkage, the existing function is
+ /// renamed and a new one is inserted.
+ /// 3. Otherwise, if the existing function has the correct prototype, return
/// the existing function.
- /// 3. Finally, the function exists but has the wrong prototype: return the
+ /// 4. Finally, the function exists but has the wrong prototype: return the
/// function with a constantexpr cast to the right prototype.
- ///
- /// In all cases, the returned value is a FunctionCallee wrapper around the
- /// 'FunctionType *T' passed in, as well as a 'Value*' either of the Function or
- /// the bitcast to the function.
- FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T,
- AttributeList AttributeList);
+ Constant *getOrInsertFunction(StringRef Name, FunctionType *T,
+ AttributeList AttributeList);
- FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T);
+ Constant *getOrInsertFunction(StringRef Name, FunctionType *T);
/// Look up the specified function in the module symbol table. If it does not
/// exist, add a prototype for the function and return it. This function
@@ -351,10 +349,11 @@ public:
/// or a ConstantExpr BitCast of that type if the named function has a
/// different type. This version of the method takes a list of
/// function arguments, which makes it easier for clients to use.
- template <typename... ArgsTy>
- FunctionCallee getOrInsertFunction(StringRef Name,
- AttributeList AttributeList, Type *RetTy,
- ArgsTy... Args) {
+ template<typename... ArgsTy>
+ Constant *getOrInsertFunction(StringRef Name,
+ AttributeList AttributeList,
+ Type *RetTy, ArgsTy... Args)
+ {
SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
return getOrInsertFunction(Name,
FunctionType::get(RetTy, ArgTys, false),
@@ -362,17 +361,15 @@ public:
}
/// Same as above, but without the attributes.
- template <typename... ArgsTy>
- FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy,
- ArgsTy... Args) {
+ template<typename... ArgsTy>
+ Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args) {
return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
}
// Avoid an incorrect ordering that'd otherwise compile incorrectly.
template <typename... ArgsTy>
- FunctionCallee
- getOrInsertFunction(StringRef Name, AttributeList AttributeList,
- FunctionType *Invalid, ArgsTy... Args) = delete;
+ Constant *getOrInsertFunction(StringRef Name, AttributeList AttributeList,
+ FunctionType *Invalid, ArgsTy... Args) = delete;
/// Look up the specified function in the module symbol table. If it does not
/// exist, return null.
diff --git a/llvm/include/llvm/Transforms/Utils/ModuleUtils.h b/llvm/include/llvm/Transforms/Utils/ModuleUtils.h
index c69af558874..0b85e96446d 100644
--- a/llvm/include/llvm/Transforms/Utils/ModuleUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/ModuleUtils.h
@@ -21,7 +21,6 @@ namespace llvm {
template <typename T> class ArrayRef;
class Module;
class Function;
-class FunctionCallee;
class GlobalValue;
class GlobalVariable;
class Constant;
@@ -40,14 +39,20 @@ void appendToGlobalCtors(Module &M, Function *F, int Priority,
void appendToGlobalDtors(Module &M, Function *F, int Priority,
Constant *Data = nullptr);
-FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName,
- ArrayRef<Type *> InitArgTypes);
+// Validate the result of Module::getOrInsertFunction called for an interface
+// function of given sanitizer. If the instrumented module defines a function
+// with the same name, their prototypes must match, otherwise
+// getOrInsertFunction returns a bitcast.
+Function *checkSanitizerInterfaceFunction(Constant *FuncOrBitcast);
+
+Function *declareSanitizerInitFunction(Module &M, StringRef InitName,
+ ArrayRef<Type *> InitArgTypes);
/// Creates sanitizer constructor function, and calls sanitizer's init
/// function from it.
/// \return Returns pair of pointers to constructor, and init functions
/// respectively.
-std::pair<Function *, FunctionCallee> createSanitizerCtorAndInitFunctions(
+std::pair<Function *, Function *> createSanitizerCtorAndInitFunctions(
Module &M, StringRef CtorName, StringRef InitName,
ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
StringRef VersionCheckName = StringRef());
@@ -59,10 +64,10 @@ std::pair<Function *, FunctionCallee> createSanitizerCtorAndInitFunctions(
///
/// \return Returns pair of pointers to constructor, and init functions
/// respectively.
-std::pair<Function *, FunctionCallee> getOrCreateSanitizerCtorAndInitFunctions(
+std::pair<Function *, Function *> getOrCreateSanitizerCtorAndInitFunctions(
Module &M, StringRef CtorName, StringRef InitName,
ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
- function_ref<void(Function *, FunctionCallee)> FunctionsCreatedCallback,
+ function_ref<void(Function *, Function *)> FunctionsCreatedCallback,
StringRef VersionCheckName = StringRef());
// Creates and returns a sanitizer init function without argument if it doesn't
OpenPOWER on IntegriCloud