Code cleanups in opt.cpp; no functional change
This commit is contained in:
162
opt.cpp
162
opt.cpp
@@ -176,6 +176,66 @@ lGetSourcePosFromMetadata(const llvm::Instruction *inst, SourcePos *pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static llvm::Instruction *
|
||||||
|
lCallInst(llvm::Function *func, llvm::Value *arg0, llvm::Value *arg1,
|
||||||
|
const char *name, llvm::Instruction *insertBefore = NULL) {
|
||||||
|
llvm::Value *args[2] = { arg0, arg1 };
|
||||||
|
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
||||||
|
llvm::ArrayRef<llvm::Value *> newArgArray(&args[0], &args[2]);
|
||||||
|
return llvm::CallInst::Create(func, newArgArray, name, insertBefore);
|
||||||
|
#else
|
||||||
|
return llvm::CallInst::Create(func, &newArgs[0], &newArgs[2],
|
||||||
|
name, insertBefore);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static llvm::Instruction *
|
||||||
|
lCallInst(llvm::Function *func, llvm::Value *arg0, llvm::Value *arg1,
|
||||||
|
llvm::Value *arg2, const char *name,
|
||||||
|
llvm::Instruction *insertBefore = NULL) {
|
||||||
|
llvm::Value *args[3] = { arg0, arg1, arg2 };
|
||||||
|
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
||||||
|
llvm::ArrayRef<llvm::Value *> newArgArray(&args[0], &args[3]);
|
||||||
|
return llvm::CallInst::Create(func, newArgArray, name, insertBefore);
|
||||||
|
#else
|
||||||
|
return llvm::CallInst::Create(func, &newArgs[0], &newArgs[3],
|
||||||
|
name, insertBefore);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static llvm::Instruction *
|
||||||
|
lCallInst(llvm::Function *func, llvm::Value *arg0, llvm::Value *arg1,
|
||||||
|
llvm::Value *arg2, llvm::Value *arg3, const char *name,
|
||||||
|
llvm::Instruction *insertBefore = NULL) {
|
||||||
|
llvm::Value *args[4] = { arg0, arg1, arg2, arg3 };
|
||||||
|
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
||||||
|
llvm::ArrayRef<llvm::Value *> newArgArray(&args[0], &args[4]);
|
||||||
|
return llvm::CallInst::Create(func, newArgArray, name, insertBefore);
|
||||||
|
#else
|
||||||
|
return llvm::CallInst::Create(func, &newArgs[0], &newArgs[4],
|
||||||
|
name, insertBefore);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static llvm::Instruction *
|
||||||
|
lCallInst(llvm::Function *func, llvm::Value *arg0, llvm::Value *arg1,
|
||||||
|
llvm::Value *arg2, llvm::Value *arg3, llvm::Value *arg4,
|
||||||
|
const char *name, llvm::Instruction *insertBefore = NULL) {
|
||||||
|
llvm::Value *args[5] = { arg0, arg1, arg2, arg3, arg4 };
|
||||||
|
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
||||||
|
llvm::ArrayRef<llvm::Value *> newArgArray(&args[0], &args[5]);
|
||||||
|
return llvm::CallInst::Create(func, newArgArray, name, insertBefore);
|
||||||
|
#else
|
||||||
|
return llvm::CallInst::Create(func, &newArgs[0], &newArgs[5],
|
||||||
|
name, insertBefore);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void
|
void
|
||||||
Optimize(llvm::Module *module, int optLevel) {
|
Optimize(llvm::Module *module, int optLevel) {
|
||||||
if (g->debugPrint) {
|
if (g->debugPrint) {
|
||||||
@@ -509,7 +569,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
char IntrinsicsOpt::ID = 0;
|
char IntrinsicsOpt::ID = 0;
|
||||||
llvm::RegisterPass<IntrinsicsOpt> sse("sse-constants", "Intrinsics Cleanup Pass");
|
|
||||||
|
|
||||||
|
|
||||||
IntrinsicsOpt::IntrinsicsOpt()
|
IntrinsicsOpt::IntrinsicsOpt()
|
||||||
@@ -829,7 +888,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
char VSelMovmskOpt::ID = 0;
|
char VSelMovmskOpt::ID = 0;
|
||||||
llvm::RegisterPass<VSelMovmskOpt> vsel("vector-select", "Vector Select Pass");
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -918,7 +976,6 @@ public:
|
|||||||
|
|
||||||
char GatherScatterFlattenOpt::ID = 0;
|
char GatherScatterFlattenOpt::ID = 0;
|
||||||
|
|
||||||
llvm::RegisterPass<GatherScatterFlattenOpt> gsf("gs-flatten", "Gather/Scatter Flatten Pass");
|
|
||||||
|
|
||||||
|
|
||||||
/** Check to make sure that this value is actually a pointer in the end.
|
/** Check to make sure that this value is actually a pointer in the end.
|
||||||
@@ -1345,17 +1402,9 @@ GatherScatterFlattenOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
|
|||||||
// llvm::Instruction to llvm::CallInst::Create; this means that
|
// llvm::Instruction to llvm::CallInst::Create; this means that
|
||||||
// the instruction isn't inserted into a basic block and that
|
// the instruction isn't inserted into a basic block and that
|
||||||
// way we can then call ReplaceInstWithInst().
|
// way we can then call ReplaceInstWithInst().
|
||||||
llvm::Value *newArgs[4] = { basePtr, offsetVector, offsetScale, mask };
|
|
||||||
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
|
||||||
llvm::ArrayRef<llvm::Value *> newArgArray(&newArgs[0], &newArgs[4]);
|
|
||||||
llvm::Instruction *newCall =
|
llvm::Instruction *newCall =
|
||||||
llvm::CallInst::Create(gatherScatterFunc, newArgArray, "newgather",
|
lCallInst(gatherScatterFunc, basePtr, offsetVector, offsetScale,
|
||||||
(llvm::Instruction *)NULL);
|
mask, "newgather", NULL);
|
||||||
#else
|
|
||||||
llvm::Instruction *newCall =
|
|
||||||
llvm::CallInst::Create(gatherScatterFunc, &newArgs[0], &newArgs[4],
|
|
||||||
"newgather");
|
|
||||||
#endif
|
|
||||||
lCopyMetadata(newCall, callInst);
|
lCopyMetadata(newCall, callInst);
|
||||||
llvm::ReplaceInstWithInst(callInst, newCall);
|
llvm::ReplaceInstWithInst(callInst, newCall);
|
||||||
}
|
}
|
||||||
@@ -1366,18 +1415,9 @@ GatherScatterFlattenOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
|
|||||||
// Generate a new function call to the next pseudo scatter
|
// Generate a new function call to the next pseudo scatter
|
||||||
// base+offsets instruction. See above for why passing NULL
|
// base+offsets instruction. See above for why passing NULL
|
||||||
// for the Instruction * is intended.
|
// for the Instruction * is intended.
|
||||||
llvm::Value *newArgs[5] = { basePtr, offsetVector, offsetScale,
|
|
||||||
storeValue, mask };
|
|
||||||
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
|
||||||
llvm::ArrayRef<llvm::Value *> newArgArray(&newArgs[0], &newArgs[5]);
|
|
||||||
llvm::Instruction *newCall =
|
llvm::Instruction *newCall =
|
||||||
llvm::CallInst::Create(gatherScatterFunc, newArgArray, "",
|
lCallInst(gatherScatterFunc, basePtr, offsetVector, offsetScale,
|
||||||
(llvm::Instruction *)NULL);
|
storeValue, mask, "", NULL);
|
||||||
#else
|
|
||||||
llvm::Instruction *newCall =
|
|
||||||
llvm::CallInst::Create(gatherScatterFunc, &newArgs[0],
|
|
||||||
&newArgs[5]);
|
|
||||||
#endif
|
|
||||||
lCopyMetadata(newCall, callInst);
|
lCopyMetadata(newCall, callInst);
|
||||||
llvm::ReplaceInstWithInst(callInst, newCall);
|
llvm::ReplaceInstWithInst(callInst, newCall);
|
||||||
}
|
}
|
||||||
@@ -1416,9 +1456,6 @@ public:
|
|||||||
|
|
||||||
char MaskedStoreOptPass::ID = 0;
|
char MaskedStoreOptPass::ID = 0;
|
||||||
|
|
||||||
llvm::RegisterPass<MaskedStoreOptPass> mss("masked-store-scalarize",
|
|
||||||
"Masked Store Scalarize Pass");
|
|
||||||
|
|
||||||
struct MSInfo {
|
struct MSInfo {
|
||||||
MSInfo(const char *name, const int a)
|
MSInfo(const char *name, const int a)
|
||||||
: align(a) {
|
: align(a) {
|
||||||
@@ -1532,9 +1569,6 @@ public:
|
|||||||
|
|
||||||
char MaskedLoadOptPass::ID = 0;
|
char MaskedLoadOptPass::ID = 0;
|
||||||
|
|
||||||
llvm::RegisterPass<MaskedLoadOptPass> ml("masked-load-improvements",
|
|
||||||
"Masked Load Improvements Pass");
|
|
||||||
|
|
||||||
struct MLInfo {
|
struct MLInfo {
|
||||||
MLInfo(const char *name, const int a)
|
MLInfo(const char *name, const int a)
|
||||||
: align(a) {
|
: align(a) {
|
||||||
@@ -1636,9 +1670,6 @@ public:
|
|||||||
|
|
||||||
char LowerMaskedStorePass::ID = 0;
|
char LowerMaskedStorePass::ID = 0;
|
||||||
|
|
||||||
llvm::RegisterPass<LowerMaskedStorePass> lms("masked-store-lower",
|
|
||||||
"Lower Masked Store Pass");
|
|
||||||
|
|
||||||
|
|
||||||
/** This routine attempts to determine if the given pointer in lvalue is
|
/** This routine attempts to determine if the given pointer in lvalue is
|
||||||
pointing to stack-allocated memory. It's conservative in that it
|
pointing to stack-allocated memory. It's conservative in that it
|
||||||
@@ -1741,15 +1772,7 @@ LowerMaskedStorePass::runOnBasicBlock(llvm::BasicBlock &bb) {
|
|||||||
// Generate the call to the appropriate masked store function and
|
// Generate the call to the appropriate masked store function and
|
||||||
// replace the __pseudo_* one with it.
|
// replace the __pseudo_* one with it.
|
||||||
llvm::Function *fms = doBlend ? info->blendFunc : info->maskedStoreFunc;
|
llvm::Function *fms = doBlend ? info->blendFunc : info->maskedStoreFunc;
|
||||||
llvm::Value *args[3] = { lvalue, rvalue, mask };
|
llvm::Instruction *inst = lCallInst(fms, lvalue, rvalue, mask, "", callInst);
|
||||||
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
|
||||||
llvm::ArrayRef<llvm::Value *> newArgArray(&args[0], &args[3]);
|
|
||||||
llvm::Instruction *inst = llvm::CallInst::Create(fms, newArgArray, "",
|
|
||||||
callInst);
|
|
||||||
#else
|
|
||||||
llvm::Instruction *inst = llvm::CallInst::Create(fms, &args[0], &args[3], "",
|
|
||||||
callInst);
|
|
||||||
#endif
|
|
||||||
lCopyMetadata(inst, callInst);
|
lCopyMetadata(inst, callInst);
|
||||||
|
|
||||||
callInst->eraseFromParent();
|
callInst->eraseFromParent();
|
||||||
@@ -1795,8 +1818,6 @@ public:
|
|||||||
|
|
||||||
char GSImprovementsPass::ID = 0;
|
char GSImprovementsPass::ID = 0;
|
||||||
|
|
||||||
llvm::RegisterPass<GSImprovementsPass> gsi("gs-improvements",
|
|
||||||
"Gather/Scatter Improvements Pass");
|
|
||||||
|
|
||||||
|
|
||||||
/** Given a vector of compile-time constant integer values, test to see if
|
/** Given a vector of compile-time constant integer values, test to see if
|
||||||
@@ -2117,11 +2138,7 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
|
|||||||
llvm::Value *firstOffset =
|
llvm::Value *firstOffset =
|
||||||
llvm::ExtractElementInst::Create(offsets, LLVMInt32(0), "first_offset",
|
llvm::ExtractElementInst::Create(offsets, LLVMInt32(0), "first_offset",
|
||||||
callInst);
|
callInst);
|
||||||
llvm::Value *scaledOffset =
|
llvm::Value *indices[1] = { firstOffset };
|
||||||
llvm::BinaryOperator::Create(llvm::Instruction::Mul, firstOffset,
|
|
||||||
offsetScale, "scaled_offset", callInst);
|
|
||||||
|
|
||||||
llvm::Value *indices[1] = { scaledOffset };
|
|
||||||
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
||||||
llvm::ArrayRef<llvm::Value *> arrayRef(&indices[0], &indices[1]);
|
llvm::ArrayRef<llvm::Value *> arrayRef(&indices[0], &indices[1]);
|
||||||
llvm::Value *ptr =
|
llvm::Value *ptr =
|
||||||
@@ -2141,17 +2158,9 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
|
|||||||
// access memory if the mask is all off (the location may
|
// access memory if the mask is all off (the location may
|
||||||
// be invalid in that case).
|
// be invalid in that case).
|
||||||
Debug(pos, "Transformed gather to scalar load and broadcast!");
|
Debug(pos, "Transformed gather to scalar load and broadcast!");
|
||||||
llvm::Value *args[2] = { ptr, mask };
|
|
||||||
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
|
||||||
llvm::ArrayRef<llvm::Value *> newArgArray(&args[0], &args[2]);
|
|
||||||
llvm::Instruction *newCall =
|
llvm::Instruction *newCall =
|
||||||
llvm::CallInst::Create(gatherInfo->loadBroadcastFunc, newArgArray,
|
lCallInst(gatherInfo->loadBroadcastFunc, ptr, mask,
|
||||||
"load_broadcast", (llvm::Instruction *)NULL);
|
"load_braodcast");
|
||||||
#else
|
|
||||||
llvm::Instruction *newCall =
|
|
||||||
llvm::CallInst::Create(gatherInfo->loadBroadcastFunc, &args[0],
|
|
||||||
&args[2], "load_broadcast");
|
|
||||||
#endif
|
|
||||||
lCopyMetadata(newCall, callInst);
|
lCopyMetadata(newCall, callInst);
|
||||||
llvm::ReplaceInstWithInst(callInst, newCall);
|
llvm::ReplaceInstWithInst(callInst, newCall);
|
||||||
}
|
}
|
||||||
@@ -2213,17 +2222,8 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
|
|||||||
|
|
||||||
if (gatherInfo != NULL) {
|
if (gatherInfo != NULL) {
|
||||||
Debug(pos, "Transformed gather to unaligned vector load!");
|
Debug(pos, "Transformed gather to unaligned vector load!");
|
||||||
llvm::Value *args[2] = { ptr, mask };
|
|
||||||
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
|
||||||
llvm::ArrayRef<llvm::Value *> argArray(&args[0], &args[2]);
|
|
||||||
llvm::Instruction *newCall =
|
llvm::Instruction *newCall =
|
||||||
llvm::CallInst::Create(gatherInfo->loadMaskedFunc, argArray,
|
lCallInst(gatherInfo->loadMaskedFunc, ptr, mask, "masked_load");
|
||||||
"masked_load", (llvm::Instruction *)NULL);
|
|
||||||
#else
|
|
||||||
llvm::Instruction *newCall =
|
|
||||||
llvm::CallInst::Create(gatherInfo->loadMaskedFunc, &args[0],
|
|
||||||
&args[2], "masked_load");
|
|
||||||
#endif
|
|
||||||
lCopyMetadata(newCall, callInst);
|
lCopyMetadata(newCall, callInst);
|
||||||
llvm::ReplaceInstWithInst(callInst, newCall);
|
llvm::ReplaceInstWithInst(callInst, newCall);
|
||||||
}
|
}
|
||||||
@@ -2231,18 +2231,9 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
|
|||||||
Debug(pos, "Transformed scatter to unaligned vector store!");
|
Debug(pos, "Transformed scatter to unaligned vector store!");
|
||||||
ptr = new llvm::BitCastInst(ptr, scatterInfo->vecPtrType, "ptrcast",
|
ptr = new llvm::BitCastInst(ptr, scatterInfo->vecPtrType, "ptrcast",
|
||||||
callInst);
|
callInst);
|
||||||
|
llvm::Instruction *newCall =
|
||||||
llvm::Value *args[3] = { ptr, storeValue, mask };
|
lCallInst(scatterInfo->maskedStoreFunc, ptr, storeValue,
|
||||||
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
|
mask, "");
|
||||||
llvm::ArrayRef<llvm::Value *> argArray(&args[0], &args[3]);
|
|
||||||
llvm::Instruction *newCall =
|
|
||||||
llvm::CallInst::Create(scatterInfo->maskedStoreFunc, argArray,
|
|
||||||
"", (llvm::Instruction *)NULL);
|
|
||||||
#else
|
|
||||||
llvm::Instruction *newCall =
|
|
||||||
llvm::CallInst::Create(scatterInfo->maskedStoreFunc,
|
|
||||||
&args[0], &args[3], "");
|
|
||||||
#endif
|
|
||||||
lCopyMetadata(newCall, callInst);
|
lCopyMetadata(newCall, callInst);
|
||||||
llvm::ReplaceInstWithInst(callInst, newCall);
|
llvm::ReplaceInstWithInst(callInst, newCall);
|
||||||
}
|
}
|
||||||
@@ -2281,8 +2272,6 @@ public:
|
|||||||
|
|
||||||
char LowerGSPass::ID = 0;
|
char LowerGSPass::ID = 0;
|
||||||
|
|
||||||
llvm::RegisterPass<LowerGSPass> lgs("lower-gs",
|
|
||||||
"Lower Gather/Scatter Pass");
|
|
||||||
|
|
||||||
struct LowerGSInfo {
|
struct LowerGSInfo {
|
||||||
LowerGSInfo(const char *pName, const char *aName, bool ig)
|
LowerGSInfo(const char *pName, const char *aName, bool ig)
|
||||||
@@ -2422,9 +2411,6 @@ public:
|
|||||||
|
|
||||||
char IsCompileTimeConstantPass::ID = 0;
|
char IsCompileTimeConstantPass::ID = 0;
|
||||||
|
|
||||||
llvm::RegisterPass<IsCompileTimeConstantPass>
|
|
||||||
ctcrp("compile-time-constant", "Compile-Time Constant Resolve Pass");
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
IsCompileTimeConstantPass::runOnBasicBlock(llvm::BasicBlock &bb) {
|
IsCompileTimeConstantPass::runOnBasicBlock(llvm::BasicBlock &bb) {
|
||||||
llvm::Function *funcs[] = {
|
llvm::Function *funcs[] = {
|
||||||
@@ -2520,10 +2506,6 @@ public:
|
|||||||
|
|
||||||
char MakeInternalFuncsStaticPass::ID = 0;
|
char MakeInternalFuncsStaticPass::ID = 0;
|
||||||
|
|
||||||
llvm::RegisterPass<MakeInternalFuncsStaticPass>
|
|
||||||
mifsp("make-internal-funcs-static", "Make Internal Funcs Static Pass");
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MakeInternalFuncsStaticPass::runOnModule(llvm::Module &module) {
|
MakeInternalFuncsStaticPass::runOnModule(llvm::Module &module) {
|
||||||
const char *names[] = {
|
const char *names[] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user