InlinePreparationPass.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2016, The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "InlinePreparationPass.h"
  17. #include "llvm/IR/Module.h"
  18. #include "llvm/Pass.h"
  19. #include "llvm/Support/Debug.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. #include "Context.h"
  22. #define DEBUG_TYPE "rs2spirv-inline"
  23. using namespace llvm;
  24. namespace rs2spirv {
  25. namespace {
  26. class InlinePreparationPass : public ModulePass {
  27. public:
  28. static char ID;
  29. explicit InlinePreparationPass() : ModulePass(ID) {}
  30. const char *getPassName() const override { return "InlinePreparationPass"; }
  31. bool runOnModule(Module &M) override {
  32. DEBUG(dbgs() << "InlinePreparationPass\n");
  33. rs2spirv::Context &Ctxt = rs2spirv::Context::getInstance();
  34. for (auto &F : M.functions()) {
  35. if (F.isDeclaration()) {
  36. continue;
  37. }
  38. if (Ctxt.isForEachKernel(F.getName())) {
  39. continue; // Skip kernels.
  40. }
  41. F.addFnAttr(Attribute::AlwaysInline);
  42. F.setLinkage(GlobalValue::InternalLinkage);
  43. DEBUG(dbgs() << "Marked as alwaysinline:\t" << F.getName() << '\n');
  44. }
  45. // Returns true, because this pass modifies the Module.
  46. return true;
  47. }
  48. };
  49. } // namespace
  50. char InlinePreparationPass::ID = 0;
  51. ModulePass *createInlinePreparationPass() {
  52. return new InlinePreparationPass();
  53. }
  54. } // namespace rs2spirv