summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/IPO/MergeFunctions.cpp
diff options
context:
space:
mode:
authorrdivacky <rdivacky@FreeBSD.org>2009-10-14 17:57:32 +0000
committerrdivacky <rdivacky@FreeBSD.org>2009-10-14 17:57:32 +0000
commitcd749a9c07f1de2fb8affde90537efa4bc3e7c54 (patch)
treeb21f6de4e08b89bb7931806bab798fc2a5e3a686 /lib/Transforms/IPO/MergeFunctions.cpp
parent72621d11de5b873f1695f391eb95f0b336c3d2d4 (diff)
downloadFreeBSD-src-cd749a9c07f1de2fb8affde90537efa4bc3e7c54.zip
FreeBSD-src-cd749a9c07f1de2fb8affde90537efa4bc3e7c54.tar.gz
Update llvm to r84119.
Diffstat (limited to 'lib/Transforms/IPO/MergeFunctions.cpp')
-rw-r--r--lib/Transforms/IPO/MergeFunctions.cpp45
1 files changed, 25 insertions, 20 deletions
diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp
index 5693cc0..13bbf9c 100644
--- a/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/lib/Transforms/IPO/MergeFunctions.cpp
@@ -47,11 +47,14 @@
#include "llvm/Constants.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/CallSite.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
#include <map>
#include <vector>
using namespace llvm;
@@ -61,7 +64,7 @@ STATISTIC(NumFunctionsMerged, "Number of functions merged");
namespace {
struct VISIBILITY_HIDDEN MergeFunctions : public ModulePass {
static char ID; // Pass identification, replacement for typeid
- MergeFunctions() : ModulePass((intptr_t)&ID) {}
+ MergeFunctions() : ModulePass(&ID) {}
bool runOnModule(Module &M);
};
@@ -127,7 +130,7 @@ static bool isEquivalentType(const Type *Ty1, const Type *Ty2) {
return false;
default:
- assert(0 && "Unknown type!");
+ llvm_unreachable("Unknown type!");
return false;
case Type::PointerTyID: {
@@ -185,7 +188,8 @@ static bool
isEquivalentOperation(const Instruction *I1, const Instruction *I2) {
if (I1->getOpcode() != I2->getOpcode() ||
I1->getNumOperands() != I2->getNumOperands() ||
- !isEquivalentType(I1->getType(), I2->getType()))
+ !isEquivalentType(I1->getType(), I2->getType()) ||
+ !I1->hasSameSubclassOptionalData(I2))
return false;
// We have two instructions of identical opcode and #operands. Check to see
@@ -449,6 +453,7 @@ static LinkageCategory categorize(const Function *F) {
switch (F->getLinkage()) {
case GlobalValue::InternalLinkage:
case GlobalValue::PrivateLinkage:
+ case GlobalValue::LinkerPrivateLinkage:
return Internal;
case GlobalValue::WeakAnyLinkage:
@@ -468,14 +473,14 @@ static LinkageCategory categorize(const Function *F) {
return ExternalStrong;
}
- assert(0 && "Unknown LinkageType.");
+ llvm_unreachable("Unknown LinkageType.");
return ExternalWeak;
}
static void ThunkGToF(Function *F, Function *G) {
Function *NewG = Function::Create(G->getFunctionType(), G->getLinkage(), "",
G->getParent());
- BasicBlock *BB = BasicBlock::Create("", NewG);
+ BasicBlock *BB = BasicBlock::Create(F->getContext(), "", NewG);
std::vector<Value *> Args;
unsigned i = 0;
@@ -494,13 +499,13 @@ static void ThunkGToF(Function *F, Function *G) {
CallInst *CI = CallInst::Create(F, Args.begin(), Args.end(), "", BB);
CI->setTailCall();
CI->setCallingConv(F->getCallingConv());
- if (NewG->getReturnType() == Type::VoidTy) {
- ReturnInst::Create(BB);
+ if (NewG->getReturnType() == Type::getVoidTy(F->getContext())) {
+ ReturnInst::Create(F->getContext(), BB);
} else if (CI->getType() != NewG->getReturnType()) {
Value *BCI = new BitCastInst(CI, NewG->getReturnType(), "", BB);
- ReturnInst::Create(BCI, BB);
+ ReturnInst::Create(F->getContext(), BCI, BB);
} else {
- ReturnInst::Create(CI, BB);
+ ReturnInst::Create(F->getContext(), CI, BB);
}
NewG->copyAttributesFrom(G);
@@ -574,22 +579,22 @@ static bool fold(std::vector<Function *> &FnVec, unsigned i, unsigned j) {
case Internal:
switch (catG) {
case ExternalStrong:
- assert(0);
+ llvm_unreachable(0);
// fall-through
case ExternalWeak:
- if (F->hasAddressTaken())
+ if (F->hasAddressTaken())
ThunkGToF(F, G);
else
AliasGToF(F, G);
- break;
+ break;
case Internal: {
bool addrTakenF = F->hasAddressTaken();
bool addrTakenG = G->hasAddressTaken();
if (!addrTakenF && addrTakenG) {
std::swap(FnVec[i], FnVec[j]);
std::swap(F, G);
- std::swap(addrTakenF, addrTakenG);
- }
+ std::swap(addrTakenF, addrTakenG);
+ }
if (addrTakenF && addrTakenG) {
ThunkGToF(F, G);
@@ -597,7 +602,7 @@ static bool fold(std::vector<Function *> &FnVec, unsigned i, unsigned j) {
assert(!addrTakenG);
AliasGToF(F, G);
}
- } break;
+ } break;
}
break;
}
@@ -629,19 +634,19 @@ bool MergeFunctions::runOnModule(Module &M) {
bool LocalChanged;
do {
LocalChanged = false;
- DOUT << "size: " << FnMap.size() << "\n";
+ DEBUG(errs() << "size: " << FnMap.size() << "\n");
for (std::map<unsigned long, std::vector<Function *> >::iterator
I = FnMap.begin(), E = FnMap.end(); I != E; ++I) {
std::vector<Function *> &FnVec = I->second;
- DOUT << "hash (" << I->first << "): " << FnVec.size() << "\n";
+ DEBUG(errs() << "hash (" << I->first << "): " << FnVec.size() << "\n");
for (int i = 0, e = FnVec.size(); i != e; ++i) {
for (int j = i + 1; j != e; ++j) {
bool isEqual = equals(FnVec[i], FnVec[j]);
- DOUT << " " << FnVec[i]->getName()
- << (isEqual ? " == " : " != ")
- << FnVec[j]->getName() << "\n";
+ DEBUG(errs() << " " << FnVec[i]->getName()
+ << (isEqual ? " == " : " != ")
+ << FnVec[j]->getName() << "\n");
if (isEqual) {
if (fold(FnVec, i, j)) {
OpenPOWER on IntegriCloud