Skip to content

Commit

Permalink
Sink codegen optimization level into MCCodeGenInfo along side relocat…
Browse files Browse the repository at this point in the history
…ion model

and code model. This eliminates the need to pass OptLevel flag all over the
place and makes it possible for any codegen pass to use this information.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144788 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Evan Cheng committed Nov 16, 2011
1 parent f1b41dd commit b95fc31
Show file tree
Hide file tree
Showing 46 changed files with 344 additions and 313 deletions.
5 changes: 1 addition & 4 deletions include/llvm/CodeGen/MachineFunctionAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ class MachineFunction;
struct MachineFunctionAnalysis : public FunctionPass {
private:
const TargetMachine &TM;
CodeGenOpt::Level OptLevel;
MachineFunction *MF;
unsigned NextFnNum;
public:
static char ID;
explicit MachineFunctionAnalysis(const TargetMachine &tm,
CodeGenOpt::Level OL = CodeGenOpt::Default);
explicit MachineFunctionAnalysis(const TargetMachine &tm);
~MachineFunctionAnalysis();

MachineFunction &getMF() const { return *MF; }
CodeGenOpt::Level getOptLevel() const { return OptLevel; }

virtual const char* getPassName() const {
return "Machine Function Analysis";
Expand Down
9 changes: 8 additions & 1 deletion include/llvm/MC/MCCodeGenInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ namespace llvm {
///
CodeModel::Model CMModel;

/// OptLevel - Optimization level.
///
CodeGenOpt::Level OptLevel;

public:
void InitMCCodeGenInfo(Reloc::Model RM = Reloc::Default,
CodeModel::Model CM = CodeModel::Default);
CodeModel::Model CM = CodeModel::Default,
CodeGenOpt::Level OL = CodeGenOpt::Default);

Reloc::Model getRelocationModel() const { return RelocationModel; }

CodeModel::Model getCodeModel() const { return CMModel; }

CodeGenOpt::Level getOptLevel() const { return OptLevel; }
};
} // namespace llvm

Expand Down
10 changes: 10 additions & 0 deletions include/llvm/Support/CodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ namespace llvm {
enum Model { Default, JITDefault, Small, Kernel, Medium, Large };
}

// Code generation optimization level.
namespace CodeGenOpt {
enum Level {
None, // -O0
Less, // -O1
Default, // -O2, -Os
Aggressive // -O3
};
}

} // end llvm namespace

#endif
33 changes: 19 additions & 14 deletions include/llvm/Support/TargetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ namespace llvm {
StringRef TT);
typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
Reloc::Model RM,
CodeModel::Model CM);
CodeModel::Model CM,
CodeGenOpt::Level OL);
typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
Expand All @@ -86,7 +87,8 @@ namespace llvm {
StringRef CPU,
StringRef Features,
Reloc::Model RM,
CodeModel::Model CM);
CodeModel::Model CM,
CodeGenOpt::Level OL);
typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
MCStreamer &Streamer);
typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
Expand Down Expand Up @@ -145,8 +147,8 @@ namespace llvm {
/// registered.
MCAsmInfoCtorFnTy MCAsmInfoCtorFn;

/// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
/// if registered.
/// MCCodeGenInfoCtorFn - Constructor function for this target's
/// MCCodeGenInfo, if registered.
MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;

/// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
Expand Down Expand Up @@ -277,10 +279,11 @@ namespace llvm {
/// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
///
MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
CodeModel::Model CM) const {
CodeModel::Model CM,
CodeGenOpt::Level OL) const {
if (!MCCodeGenInfoCtorFn)
return 0;
return MCCodeGenInfoCtorFn(Triple, RM, CM);
return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
}

/// createMCInstrInfo - Create a MCInstrInfo implementation.
Expand Down Expand Up @@ -331,12 +334,13 @@ namespace llvm {
/// either the target triple from the module, or the target triple of the
/// host if that does not exist.
TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
StringRef Features,
Reloc::Model RM = Reloc::Default,
CodeModel::Model CM = CodeModel::Default) const {
StringRef Features,
Reloc::Model RM = Reloc::Default,
CodeModel::Model CM = CodeModel::Default,
CodeGenOpt::Level OL = CodeGenOpt::Default) const {
if (!TargetMachineCtorFn)
return 0;
return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM, OL);
}

/// createMCAsmBackend - Create a target specific assembly parser.
Expand Down Expand Up @@ -843,8 +847,8 @@ namespace llvm {
TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
}
private:
static MCCodeGenInfo *Allocator(StringRef TT,
Reloc::Model RM, CodeModel::Model CM) {
static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
CodeModel::Model CM, CodeGenOpt::Level OL) {
return new MCCodeGenInfoImpl();
}
};
Expand Down Expand Up @@ -1014,8 +1018,9 @@ namespace llvm {
static TargetMachine *Allocator(const Target &T, StringRef TT,
StringRef CPU, StringRef FS,
Reloc::Model RM,
CodeModel::Model CM) {
return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
CodeModel::Model CM,
CodeGenOpt::Level OL) {
return new TargetMachineImpl(T, TT, CPU, FS, RM, CM, OL);
}
};

Expand Down
42 changes: 15 additions & 27 deletions include/llvm/Target/TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ class TargetSubtargetInfo;
class formatted_raw_ostream;
class raw_ostream;

// Code generation optimization level.
namespace CodeGenOpt {
enum Level {
None, // -O0
Less, // -O1
Default, // -O2, -Os
Aggressive // -O3
};
}

