<commit_before>//===- SuperGraph.cpp - inserts CFI checks based on control flow graph ----===//
//
// This file inserts IDs and checks for a CFI implementation based on the
// control flow graphs and the call graph of a module.
//
//===----------------------------------------------------------------------===//

#define DEBUG_TYPE "SuperGraph"

#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"

#include "dsa/CallTargets.h"

using namespace llvm;

#define CFI_INSERT_INTRINSIC "llvm.arm.cfiid"
#define CFI_CHECK_TAR_INTRINSIC "llvm.arm.cfichecktar"
#define CFI_CHECK_RET_INTRINSIC "llvm.arm.cficheckret"
#define CFI_ABORT "cfi_abort"

namespace {
    /**
     * @brief CFILowering class - handles creation of llvm intrinsic
     * functions
     */
    class CFILowering {
        typedef std::vector<std::string> ArgNames;
        typedef std::vector<llvm::Type*> ArgTypes;
        typedef std::vector<llvm::Value*> ArgVals;
        
        //cfi intrinsic functions, all are of the form:
        //@llvm.arm.cfiid(i32 dest_id)
        Function *cfiInsertID;
        Function *cfiCheckTarget;
        Function *cfiCheckReturn;
        
        /**
         * @brief Creates a function
         *
         * @return Function pointer to newly created function
         *
         * @arg module - current function<commit_msg>commandline enums<commit_after>//===- SuperGraph.cpp - inserts CFI checks based on control flow graph ----===//
//
// This file inserts IDs and checks for a CFI implementation based on the
// control flow graphs and the call graph of a module.
//
//===----------------------------------------------------------------------===//

#define DEBUG_TYPE "SuperGraph"

#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include "dsa/CallTargets.h"
#include "llvm/Support/CommandLine.h"

using namespace llvm;

#define CFI_INSERT_INTRINSIC "llvm.arm.cfiid"
#define CFI_CHECK_TAR_INTRINSIC "llvm.arm.cfichecktar"
#define CFI_CHECK_RET_INTRINSIC "llvm.arm.cficheckret"
#define CFI_ABORT "cfi_abort"

/*
 * Levels of CFI precision
 */
enum CfiLevel{
    TwoId,          /* Abadi's basic "Two-ID CFI" */
    MultiSimple,    /* Abadi's main "Multi-ID CFI" */ 
    MultiPlus,      /* Multi-ID with a white list for solving destination equivalence */
    MultiClone      /* Multi-ID with cloning for context sensitivity */
};

/*
 * Command-line flag for the level of CFI precision
 */
cl::opt<CfiLevel> PrecisionLevel(cl::desc("Choose level of CFI precision:"),
        cl::values(
            clEnumValN(TwoId, "two", "No optimizations, enable debugging"),
            clEnumValN(MultiSimple, "multi", "No optimizations, enable debugging"),
            clEnumValN(MultiPlus, "plus", "No optimizations, enable debugging"),
            clEnumValN(MultiClone, "clone", "No optimizations, enable debugging"),
            clEnumValEnd));

/*
 * Command-line flag for printing precision statistics 
 */
cl::opt<bool> PrintPrecStats("p", cl::desc("Print precision statistics"));

/*
 * Command-line flag for printing debug
 */
cl::opt<bool> Debug("d", cl::desc("Useful for debugging"));

namespace {
    /**
     * @brief CFILowering class - handles creation of llvm intrinsic
     * functions
     */
    class CFILowering {
        typedef std::vector<std::string> ArgNames;
        typedef std::vector<llvm::Type*> ArgTypes;
        typedef std::vector<llvm::Value*> ArgVals;
        
        //cfi intrinsic functions, all are of the form:
        //@llvm.arm.cfiid(i32 dest_id)
        Function *cfiInsertID;
        Function *cfiCheckTarget;
        Function *cfiCheckReturn;
        
        /**
         * @brief Creates a function
         *
         * @return Function pointer to newly created function
         *
         * @arg module - current function
{'fraction_non_alphanumeric': 0.1545610173636586, 'fraction_numerical': 0.0009782342871117633, 'mean_word_length': 2.6003521126760565, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5310041', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1223, 'n_words': 334}