llvm.org GIT mirror llvm / e3d0e86
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 Nadav Rotem 7 years ago
43 changed file(s) with 814 addition(s) and 320 deletion(s). Raw diff Collapse all Expand all
2121 #include
2222
2323 namespace llvm {
24 class TargetLowering;
24 class ScalarTargetTransformInfo;
2525
2626 /// Return true if the given expression is safe to expand in the sense that
2727 /// all materialized values are safe to speculate.
128128 /// representative. Return the number of phis eliminated.
129129 unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT,
130130 SmallVectorImpl &DeadInsts,
131 const TargetLowering *TLI = NULL);
131 const ScalarTargetTransformInfo *STTI = NULL);
132132
133133 /// expandCodeFor - Insert code to directly compute the specified SCEV
134134 /// expression into the program. The inserted code is inserted into the
0 //===-- CommandFlags.h - Register Coalescing Interface ----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains codegen-specific flags that are shared between different
10 // command line tools. The tools "llc" and "opt" both use this file to prevent
11 // flag duplication.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_COMMAND_LINE_FLAGS_H
16 #define LLVM_CODEGEN_COMMAND_LINE_FLAGS_H
17
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/CodeGen.h"
20 #include "llvm/Target/TargetMachine.h"
21
22 #include
23 using namespace llvm;
24
25 cl::opt
26 MArch("march", cl::desc("Architecture to generate code for (see --version)"));
27
28 cl::opt
29 MCPU("mcpu",
30 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
31 cl::value_desc("cpu-name"),
32 cl::init(""));
33
34 cl::list
35 MAttrs("mattr",
36 cl::CommaSeparated,
37 cl::desc("Target specific attributes (-mattr=help for details)"),
38 cl::value_desc("a1,+a2,-a3,..."));
39
40 cl::opt
41 RelocModel("relocation-model",
42 cl::desc("Choose relocation model"),
43 cl::init(Reloc::Default),
44 cl::values(
45 clEnumValN(Reloc::Default, "default",
46 "Target default relocation model"),
47 clEnumValN(Reloc::Static, "static",
48 "Non-relocatable code"),
49 clEnumValN(Reloc::PIC_, "pic",
50 "Fully relocatable, position independent code"),
51 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
52 "Relocatable external references, non-relocatable code"),
53 clEnumValEnd));
54
55 cl::opt
56 CMModel("code-model",
57 cl::desc("Choose code model"),
58 cl::init(CodeModel::Default),
59 cl::values(clEnumValN(CodeModel::Default, "default",
60 "Target default code model"),
61 clEnumValN(CodeModel::Small, "small",
62 "Small code model"),
63 clEnumValN(CodeModel::Kernel, "kernel",
64 "Kernel code model"),
65 clEnumValN(CodeModel::Medium, "medium",
66 "Medium code model"),
67 clEnumValN(CodeModel::Large, "large",
68 "Large code model"),
69 clEnumValEnd));
70
71 cl::opt
72 RelaxAll("mc-relax-all",
73 cl::desc("When used with filetype=obj, "
74 "relax all fixups in the emitted object file"));
75
76 cl::opt
77 FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
78 cl::desc("Choose a file type (not all types are supported by all targets):"),
79 cl::values(
80 clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
81 "Emit an assembly ('.s') file"),
82 clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
83 "Emit a native object ('.o') file"),
84 clEnumValN(TargetMachine::CGFT_Null, "null",
85 "Emit nothing, for performance testing"),
86 clEnumValEnd));
87
88 cl::opt DisableDotLoc("disable-dot-loc", cl::Hidden,
89 cl::desc("Do not use .loc entries"));
90
91 cl::opt DisableCFI("disable-cfi", cl::Hidden,
92 cl::desc("Do not use .cfi_* directives"));
93
94 cl::opt EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden,
95 cl::desc("Use .file directives with an explicit directory."));
96
97 cl::opt
98 DisableRedZone("disable-red-zone",
99 cl::desc("Do not emit code that uses the red zone."),
100 cl::init(false));
101
102 cl::opt
103 EnableFPMAD("enable-fp-mad",
104 cl::desc("Enable less precise MAD instructions to be generated"),
105 cl::init(false));
106
107 cl::opt
108 DisableFPElim("disable-fp-elim",
109 cl::desc("Disable frame pointer elimination optimization"),
110 cl::init(false));
111
112 cl::opt
113 DisableFPElimNonLeaf("disable-non-leaf-fp-elim",
114 cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"),
115 cl::init(false));
116
117 cl::opt
118 EnableUnsafeFPMath("enable-unsafe-fp-math",
119 cl::desc("Enable optimizations that may decrease FP precision"),
120 cl::init(false));
121
122 cl::opt
123 EnableNoInfsFPMath("enable-no-infs-fp-math",
124 cl::desc("Enable FP math optimizations that assume no +-Infs"),
125 cl::init(false));
126
127 cl::opt
128 EnableNoNaNsFPMath("enable-no-nans-fp-math",
129 cl::desc("Enable FP math optimizations that assume no NaNs"),
130 cl::init(false));
131
132 cl::opt
133 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
134 cl::Hidden,
135 cl::desc("Force codegen to assume rounding mode can change dynamically"),
136 cl::init(false));
137
138 cl::opt
139 GenerateSoftFloatCalls("soft-float",
140 cl::desc("Generate software floating point library calls"),
141 cl::init(false));
142
143 cl::opt
144 FloatABIForCalls("float-abi",
145 cl::desc("Choose float ABI type"),
146 cl::init(FloatABI::Default),
147 cl::values(
148 clEnumValN(FloatABI::Default, "default",
149 "Target default float ABI type"),
150 clEnumValN(FloatABI::Soft, "soft",
151 "Soft float ABI (implied by -soft-float)"),
152 clEnumValN(FloatABI::Hard, "hard",
153 "Hard float ABI (uses FP registers)"),
154 clEnumValEnd));
155
156 cl::opt
157 FuseFPOps("fp-contract",
158 cl::desc("Enable aggresive formation of fused FP ops"),
159 cl::init(FPOpFusion::Standard),
160 cl::values(
161 clEnumValN(FPOpFusion::Fast, "fast",
162 "Fuse FP ops whenever profitable"),
163 clEnumValN(FPOpFusion::Standard, "on",
164 "Only fuse 'blessed' FP ops."),
165 clEnumValN(FPOpFusion::Strict, "off",
166 "Only fuse FP ops when the result won't be effected."),
167 clEnumValEnd));
168
169 cl::opt
170 DontPlaceZerosInBSS("nozero-initialized-in-bss",
171 cl::desc("Don't place zero-initialized symbols into bss section"),
172 cl::init(false));
173
174 cl::opt
175 EnableGuaranteedTailCallOpt("tailcallopt",
176 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
177 cl::init(false));
178
179 cl::opt
180 DisableTailCalls("disable-tail-calls",
181 cl::desc("Never emit tail calls"),
182 cl::init(false));
183
184 cl::opt
185 OverrideStackAlignment("stack-alignment",
186 cl::desc("Override default stack alignment"),
187 cl::init(0));
188
189 cl::opt
190 EnableRealignStack("realign-stack",
191 cl::desc("Realign stack if needed"),
192 cl::init(true));
193
194 cl::opt
195 TrapFuncName("trap-func", cl::Hidden,
196 cl::desc("Emit a call to trap function rather than a trap instruction"),
197 cl::init(""));
198
199 cl::opt
200 EnablePIE("enable-pie",
201 cl::desc("Assume the creation of a position independent executable."),
202 cl::init(false));
203
204 cl::opt
205 SegmentedStacks("segmented-stacks",
206 cl::desc("Use segmented stacks if possible."),
207 cl::init(false));
208
209 cl::opt
210 UseInitArray("use-init-array",
211 cl::desc("Use .init_array instead of .ctors."),
212 cl::init(false));
213
214 cl::opt StopAfter("stop-after",
215 cl::desc("Stop compilation after a specific pass"),
216 cl::value_desc("pass-name"),
217 cl::init(""));
218 cl::opt StartAfter("start-after",
219 cl::desc("Resume compilation after a specific pass"),
220 cl::value_desc("pass-name"),
221 cl::init(""));
222
223 cl::opt
224 SSPBufferSize("stack-protector-buffer-size", cl::init(8),
225 cl::desc("Lower bound for a buffer to be considered for "
226 "stack protection"));
227 #endif
246246 void initializeTailDuplicatePassPass(PassRegistry&);
247247 void initializeTargetPassConfigPass(PassRegistry&);
248248 void initializeDataLayoutPass(PassRegistry&);
249 void initializeTargetTransformInfoPass(PassRegistry&);
249250 void initializeTargetLibraryInfoPass(PassRegistry&);
250251 void initializeTwoAddressInstructionPassPass(PassRegistry&);
251252 void initializeTypeBasedAliasAnalysisPass(PassRegistry&);
1616 #include "llvm/Pass.h"
1717 #include "llvm/Support/CodeGen.h"
1818 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/TargetTransformInfo.h"
20 #include "llvm/Target/TargetTransformImpl.h"
1921 #include "llvm/ADT/StringRef.h"
2022 #include
2123 #include
106108 virtual const TargetLowering *getTargetLowering() const { return 0; }
107109 virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
108110 virtual const DataLayout *getDataLayout() const { return 0; }
111 virtual const ScalarTargetTransformInfo*
112 getScalarTargetTransformInfo() const { return 0; }
113 virtual const VectorTargetTransformInfo*
114 getVectorTargetTransformInfo() const { return 0; }
109115
110116 /// getMCAsmInfo - Return target specific asm information.
111117 ///
0 //=- llvm/Target/TargetTransformImpl.h - Target Loop Trans Info----*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the target-specific implementations of the
10 // TargetTransform interfaces.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGET_TRANSFORMATION_IMPL_H
15 #define LLVM_TARGET_TARGET_TRANSFORMATION_IMPL_H
16
17 #include "llvm/TargetTransformInfo.h"
18
19 namespace llvm {
20
21 class TargetLowering;
22
23 /// ScalarTargetTransformInfo - This is a default implementation for the
24 /// ScalarTargetTransformInfo interface. Different targets can implement
25 /// this interface differently.
26 class ScalarTargetTransformImpl : public ScalarTargetTransformInfo {
27 private:
28 const TargetLowering *TLI;
29
30 public:
31 /// Ctor
32 explicit ScalarTargetTransformImpl(const TargetLowering *TL): TLI(TL) {}
33
34 virtual bool isLegalAddImmediate(int64_t imm) const;
35
36 virtual bool isLegalICmpImmediate(int64_t imm) const;
37
38 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const;
39
40 virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const;
41
42 virtual bool isTypeLegal(Type *Ty) const;
43
44 virtual unsigned getJumpBufAlignment() const;
45
46 virtual unsigned getJumpBufSize() const;
47 };
48
49 class VectorTargetTransformImpl : public VectorTargetTransformInfo { };
50
51 } // end llvm namespace
52
53 #endif
0 //===- llvm/Transforms/TargetTransformInfo.h --------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass exposes codegen information to IR-level passes. Every
10 // transformation that uses codegen information is broken into three parts:
11 // 1. The IR-level analysis pass.
12 // 2. The IR-level transformation interface which provides the needed
13 // information.
14 // 3. Codegen-level implementation which uses target-specific hooks.
15 //
16 // This file defines #2, which is the interface that IR-level transformations
17 // use for querying the codegen.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef LLVM_TRANSFORMS_TARGET_TRANSFORM_INTERFACE
22 #define LLVM_TRANSFORMS_TARGET_TRANSFORM_INTERFACE
23
24 #include "llvm/Pass.h"
25 #include "llvm/AddressingMode.h"
26 #include "llvm/Support/DataTypes.h"
27 #include "llvm/Type.h"
28
29 namespace llvm {
30
31 class ScalarTargetTransformInfo;
32 class VectorTargetTransformInfo;
33
34 /// TargetTransformInfo - This pass provides access to the codegen
35 /// interfaces that are needed for IR-level transformations.
36 class TargetTransformInfo : public ImmutablePass {
37 private:
38 const ScalarTargetTransformInfo *STTI;
39 const VectorTargetTransformInfo *VTTI;
40 public:
41 /// Default ctor.
42 ///
43 /// @note This has to exist, because this is a pass, but it should never be
44 /// used.
45 TargetTransformInfo();
46
47 explicit TargetTransformInfo(const ScalarTargetTransformInfo* S,
48 const VectorTargetTransformInfo *V)
49 : ImmutablePass(ID), STTI(S), VTTI(V) {
50 initializeTargetTransformInfoPass(*PassRegistry::getPassRegistry());
51 }
52
53 TargetTransformInfo(const TargetTransformInfo &T) :
54 ImmutablePass(ID), STTI(T.STTI), VTTI(T.VTTI) { }
55
56 const ScalarTargetTransformInfo* getScalarTargetTransformInfo() {
57 return STTI;
58 }
59 const VectorTargetTransformInfo* getVectorTargetTransformInfo() {
60 return VTTI;
61 }
62
63 /// Pass identification, replacement for typeid.
64 static char ID;
65 };
66
67 // ---------------------------------------------------------------------------//
68 // The classes below are inherited and implemented by target-specific classes
69 // in the codegen.
70 // ---------------------------------------------------------------------------//
71
72 /// ScalarTargetTransformInfo - This interface is used by IR-level passes
73 /// that need target-dependent information for generic scalar transformations.
74 /// LSR, and LowerInvoke use this interface.
75 class ScalarTargetTransformInfo {
76 public:
77 /// isLegalAddImmediate - Return true if the specified immediate is legal
78 /// add immediate, that is the target has add instructions which can add
79 /// a register with the immediate without having to materialize the
80 /// immediate into a register.
81 virtual bool isLegalAddImmediate(int64_t) const {
82 return false;
83 }
84 /// isLegalICmpImmediate - Return true if the specified immediate is legal
85 /// icmp immediate, that is the target has icmp instructions which can compare
86 /// a register against the immediate without having to materialize the
87 /// immediate into a register.
88 virtual bool isLegalICmpImmediate(int64_t) const {
89 return false;
90 }
91 /// isLegalAddressingMode - Return true if the addressing mode represented by
92 /// AM is legal for this target, for a load/store of the specified type.
93 /// The type may be VoidTy, in which case only return true if the addressing
94 /// mode is legal for a load/store of any legal type.
95 /// TODO: Handle pre/postinc as well.
96 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const {
97 return false;
98 }
99 /// isTruncateFree - Return true if it's free to truncate a value of
100 /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
101 /// register EAX to i16 by referencing its sub-register AX.
102 virtual bool isTruncateFree(Type * /*Ty1*/, Type * /*Ty2*/) const {
103 return false;
104 }
105 /// Is this type legal.
106 virtual bool isTypeLegal(Type *Ty) const {
107 return false;
108 }
109 /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
110 virtual unsigned getJumpBufAlignment() const {
111 return 0;
112 }
113 /// getJumpBufSize - returns the target's jmp_buf size in bytes.
114 virtual unsigned getJumpBufSize() const {
115 return 0;
116 }
117 };
118
119 class VectorTargetTransformInfo {
120 // TODO: define an interface for VectorTargetTransformInfo.
121 };
122
123 } // End llvm namespace
124
125 #endif
118118 // optional parameter used to consult the target machine whether certain
119119 // transformations are profitable.
120120 //
121 Pass *createLoopStrengthReducePass(const TargetLowering *TLI = 0);
121 Pass *createLoopStrengthReducePass();
122122
123123 Pass *createGlobalMergePass(const TargetLowering *TLI = 0);
124124
248248 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
249249 // lowering pass.
250250 //
251 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0);
252 FunctionPass *createLowerInvokePass(const TargetLowering *TLI,
253 bool useExpensiveEHSupport);
251 FunctionPass *createLowerInvokePass();
252 FunctionPass *createLowerInvokePass(bool useExpensiveEHSupport);
254253 extern char &LowerInvokePassID;
255254
256255 //===----------------------------------------------------------------------===//
1818 #include "llvm/LLVMContext.h"
1919 #include "llvm/Support/Debug.h"
2020 #include "llvm/DataLayout.h"
21 #include "llvm/Target/TargetLowering.h"
2221 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/TargetTransformInfo.h"
2323
2424 using namespace llvm;
2525
15981598 /// This does not depend on any SCEVExpander state but should be used in
15991599 /// the same context that SCEVExpander is used.
16001600 unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
1601 SmallVectorImpl &DeadInsts,
1602 const TargetLowering *TLI) {
1601 SmallVectorImpl &DeadInsts,
1602 const ScalarTargetTransformInfo *STTI) {
16031603 // Find integer phis in order of increasing width.
16041604 SmallVector Phis;
16051605 for (BasicBlock::iterator I = L->getHeader()->begin();
16061606 PHINode *Phi = dyn_cast(I); ++I) {
16071607 Phis.push_back(Phi);
16081608 }
1609 if (TLI)
1609 if (STTI)
16101610 std::sort(Phis.begin(), Phis.end(), width_descending);
16111611
16121612 unsigned NumElim = 0;
16231623 PHINode *&OrigPhiRef = ExprToIVMap[SE.getSCEV(Phi)];
16241624 if (!OrigPhiRef) {
16251625 OrigPhiRef = Phi;
1626 if (Phi->getType()->isIntegerTy() && TLI
1627 && TLI->isTruncateFree(Phi->getType(), Phis.back()->getType())) {
1626 if (Phi->getType()->isIntegerTy() && STTI &&
1627 STTI->isTruncateFree(Phi->getType(), Phis.back()->getType())) {
16281628 // This phi can be freely truncated to the narrowest phi type. Map the
16291629 // truncated expression to it so it will be reused for narrow types.
16301630 const SCEV *TruncExpr =
358358
359359 // Run loop strength reduction before anything else.
360360 if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
361 addPass(createLoopStrengthReducePass(getTargetLowering()));
361 addPass(createLoopStrengthReducePass());
362362 if (PrintLSR)
363363 addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
364364 }
388388 addPass(createDwarfEHPass(TM));
389389 break;
390390 case ExceptionHandling::None:
391 addPass(createLowerInvokePass(TM->getTargetLowering()));
391 addPass(createLowerInvokePass());
392392
393393 // The lower invoke pass may create unreachable code. Remove it.
394394 addPass(createUnreachableBlockEliminationPass());
7070 ELFWriterInfo(*this),
7171 TLInfo(*this),
7272 TSInfo(*this),
73 FrameLowering(Subtarget) {
73 FrameLowering(Subtarget),
74 STTI(&TLInfo) {
7475 if (!Subtarget.hasARMOps())
7576 report_fatal_error("CPU: '" + Subtarget.getCPUString() + "' does not "
7677 "support ARM mode execution!");
103104 TSInfo(*this),
104105 FrameLowering(Subtarget.hasThumb2()
105106 ? new ARMFrameLowering(Subtarget)
106 : (ARMFrameLowering*)new Thumb1FrameLowering(Subtarget)) {
107 : (ARMFrameLowering*)new Thumb1FrameLowering(Subtarget)),
108 STTI(&TLInfo){
107109 }
108110
109111 namespace {
2424 #include "Thumb1FrameLowering.h"
2525 #include "Thumb2InstrInfo.h"
2626 #include "llvm/Target/TargetMachine.h"
27 #include "llvm/Target/TargetTransformImpl.h"
2728 #include "llvm/DataLayout.h"
2829 #include "llvm/MC/MCStreamer.h"
2930 #include "llvm/ADT/OwningPtr.h"
6667 ARMTargetLowering TLInfo;
6768 ARMSelectionDAGInfo TSInfo;
6869 ARMFrameLowering FrameLowering;
70 ScalarTargetTransformImpl STTI;
71 VectorTargetTransformImpl VTTI;
6972 public:
7073 ARMTargetMachine(const Target &T, StringRef TT,
7174 StringRef CPU, StringRef FS,
8790 virtual const ARMFrameLowering *getFrameLowering() const {
8891 return &FrameLowering;
8992 }
90
93 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
94 return &STTI;
95 }
96 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
97 return &VTTI;
98 }
9199 virtual const ARMInstrInfo *getInstrInfo() const { return &InstrInfo; }
92100 virtual const DataLayout *getDataLayout() const { return &DL; }
93101 virtual const ARMELFWriterInfo *getELFWriterInfo() const {
109117 ARMSelectionDAGInfo TSInfo;
110118 // Either Thumb1FrameLowering or ARMFrameLowering.
111119 OwningPtr FrameLowering;
120 ScalarTargetTransformImpl STTI;
121 VectorTargetTransformImpl VTTI;
112122 public:
113123 ThumbTargetMachine(const Target &T, StringRef TT,
114124 StringRef CPU, StringRef FS,
137147 virtual const ARMFrameLowering *getFrameLowering() const {
138148 return FrameLowering.get();
139149 }
150 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
151 return &STTI;
152 }
153 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
154 return &VTTI;
155 }
140156 virtual const DataLayout *getDataLayout() const { return &DL; }
141157 virtual const ARMELFWriterInfo *getELFWriterInfo() const {
142158 return Subtarget.isTargetELF() ? &ELFWriterInfo : 0;
1010 TargetMachineC.cpp
1111 TargetRegisterInfo.cpp
1212 TargetSubtargetInfo.cpp
13 TargetTransformImpl.cpp
1314 )
1415
1516 foreach(t ${LLVM_TARGETS_TO_BUILD})
4242 FrameLowering(Subtarget),
4343 TLInfo(*this),
4444 TSInfo(*this),
45 InstrItins(Subtarget.getInstrItineraryData()) {
45 InstrItins(Subtarget.getInstrItineraryData()),
46 STTI(&TLInfo){
4647 }
4748
4849 //===----------------------------------------------------------------------===//
1919 #include "SPUSelectionDAGInfo.h"
2020 #include "SPUFrameLowering.h"
2121 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/Target/TargetTransformImpl.h"
2223 #include "llvm/DataLayout.h"
2324
2425 namespace llvm {
3334 SPUTargetLowering TLInfo;
3435 SPUSelectionDAGInfo TSInfo;
3536 InstrItineraryData InstrItins;
37 ScalarTargetTransformImpl STTI;
38 VectorTargetTransformImpl VTTI;
3639 public:
3740 SPUTargetMachine(const Target &T, StringRef TT,
3841 StringRef CPU, StringRef FS, const TargetOptions &Options,
7679 virtual const InstrItineraryData *getInstrItineraryData() const {
7780 return &InstrItins;
7881 }
82 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
83 return &STTI;
84 }
85 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
86 return &VTTI;
87 }
7988
8089 // Pass Pipeline Configuration
8190 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
7373 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
7474 TSInfo(*this),
7575 FrameLowering(Subtarget),
76 InstrItins(&Subtarget.getInstrItineraryData()) {
76 InstrItins(&Subtarget.getInstrItineraryData()),
77 STTI(&TLInfo) {
7778 setMCUseCFI(false);
7879 }
7980
8687 PM.add(createDeadCodeEliminationPass());
8788 PM.add(createConstantPropagationPass());
8889 PM.add(createLoopUnrollPass());
89 PM.add(createLoopStrengthReducePass(getTargetLowering()));
90 PM.add(createLoopStrengthReducePass());
9091 return true;
9192 }
9293
2020 #include "HexagonFrameLowering.h"
2121 #include "llvm/Target/TargetMachine.h"
2222 #include "llvm/DataLayout.h"
23 #include "llvm/Target/TargetTransformImpl.h"
2324
2425 namespace llvm {
2526
3334 HexagonSelectionDAGInfo TSInfo;
3435 HexagonFrameLowering FrameLowering;
3536 const InstrItineraryData* InstrItins;
37 ScalarTargetTransformImpl STTI;
38 VectorTargetTransformImpl VTTI;
3639
3740 public:
3841 HexagonTargetMachine(const Target &T, StringRef TT,StringRef CPU,
6770 return &TSInfo;
6871 }
6972
73 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
74 return &STTI;
75 }
76
77 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
78 return &VTTI;
79 }
80
7081 virtual const DataLayout *getDataLayout() const { return &DL; }
7182 static unsigned getModuleMatchQuality(const Module &M);
7283
4141 InstrInfo(*this),
4242 FrameLowering(Subtarget),
4343 TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this),
44 InstrItins(Subtarget.getInstrItineraryData()) {
44 InstrItins(Subtarget.getInstrItineraryData()), STTI(&TLInfo) {
4545 }
4646
4747 namespace {
2424 #include "llvm/Target/TargetMachine.h"
2525 #include "llvm/DataLayout.h"
2626 #include "llvm/Target/TargetFrameLowering.h"
27 #include "llvm/Target/TargetTransformImpl.h"
2728
2829 namespace llvm {
2930 class formatted_raw_ostream;
3839 MBlazeIntrinsicInfo IntrinsicInfo;
3940 MBlazeELFWriterInfo ELFWriterInfo;
4041 InstrItineraryData InstrItins;
42 ScalarTargetTransformImpl STTI;
43 VectorTargetTransformImpl VTTI;
4144
4245 public:
4346 MBlazeTargetMachine(const Target &T, StringRef TT,
7679 virtual const MBlazeELFWriterInfo *getELFWriterInfo() const {
7780 return &ELFWriterInfo;
7881 }
82 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const
83 { return &STTI; }
84 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const
85 { return &VTTI; }
7986
8087 // Pass Pipeline Configuration
8188 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
3535 // FIXME: Check DataLayout string.
3636 DL("e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"),
3737 InstrInfo(*this), TLInfo(*this), TSInfo(*this),
38 FrameLowering(Subtarget) { }
38 FrameLowering(Subtarget), STTI(&TLInfo) { }
3939
4040 namespace {
4141 /// MSP430 Code Generator Pass Configuration Options.
2323 #include "llvm/DataLayout.h"
2424 #include "llvm/Target/TargetFrameLowering.h"
2525 #include "llvm/Target/TargetMachine.h"
26 #include "llvm/Target/TargetTransformImpl.h"
2627
2728 namespace llvm {
2829
3536 MSP430TargetLowering TLInfo;
3637 MSP430SelectionDAGInfo TSInfo;
3738 MSP430FrameLowering FrameLowering;
39 ScalarTargetTransformImpl STTI;
40 VectorTargetTransformImpl VTTI;
3841
3942 public:
4043 MSP430TargetMachine(const Target &T, StringRef TT,
6063 virtual const MSP430SelectionDAGInfo* getSelectionDAGInfo() const {
6164 return &TSInfo;
6265 }
63
66 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
67 return &STTI;
68 }
69 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
70 return &VTTI;
71 }
6472 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
6573 }; // MSP430TargetMachine.
6674
5252 InstrInfo(MipsInstrInfo::create(*this)),
5353 FrameLowering(MipsFrameLowering::create(*this, Subtarget)),
5454 TLInfo(*this), TSInfo(*this), JITInfo(),
55 ELFWriterInfo(false, isLittle) {
55 ELFWriterInfo(false, isLittle), STTI(&TLInfo) {
5656 }
5757
5858 void MipsebTargetMachine::anchor() { }
2323 #include "llvm/Target/TargetMachine.h"
2424 #include "llvm/DataLayout.h"
2525 #include "llvm/Target/TargetFrameLowering.h"
26 #include "llvm/Target/TargetTransformImpl.h"
2627
2728 namespace llvm {
2829 class formatted_raw_ostream;
3738 MipsSelectionDAGInfo TSInfo;
3839 MipsJITInfo JITInfo;
3940 MipsELFWriterInfo ELFWriterInfo;
41 ScalarTargetTransformImpl STTI;
42 VectorTargetTransformImpl VTTI;
4043
4144 public:
4245 MipsTargetMachine(const Target &T, StringRef TT,
7171 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
7272 Subtarget(TT, CPU, FS, is64bit),
7373 DL(Subtarget.getDataLayout()),
74 InstrInfo(*this), TLInfo(*this), TSInfo(*this), FrameLowering(*this,is64bit)
74 InstrInfo(*this), TLInfo(*this), TSInfo(*this), FrameLowering(*this,is64bit),
75 STTI(&TLInfo)
7576 /*FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0)*/ {
7677 }
7778
2424 #include "llvm/Target/TargetFrameLowering.h"
2525 #include "llvm/Target/TargetMachine.h"
2626 #include "llvm/Target/TargetSelectionDAGInfo.h"
27 #include "llvm/Target/TargetTransformImpl.h"
2728
2829 namespace llvm {
2930
4243
4344 // Hold Strings that can be free'd all together with NVPTXTargetMachine
4445 ManagedStringPool ManagedStrPool;
46
47 ScalarTargetTransformImpl STTI;
48 VectorTargetTransformImpl VTTI;
4549
4650 //bool addCommonCodeGenPasses(PassManagerBase &, CodeGenOpt::Level,
4751 // bool DisableVerify, MCContext *&OutCtx);
7074
7175 virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const {
7276 return &TSInfo;
77 }
78 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
79 return &STTI;
80 }
81 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
82 return &VTTI;
7383 }
7484
7585 //virtual bool addInstSelector(PassManagerBase &PM,
4242 DL(Subtarget.getDataLayoutString()), InstrInfo(*this),
4343 FrameLowering(Subtarget), JITInfo(*this, is64Bit),
4444 TLInfo(*this), TSInfo(*this),
45 InstrItins(Subtarget.getInstrItineraryData()) {
45 InstrItins(Subtarget.getInstrItineraryData()),
46 STTI(&TLInfo){
4647
4748 // The binutils for the BG/P are too old for CFI.
4849 if (Subtarget.isBGP())
2020 #include "PPCISelLowering.h"
2121 #include "PPCSelectionDAGInfo.h"
2222 #include "llvm/Target/TargetMachine.h"
23 #include "llvm/Target/TargetTransformImpl.h"
2324 #include "llvm/DataLayout.h"
2425
2526 namespace llvm {
3536 PPCTargetLowering TLInfo;
3637 PPCSelectionDAGInfo TSInfo;
3738 InstrItineraryData InstrItins;
39 ScalarTargetTransformImpl STTI;
40 VectorTargetTransformImpl VTTI;
3841
3942 public:
4043 PPCTargetMachine(const Target &T, StringRef TT,
6164 virtual const PPCSubtarget *getSubtargetImpl() const { return &Subtarget; }
6265 virtual const InstrItineraryData *getInstrItineraryData() const {
6366 return &InstrItins;
67 }
68 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
69 return &STTI;
70 }
71 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
72 return &VTTI;
6473 }
6574
6675 // Pass Pipeline Configuration
3535 DL(Subtarget.getDataLayout()),
3636 InstrInfo(Subtarget),
3737 TLInfo(*this), TSInfo(*this),
38 FrameLowering(Subtarget) {
38 FrameLowering(Subtarget),STTI(&TLInfo) {
3939 }
4040
4141 namespace {
2121 #include "llvm/Target/TargetMachine.h"
2222 #include "llvm/DataLayout.h"
2323 #include "llvm/Target/TargetFrameLowering.h"
24 #include "llvm/Target/TargetTransformImpl.h"
2425
2526 namespace llvm {
2627
3132 SparcTargetLowering TLInfo;
3233 SparcSelectionDAGInfo TSInfo;
3334 SparcFrameLowering FrameLowering;
35 ScalarTargetTransformImpl STTI;
36 VectorTargetTransformImpl VTTI;
3437 public:
3538 SparcTargetMachine(const Target &T, StringRef TT,
3639 StringRef CPU, StringRef FS, const TargetOptions &Options,
5053 }
5154 virtual const SparcSelectionDAGInfo* getSelectionDAGInfo() const {
5255 return &TSInfo;
56 }
57 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
58 return &STTI;
59 }
60 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
61 return &VTTI;
5362 }
5463 virtual const DataLayout *getDataLayout() const { return &DL; }
5564
2525 void llvm::initializeTarget(PassRegistry &Registry) {
2626 initializeDataLayoutPass(Registry);
2727 initializeTargetLibraryInfoPass(Registry);
28 initializeTargetTransformInfoPass(Registry);
2829 }
2930
3031 void LLVMInitializeTarget(LLVMPassRegistryRef R) {
0 // llvm/Target/TargetTransformImpl.cpp - Target Loop Trans Info ---*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Target/TargetTransformImpl.h"
10 #include "llvm/Target/TargetLowering.h"
11
12 using namespace llvm;
13
14 bool ScalarTargetTransformImpl::isLegalAddImmediate(int64_t imm) const {
15 return TLI->isLegalAddImmediate(imm);
16 }
17
18 bool ScalarTargetTransformImpl::isLegalICmpImmediate(int64_t imm) const {
19 return TLI->isLegalICmpImmediate(imm);
20 }
21
22 bool ScalarTargetTransformImpl::isLegalAddressingMode(const AddrMode &AM,
23 Type *Ty) const {
24 return TLI->isLegalAddressingMode(AM, Ty);
25 }
26
27 bool ScalarTargetTransformImpl::isTruncateFree(Type *Ty1, Type *Ty2) const {
28 return TLI->isTruncateFree(Ty1, Ty2);
29 }
30
31 bool ScalarTargetTransformImpl::isTypeLegal(Type *Ty) const {
32 EVT T = TLI->getValueType(Ty);
33 return TLI->isTypeLegal(T);
34 }
35
36 unsigned ScalarTargetTransformImpl::getJumpBufAlignment() const {
37 return TLI->getJumpBufAlignment();
38 }
39
40 unsigned ScalarTargetTransformImpl::getJumpBufSize() const {
41 return TLI->getJumpBufSize();
42 }
4747 InstrInfo(*this),
4848 TSInfo(*this),
4949 TLInfo(*this),
50 JITInfo(*this) {
50 JITInfo(*this),
51 STTI(&TLInfo) {
5152 }
5253
5354 void X86_64TargetMachine::anchor() { }
6364 InstrInfo(*this),
6465 TSInfo(*this),
6566 TLInfo(*this),
66 JITInfo(*this) {
67 JITInfo(*this),
68 STTI(&TLInfo) {
6769 }
6870
6971 /// X86TargetMachine ctor - Create an X86 target.
2424 #include "llvm/Target/TargetMachine.h"
2525 #include "llvm/DataLayout.h"
2626 #include "llvm/Target/TargetFrameLowering.h"
27 #include "llvm/Target/TargetTransformImpl.h"
2728
2829 namespace llvm {
2930
8485 X86SelectionDAGInfo TSInfo;
8586 X86TargetLowering TLInfo;
8687 X86JITInfo JITInfo;
88 ScalarTargetTransformImpl STTI;
89 VectorTargetTransformImpl VTTI;
8790 public:
8891 X86_32TargetMachine(const Target &T, StringRef TT,
8992 StringRef CPU, StringRef FS, const TargetOptions &Options,
102105 virtual X86JITInfo *getJITInfo() {
103106 return &JITInfo;
104107 }
108 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
109 return &STTI;
110 }
111 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
112 return &VTTI;
113 }
105114 };
106115
107116 /// X86_64TargetMachine - X86 64-bit target machine.
113122 X86SelectionDAGInfo TSInfo;
114123 X86TargetLowering TLInfo;
115124 X86JITInfo JITInfo;
125 ScalarTargetTransformImpl STTI;
126 VectorTargetTransformImpl VTTI;
116127 public:
117128 X86_64TargetMachine(const Target &T, StringRef TT,
118129 StringRef CPU, StringRef FS, const TargetOptions &Options,
131142 virtual X86JITInfo *getJITInfo() {
132143 return &JITInfo;
133144 }
145 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
146 return &STTI;
147 }
148 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
149 return &VTTI;
150 }
134151 };
135152
136153 } // End llvm namespace
3131 InstrInfo(),
3232 FrameLowering(Subtarget),
3333 TLInfo(*this),
34 TSInfo(*this) {
34 TSInfo(*this), STTI(&TLInfo) {
3535 }
3636
3737 namespace {
1919 #include "XCoreISelLowering.h"
2020 #include "XCoreSelectionDAGInfo.h"
2121 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/Target/TargetTransformImpl.h"
2223 #include "llvm/DataLayout.h"
2324
2425 namespace llvm {
3031 XCoreFrameLowering FrameLowering;
3132 XCoreTargetLowering TLInfo;
3233 XCoreSelectionDAGInfo TSInfo;
34 ScalarTargetTransformImpl STTI;
35 VectorTargetTransformImpl VTTI;
3336 public:
3437 XCoreTargetMachine(const Target &T, StringRef TT,
3538 StringRef CPU, StringRef FS, const TargetOptions &Options,
5255 virtual const TargetRegisterInfo *getRegisterInfo() const {
5356 return &InstrInfo.getRegisterInfo();
5457 }
58 virtual const ScalarTargetTransformInfo *getScalarTargetTransformInfo()const {
59 return &STTI;
60 }
61 virtual const VectorTargetTransformInfo *getVectorTargetTransformInfo()const {
62 return &VTTI;
63 }
5564 virtual const DataLayout *getDataLayout() const { return &DL; }
5665
5766 // Pass Pipeline Configuration
3636 //
3737 // TODO: Handle multiple loops at a time.
3838 //
39 // TODO: Should TargetLowering::AddrMode::BaseGV be changed to a ConstantExpr
39 // TODO: Should AddrMode::BaseGV be changed to a ConstantExpr
4040 // instead of a GlobalValue?
4141 //
4242 // TODO: When truncation is free, truncate ICmp users' operands to make it a
6666 #include "llvm/Transforms/Scalar.h"
6767 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
6868 #include "llvm/Transforms/Utils/Local.h"
69 #include "llvm/TargetTransformInfo.h"
6970 #include "llvm/ADT/SmallBitVector.h"
7071 #include "llvm/ADT/SetVector.h"
7172 #include "llvm/ADT/DenseSet.h"
7374 #include "llvm/Support/CommandLine.h"
7475 #include "llvm/Support/ValueHandle.h"
7576 #include "llvm/Support/raw_ostream.h"
76 #include "llvm/Target/TargetLowering.h"
7777 #include
7878 using namespace llvm;
7979
11171117 enum KindType {
11181118 Basic, ///< A normal use, with no folding.
11191119 Special, ///< A special case of basic, allowing -1 scales.
1120 Address, ///< An address use; folding according to TargetLowering
1120 Address, ///< An address use; folding according to ScalarTargetTransformInfo.
11211121 ICmpZero ///< An equality icmp with both operands folded into one.
11221122 // TODO: Add a generic icmp too?
11231123 };
12711271 /// address-mode folding and special icmp tricks.
12721272 static bool isLegalUse(const AddrMode &AM,
12731273 LSRUse::KindType Kind, Type *AccessTy,
1274 const TargetLowering *TLI) {
1274 const ScalarTargetTransformInfo *STTI) {
12751275 switch (Kind) {
12761276 case LSRUse::Address:
12771277 // If we have low-level target information, ask the target if it can
12781278 // completely fold this address.
1279 if (TLI) return TLI->isLegalAddressingMode(AM, AccessTy);
1279 if (STTI) return STTI->isLegalAddressingMode(AM, AccessTy);
12801280
12811281 // Otherwise, just guess that reg+reg addressing is legal.
12821282 return !AM.BaseGV && AM.BaseOffs == 0 && AM.Scale <= 1;
12991299 // If we have low-level target information, ask the target if it can fold an
13001300 // integer immediate on an icmp.
13011301 if (AM.BaseOffs != 0) {
1302 if (!TLI)
1302 if (!STTI)
13031303 return false;
13041304 // We have one of:
13051305 // ICmpZero BaseReg + Offset => ICmp BaseReg, -Offset
13081308 int64_t Offs = AM.BaseOffs;
13091309 if (AM.Scale == 0)
13101310 Offs = -(uint64_t)Offs; // The cast does the right thing with INT64_MIN.
1311 return TLI->isLegalICmpImmediate(Offs);
1311 return STTI->isLegalICmpImmediate(Offs);
13121312 }
13131313
13141314 // ICmpZero BaseReg + -1*ScaleReg => ICmp BaseReg, ScaleReg
13291329 static bool isLegalUse(AddrMode AM,
13301330 int64_t MinOffset, int64_t MaxOffset,
13311331 LSRUse::KindType Kind, Type *AccessTy,
1332 const TargetLowering *TLI) {
1332 const ScalarTargetTransformInfo *LTTI) {
13331333 // Check for overflow.
13341334 if (((int64_t)((uint64_t)AM.BaseOffs + MinOffset) > AM.BaseOffs) !=
13351335 (MinOffset > 0))
13361336 return false;
13371337 AM.BaseOffs = (uint64_t)AM.BaseOffs + MinOffset;
1338 if (isLegalUse(AM, Kind, AccessTy, TLI)) {
1338 if (isLegalUse(AM, Kind, AccessTy, LTTI)) {
13391339 AM.BaseOffs = (uint64_t)AM.BaseOffs - MinOffset;
13401340 // Check for overflow.
13411341 if (((int64_t)((uint64_t)AM.BaseOffs + MaxOffset) > AM.BaseOffs) !=
13421342 (MaxOffset > 0))
13431343 return false;
13441344 AM.BaseOffs = (uint64_t)AM.BaseOffs + MaxOffset;
1345 return isLegalUse(AM, Kind, AccessTy, TLI);
1345 return isLegalUse(AM, Kind, AccessTy, LTTI);
13461346 }
13471347 return false;
13481348 }
13511351 GlobalValue *BaseGV,
13521352 bool HasBaseReg,
13531353 LSRUse::KindType Kind, Type *AccessTy,
1354 const TargetLowering *TLI) {
1354 const ScalarTargetTransformInfo *LTTI) {
13551355 // Fast-path: zero is always foldable.
13561356 if (BaseOffs == 0 && !BaseGV) return true;
13571357
13701370 AM.HasBaseReg = true;
13711371 }
13721372
1373 return isLegalUse(AM, Kind, AccessTy, TLI);
1373 return isLegalUse(AM, Kind, AccessTy, LTTI);
13741374 }
13751375
13761376 static bool isAlwaysFoldable(const SCEV *S,
13771377 int64_t MinOffset, int64_t MaxOffset,
13781378 bool HasBaseReg,
13791379 LSRUse::KindType Kind, Type *AccessTy,
1380 const TargetLowering *TLI,
1380 const ScalarTargetTransformInfo *LTTI,
13811381 ScalarEvolution &SE) {
13821382 // Fast-path: zero is always foldable.
13831383 if (S->isZero()) return true;
14011401 AM.HasBaseReg = HasBaseReg;
14021402 AM.Scale = Kind == LSRUse::ICmpZero ? -1 : 1;
14031403
1404 return isLegalUse(AM, MinOffset, MaxOffset, Kind, AccessTy, TLI);
1404 return isLegalUse(AM, MinOffset, MaxOffset, Kind, AccessTy, LTTI);
14051405 }
14061406
14071407 namespace {
15011501 ScalarEvolution &SE;
15021502 DominatorTree &DT;
15031503 LoopInfo &LI;
1504 const TargetLowering *const TLI;
1504 const ScalarTargetTransformInfo *const STTI;
15051505 Loop *const L;
15061506 bool Changed;
15071507
16371637 Pass *P);
16381638
16391639 public:
1640 LSRInstance(const TargetLowering *tli, Loop *l, Pass *P);
1640 LSRInstance(const ScalarTargetTransformInfo *ltti, Loop *l, Pass *P);
16411641
16421642 bool getChanged() const { return Changed; }
16431643
16871687 }
16881688 if (!DestTy) continue;
16891689
1690 if (TLI) {
1690 if (STTI) {
16911691 // If target does not support DestTy natively then do not apply
16921692 // this transformation.
1693 EVT DVT = TLI->getValueType(DestTy);
1694 if (!TLI->isTypeLegal(DVT)) continue;
1693 if (!STTI->isTypeLegal(DestTy)) continue;
16951694 }
16961695
16971696 PHINode *PH = dyn_cast(ShadowUse->getOperand(0));
20142013 if (C->getValue().getMinSignedBits() >= 64 ||
20152014 C->getValue().isMinSignedValue())
20162015 goto decline_post_inc;
2017 // Without TLI, assume that any stride might be valid, and so any
2016 // Without STTI, assume that any stride might be valid, and so any
20182017 // use might be shared.
2019 if (!TLI)
2018 if (!STTI)
20202019 goto decline_post_inc;
20212020 // Check for possible scaled-address reuse.
20222021 Type *AccessTy = getAccessType(UI->getUser());
20232022 AddrMode AM;
20242023 AM.Scale = C->getSExtValue();
2025 if (TLI->isLegalAddressingMode(AM, AccessTy))
2024 if (STTI->isLegalAddressingMode(AM, AccessTy))
20262025 goto decline_post_inc;
20272026 AM.Scale = -AM.Scale;
2028 if (TLI->isLegalAddressingMode(AM, AccessTy))
2027 if (STTI->isLegalAddressingMode(AM, AccessTy))
20292028 goto decline_post_inc;
20302029 }
20312030 }
20962095 // Conservatively assume HasBaseReg is true for now.
20972096 if (NewOffset < LU.MinOffset) {
20982097 if (!isAlwaysFoldable(LU.MaxOffset - NewOffset, 0, HasBaseReg,
2099 Kind, AccessTy, TLI))
2098 Kind, AccessTy, STTI))
21002099 return false;
21012100 NewMinOffset = NewOffset;
21022101 } else if (NewOffset > LU.MaxOffset) {
21032102 if (!isAlwaysFoldable(NewOffset - LU.MinOffset, 0, HasBaseReg,
2104 Kind, AccessTy, TLI))
2103 Kind, AccessTy, STTI))
21052104 return false;
21062105 NewMaxOffset = NewOffset;
21072106 }
21302129 int64_t Offset = ExtractImmediate(Expr, SE);
21312130
21322131 // Basic uses can't accept any offset, for example.
2133 if (!isAlwaysFoldable(Offset, 0, /*HasBaseReg=*/true, Kind, AccessTy, TLI)) {
2132 if (!isAlwaysFoldable(Offset, 0, /*HasBaseReg=*/true, Kind, AccessTy, STTI)) {
21342133 Expr = Copy;
21352134 Offset = 0;
21362135 }
23952394 /// TODO: Consider IVInc free if it's already used in another chains.
23962395 static bool
23972396 isProfitableChain(IVChain &Chain, SmallPtrSet &Users,
2398 ScalarEvolution &SE, const TargetLowering *TLI) {
2397 ScalarEvolution &SE, const ScalarTargetTransformInfo *STTI) {
23992398 if (StressIVChain)
24002399 return true;
24012400
26532652 for (unsigned UsersIdx = 0, NChains = IVChainVec.size();
26542653 UsersIdx < NChains; ++UsersIdx) {
26552654 if (!isProfitableChain(IVChainVec[UsersIdx],
2656 ChainUsersVec[UsersIdx].FarUsers, SE, TLI))
2655 ChainUsersVec[UsersIdx].FarUsers, SE, STTI))
26572656 continue;
26582657 // Preserve the chain at UsesIdx.
26592658 if (ChainIdx != UsersIdx)
26802679
26812680 /// Return true if the IVInc can be folded into an addressing mode.
26822681 static bool canFoldIVIncExpr(const SCEV *IncExpr, Instruction *UserInst,
2683 Value *Operand, const TargetLowering *TLI) {
2682 Value *Operand,
2683 const ScalarTargetTransformInfo *STTI) {
26842684 const SCEVConstant *IncConst = dyn_cast(IncExpr);
26852685 if (!IncConst || !isAddressUse(UserInst, Operand))
26862686 return false;
26902690
26912691 int64_t IncOffset = IncConst->getValue()->getSExtValue();
26922692 if (!isAlwaysFoldable(IncOffset, /*BaseGV=*/0, /*HaseBaseReg=*/false,
2693 LSRUse::Address, getAccessType(UserInst), TLI))
2693 LSRUse::Address, getAccessType(UserInst), STTI))
26942694 return false;
26952695
26962696 return true;
27612761
27622762 // If an IV increment can't be folded, use it as the next IV value.
27632763 if (!canFoldIVIncExpr(LeftOverExpr, IncI->UserInst, IncI->IVOperand,
2764 TLI)) {
2764 STTI)) {
27652765 assert(IVTy == IVOper->getType() && "inconsistent IV increment type");
27662766 IVSrc = IVOper;
27672767 LeftOverExpr = 0;
31073107 // into an immediate field.
31083108 if (isAlwaysFoldable(*J, LU.MinOffset, LU.MaxOffset,
31093109 Base.getNumRegs() > 1,
3110 LU.Kind, LU.AccessTy, TLI, SE))
3110 LU.Kind, LU.AccessTy, STTI, SE))
31113111 continue;
31123112
31133113 // Collect all operands except *J.
31213121 if (InnerAddOps.size() == 1 &&
31223122 isAlwaysFoldable(InnerAddOps[0], LU.MinOffset, LU.MaxOffset,
31233123 Base.getNumRegs() > 1,
3124 LU.Kind, LU.AccessTy, TLI, SE))
3124 LU.Kind, LU.AccessTy, STTI, SE))
31253125 continue;
31263126
31273127 const SCEV *InnerSum = SE.getAddExpr(InnerAddOps);
31313131
31323132 // Add the remaining pieces of the add back into the new formula.
31333133 const SCEVConstant *InnerSumSC = dyn_cast(InnerSum);
3134 if (TLI && InnerSumSC &&
3134 if (STTI && InnerSumSC &&
31353135 SE.getTypeSizeInBits(InnerSumSC->getType()) <= 64 &&
3136 TLI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
3136 STTI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
31373137 InnerSumSC->getValue()->getZExtValue())) {
31383138 F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset +
31393139 InnerSumSC->getValue()->getZExtValue();
31433143
31443144 // Add J as its own register, or an unfolded immediate.
31453145 const SCEVConstant *SC = dyn_cast(*J);
3146 if (TLI && SC && SE.getTypeSizeInBits(SC->getType()) <= 64 &&
3147 TLI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
3146 if (STTI && SC && SE.getTypeSizeInBits(SC->getType()) <= 64 &&
3147 STTI->isLegalAddImmediate((uint64_t)F.UnfoldedOffset +
31483148 SC->getValue()->getZExtValue()))
31493149 F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset +
31503150 SC->getValue()->getZExtValue();
32043204 Formula F = Base;
32053205 F.AM.BaseGV = GV;
32063206 if (!isLegalUse(F.AM, LU.MinOffset, LU.MaxOffset,
3207 LU.Kind, LU.AccessTy, TLI))
3207 LU.Kind, LU.AccessTy, STTI))
32083208 continue;
32093209 F.BaseRegs[i] = G;
32103210 (void)InsertFormula(LU, LUIdx, F);
32293229 Formula F = Base;
32303230 F.AM.BaseOffs = (uint64_t)Base.AM.BaseOffs - *I;
32313231 if (isLegalUse(F.AM, LU.MinOffset - *I, LU.MaxOffset - *I,
3232 LU.Kind, LU.AccessTy, TLI)) {
3232 LU.Kind, LU.AccessTy, STTI)) {
32333233 // Add the offset to the base register.
32343234 const SCEV *NewG = SE.getAddExpr(SE.getConstant(G->getType(), *I), G);
32353235 // If it cancelled out, drop the base register, otherwise update it.
32493249 Formula F = Base;
32503250 F.AM.BaseOffs = (uint64_t)F.AM.BaseOffs + Imm;
32513251 if (!isLegalUse(F.AM, LU.MinOffset, LU.MaxOffset,
3252 LU.Kind, LU.AccessTy, TLI))
3252 LU.Kind, LU.AccessTy, STTI))
32533253 continue;
32543254 F.BaseRegs[i] = G;
32553255 (void)InsertFormula(LU, LUIdx, F);
32963296 F.AM.BaseOffs = NewBaseOffs;
32973297
32983298 // Check that this scale is legal.
3299 if (!isLegalUse(F.AM, Offset, Offset, LU.Kind, LU.AccessTy, TLI))
3299 if (!isLegalUse(F.AM, Offset, Offset, LU.Kind, LU.AccessTy, STTI))
33003300 continue;
33013301
33023302 // Compensate for the use having MinOffset built into it.
33523352 Base.AM.HasBaseReg = Base.BaseRegs.size() > 1;
33533353 // Check whether this scale is going to be legal.
33543354 if (!isLegalUse(Base.AM, LU.MinOffset, LU.MaxOffset,
3355 LU.Kind, LU.AccessTy, TLI)) {
3355 LU.Kind, LU.AccessTy, STTI)) {
33563356 // As a special-case, handle special out-of-loop Basic users specially.
33573357 // TODO: Reconsider this special case.
33583358 if (LU.Kind == LSRUse::Basic &&
33593359 isLegalUse(Base.AM, LU.MinOffset, LU.MaxOffset,
3360 LSRUse::Special, LU.AccessTy, TLI) &&
3360 LSRUse::Special, LU.AccessTy, STTI) &&
33613361 LU.AllFixupsOutsideLoop)
33623362 LU.Kind = LSRUse::Special;
33633363 else
33903390
33913391 /// GenerateTruncates - Generate reuse formulae from different IV types.
33923392 void LSRInstance::GenerateTruncates(LSRUse &LU, unsigned LUIdx, Formula Base) {
3393 // This requires TargetLowering to tell us which truncates are free.
3394 if (!TLI) return;
3393 // This requires ScalarTargetTransformInfo to tell us which truncates are free.
3394 if (!STTI) return;
33953395
33963396 // Don't bother truncating symbolic values.
33973397 if (Base.AM.BaseGV) return;
34043404 for (SmallSetVector::const_iterator
34053405 I = Types.begin(), E = Types.end(); I != E; ++I) {
34063406 Type *SrcTy = *I;
3407 if (SrcTy != DstTy && TLI->isTruncateFree(SrcTy, DstTy)) {
3407 if (SrcTy != DstTy && STTI->isTruncateFree(SrcTy, DstTy)) {
34083408 Formula F = Base;
34093409
34103410 if (F.ScaledReg) F.ScaledReg = SE.getAnyExtendExpr(F.ScaledReg, *I);
35603560 Formula NewF = F;
35613561 NewF.AM.BaseOffs = Offs;
35623562 if (!isLegalUse(NewF.AM, LU.MinOffset, LU.MaxOffset,
3563 LU.Kind, LU.AccessTy, TLI))
3563 LU.Kind, LU.AccessTy, STTI))
35643564 continue;
35653565 NewF.ScaledReg = SE.getAddExpr(NegImmS, NewF.ScaledReg);
35663566
35853585 Formula NewF = F;
35863586 NewF.AM.BaseOffs = (uint64_t)NewF.AM.BaseOffs + Imm;
35873587 if (!isLegalUse(NewF.AM, LU.MinOffset, LU.MaxOffset,
3588 LU.Kind, LU.AccessTy, TLI)) {
3589 if (!TLI ||
3590 !TLI->isLegalAddImmediate((uint64_t)NewF.UnfoldedOffset + Imm))
3588 LU.Kind, LU.AccessTy, STTI)) {
3589 if (!STTI ||
3590 !STTI->isLegalAddImmediate((uint64_t)NewF.UnfoldedOffset + Imm))
35913591 continue;
35923592 NewF = F;
35933593 NewF.UnfoldedOffset = (uint64_t)NewF.UnfoldedOffset + Imm;
38993899 Formula &F = LUThatHas->Formulae[i];
39003900 if (!isLegalUse(F.AM,
39013901 LUThatHas->MinOffset, LUThatHas->MaxOffset,
3902 LUThatHas->Kind, LUThatHas->AccessTy, TLI)) {
3902 LUThatHas->Kind, LUThatHas->AccessTy, STTI)) {
39033903 DEBUG(dbgs() << " Deleting "; F.print(dbgs());
39043904 dbgs() << '\n');
39053905 LUThatHas->DeleteFormula(F);
45884588 Changed |= DeleteTriviallyDeadInstructions(DeadInsts);
45894589 }
45904590
4591 LSRInstance::LSRInstance(const TargetLowering *tli, Loop *l, Pass *P)
4591 LSRInstance::LSRInstance(const ScalarTargetTransformInfo *stti, Loop *l, Pass *P)
45924592 : IU(P->getAnalysis()),
45934593 SE(P->getAnalysis()),
45944594 DT(P->getAnalysis()),
45954595 LI(P->getAnalysis()),
4596 TLI(tli), L(l), Changed(false), IVIncInsertPos(0) {
4596 STTI(stti), L(l), Changed(false), IVIncInsertPos(0) {
45974597
45984598 // If LoopSimplify form is not available, stay out of trouble.
45994599 if (!L->isLoopSimplifyForm())
46834683 for (SmallVectorImpl::const_iterator J = LU.Formulae.begin(),
46844684 JE = LU.Formulae.end(); J != JE; ++J)
46854685 assert(isLegalUse(J->AM, LU.MinOffset, LU.MaxOffset,
4686 LU.Kind, LU.AccessTy, TLI) &&
4686 LU.Kind, LU.AccessTy, STTI) &&
46874687 "Illegal formula generated!");
46884688 };
46894689 #endif
47564756 namespace {
47574757
47584758 class LoopStrengthReduce : public LoopPass {
4759 /// TLI - Keep a pointer of a TargetLowering to consult for determining
4760 /// transformation profitability.
4761 const TargetLowering *const TLI;
4759 /// ScalarTargetTransformInfo provides target information that is needed
4760 /// for strength reducing loops.
4761 const ScalarTargetTransformInfo *STTI;
47624762
47634763 public:
47644764 static char ID; // Pass ID, replacement for typeid
4765 explicit LoopStrengthReduce(const TargetLowering *tli = 0);
4765 LoopStrengthReduce();
47664766
47674767 private:
47684768 bool runOnLoop(Loop *L, LPPassManager &LPM);
47824782 INITIALIZE_PASS_END(LoopStrengthReduce, "loop-reduce",
47834783 "Loop Strength Reduction", false, false)
47844784
4785
4786 Pass *llvm::createLoopStrengthReducePass(const TargetLowering *TLI) {
4787 return new LoopStrengthReduce(TLI);
4788 }
4789
4790 LoopStrengthReduce::LoopStrengthReduce(const TargetLowering *tli)
4791 : LoopPass(ID), TLI(tli) {
4785 Pass *llvm::createLoopStrengthReducePass() {
4786 return new LoopStrengthReduce();
4787 }
4788
4789 LoopStrengthReduce::LoopStrengthReduce()
4790 : LoopPass(ID), STTI(0) {
47924791 initializeLoopStrengthReducePass(*PassRegistry::getPassRegistry());
47934792 }
47944793
48144813 bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager & /*LPM*/) {
48154814 bool Changed = false;
48164815
4816 TargetTransformInfo *TTI = getAnalysisIfAvailable();
4817
4818 if (TTI)
4819 STTI = TTI->getScalarTargetTransformInfo();
4820
48174821 // Run the main LSR transformation.
4818 Changed |= LSRInstance(TLI, L, this).getChanged();
4822 Changed |= LSRInstance(STTI, L, this).getChanged();
48194823
48204824 // Remove any extra phis created by processing inner loops.
48214825 Changed |= DeleteDeadPHIs(L->getHeader());
48264830 Rewriter.setDebugType(DEBUG_TYPE);
48274831 #endif
48284832 unsigned numFolded = Rewriter.
4829 replaceCongruentIVs(L, &getAnalysis(), DeadInsts, TLI);
4833 replaceCongruentIVs(L, &getAnalysis(), DeadInsts, STTI);
48304834 if (numFolded) {
48314835 Changed = true;
48324836 DeleteTriviallyDeadInstructions(DeadInsts);
4444 #include "llvm/Pass.h"
4545 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
4646 #include "llvm/Transforms/Utils/Local.h"
47 #include "llvm/TargetTransformInfo.h"
4748 #include "llvm/ADT/SmallVector.h"
4849 #include "llvm/ADT/Statistic.h"
4950 #include "llvm/Support/CommandLine.h"
50 #include "llvm/Target/TargetLowering.h"
5151 #include
5252 #include
5353 using namespace llvm;
6969 Constant *SetJmpFn, *LongJmpFn, *StackSaveFn, *StackRestoreFn;
7070 bool useExpensiveEHSupport;
7171
72 // We peek in TLI to grab the target's jmp_buf size and alignment
73 const TargetLowering *TLI;
72 // We peek in STTI to grab the target's jmp_buf size and alignment
73 const ScalarTargetTransformInfo *STTI;
7474
7575 public:
7676 static char ID; // Pass identification, replacement for typeid
77 explicit LowerInvoke(const TargetLowering *tli = NULL,
78 bool useExpensiveEHSupport = ExpensiveEHSupport)
77 explicit LowerInvoke(bool useExpensiveEHSupport = ExpensiveEHSupport)
7978 : FunctionPass(ID), useExpensiveEHSupport(useExpensiveEHSupport),
80 TLI(tli) {
79 STTI(0) {
8180 initializeLowerInvokePass(*PassRegistry::getPassRegistry());
8281 }
8382 bool doInitialization(Module &M);
107106 char &llvm::LowerInvokePassID = LowerInvoke::ID;
108107
109108 // Public Interface To the LowerInvoke pass.
110 FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) {
111 return new LowerInvoke(TLI, ExpensiveEHSupport);
112 }
113 FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI,
114 bool useExpensiveEHSupport) {
115 return new LowerInvoke(TLI, useExpensiveEHSupport);
109 FunctionPass *llvm::createLowerInvokePass() {
110 return new LowerInvoke(ExpensiveEHSupport);
111 }
112 FunctionPass *llvm::createLowerInvokePass(bool useExpensiveEHSupport) {
113 return new LowerInvoke(useExpensiveEHSupport);
116114 }
117115
118116 // doInitialization - Make sure that there is a prototype for abort in the
119117 // current module.
120118 bool LowerInvoke::doInitialization(Module &M) {
119 TargetTransformInfo *TTI = getAnalysisIfAvailable();
120 if (TTI)
121 STTI = TTI->getScalarTargetTransformInfo();
122
121123 Type *VoidPtrTy = Type::getInt8PtrTy(M.getContext());
122124 if (useExpensiveEHSupport) {
123125 // Insert a type for the linked list of jump buffers.
124 unsigned JBSize = TLI ? TLI->getJumpBufSize() : 0;
126 unsigned JBSize = STTI ? STTI->getJumpBufSize() : 0;
125127 JBSize = JBSize ? JBSize : 200;
126128 Type *JmpBufTy = ArrayType::get(VoidPtrTy, JBSize);
127129
429431 // Create an alloca for the incoming jump buffer ptr and the new jump buffer
430432 // that needs to be restored on all exits from the function. This is an
431433 // alloca because the value needs to be live across invokes.
432 unsigned Align = TLI ? TLI->getJumpBufAlignment() : 0;
434 unsigned Align = STTI ? STTI->getJumpBufAlignment() : 0;
433435 AllocaInst *JmpBuf =
434436 new AllocaInst(JBLinkTy, 0, Align,
435437 "jblink", F.begin()->begin());
574576 }
575577
576578 bool LowerInvoke::runOnFunction(Function &F) {
579 TargetTransformInfo *TTI = getAnalysisIfAvailable();
580 if (TTI)
581 STTI = TTI->getScalarTargetTransformInfo();
582
577583 if (useExpensiveEHSupport)
578584 return insertExpensiveEHSupport(F);
579585 else
3232 PrintModulePass.cpp
3333 Type.cpp
3434 TypeFinder.cpp
35 TargetTransformInfo.cpp
3536 Use.cpp
3637 User.cpp
3738 Value.cpp
0 //===- llvm/VMCore/TargetTransformInfo.cpp ----------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/TargetTransformInfo.h"
10 #include "llvm/Support/ErrorHandling.h"
11
12 using namespace llvm;
13
14 /// Default ctor.
15 ///
16 /// @note This has to exist, because this is a pass, but it should never be
17 /// used.
18 TargetTransformInfo::TargetTransformInfo() : ImmutablePass(ID) {
19 report_fatal_error("Bad TargetTransformInfo ctor used. "
20 "Tool did not specify a TargetTransformInfo to use?");
21 }
22
23 INITIALIZE_PASS(TargetTransformInfo, "TargetTransformInfo",
24 "Target Transform Info", false, true)
25 char TargetTransformInfo::ID = 0;
26
2020 #include "llvm/ADT/Triple.h"
2121 #include "llvm/Assembly/PrintModulePass.h"
2222 #include "llvm/Support/IRReader.h"
23 #include "llvm/CodeGen/CommandFlags.h"
2324 #include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
2425 #include "llvm/CodeGen/LinkAllCodegenComponents.h"
2526 #include "llvm/MC/SubtargetFeature.h"
6162 static cl::opt
6263 TargetTriple("mtriple", cl::desc("Override target triple for module"));
6364
64 static cl::opt
65 MArch("march", cl::desc("Architecture to generate code for (see --version)"));
66
67 static cl::opt
68 MCPU("mcpu",
69 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
70 cl::value_desc("cpu-name"),
71 cl::init(""));
72
73 static cl::list
74 MAttrs("mattr",
75 cl::CommaSeparated,
76 cl::desc("Target specific attributes (-mattr=help for details)"),
77 cl::value_desc("a1,+a2,-a3,..."));
78
79 static cl::opt
80 RelocModel("relocation-model",
81 cl::desc("Choose relocation model"),
82 cl::init(Reloc::Default),
83 cl::values(
84 clEnumValN(Reloc::Default, "default",
85 "Target default relocation model"),
86 clEnumValN(Reloc::Static, "static",
87 "Non-relocatable code"),
88 clEnumValN(Reloc::PIC_, "pic",
89 "Fully relocatable, position independent code"),
90 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
91 "Relocatable external references, non-relocatable code"),
92 clEnumValEnd));
93
94 static cl::opt
95 CMModel("code-model",
96 cl::desc("Choose code model"),
97 cl::init(CodeModel::Default),
98 cl::values(clEnumValN(CodeModel::Default, "default",
99 "Target default code model"),
100 clEnumValN(CodeModel::Small, "small",
101 "Small code model"),
102 clEnumValN(CodeModel::Kernel, "kernel",
103 "Kernel code model"),
104 clEnumValN(CodeModel::Medium, "medium",
105 "Medium code model"),
106 clEnumValN(CodeModel::Large, "large",
107 "Large code model"),
108 clEnumValEnd));
109
110 static cl::opt
111 RelaxAll("mc-relax-all",
112 cl::desc("When used with filetype=obj, "
113 "relax all fixups in the emitted object file"));
114
115 cl::opt
116 FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
117 cl::desc("Choose a file type (not all types are supported by all targets):"),
118 cl::values(
119 clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
120 "Emit an assembly ('.s') file"),
121 clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
122 "Emit a native object ('.o') file"),
123 clEnumValN(TargetMachine::CGFT_Null, "null",
124 "Emit nothing, for performance testing"),
125 clEnumValEnd));
126
12765 cl::opt NoVerify("disable-verify", cl::Hidden,
12866 cl::desc("Do not verify input module"));
12967
130 cl::opt DisableDotLoc("disable-dot-loc", cl::Hidden,
131 cl::desc("Do not use .loc entries"));
132
133 cl::opt DisableCFI("disable-cfi", cl::Hidden,
134 cl::desc("Do not use .cfi_* directives"));
135
136 cl::opt EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden,
137 cl::desc("Use .file directives with an explicit directory."));
138
139 static cl::opt
140 DisableRedZone("disable-red-zone",
141 cl::desc("Do not emit code that uses the red zone."),
142 cl::init(false));
143
144 static cl::opt
145 EnableFPMAD("enable-fp-mad",
146 cl::desc("Enable less precise MAD instructions to be generated"),
147 cl::init(false));
148
149 static cl::opt
150 DisableFPElim("disable-fp-elim",
151 cl::desc("Disable frame pointer elimination optimization"),
152 cl::init(false));
153
154 static cl::opt
155 DisableFPElimNonLeaf("disable-non-leaf-fp-elim",
156 cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"),
157 cl::init(false));
158
159 static cl::opt
160 EnableUnsafeFPMath("enable-unsafe-fp-math",
161 cl::desc("Enable optimizations that may decrease FP precision"),
162 cl::init(false));
163
164 static cl::opt
165 EnableNoInfsFPMath("enable-no-infs-fp-math",
166 cl::desc("Enable FP math optimizations that assume no +-Infs"),
167 cl::init(false));
168
169 static cl::opt
170 EnableNoNaNsFPMath("enable-no-nans-fp-math",
171 cl::desc("Enable FP math optimizations that assume no NaNs"),
172 cl::init(false));
173
174 static cl::opt
175 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
176 cl::Hidden,
177 cl::desc("Force codegen to assume rounding mode can change dynamically"),
178 cl::init(false));
179
180 static cl::opt
181 GenerateSoftFloatCalls("soft-float",
182 cl::desc("Generate software floating point library calls"),
183 cl::init(false));
184
185 static cl::opt
186 FloatABIForCalls("float-abi",
187 cl::desc("Choose float ABI type"),
188 cl::init(FloatABI::Default),
189 cl::values(
190 clEnumValN(FloatABI::Default, "default",
191 "Target default float ABI type"),
192 clEnumValN(FloatABI::Soft, "soft",
193 "Soft float ABI (implied by -soft-float)"),
194 clEnumValN(FloatABI::Hard, "hard",
195 "Hard float ABI (uses FP registers)"),
196 clEnumValEnd));
197
198 static cl::opt
199 FuseFPOps("fp-contract",
200 cl::desc("Enable aggresive formation of fused FP ops"),
201 cl::init(FPOpFusion::Standard),
202 cl::values(
203 clEnumValN(FPOpFusion::Fast, "fast",
204 "Fuse FP ops whenever profitable"),
205 clEnumValN(FPOpFusion::Standard, "on",
206 "Only fuse 'blessed' FP ops."),
207 clEnumValN(FPOpFusion::Strict, "off",
208 "Only fuse FP ops when the result won't be effected."),
209 clEnumValEnd));
210
211 static cl::opt
212 DontPlaceZerosInBSS("nozero-initialized-in-bss",
213 cl::desc("Don't place zero-initialized symbols into bss section"),
214 cl::init(false));
215
216 static cl::opt
68 cl::opt
21769 DisableSimplifyLibCalls("disable-simplify-libcalls",
218 cl::desc("Disable simplify-libcalls"),
219 cl::init(false));
220
221 static cl::opt
222 EnableGuaranteedTailCallOpt("tailcallopt",
223 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
224 cl::init(false));
225
226 static cl::opt
227 DisableTailCalls("disable-tail-calls",
228 cl::desc("Never emit tail calls"),
229 cl::init(false));
230
231 static cl::opt
232 OverrideStackAlignment("stack-alignment",
233 cl::desc("Override default stack alignment"),
234 cl::init(0));
235
236 static cl::opt
237 EnableRealignStack("realign-stack",
238 cl::desc("Realign stack if needed"),
239 cl::init(true));
240
241 static cl::opt
242 TrapFuncName("trap-func", cl::Hidden,
243 cl::desc("Emit a call to trap function rather than a trap instruction"),
244 cl::init(""));
245
246 static cl::opt
247 EnablePIE("enable-pie",
248 cl::desc("Assume the creation of a position independent executable."),
249 cl::init(false));
250
251 static cl::opt
252 SegmentedStacks("segmented-stacks",
253 cl::desc("Use segmented stacks if possible."),
254 cl::init(false));
255
256 static cl::opt
257 UseInitArray("use-init-array",
258 cl::desc("Use .init_array instead of .ctors."),
259 cl::init(false));
260
261 static cl::opt StopAfter("stop-after",
262 cl::desc("Stop compilation after a specific pass"),
263 cl::value_desc("pass-name"),
264 cl::init(""));
265 static cl::opt StartAfter("start-after",
266 cl::desc("Resume compilation after a specific pass"),
267 cl::value_desc("pass-name"),
268 cl::init(""));
269
270 static cl::opt
271 SSPBufferSize("stack-protector-buffer-size", cl::init(8),
272 cl::desc("Lower bound for a buffer to be considered for "
273 "stack protection"));
70 cl::desc("Disable simplify-libcalls"),
71 cl::init(false));
27472
27573 // GetFileNameRoot - Helper function to get the basename of a filename.
27674 static inline std::string
504302 TLI->disableAllFunctions();
505303 PM.add(TLI);
506304
305 if (target.get()) {
306 PM.add(new TargetTransformInfo(target->getScalarTargetTransformInfo(),
307 target->getVectorTargetTransformInfo()));
308 }
309
507310 // Add the target data from the target machine, if it exists, or the module.
508311 if (const DataLayout *TD = Target.getDataLayout())
509312 PM.add(new DataLayout(*TD));
None set(LLVM_LINK_COMPONENTS bitreader asmparser bitwriter instrumentation scalaropts ipo vectorize)
0 set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} bitreader asmparser bitwriter instrumentation scalaropts ipo vectorize)
11
22 add_llvm_tool(opt
33 AnalysisWrappers.cpp
1818 type = Tool
1919 name = opt
2020 parent = Tools
21 required_libraries = AsmParser BitReader BitWriter IPO Instrumentation Scalar
21 required_libraries = AsmParser BitReader BitWriter IPO Instrumentation Scalar all-targets
88
99 LEVEL := ../..
1010 TOOLNAME := opt
11 LINK_COMPONENTS := bitreader bitwriter asmparser instrumentation scalaropts ipo vectorize
11 LINK_COMPONENTS := bitreader bitwriter asmparser instrumentation scalaropts ipo vectorize all-targets
1212
1313 include $(LEVEL)/Makefile.common
1717 #include "llvm/Module.h"
1818 #include "llvm/PassManager.h"
1919 #include "llvm/CallGraphSCCPass.h"
20 #include "llvm/CodeGen/CommandFlags.h"
2021 #include "llvm/Bitcode/ReaderWriter.h"
2122 #include "llvm/Assembly/PrintModulePass.h"
2223 #include "llvm/Analysis/Verifier.h"
3536 #include "llvm/Support/PluginLoader.h"
3637 #include "llvm/Support/PrettyStackTrace.h"
3738 #include "llvm/Support/SystemUtils.h"
39 #include "llvm/Support/TargetRegistry.h"
3840 #include "llvm/Support/ToolOutputFile.h"
41 #include "llvm/MC/SubtargetFeature.h"
3942 #include "llvm/LinkAllPasses.h"
4043 #include "llvm/LinkAllVMCore.h"
4144 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
477480 /*RunInliner=*/ !DisableInline);
478481 }
479482
483 //===----------------------------------------------------------------------===//
484 // CodeGen-related helper functions.
485 //
486 static TargetOptions GetTargetOptions() {
487 TargetOptions Options;
488 Options.LessPreciseFPMADOption = EnableFPMAD;
489 Options.NoFramePointerElim = DisableFPElim;
490 Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf;
491 Options.AllowFPOpFusion = FuseFPOps;
492 Options.UnsafeFPMath = EnableUnsafeFPMath;
493 Options.NoInfsFPMath = EnableNoInfsFPMath;
494 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
495 Options.HonorSignDependentRoundingFPMathOption =
496 EnableHonorSignDependentRoundingFPMath;
497 Options.UseSoftFloat = GenerateSoftFloatCalls;
498 if (FloatABIForCalls != FloatABI::Default)
499 Options.FloatABIType = FloatABIForCalls;
500 Options.NoZerosInBSS = DontPlaceZerosInBSS;
501 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
502 Options.DisableTailCalls = DisableTailCalls;
503 Options.StackAlignmentOverride = OverrideStackAlignment;
504 Options.RealignStack = EnableRealignStack;
505 Options.TrapFuncName = TrapFuncName;
506 Options.PositionIndependentExecutable = EnablePIE;
507 Options.EnableSegmentedStacks = SegmentedStacks;
508 Options.UseInitArray = UseInitArray;
509 Options.SSPBufferSize = SSPBufferSize;
510 return Options;
511 }
512
513 CodeGenOpt::Level GetCodeGenOptLevel() {
514 if (OptLevelO1)
515 return CodeGenOpt::Less;
516 if (OptLevelO2)
517 return CodeGenOpt::Default;
518 if (OptLevelO3)
519 return CodeGenOpt::Aggressive;
520 return CodeGenOpt::None;
521 }
522
523 // Returns the TargetMachine instance or zero if no triple is provided.
524 static TargetMachine* GetTargetMachine(std::string TripleStr) {
525 if (TripleStr.empty())
526 return 0;
527
528 // Get the target specific parser.
529 std::string Error;
530 Triple TheTriple(Triple::normalize(TargetTriple));
531
532 const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
533 Error);
534 if (!TheTarget) {
535 return 0;
536 }
537
538 // Package up features to be passed to target/subtarget
539 std::string FeaturesStr;
540 if (MAttrs.size()) {
541 SubtargetFeatures Features;
542 for (unsigned i = 0; i != MAttrs.size(); ++i)
543 Features.AddFeature(MAttrs[i]);
544 FeaturesStr = Features.getString();
545 }
546
547 return TheTarget->createTargetMachine(TheTriple.getTriple(),
548 MCPU, FeaturesStr, GetTargetOptions(),
549 RelocModel, CMModel,
550 GetCodeGenOptLevel());
551 }
480552
481553 //===----------------------------------------------------------------------===//
482554 // main for opt
577649
578650 if (TD)
579651 Passes.add(TD);
652
653 std::auto_ptr TM(GetTargetMachine(TargetTriple));
654 if (TM.get()) {
655 Passes.add(new TargetTransformInfo(TM->getScalarTargetTransformInfo(),
656 TM->getVectorTargetTransformInfo()));
657 }
580658
581659 OwningPtr FPasses;
582660 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {