From: Saleem Abdulrasool Date: Fri, 30 Dec 2016 18:45:03 +0000 (+0000) Subject: CodeGen: use a StringSwitch instead of cascasding ifs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac2b77e46c155193933f43aca1935abe5bf3d0c0;p=clang CodeGen: use a StringSwitch instead of cascasding ifs Change the cascading ifs to a StringSwitch to simplify the conversion of the relocation model. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290762 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 54f05ef75d..164e52d7de 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -504,21 +504,14 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { // Keep this synced with the equivalent code in tools/driver/cc1as_main.cpp. llvm::Optional RM; - if (CodeGenOpts.RelocationModel == "static") { - RM = llvm::Reloc::Static; - } else if (CodeGenOpts.RelocationModel == "pic") { - RM = llvm::Reloc::PIC_; - } else if (CodeGenOpts.RelocationModel == "ropi") { - RM = llvm::Reloc::ROPI; - } else if (CodeGenOpts.RelocationModel == "rwpi") { - RM = llvm::Reloc::RWPI; - } else if (CodeGenOpts.RelocationModel == "ropi-rwpi") { - RM = llvm::Reloc::ROPI_RWPI; - } else { - assert(CodeGenOpts.RelocationModel == "dynamic-no-pic" && - "Invalid PIC model!"); - RM = llvm::Reloc::DynamicNoPIC; - } + RM = llvm::StringSwitch(CodeGenOpts.RelocationModel) + .Case("static", llvm::Reloc::Static) + .Case("pic", llvm::Reloc::PIC_) + .Case("ropi", llvm::Reloc::ROPI) + .Case("rwpi", llvm::Reloc::RWPI) + .Case("ropi-rwpi", llvm::Reloc::ROPI_RWPI) + .Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC); + assert(RM.hasValue() && "invalid PIC model!"); CodeGenOpt::Level OptLevel = CodeGenOpt::Default; switch (CodeGenOpts.OptimizationLevel) {