mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
merge two near-identical functions createPrivateGlobalForString into one
Summary: We have two copies of createPrivateGlobalForString (in asan and in esan). This change merges them into one. NFC Reviewers: vitalybuka Reviewed By: vitalybuka Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D53178 llvm-svn: 344314
This commit is contained in:
parent
18184d48f3
commit
5246ff552b
@ -36,6 +36,11 @@ class OptimizationRemarkEmitter;
|
|||||||
BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB,
|
BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB,
|
||||||
BasicBlock::iterator IP);
|
BasicBlock::iterator IP);
|
||||||
|
|
||||||
|
// Create a constant for Str so that we can pass it to the run-time lib.
|
||||||
|
GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str,
|
||||||
|
bool AllowMerging,
|
||||||
|
const char *NamePrefix = "");
|
||||||
|
|
||||||
// Insert GCOV profiling instrumentation
|
// Insert GCOV profiling instrumentation
|
||||||
struct GCOVOptions {
|
struct GCOVOptions {
|
||||||
static GCOVOptions getDefault();
|
static GCOVOptions getDefault();
|
||||||
|
@ -1174,25 +1174,11 @@ static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
|
|||||||
return Res;
|
return Res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a constant for Str so that we can pass it to the run-time lib.
|
|
||||||
static GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str,
|
|
||||||
bool AllowMerging) {
|
|
||||||
Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
|
|
||||||
// We use private linkage for module-local strings. If they can be merged
|
|
||||||
// with another one, we set the unnamed_addr attribute.
|
|
||||||
GlobalVariable *GV =
|
|
||||||
new GlobalVariable(M, StrConst->getType(), true,
|
|
||||||
GlobalValue::PrivateLinkage, StrConst, kAsanGenPrefix);
|
|
||||||
if (AllowMerging) GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
|
|
||||||
GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
|
|
||||||
return GV;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a global describing a source location.
|
/// Create a global describing a source location.
|
||||||
static GlobalVariable *createPrivateGlobalForSourceLoc(Module &M,
|
static GlobalVariable *createPrivateGlobalForSourceLoc(Module &M,
|
||||||
LocationMetadata MD) {
|
LocationMetadata MD) {
|
||||||
Constant *LocData[] = {
|
Constant *LocData[] = {
|
||||||
createPrivateGlobalForString(M, MD.Filename, true),
|
createPrivateGlobalForString(M, MD.Filename, true, kAsanGenPrefix),
|
||||||
ConstantInt::get(Type::getInt32Ty(M.getContext()), MD.LineNo),
|
ConstantInt::get(Type::getInt32Ty(M.getContext()), MD.LineNo),
|
||||||
ConstantInt::get(Type::getInt32Ty(M.getContext()), MD.ColumnNo),
|
ConstantInt::get(Type::getInt32Ty(M.getContext()), MD.ColumnNo),
|
||||||
};
|
};
|
||||||
@ -2179,7 +2165,7 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool
|
|||||||
// We shouldn't merge same module names, as this string serves as unique
|
// We shouldn't merge same module names, as this string serves as unique
|
||||||
// module ID in runtime.
|
// module ID in runtime.
|
||||||
GlobalVariable *ModuleName = createPrivateGlobalForString(
|
GlobalVariable *ModuleName = createPrivateGlobalForString(
|
||||||
M, M.getModuleIdentifier(), /*AllowMerging*/ false);
|
M, M.getModuleIdentifier(), /*AllowMerging*/ false, kAsanGenPrefix);
|
||||||
|
|
||||||
for (size_t i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
static const uint64_t kMaxGlobalRedzone = 1 << 18;
|
static const uint64_t kMaxGlobalRedzone = 1 << 18;
|
||||||
@ -2191,7 +2177,7 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool
|
|||||||
// if it's available, otherwise just write the name of global variable).
|
// if it's available, otherwise just write the name of global variable).
|
||||||
GlobalVariable *Name = createPrivateGlobalForString(
|
GlobalVariable *Name = createPrivateGlobalForString(
|
||||||
M, MD.Name.empty() ? NameForGlobal : MD.Name,
|
M, MD.Name.empty() ? NameForGlobal : MD.Name,
|
||||||
/*AllowMerging*/ true);
|
/*AllowMerging*/ true, kAsanGenPrefix);
|
||||||
|
|
||||||
Type *Ty = G->getValueType();
|
Type *Ty = G->getValueType();
|
||||||
uint64_t SizeInBytes = DL.getTypeAllocSize(Ty);
|
uint64_t SizeInBytes = DL.getTypeAllocSize(Ty);
|
||||||
@ -3072,7 +3058,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
|
|||||||
IntptrPtrTy);
|
IntptrPtrTy);
|
||||||
GlobalVariable *StackDescriptionGlobal =
|
GlobalVariable *StackDescriptionGlobal =
|
||||||
createPrivateGlobalForString(*F.getParent(), DescriptionString,
|
createPrivateGlobalForString(*F.getParent(), DescriptionString,
|
||||||
/*AllowMerging*/ true);
|
/*AllowMerging*/ true, kAsanGenPrefix);
|
||||||
Value *Description = IRB.CreatePointerCast(StackDescriptionGlobal, IntptrTy);
|
Value *Description = IRB.CreatePointerCast(StackDescriptionGlobal, IntptrTy);
|
||||||
IRB.CreateStore(Description, BasePlus1);
|
IRB.CreateStore(Description, BasePlus1);
|
||||||
// Write the PC to redzone[2].
|
// Write the PC to redzone[2].
|
||||||
|
@ -144,21 +144,6 @@ OverrideOptionsFromCL(EfficiencySanitizerOptions Options) {
|
|||||||
return Options;
|
return Options;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a constant for Str so that we can pass it to the run-time lib.
|
|
||||||
static GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str,
|
|
||||||
bool AllowMerging) {
|
|
||||||
Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
|
|
||||||
// We use private linkage for module-local strings. If they can be merged
|
|
||||||
// with another one, we set the unnamed_addr attribute.
|
|
||||||
GlobalVariable *GV =
|
|
||||||
new GlobalVariable(M, StrConst->getType(), true,
|
|
||||||
GlobalValue::PrivateLinkage, StrConst, "");
|
|
||||||
if (AllowMerging)
|
|
||||||
GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
|
|
||||||
GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
|
|
||||||
return GV;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// EfficiencySanitizer: instrument each module to find performance issues.
|
/// EfficiencySanitizer: instrument each module to find performance issues.
|
||||||
class EfficiencySanitizer : public ModulePass {
|
class EfficiencySanitizer : public ModulePass {
|
||||||
public:
|
public:
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "llvm/Transforms/Instrumentation.h"
|
#include "llvm/Transforms/Instrumentation.h"
|
||||||
#include "llvm-c/Initialization.h"
|
#include "llvm-c/Initialization.h"
|
||||||
#include "llvm/IR/IntrinsicInst.h"
|
#include "llvm/IR/IntrinsicInst.h"
|
||||||
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/InitializePasses.h"
|
#include "llvm/InitializePasses.h"
|
||||||
#include "llvm/PassRegistry.h"
|
#include "llvm/PassRegistry.h"
|
||||||
|
|
||||||
@ -53,6 +54,22 @@ BasicBlock::iterator llvm::PrepareToSplitEntryBlock(BasicBlock &BB,
|
|||||||
return IP;
|
return IP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a constant for Str so that we can pass it to the run-time lib.
|
||||||
|
GlobalVariable *llvm::createPrivateGlobalForString(Module &M, StringRef Str,
|
||||||
|
bool AllowMerging,
|
||||||
|
const char *NamePrefix) {
|
||||||
|
Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
|
||||||
|
// We use private linkage for module-local strings. If they can be merged
|
||||||
|
// with another one, we set the unnamed_addr attribute.
|
||||||
|
GlobalVariable *GV =
|
||||||
|
new GlobalVariable(M, StrConst->getType(), true,
|
||||||
|
GlobalValue::PrivateLinkage, StrConst, NamePrefix);
|
||||||
|
if (AllowMerging)
|
||||||
|
GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
|
||||||
|
GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
|
||||||
|
return GV;
|
||||||
|
}
|
||||||
|
|
||||||
/// initializeInstrumentation - Initialize all passes in the TransformUtils
|
/// initializeInstrumentation - Initialize all passes in the TransformUtils
|
||||||
/// library.
|
/// library.
|
||||||
void llvm::initializeInstrumentation(PassRegistry &Registry) {
|
void llvm::initializeInstrumentation(PassRegistry &Registry) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user