diff options
Diffstat (limited to 'llvm/lib/Target/AArch64/AArch64TargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64TargetMachine.cpp | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp index b3ed96e815be..115a7da8a6d9 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp @@ -31,6 +31,7 @@ #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/Function.h" +#include "llvm/InitializePasses.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCTargetOptions.h" #include "llvm/Pass.h" @@ -39,6 +40,7 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetOptions.h" +#include "llvm/Transforms/CFGuard.h" #include "llvm/Transforms/Scalar.h" #include <memory> #include <string> @@ -152,7 +154,7 @@ static cl::opt<bool> cl::desc("Enable the AAcrh64 branch target pass"), cl::init(true)); -extern "C" void LLVMInitializeAArch64Target() { +extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64Target() { // Register the target. RegisterTargetMachine<AArch64leTargetMachine> X(getTheAArch64leTarget()); RegisterTargetMachine<AArch64beTargetMachine> Y(getTheAArch64beTarget()); @@ -247,7 +249,10 @@ getEffectiveAArch64CodeModel(const Triple &TT, Optional<CodeModel::Model> CM, // The default MCJIT memory managers make no guarantees about where they can // find an executable page; JITed code needs to be able to refer to globals // no matter how far away they are. - if (JIT) + // We should set the CodeModel::Small for Windows ARM64 in JIT mode, + // since with large code model LLVM generating 4 MOV instructions, and + // Windows doesn't support relocating these long branch (4 MOVs). + if (JIT && !TT.isOSWindows()) return CodeModel::Large; return CodeModel::Small; } @@ -283,6 +288,17 @@ AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT, this->Options.TrapUnreachable = true; } + if (this->Options.TLSSize == 0) // default + this->Options.TLSSize = 24; + if ((getCodeModel() == CodeModel::Small || + getCodeModel() == CodeModel::Kernel) && + this->Options.TLSSize > 32) + // for the small (and kernel) code model, the maximum TLS size is 4GiB + this->Options.TLSSize = 32; + else if (getCodeModel() == CodeModel::Tiny && this->Options.TLSSize > 24) + // for the tiny code model, the maximum TLS size is 1MiB (< 16MiB) + this->Options.TLSSize = 24; + // Enable GlobalISel at or below EnableGlobalISelAt0, unless this is // MachO/CodeModel::Large, which GlobalISel does not support. if (getOptLevel() <= EnableGlobalISelAtO && @@ -459,6 +475,10 @@ void AArch64PassConfig::addIRPasses() { addPass(createAArch64StackTaggingPass(/* MergeInit = */ TM->getOptLevel() != CodeGenOpt::None)); + + // Add Control Flow Guard checks. + if (TM->getTargetTriple().isOSWindows()) + addPass(createCFGuardCheckPass()); } // Pass Pipeline Configuration @@ -563,7 +583,7 @@ void AArch64PassConfig::addPreRegAlloc() { if (TM->getOptLevel() != CodeGenOpt::None && EnableAdvSIMDScalar) { addPass(createAArch64AdvSIMDScalar()); // The AdvSIMD pass may produce copies that can be rewritten to - // be register coaleascer friendly. + // be register coalescer friendly. addPass(&PeepholeOptimizerID); } } @@ -609,13 +629,18 @@ void AArch64PassConfig::addPreEmitPass() { if (EnableA53Fix835769) addPass(createAArch64A53Fix835769()); + + if (EnableBranchTargets) + addPass(createAArch64BranchTargetsPass()); + // Relax conditional branch instructions if they're otherwise out of // range of their destination. if (BranchRelaxation) addPass(&BranchRelaxationPassID); - if (EnableBranchTargets) - addPass(createAArch64BranchTargetsPass()); + // Identify valid longjmp targets for Windows Control Flow Guard. + if (TM->getTargetTriple().isOSWindows()) + addPass(createCFGuardLongjmpPass()); if (TM->getOptLevel() != CodeGenOpt::None && EnableCompressJumpTables) addPass(createAArch64CompressJumpTablesPass()); |