| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef LLVM_TARGET_TARGETMACHINE_H |
| 14 |
#define LLVM_TARGET_TARGETMACHINE_H |
| 15 |
|
| 16 |
#include "llvm/ADT/Optional.h" |
| 17 |
#include "llvm/ADT/StringRef.h" |
| 18 |
#include "llvm/ADT/Triple.h" |
| 19 |
#include "llvm/IR/DataLayout.h" |
| 20 |
#include "llvm/IR/PassManager.h" |
| 21 |
#include "llvm/Pass.h" |
| 22 |
#include "llvm/Support/CodeGen.h" |
| 23 |
#include "llvm/Support/Error.h" |
| 24 |
#include "llvm/Support/PGOOptions.h" |
| 25 |
#include "llvm/Target/CGPassBuilderOption.h" |
| 26 |
#include "llvm/Target/TargetOptions.h" |
| 27 |
#include <string> |
| 28 |
#include <utility> |
| 29 |
|
| 30 |
namespace llvm { |
| 31 |
|
| 32 |
class AAManager; |
| 33 |
template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs> |
| 34 |
class PassManager; |
| 35 |
using ModulePassManager = PassManager<Module>; |
| 36 |
|
| 37 |
class Function; |
| 38 |
class GlobalValue; |
| 39 |
class MachineFunctionPassManager; |
| 40 |
class MachineFunctionAnalysisManager; |
| 41 |
class MachineModuleInfoWrapperPass; |
| 42 |
class Mangler; |
| 43 |
class MCAsmInfo; |
| 44 |
class MCContext; |
| 45 |
class MCInstrInfo; |
| 46 |
class MCRegisterInfo; |
| 47 |
class MCStreamer; |
| 48 |
class MCSubtargetInfo; |
| 49 |
class MCSymbol; |
| 50 |
class raw_pwrite_stream; |
| 51 |
class PassBuilder; |
| 52 |
class PassManagerBuilder; |
| 53 |
struct PerFunctionMIParsingState; |
| 54 |
class SMDiagnostic; |
| 55 |
class SMRange; |
| 56 |
class Target; |
| 57 |
class TargetIntrinsicInfo; |
| 58 |
class TargetIRAnalysis; |
| 59 |
class TargetTransformInfo; |
| 60 |
class TargetLoweringObjectFile; |
| 61 |
class TargetPassConfig; |
| 62 |
class TargetSubtargetInfo; |
| 63 |
|
| 64 |
|
| 65 |
namespace legacy { |
| 66 |
class PassManagerBase; |
| 67 |
} |
| 68 |
using legacy::PassManagerBase; |
| 69 |
|
| 70 |
namespace yaml { |
| 71 |
struct MachineFunctionInfo; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
class TargetMachine { |
| 81 |
protected: |
| 82 |
TargetMachine(const Target &T, StringRef DataLayoutString, |
| 83 |
const Triple &TargetTriple, StringRef CPU, StringRef FS, |
| 84 |
const TargetOptions &Options); |
| 85 |
|
| 86 |
|
| 87 |
const Target &TheTarget; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
const DataLayout DL; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
Triple TargetTriple; |
| 100 |
std::string TargetCPU; |
| 101 |
std::string TargetFS; |
| 102 |
|
| 103 |
Reloc::Model RM = Reloc::Static; |
| 104 |
CodeModel::Model CMModel = CodeModel::Small; |
| 105 |
CodeGenOpt::Level OptLevel = CodeGenOpt::Default; |
| 106 |
|
| 107 |
|
| 108 |
std::unique_ptr<const MCAsmInfo> AsmInfo; |
| 109 |
std::unique_ptr<const MCRegisterInfo> MRI; |
| 110 |
std::unique_ptr<const MCInstrInfo> MII; |
| 111 |
std::unique_ptr<const MCSubtargetInfo> STI; |
| 112 |
|
| 113 |
unsigned RequireStructuredCFG : 1; |
| 114 |
unsigned O0WantsFastISel : 1; |
| 115 |
|
| 116 |
|
| 117 |
Optional<PGOOptions> PGOOption = None; |
| 118 |
|
| 119 |
public: |
| 120 |
const TargetOptions DefaultOptions; |
| 121 |
mutable TargetOptions Options; |
| 122 |
|
| 123 |
TargetMachine(const TargetMachine &) = delete; |
| 124 |
void operator=(const TargetMachine &) = delete; |
| 125 |
virtual ~TargetMachine(); |
| 126 |
|
| 127 |
const Target &getTarget() const { return TheTarget; } |
| 128 |
|
| 129 |
const Triple &getTargetTriple() const { return TargetTriple; } |
| 130 |
StringRef getTargetCPU() const { return TargetCPU; } |
| 131 |
StringRef getTargetFeatureString() const { return TargetFS; } |
| 132 |
void setTargetFeatureString(StringRef FS) { TargetFS = std::string(FS); } |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
virtual const TargetSubtargetInfo *getSubtargetImpl(const Function &) const { |
| 137 |
return nullptr; |
| 138 |
} |
| 139 |
virtual TargetLoweringObjectFile *getObjFileLowering() const { |
| 140 |
return nullptr; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
virtual yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const { |
| 146 |
return nullptr; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
virtual yaml::MachineFunctionInfo * |
| 152 |
convertFuncInfoToYAML(const MachineFunction &MF) const { |
| 153 |
return nullptr; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
virtual bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, |
| 158 |
PerFunctionMIParsingState &PFS, |
| 159 |
SMDiagnostic &Error, |
| 160 |
SMRange &SourceRange) const { |
| 161 |
return false; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
template <typename STC> const STC &getSubtarget(const Function &F) const { |
| 168 |
return *static_cast<const STC*>(getSubtargetImpl(F)); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
const DataLayout createDataLayout() const { return DL; } |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
bool isCompatibleDataLayout(const DataLayout &Candidate) const { |
| 180 |
return DL == Candidate; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
unsigned getPointerSize(unsigned AS) const { |
| 187 |
return DL.getPointerSize(AS); |
| 188 |
} |
| 189 |
|
| 190 |
unsigned getPointerSizeInBits(unsigned AS) const { |
| 191 |
return DL.getPointerSizeInBits(AS); |
| 192 |
} |
| 193 |
|
| 194 |
unsigned getProgramPointerSize() const { |
| 195 |
return DL.getPointerSize(DL.getProgramAddressSpace()); |
| 196 |
} |
| 197 |
|
| 198 |
unsigned getAllocaPointerSize() const { |
| 199 |
return DL.getPointerSize(DL.getAllocaAddrSpace()); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
void resetTargetOptions(const Function &F) const; |
| 206 |
|
| 207 |
|
| 208 |
const MCAsmInfo *getMCAsmInfo() const { return AsmInfo.get(); } |
| 209 |
|
| 210 |
const MCRegisterInfo *getMCRegisterInfo() const { return MRI.get(); } |
| 211 |
const MCInstrInfo *getMCInstrInfo() const { return MII.get(); } |
| 212 |
const MCSubtargetInfo *getMCSubtargetInfo() const { return STI.get(); } |
| 213 |
|
| 214 |
|
| 215 |
virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { |
| 216 |
return nullptr; |
| 217 |
} |
| 218 |
|
| 219 |
bool requiresStructuredCFG() const { return RequireStructuredCFG; } |
| 220 |
void setRequiresStructuredCFG(bool Value) { RequireStructuredCFG = Value; } |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
Reloc::Model getRelocationModel() const; |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
CodeModel::Model getCodeModel() const; |
| 229 |
|
| 230 |
bool isPositionIndependent() const; |
| 231 |
|
| 232 |
bool shouldAssumeDSOLocal(const Module &M, const GlobalValue *GV) const; |
| 233 |
|
| 234 |
|
| 235 |
bool useEmulatedTLS() const; |
| 236 |
|
| 237 |
|
| 238 |
TLSModel::Model getTLSModel(const GlobalValue *GV) const; |
| 239 |
|
| 240 |
|
| 241 |
CodeGenOpt::Level getOptLevel() const; |
| 242 |
|
| 243 |
|
| 244 |
void setOptLevel(CodeGenOpt::Level Level); |
| 245 |
|
| 246 |
void setFastISel(bool Enable) { Options.EnableFastISel = Enable; } |
| 247 |
bool getO0WantsFastISel() { return O0WantsFastISel; } |
| 248 |
void setO0WantsFastISel(bool Enable) { O0WantsFastISel = Enable; } |
| 249 |
void setGlobalISel(bool Enable) { Options.EnableGlobalISel = Enable; } |
| 250 |
void setGlobalISelAbort(GlobalISelAbortMode Mode) { |
| 251 |
Options.GlobalISelAbort = Mode; |
| 252 |
} |
| 253 |
void setMachineOutliner(bool Enable) { |
| 254 |
Options.EnableMachineOutliner = Enable; |
| 255 |
} |
| 256 |
void setSupportsDefaultOutlining(bool Enable) { |
| 257 |
Options.SupportsDefaultOutlining = Enable; |
| 258 |
} |
| 259 |
void setSupportsDebugEntryValues(bool Enable) { |
| 260 |
Options.SupportsDebugEntryValues = Enable; |
| 261 |
} |
| 262 |
|
| 263 |
bool getAIXExtendedAltivecABI() const { |
| 264 |
return Options.EnableAIXExtendedAltivecABI; |
| 265 |
} |
| 266 |
|
| 267 |
bool getUniqueSectionNames() const { return Options.UniqueSectionNames; } |
| 268 |
|
| 269 |
|
| 270 |
bool getUniqueBasicBlockSectionNames() const { |
| 271 |
return Options.UniqueBasicBlockSectionNames; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
bool getDataSections() const { |
| 277 |
return Options.DataSections; |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
bool getFunctionSections() const { |
| 283 |
return Options.FunctionSections; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
bool getIgnoreXCOFFVisibility() const { |
| 289 |
return Options.IgnoreXCOFFVisibility; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
bool getXCOFFTracebackTable() const { return Options.XCOFFTracebackTable; } |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
llvm::BasicBlockSection getBBSectionsType() const { |
| 299 |
return Options.BBSections; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
const MemoryBuffer *getBBSectionsFuncListBuf() const { |
| 304 |
return Options.BBSectionsFuncListBuf.get(); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
virtual bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const { |
| 309 |
return false; |
| 310 |
} |
| 311 |
|
| 312 |
void setPGOOption(Optional<PGOOptions> PGOOpt) { PGOOption = PGOOpt; } |
| 313 |
const Optional<PGOOptions> &getPGOOption() const { return PGOOption; } |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
virtual unsigned getAssumedAddrSpace(const Value *V) const { return -1; } |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
virtual std::pair<const Value *, unsigned> |
| 331 |
getPredicatedAddrSpace(const Value *V) const { |
| 332 |
return std::make_pair(nullptr, -1); |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
TargetIRAnalysis getTargetIRAnalysis(); |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
virtual TargetTransformInfo getTargetTransformInfo(const Function &F); |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
virtual void adjustPassManager(PassManagerBuilder &) {} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
virtual void registerPassBuilderCallbacks(PassBuilder &) {} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
virtual void registerDefaultAliasAnalyses(AAManager &) {} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
virtual bool |
| 367 |
addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &, |
| 368 |
raw_pwrite_stream *, CodeGenFileType, |
| 369 |
bool = true, |
| 370 |
MachineModuleInfoWrapperPass *MMIWP = nullptr) { |
| 371 |
return true; |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
virtual bool addPassesToEmitMC(PassManagerBase &, MCContext *&, |
| 380 |
raw_pwrite_stream &, |
| 381 |
bool = true) { |
| 382 |
return true; |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
virtual bool targetSchedulesPostRAScheduling() const { return false; }; |
| 391 |
|
| 392 |
void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV, |
| 393 |
Mangler &Mang, bool MayAlwaysUsePrivate = false) const; |
| 394 |
MCSymbol *getSymbol(const GlobalValue *GV) const; |
| 395 |
|
| 396 |
|
| 397 |
static constexpr unsigned DefaultSjLjDataSize = 32; |
| 398 |
virtual unsigned getSjLjDataSize() const { return DefaultSjLjDataSize; } |
| 399 |
|
| 400 |
static std::pair<int, int> parseBinutilsVersion(StringRef Version); |
| 401 |
}; |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
class LLVMTargetMachine : public TargetMachine { |
| 407 |
protected: |
| 408 |
LLVMTargetMachine(const Target &T, StringRef DataLayoutString, |
| 409 |
const Triple &TT, StringRef CPU, StringRef FS, |
| 410 |
const TargetOptions &Options, Reloc::Model RM, |
| 411 |
CodeModel::Model CM, CodeGenOpt::Level OL); |
| 412 |
|
| 413 |
void initAsmInfo(); |
| 414 |
|
| 415 |
public: |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
TargetTransformInfo getTargetTransformInfo(const Function &F) override; |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM); |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
bool |
| 431 |
addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out, |
| 432 |
raw_pwrite_stream *DwoOut, CodeGenFileType FileType, |
| 433 |
bool DisableVerify = true, |
| 434 |
MachineModuleInfoWrapperPass *MMIWP = nullptr) override; |
| 435 |
|
| 436 |
virtual Error buildCodeGenPipeline(ModulePassManager &, |
| 437 |
MachineFunctionPassManager &, |
| 438 |
MachineFunctionAnalysisManager &, |
| 439 |
raw_pwrite_stream &, raw_pwrite_stream *, |
| 440 |
CodeGenFileType, CGPassBuilderOption, |
| 441 |
PassInstrumentationCallbacks *) { |
| 442 |
return make_error<StringError>("buildCodeGenPipeline is not overriden", |
| 443 |
inconvertibleErrorCode()); |
| 444 |
} |
| 445 |
|
| 446 |
virtual std::pair<StringRef, bool> getPassNameFromLegacyName(StringRef) { |
| 447 |
llvm_unreachable( |
| 448 |
"getPassNameFromLegacyName parseMIRPipeline is not overriden"); |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx, |
| 456 |
raw_pwrite_stream &Out, |
| 457 |
bool DisableVerify = true) override; |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
virtual bool isMachineVerifierClean() const { return true; } |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
bool addAsmPrinter(PassManagerBase &PM, raw_pwrite_stream &Out, |
| 468 |
raw_pwrite_stream *DwoOut, CodeGenFileType FileType, |
| 469 |
MCContext &Context); |
| 470 |
|
| 471 |
Expected<std::unique_ptr<MCStreamer>> |
| 472 |
createMCStreamer(raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, |
| 473 |
CodeGenFileType FileType, MCContext &Ctx); |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
virtual bool usesPhysRegsForValues() const { return true; } |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
virtual bool useIPRA() const { |
| 486 |
return false; |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
virtual int unqualifiedInlineAsmVariant() const { return 0; } |
| 492 |
}; |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
inline CodeModel::Model getEffectiveCodeModel(Optional<CodeModel::Model> CM, |
| 499 |
CodeModel::Model Default) { |
| 500 |
if (CM) { |
| 501 |
|
| 502 |
if (*CM == CodeModel::Tiny) |
| 503 |
report_fatal_error("Target does not support the tiny CodeModel", false); |
| 504 |
if (*CM == CodeModel::Kernel) |
| 505 |
report_fatal_error("Target does not support the kernel CodeModel", false); |
| 506 |
return *CM; |
| 507 |
} |
| 508 |
return Default; |
| 509 |
} |
| 510 |
|
| 511 |
} |
| 512 |
|
| 513 |
#endif |