Add a new interface to allow IR-level passes to access codegen-specific information.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165665 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nadav Rotem 2012-10-10 22:04:55 +00:00
parent 3a55b64e5e
commit e3d0e86919
43 changed files with 811 additions and 317 deletions

View File

@ -22,7 +22,7 @@
#include <set> #include <set>
namespace llvm { namespace llvm {
class TargetLowering; class ScalarTargetTransformInfo;
/// Return true if the given expression is safe to expand in the sense that /// Return true if the given expression is safe to expand in the sense that
/// all materialized values are safe to speculate. /// all materialized values are safe to speculate.
@ -129,7 +129,7 @@ namespace llvm {
/// representative. Return the number of phis eliminated. /// representative. Return the number of phis eliminated.
unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT, unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT,
SmallVectorImpl<WeakVH> &DeadInsts, SmallVectorImpl<WeakVH> &DeadInsts,
const TargetLowering *TLI = NULL); const ScalarTargetTransformInfo *STTI = NULL);
/// expandCodeFor - Insert code to directly compute the specified SCEV /// expandCodeFor - Insert code to directly compute the specified SCEV
/// expression into the program. The inserted code is inserted into the /// expression into the program. The inserted code is inserted into the

View File

@ -0,0 +1,228 @@
//===-- CommandFlags.h - Register Coalescing Interface ----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains codegen-specific flags that are shared between different
// command line tools. The tools "llc" and "opt" both use this file to prevent
// flag duplication.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CODEGEN_COMMAND_LINE_FLAGS_H
#define LLVM_CODEGEN_COMMAND_LINE_FLAGS_H
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Target/TargetMachine.h"
#include <string>
using namespace llvm;
cl::opt<std::string>
MArch("march", cl::desc("Architecture to generate code for (see --version)"));
cl::opt<std::string>
MCPU("mcpu",
cl::desc("Target a specific cpu type (-mcpu=help for details)"),
cl::value_desc("cpu-name"),
cl::init(""));
cl::list<std::string>
MAttrs("mattr",
cl::CommaSeparated,
cl::desc("Target specific attributes (-mattr=help for details)"),
cl::value_desc("a1,+a2,-a3,..."));
cl::opt<Reloc::Model>
RelocModel("relocation-model",
cl::desc("Choose relocation model"),
cl::init(Reloc::Default),
cl::values(
clEnumValN(Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(Reloc::Static, "static",
"Non-relocatable code"),
clEnumValN(Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));
cl::opt<llvm::CodeModel::Model>
CMModel("code-model",
cl::desc("Choose code model"),
cl::init(CodeModel::Default),
cl::values(clEnumValN(CodeModel::Default, "default",
"Target default code model"),
clEnumValN(CodeModel::Small, "small",
"Small code model"),
clEnumValN(CodeModel::Kernel, "kernel",
"Kernel code model"),
clEnumValN(CodeModel::Medium, "medium",
"Medium code model"),
clEnumValN(CodeModel::Large, "large",
"Large code model"),
clEnumValEnd));
cl::opt<bool>
RelaxAll("mc-relax-all",
cl::desc("When used with filetype=obj, "
"relax all fixups in the emitted object file"));
cl::opt<TargetMachine::CodeGenFileType>
FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
cl::desc("Choose a file type (not all types are supported by all targets):"),
cl::values(
clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
"Emit an assembly ('.s') file"),
clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
"Emit a native object ('.o') file"),
clEnumValN(TargetMachine::CGFT_Null, "null",
"Emit nothing, for performance testing"),
clEnumValEnd));
cl::opt<bool> DisableDotLoc("disable-dot-loc", cl::Hidden,
cl::desc("Do not use .loc entries"));
cl::opt<bool> DisableCFI("disable-cfi", cl::Hidden,
cl::desc("Do not use .cfi_* directives"));
cl::opt<bool> EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden,
cl::desc("Use .file directives with an explicit directory."));
cl::opt<bool>
DisableRedZone("disable-red-zone",
cl::desc("Do not emit code that uses the red zone."),
cl::init(false));
cl::opt<bool>
EnableFPMAD("enable-fp-mad",
cl::desc("Enable less precise MAD instructions to be generated"),
cl::init(false));
cl::opt<bool>
DisableFPElim("disable-fp-elim",
cl::desc("Disable frame pointer elimination optimization"),
cl::init(false));
cl::opt<bool>
DisableFPElimNonLeaf("disable-non-leaf-fp-elim",
cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"),
cl::init(false));
cl::opt<bool>
EnableUnsafeFPMath("enable-unsafe-fp-math",
cl::desc("Enable optimizations that may decrease FP precision"),
cl::init(false));
cl::opt<bool>
EnableNoInfsFPMath("enable-no-infs-fp-math",
cl::desc("Enable FP math optimizations that assume no +-Infs"),
cl::init(false));
cl::opt<bool>
EnableNoNaNsFPMath("enable-no-nans-fp-math",
cl::desc("Enable FP math optimizations that assume no NaNs"),
cl::init(false));
cl::opt<bool>
EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
cl::Hidden,
cl::desc("Force codegen to assume rounding mode can change dynamically"),
cl::init(false));
cl::opt<bool>
GenerateSoftFloatCalls("soft-float",
cl::desc("Generate software floating point library calls"),
cl::init(false));
cl::opt<llvm::FloatABI::ABIType>
FloatABIForCalls("float-abi",
cl::desc("Choose float ABI type"),
cl::init(FloatABI::Default),
cl::values(
clEnumValN(FloatABI::Default, "default",
"Target default float ABI type"),
clEnumValN(FloatABI::Soft, "soft",
"Soft float ABI (implied by -soft-float)"),
clEnumValN(FloatABI::Hard, "hard",
"Hard float ABI (uses FP registers)"),
clEnumValEnd));
cl::opt<llvm::FPOpFusion::FPOpFusionMode>
FuseFPOps("fp-contract",
cl::desc("Enable aggresive formation of fused FP ops"),
cl::init(FPOpFusion::Standard),
cl::values(
clEnumValN(FPOpFusion::Fast, "fast",
"Fuse FP ops whenever profitable"),
clEnumValN(FPOpFusion::Standard, "on",
"Only fuse 'blessed' FP ops."),
clEnumValN(FPOpFusion::Strict, "off",
"Only fuse FP ops when the result won't be effected."),
clEnumValEnd));
cl::opt<bool>
DontPlaceZerosInBSS("nozero-initialized-in-bss",
cl::desc("Don't place zero-initialized symbols into bss section"),
cl::init(false));
cl::opt<bool>
EnableGuaranteedTailCallOpt("tailcallopt",
cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
cl::init(false));
cl::opt<bool>
DisableTailCalls("disable-tail-calls",
cl::desc("Never emit tail calls"),
cl::init(false));
cl::opt<unsigned>
OverrideStackAlignment("stack-alignment",
cl::desc("Override default stack alignment"),
cl::init(0));
cl::opt<bool>
EnableRealignStack("realign-stack",
cl::desc("Realign stack if needed"),
cl::init(true));
cl::opt<std::string>
TrapFuncName("trap-func", cl::Hidden,
cl::desc("Emit a call to trap function rather than a trap instruction"),
cl::init(""));
cl::opt<bool>
EnablePIE("enable-pie",
cl::desc("Assume the creation of a position independent executable."),
cl::init(false));
cl::opt<bool>
SegmentedStacks("segmented-stacks",
cl::desc("Use segmented stacks if possible."),
cl::init(false));
cl::opt<bool>
UseInitArray("use-init-array",
cl::desc("Use .init_array instead of .ctors."),
cl::init(false));
cl::opt<std::string> StopAfter("stop-after",
cl::desc("Stop compilation after a specific pass"),
cl::value_desc("pass-name"),
cl::init(""));
cl::opt<std::string> StartAfter("start-after",
cl::desc("Resume compilation after a specific pass"),
cl::value_desc("pass-name"),
cl::init(""));
cl::opt<unsigned>
SSPBufferSize("stack-protector-buffer-size", cl::init(8),
cl::desc("Lower bound for a buffer to be considered for "
"stack protection"));
#endif

View File

@ -247,6 +247,7 @@ void initializeTailCallElimPass(PassRegistry&);
void initializeTailDuplicatePassPass(PassRegistry&); void initializeTailDuplicatePassPass(PassRegistry&);
void initializeTargetPassConfigPass(PassRegistry&); void initializeTargetPassConfigPass(PassRegistry&);
void initializeDataLayoutPass(PassRegistry&); void initializeDataLayoutPass(PassRegistry&);
void initializeTargetTransformInfoPass(PassRegistry&);
void initializeTargetLibraryInfoPass(PassRegistry&); void initializeTargetLibraryInfoPass(PassRegistry&);
void initializeTwoAddressInstructionPassPass(PassRegistry&); void initializeTwoAddressInstructionPassPass(PassRegistry&);
void initializeTypeBasedAliasAnalysisPass(PassRegistry&); void initializeTypeBasedAliasAnalysisPass(PassRegistry&);

View File

@ -17,6 +17,8 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Support/CodeGen.h" #include "llvm/Support/CodeGen.h"
#include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetOptions.h"
#include "llvm/TargetTransformInfo.h"
#include "llvm/Target/TargetTransformImpl.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include <cassert> #include <cassert>
#include <string> #include <string>
@ -107,6 +109,10 @@ public:
virtual const TargetLowering *getTargetLowering() const { return 0; } virtual const TargetLowering *getTargetLowering() const { return 0; }
virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; } virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
virtual const DataLayout *getDataLayout() const { return 0; } virtual const DataLayout *getDataLayout() const { return 0; }
virtual const ScalarTargetTransformInfo*
getScalarTargetTransformInfo() const { return 0; }
virtual const VectorTargetTransformInfo*
getVectorTargetTransformInfo() const { return 0; }
/// getMCAsmInfo - Return target specific asm information. /// getMCAsmInfo - Return target specific asm information.
/// ///

View File

@ -0,0 +1,54 @@
//=- llvm/Target/TargetTransformImpl.h - Target Loop Trans Info----*- C++ -*-=//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the target-specific implementations of the
// TargetTransform interfaces.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TARGET_TARGET_TRANSFORMATION_IMPL_H
#define LLVM_TARGET_TARGET_TRANSFORMATION_IMPL_H
#include "llvm/TargetTransformInfo.h"
namespace llvm {
class TargetLowering;
/// ScalarTargetTransformInfo - This is a default implementation for the
/// ScalarTargetTransformInfo interface. Different targets can implement
/// this interface differently.
class ScalarTargetTransformImpl : public ScalarTargetTransformInfo {
private:
const TargetLowering *TLI;
public:
/// Ctor
explicit ScalarTargetTransformImpl(const TargetLowering *TL): TLI(TL) {}
virtual bool isLegalAddImmediate(int64_t imm) const;
virtual bool isLegalICmpImmediate(int64_t imm) const;
virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const;
virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const;
virtual bool isTypeLegal(Type *Ty) const;
virtual unsigned getJumpBufAlignment() const;
virtual unsigned getJumpBufSize() const;
};
class VectorTargetTransformImpl : public VectorTargetTransformInfo { };
} // end llvm namespace
#endif

View File