namespace Sched {
enum Preference {
None, // No preference
Expand Down Expand Up @@ -212,6 +202,10 @@ class TargetMachine {
/// medium, large, and target default.
CodeModel::Model getCodeModel() const;

/// getOptLevel - Returns the optimization level: None, Less,
/// Default, or Aggressive.
CodeGenOpt::Level getOptLevel() const;

/// getAsmVerbosityDefault - Returns the default value of asm verbosity.
///
static bool getAsmVerbosityDefault();
Expand Down Expand Up @@ -255,7 +249,6 @@ class TargetMachine {
virtual bool addPassesToEmitFile(PassManagerBase &,
formatted_raw_ostream &,
CodeGenFileType,
CodeGenOpt::Level,
bool = true) {
return true;
}
Expand All @@ -268,7 +261,6 @@ class TargetMachine {
///
virtual bool addPassesToEmitMachineCode(PassManagerBase &,
JITCodeEmitter &,
CodeGenOpt::Level,
bool = true) {
return true;
}
Expand All @@ -281,7 +273,6 @@ class TargetMachine {
virtual bool addPassesToEmitMC(PassManagerBase &,
MCContext *&,
raw_ostream &,
CodeGenOpt::Level,
bool = true) {
return true;
}
Expand All @@ -294,24 +285,23 @@ class LLVMTargetMachine : public TargetMachine {
protected: // Can only create subclasses.
LLVMTargetMachine(const Target &T, StringRef TargetTriple,
StringRef CPU, StringRef FS,
Reloc::Model RM, CodeModel::Model CM);
Reloc::Model RM, CodeModel::Model CM,
CodeGenOpt::Level OL);

private:
/// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
/// both emitting to assembly files or machine code output.
///
bool addCommonCodeGenPasses(PassManagerBase &, CodeGenOpt::Level,
bool addCommonCodeGenPasses(PassManagerBase &,
bool DisableVerify, MCContext *&OutCtx);

public:
/// addPassesToEmitFile - Add passes to the specified pass manager to get the
/// specified file emitted. Typically this will involve several steps of code
/// generation. If OptLevel is None, the code generator should emit code as
/// fast as possible, though the generated code may be less efficient.
/// generation.
virtual bool addPassesToEmitFile(PassManagerBase &PM,
formatted_raw_ostream &Out,
CodeGenFileType FileType,
CodeGenOpt::Level,
bool DisableVerify = true);

/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
Expand All @@ -322,7 +312,6 @@ class LLVMTargetMachine : public TargetMachine {
///
virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
JITCodeEmitter &MCE,
CodeGenOpt::Level,
bool DisableVerify = true);

/// addPassesToEmitMC - Add passes to the specified pass manager to get
Expand All @@ -333,58 +322,57 @@ class LLVMTargetMachine : public TargetMachine {
virtual bool addPassesToEmitMC(PassManagerBase &PM,
MCContext *&Ctx,
raw_ostream &OS,
CodeGenOpt::Level OptLevel,
bool DisableVerify = true);

/// Target-Independent Code Generator Pass Configuration Options.

/// addPreISelPasses - This method should add any "last minute" LLVM->LLVM
/// passes (which are run just before instruction selector).
virtual bool addPreISel(PassManagerBase &, CodeGenOpt::Level) {
virtual bool addPreISel(PassManagerBase &) {
return true;
}

/// addInstSelector - This method should install an instruction selector pass,
/// which converts from LLVM code to machine instructions.
virtual bool addInstSelector(PassManagerBase &, CodeGenOpt::Level) {
virtual bool addInstSelector(PassManagerBase &) {
return true;
}

/// addPreRegAlloc - This method may be implemented by targets that want to
/// run passes immediately before register allocation. This should return
/// true if -print-machineinstrs should print after these passes.
virtual bool addPreRegAlloc(PassManagerBase &, CodeGenOpt::Level) {
virtual bool addPreRegAlloc(PassManagerBase &) {
return false;
}

/// addPostRegAlloc - This method may be implemented by targets that want
/// to run passes after register allocation but before prolog-epilog
/// insertion. This should return true if -print-machineinstrs should print
/// after these passes.
virtual bool addPostRegAlloc(PassManagerBase &, CodeGenOpt::Level) {
virtual bool addPostRegAlloc(PassManagerBase &) {
return false;
}

/// addPreSched2 - This method may be implemented by targets that want to
/// run passes after prolog-epilog insertion and before the second instruction
/// scheduling pass. This should return true if -print-machineinstrs should
/// print after these passes.
virtual bool addPreSched2(PassManagerBase &, CodeGenOpt::Level) {
virtual bool addPreSched2(PassManagerBase &) {
return false;
}

/// addPreEmitPass - This pass may be implemented by targets that want to run
/// passes immediately before machine code is emitted. This should return
/// true if -print-machineinstrs should print out the code after the passes.
virtual bool addPreEmitPass(PassManagerBase &, CodeGenOpt::Level) {
virtual bool addPreEmitPass(PassManagerBase &) {
return false;
}


/// addCodeEmitter - This pass should be overridden by the target to add a
/// code emitter, if supported. If this is not supported, 'true' should be
/// returned.
virtual bool addCodeEmitter(PassManagerBase &, CodeGenOpt::Level,
virtual bool addCodeEmitter(PassManagerBase &,
JITCodeEmitter &) {
return true;
}
Expand Down
Loading

0 comments on commit b95fc31

Please sign in to comment.