mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-07 12:29:30 +00:00
More LLVMContext-ification.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74807 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
db882950f3
commit
0a205a4598
@ -22,6 +22,7 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class TerminatorInst;
|
class TerminatorInst;
|
||||||
|
class LLVMContext;
|
||||||
|
|
||||||
template<> struct ilist_traits<Instruction>
|
template<> struct ilist_traits<Instruction>
|
||||||
: public SymbolTableListTraits<Instruction, BasicBlock> {
|
: public SymbolTableListTraits<Instruction, BasicBlock> {
|
||||||
@ -85,6 +86,10 @@ private:
|
|||||||
explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
|
explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
|
||||||
BasicBlock *InsertBefore = 0);
|
BasicBlock *InsertBefore = 0);
|
||||||
public:
|
public:
|
||||||
|
/// getContext - Get the context in which this basic block lives,
|
||||||
|
/// or null if it is not currently attached to a function.
|
||||||
|
LLVMContext* getContext() const;
|
||||||
|
|
||||||
/// Instruction iterators...
|
/// Instruction iterators...
|
||||||
typedef InstListType::iterator iterator;
|
typedef InstListType::iterator iterator;
|
||||||
typedef InstListType::const_iterator const_iterator;
|
typedef InstListType::const_iterator const_iterator;
|
||||||
|
@ -129,7 +129,7 @@ public:
|
|||||||
|
|
||||||
/// getContext - Return a pointer to the LLVMContext associated with this
|
/// getContext - Return a pointer to the LLVMContext associated with this
|
||||||
/// function, or NULL if this function is not bound to a context yet.
|
/// function, or NULL if this function is not bound to a context yet.
|
||||||
LLVMContext* getContext();
|
LLVMContext* getContext() const;
|
||||||
|
|
||||||
/// isVarArg - Return true if this function takes a variable number of
|
/// isVarArg - Return true if this function takes a variable number of
|
||||||
/// arguments.
|
/// arguments.
|
||||||
|
@ -166,6 +166,7 @@ public:
|
|||||||
Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
|
Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
|
||||||
const unsigned* IdxList,
|
const unsigned* IdxList,
|
||||||
unsigned NumIdx);
|
unsigned NumIdx);
|
||||||
|
Constant* getConstantExprSizeOf(const Type* Ty);
|
||||||
Constant* getZeroValueForNegation(const Type* Ty);
|
Constant* getZeroValueForNegation(const Type* Ty);
|
||||||
|
|
||||||
// ConstantFP accessors
|
// ConstantFP accessors
|
||||||
@ -188,6 +189,7 @@ public:
|
|||||||
MDString* getMDString(const std::string &Str);
|
MDString* getMDString(const std::string &Str);
|
||||||
|
|
||||||
// FunctionType accessors
|
// FunctionType accessors
|
||||||
|
FunctionType* getFunctionType(const Type* Result, bool isVarArg);
|
||||||
FunctionType* getFunctionType(const Type* Result,
|
FunctionType* getFunctionType(const Type* Result,
|
||||||
const std::vector<const Type*>& Params,
|
const std::vector<const Type*>& Params,
|
||||||
bool isVarArg);
|
bool isVarArg);
|
||||||
|
@ -23,6 +23,7 @@ class AllocaInst;
|
|||||||
class DominatorTree;
|
class DominatorTree;
|
||||||
class DominanceFrontier;
|
class DominanceFrontier;
|
||||||
class AliasSetTracker;
|
class AliasSetTracker;
|
||||||
|
class LLVMContext;
|
||||||
|
|
||||||
/// isAllocaPromotable - Return true if this alloca is legal for promotion.
|
/// isAllocaPromotable - Return true if this alloca is legal for promotion.
|
||||||
/// This is true if there are only loads and stores to the alloca...
|
/// This is true if there are only loads and stores to the alloca...
|
||||||
@ -39,6 +40,7 @@ bool isAllocaPromotable(const AllocaInst *AI);
|
|||||||
///
|
///
|
||||||
void PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
|
void PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
|
||||||
DominatorTree &DT, DominanceFrontier &DF,
|
DominatorTree &DT, DominanceFrontier &DF,
|
||||||
|
LLVMContext* Context,
|
||||||
AliasSetTracker *AST = 0);
|
AliasSetTracker *AST = 0);
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
@ -20,9 +20,10 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
class Value;
|
class Value;
|
||||||
class Instruction;
|
class Instruction;
|
||||||
|
class LLVMContext;
|
||||||
typedef DenseMap<const Value *, Value *> ValueMapTy;
|
typedef DenseMap<const Value *, Value *> ValueMapTy;
|
||||||
|
|
||||||
Value *MapValue(const Value *V, ValueMapTy &VM);
|
Value *MapValue(const Value *V, ValueMapTy &VM, LLVMContext* Context);
|
||||||
void RemapInstruction(Instruction *I, ValueMapTy &VM);
|
void RemapInstruction(Instruction *I, ValueMapTy &VM);
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ bool DwarfEHPrepare::PromoteStackTemporaries() {
|
|||||||
if (ExceptionValueVar && DT && DF && isAllocaPromotable(ExceptionValueVar)) {
|
if (ExceptionValueVar && DT && DF && isAllocaPromotable(ExceptionValueVar)) {
|
||||||
// Turn the exception temporary into registers and phi nodes if possible.
|
// Turn the exception temporary into registers and phi nodes if possible.
|
||||||
std::vector<AllocaInst*> Allocas(1, ExceptionValueVar);
|
std::vector<AllocaInst*> Allocas(1, ExceptionValueVar);
|
||||||
PromoteMemToReg(Allocas, *DT, *DF);
|
PromoteMemToReg(Allocas, *DT, *DF, Context);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -593,7 +593,7 @@ void LICM::sink(Instruction &I) {
|
|||||||
if (AI) {
|
if (AI) {
|
||||||
std::vector<AllocaInst*> Allocas;
|
std::vector<AllocaInst*> Allocas;
|
||||||
Allocas.push_back(AI);
|
Allocas.push_back(AI);
|
||||||
PromoteMemToReg(Allocas, *DT, *DF, CurAST);
|
PromoteMemToReg(Allocas, *DT, *DF, Context, CurAST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -773,7 +773,7 @@ void LICM::PromoteValuesInLoop() {
|
|||||||
PromotedAllocas.reserve(PromotedValues.size());
|
PromotedAllocas.reserve(PromotedValues.size());
|
||||||
for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i)
|
for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i)
|
||||||
PromotedAllocas.push_back(PromotedValues[i].first);
|
PromotedAllocas.push_back(PromotedValues[i].first);
|
||||||
PromoteMemToReg(PromotedAllocas, *DT, *DF, CurAST);
|
PromoteMemToReg(PromotedAllocas, *DT, *DF, Context, CurAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FindPromotableValuesInLoop - Check the current loop for stores to definite
|
/// FindPromotableValuesInLoop - Check the current loop for stores to definite
|
||||||
|
@ -186,7 +186,7 @@ bool SROA::performPromotion(Function &F) {
|
|||||||
|
|
||||||
if (Allocas.empty()) break;
|
if (Allocas.empty()) break;
|
||||||
|
|
||||||
PromoteMemToReg(Allocas, DT, DF);
|
PromoteMemToReg(Allocas, DT, DF, Context);
|
||||||
NumPromoted += Allocas.size();
|
NumPromoted += Allocas.size();
|
||||||
Changed = true;
|
Changed = true;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Constant.h"
|
#include "llvm/Constant.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
@ -49,7 +50,7 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
|
|||||||
// contained within it must dominate their uses, that all uses will
|
// contained within it must dominate their uses, that all uses will
|
||||||
// eventually be removed (they are themselves dead).
|
// eventually be removed (they are themselves dead).
|
||||||
if (!I.use_empty())
|
if (!I.use_empty())
|
||||||
I.replaceAllUsesWith(UndefValue::get(I.getType()));
|
I.replaceAllUsesWith(BB->getContext()->getUndef(I.getType()));
|
||||||
BB->getInstList().pop_back();
|
BB->getInstList().pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ void llvm::FoldSingleEntryPHINodes(BasicBlock *BB) {
|
|||||||
if (PN->getIncomingValue(0) != PN)
|
if (PN->getIncomingValue(0) != PN)
|
||||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
||||||
else
|
else
|
||||||
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
|
PN->replaceAllUsesWith(BB->getContext()->getUndef(PN->getType()));
|
||||||
PN->eraseFromParent();
|
PN->eraseFromParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,7 +251,8 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {
|
|||||||
|
|
||||||
// Create a value to return... if the function doesn't return null...
|
// Create a value to return... if the function doesn't return null...
|
||||||
if (BB->getParent()->getReturnType() != Type::VoidTy)
|
if (BB->getParent()->getReturnType() != Type::VoidTy)
|
||||||
RetVal = Constant::getNullValue(BB->getParent()->getReturnType());
|
RetVal = TI->getParent()->getContext()->getNullValue(
|
||||||
|
BB->getParent()->getReturnType());
|
||||||
|
|
||||||
// Create the return...
|
// Create the return...
|
||||||
NewTI = ReturnInst::Create(RetVal);
|
NewTI = ReturnInst::Create(RetVal);
|
||||||
@ -385,7 +387,8 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
|
|||||||
if (NumPreds == 0) {
|
if (NumPreds == 0) {
|
||||||
// Insert dummy values as the incoming value.
|
// Insert dummy values as the incoming value.
|
||||||
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I)
|
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I)
|
||||||
cast<PHINode>(I)->addIncoming(UndefValue::get(I->getType()), NewBB);
|
cast<PHINode>(I)->addIncoming(BB->getContext()->getUndef(I->getType()),
|
||||||
|
NewBB);
|
||||||
return NewBB;
|
return NewBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/GlobalVariable.h"
|
#include "llvm/GlobalVariable.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Transforms/Utils/ValueMapper.h"
|
#include "llvm/Transforms/Utils/ValueMapper.h"
|
||||||
@ -150,7 +151,8 @@ Function *llvm::CloneFunction(const Function *F,
|
|||||||
ArgTypes.push_back(I->getType());
|
ArgTypes.push_back(I->getType());
|
||||||
|
|
||||||
// Create a new function type...
|
// Create a new function type...
|
||||||
FunctionType *FTy = FunctionType::get(F->getFunctionType()->getReturnType(),
|
FunctionType *FTy =
|
||||||
|
F->getContext()->getFunctionType(F->getFunctionType()->getReturnType(),
|
||||||
ArgTypes, F->getFunctionType()->isVarArg());
|
ArgTypes, F->getFunctionType()->isVarArg());
|
||||||
|
|
||||||
// Create the new function...
|
// Create the new function...
|
||||||
@ -323,10 +325,13 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
|
|||||||
/// mapping its operands through ValueMap if they are available.
|
/// mapping its operands through ValueMap if they are available.
|
||||||
Constant *PruningFunctionCloner::
|
Constant *PruningFunctionCloner::
|
||||||
ConstantFoldMappedInstruction(const Instruction *I) {
|
ConstantFoldMappedInstruction(const Instruction *I) {
|
||||||
|
LLVMContext* Context = I->getParent()->getContext();
|
||||||
|
|
||||||
SmallVector<Constant*, 8> Ops;
|
SmallVector<Constant*, 8> Ops;
|
||||||
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
|
||||||
if (Constant *Op = dyn_cast_or_null<Constant>(MapValue(I->getOperand(i),
|
if (Constant *Op = dyn_cast_or_null<Constant>(MapValue(I->getOperand(i),
|
||||||
ValueMap)))
|
ValueMap,
|
||||||
|
Context)))
|
||||||
Ops.push_back(Op);
|
Ops.push_back(Op);
|
||||||
else
|
else
|
||||||
return 0; // All operands not constant!
|
return 0; // All operands not constant!
|
||||||
@ -361,6 +366,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||||||
ClonedCodeInfo *CodeInfo,
|
ClonedCodeInfo *CodeInfo,
|
||||||
const TargetData *TD) {
|
const TargetData *TD) {
|
||||||
assert(NameSuffix && "NameSuffix cannot be null!");
|
assert(NameSuffix && "NameSuffix cannot be null!");
|
||||||
|
LLVMContext* Context = OldFunc->getContext();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
for (Function::const_arg_iterator II = OldFunc->arg_begin(),
|
for (Function::const_arg_iterator II = OldFunc->arg_begin(),
|
||||||
@ -430,7 +436,8 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||||||
for (unsigned pred = 0, e = NumPreds; pred != e; ++pred) {
|
for (unsigned pred = 0, e = NumPreds; pred != e; ++pred) {
|
||||||
if (BasicBlock *MappedBlock =
|
if (BasicBlock *MappedBlock =
|
||||||
cast_or_null<BasicBlock>(ValueMap[PN->getIncomingBlock(pred)])) {
|
cast_or_null<BasicBlock>(ValueMap[PN->getIncomingBlock(pred)])) {
|
||||||
Value *InVal = MapValue(PN->getIncomingValue(pred), ValueMap);
|
Value *InVal = MapValue(PN->getIncomingValue(pred),
|
||||||
|
ValueMap, Context);
|
||||||
assert(InVal && "Unknown input value?");
|
assert(InVal && "Unknown input value?");
|
||||||
PN->setIncomingValue(pred, InVal);
|
PN->setIncomingValue(pred, InVal);
|
||||||
PN->setIncomingBlock(pred, MappedBlock);
|
PN->setIncomingBlock(pred, MappedBlock);
|
||||||
@ -482,7 +489,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||||||
BasicBlock::iterator I = NewBB->begin();
|
BasicBlock::iterator I = NewBB->begin();
|
||||||
BasicBlock::const_iterator OldI = OldBB->begin();
|
BasicBlock::const_iterator OldI = OldBB->begin();
|
||||||
while ((PN = dyn_cast<PHINode>(I++))) {
|
while ((PN = dyn_cast<PHINode>(I++))) {
|
||||||
Value *NV = UndefValue::get(PN->getType());
|
Value *NV = OldFunc->getContext()->getUndef(PN->getType());
|
||||||
PN->replaceAllUsesWith(NV);
|
PN->replaceAllUsesWith(NV);
|
||||||
assert(ValueMap[OldI] == PN && "ValueMap mismatch");
|
assert(ValueMap[OldI] == PN && "ValueMap mismatch");
|
||||||
ValueMap[OldI] = NV;
|
ValueMap[OldI] = NV;
|
||||||
|
@ -88,7 +88,8 @@ Module *llvm::CloneModule(const Module *M,
|
|||||||
GlobalVariable *GV = cast<GlobalVariable>(ValueMap[I]);
|
GlobalVariable *GV = cast<GlobalVariable>(ValueMap[I]);
|
||||||
if (I->hasInitializer())
|
if (I->hasInitializer())
|
||||||
GV->setInitializer(cast<Constant>(MapValue(I->getInitializer(),
|
GV->setInitializer(cast<Constant>(MapValue(I->getInitializer(),
|
||||||
ValueMap)));
|
ValueMap,
|
||||||
|
&M->getContext())));
|
||||||
GV->setLinkage(I->getLinkage());
|
GV->setLinkage(I->getLinkage());
|
||||||
GV->setThreadLocal(I->isThreadLocal());
|
GV->setThreadLocal(I->isThreadLocal());
|
||||||
GV->setConstant(I->isConstant());
|
GV->setConstant(I->isConstant());
|
||||||
@ -119,7 +120,7 @@ Module *llvm::CloneModule(const Module *M,
|
|||||||
GlobalAlias *GA = cast<GlobalAlias>(ValueMap[I]);
|
GlobalAlias *GA = cast<GlobalAlias>(ValueMap[I]);
|
||||||
GA->setLinkage(I->getLinkage());
|
GA->setLinkage(I->getLinkage());
|
||||||
if (const Constant* C = I->getAliasee())
|
if (const Constant* C = I->getAliasee())
|
||||||
GA->setAliasee(cast<Constant>(MapValue(C, ValueMap)));
|
GA->setAliasee(cast<Constant>(MapValue(C, ValueMap, &M->getContext())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return New;
|
return New;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Intrinsics.h"
|
#include "llvm/Intrinsics.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
@ -237,6 +238,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
|||||||
DOUT << "inputs: " << inputs.size() << "\n";
|
DOUT << "inputs: " << inputs.size() << "\n";
|
||||||
DOUT << "outputs: " << outputs.size() << "\n";
|
DOUT << "outputs: " << outputs.size() << "\n";
|
||||||
|
|
||||||
|
LLVMContext* Context = header->getContext();
|
||||||
|
|
||||||
// This function returns unsigned, outputs will go back by reference.
|
// This function returns unsigned, outputs will go back by reference.
|
||||||
switch (NumExitBlocks) {
|
switch (NumExitBlocks) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -262,7 +265,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
|||||||
if (AggregateArgs)
|
if (AggregateArgs)
|
||||||
paramTy.push_back((*I)->getType());
|
paramTy.push_back((*I)->getType());
|
||||||
else
|
else
|
||||||
paramTy.push_back(PointerType::getUnqual((*I)->getType()));
|
paramTy.push_back(
|
||||||
|
header->getContext()->getPointerTypeUnqual((*I)->getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
DOUT << "Function type: " << *RetTy << " f(";
|
DOUT << "Function type: " << *RetTy << " f(";
|
||||||
@ -272,11 +276,13 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
|||||||
DOUT << ")\n";
|
DOUT << ")\n";
|
||||||
|
|
||||||
if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
|
if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
|
||||||
PointerType *StructPtr = PointerType::getUnqual(StructType::get(paramTy));
|
PointerType *StructPtr =
|
||||||
|
Context->getPointerTypeUnqual(Context->getStructType(paramTy));
|
||||||
paramTy.clear();
|
paramTy.clear();
|
||||||
paramTy.push_back(StructPtr);
|
paramTy.push_back(StructPtr);
|
||||||
}
|
}
|
||||||
const FunctionType *funcType = FunctionType::get(RetTy, paramTy, false);
|
const FunctionType *funcType =
|
||||||
|
Context->getFunctionType(RetTy, paramTy, false);
|
||||||
|
|
||||||
// Create the new function
|
// Create the new function
|
||||||
Function *newFunction = Function::Create(funcType,
|
Function *newFunction = Function::Create(funcType,
|
||||||
@ -298,8 +304,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
|||||||
Value *RewriteVal;
|
Value *RewriteVal;
|
||||||
if (AggregateArgs) {
|
if (AggregateArgs) {
|
||||||
Value *Idx[2];
|
Value *Idx[2];
|
||||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
Idx[0] = Context->getNullValue(Type::Int32Ty);
|
||||||
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
|
Idx[1] = Context->getConstantInt(Type::Int32Ty, i);
|
||||||
std::string GEPname = "gep_" + inputs[i]->getName();
|
std::string GEPname = "gep_" + inputs[i]->getName();
|
||||||
TerminatorInst *TI = newFunction->begin()->getTerminator();
|
TerminatorInst *TI = newFunction->begin()->getTerminator();
|
||||||
GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2,
|
GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2,
|
||||||
@ -346,6 +352,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
|||||||
void CodeExtractor::
|
void CodeExtractor::
|
||||||
emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||||
Values &inputs, Values &outputs) {
|
Values &inputs, Values &outputs) {
|
||||||
|
LLVMContext* Context = codeReplacer->getContext();
|
||||||
|
|
||||||
// Emit a call to the new function, passing in: *pointer to struct (if
|
// Emit a call to the new function, passing in: *pointer to struct (if
|
||||||
// aggregating parameters), or plan inputs and allocated memory for outputs
|
// aggregating parameters), or plan inputs and allocated memory for outputs
|
||||||
std::vector<Value*> params, StructValues, ReloadOutputs;
|
std::vector<Value*> params, StructValues, ReloadOutputs;
|
||||||
@ -378,7 +386,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
|||||||
ArgTypes.push_back((*v)->getType());
|
ArgTypes.push_back((*v)->getType());
|
||||||
|
|
||||||
// Allocate a struct at the beginning of this function
|
// Allocate a struct at the beginning of this function
|
||||||
Type *StructArgTy = StructType::get(ArgTypes);
|
Type *StructArgTy = Context->getStructType(ArgTypes);
|
||||||
Struct =
|
Struct =
|
||||||
new AllocaInst(StructArgTy, 0, "structArg",
|
new AllocaInst(StructArgTy, 0, "structArg",
|
||||||
codeReplacer->getParent()->begin()->begin());
|
codeReplacer->getParent()->begin()->begin());
|
||||||
@ -386,8 +394,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
|||||||
|
|
||||||
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
|
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
|
||||||
Value *Idx[2];
|
Value *Idx[2];
|
||||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
Idx[0] = Context->getNullValue(Type::Int32Ty);
|
||||||
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
|
Idx[1] = Context->getConstantInt(Type::Int32Ty, i);
|
||||||
GetElementPtrInst *GEP =
|
GetElementPtrInst *GEP =
|
||||||
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
|
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
|
||||||
"gep_" + StructValues[i]->getName());
|
"gep_" + StructValues[i]->getName());
|
||||||
@ -412,8 +420,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
|||||||
Value *Output = 0;
|
Value *Output = 0;
|
||||||
if (AggregateArgs) {
|
if (AggregateArgs) {
|
||||||
Value *Idx[2];
|
Value *Idx[2];
|
||||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
Idx[0] = Context->getNullValue(Type::Int32Ty);
|
||||||
Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
|
Idx[1] = Context->getConstantInt(Type::Int32Ty, FirstOut + i);
|
||||||
GetElementPtrInst *GEP
|
GetElementPtrInst *GEP
|
||||||
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
|
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
|
||||||
"gep_reload_" + outputs[i]->getName());
|
"gep_reload_" + outputs[i]->getName());
|
||||||
@ -434,7 +442,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
|||||||
|
|
||||||
// Now we can emit a switch statement using the call as a value.
|
// Now we can emit a switch statement using the call as a value.
|
||||||
SwitchInst *TheSwitch =
|
SwitchInst *TheSwitch =
|
||||||
SwitchInst::Create(ConstantInt::getNullValue(Type::Int16Ty),
|
SwitchInst::Create(Context->getNullValue(Type::Int16Ty),
|
||||||
codeReplacer, 0, codeReplacer);
|
codeReplacer, 0, codeReplacer);
|
||||||
|
|
||||||
// Since there may be multiple exits from the original region, make the new
|
// Since there may be multiple exits from the original region, make the new
|
||||||
@ -465,17 +473,17 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
|||||||
case 0:
|
case 0:
|
||||||
case 1: break; // No value needed.
|
case 1: break; // No value needed.
|
||||||
case 2: // Conditional branch, return a bool
|
case 2: // Conditional branch, return a bool
|
||||||
brVal = ConstantInt::get(Type::Int1Ty, !SuccNum);
|
brVal = Context->getConstantInt(Type::Int1Ty, !SuccNum);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
brVal = ConstantInt::get(Type::Int16Ty, SuccNum);
|
brVal = Context->getConstantInt(Type::Int16Ty, SuccNum);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
|
ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
|
||||||
|
|
||||||
// Update the switch instruction.
|
// Update the switch instruction.
|
||||||
TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum),
|
TheSwitch->addCase(Context->getConstantInt(Type::Int16Ty, SuccNum),
|
||||||
OldTarget);
|
OldTarget);
|
||||||
|
|
||||||
// Restore values just before we exit
|
// Restore values just before we exit
|
||||||
@ -513,8 +521,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
|||||||
if (DominatesDef) {
|
if (DominatesDef) {
|
||||||
if (AggregateArgs) {
|
if (AggregateArgs) {
|
||||||
Value *Idx[2];
|
Value *Idx[2];
|
||||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
Idx[0] = Context->getNullValue(Type::Int32Ty);
|
||||||
Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
|
Idx[1] = Context->getConstantInt(Type::Int32Ty,FirstOut+out);
|
||||||
GetElementPtrInst *GEP =
|
GetElementPtrInst *GEP =
|
||||||
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
|
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
|
||||||
"gep_" + outputs[out]->getName(),
|
"gep_" + outputs[out]->getName(),
|
||||||
@ -551,7 +559,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
|||||||
} else {
|
} else {
|
||||||
// Otherwise we must have code extracted an unwind or something, just
|
// Otherwise we must have code extracted an unwind or something, just
|
||||||
// return whatever we want.
|
// return whatever we want.
|
||||||
ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch);
|
ReturnInst::Create(Context->getNullValue(OldFnRetTy), TheSwitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
TheSwitch->eraseFromParent();
|
TheSwitch->eraseFromParent();
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "llvm/Transforms/Utils/Cloning.h"
|
#include "llvm/Transforms/Utils/Cloning.h"
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
@ -238,6 +239,7 @@ static const DbgRegionEndInst *findFnRegionEndMarker(const Function *F) {
|
|||||||
//
|
//
|
||||||
bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
|
bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
|
||||||
Instruction *TheCall = CS.getInstruction();
|
Instruction *TheCall = CS.getInstruction();
|
||||||
|
LLVMContext *Context = TheCall->getParent()->getContext();
|
||||||
assert(TheCall->getParent() && TheCall->getParent()->getParent() &&
|
assert(TheCall->getParent() && TheCall->getParent()->getParent() &&
|
||||||
"Instruction not in function!");
|
"Instruction not in function!");
|
||||||
|
|
||||||
@ -302,7 +304,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
|
|||||||
if (CalledFunc->paramHasAttr(ArgNo+1, Attribute::ByVal) &&
|
if (CalledFunc->paramHasAttr(ArgNo+1, Attribute::ByVal) &&
|
||||||
!CalledFunc->onlyReadsMemory()) {
|
!CalledFunc->onlyReadsMemory()) {
|
||||||
const Type *AggTy = cast<PointerType>(I->getType())->getElementType();
|
const Type *AggTy = cast<PointerType>(I->getType())->getElementType();
|
||||||
const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
|
const Type *VoidPtrTy = Context->getPointerTypeUnqual(Type::Int8Ty);
|
||||||
|
|
||||||
// Create the alloca. If we have TargetData, use nice alignment.
|
// Create the alloca. If we have TargetData, use nice alignment.
|
||||||
unsigned Align = 1;
|
unsigned Align = 1;
|
||||||
@ -319,15 +321,16 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
|
|||||||
|
|
||||||
Value *Size;
|
Value *Size;
|
||||||
if (TD == 0)
|
if (TD == 0)
|
||||||
Size = ConstantExpr::getSizeOf(AggTy);
|
Size = Context->getConstantExprSizeOf(AggTy);
|
||||||
else
|
else
|
||||||
Size = ConstantInt::get(Type::Int64Ty, TD->getTypeStoreSize(AggTy));
|
Size = Context->getConstantInt(Type::Int64Ty,
|
||||||
|
TD->getTypeStoreSize(AggTy));
|
||||||
|
|
||||||
// Always generate a memcpy of alignment 1 here because we don't know
|
// Always generate a memcpy of alignment 1 here because we don't know
|
||||||
// the alignment of the src pointer. Other optimizations can infer
|
// the alignment of the src pointer. Other optimizations can infer
|
||||||
// better alignment.
|
// better alignment.
|
||||||
Value *CallArgs[] = {
|
Value *CallArgs[] = {
|
||||||
DestCast, SrcCast, Size, ConstantInt::get(Type::Int32Ty, 1)
|
DestCast, SrcCast, Size, Context->getConstantInt(Type::Int32Ty, 1)
|
||||||
};
|
};
|
||||||
CallInst *TheMemCpy =
|
CallInst *TheMemCpy =
|
||||||
CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
|
CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
|
||||||
@ -517,7 +520,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
|
|||||||
if (!TheCall->use_empty()) {
|
if (!TheCall->use_empty()) {
|
||||||
ReturnInst *R = Returns[0];
|
ReturnInst *R = Returns[0];
|
||||||
if (TheCall == R->getReturnValue())
|
if (TheCall == R->getReturnValue())
|
||||||
TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
|
TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
|
||||||
else
|
else
|
||||||
TheCall->replaceAllUsesWith(R->getReturnValue());
|
TheCall->replaceAllUsesWith(R->getReturnValue());
|
||||||
}
|
}
|
||||||
@ -610,7 +613,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
|
|||||||
// using the return value of the call with the computed value.
|
// using the return value of the call with the computed value.
|
||||||
if (!TheCall->use_empty()) {
|
if (!TheCall->use_empty()) {
|
||||||
if (TheCall == Returns[0]->getReturnValue())
|
if (TheCall == Returns[0]->getReturnValue())
|
||||||
TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
|
TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
|
||||||
else
|
else
|
||||||
TheCall->replaceAllUsesWith(Returns[0]->getReturnValue());
|
TheCall->replaceAllUsesWith(Returns[0]->getReturnValue());
|
||||||
}
|
}
|
||||||
@ -630,7 +633,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
|
|||||||
} else if (!TheCall->use_empty()) {
|
} else if (!TheCall->use_empty()) {
|
||||||
// No returns, but something is using the return value of the call. Just
|
// No returns, but something is using the return value of the call. Just
|
||||||
// nuke the result.
|
// nuke the result.
|
||||||
TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
|
TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we are now done with the Call/Invoke, we can delete it.
|
// Since we are now done with the Call/Invoke, we can delete it.
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/ADT/SetVector.h"
|
#include "llvm/ADT/SetVector.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
@ -242,7 +243,7 @@ Value *LCSSA::GetValueForBlock(DomTreeNode *BB, Instruction *OrigInst,
|
|||||||
DenseMap<DomTreeNode*, Value*> &Phis) {
|
DenseMap<DomTreeNode*, Value*> &Phis) {
|
||||||
// If there is no dominator info for this BB, it is unreachable.
|
// If there is no dominator info for this BB, it is unreachable.
|
||||||
if (BB == 0)
|
if (BB == 0)
|
||||||
return UndefValue::get(OrigInst->getType());
|
return Context->getUndef(OrigInst->getType());
|
||||||
|
|
||||||
// If we have already computed this value, return the previously computed val.
|
// If we have already computed this value, return the previously computed val.
|
||||||
if (Phis.count(BB)) return Phis[BB];
|
if (Phis.count(BB)) return Phis[BB];
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Intrinsics.h"
|
#include "llvm/Intrinsics.h"
|
||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/ADT/SmallPtrSet.h"
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/Analysis/ConstantFolding.h"
|
#include "llvm/Analysis/ConstantFolding.h"
|
||||||
#include "llvm/Analysis/DebugInfo.h"
|
#include "llvm/Analysis/DebugInfo.h"
|
||||||
@ -262,7 +263,8 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) {
|
|||||||
/// too, recursively.
|
/// too, recursively.
|
||||||
void
|
void
|
||||||
llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
|
llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
|
||||||
|
LLVMContext* Context = PN->getParent()->getContext();
|
||||||
|
|
||||||
// We can remove a PHI if it is on a cycle in the def-use graph
|
// We can remove a PHI if it is on a cycle in the def-use graph
|
||||||
// where each node in the cycle has degree one, i.e. only one use,
|
// where each node in the cycle has degree one, i.e. only one use,
|
||||||
// and is an instruction with no side effects.
|
// and is an instruction with no side effects.
|
||||||
@ -279,7 +281,7 @@ llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
|
|||||||
if (PHINode *JP = dyn_cast<PHINode>(J))
|
if (PHINode *JP = dyn_cast<PHINode>(J))
|
||||||
if (!PHIs.insert(cast<PHINode>(JP))) {
|
if (!PHIs.insert(cast<PHINode>(JP))) {
|
||||||
// Break the cycle and delete the PHI and its operands.
|
// Break the cycle and delete the PHI and its operands.
|
||||||
JP->replaceAllUsesWith(UndefValue::get(JP->getType()));
|
JP->replaceAllUsesWith(Context->getUndef(JP->getType()));
|
||||||
RecursivelyDeleteTriviallyDeadInstructions(JP);
|
RecursivelyDeleteTriviallyDeadInstructions(JP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -299,7 +301,7 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
|
|||||||
while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
|
while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
|
||||||
Value *NewVal = PN->getIncomingValue(0);
|
Value *NewVal = PN->getIncomingValue(0);
|
||||||
// Replace self referencing PHI with undef, it must be dead.
|
// Replace self referencing PHI with undef, it must be dead.
|
||||||
if (NewVal == PN) NewVal = UndefValue::get(PN->getType());
|
if (NewVal == PN) NewVal = DestBB->getContext()->getUndef(PN->getType());
|
||||||
PN->replaceAllUsesWith(NewVal);
|
PN->replaceAllUsesWith(NewVal);
|
||||||
PN->eraseFromParent();
|
PN->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
@ -165,7 +166,7 @@ bool LoopSimplify::runOnFunction(Function &F) {
|
|||||||
// Delete the dead terminator.
|
// Delete the dead terminator.
|
||||||
if (AA) AA->deleteValue(TI);
|
if (AA) AA->deleteValue(TI);
|
||||||
if (!TI->use_empty())
|
if (!TI->use_empty())
|
||||||
TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
|
TI->replaceAllUsesWith(Context->getUndef(TI->getType()));
|
||||||
TI->eraseFromParent();
|
TI->eraseFromParent();
|
||||||
Changed |= true;
|
Changed |= true;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
@ -86,10 +87,10 @@ Pass *llvm::createLowerAllocationsPass(bool LowerMallocArgToInteger) {
|
|||||||
// This function is always successful.
|
// This function is always successful.
|
||||||
//
|
//
|
||||||
bool LowerAllocations::doInitialization(Module &M) {
|
bool LowerAllocations::doInitialization(Module &M) {
|
||||||
const Type *BPTy = PointerType::getUnqual(Type::Int8Ty);
|
const Type *BPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
|
||||||
// Prototype malloc as "char* malloc(...)", because we don't know in
|
// Prototype malloc as "char* malloc(...)", because we don't know in
|
||||||
// doInitialization whether size_t is int or long.
|
// doInitialization whether size_t is int or long.
|
||||||
FunctionType *FT = FunctionType::get(BPTy, true);
|
FunctionType *FT = Context->getFunctionType(BPTy, true);
|
||||||
MallocFunc = M.getOrInsertFunction("malloc", FT);
|
MallocFunc = M.getOrInsertFunction("malloc", FT);
|
||||||
FreeFunc = M.getOrInsertFunction("free" , Type::VoidTy, BPTy, (Type *)0);
|
FreeFunc = M.getOrInsertFunction("free" , Type::VoidTy, BPTy, (Type *)0);
|
||||||
return true;
|
return true;
|
||||||
@ -115,11 +116,12 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
|
|||||||
// malloc(type) becomes i8 *malloc(size)
|
// malloc(type) becomes i8 *malloc(size)
|
||||||
Value *MallocArg;
|
Value *MallocArg;
|
||||||
if (LowerMallocArgToInteger)
|
if (LowerMallocArgToInteger)
|
||||||
MallocArg = ConstantInt::get(Type::Int64Ty,
|
MallocArg = Context->getConstantInt(Type::Int64Ty,
|
||||||
TD.getTypeAllocSize(AllocTy));
|
TD.getTypeAllocSize(AllocTy));
|
||||||
else
|
else
|
||||||
MallocArg = ConstantExpr::getSizeOf(AllocTy);
|
MallocArg = Context->getConstantExprSizeOf(AllocTy);
|
||||||
MallocArg = ConstantExpr::getTruncOrBitCast(cast<Constant>(MallocArg),
|
MallocArg =
|
||||||
|
Context->getConstantExprTruncOrBitCast(cast<Constant>(MallocArg),
|
||||||
IntPtrTy);
|
IntPtrTy);
|
||||||
|
|
||||||
if (MI->isArrayAllocation()) {
|
if (MI->isArrayAllocation()) {
|
||||||
@ -127,8 +129,10 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
|
|||||||
cast<ConstantInt>(MallocArg)->isOne()) {
|
cast<ConstantInt>(MallocArg)->isOne()) {
|
||||||
MallocArg = MI->getOperand(0); // Operand * 1 = Operand
|
MallocArg = MI->getOperand(0); // Operand * 1 = Operand
|
||||||
} else if (Constant *CO = dyn_cast<Constant>(MI->getOperand(0))) {
|
} else if (Constant *CO = dyn_cast<Constant>(MI->getOperand(0))) {
|
||||||
CO = ConstantExpr::getIntegerCast(CO, IntPtrTy, false /*ZExt*/);
|
CO =
|
||||||
MallocArg = ConstantExpr::getMul(CO, cast<Constant>(MallocArg));
|
Context->getConstantExprIntegerCast(CO, IntPtrTy, false /*ZExt*/);
|
||||||
|
MallocArg = Context->getConstantExprMul(CO,
|
||||||
|
cast<Constant>(MallocArg));
|
||||||
} else {
|
} else {
|
||||||
Value *Scale = MI->getOperand(0);
|
Value *Scale = MI->getOperand(0);
|
||||||
if (Scale->getType() != IntPtrTy)
|
if (Scale->getType() != IntPtrTy)
|
||||||
@ -150,7 +154,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
|
|||||||
if (MCall->getType() != Type::VoidTy)
|
if (MCall->getType() != Type::VoidTy)
|
||||||
MCast = new BitCastInst(MCall, MI->getType(), "", I);
|
MCast = new BitCastInst(MCall, MI->getType(), "", I);
|
||||||
else
|
else
|
||||||
MCast = Constant::getNullValue(MI->getType());
|
MCast = Context->getNullValue(MI->getType());
|
||||||
|
|
||||||
// Replace all uses of the old malloc inst with the cast inst
|
// Replace all uses of the old malloc inst with the cast inst
|
||||||
MI->replaceAllUsesWith(MCast);
|
MI->replaceAllUsesWith(MCast);
|
||||||
@ -160,7 +164,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
|
|||||||
} else if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
|
} else if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
|
||||||
Value *PtrCast =
|
Value *PtrCast =
|
||||||
new BitCastInst(FI->getOperand(0),
|
new BitCastInst(FI->getOperand(0),
|
||||||
PointerType::getUnqual(Type::Int8Ty), "", I);
|
Context->getPointerTypeUnqual(Type::Int8Ty), "", I);
|
||||||
|
|
||||||
// Insert a call to the free function...
|
// Insert a call to the free function...
|
||||||
CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall();
|
CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall();
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Intrinsics.h"
|
#include "llvm/Intrinsics.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
@ -114,33 +115,33 @@ FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) {
|
|||||||
// doInitialization - Make sure that there is a prototype for abort in the
|
// doInitialization - Make sure that there is a prototype for abort in the
|
||||||
// current module.
|
// current module.
|
||||||
bool LowerInvoke::doInitialization(Module &M) {
|
bool LowerInvoke::doInitialization(Module &M) {
|
||||||
const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
|
const Type *VoidPtrTy = Context->getPointerTypeUnqual(Type::Int8Ty);
|
||||||
AbortMessage = 0;
|
AbortMessage = 0;
|
||||||
if (ExpensiveEHSupport) {
|
if (ExpensiveEHSupport) {
|
||||||
// Insert a type for the linked list of jump buffers.
|
// Insert a type for the linked list of jump buffers.
|
||||||
unsigned JBSize = TLI ? TLI->getJumpBufSize() : 0;
|
unsigned JBSize = TLI ? TLI->getJumpBufSize() : 0;
|
||||||
JBSize = JBSize ? JBSize : 200;
|
JBSize = JBSize ? JBSize : 200;
|
||||||
const Type *JmpBufTy = ArrayType::get(VoidPtrTy, JBSize);
|
const Type *JmpBufTy = Context->getArrayType(VoidPtrTy, JBSize);
|
||||||
|
|
||||||
{ // The type is recursive, so use a type holder.
|
{ // The type is recursive, so use a type holder.
|
||||||
std::vector<const Type*> Elements;
|
std::vector<const Type*> Elements;
|
||||||
Elements.push_back(JmpBufTy);
|
Elements.push_back(JmpBufTy);
|
||||||
OpaqueType *OT = OpaqueType::get();
|
OpaqueType *OT = Context->getOpaqueType();
|
||||||
Elements.push_back(PointerType::getUnqual(OT));
|
Elements.push_back(Context->getPointerTypeUnqual(OT));
|
||||||
PATypeHolder JBLType(StructType::get(Elements));
|
PATypeHolder JBLType(Context->getStructType(Elements));
|
||||||
OT->refineAbstractTypeTo(JBLType.get()); // Complete the cycle.
|
OT->refineAbstractTypeTo(JBLType.get()); // Complete the cycle.
|
||||||
JBLinkTy = JBLType.get();
|
JBLinkTy = JBLType.get();
|
||||||
M.addTypeName("llvm.sjljeh.jmpbufty", JBLinkTy);
|
M.addTypeName("llvm.sjljeh.jmpbufty", JBLinkTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Type *PtrJBList = PointerType::getUnqual(JBLinkTy);
|
const Type *PtrJBList = Context->getPointerTypeUnqual(JBLinkTy);
|
||||||
|
|
||||||
// Now that we've done that, insert the jmpbuf list head global, unless it
|
// Now that we've done that, insert the jmpbuf list head global, unless it
|
||||||
// already exists.
|
// already exists.
|
||||||
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
|
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
|
||||||
JBListHead = new GlobalVariable(PtrJBList, false,
|
JBListHead = new GlobalVariable(PtrJBList, false,
|
||||||
GlobalValue::LinkOnceAnyLinkage,
|
GlobalValue::LinkOnceAnyLinkage,
|
||||||
Constant::getNullValue(PtrJBList),
|
Context->getNullValue(PtrJBList),
|
||||||
"llvm.sjljeh.jblist", &M);
|
"llvm.sjljeh.jblist", &M);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,26 +179,26 @@ void LowerInvoke::createAbortMessage(Module *M) {
|
|||||||
// The abort message for expensive EH support tells the user that the
|
// The abort message for expensive EH support tells the user that the
|
||||||
// program 'unwound' without an 'invoke' instruction.
|
// program 'unwound' without an 'invoke' instruction.
|
||||||
Constant *Msg =
|
Constant *Msg =
|
||||||
ConstantArray::get("ERROR: Exception thrown, but not caught!\n");
|
Context->getConstantArray("ERROR: Exception thrown, but not caught!\n");
|
||||||
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
||||||
|
|
||||||
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
||||||
GlobalValue::InternalLinkage,
|
GlobalValue::InternalLinkage,
|
||||||
Msg, "abortmsg", M);
|
Msg, "abortmsg", M);
|
||||||
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty));
|
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
|
||||||
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
|
AbortMessage = Context->getConstantExprGetElementPtr(MsgGV, &GEPIdx[0], 2);
|
||||||
} else {
|
} else {
|
||||||
// The abort message for cheap EH support tells the user that EH is not
|
// The abort message for cheap EH support tells the user that EH is not
|
||||||
// enabled.
|
// enabled.
|
||||||
Constant *Msg =
|
Constant *Msg =
|
||||||
ConstantArray::get("Exception handler needed, but not enabled. Recompile"
|
Context->getConstantArray("Exception handler needed, but not enabled."
|
||||||
" program with -enable-correct-eh-support.\n");
|
"Recompile program with -enable-correct-eh-support.\n");
|
||||||
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
||||||
|
|
||||||
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
||||||
GlobalValue::InternalLinkage,
|
GlobalValue::InternalLinkage,
|
||||||
Msg, "abortmsg", M);
|
Msg, "abortmsg", M);
|
||||||
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty));
|
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
|
||||||
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
|
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
@ -200,11 +201,11 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
|
|||||||
"SwitchLeaf", NewLeaf);
|
"SwitchLeaf", NewLeaf);
|
||||||
} else {
|
} else {
|
||||||
// Emit V-Lo <=u Hi-Lo
|
// Emit V-Lo <=u Hi-Lo
|
||||||
Constant* NegLo = ConstantExpr::getNeg(Leaf.Low);
|
Constant* NegLo = Context->getConstantExprNeg(Leaf.Low);
|
||||||
Instruction* Add = BinaryOperator::CreateAdd(Val, NegLo,
|
Instruction* Add = BinaryOperator::CreateAdd(Val, NegLo,
|
||||||
Val->getName()+".off",
|
Val->getName()+".off",
|
||||||
NewLeaf);
|
NewLeaf);
|
||||||
Constant *UpperBound = ConstantExpr::getAdd(NegLo, Leaf.High);
|
Constant *UpperBound = Context->getConstantExprAdd(NegLo, Leaf.High);
|
||||||
Comp = new ICmpInst(ICmpInst::ICMP_ULE, Add, UpperBound,
|
Comp = new ICmpInst(ICmpInst::ICMP_ULE, Add, UpperBound,
|
||||||
"SwitchLeaf", NewLeaf);
|
"SwitchLeaf", NewLeaf);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ bool PromotePass::runOnFunction(Function &F) {
|
|||||||
|
|
||||||
if (Allocas.empty()) break;
|
if (Allocas.empty()) break;
|
||||||
|
|
||||||
PromoteMemToReg(Allocas, DT, DF);
|
PromoteMemToReg(Allocas, DT, DF, Context);
|
||||||
NumPromoted += Allocas.size();
|
NumPromoted += Allocas.size();
|
||||||
Changed = true;
|
Changed = true;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
#include "llvm/Analysis/AliasSetTracker.h"
|
#include "llvm/Analysis/AliasSetTracker.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
@ -181,6 +182,8 @@ namespace {
|
|||||||
/// AST - An AliasSetTracker object to update. If null, don't update it.
|
/// AST - An AliasSetTracker object to update. If null, don't update it.
|
||||||
///
|
///
|
||||||
AliasSetTracker *AST;
|
AliasSetTracker *AST;
|
||||||
|
|
||||||
|
LLVMContext* Context;
|
||||||
|
|
||||||
/// AllocaLookup - Reverse mapping of Allocas.
|
/// AllocaLookup - Reverse mapping of Allocas.
|
||||||
///
|
///
|
||||||
@ -212,8 +215,9 @@ namespace {
|
|||||||
DenseMap<const BasicBlock*, unsigned> BBNumPreds;
|
DenseMap<const BasicBlock*, unsigned> BBNumPreds;
|
||||||
public:
|
public:
|
||||||
PromoteMem2Reg(const std::vector<AllocaInst*> &A, DominatorTree &dt,
|
PromoteMem2Reg(const std::vector<AllocaInst*> &A, DominatorTree &dt,
|
||||||
DominanceFrontier &df, AliasSetTracker *ast)
|
DominanceFrontier &df, AliasSetTracker *ast,
|
||||||
: Allocas(A), DT(dt), DF(df), AST(ast) {}
|
LLVMContext* C)
|
||||||
|
: Allocas(A), DT(dt), DF(df), AST(ast), Context(C) {}
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
@ -445,7 +449,7 @@ void PromoteMem2Reg::run() {
|
|||||||
//
|
//
|
||||||
RenamePassData::ValVector Values(Allocas.size());
|
RenamePassData::ValVector Values(Allocas.size());
|
||||||
for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
|
for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
|
||||||
Values[i] = UndefValue::get(Allocas[i]->getAllocatedType());
|
Values[i] = Context->getUndef(Allocas[i]->getAllocatedType());
|
||||||
|
|
||||||
// Walks all basic blocks in the function performing the SSA rename algorithm
|
// Walks all basic blocks in the function performing the SSA rename algorithm
|
||||||
// and inserting the phi nodes we marked as necessary
|
// and inserting the phi nodes we marked as necessary
|
||||||
@ -472,7 +476,7 @@ void PromoteMem2Reg::run() {
|
|||||||
// Just delete the users now.
|
// Just delete the users now.
|
||||||
//
|
//
|
||||||
if (!A->use_empty())
|
if (!A->use_empty())
|
||||||
A->replaceAllUsesWith(UndefValue::get(A->getType()));
|
A->replaceAllUsesWith(Context->getUndef(A->getType()));
|
||||||
if (AST) AST->deleteValue(A);
|
if (AST) AST->deleteValue(A);
|
||||||
A->eraseFromParent();
|
A->eraseFromParent();
|
||||||
}
|
}
|
||||||
@ -558,7 +562,7 @@ void PromoteMem2Reg::run() {
|
|||||||
BasicBlock::iterator BBI = BB->begin();
|
BasicBlock::iterator BBI = BB->begin();
|
||||||
while ((SomePHI = dyn_cast<PHINode>(BBI++)) &&
|
while ((SomePHI = dyn_cast<PHINode>(BBI++)) &&
|
||||||
SomePHI->getNumIncomingValues() == NumBadPreds) {
|
SomePHI->getNumIncomingValues() == NumBadPreds) {
|
||||||
Value *UndefVal = UndefValue::get(SomePHI->getType());
|
Value *UndefVal = Context->getUndef(SomePHI->getType());
|
||||||
for (unsigned pred = 0, e = Preds.size(); pred != e; ++pred)
|
for (unsigned pred = 0, e = Preds.size(); pred != e; ++pred)
|
||||||
SomePHI->addIncoming(UndefVal, Preds[pred]);
|
SomePHI->addIncoming(UndefVal, Preds[pred]);
|
||||||
}
|
}
|
||||||
@ -804,7 +808,7 @@ void PromoteMem2Reg::PromoteSingleBlockAlloca(AllocaInst *AI, AllocaInfo &Info,
|
|||||||
if (StoresByIndex.empty()) {
|
if (StoresByIndex.empty()) {
|
||||||
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E;)
|
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E;)
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(*UI++)) {
|
if (LoadInst *LI = dyn_cast<LoadInst>(*UI++)) {
|
||||||
LI->replaceAllUsesWith(UndefValue::get(LI->getType()));
|
LI->replaceAllUsesWith(Context->getUndef(LI->getType()));
|
||||||
if (AST && isa<PointerType>(LI->getType()))
|
if (AST && isa<PointerType>(LI->getType()))
|
||||||
AST->deleteValue(LI);
|
AST->deleteValue(LI);
|
||||||
LBI.deleteValue(LI);
|
LBI.deleteValue(LI);
|
||||||
@ -995,9 +999,9 @@ NextIteration:
|
|||||||
///
|
///
|
||||||
void llvm::PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
|
void llvm::PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
|
||||||
DominatorTree &DT, DominanceFrontier &DF,
|
DominatorTree &DT, DominanceFrontier &DF,
|
||||||
AliasSetTracker *AST) {
|
LLVMContext* Context, AliasSetTracker *AST) {
|
||||||
// If there is nothing to do, bail out...
|
// If there is nothing to do, bail out...
|
||||||
if (Allocas.empty()) return;
|
if (Allocas.empty()) return;
|
||||||
|
|
||||||
PromoteMem2Reg(Allocas, DT, DF, AST).run();
|
PromoteMem2Reg(Allocas, DT, DF, AST, Context).run();
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/GlobalVariable.h"
|
#include "llvm/GlobalVariable.h"
|
||||||
@ -1274,6 +1275,8 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
|
|||||||
/// FoldTwoEntryPHINode - Given a BB that starts with the specified two-entry
|
/// FoldTwoEntryPHINode - Given a BB that starts with the specified two-entry
|
||||||
/// PHI node, see if we can eliminate it.
|
/// PHI node, see if we can eliminate it.
|
||||||
static bool FoldTwoEntryPHINode(PHINode *PN) {
|
static bool FoldTwoEntryPHINode(PHINode *PN) {
|
||||||
|
LLVMContext* Context = PN->getParent()->getContext();
|
||||||
|
|
||||||
// Ok, this is a two entry PHI node. Check to see if this is a simple "if
|
// Ok, this is a two entry PHI node. Check to see if this is a simple "if
|
||||||
// statement", which has a very simple dominance structure. Basically, we
|
// statement", which has a very simple dominance structure. Basically, we
|
||||||
// are trying to find the condition that is being branched on, which
|
// are trying to find the condition that is being branched on, which
|
||||||
@ -1311,7 +1314,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN) {
|
|||||||
if (PN->getIncomingValue(0) != PN)
|
if (PN->getIncomingValue(0) != PN)
|
||||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
||||||
else
|
else
|
||||||
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
|
PN->replaceAllUsesWith(Context->getUndef(PN->getType()));
|
||||||
} else if (!DominatesMergePoint(PN->getIncomingValue(0), BB,
|
} else if (!DominatesMergePoint(PN->getIncomingValue(0), BB,
|
||||||
&AggressiveInsts) ||
|
&AggressiveInsts) ||
|
||||||
!DominatesMergePoint(PN->getIncomingValue(1), BB,
|
!DominatesMergePoint(PN->getIncomingValue(1), BB,
|
||||||
@ -1605,6 +1608,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
|
|||||||
static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
||||||
assert(PBI->isConditional() && BI->isConditional());
|
assert(PBI->isConditional() && BI->isConditional());
|
||||||
BasicBlock *BB = BI->getParent();
|
BasicBlock *BB = BI->getParent();
|
||||||
|
LLVMContext* Context = BB->getContext();
|
||||||
|
|
||||||
// If this block ends with a branch instruction, and if there is a
|
// If this block ends with a branch instruction, and if there is a
|
||||||
// predecessor that ends on a branch of the same condition, make
|
// predecessor that ends on a branch of the same condition, make
|
||||||
@ -1616,7 +1620,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
|||||||
if (BB->getSinglePredecessor()) {
|
if (BB->getSinglePredecessor()) {
|
||||||
// Turn this into a branch on constant.
|
// Turn this into a branch on constant.
|
||||||
bool CondIsTrue = PBI->getSuccessor(0) == BB;
|
bool CondIsTrue = PBI->getSuccessor(0) == BB;
|
||||||
BI->setCondition(ConstantInt::get(Type::Int1Ty, CondIsTrue));
|
BI->setCondition(Context->getConstantInt(Type::Int1Ty, CondIsTrue));
|
||||||
return true; // Nuke the branch on constant.
|
return true; // Nuke the branch on constant.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1636,7 +1640,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
|||||||
PBI->getCondition() == BI->getCondition() &&
|
PBI->getCondition() == BI->getCondition() &&
|
||||||
PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
|
PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
|
||||||
bool CondIsTrue = PBI->getSuccessor(0) == BB;
|
bool CondIsTrue = PBI->getSuccessor(0) == BB;
|
||||||
NewPN->addIncoming(ConstantInt::get(Type::Int1Ty,
|
NewPN->addIncoming(Context->getConstantInt(Type::Int1Ty,
|
||||||
CondIsTrue), *PI);
|
CondIsTrue), *PI);
|
||||||
} else {
|
} else {
|
||||||
NewPN->addIncoming(BI->getCondition(), *PI);
|
NewPN->addIncoming(BI->getCondition(), *PI);
|
||||||
|
@ -13,14 +13,16 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Transforms/Utils/ValueMapper.h"
|
#include "llvm/Transforms/Utils/ValueMapper.h"
|
||||||
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/GlobalValue.h"
|
#include "llvm/GlobalValue.h"
|
||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/MDNode.h"
|
#include "llvm/MDNode.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext* Context) {
|
||||||
Value *&VMSlot = VM[V];
|
Value *&VMSlot = VM[V];
|
||||||
if (VMSlot) return VMSlot; // Does it exist in the map yet?
|
if (VMSlot) return VMSlot; // Does it exist in the map yet?
|
||||||
|
|
||||||
@ -40,7 +42,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
|
else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
|
||||||
for (User::op_iterator b = CA->op_begin(), i = b, e = CA->op_end();
|
for (User::op_iterator b = CA->op_begin(), i = b, e = CA->op_end();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
Value *MV = MapValue(*i, VM);
|
Value *MV = MapValue(*i, VM, Context);
|
||||||
if (MV != *i) {
|
if (MV != *i) {
|
||||||
// This array must contain a reference to a global, make a new array
|
// This array must contain a reference to a global, make a new array
|
||||||
// and return it.
|
// and return it.
|
||||||
@ -51,8 +53,8 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
Values.push_back(cast<Constant>(*j));
|
Values.push_back(cast<Constant>(*j));
|
||||||
Values.push_back(cast<Constant>(MV));
|
Values.push_back(cast<Constant>(MV));
|
||||||
for (++i; i != e; ++i)
|
for (++i; i != e; ++i)
|
||||||
Values.push_back(cast<Constant>(MapValue(*i, VM)));
|
Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
|
||||||
return VM[V] = ConstantArray::get(CA->getType(), Values);
|
return VM[V] = Context->getConstantArray(CA->getType(), Values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return VM[V] = C;
|
return VM[V] = C;
|
||||||
@ -60,7 +62,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
} else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
|
} else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
|
||||||
for (User::op_iterator b = CS->op_begin(), i = b, e = CS->op_end();
|
for (User::op_iterator b = CS->op_begin(), i = b, e = CS->op_end();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
Value *MV = MapValue(*i, VM);
|
Value *MV = MapValue(*i, VM, Context);
|
||||||
if (MV != *i) {
|
if (MV != *i) {
|
||||||
// This struct must contain a reference to a global, make a new struct
|
// This struct must contain a reference to a global, make a new struct
|
||||||
// and return it.
|
// and return it.
|
||||||
@ -71,8 +73,8 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
Values.push_back(cast<Constant>(*j));
|
Values.push_back(cast<Constant>(*j));
|
||||||
Values.push_back(cast<Constant>(MV));
|
Values.push_back(cast<Constant>(MV));
|
||||||
for (++i; i != e; ++i)
|
for (++i; i != e; ++i)
|
||||||
Values.push_back(cast<Constant>(MapValue(*i, VM)));
|
Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
|
||||||
return VM[V] = ConstantStruct::get(CS->getType(), Values);
|
return VM[V] = Context->getConstantStruct(CS->getType(), Values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return VM[V] = C;
|
return VM[V] = C;
|
||||||
@ -80,12 +82,12 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
||||||
std::vector<Constant*> Ops;
|
std::vector<Constant*> Ops;
|
||||||
for (User::op_iterator i = CE->op_begin(), e = CE->op_end(); i != e; ++i)
|
for (User::op_iterator i = CE->op_begin(), e = CE->op_end(); i != e; ++i)
|
||||||
Ops.push_back(cast<Constant>(MapValue(*i, VM)));
|
Ops.push_back(cast<Constant>(MapValue(*i, VM, Context)));
|
||||||
return VM[V] = CE->getWithOperands(Ops);
|
return VM[V] = CE->getWithOperands(Ops);
|
||||||
} else if (ConstantVector *CP = dyn_cast<ConstantVector>(C)) {
|
} else if (ConstantVector *CP = dyn_cast<ConstantVector>(C)) {
|
||||||
for (User::op_iterator b = CP->op_begin(), i = b, e = CP->op_end();
|
for (User::op_iterator b = CP->op_begin(), i = b, e = CP->op_end();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
Value *MV = MapValue(*i, VM);
|
Value *MV = MapValue(*i, VM, Context);
|
||||||
if (MV != *i) {
|
if (MV != *i) {
|
||||||
// This vector value must contain a reference to a global, make a new
|
// This vector value must contain a reference to a global, make a new
|
||||||
// vector constant and return it.
|
// vector constant and return it.
|
||||||
@ -96,8 +98,8 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
Values.push_back(cast<Constant>(*j));
|
Values.push_back(cast<Constant>(*j));
|
||||||
Values.push_back(cast<Constant>(MV));
|
Values.push_back(cast<Constant>(MV));
|
||||||
for (++i; i != e; ++i)
|
for (++i; i != e; ++i)
|
||||||
Values.push_back(cast<Constant>(MapValue(*i, VM)));
|
Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
|
||||||
return VM[V] = ConstantVector::get(Values);
|
return VM[V] = Context->getConstantVector(Values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return VM[V] = C;
|
return VM[V] = C;
|
||||||
@ -107,7 +109,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
e = N->elem_end(); i != e; ++i) {
|
e = N->elem_end(); i != e; ++i) {
|
||||||
if (!*i) continue;
|
if (!*i) continue;
|
||||||
|
|
||||||
Value *MV = MapValue(*i, VM);
|
Value *MV = MapValue(*i, VM, Context);
|
||||||
if (MV != *i) {
|
if (MV != *i) {
|
||||||
// This MDNode must contain a reference to a global, make a new MDNode
|
// This MDNode must contain a reference to a global, make a new MDNode
|
||||||
// and return it.
|
// and return it.
|
||||||
@ -117,8 +119,8 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
Values.push_back(*j);
|
Values.push_back(*j);
|
||||||
Values.push_back(MV);
|
Values.push_back(MV);
|
||||||
for (++i; i != e; ++i)
|
for (++i; i != e; ++i)
|
||||||
Values.push_back(MapValue(*i, VM));
|
Values.push_back(MapValue(*i, VM, Context));
|
||||||
return VM[V] = MDNode::get(Values.data(), Values.size());
|
return VM[V] = Context->getMDNode(Values.data(), Values.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return VM[V] = C;
|
return VM[V] = C;
|
||||||
@ -136,7 +138,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
|
|||||||
///
|
///
|
||||||
void llvm::RemapInstruction(Instruction *I, ValueMapTy &ValueMap) {
|
void llvm::RemapInstruction(Instruction *I, ValueMapTy &ValueMap) {
|
||||||
for (User::op_iterator op = I->op_begin(), E = I->op_end(); op != E; ++op) {
|
for (User::op_iterator op = I->op_begin(), E = I->op_end(); op != E; ++op) {
|
||||||
Value *V = MapValue(*op, ValueMap);
|
Value *V = MapValue(*op, ValueMap, I->getParent()->getContext());
|
||||||
assert(V && "Referenced value not in value map!");
|
assert(V && "Referenced value not in value map!");
|
||||||
*op = V;
|
*op = V;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,10 @@ ValueSymbolTable *BasicBlock::getValueSymbolTable() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LLVMContext* BasicBlock::getContext() const {
|
||||||
|
return Parent ? Parent->getContext() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Explicit instantiation of SymbolTableListTraits since some of the methods
|
// Explicit instantiation of SymbolTableListTraits since some of the methods
|
||||||
// are not in the public header file...
|
// are not in the public header file...
|
||||||
template class SymbolTableListTraits<Instruction, BasicBlock>;
|
template class SymbolTableListTraits<Instruction, BasicBlock>;
|
||||||
|
@ -114,8 +114,8 @@ void Argument::removeAttr(Attributes attr) {
|
|||||||
// Helper Methods in Function
|
// Helper Methods in Function
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
LLVMContext* Function::getContext() {
|
LLVMContext* Function::getContext() const {
|
||||||
Module* M = getParent();
|
const Module* M = getParent();
|
||||||
if (M) return &M->getContext();
|
if (M) return &M->getContext();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -374,6 +374,10 @@ Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
|
|||||||
return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
|
return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
|
||||||
|
return ConstantExpr::getSizeOf(Ty);
|
||||||
|
}
|
||||||
|
|
||||||
Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
|
Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
|
||||||
return ConstantExpr::getZeroValueForNegationExpr(Ty);
|
return ConstantExpr::getZeroValueForNegationExpr(Ty);
|
||||||
}
|
}
|
||||||
@ -428,6 +432,10 @@ MDString* LLVMContext::getMDString(const std::string &Str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FunctionType accessors
|
// FunctionType accessors
|
||||||
|
FunctionType* LLVMContext::getFunctionType(const Type* Result, bool isVarArg) {
|
||||||
|
return FunctionType::get(Result, isVarArg);
|
||||||
|
}
|
||||||
|
|
||||||
FunctionType* LLVMContext::getFunctionType(const Type* Result,
|
FunctionType* LLVMContext::getFunctionType(const Type* Result,
|
||||||
const std::vector<const Type*>& Params,
|
const std::vector<const Type*>& Params,
|
||||||
bool isVarArg) {
|
bool isVarArg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user