// Set up the optimizer pipeline.
// Start with registering info about how the
// target lays out data structures.
- fpm.add(new llvm::DataLayoutPass(*executionEngine->getDataLayout()));
+ module->setDataLayout(executionEngine->getDataLayout());
+ fpm.add(new llvm::DataLayoutPass(module));
// Optimizations turned on
#ifdef ADD_OPT_PASSES
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
- OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
+ TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+ OurFPM.add(new DataLayoutPass(TheModule));
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
- OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
+ TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+ OurFPM.add(new DataLayoutPass(TheModule));
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
- OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
+ TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+ OurFPM.add(new DataLayoutPass(TheModule));
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
- OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
+ TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+ OurFPM.add(new DataLayoutPass(TheModule));
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Promote allocas to registers.
/// \brief Cost analyzer used by inliner.
class InlineCostAnalysis : public CallGraphSCCPass {
- const DataLayout *DL;
const TargetTransformInfo *TTI;
public:
const Function *getParent() const { return Parent; }
Function *getParent() { return Parent; }
+ const DataLayout *getDataLayout() const;
+
/// \brief Returns the terminator instruction if the block is well formed or
/// null if the block is not well formed.
TerminatorInst *getTerminator();
const DataLayout &getDataLayout() const { return DL; }
+ // For use with the C API. C++ code should always use the constructor that
+ // takes a module.
explicit DataLayoutPass(const DataLayout &DL);
- explicit DataLayoutPass(StringRef LayoutDescription);
-
explicit DataLayoutPass(const Module *M);
static char ID; // Pass identification, replacement for typeid
inline Module *getParent() { return Parent; }
inline const Module *getParent() const { return Parent; }
+ const DataLayout *getDataLayout() const;
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Value *V) {
return V->getValueID() == Value::FunctionVal ||
inline const BasicBlock *getParent() const { return Parent; }
inline BasicBlock *getParent() { return Parent; }
+ const DataLayout *getDataLayout() const;
+
/// removeFromParent - This method unlinks 'this' from the containing basic
/// block, but does not delete it.
///
}
bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) {
+ const DataLayout *DL = I.getDataLayout();
// Propagate constants through ptrtoint.
Constant *COp = dyn_cast<Constant>(I.getOperand(0));
if (!COp)
}
bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
+ const DataLayout *DL = I.getDataLayout();
// Propagate constants through ptrtoint.
Constant *COp = dyn_cast<Constant>(I.getOperand(0));
if (!COp)
char InlineCostAnalysis::ID = 0;
-InlineCostAnalysis::InlineCostAnalysis() : CallGraphSCCPass(ID), DL(0) {}
+InlineCostAnalysis::InlineCostAnalysis() : CallGraphSCCPass(ID) {}
InlineCostAnalysis::~InlineCostAnalysis() {}
}
bool InlineCostAnalysis::runOnSCC(CallGraphSCC &SCC) {
- DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
- DL = DLP ? &DLP->getDataLayout() : 0;
TTI = &getAnalysis<TargetTransformInfo>();
return false;
}
DEBUG(llvm::dbgs() << " Analyzing call of " << Callee->getName()
<< "...\n");
- CallAnalyzer CA(DL, *TTI, *Callee, Threshold);
+ CallAnalyzer CA(Callee->getDataLayout(), *TTI, *Callee, Threshold);
bool ShouldInline = CA.analyzeCall(CS);
DEBUG(CA.dump());
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
// Add target data
MutexGuard locked(lock);
FunctionPassManager &PM = jitstate->getPM(locked);
- PM.add(new DataLayoutPass(*TM.getDataLayout()));
+ M->setDataLayout(TM.getDataLayout());
+ PM.add(new DataLayoutPass(M));
// Turn the machine code intermediate representation into bytes in memory that
// may be executed.
jitstate = new JITState(M);
FunctionPassManager &PM = jitstate->getPM(locked);
- PM.add(new DataLayoutPass(*TM.getDataLayout()));
+ M->setDataLayout(TM.getDataLayout());
+ PM.add(new DataLayoutPass(M));
// Turn the machine code intermediate representation into bytes in memory
// that may be executed.
jitstate = new JITState(Modules[0]);
FunctionPassManager &PM = jitstate->getPM(locked);
- PM.add(new DataLayoutPass(*TM.getDataLayout()));
+ M->setDataLayout(TM.getDataLayout());
+ PM.add(new DataLayoutPass(M));
// Turn the machine code intermediate representation into bytes in memory
// that may be executed.
PassManager PM;
- PM.add(new DataLayoutPass(*TM->getDataLayout()));
+ M->setDataLayout(TM->getDataLayout());
+ PM.add(new DataLayoutPass(M));
// The RuntimeDyld will take ownership of this shortly
OwningPtr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
return 0;
}
+const DataLayout *BasicBlock::getDataLayout() const {
+ return getParent()->getDataLayout();
+}
+
LLVMContext &BasicBlock::getContext() const {
return getType()->getContext();
}
initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
}
-DataLayoutPass::DataLayoutPass(StringRef Str) : ImmutablePass(ID), DL(Str) {
- initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
-}
-
DataLayoutPass::DataLayoutPass(const Module *M) : ImmutablePass(ID), DL(M) {
initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
}
getParent()->Dematerialize(this);
}
+const DataLayout *GlobalValue::getDataLayout() const {
+ return getParent()->getDataLayout();
+}
+
/// Override destroyConstant to make sure it doesn't get called on
/// GlobalValue's because they shouldn't be treated like other constants.
void GlobalValue::destroyConstant() {
}
}
+const DataLayout *Instruction::getDataLayout() const {
+ return getParent()->getDataLayout();
+}
+
Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
BasicBlock *InsertAtEnd)
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
passes.add(createVerifierPass());
// Add an appropriate DataLayout instance for this module...
- passes.add(new DataLayoutPass(*TargetMach->getDataLayout()));
+ mergedModule->setDataLayout(TargetMach->getDataLayout());
+ passes.add(new DataLayoutPass(mergedModule));
// Add appropriate TargetLibraryInfo for this module.
passes.add(new TargetLibraryInfo(Triple(TargetMach->getTargetTriple())));
PassManager codeGenPasses;
- codeGenPasses.add(new DataLayoutPass(*TargetMach->getDataLayout()));
+ codeGenPasses.add(new DataLayoutPass(mergedModule));
formatted_raw_ostream Out(out);
}
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
+ // The DataLayoutPass must now be in sync with the module. Unfortunatelly we
+ // cannot enforce that from the C api.
unwrap(PM)->add(new DataLayoutPass(*unwrap(TD)));
}
*ErrorMessage = strdup(error.c_str());
return true;
}
- pass.add(new DataLayoutPass(*td));
+ Mod->setDataLayout(td);
+ pass.add(new DataLayoutPass(Mod));
TargetMachine::CodeGenFileType ft;
switch (codegen) {
// Add the target data from the target machine, if it exists, or the module.
if (const DataLayout *DL = Target.getDataLayout())
- PM.add(new DataLayoutPass(*DL));
- else
- PM.add(new DataLayoutPass(mod));
+ mod->setDataLayout(DL);
+ PM.add(new DataLayoutPass(mod));
// Override default to generate verbose assembly.
Target.setAsmVerbosityDefault(true);
// Add an appropriate DataLayout instance for this module.
const DataLayout *DL = M.get()->getDataLayout();
- if (!DL && !DefaultDataLayout.empty())
- DL = new DataLayout(DefaultDataLayout);
+ if (!DL && !DefaultDataLayout.empty()) {
+ M->setDataLayout(DefaultDataLayout);
+ DL = M.get()->getDataLayout();
+ }
if (DL)
- Passes.add(new DataLayoutPass(*DL));
+ Passes.add(new DataLayoutPass(M.get()));
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = 0;
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
FPasses.reset(new FunctionPassManager(M.get()));
if (DL)
- FPasses->add(new DataLayoutPass(*DL));
+ FPasses->add(new DataLayoutPass(M.get()));
if (TM.get())
TM->addAnalysisPasses(*FPasses);