@ -0,0 +1,126 @@
//===- llvm/Transforms/TargetTransformInfo.h --------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This pass exposes codegen information to IR-level passes. Every
// transformation that uses codegen information is broken into three parts:
// 1. The IR-level analysis pass.
// 2. The IR-level transformation interface which provides the needed
// information.
// 3. Codegen-level implementation which uses target-specific hooks.
//
// This file defines #2, which is the interface that IR-level transformations
// use for querying the codegen.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_TARGET_TRANSFORM_INTERFACE
#define LLVM_TRANSFORMS_TARGET_TRANSFORM_INTERFACE
#include "llvm/Pass.h"
#include "llvm/AddressingMode.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Type.h"
namespace llvm {
class ScalarTargetTransformInfo;
class VectorTargetTransformInfo;
/// TargetTransformInfo - This pass provides access to the codegen
/// interfaces that are needed for IR-level transformations.
class TargetTransformInfo : public ImmutablePass {
private:
const ScalarTargetTransformInfo *STTI;
const VectorTargetTransformInfo *VTTI;
public:
/// Default ctor.
///
/// @note This has to exist, because this is a pass, but it should never be
/// used.
TargetTransformInfo();
explicit TargetTransformInfo(const ScalarTargetTransformInfo* S,
const VectorTargetTransformInfo *V)
: ImmutablePass(ID), STTI(S), VTTI(V) {
initializeTargetTransformInfoPass(*PassRegistry::getPassRegistry());
}
TargetTransformInfo(const TargetTransformInfo &T) :
ImmutablePass(ID), STTI(T.STTI), VTTI(T.VTTI) { }
const ScalarTargetTransformInfo* getScalarTargetTransformInfo() {
return STTI;
}
const VectorTargetTransformInfo* getVectorTargetTransformInfo() {
return VTTI;
}
/// Pass identification, replacement for typeid.
static char ID;
};
// ---------------------------------------------------------------------------//
// The classes below are inherited and implemented by target-specific classes
// in the codegen.
// ---------------------------------------------------------------------------//
/// ScalarTargetTransformInfo - This interface is used by IR-level passes
/// that need target-dependent information for generic scalar transformations.
/// LSR, and LowerInvoke use this interface.
class ScalarTargetTransformInfo {
public:
/// isLegalAddImmediate - Return true if the specified immediate is legal
/// add immediate, that is the target has add instructions which can add
/// a register with the immediate without having to materialize the
/// immediate into a register.
virtual bool isLegalAddImmediate(int64_t) const {
return false;
}
/// isLegalICmpImmediate - Return true if the specified immediate is legal
/// icmp immediate, that is the target has icmp instructions which can compare
/// a register against the immediate without having to materialize the
/// immediate into a register.
virtual bool isLegalICmpImmediate(int64_t) const {
return false;
}
/// isLegalAddressingMode - Return true if the addressing mode represented by
/// AM is legal for this target, for a load/store of the specified type.
/// The type may be VoidTy, in which case only return true if the addressing
/// mode is legal for a load/store of any legal type.
/// TODO: Handle pre/postinc as well.
virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const {
return false;
}
/// isTruncateFree - Return true if it's free to truncate a value of
/// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
/// register EAX to i16 by referencing its sub-register AX.
virtual bool isTruncateFree(Type * /*Ty1*/, Type * /*Ty2*/) const {
return false;
}
/// Is this type legal.
virtual bool isTypeLegal(Type *Ty) const {
return false;
}
/// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
virtual unsigned getJumpBufAlignment() const {
return 0;
}
/// getJumpBufSize - returns the target's jmp_buf size in bytes.
virtual unsigned getJumpBufSize() const {
return 0;
}
};
class VectorTargetTransformInfo {
// TODO: define an interface for VectorTargetTransformInfo.
};
} // End llvm namespace
#endif

View File

@ -119,7 +119,7 @@ Pass *createLICMPass();
// optional parameter used to consult the target machine whether certain // optional parameter used to consult the target machine whether certain
// transformations are profitable. // transformations are profitable.
// //
Pass *createLoopStrengthReducePass(const TargetLowering *TLI = 0); Pass *createLoopStrengthReducePass();
Pass *createGlobalMergePass(const TargetLowering *TLI = 0); Pass *createGlobalMergePass(const TargetLowering *TLI = 0);
@ -249,9 +249,8 @@ extern char &LowerSwitchID;
// purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet" // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
// lowering pass. // lowering pass.
// //
FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0); FunctionPass *createLowerInvokePass();
FunctionPass *createLowerInvokePass(const TargetLowering *TLI, FunctionPass *createLowerInvokePass(bool useExpensiveEHSupport);
bool useExpensiveEHSupport);
extern char &LowerInvokePassID; extern char &LowerInvokePassID;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -19,8 +19,8 @@
#include "llvm/LLVMContext.h" #include "llvm/LLVMContext.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/TargetTransformInfo.h"
using namespace llvm; using namespace llvm;
@ -1599,15 +1599,15 @@ static bool width_descending(Value *lhs, Value *rhs) {
/// This does not depend on any SCEVExpander state but should be used in /// This does not depend on any SCEVExpander state but should be used in
/// the same context that SCEVExpander is used. /// the same context that SCEVExpander is used.
unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT, unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
SmallVectorImpl<WeakVH> &DeadInsts, SmallVectorImpl<WeakVH> &DeadInsts,
const TargetLowering *TLI) { const ScalarTargetTransformInfo *STTI) {
// Find integer phis in order of increasing width. // Find integer phis in order of increasing width.
SmallVector<PHINode*, 8> Phis; SmallVector<PHINode*, 8> Phis;
for (BasicBlock::iterator I = L->getHeader()->begin(); for (BasicBlock::iterator I = L->getHeader()->begin();
PHINode *Phi = dyn_cast<PHINode>(I); ++I) { PHINode *Phi = dyn_cast<PHINode>(I); ++I) {
Phis.push_back(Phi); Phis.push_back(Phi);
} }
if (TLI) if (STTI)
std::sort(Phis.begin(), Phis.end(), width_descending); std::sort(Phis.begin(), Phis.end(), width_descending);
unsigned NumElim = 0; unsigned NumElim = 0;
@ -1624,8 +1624,8 @@ unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
PHINode *&OrigPhiRef = ExprToIVMap[SE.getSCEV(Phi)]; PHINode *&OrigPhiRef = ExprToIVMap[SE.getSCEV(Phi)];
if (!OrigPhiRef) { if (!OrigPhiRef) {
OrigPhiRef = Phi; OrigPhiRef = Phi;
if (Phi->getType()->isIntegerTy() && TLI if (Phi->getType()->isIntegerTy() && STTI &&
&& TLI->isTruncateFree(Phi->getType(), Phis.back()->getType())) { STTI->isTruncateFree(Phi->getType(), Phis.back()->getType())) {
// This phi can be freely truncated to the narrowest phi type. Map the // This phi can be freely truncated to the narrowest phi type. Map the
// truncated expression to it so it will be reused for narrow types. // truncated expression to it so it will be reused for narrow types.
const SCEV *TruncExpr = const SCEV *TruncExpr =

View File

@ -359,7 +359,7 @@ void TargetPassConfig::addIRPasses() {
// Run loop strength reduction before anything else. // Run loop strength reduction before anything else.
if (getOptLevel() != CodeGenOpt::None && !DisableLSR) { if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
addPass(createLoopStrengthReducePass(getTargetLowering())); addPass(createLoopStrengthReducePass());
if (PrintLSR) if (PrintLSR)
addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs())); addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
} }
@ -389,7 +389,7 @@ void TargetPassConfig::addPassesToHandleExceptions() {
addPass(createDwarfEHPass(TM)); addPass(createDwarfEHPass(TM));
break; break;
case ExceptionHandling::None: case ExceptionHandling::None:
addPass(createLowerInvokePass(TM->getTargetLowering())); addPass(createLowerInvokePass());
// The lower invoke pass may create unreachable code. Remove it. // The lower invoke pass may create unreachable code. Remove it.
addPass(createUnreachableBlockEliminationPass()); addPass(createUnreachableBlockEliminationPass());

View File

@ -71,7 +71,8 @@ ARMTargetMachine::ARMTargetMachine(const Target &T, StringRef TT,
ELFWriterInfo(*this), ELFWriterInfo(*this),
TLInfo(*this), TLInfo(*this),
TSInfo(*this), TSInfo(*this),
FrameLowering(Subtarget) { FrameLowering(Subtarget),
STTI(&TLInfo) {
if (!Subtarget.hasARMOps()) if (!Subtarget.hasARMOps())
report_fatal_error("CPU: '" + Subtarget.getCPUString() + "' does not " report_fatal_error("CPU: '" + Subtarget.getCPUString() + "' does not "
"support ARM mode execution!"); "support ARM mode execution!");
@ -104,7 +105,8 @@ ThumbTargetMachine::ThumbTargetMachine(const Target &T, StringRef TT,
TSInfo(*this), TSInfo(*this),
FrameLowering(Subtarget.hasThumb2() FrameLowering(Subtarget.hasThumb2()
? new ARMFrameLowering(Subtarget) ? new ARMFrameLowering(Subtarget)
: (ARMFrameLowering*)new Thumb1FrameLowering(Subtarget)) { : (ARMFrameLowering*)new Thumb1FrameLowering(Subtarget)),
STTI(&TLInfo){
} }
namespace { namespace {

View File

@ -25,6 +25,7 @@
#include "Thumb1FrameLowering.h" #include "Thumb1FrameLowering.h"
#include "Thumb2InstrInfo.h" #include "Thumb2InstrInfo.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetTransformImpl.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCStreamer.h"
#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/OwningPtr.h"
@ -67,6 +68,8 @@ class ARMTargetMachine : public ARMBaseTargetMachine {
ARMTargetLowering TLInfo; ARMTargetLowering TLInfo;
ARMSelectionDAGInfo TSInfo; ARMSelectionDAGInfo TSInfo;
ARMFrameLowering FrameLowering; ARMFrameLowering FrameLowering;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
ARMTargetMachine(const Target &T, StringRef TT, ARMTargetMachine(const Target &T, StringRef TT,
StringRef CPU, StringRef FS, StringRef CPU, StringRef FS,
@ -88,7 +91,12 @@ class ARMTargetMachine : public ARMBaseTargetMachine {
virtual const ARMFrameLowering *getFrameLowering() const { virtual const ARMFrameLowering *getFrameLowering() const {
return &FrameLowering; return &FrameLowering;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
virtual const ARMInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const ARMInstrInfo *getInstrInfo() const { return &InstrInfo; }
virtual const DataLayout *getDataLayout() const { return &DL; } virtual const DataLayout *getDataLayout() const { return &DL; }
virtual const ARMELFWriterInfo *getELFWriterInfo() const { virtual const ARMELFWriterInfo *getELFWriterInfo() const {
@ -110,6 +118,8 @@ class ThumbTargetMachine : public ARMBaseTargetMachine {
ARMSelectionDAGInfo TSInfo; ARMSelectionDAGInfo TSInfo;
// Either Thumb1FrameLowering or ARMFrameLowering. // Either Thumb1FrameLowering or ARMFrameLowering.
OwningPtr<ARMFrameLowering> FrameLowering; OwningPtr<ARMFrameLowering> FrameLowering;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
ThumbTargetMachine(const Target &T, StringRef TT, ThumbTargetMachine(const Target &T, StringRef TT,
StringRef CPU, StringRef FS, StringRef CPU, StringRef FS,
@ -138,6 +148,12 @@ public:
virtual const ARMFrameLowering *getFrameLowering() const { virtual const ARMFrameLowering *getFrameLowering() const {
return FrameLowering.get(); return FrameLowering.get();
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
virtual const DataLayout *getDataLayout() const { return &DL; } virtual const DataLayout *getDataLayout() const { return &DL; }
virtual const ARMELFWriterInfo *getELFWriterInfo() const { virtual const ARMELFWriterInfo *getELFWriterInfo() const {
return Subtarget.isTargetELF() ? &ELFWriterInfo : 0; return Subtarget.isTargetELF() ? &ELFWriterInfo : 0;

View File

@ -11,6 +11,7 @@ add_llvm_library(LLVMTarget
TargetMachineC.cpp TargetMachineC.cpp
TargetRegisterInfo.cpp TargetRegisterInfo.cpp
TargetSubtargetInfo.cpp TargetSubtargetInfo.cpp
TargetTransformImpl.cpp
) )
foreach(t ${LLVM_TARGETS_TO_BUILD}) foreach(t ${LLVM_TARGETS_TO_BUILD})

View File

@ -43,7 +43,8 @@ SPUTargetMachine::SPUTargetMachine(const Target &T, StringRef TT,
FrameLowering(Subtarget), FrameLowering(Subtarget),
TLInfo(*this), TLInfo(*this),
TSInfo(*this), TSInfo(*this),
InstrItins(Subtarget.getInstrItineraryData()) { InstrItins(Subtarget.getInstrItineraryData()),
STTI(&TLInfo){
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -20,6 +20,7 @@
#include "SPUSelectionDAGInfo.h" #include "SPUSelectionDAGInfo.h"
#include "SPUFrameLowering.h" #include "SPUFrameLowering.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetTransformImpl.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
namespace llvm { namespace llvm {
@ -34,6 +35,8 @@ class SPUTargetMachine : public LLVMTargetMachine {
SPUTargetLowering TLInfo; SPUTargetLowering TLInfo;
SPUSelectionDAGInfo TSInfo; SPUSelectionDAGInfo TSInfo;
InstrItineraryData InstrItins; InstrItineraryData InstrItins;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
SPUTargetMachine(const Target &T, StringRef TT, SPUTargetMachine(const Target &T, StringRef TT,
StringRef CPU, StringRef FS, const TargetOptions &Options, StringRef CPU, StringRef FS, const TargetOptions &Options,
@ -77,6 +80,12 @@ public:
virtual const InstrItineraryData *getInstrItineraryData() const { virtual const InstrItineraryData *getInstrItineraryData() const {
return &InstrItins; return &InstrItins;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
// Pass Pipeline Configuration // Pass Pipeline Configuration
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM); virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);

View File

@ -74,7 +74,8 @@ HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this), Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
TSInfo(*this), TSInfo(*this),
FrameLowering(Subtarget), FrameLowering(Subtarget),
InstrItins(&Subtarget.getInstrItineraryData()) { InstrItins(&Subtarget.getInstrItineraryData()),
STTI(&TLInfo) {
setMCUseCFI(false); setMCUseCFI(false);
} }
@ -87,7 +88,7 @@ bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
PM.add(createDeadCodeEliminationPass()); PM.add(createDeadCodeEliminationPass());
PM.add(createConstantPropagationPass()); PM.add(createConstantPropagationPass());
PM.add(createLoopUnrollPass()); PM.add(createLoopUnrollPass());
PM.add(createLoopStrengthReducePass(getTargetLowering())); PM.add(createLoopStrengthReducePass());
return true; return true;
} }

View File

@ -21,6 +21,7 @@
#include "HexagonFrameLowering.h" #include "HexagonFrameLowering.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#include "llvm/Target/TargetTransformImpl.h"
namespace llvm { namespace llvm {
@ -34,6 +35,8 @@ class HexagonTargetMachine : public LLVMTargetMachine {
HexagonSelectionDAGInfo TSInfo; HexagonSelectionDAGInfo TSInfo;
HexagonFrameLowering FrameLowering; HexagonFrameLowering FrameLowering;
const InstrItineraryData* InstrItins; const InstrItineraryData* InstrItins;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
HexagonTargetMachine(const Target &T, StringRef TT,StringRef CPU, HexagonTargetMachine(const Target &T, StringRef TT,StringRef CPU,
@ -68,6 +71,14 @@ public:
return &TSInfo; return &TSInfo;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
virtual const DataLayout *getDataLayout() const { return &DL; } virtual const DataLayout *getDataLayout() const { return &DL; }
static unsigned getModuleMatchQuality(const Module &M); static unsigned getModuleMatchQuality(const Module &M);

View File

@ -42,7 +42,7 @@ MBlazeTargetMachine(const Target &T, StringRef TT,
InstrInfo(*this), InstrInfo(*this),
FrameLowering(Subtarget), FrameLowering(Subtarget),
TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this), TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this),
InstrItins(Subtarget.getInstrItineraryData()) { InstrItins(Subtarget.getInstrItineraryData()), STTI(&TLInfo) {
} }
namespace { namespace {

View File

@ -25,6 +25,7 @@
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetTransformImpl.h"
namespace llvm { namespace llvm {
class formatted_raw_ostream; class formatted_raw_ostream;
@ -39,6 +40,8 @@ namespace llvm {
MBlazeIntrinsicInfo IntrinsicInfo; MBlazeIntrinsicInfo IntrinsicInfo;
MBlazeELFWriterInfo ELFWriterInfo; MBlazeELFWriterInfo ELFWriterInfo;
InstrItineraryData InstrItins; InstrItineraryData InstrItins;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
MBlazeTargetMachine(const Target &T, StringRef TT, MBlazeTargetMachine(const Target &T, StringRef TT,
@ -77,6 +80,10 @@ namespace llvm {
virtual const MBlazeELFWriterInfo *getELFWriterInfo() const { virtual const MBlazeELFWriterInfo *getELFWriterInfo() const {
return &ELFWriterInfo; return &ELFWriterInfo;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const
{ return &STTI; }
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const
{ return &VTTI; }
// Pass Pipeline Configuration // Pass Pipeline Configuration
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM); virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);

View File

@ -36,7 +36,7 @@ MSP430TargetMachine::MSP430TargetMachine(const Target &T,
// FIXME: Check DataLayout string. // FIXME: Check DataLayout string.
DL("e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"), DL("e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"),
InstrInfo(*this), TLInfo(*this), TSInfo(*this), InstrInfo(*this), TLInfo(*this), TSInfo(*this),
FrameLowering(Subtarget) { } FrameLowering(Subtarget), STTI(&TLInfo) { }
namespace { namespace {
/// MSP430 Code Generator Pass Configuration Options. /// MSP430 Code Generator Pass Configuration Options.

View File

@ -24,6 +24,7 @@
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetTransformImpl.h"
namespace llvm { namespace llvm {
@ -36,6 +37,8 @@ class MSP430TargetMachine : public LLVMTargetMachine {
MSP430TargetLowering TLInfo; MSP430TargetLowering TLInfo;
MSP430SelectionDAGInfo TSInfo; MSP430SelectionDAGInfo TSInfo;
MSP430FrameLowering FrameLowering; MSP430FrameLowering FrameLowering;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
MSP430TargetMachine(const Target &T, StringRef TT, MSP430TargetMachine(const Target &T, StringRef TT,
@ -61,7 +64,12 @@ public:
virtual const MSP430SelectionDAGInfo* getSelectionDAGInfo() const { virtual const MSP430SelectionDAGInfo* getSelectionDAGInfo() const {
return &TSInfo; return &TSInfo;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM); virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
}; // MSP430TargetMachine. }; // MSP430TargetMachine.

View File

@ -53,7 +53,7 @@ MipsTargetMachine(const Target &T, StringRef TT,
InstrInfo(MipsInstrInfo::create(*this)), InstrInfo(MipsInstrInfo::create(*this)),
FrameLowering(MipsFrameLowering::create(*this, Subtarget)), FrameLowering(MipsFrameLowering::create(*this, Subtarget)),
TLInfo(*this), TSInfo(*this), JITInfo(), TLInfo(*this), TSInfo(*this), JITInfo(),
ELFWriterInfo(false, isLittle) { ELFWriterInfo(false, isLittle), STTI(&TLInfo) {
} }
void MipsebTargetMachine::anchor() { } void MipsebTargetMachine::anchor() { }

View File

@ -24,6 +24,7 @@
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetTransformImpl.h"
namespace llvm { namespace llvm {
class formatted_raw_ostream; class formatted_raw_ostream;
@ -38,6 +39,8 @@ class MipsTargetMachine : public LLVMTargetMachine {
MipsSelectionDAGInfo TSInfo; MipsSelectionDAGInfo TSInfo;
MipsJITInfo JITInfo; MipsJITInfo JITInfo;
MipsELFWriterInfo ELFWriterInfo; MipsELFWriterInfo ELFWriterInfo;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
MipsTargetMachine(const Target &T, StringRef TT, MipsTargetMachine(const Target &T, StringRef TT,

View File

@ -72,7 +72,8 @@ NVPTXTargetMachine::NVPTXTargetMachine(const Target &T,
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
Subtarget(TT, CPU, FS, is64bit), Subtarget(TT, CPU, FS, is64bit),
DL(Subtarget.getDataLayout()), DL(Subtarget.getDataLayout()),
InstrInfo(*this), TLInfo(*this), TSInfo(*this), FrameLowering(*this,is64bit) InstrInfo(*this), TLInfo(*this), TSInfo(*this), FrameLowering(*this,is64bit),
STTI(&TLInfo)
/*FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0)*/ { /*FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0)*/ {
} }

View File

@ -25,6 +25,7 @@
#include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetSelectionDAGInfo.h" #include "llvm/Target/TargetSelectionDAGInfo.h"
#include "llvm/Target/TargetTransformImpl.h"
namespace llvm { namespace llvm {
@ -44,6 +45,9 @@ class NVPTXTargetMachine : public LLVMTargetMachine {
// Hold Strings that can be free'd all together with NVPTXTargetMachine // Hold Strings that can be free'd all together with NVPTXTargetMachine
ManagedStringPool ManagedStrPool; ManagedStringPool ManagedStrPool;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
//bool addCommonCodeGenPasses(PassManagerBase &, CodeGenOpt::Level, //bool addCommonCodeGenPasses(PassManagerBase &, CodeGenOpt::Level,
// bool DisableVerify, MCContext *&OutCtx); // bool DisableVerify, MCContext *&OutCtx);
@ -72,6 +76,12 @@ public:
virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const { virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const {
return &TSInfo; return &TSInfo;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
//virtual bool addInstSelector(PassManagerBase &PM, //virtual bool addInstSelector(PassManagerBase &PM,
// CodeGenOpt::Level OptLevel); // CodeGenOpt::Level OptLevel);

View File

@ -43,7 +43,8 @@ PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT,
DL(Subtarget.getDataLayoutString()), InstrInfo(*this), DL(Subtarget.getDataLayoutString()), InstrInfo(*this),
FrameLowering(Subtarget), JITInfo(*this, is64Bit), FrameLowering(Subtarget), JITInfo(*this, is64Bit),
TLInfo(*this), TSInfo(*this), TLInfo(*this), TSInfo(*this),
InstrItins(Subtarget.getInstrItineraryData()) { InstrItins(Subtarget.getInstrItineraryData()),
STTI(&TLInfo){
// The binutils for the BG/P are too old for CFI. // The binutils for the BG/P are too old for CFI.
if (Subtarget.isBGP()) if (Subtarget.isBGP())

View File

@ -21,6 +21,7 @@
#include "PPCISelLowering.h" #include "PPCISelLowering.h"
#include "PPCSelectionDAGInfo.h" #include "PPCSelectionDAGInfo.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetTransformImpl.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
namespace llvm { namespace llvm {
@ -36,6 +37,8 @@ class PPCTargetMachine : public LLVMTargetMachine {
PPCTargetLowering TLInfo; PPCTargetLowering TLInfo;
PPCSelectionDAGInfo TSInfo; PPCSelectionDAGInfo TSInfo;
InstrItineraryData InstrItins; InstrItineraryData InstrItins;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
PPCTargetMachine(const Target &T, StringRef TT, PPCTargetMachine(const Target &T, StringRef TT,
@ -63,6 +66,12 @@ public:
virtual const InstrItineraryData *getInstrItineraryData() const { virtual const InstrItineraryData *getInstrItineraryData() const {
return &InstrItins; return &InstrItins;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
// Pass Pipeline Configuration // Pass Pipeline Configuration
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM); virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);

View File

@ -36,7 +36,7 @@ SparcTargetMachine::SparcTargetMachine(const Target &T, StringRef TT,
DL(Subtarget.getDataLayout()), DL(Subtarget.getDataLayout()),
InstrInfo(Subtarget), InstrInfo(Subtarget),
TLInfo(*this), TSInfo(*this), TLInfo(*this), TSInfo(*this),
FrameLowering(Subtarget) { FrameLowering(Subtarget),STTI(&TLInfo) {
} }
namespace { namespace {

View File

@ -22,6 +22,7 @@
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetTransformImpl.h"
namespace llvm { namespace llvm {
@ -32,6 +33,8 @@ class SparcTargetMachine : public LLVMTargetMachine {
SparcTargetLowering TLInfo; SparcTargetLowering TLInfo;
SparcSelectionDAGInfo TSInfo; SparcSelectionDAGInfo TSInfo;
SparcFrameLowering FrameLowering; SparcFrameLowering FrameLowering;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
SparcTargetMachine(const Target &T, StringRef TT, SparcTargetMachine(const Target &T, StringRef TT,
StringRef CPU, StringRef FS, const TargetOptions &Options, StringRef CPU, StringRef FS, const TargetOptions &Options,
@ -52,6 +55,12 @@ public:
virtual const SparcSelectionDAGInfo* getSelectionDAGInfo() const { virtual const SparcSelectionDAGInfo* getSelectionDAGInfo() const {
return &TSInfo; return &TSInfo;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
virtual const DataLayout *getDataLayout() const { return &DL; } virtual const DataLayout *getDataLayout() const { return &DL; }
// Pass Pipeline Configuration // Pass Pipeline Configuration

View File

@ -26,6 +26,7 @@ using namespace llvm;
void llvm::initializeTarget(PassRegistry &Registry) { void llvm::initializeTarget(PassRegistry &Registry) {
initializeDataLayoutPass(Registry); initializeDataLayoutPass(Registry);
initializeTargetLibraryInfoPass(Registry); initializeTargetLibraryInfoPass(Registry);
initializeTargetTransformInfoPass(Registry);
} }
void LLVMInitializeTarget(LLVMPassRegistryRef R) { void LLVMInitializeTarget(LLVMPassRegistryRef R) {

View File

@ -0,0 +1,43 @@
// llvm/Target/TargetTransformImpl.cpp - Target Loop Trans Info ---*- C++ -*-=//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Target/TargetTransformImpl.h"
#include "llvm/Target/TargetLowering.h"
using namespace llvm;
bool ScalarTargetTransformImpl::isLegalAddImmediate(int64_t imm) const {
return TLI->isLegalAddImmediate(imm);
}
bool ScalarTargetTransformImpl::isLegalICmpImmediate(int64_t imm) const {
return TLI->isLegalICmpImmediate(imm);
}
bool ScalarTargetTransformImpl::isLegalAddressingMode(const AddrMode &AM,
Type *Ty) const {
return TLI->isLegalAddressingMode(AM, Ty);
}
bool ScalarTargetTransformImpl::isTruncateFree(Type *Ty1, Type *Ty2) const {
return TLI->isTruncateFree(Ty1, Ty2);
}
bool ScalarTargetTransformImpl::isTypeLegal(Type *Ty) const {
EVT T = TLI->getValueType(Ty);
return TLI->isTypeLegal(T);
}
unsigned ScalarTargetTransformImpl::getJumpBufAlignment() const {
return TLI->getJumpBufAlignment();
}
unsigned ScalarTargetTransformImpl::getJumpBufSize() const {
return TLI->getJumpBufSize();
}

View File

@ -48,7 +48,8 @@ X86_32TargetMachine::X86_32TargetMachine(const Target &T, StringRef TT,
InstrInfo(*this), InstrInfo(*this),
TSInfo(*this), TSInfo(*this),
TLInfo(*this), TLInfo(*this),
JITInfo(*this) { JITInfo(*this),
STTI(&TLInfo) {
} }
void X86_64TargetMachine::anchor() { } void X86_64TargetMachine::anchor() { }
@ -64,7 +65,8 @@ X86_64TargetMachine::X86_64TargetMachine(const Target &T, StringRef TT,
InstrInfo(*this), InstrInfo(*this),
TSInfo(*this), TSInfo(*this),
TLInfo(*this), TLInfo(*this),
JITInfo(*this) { JITInfo(*this),
STTI(&TLInfo) {
} }
/// X86TargetMachine ctor - Create an X86 target. /// X86TargetMachine ctor - Create an X86 target.

View File

@ -25,6 +25,7 @@
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetTransformImpl.h"
namespace llvm { namespace llvm {
@ -85,6 +86,8 @@ class X86_32TargetMachine : public X86TargetMachine {
X86SelectionDAGInfo TSInfo; X86SelectionDAGInfo TSInfo;
X86TargetLowering TLInfo; X86TargetLowering TLInfo;
X86JITInfo JITInfo; X86JITInfo JITInfo;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
X86_32TargetMachine(const Target &T, StringRef TT, X86_32TargetMachine(const Target &T, StringRef TT,
StringRef CPU, StringRef FS, const TargetOptions &Options, StringRef CPU, StringRef FS, const TargetOptions &Options,
@ -103,6 +106,12 @@ public:
virtual X86JITInfo *getJITInfo() { virtual X86JITInfo *getJITInfo() {
return &JITInfo; return &JITInfo;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
}; };
/// X86_64TargetMachine - X86 64-bit target machine. /// X86_64TargetMachine - X86 64-bit target machine.
@ -114,6 +123,8 @@ class X86_64TargetMachine : public X86TargetMachine {
X86SelectionDAGInfo TSInfo; X86SelectionDAGInfo TSInfo;
X86TargetLowering TLInfo; X86TargetLowering TLInfo;
X86JITInfo JITInfo; X86JITInfo JITInfo;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
X86_64TargetMachine(const Target &T, StringRef TT, X86_64TargetMachine(const Target &T, StringRef TT,
StringRef CPU, StringRef FS, const TargetOptions &Options, StringRef CPU, StringRef FS, const TargetOptions &Options,
@ -132,6 +143,12 @@ public:
virtual X86JITInfo *getJITInfo() { virtual X86JITInfo *getJITInfo() {
return &JITInfo; return &JITInfo;
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
}; };
} // End llvm namespace } // End llvm namespace

View File

@ -32,7 +32,7 @@ XCoreTargetMachine::XCoreTargetMachine(const Target &T, StringRef TT,
InstrInfo(), InstrInfo(),
FrameLowering(Subtarget), FrameLowering(Subtarget),
TLInfo(*this), TLInfo(*this),
TSInfo(*this) { TSInfo(*this), STTI(&TLInfo) {
} }
namespace { namespace {

View File

@ -20,6 +20,7 @@
#include "XCoreISelLowering.h" #include "XCoreISelLowering.h"
#include "XCoreSelectionDAGInfo.h" #include "XCoreSelectionDAGInfo.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetTransformImpl.h"
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
namespace llvm { namespace llvm {
@ -31,6 +32,8 @@ class XCoreTargetMachine : public LLVMTargetMachine {
XCoreFrameLowering FrameLowering; XCoreFrameLowering FrameLowering;
XCoreTargetLowering TLInfo; XCoreTargetLowering TLInfo;
XCoreSelectionDAGInfo TSInfo; XCoreSelectionDAGInfo TSInfo;
ScalarTargetTransformImpl STTI;
VectorTargetTransformImpl VTTI;
public: public:
XCoreTargetMachine(const Target &T, StringRef TT, XCoreTargetMachine(const Target &T, StringRef TT,
StringRef CPU, StringRef FS, const TargetOptions &Options, StringRef CPU, StringRef FS, const TargetOptions &Options,
@ -53,6 +56,12 @@ public:
virtual const TargetRegisterInfo *getRegisterInfo() const { virtual const TargetRegisterInfo *getRegisterInfo() const {
return &InstrInfo.getRegisterInfo(); return &InstrInfo.getRegisterInfo();
} }
virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
return &STTI;
}
virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
return &VTTI;
}
virtual const DataLayout *getDataLayout() const { return &DL; } virtual const DataLayout *getDataLayout() const { return &DL; }
// Pass Pipeline Configuration // Pass Pipeline Configuration

View File

@ -37,7 +37,7 @@
// //
// TODO: Handle multiple loops at a time. // TODO: Handle multiple loops at a time.
// //
// TODO: Should TargetLowering::AddrMode::BaseGV be changed to a ConstantExpr // TODO: Should AddrMode::BaseGV be changed to a ConstantExpr
// instead of a GlobalValue? // instead of a GlobalValue?
// //
// TODO: When truncation is free, truncate ICmp users' operands to make it a // TODO: When truncation is free, truncate ICmp users' operands to make it a
@ -67,6 +67,7 @@
#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/Local.h"
#include "llvm/TargetTransformInfo.h"
#include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SetVector.h"
#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/DenseSet.h"
@ -74,7 +75,6 @@
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/ValueHandle.h" #include "llvm/Support/ValueHandle.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLowering.h"
#include <algorithm> #include <algorithm>
using namespace llvm; using namespace llvm;
@ -1118,7 +1118,7 @@ public:
enum KindType { enum KindType {
Basic, ///< A normal use, with no folding. Basic, ///< A normal use, with no folding.
Special, ///< A special case of basic, allowing -1 scales. Special, ///< A special case of basic, allowing -1 scales.
Address, ///< An address use; folding according to TargetLowering Address, ///< An address use; folding according to ScalarTargetTransformInfo.
ICmpZero ///< An equality icmp with both operands folded into one. ICmpZero ///< An equality icmp with both operands folded into one.
// TODO: Add a generic icmp too? // TODO: Add a generic icmp too?
}; };
@ -1272,12 +1272,12 @@ void LSRUse::dump() const {
/// address-mode folding and special icmp tricks. /// address-mode folding and special icmp tricks.
static bool isLegalUse(const AddrMode &AM, static bool isLegalUse(const AddrMode &AM,
LSRUse::KindType Kind, Type *AccessTy, LSRUse::KindType Kind, Type *AccessTy,
const TargetLowering *TLI) { const ScalarTargetTransformInfo *STTI) {
switch (Kind) { switch (Kind) {
case LSRUse::Address: case LSRUse::Address:
// If we have low-level target information, ask the target if it can // If we have low-level target information, ask the target if it can
// completely fold this address. // completely fold this address.
if (TLI) return TLI->isLegalAddressingMode(AM, AccessTy); if (STTI) return STTI->isLegalAddressingMode(AM, AccessTy);
// Otherwise, just guess that reg+reg addressing is legal. // Otherwise, just guess that reg+reg addressing is legal.
return !AM.BaseGV && AM.BaseOffs == 0 && AM.Scale <= 1; return !AM.BaseGV && AM.BaseOffs == 0 && AM.Scale <= 1;
@ -1300,7 +1300,7 @@ static bool isLegalUse(const AddrMode &AM,
// If we have low-level target information, ask the target if it can fold an // If we have low-level target information, ask the target if it can fold an
// integer immediate on an icmp. // integer immediate on an icmp.
if (AM.BaseOffs != 0) { if (AM.BaseOffs != 0) {
if (!TLI) if (!STTI)
return false; return false;
// We have one of: // We have one of:
// ICmpZero BaseReg + Offset => ICmp BaseReg, -Offset // ICmpZero BaseReg + Offset => ICmp BaseReg, -Offset
@ -1309,7 +1309,7 @@ static bool isLegalUse(const AddrMode &AM,
int64_t Offs = AM.BaseOffs; int64_t Offs = AM.BaseOffs;
if (AM.Scale == 0) if (AM.Scale == 0)
Offs = -(uint64_t)Offs; // The cast does the right thing with INT64_MIN. Offs = -(uint64_t)Offs; // The cast does the right thing with INT64_MIN.
return TLI->isLegalICmpImmediate(Offs); return STTI->isLegalICmpImmediate(Offs);
} }
// ICmpZero BaseReg + -1*ScaleReg => ICmp BaseReg, ScaleReg // ICmpZero BaseReg + -1*ScaleReg => ICmp BaseReg, ScaleReg
@ -1330,20 +1330,20 @@ static bool isLegalUse(const AddrMode &AM,
static bool isLegalUse(AddrMode AM, static bool isLegalUse(AddrMode AM,
int64_t MinOffset, int64_t MaxOffset, int64_t MinOffset, int64_t MaxOffset,
LSRUse::KindType Kind, Type *AccessTy, LSRUse::KindType Kind, Type *AccessTy,
const TargetLowering *TLI) { const ScalarTargetTransformInfo *LTTI) {
// Check for overflow. // Check for overflow.
if (((int64_t)((uint64_t)AM.BaseOffs + MinOffset) > AM.BaseOffs) != if (((int64_t)((uint64_t)AM.BaseOffs + MinOffset) > AM.BaseOffs) !=
(MinOffset > 0)) (MinOffset > 0))
return false; return false;
AM.BaseOffs = (uint64_t)AM.BaseOffs + MinOffset; AM.BaseOffs = (uint64_t)AM.BaseOffs + MinOffset;
if (isLegalUse(AM, Kind, AccessTy, TLI)) { if (isLegalUse(AM, Kind, AccessTy, LTTI)) {
AM.BaseOffs = (uint64_t)AM.BaseOffs - MinOffset; AM.BaseOffs = (uint64_t)AM.BaseOffs - MinOffset;
// Check for overflow. // Check for overflow.
if (((int64_t)((uint64_t)AM.BaseOffs + MaxOffset) > AM.BaseOffs) != if (((int64_t)((uint64_t)AM.BaseOffs + MaxOffset) > AM.BaseOffs) !=
(MaxOffset > 0)) (MaxOffset > 0))
return false; return false;
AM.BaseOffs = (uint64_t)AM.BaseOffs + MaxOffset; AM.BaseOffs = (uint64_t)AM.BaseOffs + MaxOffset;
return isLegalUse(AM, Kind, AccessTy, TLI); return isLegalUse(AM, Kind, AccessTy, LTTI);
} }
return false; return false;
} }
@ -1352,7 +1352,7 @@ static bool isAlwaysFoldable(int64_t BaseOffs,
GlobalValue *BaseGV, GlobalValue *BaseGV,
bool HasBaseReg, bool HasBaseReg,
LSRUse::KindType Kind, Type *AccessTy, LSRUse::KindType Kind, Type *AccessTy,
const TargetLowering *TLI) { const ScalarTargetTransformInfo *LTTI) {
// Fast-path: zero is always foldable. // Fast-path: zero is always foldable.
if (BaseOffs == 0 && !BaseGV) return true; if (BaseOffs == 0 && !BaseGV) return true;
@ -1371,14 +1371,14 @@ static bool isAlwaysFoldable(int64_t BaseOffs,
AM.HasBaseReg = true; AM.HasBaseReg = true;
} }
return isLegalUse(AM, Kind, AccessTy, TLI); return isLegalUse(AM, Kind, AccessTy, LTTI);
} }
static bool isAlwaysFoldable(const SCEV *S, static bool isAlwaysFoldable(const SCEV *S,
int64_t MinOffset, int64_t MaxOffset, int64_t MinOffset, int64_t MaxOffset,
bool HasBaseReg, bool HasBaseReg,
LSRUse::KindType Kind, Type *AccessTy, LSRUse::KindType Kind, Type *AccessTy,
const TargetLowering *TLI, const ScalarTargetTransformInfo *LTTI,
ScalarEvolution &SE) { ScalarEvolution &SE) {
// Fast-path: zero is always foldable. // Fast-path: zero is always foldable.
if (S->isZero()) return true; if (S->isZero()) return true;
@ -1402,7 +1402,7 @@ static bool isAlwaysFoldable(const SCEV *S,
AM.HasBaseReg = HasBaseReg; AM.HasBaseReg = HasBaseReg;
AM.Scale = Kind == LSRUse::ICmpZero ? -1 : 1; AM.Scale = Kind == LSRUse::ICmpZero ? -1 : 1;
return isLegalUse(AM, MinOffset, MaxOffset, Kind, AccessTy, TLI); return isLegalUse(AM, MinOffset, MaxOffset, Kind, AccessTy, LTTI);
} }
namespace { namespace {
@ -1502,7 +1502,7 @@ class LSRInstance {
ScalarEvolution &SE; ScalarEvolution &SE;
DominatorTree &DT; DominatorTree &DT;
LoopInfo &LI; LoopInfo &LI;
const TargetLowering *const TLI; const ScalarTargetTransformInfo *const STTI;
Loop *const L; Loop *const L;
bool Changed; bool Changed;
@ -1638,7 +1638,7 @@ class LSRInstance {
Pass *P); Pass *P);
public: public:
LSRInstance(const TargetLowering *tli, Loop *l, Pass *P); LSRInstance(const ScalarTargetTransformInfo *ltti, Loop *l, Pass *P);
bool getChanged() const { return Changed; } bool getChanged() const { return Changed; }
@ -1688,11 +1688,10 @@ void LSRInstance::OptimizeShadowIV() {
} }
if (!DestTy) continue; if (!DestTy) continue;
if (TLI) { if (STTI) {
// If target does not support DestTy natively then do not apply // If target does not support DestTy natively then do not apply
// this transformation. // this transformation.
EVT DVT = TLI->getValueType(DestTy); if (!STTI->isTypeLegal(DestTy)) continue;
if (!TLI->isTypeLegal(DVT)) continue;
} }
PHINode *PH = dyn_cast<PHINode>(ShadowUse->getOperand(0)); PHINode *PH = dyn_cast<PHINode>(ShadowUse->getOperand(0));
@ -2015,18 +2014,18 @@ LSRInstance::OptimizeLoopTermCond() {
if (C->getValue().getMinSignedBits() >= 64 || if (C->getValue().getMinSignedBits() >= 64 ||
C->getValue().isMinSignedValue()) C->getValue().isMinSignedValue())
goto decline_post_inc; goto decline_post_inc;
// Without TLI, assume that any stride might be valid, and so any // Without STTI, assume that any stride might be valid, and so any
// use might be shared. // use might be shared.
if (!TLI) if (!STTI)
goto decline_post_inc; goto decline_post_inc;
// Check for possible scaled-address reuse. // Check for possible scaled-address reuse.
Type *AccessTy = getAccessType(UI->getUser()); Type *AccessTy = getAccessType(UI->getUser());
AddrMode AM; AddrMode AM;
AM.Scale = C->getSExtValue(); AM.Scale = C->getSExtValue();
if (TLI->isLegalAddressingMode(AM, AccessTy)) if (STTI->isLegalAddressingMode(AM, AccessTy))
goto decline_post_inc; goto decline_post_inc;
AM.Scale = -AM.Scale; AM.Scale = -AM.Scale;
if (TLI->isLegalAddressingMode(AM, AccessTy)) if (STTI->isLegalAddressingMode(AM, AccessTy))
goto decline_post_inc; goto decline_post_inc;
} }
} }
@ -2097,12 +2096,12 @@ LSRInstance::reconcileNewOffset(LSRUse &LU, int64_t NewOffset, bool HasBaseReg,
// Conservatively assume HasBaseReg is true for now. // Conservatively assume HasBaseReg is true for now.
if (NewOffset < LU.MinOffset) { if (NewOffset < LU.MinOffset) {
if (!isAlwaysFoldable(LU.MaxOffset - NewOffset, 0, HasBaseReg, if (!isAlwaysFoldable(LU.MaxOffset - NewOffset, 0, HasBaseReg,
Kind, AccessTy, TLI)) Kind, AccessTy, STTI))
return false; return false;
NewMinOffset = NewOffset; NewMinOffset = NewOffset;
} else if (NewOffset > LU.MaxOffset) { } else if (NewOffset > LU.MaxOffset) {
if (!isAlwaysFoldable(NewOffset - LU.MinOffset, 0, HasBaseReg, if (!isAlwaysFoldable(NewOffset - LU.MinOffset, 0, HasBaseReg,
Kind, AccessTy, TLI)) Kind, AccessTy, STTI))
return false; return false;
NewMaxOffset = NewOffset; NewMaxOffset = NewOffset;
} }
@ -2131,7 +2130,7 @@ LSRInstance::getUse(const SCEV *&Expr,
int64_t Offset = ExtractImmediate(Expr, SE); int64_t Offset = ExtractImmediate(Expr, SE);
// Basic uses can't accept any offset, for example. // Basic uses can't accept any offset, for example.
if (!isAlwaysFoldable(Offset, 0, /*HasBaseReg=*/true, Kind, AccessTy, TLI)) { if (!isAlwaysFoldable(Offset, 0, /*HasBaseReg=*/true, Kind, AccessTy, STTI)) {
Expr = Copy; Expr = Copy;
Offset = 0; Offset = 0;
} }
@ -2396,7 +2395,7 @@ bool IVChain::isProfitableIncrement(const SCEV *OperExpr,
/// TODO: Consider IVInc free if it's already used in another chains. /// TODO: Consider IVInc free if it's already used in another chains.
static bool static bool
isProfitableChain(IVChain &Chain, SmallPtrSet<Instruction*, 4> &Users, isProfitableChain(IVChain &Chain, SmallPtrSet<Instruction*, 4> &Users,
ScalarEvolution &SE, const TargetLowering *TLI) { ScalarEvolution &SE, const ScalarTargetTransformInfo *STTI) {
if (StressIVChain) if (StressIVChain)
return true; return true;
@ -2654,7 +2653,7 @@ void LSRInstance::CollectChains() {
for (unsigned UsersIdx = 0, NChains = IVChainVec.size(); for (unsigned UsersIdx = 0, NChains = IVChainVec.size();
UsersIdx < NChains; ++UsersIdx) { UsersIdx < NChains; ++UsersIdx) {
if (!isProfitableChain(IVChainVec[UsersIdx], if (!isProfitableChain(IVChainVec[UsersIdx],
ChainUsersVec[UsersIdx].FarUsers, SE, TLI)) ChainUsersVec[UsersIdx].FarUsers, SE, STTI))
continue; continue;
// Preserve the chain at UsesIdx. // Preserve the chain at UsesIdx.
if (ChainIdx != UsersIdx) if (ChainIdx != UsersIdx)
@ -2681,7 +2680,8 @@ void LSRInstance::FinalizeChain(IVChain &Chain) {
/// Return true if the IVInc can be folded into an addressing mode. /// Return true if the IVInc can be folded into an addressing mode.
static bool canFoldIVIncExpr(const SCEV *IncExpr, Instruction *UserInst, static bool canFoldIVIncExpr(const SCEV *IncExpr, Instruction *UserInst,
Value *Operand, const TargetLowering *TLI) { Value *Operand,
const ScalarTargetTransformInfo *STTI) {
const SCEVConstant *IncConst = dyn_cast<SCEVConstant>(IncExpr); const SCEVConstant *IncConst = dyn_cast<SCEVConstant>(IncExpr);
if (!IncConst || !isAddressUse(UserInst, Operand)) if (!IncConst || !isAddressUse(UserInst, Operand))
return false; return false;
@ -2691,7 +2691,7 @@ static bool canFoldIVIncExpr(const SCEV *IncExpr, Instruction *UserInst,
int64_t IncOffset = IncConst->getValue()->getSExtValue(); int64_t IncOffset = IncConst->getValue()->getSExtValue();
if (!isAlwaysFoldable(IncOffset, /*BaseGV=*/0, /*HaseBaseReg=*/false, if (!isAlwaysFoldable(IncOffset, /*BaseGV=*/0, /*HaseBaseReg=*/false,
LSRUse::Address, getAccessType(UserInst), TLI)) LSRUse::Address, getAccessType(UserInst), STTI))
return false; return false;
return true; return true;
@ -2762,7 +2762,7 @@ void LSRInstance::GenerateIVChain(const IVChain &Chain, SCEVExpander &Rewriter,
// If an IV increment can't be folded, use it as the next IV value. // If an IV increment can't be folded, use it as the next IV value.
if (!canFoldIVIncExpr(LeftOverExpr, IncI->UserInst, IncI->IVOperand, if (!canFoldIVIncExpr(LeftOverExpr, IncI->UserInst, IncI->IVOperand,
TLI)) { STTI)) {
assert(IVTy == IVOper->getType() && "inconsistent IV increment type"); assert(IVTy == IVOper->getType() && "inconsistent IV increment type");
IVSrc = IVOper; IVSrc = IVOper;
LeftOverExpr = 0; LeftOverExpr = 0;
@ -3108,7 +3108,7 @@ void LSRInstance::GenerateReassociations(LSRUse &LU, unsigned LUIdx,
// into an immediate field. // into an immediate field.
if (isAlwaysFoldable(*J, LU.MinOffset, LU.MaxOffset, if (isAlwaysFoldable(*J, LU.MinOffset, LU.MaxOffset,
Base.getNumRegs() > 1, Base.getNumRegs() > 1,
LU.Kind, LU.AccessTy, TLI, SE)) LU.Kind, LU.AccessTy, STTI, SE))
continue; continue;
// Collect all operands except *J. // Collect all operands except *J.
@ -3122,7 +3122,7 @@ void LSRInstance::GenerateReassociations(LSRUse &LU, unsigned LUIdx,
if (InnerAddOps.size() == 1 && if (InnerAddOps.size() == 1 &&
isAlwaysFoldable(InnerAddOps[0], LU.MinOffset, LU.MaxOffset, isAlwaysFoldable(InnerAddOps[0], LU.MinOffset, LU.MaxOffset,
Base.getNumRegs() > 1, Base.getNumRegs() > 1,
LU.Kind, LU.AccessTy, TLI, SE)) LU.Kind, LU.AccessTy, STTI, SE))
continue; continue;
const SCEV *InnerSum = SE.getAddExpr(InnerAddOps); const SCEV *InnerSum = SE.getAddExpr(InnerAddOps);
@ -3132,9 +3132,9 @@ void LSRInstance::GenerateReassociations(LSRUse &LU, unsigned LUIdx,
// Add the remaining pieces of the add back into the new formula. // Add the remaining pieces of the add back into the new formula.
const SCEVConstant *InnerSumSC = dyn_cast<SCEVConstant>(InnerSum); const SCEVConstant *InnerSumSC = dyn_cast<SCEVConstant>(InnerSum);
if (TLI && InnerSumSC && if (STTI && InnerSumSC &&
SE.getTypeSizeInBits(InnerSumSC->getType()) <= 64 && SE.getTypeSizeInBits(InnerSumSC->getType()) <= 64 &&
TLI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset + STTI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
InnerSumSC->getValue()->getZExtValue())) { InnerSumSC->getValue()->getZExtValue())) {
F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset + F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset +
InnerSumSC->getValue()->getZExtValue(); InnerSumSC->getValue()->getZExtValue();
@ -3144,8 +3144,8 @@ void LSRInstance::GenerateReassociations(LSRUse &LU, unsigned LUIdx,
// Add J as its own register, or an unfolded immediate. // Add J as its own register, or an unfolded immediate.
const SCEVConstant *SC = dyn_cast<SCEVConstant>(*J); const SCEVConstant *SC = dyn_cast<SCEVConstant>(*J);
if (TLI && SC && SE.getTypeSizeInBits(SC->getType()) <= 64 && if (STTI && SC && SE.getTypeSizeInBits(SC->getType()) <= 64 &&
TLI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset + STTI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
SC->getValue()->getZExtValue())) SC->getValue()->getZExtValue()))
F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset + F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset +
SC->getValue()->getZExtValue(); SC->getValue()->getZExtValue();
@ -3205,7 +3205,7 @@ void LSRInstance::GenerateSymbolicOffsets(LSRUse &LU, unsigned LUIdx,
Formula F = Base; Formula F = Base;
F.AM.BaseGV = GV; F.AM.BaseGV = GV;
if (!isLegalUse(F.AM, LU.MinOffset, LU.MaxOffset, if (!isLegalUse(F.AM, LU.MinOffset, LU.MaxOffset,
LU.Kind, LU.AccessTy, TLI)) LU.Kind, LU.AccessTy, STTI))
continue; continue;
F.BaseRegs[i] = G; F.BaseRegs[i] = G;
(void)InsertFormula(LU, LUIdx, F); (void)InsertFormula(LU, LUIdx, F);
@ -3230,7 +3230,7 @@ void LSRInstance::GenerateConstantOffsets(LSRUse &LU, unsigned LUIdx,
Formula F = Base; Formula F = Base;
F.AM.BaseOffs = (uint64_t)Base.AM.BaseOffs - *I; F.AM.BaseOffs = (uint64_t)Base.AM.BaseOffs - *I;
if (isLegalUse(F.AM, LU.MinOffset - *I, LU.MaxOffset - *I, if (isLegalUse(F.AM, LU.MinOffset - *I, LU.MaxOffset - *I,
LU.Kind, LU.AccessTy, TLI)) { LU.Kind, LU.AccessTy, STTI)) {
// Add the offset to the base register. // Add the offset to the base register.
const SCEV *NewG = SE.getAddExpr(SE.getConstant(G->getType(), *I), G); const SCEV *NewG = SE.getAddExpr(SE.getConstant(G->getType(), *I), G);
// If it cancelled out, drop the base register, otherwise update it. // If it cancelled out, drop the base register, otherwise update it.
@ -3250,7 +3250,7 @@ void LSRInstance::GenerateConstantOffsets(LSRUse &LU, unsigned LUIdx,
Formula F = Base; Formula F = Base;
F.AM.BaseOffs = (uint64_t)F.AM.BaseOffs + Imm; F.AM.BaseOffs = (uint64_t)F.AM.BaseOffs + Imm;
if (!isLegalUse(F.AM, LU.MinOffset, LU.MaxOffset, if (!isLegalUse(F.AM, LU.MinOffset, LU.MaxOffset,
LU.Kind, LU.AccessTy, TLI)) LU.Kind, LU.AccessTy, STTI))
continue; continue;
F.BaseRegs[i] = G; F.BaseRegs[i] = G;
(void)InsertFormula(LU, LUIdx, F); (void)InsertFormula(LU, LUIdx, F);
@ -3297,7 +3297,7 @@ void LSRInstance::GenerateICmpZeroScales(LSRUse &LU, unsigned LUIdx,
F.AM.BaseOffs = NewBaseOffs; F.AM.BaseOffs = NewBaseOffs;
// Check that this scale is legal. // Check that this scale is legal.
if (!isLegalUse(F.AM, Offset, Offset, LU.Kind, LU.AccessTy, TLI)) if (!isLegalUse(F.AM, Offset, Offset, LU.Kind, LU.AccessTy, STTI))
continue; continue;
// Compensate for the use having MinOffset built into it. // Compensate for the use having MinOffset built into it.
@ -3353,12 +3353,12 @@ void LSRInstance::GenerateScales(LSRUse &LU, unsigned LUIdx, Formula Base) {
Base.AM.HasBaseReg = Base.BaseRegs.size() > 1; Base.AM.HasBaseReg = Base.BaseRegs.size() > 1;
// Check whether this scale is going to be legal. // Check whether this scale is going to be legal.
if (!isLegalUse(Base.AM, LU.MinOffset, LU.MaxOffset, if (!isLegalUse(Base.AM, LU.MinOffset, LU.MaxOffset,
LU.Kind, LU.AccessTy, TLI)) { LU.Kind, LU.AccessTy, STTI)) {
// As a special-case, handle special out-of-loop Basic users specially. // As a special-case, handle special out-of-loop Basic users specially.
// TODO: Reconsider this special case. // TODO: Reconsider this special case.
if (LU.Kind == LSRUse::Basic && if (LU.Kind == LSRUse::Basic &&
isLegalUse(Base.AM, LU.MinOffset, LU.MaxOffset, isLegalUse(Base.AM, LU.MinOffset, LU.MaxOffset,
LSRUse::Special, LU.AccessTy, TLI) && LSRUse::Special, LU.AccessTy, STTI) &&
LU.AllFixupsOutsideLoop) LU.AllFixupsOutsideLoop)
LU.Kind = LSRUse::Special; LU.Kind = LSRUse::Special;
else else
@ -3391,8 +3391,8 @@ void LSRInstance::GenerateScales(LSRUse &LU, unsigned LUIdx, Formula Base) {
/// GenerateTruncates - Generate reuse formulae from different IV types. /// GenerateTruncates - Generate reuse formulae from different IV types.
void LSRInstance::GenerateTruncates(LSRUse &LU, unsigned LUIdx, Formula Base) { void LSRInstance::GenerateTruncates(LSRUse &LU, unsigned LUIdx, Formula Base) {
// This requires TargetLowering to tell us which truncates are free. // This requires ScalarTargetTransformInfo to tell us which truncates are free.
if (!TLI) return; if (!STTI) return;
// Don't bother truncating symbolic values. // Don't bother truncating symbolic values.
if (Base.AM.BaseGV) return; if (Base.AM.BaseGV) return;
@ -3405,7 +3405,7 @@ void LSRInstance::GenerateTruncates(LSRUse &LU, unsigned LUIdx, Formula Base) {
for (SmallSetVector<Type *, 4>::const_iterator for (SmallSetVector<Type *, 4>::const_iterator
I = Types.begin(), E = Types.end(); I != E; ++I) { I = Types.begin(), E = Types.end(); I != E; ++I) {
Type *SrcTy = *I; Type *SrcTy = *I;
if (SrcTy != DstTy && TLI->isTruncateFree(SrcTy, DstTy)) { if (SrcTy != DstTy && STTI->isTruncateFree(SrcTy, DstTy)) {
Formula F = Base; Formula F = Base;
if (F.ScaledReg) F.ScaledReg = SE.getAnyExtendExpr(F.ScaledReg, *I); if (F.ScaledReg) F.ScaledReg = SE.getAnyExtendExpr(F.ScaledReg, *I);
@ -3561,7 +3561,7 @@ void LSRInstance::GenerateCrossUseConstantOffsets() {
Formula NewF = F; Formula NewF = F;
NewF.AM.BaseOffs = Offs; NewF.AM.BaseOffs = Offs;
if (!isLegalUse(NewF.AM, LU.MinOffset, LU.MaxOffset, if (!isLegalUse(NewF.AM, LU.MinOffset, LU.MaxOffset,
LU.Kind, LU.AccessTy, TLI)) LU.Kind, LU.AccessTy, STTI))
continue; continue;
NewF.ScaledReg = SE.getAddExpr(NegImmS, NewF.ScaledReg); NewF.ScaledReg = SE.getAddExpr(NegImmS, NewF.ScaledReg);
@ -3586,9 +3586,9 @@ void LSRInstance::GenerateCrossUseConstantOffsets() {
Formula NewF = F; Formula NewF = F;
NewF.AM.BaseOffs = (uint64_t)NewF.AM.BaseOffs + Imm; NewF.AM.BaseOffs = (uint64_t)NewF.AM.BaseOffs + Imm;
if (!isLegalUse(NewF.AM, LU.MinOffset, LU.MaxOffset, if (!isLegalUse(NewF.AM, LU.MinOffset, LU.MaxOffset,
LU.Kind, LU.AccessTy, TLI)) { LU.Kind, LU.AccessTy, STTI)) {
if (!TLI || if (!STTI ||
!TLI->isLegalAddImmediate((uint64_t)NewF.UnfoldedOffset + Imm)) !STTI->isLegalAddImmediate((uint64_t)NewF.UnfoldedOffset + Imm))
continue; continue;
NewF = F; NewF = F;
NewF.UnfoldedOffset = (uint64_t)NewF.UnfoldedOffset + Imm; NewF.UnfoldedOffset = (uint64_t)NewF.UnfoldedOffset + Imm;
@ -3900,7 +3900,7 @@ void LSRInstance::NarrowSearchSpaceByCollapsingUnrolledCode() {
Formula &F = LUThatHas->Formulae[i]; Formula &F = LUThatHas->Formulae[i];
if (!isLegalUse(F.AM, if (!isLegalUse(F.AM,
LUThatHas->MinOffset, LUThatHas->MaxOffset, LUThatHas->MinOffset, LUThatHas->MaxOffset,
LUThatHas->Kind, LUThatHas->AccessTy, TLI)) { LUThatHas->Kind, LUThatHas->AccessTy, STTI)) {
DEBUG(dbgs() << " Deleting "; F.print(dbgs()); DEBUG(dbgs() << " Deleting "; F.print(dbgs());
dbgs() << '\n'); dbgs() << '\n');
LUThatHas->DeleteFormula(F); LUThatHas->DeleteFormula(F);
@ -4589,12 +4589,12 @@ LSRInstance::ImplementSolution(const SmallVectorImpl<const Formula *> &Solution,
Changed |= DeleteTriviallyDeadInstructions(DeadInsts); Changed |= DeleteTriviallyDeadInstructions(DeadInsts);
} }
LSRInstance::LSRInstance(const TargetLowering *tli, Loop *l, Pass *P) LSRInstance::LSRInstance(const ScalarTargetTransformInfo *stti, Loop *l, Pass *P)
: IU(P->getAnalysis<IVUsers>()), : IU(P->getAnalysis<IVUsers>()),
SE(P->getAnalysis<ScalarEvolution>()), SE(P->getAnalysis<ScalarEvolution>()),
DT(P->getAnalysis<DominatorTree>()), DT(P->getAnalysis<DominatorTree>()),
LI(P->getAnalysis<LoopInfo>()), LI(P->getAnalysis<LoopInfo>()),
TLI(tli), L(l), Changed(false), IVIncInsertPos(0) { STTI(stti), L(l), Changed(false), IVIncInsertPos(0) {
// If LoopSimplify form is not available, stay out of trouble. // If LoopSimplify form is not available, stay out of trouble.
if (!L->isLoopSimplifyForm()) if (!L->isLoopSimplifyForm())
@ -4684,7 +4684,7 @@ LSRInstance::LSRInstance(const TargetLowering *tli, Loop *l, Pass *P)
for (SmallVectorImpl<Formula>::const_iterator J = LU.Formulae.begin(), for (SmallVectorImpl<Formula>::const_iterator J = LU.Formulae.begin(),
JE = LU.Formulae.end(); J != JE; ++J) JE = LU.Formulae.end(); J != JE; ++J)
assert(isLegalUse(J->AM, LU.MinOffset, LU.MaxOffset, assert(isLegalUse(J->AM, LU.MinOffset, LU.MaxOffset,
LU.Kind, LU.AccessTy, TLI) && LU.Kind, LU.AccessTy, STTI) &&
"Illegal formula generated!"); "Illegal formula generated!");
}; };
#endif #endif
@ -4757,13 +4757,13 @@ void LSRInstance::dump() const {
namespace { namespace {
class LoopStrengthReduce : public LoopPass { class LoopStrengthReduce : public LoopPass {
/// TLI - Keep a pointer of a TargetLowering to consult for determining /// ScalarTargetTransformInfo provides target information that is needed
/// transformation profitability. /// for strength reducing loops.
const TargetLowering *const TLI; const ScalarTargetTransformInfo *STTI;
public: public:
static char ID; // Pass ID, replacement for typeid static char ID; // Pass ID, replacement for typeid
explicit LoopStrengthReduce(const TargetLowering *tli = 0); LoopStrengthReduce();
private: private:
bool runOnLoop(Loop *L, LPPassManager &LPM); bool runOnLoop(Loop *L, LPPassManager &LPM);
@ -4783,13 +4783,12 @@ INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
INITIALIZE_PASS_END(LoopStrengthReduce, "loop-reduce", INITIALIZE_PASS_END(LoopStrengthReduce, "loop-reduce",
"Loop Strength Reduction", false, false) "Loop Strength Reduction", false, false)
Pass *llvm::createLoopStrengthReducePass() {
Pass *llvm::createLoopStrengthReducePass(const TargetLowering *TLI) { return new LoopStrengthReduce();
return new LoopStrengthReduce(TLI);
} }
LoopStrengthReduce::LoopStrengthReduce(const TargetLowering *tli) LoopStrengthReduce::LoopStrengthReduce()
: LoopPass(ID), TLI(tli) { : LoopPass(ID), STTI(0) {
initializeLoopStrengthReducePass(*PassRegistry::getPassRegistry()); initializeLoopStrengthReducePass(*PassRegistry::getPassRegistry());
} }
@ -4815,8 +4814,13 @@ void LoopStrengthReduce::getAnalysisUsage(AnalysisUsage &AU) const {
bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager & /*LPM*/) { bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager & /*LPM*/) {
bool Changed = false; bool Changed = false;
TargetTransformInfo *TTI = getAnalysisIfAvailable<TargetTransformInfo>();
if (TTI)
STTI = TTI->getScalarTargetTransformInfo();
// Run the main LSR transformation. // Run the main LSR transformation.
Changed |= LSRInstance(TLI, L, this).getChanged(); Changed |= LSRInstance(STTI, L, this).getChanged();
// Remove any extra phis created by processing inner loops. // Remove any extra phis created by processing inner loops.
Changed |= DeleteDeadPHIs(L->getHeader()); Changed |= DeleteDeadPHIs(L->getHeader());
@ -4827,7 +4831,7 @@ bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager & /*LPM*/) {
Rewriter.setDebugType(DEBUG_TYPE); Rewriter.setDebugType(DEBUG_TYPE);
#endif #endif
unsigned numFolded = Rewriter. unsigned numFolded = Rewriter.
replaceCongruentIVs(L, &getAnalysis<DominatorTree>(), DeadInsts, TLI); replaceCongruentIVs(L, &getAnalysis<DominatorTree>(), DeadInsts, STTI);
if (numFolded) { if (numFolded) {
Changed = true; Changed = true;
DeleteTriviallyDeadInstructions(DeadInsts); DeleteTriviallyDeadInstructions(DeadInsts);

View File

@ -45,10 +45,10 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/Local.h"
#include "llvm/TargetTransformInfo.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h" #include "llvm/ADT/Statistic.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetLowering.h"
#include <csetjmp> #include <csetjmp>
#include <set> #include <set>
using namespace llvm; using namespace llvm;
@ -70,15 +70,14 @@ namespace {
Constant *SetJmpFn, *LongJmpFn, *StackSaveFn, *StackRestoreFn; Constant *SetJmpFn, *LongJmpFn, *StackSaveFn, *StackRestoreFn;
bool useExpensiveEHSupport; bool useExpensiveEHSupport;
// We peek in TLI to grab the target's jmp_buf size and alignment // We peek in STTI to grab the target's jmp_buf size and alignment
const TargetLowering *TLI; const ScalarTargetTransformInfo *STTI;
public: public:
static char ID; // Pass identification, replacement for typeid static char ID; // Pass identification, replacement for typeid
explicit LowerInvoke(const TargetLowering *tli = NULL, explicit LowerInvoke(bool useExpensiveEHSupport = ExpensiveEHSupport)
bool useExpensiveEHSupport = ExpensiveEHSupport)
: FunctionPass(ID), useExpensiveEHSupport(useExpensiveEHSupport), : FunctionPass(ID), useExpensiveEHSupport(useExpensiveEHSupport),
TLI(tli) { STTI(0) {
initializeLowerInvokePass(*PassRegistry::getPassRegistry()); initializeLowerInvokePass(*PassRegistry::getPassRegistry());
} }
bool doInitialization(Module &M); bool doInitialization(Module &M);
@ -108,21 +107,24 @@ INITIALIZE_PASS(LowerInvoke, "lowerinvoke",
char &llvm::LowerInvokePassID = LowerInvoke::ID; char &llvm::LowerInvokePassID = LowerInvoke::ID;
// Public Interface To the LowerInvoke pass. // Public Interface To the LowerInvoke pass.
FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) { FunctionPass *llvm::createLowerInvokePass() {
return new LowerInvoke(TLI, ExpensiveEHSupport); return new LowerInvoke(ExpensiveEHSupport);
} }
FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI, FunctionPass *llvm::createLowerInvokePass(bool useExpensiveEHSupport) {
bool useExpensiveEHSupport) { return new LowerInvoke(useExpensiveEHSupport);
return new LowerInvoke(TLI, useExpensiveEHSupport);
} }
// 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) {
TargetTransformInfo *TTI = getAnalysisIfAvailable<TargetTransformInfo>();
if (TTI)
STTI = TTI->getScalarTargetTransformInfo();
Type *VoidPtrTy = Type::getInt8PtrTy(M.getContext()); Type *VoidPtrTy = Type::getInt8PtrTy(M.getContext());
if (useExpensiveEHSupport) { if (useExpensiveEHSupport) {
// 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 = STTI ? STTI->getJumpBufSize() : 0;
JBSize = JBSize ? JBSize : 200; JBSize = JBSize ? JBSize : 200;
Type *JmpBufTy = ArrayType::get(VoidPtrTy, JBSize); Type *JmpBufTy = ArrayType::get(VoidPtrTy, JBSize);
@ -430,7 +432,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Create an alloca for the incoming jump buffer ptr and the new jump buffer // Create an alloca for the incoming jump buffer ptr and the new jump buffer
// that needs to be restored on all exits from the function. This is an // that needs to be restored on all exits from the function. This is an
// alloca because the value needs to be live across invokes. // alloca because the value needs to be live across invokes.
unsigned Align = TLI ? TLI->getJumpBufAlignment() : 0; unsigned Align = STTI ? STTI->getJumpBufAlignment() : 0;
AllocaInst *JmpBuf = AllocaInst *JmpBuf =
new AllocaInst(JBLinkTy, 0, Align, new AllocaInst(JBLinkTy, 0, Align,
"jblink", F.begin()->begin()); "jblink", F.begin()->begin());
@ -575,6 +577,10 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
} }
bool LowerInvoke::runOnFunction(Function &F) { bool LowerInvoke::runOnFunction(Function &F) {
TargetTransformInfo *TTI = getAnalysisIfAvailable<TargetTransformInfo>();
if (TTI)
STTI = TTI->getScalarTargetTransformInfo();
if (useExpensiveEHSupport) if (useExpensiveEHSupport)
return insertExpensiveEHSupport(F); return insertExpensiveEHSupport(F);
else else

View File

@ -33,6 +33,7 @@ add_llvm_library(LLVMCore
PrintModulePass.cpp PrintModulePass.cpp
Type.cpp Type.cpp
TypeFinder.cpp TypeFinder.cpp
TargetTransformInfo.cpp
Use.cpp Use.cpp
User.cpp User.cpp
Value.cpp Value.cpp

View File

@ -0,0 +1,27 @@
//===- llvm/VMCore/TargetTransformInfo.cpp ----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/TargetTransformInfo.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
/// Default ctor.
///
/// @note This has to exist, because this is a pass, but it should never be
/// used.
TargetTransformInfo::TargetTransformInfo() : ImmutablePass(ID) {
report_fatal_error("Bad TargetTransformInfo ctor used. "
"Tool did not specify a TargetTransformInfo to use?");
}
INITIALIZE_PASS(TargetTransformInfo, "TargetTransformInfo",
"Target Transform Info", false, true)
char TargetTransformInfo::ID = 0;

View File

@ -21,6 +21,7 @@
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/Assembly/PrintModulePass.h" #include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Support/IRReader.h" #include "llvm/Support/IRReader.h"
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h" #include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h" #include "llvm/CodeGen/LinkAllCodegenComponents.h"
#include "llvm/MC/SubtargetFeature.h" #include "llvm/MC/SubtargetFeature.h"
@ -62,216 +63,13 @@ OptLevel("O",
static cl::opt<std::string> static cl::opt<std::string>
TargetTriple("mtriple", cl::desc("Override target triple for module")); TargetTriple("mtriple", cl::desc("Override target triple for module"));
static cl::opt<std::string>
MArch("march", cl::desc("Architecture to generate code for (see --version)"));
static cl::opt<std::string>
MCPU("mcpu",
cl::desc("Target a specific cpu type (-mcpu=help for details)"),
cl::value_desc("cpu-name"),
cl::init(""));
static cl::list<std::string>
MAttrs("mattr",
cl::CommaSeparated,
cl::desc("Target specific attributes (-mattr=help for details)"),
cl::value_desc("a1,+a2,-a3,..."));
static cl::opt<Reloc::Model>
RelocModel("relocation-model",
cl::desc("Choose relocation model"),
cl::init(Reloc::Default),
cl::values(
clEnumValN(Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(Reloc::Static, "static",
"Non-relocatable code"),
clEnumValN(Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));
static cl::opt<llvm::CodeModel::Model>
CMModel("code-model",
cl::desc("Choose code model"),
cl::init(CodeModel::Default),
cl::values(clEnumValN(CodeModel::Default, "default",
"Target default code model"),
clEnumValN(CodeModel::Small, "small",
"Small code model"),
clEnumValN(CodeModel::Kernel, "kernel",
"Kernel code model"),
clEnumValN(CodeModel::Medium, "medium",
"Medium code model"),
clEnumValN(CodeModel::Large, "large",
"Large code model"),
clEnumValEnd));
static cl::opt<bool>
RelaxAll("mc-relax-all",
cl::desc("When used with filetype=obj, "
"relax all fixups in the emitted object file"));
cl::opt<TargetMachine::CodeGenFileType>
FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
cl::desc("Choose a file type (not all types are supported by all targets):"),
cl::values(
clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
"Emit an assembly ('.s') file"),
clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
"Emit a native object ('.o') file"),
clEnumValN(TargetMachine::CGFT_Null, "null",
"Emit nothing, for performance testing"),
clEnumValEnd));
cl::opt<bool> NoVerify("disable-verify", cl::Hidden, cl::opt<bool> NoVerify("disable-verify", cl::Hidden,
cl::desc("Do not verify input module")); cl::desc("Do not verify input module"));
cl::opt<bool> DisableDotLoc("disable-dot-loc", cl::Hidden, cl::opt<bool>
cl::desc("Do not use .loc entries"));
cl::opt<bool> DisableCFI("disable-cfi", cl::Hidden,
cl::desc("Do not use .cfi_* directives"));
cl::opt<bool> EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden,
cl::desc("Use .file directives with an explicit directory."));
static cl::opt<bool>
DisableRedZone("disable-red-zone",
cl::desc("Do not emit code that uses the red zone."),
cl::init(false));
static cl::opt<bool>
EnableFPMAD("enable-fp-mad",
cl::desc("Enable less precise MAD instructions to be generated"),
cl::init(false));
static cl::opt<bool>
DisableFPElim("disable-fp-elim",
cl::desc("Disable frame pointer elimination optimization"),
cl::init(false));
static cl::opt<bool>
DisableFPElimNonLeaf("disable-non-leaf-fp-elim",
cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"),
cl::init(false));
static cl::opt<bool>
EnableUnsafeFPMath("enable-unsafe-fp-math",
cl::desc("Enable optimizations that may decrease FP precision"),
cl::init(false));
static cl::opt<bool>
EnableNoInfsFPMath("enable-no-infs-fp-math",
cl::desc("Enable FP math optimizations that assume no +-Infs"),
cl::init(false));
static cl::opt<bool>
EnableNoNaNsFPMath("enable-no-nans-fp-math",
cl::desc("Enable FP math optimizations that assume no NaNs"),
cl::init(false));
static cl::opt<bool>
EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
cl::Hidden,
cl::desc("Force codegen to assume rounding mode can change dynamically"),
cl::init(false));
static cl::opt<bool>
GenerateSoftFloatCalls("soft-float",
cl::desc("Generate software floating point library calls"),
cl::init(false));
static cl::opt<llvm::FloatABI::ABIType>
FloatABIForCalls("float-abi",
cl::desc("Choose float ABI type"),
cl::init(FloatABI::Default),
cl::values(
clEnumValN(FloatABI::Default, "default",
"Target default float ABI type"),
clEnumValN(FloatABI::Soft, "soft",
"Soft float ABI (implied by -soft-float)"),
clEnumValN(FloatABI::Hard, "hard",
"Hard float ABI (uses FP registers)"),
clEnumValEnd));
static cl::opt<llvm::FPOpFusion::FPOpFusionMode>
FuseFPOps("fp-contract",
cl::desc("Enable aggresive formation of fused FP ops"),
cl::init(FPOpFusion::Standard),
cl::values(
clEnumValN(FPOpFusion::Fast, "fast",
"Fuse FP ops whenever profitable"),
clEnumValN(FPOpFusion::Standard, "on",
"Only fuse 'blessed' FP ops."),
clEnumValN(FPOpFusion::Strict, "off",
"Only fuse FP ops when the result won't be effected."),
clEnumValEnd));
static cl::opt<bool>
DontPlaceZerosInBSS("nozero-initialized-in-bss",
cl::desc("Don't place zero-initialized symbols into bss section"),
cl::init(false));
static cl::opt<bool>
DisableSimplifyLibCalls("disable-simplify-libcalls", DisableSimplifyLibCalls("disable-simplify-libcalls",
cl::desc("Disable simplify-libcalls"), cl::desc("Disable simplify-libcalls"),
cl::init(false)); cl::init(false));
static cl::opt<bool>
EnableGuaranteedTailCallOpt("tailcallopt",
cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
cl::init(false));
static cl::opt<bool>
DisableTailCalls("disable-tail-calls",
cl::desc("Never emit tail calls"),
cl::init(false));
static cl::opt<unsigned>
OverrideStackAlignment("stack-alignment",
cl::desc("Override default stack alignment"),
cl::init(0));
static cl::opt<bool>
EnableRealignStack("realign-stack",
cl::desc("Realign stack if needed"),
cl::init(true));
static cl::opt<std::string>
TrapFuncName("trap-func", cl::Hidden,
cl::desc("Emit a call to trap function rather than a trap instruction"),
cl::init(""));
static cl::opt<bool>
EnablePIE("enable-pie",
cl::desc("Assume the creation of a position independent executable."),
cl::init(false));
static cl::opt<bool>
SegmentedStacks("segmented-stacks",
cl::desc("Use segmented stacks if possible."),
cl::init(false));
static cl::opt<bool>
UseInitArray("use-init-array",
cl::desc("Use .init_array instead of .ctors."),
cl::init(false));
static cl::opt<std::string> StopAfter("stop-after",
cl::desc("Stop compilation after a specific pass"),
cl::value_desc("pass-name"),
cl::init(""));
static cl::opt<std::string> StartAfter("start-after",
cl::desc("Resume compilation after a specific pass"),
cl::value_desc("pass-name"),
cl::init(""));
static cl::opt<unsigned>
SSPBufferSize("stack-protector-buffer-size", cl::init(8),
cl::desc("Lower bound for a buffer to be considered for "
"stack protection"));
// GetFileNameRoot - Helper function to get the basename of a filename. // GetFileNameRoot - Helper function to get the basename of a filename.
static inline std::string static inline std::string
@ -505,6 +303,11 @@ int main(int argc, char **argv) {
TLI->disableAllFunctions(); TLI->disableAllFunctions();
PM.add(TLI); PM.add(TLI);
if (target.get()) {
PM.add(new TargetTransformInfo(target->getScalarTargetTransformInfo(),
target->getVectorTargetTransformInfo()));
}
// Add the target data from the target machine, if it exists, or the module. // Add the target data from the target machine, if it exists, or the module.
if (const DataLayout *TD = Target.getDataLayout()) if (const DataLayout *TD = Target.getDataLayout())
PM.add(new DataLayout(*TD)); PM.add(new DataLayout(*TD));

View File

@ -1,4 +1,4 @@
set(LLVM_LINK_COMPONENTS bitreader asmparser bitwriter instrumentation scalaropts ipo vectorize) set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} bitreader asmparser bitwriter instrumentation scalaropts ipo vectorize)
add_llvm_tool(opt add_llvm_tool(opt
AnalysisWrappers.cpp AnalysisWrappers.cpp

View File

@ -19,4 +19,4 @@
type = Tool type = Tool
name = opt name = opt
parent = Tools parent = Tools
required_libraries = AsmParser BitReader BitWriter IPO Instrumentation Scalar required_libraries = AsmParser BitReader BitWriter IPO Instrumentation Scalar all-targets

View File

@ -9,6 +9,6 @@
LEVEL := ../.. LEVEL := ../..
TOOLNAME := opt TOOLNAME := opt
LINK_COMPONENTS := bitreader bitwriter asmparser instrumentation scalaropts ipo vectorize LINK_COMPONENTS := bitreader bitwriter asmparser instrumentation scalaropts ipo vectorize all-targets
include $(LEVEL)/Makefile.common include $(LEVEL)/Makefile.common

View File

@ -18,6 +18,7 @@
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#include "llvm/CallGraphSCCPass.h" #include "llvm/CallGraphSCCPass.h"
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Assembly/PrintModulePass.h" #include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Verifier.h"
@ -36,7 +37,9 @@
#include "llvm/Support/PluginLoader.h" #include "llvm/Support/PluginLoader.h"
#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/SystemUtils.h" #include "llvm/Support/SystemUtils.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/ToolOutputFile.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/LinkAllPasses.h" #include "llvm/LinkAllPasses.h"
#include "llvm/LinkAllVMCore.h" #include "llvm/LinkAllVMCore.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h"
@ -478,6 +481,75 @@ static void AddStandardLinkPasses(PassManagerBase &PM) {
/*RunInliner=*/ !DisableInline); /*RunInliner=*/ !DisableInline);
} }
//===----------------------------------------------------------------------===//
// CodeGen-related helper functions.
//
static TargetOptions GetTargetOptions() {
TargetOptions Options;
Options.LessPreciseFPMADOption = EnableFPMAD;
Options.NoFramePointerElim = DisableFPElim;
Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf;
Options.AllowFPOpFusion = FuseFPOps;
Options.UnsafeFPMath = EnableUnsafeFPMath;
Options.NoInfsFPMath = EnableNoInfsFPMath;
Options.NoNaNsFPMath = EnableNoNaNsFPMath;
Options.HonorSignDependentRoundingFPMathOption =
EnableHonorSignDependentRoundingFPMath;
Options.UseSoftFloat = GenerateSoftFloatCalls;
if (FloatABIForCalls != FloatABI::Default)
Options.FloatABIType = FloatABIForCalls;
Options.NoZerosInBSS = DontPlaceZerosInBSS;
Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
Options.DisableTailCalls = DisableTailCalls;
Options.StackAlignmentOverride = OverrideStackAlignment;
Options.RealignStack = EnableRealignStack;
Options.TrapFuncName = TrapFuncName;
Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks;
Options.UseInitArray = UseInitArray;
Options.SSPBufferSize = SSPBufferSize;
return Options;
}
CodeGenOpt::Level GetCodeGenOptLevel() {
if (OptLevelO1)
return CodeGenOpt::Less;
if (OptLevelO2)
return CodeGenOpt::Default;
if (OptLevelO3)
return CodeGenOpt::Aggressive;
return CodeGenOpt::None;
}
// Returns the TargetMachine instance or zero if no triple is provided.
static TargetMachine* GetTargetMachine(std::string TripleStr) {
if (TripleStr.empty())
return 0;
// Get the target specific parser.
std::string Error;
Triple TheTriple(Triple::normalize(TargetTriple));
const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
Error);
if (!TheTarget) {
return 0;
}
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
if (MAttrs.size()) {
SubtargetFeatures Features;
for (unsigned i = 0; i != MAttrs.size(); ++i)
Features.AddFeature(MAttrs[i]);
FeaturesStr = Features.getString();
}
return TheTarget->createTargetMachine(TheTriple.getTriple(),
MCPU, FeaturesStr, GetTargetOptions(),
RelocModel, CMModel,
GetCodeGenOptLevel());
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// main for opt // main for opt
@ -579,6 +651,12 @@ int main(int argc, char **argv) {
if (TD) if (TD)
Passes.add(TD); Passes.add(TD);
std::auto_ptr<TargetMachine> TM(GetTargetMachine(TargetTriple));
if (TM.get()) {
Passes.add(new TargetTransformInfo(TM->getScalarTargetTransformInfo(),
TM->getVectorTargetTransformInfo()));
}
OwningPtr<FunctionPassManager> FPasses; OwningPtr<FunctionPassManager> FPasses;
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
FPasses.reset(new FunctionPassManager(M.get())); FPasses.reset(new FunctionPassManager(M.get()));